Unify method visibility of private classes

Apply checkstyle rule to ensure that private and package private
classes do not have unnecessary public methods. Test classes have
also been unified as much as possible to use default scoped
inner-classes.

Closes gh-7316
This commit is contained in:
Phillip Webb
2019-07-01 12:29:51 -07:00
parent 0a02a3a19c
commit a66c4d3096
910 changed files with 3754 additions and 3945 deletions

View File

@@ -116,11 +116,11 @@ class MetadataGenerationEnvironment {
}
}
public TypeUtils getTypeUtils() {
TypeUtils getTypeUtils() {
return this.typeUtils;
}
public Messager getMessager() {
Messager getMessager() {
return this.messager;
}
@@ -131,11 +131,11 @@ class MetadataGenerationEnvironment {
* @return the default value or {@code null} if the field does not exist or no default
* value has been detected
*/
public Object getFieldDefaultValue(TypeElement type, String name) {
Object getFieldDefaultValue(TypeElement type, String name) {
return this.defaultValues.computeIfAbsent(type, this::resolveFieldValues).get(name);
}
public boolean isExcluded(TypeMirror type) {
boolean isExcluded(TypeMirror type) {
if (type == null) {
return false;
}
@@ -146,7 +146,7 @@ class MetadataGenerationEnvironment {
return TYPE_EXCLUDES.contains(typeName);
}
public boolean isDeprecated(Element element) {
boolean isDeprecated(Element element) {
if (isElementDeprecated(element)) {
return true;
}
@@ -156,7 +156,7 @@ class MetadataGenerationEnvironment {
return false;
}
public ItemDeprecation resolveItemDeprecation(Element element) {
ItemDeprecation resolveItemDeprecation(Element element) {
AnnotationMirror annotation = getAnnotation(element, this.deprecatedConfigurationPropertyAnnotation);
String reason = null;
String replacement = null;
@@ -170,11 +170,11 @@ class MetadataGenerationEnvironment {
return new ItemDeprecation(reason, replacement);
}
public boolean hasAnnotation(Element element, String type) {
boolean hasAnnotation(Element element, String type) {
return getAnnotation(element, type) != null;
}
public AnnotationMirror getAnnotation(Element element, String type) {
AnnotationMirror getAnnotation(Element element, String type) {
if (element != null) {
for (AnnotationMirror annotation : element.getAnnotationMirrors()) {
if (type.equals(annotation.getAnnotationType().toString())) {
@@ -185,7 +185,7 @@ class MetadataGenerationEnvironment {
return null;
}
public Map<String, Object> getAnnotationElementValues(AnnotationMirror annotation) {
Map<String, Object> getAnnotationElementValues(AnnotationMirror annotation) {
Map<String, Object> values = new LinkedHashMap<>();
annotation.getElementValues()
.forEach((name, value) -> values.put(name.getSimpleName().toString(), getAnnotationValue(value)));
@@ -202,31 +202,31 @@ class MetadataGenerationEnvironment {
return value;
}
public TypeElement getConfigurationPropertiesAnnotationElement() {
TypeElement getConfigurationPropertiesAnnotationElement() {
return this.elements.getTypeElement(this.configurationPropertiesAnnotation);
}
public AnnotationMirror getConfigurationPropertiesAnnotation(Element element) {
AnnotationMirror getConfigurationPropertiesAnnotation(Element element) {
return getAnnotation(element, this.configurationPropertiesAnnotation);
}
public AnnotationMirror getNestedConfigurationPropertyAnnotation(Element element) {
AnnotationMirror getNestedConfigurationPropertyAnnotation(Element element) {
return getAnnotation(element, this.nestedConfigurationPropertyAnnotation);
}
public AnnotationMirror getDefaultValueAnnotation(Element element) {
AnnotationMirror getDefaultValueAnnotation(Element element) {
return getAnnotation(element, this.defaultValueAnnotation);
}
public TypeElement getEndpointAnnotationElement() {
TypeElement getEndpointAnnotationElement() {
return this.elements.getTypeElement(this.endpointAnnotation);
}
public AnnotationMirror getReadOperationAnnotation(Element element) {
AnnotationMirror getReadOperationAnnotation(Element element) {
return getAnnotation(element, this.readOperationAnnotation);
}
public boolean hasNullableAnnotation(Element element) {
boolean hasNullableAnnotation(Element element) {
return getAnnotation(element, NULLABLE_ANNOTATION) != null;
}

View File

@@ -63,35 +63,35 @@ abstract class PropertyDescriptor<S extends Element> {
this.setter = setter;
}
public TypeElement getOwnerElement() {
TypeElement getOwnerElement() {
return this.ownerElement;
}
public ExecutableElement getFactoryMethod() {
ExecutableElement getFactoryMethod() {
return this.factoryMethod;
}
public S getSource() {
S getSource() {
return this.source;
}
public String getName() {
String getName() {
return this.name;
}
public TypeMirror getType() {
TypeMirror getType() {
return this.type;
}
public VariableElement getField() {
VariableElement getField() {
return this.field;
}
public ExecutableElement getGetter() {
ExecutableElement getGetter() {
return this.getter;
}
public ExecutableElement getSetter() {
ExecutableElement getSetter() {
return this.setter;
}
@@ -122,7 +122,7 @@ abstract class PropertyDescriptor<S extends Element> {
return isParentTheSame(typeElement, getOwnerElement());
}
public ItemMetadata resolveItemMetadata(String prefix, MetadataGenerationEnvironment environment) {
ItemMetadata resolveItemMetadata(String prefix, MetadataGenerationEnvironment environment) {
if (isNested(environment)) {
return resolveItemMetadataGroup(prefix, environment);
}

View File

@@ -49,7 +49,7 @@ class PropertyDescriptorResolver {
* or {@code null}
* @return the candidate properties for metadata generation
*/
public Stream<PropertyDescriptor<?>> resolve(TypeElement type, ExecutableElement factoryMethod) {
Stream<PropertyDescriptor<?>> resolve(TypeElement type, ExecutableElement factoryMethod) {
TypeElementMembers members = new TypeElementMembers(this.environment, type);
ExecutableElement constructor = resolveConstructor(type);
if (constructor != null) {
@@ -60,7 +60,7 @@ class PropertyDescriptorResolver {
}
}
public Stream<PropertyDescriptor<?>> resolveConstructorProperties(TypeElement type, ExecutableElement factoryMethod,
Stream<PropertyDescriptor<?>> resolveConstructorProperties(TypeElement type, ExecutableElement factoryMethod,
TypeElementMembers members, ExecutableElement constructor) {
Map<String, PropertyDescriptor<?>> candidates = new LinkedHashMap<>();
constructor.getParameters().forEach((parameter) -> {
@@ -75,7 +75,7 @@ class PropertyDescriptorResolver {
return candidates.values().stream();
}
public Stream<PropertyDescriptor<?>> resolveJavaBeanProperties(TypeElement type, ExecutableElement factoryMethod,
Stream<PropertyDescriptor<?>> resolveJavaBeanProperties(TypeElement type, ExecutableElement factoryMethod,
TypeElementMembers members) {
// First check if we have regular java bean properties there
Map<String, PropertyDescriptor<?>> candidates = new LinkedHashMap<>();

View File

@@ -133,15 +133,15 @@ class TypeElementMembers {
}
}
public Map<String, VariableElement> getFields() {
Map<String, VariableElement> getFields() {
return Collections.unmodifiableMap(this.fields);
}
public Map<String, ExecutableElement> getPublicGetters() {
Map<String, ExecutableElement> getPublicGetters() {
return Collections.unmodifiableMap(this.publicGetters);
}
public ExecutableElement getPublicGetter(String name, TypeMirror type) {
ExecutableElement getPublicGetter(String name, TypeMirror type) {
ExecutableElement candidate = this.publicGetters.get(name);
if (candidate != null) {
TypeMirror returnType = candidate.getReturnType();
@@ -156,7 +156,7 @@ class TypeElementMembers {
return null;
}
public ExecutableElement getPublicSetter(String name, TypeMirror type) {
ExecutableElement getPublicSetter(String name, TypeMirror type) {
List<ExecutableElement> candidates = this.publicSetters.get(name);
if (candidates != null) {
ExecutableElement matching = getMatchingSetter(candidates, type);

View File

@@ -106,11 +106,11 @@ class TypeUtils {
}
}
public boolean isSameType(TypeMirror t1, TypeMirror t2) {
boolean isSameType(TypeMirror t1, TypeMirror t2) {
return this.types.isSameType(t1, t2);
}
public Element asElement(TypeMirror type) {
Element asElement(TypeMirror type) {
return this.types.asElement(type);
}
@@ -120,7 +120,7 @@ class TypeUtils {
* @return the fully qualified name of the element, suitable for a call to
* {@link Class#forName(String)}
*/
public String getQualifiedName(Element element) {
String getQualifiedName(Element element) {
return this.typeExtractor.getQualifiedName(element);
}
@@ -131,7 +131,7 @@ class TypeUtils {
* @param type the type to handle
* @return a representation of the type including all its generic information
*/
public String getType(TypeElement element, TypeMirror type) {
String getType(TypeElement element, TypeMirror type) {
if (type == null) {
return null;
}
@@ -144,7 +144,7 @@ class TypeUtils {
* @param type a type, potentially wrapping an element type
* @return the element type or {@code null} if no specific type was found
*/
public TypeMirror extractElementType(TypeMirror type) {
TypeMirror extractElementType(TypeMirror type) {
if (!this.env.getTypeUtils().isAssignable(type, this.collectionType)) {
return null;
}
@@ -171,12 +171,12 @@ class TypeUtils {
return null;
}
public boolean isCollectionOrMap(TypeMirror type) {
boolean isCollectionOrMap(TypeMirror type) {
return this.env.getTypeUtils().isAssignable(type, this.collectionType)
|| this.env.getTypeUtils().isAssignable(type, this.mapType);
}
public String getJavaDoc(Element element) {
String getJavaDoc(Element element) {
String javadoc = (element != null) ? this.env.getElementUtils().getDocComment(element) : null;
if (javadoc != null) {
javadoc = NEW_LINE_PATTERN.matcher(javadoc).replaceAll("").trim();
@@ -190,14 +190,14 @@ class TypeUtils {
* @param typeMirror a type
* @return the primitive type or {@code null} if the type is not a wrapper type
*/
public PrimitiveType getPrimitiveType(TypeMirror typeMirror) {
PrimitiveType getPrimitiveType(TypeMirror typeMirror) {
if (getPrimitiveFor(typeMirror) != null) {
return this.types.unboxedType(typeMirror);
}
return null;
}
public TypeMirror getWrapperOrPrimitiveFor(TypeMirror typeMirror) {
TypeMirror getWrapperOrPrimitiveFor(TypeMirror typeMirror) {
Class<?> candidate = getWrapperFor(typeMirror);
if (candidate != null) {
return this.env.getElementUtils().getTypeElement(candidate.getName()).asType();
@@ -331,7 +331,7 @@ class TypeUtils {
return t.toString();
}
public String getQualifiedName(Element element) {
String getQualifiedName(Element element) {
if (element == null) {
return null;
}
@@ -366,15 +366,15 @@ class TypeUtils {
private final Map<TypeVariable, TypeMirror> generics = new HashMap<>();
public Map<TypeVariable, TypeMirror> getGenerics() {
Map<TypeVariable, TypeMirror> getGenerics() {
return Collections.unmodifiableMap(this.generics);
}
public TypeMirror resolveGeneric(TypeVariable typeVariable) {
TypeMirror resolveGeneric(TypeVariable typeVariable) {
return resolveGeneric(getParameterName(typeVariable));
}
public TypeMirror resolveGeneric(String parameterName) {
TypeMirror resolveGeneric(String parameterName) {
return this.generics.entrySet().stream().filter((e) -> getParameterName(e.getKey()).equals(parameterName))
.findFirst().map(Entry::getValue).orElse(null);
}

View File

@@ -44,18 +44,18 @@ class ExpressionTree extends ReflectionWrapper {
super("com.sun.source.tree.ExpressionTree", instance);
}
public String getKind() throws Exception {
String getKind() throws Exception {
return findMethod("getKind").invoke(getInstance()).toString();
}
public Object getLiteralValue() throws Exception {
Object getLiteralValue() throws Exception {
if (this.literalTreeType.isAssignableFrom(getInstance().getClass())) {
return this.literalValueMethod.invoke(getInstance());
}
return null;
}
public Object getFactoryValue() throws Exception {
Object getFactoryValue() throws Exception {
if (this.methodInvocationTreeType.isAssignableFrom(getInstance().getClass())) {
List<?> arguments = (List<?>) this.methodInvocationArgumentsMethod.invoke(getInstance());
if (arguments.size() == 1) {
@@ -65,7 +65,7 @@ class ExpressionTree extends ReflectionWrapper {
return null;
}
public List<? extends ExpressionTree> getArrayExpression() throws Exception {
List<? extends ExpressionTree> getArrayExpression() throws Exception {
if (this.newArrayTreeType.isAssignableFrom(getInstance().getClass())) {
List<?> elements = (List<?>) this.arrayValueMethod.invoke(getInstance());
List<ExpressionTree> result = new ArrayList<>();

View File

@@ -209,7 +209,7 @@ public class JavaCompilerFieldValuesParser implements FieldValuesParser {
return null;
}
public Map<String, Object> getFieldValues() {
Map<String, Object> getFieldValues() {
return this.fieldValues;
}

View File

@@ -37,7 +37,7 @@ class Tree extends ReflectionWrapper {
super("com.sun.source.tree.Tree", instance);
}
public void accept(TreeVisitor visitor) throws Exception {
void accept(TreeVisitor visitor) throws Exception {
this.acceptMethod.invoke(getInstance(), Proxy.newProxyInstance(getInstance().getClass().getClassLoader(),
new Class<?>[] { this.treeVisitorType }, new TreeVisitorInvocationHandler(visitor)), 0);
}

View File

@@ -32,12 +32,12 @@ final class Trees extends ReflectionWrapper {
super("com.sun.source.util.Trees", instance);
}
public Tree getTree(Element element) throws Exception {
Tree getTree(Element element) throws Exception {
Object tree = findMethod("getTree", Element.class).invoke(getInstance(), element);
return (tree != null) ? new Tree(tree) : null;
}
public static Trees instance(ProcessingEnvironment env) throws Exception {
static Trees instance(ProcessingEnvironment env) throws Exception {
ClassLoader classLoader = env.getClass().getClassLoader();
Class<?> type = findClass(classLoader, "com.sun.source.util.Trees");
Method method = findMethod(type, "instance", ProcessingEnvironment.class);

View File

@@ -32,21 +32,21 @@ class VariableTree extends ReflectionWrapper {
super("com.sun.source.tree.VariableTree", instance);
}
public String getName() throws Exception {
String getName() throws Exception {
return findMethod("getName").invoke(getInstance()).toString();
}
public String getType() throws Exception {
String getType() throws Exception {
return findMethod("getType").invoke(getInstance()).toString();
}
public ExpressionTree getInitializer() throws Exception {
ExpressionTree getInitializer() throws Exception {
Object instance = findMethod("getInitializer").invoke(getInstance());
return (instance != null) ? new ExpressionTree(instance) : null;
}
@SuppressWarnings("unchecked")
public Set<Modifier> getModifierFlags() throws Exception {
Set<Modifier> getModifierFlags() throws Exception {
Object modifiers = findMethod("getModifiers").invoke(getInstance());
if (modifiers == null) {
return Collections.emptySet();

View File

@@ -37,7 +37,7 @@ class JsonConverter {
private static final ItemMetadataComparator ITEM_COMPARATOR = new ItemMetadataComparator();
public JSONArray toJsonArray(ConfigurationMetadata metadata, ItemType itemType) throws Exception {
JSONArray toJsonArray(ConfigurationMetadata metadata, ItemType itemType) throws Exception {
JSONArray jsonArray = new JSONArray();
List<ItemMetadata> items = metadata.getItems().stream().filter((item) -> item.isOfItemType(itemType))
.sorted(ITEM_COMPARATOR).collect(Collectors.toList());
@@ -49,7 +49,7 @@ class JsonConverter {
return jsonArray;
}
public JSONArray toJsonArray(Collection<ItemHint> hints) throws Exception {
JSONArray toJsonArray(Collection<ItemHint> hints) throws Exception {
JSONArray jsonArray = new JSONArray();
for (ItemHint hint : hints) {
jsonArray.put(toJsonObject(hint));
@@ -57,7 +57,7 @@ class JsonConverter {
return jsonArray;
}
public JSONObject toJsonObject(ItemMetadata item) throws Exception {
JSONObject toJsonObject(ItemMetadata item) throws Exception {
JSONObject jsonObject = new JSONObject();
jsonObject.put("name", item.getName());
jsonObject.putOpt("type", item.getType());

View File

@@ -286,7 +286,7 @@ class MergeMetadataGenerationTests extends AbstractMetadataGenerationTests {
}
}
private static class AdditionalMetadata {
static class AdditionalMetadata {
}

View File

@@ -132,7 +132,7 @@ public abstract class AbstractFieldValuesProcessorTests {
return false;
}
public Map<String, Object> getValues() {
Map<String, Object> getValues() {
return this.values;
}

View File

@@ -306,7 +306,7 @@ public final class Metadata {
}
private static class ItemHintValueCondition extends Condition<ItemHint> {
static class ItemHintValueCondition extends Condition<ItemHint> {
private final int index;
@@ -350,7 +350,7 @@ public final class Metadata {
}
private static class ItemHintProviderCondition extends Condition<ItemHint> {
static class ItemHintProviderCondition extends Condition<ItemHint> {
private final int index;
@@ -365,7 +365,7 @@ public final class Metadata {
describedAs(createDescription());
}
public String createDescription() {
String createDescription() {
StringBuilder description = new StringBuilder();
description.append("value provider");
if (this.name != null) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2019 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.
@@ -16,6 +16,12 @@
package org.springframework.boot.configurationprocessor.metadata;
import java.util.Collection;
import org.springframework.boot.configurationprocessor.json.JSONArray;
import org.springframework.boot.configurationprocessor.json.JSONObject;
import org.springframework.boot.configurationprocessor.metadata.ItemMetadata.ItemType;
/**
* {@link JsonConverter} for use in tests.
*
@@ -23,4 +29,19 @@ package org.springframework.boot.configurationprocessor.metadata;
*/
public class TestJsonConverter extends JsonConverter {
@Override
public JSONArray toJsonArray(ConfigurationMetadata metadata, ItemType itemType) throws Exception {
return toJsonArray(metadata, itemType);
}
@Override
public JSONArray toJsonArray(Collection<ItemHint> hints) throws Exception {
return super.toJsonArray(hints);
}
@Override
public JSONObject toJsonObject(ItemMetadata item) throws Exception {
return super.toJsonObject(item);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2019 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.
@@ -41,7 +41,7 @@ public class EmptyTypeMethodConfig {
return new Foo();
}
public static class Foo {
static class Foo {
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 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.
@@ -68,7 +68,7 @@ public class SimpleArrayProperties {
this.nameToInteger = nameToInteger;
}
public static class Holder {
static class Holder {
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2019 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.
@@ -26,7 +26,7 @@ import org.springframework.boot.configurationsample.ConfigurationProperties;
public class InnerClassRootConfig {
@ConfigurationProperties(prefix = "config")
static class Config {
public static class Config {
private String name;