Upgrade to spring-javaformat 0.0.11

This commit is contained in:
Andy Wilkinson
2019-06-07 09:44:58 +01:00
parent d548c5ed31
commit 8f1be4cded
1940 changed files with 16814 additions and 28498 deletions

View File

@@ -55,8 +55,7 @@ import javax.tools.StandardLocation;
"org.springframework.boot.autoconfigure.AutoConfigureOrder" })
public class AutoConfigureAnnotationProcessor extends AbstractProcessor {
protected static final String PROPERTIES_PATH = "META-INF/"
+ "spring-autoconfigure-metadata.properties";
protected static final String PROPERTIES_PATH = "META-INF/" + "spring-autoconfigure-metadata.properties";
private Map<String, String> annotations;
@@ -69,16 +68,11 @@ public class AutoConfigureAnnotationProcessor extends AbstractProcessor {
}
protected void addAnnotations(Map<String, String> annotations) {
annotations.put("Configuration",
"org.springframework.context.annotation.Configuration");
annotations.put("ConditionalOnClass",
"org.springframework.boot.autoconfigure.condition.ConditionalOnClass");
annotations.put("AutoConfigureBefore",
"org.springframework.boot.autoconfigure.AutoConfigureBefore");
annotations.put("AutoConfigureAfter",
"org.springframework.boot.autoconfigure.AutoConfigureAfter");
annotations.put("AutoConfigureOrder",
"org.springframework.boot.autoconfigure.AutoConfigureOrder");
annotations.put("Configuration", "org.springframework.context.annotation.Configuration");
annotations.put("ConditionalOnClass", "org.springframework.boot.autoconfigure.condition.ConditionalOnClass");
annotations.put("AutoConfigureBefore", "org.springframework.boot.autoconfigure.AutoConfigureBefore");
annotations.put("AutoConfigureAfter", "org.springframework.boot.autoconfigure.AutoConfigureAfter");
annotations.put("AutoConfigureOrder", "org.springframework.boot.autoconfigure.AutoConfigureOrder");
}
@Override
@@ -87,8 +81,7 @@ public class AutoConfigureAnnotationProcessor extends AbstractProcessor {
}
@Override
public boolean process(Set<? extends TypeElement> annotations,
RoundEnvironment roundEnv) {
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
for (Map.Entry<String, String> entry : this.annotations.entrySet()) {
process(roundEnv, entry.getKey(), entry.getValue());
}
@@ -103,36 +96,30 @@ public class AutoConfigureAnnotationProcessor extends AbstractProcessor {
return false;
}
private void process(RoundEnvironment roundEnv, String propertyKey,
String annotationName) {
TypeElement annotationType = this.processingEnv.getElementUtils()
.getTypeElement(annotationName);
private void process(RoundEnvironment roundEnv, String propertyKey, String annotationName) {
TypeElement annotationType = this.processingEnv.getElementUtils().getTypeElement(annotationName);
if (annotationType != null) {
for (Element element : roundEnv.getElementsAnnotatedWith(annotationType)) {
Element enclosingElement = element.getEnclosingElement();
if (enclosingElement != null
&& enclosingElement.getKind() == ElementKind.PACKAGE) {
if (enclosingElement != null && enclosingElement.getKind() == ElementKind.PACKAGE) {
processElement(element, propertyKey, annotationName);
}
}
}
}
private void processElement(Element element, String propertyKey,
String annotationName) {
private void processElement(Element element, String propertyKey, String annotationName) {
try {
String qualifiedName = getQualifiedName(element);
AnnotationMirror annotation = getAnnotation(element, annotationName);
if (qualifiedName != null && annotation != null) {
List<Object> values = getValues(annotation);
this.properties.put(qualifiedName + "." + propertyKey,
toCommaDelimitedString(values));
this.properties.put(qualifiedName + "." + propertyKey, toCommaDelimitedString(values));
this.properties.put(qualifiedName, "");
}
}
catch (Exception ex) {
throw new IllegalStateException(
"Error processing configuration meta-data on " + element, ex);
throw new IllegalStateException("Error processing configuration meta-data on " + element, ex);
}
}
@@ -159,8 +146,8 @@ public class AutoConfigureAnnotationProcessor extends AbstractProcessor {
@SuppressWarnings("unchecked")
private List<Object> getValues(AnnotationMirror annotation) {
List<Object> result = new ArrayList<Object>();
for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : annotation
.getElementValues().entrySet()) {
for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : annotation.getElementValues()
.entrySet()) {
String attributeName = entry.getKey().getSimpleName().toString();
if ("name".equals(attributeName) || "value".equals(attributeName)) {
Object value = entry.getValue().getValue();
@@ -189,8 +176,7 @@ public class AutoConfigureAnnotationProcessor extends AbstractProcessor {
TypeElement enclosingElement = getEnclosingTypeElement(element.asType());
if (enclosingElement != null) {
return getQualifiedName(enclosingElement) + "$"
+ ((DeclaredType) element.asType()).asElement().getSimpleName()
.toString();
+ ((DeclaredType) element.asType()).asElement().getSimpleName().toString();
}
if (element instanceof TypeElement) {
return ((TypeElement) element).getQualifiedName().toString();
@@ -212,8 +198,8 @@ public class AutoConfigureAnnotationProcessor extends AbstractProcessor {
private void writeProperties() throws IOException {
if (!this.properties.isEmpty()) {
FileObject file = this.processingEnv.getFiler()
.createResource(StandardLocation.CLASS_OUTPUT, "", PROPERTIES_PATH);
FileObject file = this.processingEnv.getFiler().createResource(StandardLocation.CLASS_OUTPUT, "",
PROPERTIES_PATH);
OutputStream outputStream = file.openOutputStream();
try {
this.properties.store(outputStream, null);

View File

@@ -56,16 +56,14 @@ public class AutoConfigureAnnotationProcessorTests {
Properties properties = compile(TestClassConfiguration.class);
assertThat(properties).hasSize(3);
assertThat(properties).containsEntry(
"org.springframework.boot.autoconfigureprocessor."
+ "TestClassConfiguration.ConditionalOnClass",
"org.springframework.boot.autoconfigureprocessor." + "TestClassConfiguration.ConditionalOnClass",
"java.io.InputStream,org.springframework.boot.autoconfigureprocessor."
+ "TestClassConfiguration$Nested");
assertThat(properties).containsKey(
"org.springframework.boot.autoconfigureprocessor.TestClassConfiguration");
assertThat(properties).containsKey(
"org.springframework.boot.autoconfigureprocessor.TestClassConfiguration.Configuration");
assertThat(properties).doesNotContainKey(
"org.springframework.boot.autoconfigureprocessor.TestClassConfiguration$Nested");
assertThat(properties).containsKey("org.springframework.boot.autoconfigureprocessor.TestClassConfiguration");
assertThat(properties)
.containsKey("org.springframework.boot.autoconfigureprocessor.TestClassConfiguration.Configuration");
assertThat(properties)
.doesNotContainKey("org.springframework.boot.autoconfigureprocessor.TestClassConfiguration$Nested");
}
@Test
@@ -73,38 +71,29 @@ public class AutoConfigureAnnotationProcessorTests {
Properties properties = compile(TestMethodConfiguration.class);
List<String> matching = new ArrayList<String>();
for (Object key : properties.keySet()) {
if (key.toString().startsWith(
"org.springframework.boot.autoconfigureprocessor.TestMethodConfiguration")) {
if (key.toString().startsWith("org.springframework.boot.autoconfigureprocessor.TestMethodConfiguration")) {
matching.add(key.toString());
}
}
assertThat(matching).hasSize(2)
.contains("org.springframework.boot.autoconfigureprocessor."
+ "TestMethodConfiguration")
.contains("org.springframework.boot.autoconfigureprocessor."
+ "TestMethodConfiguration.Configuration");
.contains("org.springframework.boot.autoconfigureprocessor." + "TestMethodConfiguration")
.contains("org.springframework.boot.autoconfigureprocessor." + "TestMethodConfiguration.Configuration");
}
@Test
public void annotatedClassWithOrder() throws Exception {
Properties properties = compile(TestOrderedClassConfiguration.class);
assertThat(properties).containsEntry(
"org.springframework.boot.autoconfigureprocessor."
+ "TestOrderedClassConfiguration.ConditionalOnClass",
"org.springframework.boot.autoconfigureprocessor." + "TestOrderedClassConfiguration.ConditionalOnClass",
"java.io.InputStream,java.io.OutputStream");
assertThat(properties).containsEntry("org.springframework.boot.autoconfigureprocessor."
+ "TestOrderedClassConfiguration.AutoConfigureBefore", "test.before1,test.before2");
assertThat(properties).containsEntry(
"org.springframework.boot.autoconfigureprocessor."
+ "TestOrderedClassConfiguration.AutoConfigureBefore",
"test.before1,test.before2");
assertThat(properties).containsEntry(
"org.springframework.boot.autoconfigureprocessor."
+ "TestOrderedClassConfiguration.AutoConfigureAfter",
"org.springframework.boot.autoconfigureprocessor." + "TestOrderedClassConfiguration.AutoConfigureAfter",
"java.io.ObjectInputStream");
assertThat(properties)
.containsEntry(
"org.springframework.boot.autoconfigureprocessor."
+ "TestOrderedClassConfiguration.AutoConfigureOrder",
"123");
assertThat(properties).containsEntry(
"org.springframework.boot.autoconfigureprocessor." + "TestOrderedClassConfiguration.AutoConfigureOrder",
"123");
}
private Properties compile(Class<?>... types) throws IOException {

View File

@@ -22,8 +22,7 @@ package org.springframework.boot.autoconfigureprocessor;
* @author Madhura Bhave
*/
@TestConfiguration
@TestConditionalOnClass(name = "java.io.InputStream",
value = TestClassConfiguration.Nested.class)
@TestConditionalOnClass(name = "java.io.InputStream", value = TestClassConfiguration.Nested.class)
public class TestClassConfiguration {
@TestAutoConfigureOrder

View File

@@ -29,14 +29,12 @@ import javax.annotation.processing.SupportedAnnotationTypes;
*
* @author Madhura Bhave
*/
@SupportedAnnotationTypes({
"org.springframework.boot.autoconfigureprocessor.TestConfiguration",
@SupportedAnnotationTypes({ "org.springframework.boot.autoconfigureprocessor.TestConfiguration",
"org.springframework.boot.autoconfigureprocessor.TestConditionalOnClass",
"org.springframework.boot.autoconfigureprocessor.TestAutoConfigureBefore",
"org.springframework.boot.autoconfigureprocessor.TestAutoConfigureAfter",
"org.springframework.boot.autoconfigureprocessor.TestAutoConfigureOrder" })
public class TestConditionMetadataAnnotationProcessor
extends AutoConfigureAnnotationProcessor {
public class TestConditionMetadataAnnotationProcessor extends AutoConfigureAnnotationProcessor {
private final File outputLocation;