Fix checkstyle ternary issues

Fix checkstyle issues with ternary expressions following the
spring-javaformat upgrade.

See gh-13932
This commit is contained in:
Phillip Webb
2018-07-27 22:54:20 +01:00
parent ec1100a896
commit 7fc455654a
293 changed files with 714 additions and 685 deletions

View File

@@ -317,8 +317,9 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor
reason = (String) elementValues.get("reason");
replacement = (String) elementValues.get("replacement");
}
return new ItemDeprecation(("".equals(reason) ? null : reason),
("".equals(replacement) ? null : replacement));
reason = "".equals(reason) ? null : reason;
replacement = "".equals(replacement) ? null : replacement;
return new ItemDeprecation(reason, replacement);
}
private void processSimpleLombokTypes(String prefix, TypeElement element,
@@ -420,7 +421,7 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor
this.metadataCollector.add(ItemMetadata.newGroup(nestedPrefix,
this.typeUtils.getQualifiedName(returnElement),
this.typeUtils.getQualifiedName(element),
(getter != null ? getter.toString() : null)));
(getter != null) ? getter.toString() : null));
processTypeElement(nestedPrefix, (TypeElement) returnElement, source);
}
}
@@ -453,7 +454,7 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor
this.metadataCollector.add(ItemMetadata.newProperty(endpointKey, "enabled",
Boolean.class.getName(), type, null,
String.format("Whether to enable the %s endpoint.", endpointId),
(enabledByDefault != null ? enabledByDefault : true), null));
(enabledByDefault != null) ? enabledByDefault : true, null));
if (hasMainReadOperation(element)) {
this.metadataCollector.add(ItemMetadata.newProperty(endpointKey,
"cache.time-to-live", Duration.class.getName(), type, null,

View File

@@ -156,8 +156,8 @@ class TypeElementMembers {
}
private String getAccessorName(String methodName) {
String name = (methodName.startsWith("is") ? methodName.substring(2)
: methodName.substring(3));
String name = methodName.startsWith("is") ? methodName.substring(2)
: methodName.substring(3);
name = Character.toLowerCase(name.charAt(0)) + name.substring(1);
return name;
}

View File

@@ -139,12 +139,12 @@ class TypeUtils {
}
public String getJavaDoc(Element element) {
String javadoc = (element != null
? this.env.getElementUtils().getDocComment(element) : null);
String javadoc = (element != null)
? this.env.getElementUtils().getDocComment(element) : null;
if (javadoc != null) {
javadoc = javadoc.replaceAll("[\r\n]+", "").trim();
}
return ("".equals(javadoc) ? null : javadoc);
return "".equals(javadoc) ? null : javadoc;
}
public TypeMirror getWrapperOrPrimitiveFor(TypeMirror typeMirror) {

View File

@@ -178,7 +178,7 @@ public class JavaCompilerFieldValuesParser implements FieldValuesParser {
String type = instance.toString();
type = type.substring(DURATION_OF.length(), type.indexOf('('));
String suffix = DURATION_SUFFIX.get(type);
return (suffix != null ? factoryValue + suffix : null);
return (suffix != null) ? factoryValue + suffix : null;
}
return factoryValue;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -35,7 +35,7 @@ final class Trees extends ReflectionWrapper {
public Tree getTree(Element element) throws Exception {
Object tree = findMethod("getTree", Element.class).invoke(getInstance(), element);
return (tree != null ? new Tree(tree) : null);
return (tree != null) ? new Tree(tree) : null;
}
public static Trees instance(ProcessingEnvironment env) throws Exception {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -43,7 +43,7 @@ class VariableTree extends ReflectionWrapper {
public ExpressionTree getInitializer() throws Exception {
Object instance = findMethod("getInitializer").invoke(getInstance());
return (instance != null ? new ExpressionTree(instance) : null);
return (instance != null) ? new ExpressionTree(instance) : null;
}
@SuppressWarnings("unchecked")

View File

@@ -174,9 +174,9 @@ public class ConfigurationMetadata {
}
public static String nestedPrefix(String prefix, String name) {
String nestedPrefix = (prefix != null ? prefix : "");
String nestedPrefix = (prefix != null) ? prefix : "";
String dashedName = toDashedCase(name);
nestedPrefix += ("".equals(nestedPrefix) ? dashedName : "." + dashedName);
nestedPrefix += "".equals(nestedPrefix) ? dashedName : "." + dashedName;
return nestedPrefix;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -108,7 +108,7 @@ public class ItemDeprecation {
}
private int nullSafeHashCode(Object o) {
return (o != null ? o.hashCode() : 0);
return (o != null) ? o.hashCode() : 0;
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -44,9 +44,9 @@ public class ItemHint implements Comparable<ItemHint> {
public ItemHint(String name, List<ValueHint> values, List<ValueProvider> providers) {
this.name = toCanonicalName(name);
this.values = (values != null ? new ArrayList<>(values) : new ArrayList<>());
this.providers = (providers != null ? new ArrayList<>(providers)
: new ArrayList<>());
this.values = (values != null) ? new ArrayList<>(values) : new ArrayList<>();
this.providers = (providers != null) ? new ArrayList<>(providers)
: new ArrayList<>();
}
private String toCanonicalName(String name) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -61,11 +61,11 @@ public final class ItemMetadata implements Comparable<ItemMetadata> {
while (prefix != null && prefix.endsWith(".")) {
prefix = prefix.substring(0, prefix.length() - 1);
}
StringBuilder fullName = new StringBuilder(prefix != null ? prefix : "");
StringBuilder fullName = new StringBuilder((prefix != null) ? prefix : "");
if (fullName.length() > 0 && name != null) {
fullName.append(".");
}
fullName.append(name != null ? ConfigurationMetadata.toDashedCase(name) : "");
fullName.append((name != null) ? ConfigurationMetadata.toDashedCase(name) : "");
return fullName.toString();
}
@@ -196,7 +196,7 @@ public final class ItemMetadata implements Comparable<ItemMetadata> {
}
private int nullSafeHashCode(Object o) {
return (o != null ? o.hashCode() : 0);
return (o != null) ? o.hashCode() : 0;
}
@Override