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

@@ -32,7 +32,7 @@ import org.springframework.boot.autoconfigureprocessor.TestConditionalOnWebAppli
public class TestClassConfiguration {
@TestAutoConfigureOrder
public static class Nested {
static class Nested {
}

View File

@@ -29,22 +29,22 @@ class AsciidocBuilder {
this.content = new StringBuilder();
}
public AsciidocBuilder appendKey(Object... items) {
AsciidocBuilder appendKey(Object... items) {
for (Object item : items) {
appendln("`+", item, "+` +");
}
return this;
}
public AsciidocBuilder newLine() {
AsciidocBuilder newLine() {
return append(System.lineSeparator());
}
public AsciidocBuilder appendln(Object... items) {
AsciidocBuilder appendln(Object... items) {
return append(items).newLine();
}
public AsciidocBuilder append(Object... items) {
AsciidocBuilder append(Object... items) {
for (Object item : items) {
this.content.append(item);
}

View File

@@ -44,7 +44,7 @@ class CompoundConfigurationTableEntry extends ConfigurationTableEntry {
}
@Override
public void write(AsciidocBuilder builder) {
void write(AsciidocBuilder builder) {
builder.append("|");
this.configurationKeys.forEach(builder::appendKey);
builder.newLine().appendln("|").appendln("|+++", this.description, "+++");

View File

@@ -36,7 +36,7 @@ class ConfigurationTable {
this.entries = new TreeSet<>();
}
public String getId() {
String getId() {
return this.id;
}

View File

@@ -25,11 +25,11 @@ abstract class ConfigurationTableEntry implements Comparable<ConfigurationTableE
protected String key;
public String getKey() {
String getKey() {
return this.key;
}
public abstract void write(AsciidocBuilder builder);
abstract void write(AsciidocBuilder builder);
@Override
public boolean equals(Object obj) {

View File

@@ -53,7 +53,7 @@ class SingleConfigurationTableEntry extends ConfigurationTableEntry {
}
@Override
public void write(AsciidocBuilder builder) {
void write(AsciidocBuilder builder) {
builder.appendln("|`+", this.key, "+`");
writeDefaultValue(builder);
writeDescription(builder);

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.
@@ -36,15 +36,15 @@ class ConfigurationMetadataHint {
private final List<ValueProvider> valueProviders = new ArrayList<>();
public boolean isMapKeyHints() {
boolean isMapKeyHints() {
return (this.id != null && this.id.endsWith(KEY_SUFFIX));
}
public boolean isMapValueHints() {
boolean isMapValueHints() {
return (this.id != null && this.id.endsWith(VALUE_SUFFIX));
}
public String resolveId() {
String resolveId() {
if (isMapKeyHints()) {
return this.id.substring(0, this.id.length() - KEY_SUFFIX.length());
}
@@ -54,19 +54,19 @@ class ConfigurationMetadataHint {
return this.id;
}
public String getId() {
String getId() {
return this.id;
}
public void setId(String id) {
void setId(String id) {
this.id = id;
}
public List<ValueHint> getValueHints() {
List<ValueHint> getValueHints() {
return this.valueHints;
}
public List<ValueProvider> getValueProviders() {
List<ValueProvider> getValueProviders() {
return this.valueProviders;
}

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.
@@ -34,11 +34,11 @@ class ConfigurationMetadataItem extends ConfigurationMetadataProperty {
* attribute would contain the fully qualified name of that class.
* @return the source type
*/
public String getSourceType() {
String getSourceType() {
return this.sourceType;
}
public void setSourceType(String sourceType) {
void setSourceType(String sourceType) {
this.sourceType = sourceType;
}
@@ -48,11 +48,11 @@ class ConfigurationMetadataItem extends ConfigurationMetadataProperty {
* {@code @ConfigurationProperties} annotated class.
* @return the source method
*/
public String getSourceMethod() {
String getSourceMethod() {
return this.sourceMethod;
}
public void setSourceMethod(String sourceMethod) {
void setSourceMethod(String sourceMethod) {
this.sourceMethod = sourceMethod;
}

View File

@@ -39,7 +39,7 @@ class JsonReader {
private final SentenceExtractor sentenceExtractor = new SentenceExtractor();
public RawConfigurationMetadata read(InputStream in, Charset charset) throws IOException {
RawConfigurationMetadata read(InputStream in, Charset charset) throws IOException {
try {
JSONObject json = readJson(in, charset);
List<ConfigurationMetadataSource> groups = parseAllSources(json);

View File

@@ -43,11 +43,11 @@ class RawConfigurationMetadata {
}
}
public List<ConfigurationMetadataSource> getSources() {
List<ConfigurationMetadataSource> getSources() {
return this.sources;
}
public ConfigurationMetadataSource getSource(ConfigurationMetadataItem item) {
ConfigurationMetadataSource getSource(ConfigurationMetadataItem item) {
if (item.getSourceType() == null) {
return null;
}
@@ -57,11 +57,11 @@ class RawConfigurationMetadata {
.max(Comparator.comparingInt((candidate) -> candidate.getGroupId().length())).orElse(null);
}
public List<ConfigurationMetadataItem> getItems() {
List<ConfigurationMetadataItem> getItems() {
return this.items;
}
public List<ConfigurationMetadataHint> getHints() {
List<ConfigurationMetadataHint> getHints() {
return this.hints;
}

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.
@@ -28,7 +28,7 @@ import java.util.stream.Collectors;
*/
class SentenceExtractor {
public String getFirstSentence(String text) {
String getFirstSentence(String text) {
if (text == null) {
return null;
}

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;

View File

@@ -152,7 +152,7 @@ class BootZipCopyAction implements CopyAction {
this.outputStream = outputStream;
}
public void process(FileCopyDetails details) {
void process(FileCopyDetails details) {
if (BootZipCopyAction.this.exclusions.isSatisfiedBy(details)
|| (this.writtenLoaderEntries != null && this.writtenLoaderEntries.isSatisfiedBy(details))) {
return;
@@ -171,7 +171,7 @@ class BootZipCopyAction implements CopyAction {
}
}
public void finish() throws IOException {
void finish() throws IOException {
writeLoaderEntriesIfNecessary(null);
}

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.
@@ -44,7 +44,7 @@ class LoaderZipEntries {
this.entryTime = entryTime;
}
public Spec<FileTreeElement> writeTo(ZipArchiveOutputStream zipOutputStream) throws IOException {
Spec<FileTreeElement> writeTo(ZipArchiveOutputStream zipOutputStream) throws IOException {
WrittenDirectoriesSpec writtenDirectoriesSpec = new WrittenDirectoriesSpec();
try (ZipInputStream loaderJar = new ZipInputStream(
getClass().getResourceAsStream("/META-INF/loader/spring-boot-loader.jar"))) {
@@ -107,7 +107,7 @@ class LoaderZipEntries {
return this.entries.contains(path);
}
public void add(ZipEntry entry) {
void add(ZipEntry entry) {
this.entries.add(entry.getName());
}

View File

@@ -389,7 +389,7 @@ public class JarWriter implements LoaderClassesWriter, AutoCloseable {
return read;
}
public boolean hasZipHeader() {
boolean hasZipHeader() {
return Arrays.equals(this.header, ZIP_HEADER);
}
@@ -431,7 +431,7 @@ public class JarWriter implements LoaderClassesWriter, AutoCloseable {
}
}
public void setupStoredEntry(JarArchiveEntry entry) {
void setupStoredEntry(JarArchiveEntry entry) {
entry.setSize(this.size);
entry.setCompressedSize(this.size);
entry.setCrc(this.crc.getValue());

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.
@@ -40,7 +40,7 @@ public abstract class LogbackInitializer {
private static class Initializer {
public void setRootLogLevel() {
void setRootLogLevel() {
ILoggerFactory factory = StaticLoggerBinder.getSingleton().getLoggerFactory();
Logger logger = factory.getLogger(Logger.ROOT_LOGGER_NAME);
((ch.qos.logback.classic.Logger) logger).setLevel(Level.INFO);

View File

@@ -181,7 +181,7 @@ class MainClassFinderTests {
}
}
private static class ClassNameCollector implements MainClassCallback<Object> {
static class ClassNameCollector implements MainClassCallback<Object> {
private final List<String> classNames = new ArrayList<>();
@@ -191,7 +191,7 @@ class MainClassFinderTests {
return null;
}
public List<String> getClassNames() {
List<String> getClassNames() {
return this.classNames;
}

View File

@@ -680,7 +680,7 @@ class RepackagerTests {
return entryNames;
}
private static class MockLauncherScript implements LaunchScript {
static class MockLauncherScript implements LaunchScript {
private final byte[] bytes;
@@ -695,7 +695,7 @@ class RepackagerTests {
}
public static class TestLayoutFactory implements LayoutFactory {
static class TestLayoutFactory implements LayoutFactory {
@Override
public Layout getLayout(File source) {
@@ -704,7 +704,7 @@ class RepackagerTests {
}
private static class TestLayout extends Layouts.Jar implements CustomLoaderLayout {
static class TestLayout extends Layouts.Jar implements CustomLoaderLayout {
@Override
public void writeLoadedClasses(LoaderClassesWriter writer) throws IOException {

View File

@@ -225,7 +225,7 @@ public class ExplodedArchive implements Archive {
this.file = file;
}
public File getFile() {
File getFile() {
return this.file;
}

View File

@@ -207,7 +207,7 @@ public class JarFileArchive implements Archive {
this.jarEntry = jarEntry;
}
public JarEntry getJarEntry() {
JarEntry getJarEntry() {
return this.jarEntry;
}

View File

@@ -164,7 +164,7 @@ public class RandomAccessDataFile implements RandomAccessData {
* {@code b} is {@code null}. Returns -1 when the end of the stream is reached
* @throws IOException in case of I/O errors
*/
public int doRead(byte[] b, int off, int len) throws IOException {
int doRead(byte[] b, int off, int len) throws IOException {
if (len == 0) {
return 0;
}

View File

@@ -77,11 +77,11 @@ final class AsciiBytes {
this.length = length;
}
public int length() {
int length() {
return this.length;
}
public boolean startsWith(AsciiBytes prefix) {
boolean startsWith(AsciiBytes prefix) {
if (this == prefix) {
return true;
}
@@ -96,7 +96,7 @@ final class AsciiBytes {
return true;
}
public boolean endsWith(AsciiBytes postfix) {
boolean endsWith(AsciiBytes postfix) {
if (this == postfix) {
return true;
}
@@ -112,11 +112,11 @@ final class AsciiBytes {
return true;
}
public AsciiBytes substring(int beginIndex) {
AsciiBytes substring(int beginIndex) {
return substring(beginIndex, this.length);
}
public AsciiBytes substring(int beginIndex, int endIndex) {
AsciiBytes substring(int beginIndex, int endIndex) {
int length = endIndex - beginIndex;
if (this.offset + length > this.bytes.length) {
throw new IndexOutOfBoundsException();
@@ -124,7 +124,7 @@ final class AsciiBytes {
return new AsciiBytes(this.bytes, this.offset + beginIndex, length);
}
public boolean matches(CharSequence name, char suffix) {
boolean matches(CharSequence name, char suffix) {
int charIndex = 0;
int nameLen = name.length();
int totalLen = nameLen + ((suffix != 0) ? 1 : 0);
@@ -239,7 +239,7 @@ final class AsciiBytes {
return new String(bytes, StandardCharsets.UTF_8);
}
public static int hashCode(CharSequence charSequence) {
static int hashCode(CharSequence charSequence) {
// We're compatible with String's hashCode()
if (charSequence instanceof StringSequence) {
// ... but save making an unnecessary String for StringSequence
@@ -248,7 +248,7 @@ final class AsciiBytes {
return charSequence.toString().hashCode();
}
public static int hashCode(int hash, char suffix) {
static int hashCode(int hash, char suffix) {
return (suffix != 0) ? (31 * hash + suffix) : hash;
}

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.
@@ -26,7 +26,7 @@ final class Bytes {
private Bytes() {
}
public static long littleEndianValue(byte[] bytes, int offset, int length) {
static long littleEndianValue(byte[] bytes, int offset, int length) {
long value = 0;
for (int i = length - 1; i >= 0; i--) {
value = ((value << 8) | (bytes[offset + i] & 0xFF));

View File

@@ -92,7 +92,7 @@ class CentralDirectoryEndRecord {
* @param data the source data
* @return the offset within the data where the archive begins
*/
public long getStartOfArchive(RandomAccessData data) {
long getStartOfArchive(RandomAccessData data) {
long length = Bytes.littleEndianValue(this.block, this.offset + 12, 4);
long specifiedOffset = Bytes.littleEndianValue(this.block, this.offset + 16, 4);
long actualOffset = data.getSize() - this.size - length;
@@ -105,7 +105,7 @@ class CentralDirectoryEndRecord {
* @param data the source data
* @return the central directory data
*/
public RandomAccessData getCentralDirectory(RandomAccessData data) {
RandomAccessData getCentralDirectory(RandomAccessData data) {
long offset = Bytes.littleEndianValue(this.block, this.offset + 16, 4);
long length = Bytes.littleEndianValue(this.block, this.offset + 12, 4);
return data.getSubsection(offset, length);
@@ -115,7 +115,7 @@ class CentralDirectoryEndRecord {
* Return the number of ZIP entries in the file.
* @return the number of records in the zip
*/
public int getNumberOfRecords() {
int getNumberOfRecords() {
long numberOfRecords = Bytes.littleEndianValue(this.block, this.offset + 10, 2);
if (numberOfRecords == 0xFFFF) {
throw new IllegalStateException("Zip64 archives are not supported");

View File

@@ -93,7 +93,7 @@ final class CentralDirectoryFileHeader implements FileHeader {
}
}
public AsciiBytes getName() {
AsciiBytes getName() {
return this.name;
}
@@ -102,7 +102,7 @@ final class CentralDirectoryFileHeader implements FileHeader {
return this.name.matches(name, suffix);
}
public boolean isDirectory() {
boolean isDirectory() {
return this.name.endsWith(SLASH);
}
@@ -111,7 +111,7 @@ final class CentralDirectoryFileHeader implements FileHeader {
return (int) Bytes.littleEndianValue(this.header, this.headerOffset + 10, 2);
}
public long getTime() {
long getTime() {
long datetime = Bytes.littleEndianValue(this.header, this.headerOffset + 12, 4);
return decodeMsDosFormatDateTime(datetime);
}
@@ -130,7 +130,7 @@ final class CentralDirectoryFileHeader implements FileHeader {
return localDateTime.toEpochSecond(ZoneId.systemDefault().getRules().getOffset(localDateTime)) * 1000;
}
public long getCrc() {
long getCrc() {
return Bytes.littleEndianValue(this.header, this.headerOffset + 16, 4);
}
@@ -144,15 +144,15 @@ final class CentralDirectoryFileHeader implements FileHeader {
return Bytes.littleEndianValue(this.header, this.headerOffset + 24, 4);
}
public byte[] getExtra() {
byte[] getExtra() {
return this.extra;
}
public boolean hasExtra() {
boolean hasExtra() {
return this.extra.length > 0;
}
public AsciiBytes getComment() {
AsciiBytes getComment() {
return this.comment;
}
@@ -168,8 +168,8 @@ final class CentralDirectoryFileHeader implements FileHeader {
return new CentralDirectoryFileHeader(header, 0, this.name, header, this.comment, this.localHeaderOffset);
}
public static CentralDirectoryFileHeader fromRandomAccessData(RandomAccessData data, int offset,
JarEntryFilter filter) throws IOException {
static CentralDirectoryFileHeader fromRandomAccessData(RandomAccessData data, int offset, JarEntryFilter filter)
throws IOException {
CentralDirectoryFileHeader fileHeader = new CentralDirectoryFileHeader();
byte[] bytes = data.read(offset, 46);
fileHeader.load(bytes, 0, data, offset, filter);

View File

@@ -35,7 +35,7 @@ class CentralDirectoryParser {
private final List<CentralDirectoryVisitor> visitors = new ArrayList<>();
public <T extends CentralDirectoryVisitor> T addVisitor(T visitor) {
<T extends CentralDirectoryVisitor> T addVisitor(T visitor) {
this.visitors.add(visitor);
return visitor;
}
@@ -47,7 +47,7 @@ class CentralDirectoryParser {
* @return the actual archive data without any prefix bytes
* @throws IOException on error
*/
public RandomAccessData parse(RandomAccessData data, boolean skipPrefixBytes) throws IOException {
RandomAccessData parse(RandomAccessData data, boolean skipPrefixBytes) throws IOException {
CentralDirectoryEndRecord endRecord = new CentralDirectoryEndRecord(data);
if (skipPrefixBytes) {
data = getArchiveData(endRecord, data);

View File

@@ -195,20 +195,20 @@ class JarFileEntries implements CentralDirectoryVisitor, Iterable<JarEntry> {
return new EntryIterator();
}
public boolean containsEntry(CharSequence name) {
boolean containsEntry(CharSequence name) {
return getEntry(name, FileHeader.class, true) != null;
}
public JarEntry getEntry(CharSequence name) {
JarEntry getEntry(CharSequence name) {
return getEntry(name, JarEntry.class, true);
}
public InputStream getInputStream(String name) throws IOException {
InputStream getInputStream(String name) throws IOException {
FileHeader entry = getEntry(name, FileHeader.class, false);
return getInputStream(entry);
}
public InputStream getInputStream(FileHeader entry) throws IOException {
InputStream getInputStream(FileHeader entry) throws IOException {
if (entry == null) {
return null;
}
@@ -219,7 +219,7 @@ class JarFileEntries implements CentralDirectoryVisitor, Iterable<JarEntry> {
return inputStream;
}
public RandomAccessData getEntryData(String name) throws IOException {
RandomAccessData getEntryData(String name) throws IOException {
FileHeader entry = getEntry(name, FileHeader.class, false);
if (entry == null) {
return null;
@@ -336,7 +336,7 @@ class JarFileEntries implements CentralDirectoryVisitor, Iterable<JarEntry> {
return index;
}
public void clearCache() {
void clearCache() {
this.entriesCache.clear();
}

View File

@@ -377,7 +377,7 @@ final class JarURLConnection extends java.net.JarURLConnection {
return ((char) ((hi << 4) + lo));
}
public CharSequence toCharSequence() {
CharSequence toCharSequence() {
return this.name;
}
@@ -386,11 +386,11 @@ final class JarURLConnection extends java.net.JarURLConnection {
return this.name.toString();
}
public boolean isEmpty() {
boolean isEmpty() {
return this.name.isEmpty();
}
public String getContentType() {
String getContentType() {
if (this.contentType == null) {
this.contentType = deduceContentType();
}
@@ -405,11 +405,11 @@ final class JarURLConnection extends java.net.JarURLConnection {
return type;
}
public static JarEntryName get(StringSequence spec) {
static JarEntryName get(StringSequence spec) {
return get(spec, 0);
}
public static JarEntryName get(StringSequence spec, int beginIndex) {
static JarEntryName get(StringSequence spec, int beginIndex) {
if (spec.length() <= beginIndex) {
return EMPTY_JAR_ENTRY_NAME;
}

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.
@@ -52,7 +52,7 @@ final class StringSequence implements CharSequence {
this.end = end;
}
public StringSequence subSequence(int start) {
StringSequence subSequence(int start) {
return subSequence(start, length());
}
@@ -72,7 +72,7 @@ final class StringSequence implements CharSequence {
return new StringSequence(this.source, subSequenceStart, subSequenceEnd);
}
public boolean isEmpty() {
boolean isEmpty() {
return length() == 0;
}
@@ -86,23 +86,23 @@ final class StringSequence implements CharSequence {
return this.source.charAt(this.start + index);
}
public int indexOf(char ch) {
int indexOf(char ch) {
return this.source.indexOf(ch, this.start) - this.start;
}
public int indexOf(String str) {
int indexOf(String str) {
return this.source.indexOf(str, this.start) - this.start;
}
public int indexOf(String str, int fromIndex) {
int indexOf(String str, int fromIndex) {
return this.source.indexOf(str, this.start + fromIndex) - this.start;
}
public boolean startsWith(CharSequence prefix) {
boolean startsWith(CharSequence prefix) {
return startsWith(prefix, 0);
}
public boolean startsWith(CharSequence prefix, int offset) {
boolean startsWith(CharSequence prefix, int offset) {
int prefixLength = prefix.length();
if (length() - prefixLength - offset < 0) {
return false;

View File

@@ -360,7 +360,7 @@ class PropertiesLauncherTests {
};
}
public static class TestLoader extends URLClassLoader {
static class TestLoader extends URLClassLoader {
TestLoader(ClassLoader parent) {
super(new URL[0], parent);

View File

@@ -88,7 +88,7 @@ class CentralDirectoryParserTests {
assertThat(headers.hasNext()).isFalse();
}
private static class Collector implements CentralDirectoryVisitor {
static class Collector implements CentralDirectoryVisitor {
private List<CentralDirectoryFileHeader> headers = new ArrayList<>();
@@ -105,13 +105,13 @@ class CentralDirectoryParserTests {
public void visitEnd() {
}
public List<CentralDirectoryFileHeader> getHeaders() {
List<CentralDirectoryFileHeader> getHeaders() {
return this.headers;
}
}
private static class MockCentralDirectoryVisitor implements CentralDirectoryVisitor {
static class MockCentralDirectoryVisitor implements CentralDirectoryVisitor {
private final List<String> invocations = new ArrayList<>();
@@ -130,7 +130,7 @@ class CentralDirectoryParserTests {
this.invocations.add("visitEnd");
}
public List<String> getInvocations() {
List<String> getInvocations() {
return this.invocations;
}

View File

@@ -518,7 +518,7 @@ public abstract class AbstractRunMojo extends AbstractDependencyFilterMojo {
}
}
public void rethrowUncaughtException() throws MojoExecutionException {
void rethrowUncaughtException() throws MojoExecutionException {
synchronized (this.monitor) {
if (this.exception != null) {
throw new MojoExecutionException(
@@ -572,7 +572,7 @@ public abstract class AbstractRunMojo extends AbstractDependencyFilterMojo {
*/
static class SystemPropertyFormatter {
public static String format(String key, String value) {
static String format(String key, String value) {
if (key == null) {
return "";
}

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.
@@ -52,11 +52,11 @@ class EnvVariables {
return (value != null) ? value : "";
}
public Map<String, String> asMap() {
Map<String, String> asMap() {
return Collections.unmodifiableMap(this.variables);
}
public String[] asArray() {
String[] asArray() {
List<String> args = new ArrayList<>(this.variables.size());
for (Map.Entry<String, String> arg : this.variables.entrySet()) {
args.add(arg.getKey() + "=" + arg.getValue());

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.
@@ -44,27 +44,27 @@ abstract class FilterableDependency {
@Parameter
private String classifier;
public String getGroupId() {
String getGroupId() {
return this.groupId;
}
public void setGroupId(String groupId) {
void setGroupId(String groupId) {
this.groupId = groupId;
}
public String getArtifactId() {
String getArtifactId() {
return this.artifactId;
}
public void setArtifactId(String artifactId) {
void setArtifactId(String artifactId) {
this.artifactId = artifactId;
}
public String getClassifier() {
String getClassifier() {
return this.classifier;
}
public void setClassifier(String classifier) {
void setClassifier(String classifier) {
this.classifier = classifier;
}

View File

@@ -44,11 +44,11 @@ class RunArguments {
}
}
public Deque<String> getArgs() {
Deque<String> getArgs() {
return this.args;
}
public String[] asArray() {
String[] asArray() {
return this.args.toArray(new String[0]);
}

View File

@@ -58,7 +58,7 @@ class SpringApplicationAdminClient {
* @return {@code true} if the application is ready to service requests
* @throws MojoExecutionException if the JMX service could not be contacted
*/
public boolean isReady() throws MojoExecutionException {
boolean isReady() throws MojoExecutionException {
try {
return (Boolean) this.connection.getAttribute(this.objectName, "Ready");
}
@@ -82,7 +82,7 @@ class SpringApplicationAdminClient {
* @throws IOException if an I/O error occurs
* @throws InstanceNotFoundException if the lifecycle mbean cannot be found
*/
public void stop() throws MojoExecutionException, IOException, InstanceNotFoundException {
void stop() throws MojoExecutionException, IOException, InstanceNotFoundException {
try {
this.connection.invoke(this.objectName, "shutdown", null, null);
}
@@ -110,7 +110,7 @@ class SpringApplicationAdminClient {
* @return a connection
* @throws IOException if the connection to that server failed
*/
public static JMXConnector connect(int port) throws IOException {
static JMXConnector connect(int port) throws IOException {
String url = "service:jmx:rmi:///jndi/rmi://127.0.0.1:" + port + "/jmxrmi";
JMXServiceURL serviceUrl = new JMXServiceURL(url);
return JMXConnectorFactory.connect(serviceUrl, null);

View File

@@ -122,7 +122,7 @@ class DependencyFilterMojoTests {
this.additionalFilters = additionalFilters;
}
public Set<Artifact> filterDependencies(Artifact... artifacts) throws MojoExecutionException {
Set<Artifact> filterDependencies(Artifact... artifacts) throws MojoExecutionException {
Set<Artifact> input = new LinkedHashSet<>(Arrays.asList(artifacts));
return filterDependencies(input, getFilters(this.additionalFilters));
}

View File

@@ -159,7 +159,7 @@ public final class Verify {
}
private abstract static class AbstractArchiveVerification {
public abstract static class AbstractArchiveVerification {
private final File file;

View File

@@ -1,93 +0,0 @@
/*
* 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.testsupport.context;
import java.io.IOException;
import java.util.HashSet;
import java.util.Set;
import org.junit.jupiter.api.Test;
import org.springframework.asm.Opcodes;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.boot.testsupport.BuildOutput;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternResolver;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.core.type.MethodMetadata;
import org.springframework.core.type.classreading.MetadataReader;
import org.springframework.core.type.classreading.SimpleMetadataReaderFactory;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Abstract base class for {@code @Configuration} sanity checks.
*
* @author Andy Wilkinson
* @since 2.0.0
*/
public abstract class AbstractConfigurationClassTests {
private final BuildOutput buildOutput = new BuildOutput(getClass());
private ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
@Test
void allBeanMethodsArePublic() throws IOException {
Set<String> nonPublicBeanMethods = new HashSet<>();
for (AnnotationMetadata configurationClass : findConfigurationClasses()) {
Set<MethodMetadata> beanMethods = configurationClass.getAnnotatedMethods(Bean.class.getName());
for (MethodMetadata methodMetadata : beanMethods) {
if (!isPublic(methodMetadata)) {
nonPublicBeanMethods
.add(methodMetadata.getDeclaringClassName() + "." + methodMetadata.getMethodName());
}
}
}
assertThat(nonPublicBeanMethods).as("Found non-public @Bean methods").isEmpty();
}
private Set<AnnotationMetadata> findConfigurationClasses() throws IOException {
Set<AnnotationMetadata> configurationClasses = new HashSet<>();
Resource[] resources = this.resolver
.getResources("classpath*:" + getClass().getPackage().getName().replace('.', '/') + "/**/*.class");
for (Resource resource : resources) {
if (!isTestClass(resource)) {
MetadataReader metadataReader = new SimpleMetadataReaderFactory().getMetadataReader(resource);
AnnotationMetadata annotationMetadata = metadataReader.getAnnotationMetadata();
if (annotationMetadata.getAnnotationTypes().contains(Configuration.class.getName())) {
configurationClasses.add(annotationMetadata);
}
}
}
return configurationClasses;
}
private boolean isTestClass(Resource resource) throws IOException {
return resource.getFile().getAbsolutePath()
.startsWith(this.buildOutput.getTestClassesLocation().getAbsolutePath());
}
private boolean isPublic(MethodMetadata methodMetadata) {
int access = (Integer) new DirectFieldAccessor(methodMetadata).getPropertyValue("access");
return (access & Opcodes.ACC_PUBLIC) != 0;
}
}

View File

@@ -142,7 +142,7 @@ class OutputCapture implements CapturedOutput {
System.setErr(this.err);
}
public void release() {
void release() {
System.setOut(this.out.getParent());
System.setErr(this.err.getParent());
}
@@ -159,7 +159,7 @@ class OutputCapture implements CapturedOutput {
}
}
public void append(StringBuilder builder, Predicate<Type> filter) {
void append(StringBuilder builder, Predicate<Type> filter) {
synchronized (this.monitor) {
for (CapturedString stringCapture : this.capturedStrings) {
if (filter.test(stringCapture.getType())) {
@@ -169,7 +169,7 @@ class OutputCapture implements CapturedOutput {
}
}
public void reset() {
void reset() {
synchronized (this.monitor) {
this.capturedStrings.clear();
}
@@ -189,7 +189,7 @@ class OutputCapture implements CapturedOutput {
this.parent = parent;
}
public PrintStream getParent() {
PrintStream getParent() {
return this.parent;
}
@@ -248,7 +248,7 @@ class OutputCapture implements CapturedOutput {
this.string = string;
}
public Type getType() {
Type getType() {
return this.type;
}