Skip to content

Commit af0d08c

Browse files
author
Phillip Webb
committed
Polish
1 parent b772f7c commit af0d08c

File tree

14 files changed

+151
-147
lines changed

14 files changed

+151
-147
lines changed

spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/aop/AopAutoConfigurationTests.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,6 @@
3535
*/
3636
public class AopAutoConfigurationTests {
3737

38-
public interface TestInterface {
39-
40-
public abstract void foo();
41-
42-
}
43-
4438
private AnnotationConfigApplicationContext context;
4539

4640
@Test
@@ -118,4 +112,10 @@ public void before() {
118112
}
119113
}
120114

115+
public interface TestInterface {
116+
117+
public abstract void foo();
118+
119+
}
120+
121121
}

spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/ArtifactCoordinatesResolver.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,15 @@ public interface ArtifactCoordinatesResolver {
2727
/**
2828
* Gets the group id of the artifact identified by the given {@code artifactId}.
2929
* Returns {@code null} if the artifact is unknown to the resolver.
30-
*
3130
* @param artifactId The id of the artifact
32-
*
3331
* @return The group id of the artifact
3432
*/
3533
String getGroupId(String artifactId);
3634

3735
/**
3836
* Gets the version of the artifact identified by the given {@code artifactId}.
3937
* Returns {@code null} if the artifact is unknown to the resolver.
40-
*
4138
* @param artifactId The id of the artifact
42-
*
4339
* @return The version of the artifact
4440
*/
4541
String getVersion(String artifactId);

spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/AstUtils.java

Lines changed: 34 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import java.util.Arrays;
2020
import java.util.HashSet;
21-
import java.util.List;
2221
import java.util.Set;
2322

2423
import org.codehaus.groovy.ast.AnnotatedNode;
@@ -36,89 +35,70 @@
3635
*/
3736
public abstract class AstUtils {
3837

38+
/**
39+
* Determine if a {@link ClassNode} has one or more of the specified annotations on
40+
* the class or any of its methods. N.B. the type names are not normally fully
41+
* qualified.
42+
*/
43+
public static boolean hasAtLeastOneAnnotation(ClassNode node, String... annotations) {
44+
if (hasAtLeastOneAnnotation((AnnotatedNode) node, annotations)) {
45+
return true;
46+
}
47+
for (MethodNode method : node.getMethods()) {
48+
if (hasAtLeastOneAnnotation(method, annotations)) {
49+
return true;
50+
}
51+
}
52+
return false;
53+
}
54+
3955
/**
4056
* Determine if an {@link AnnotatedNode} has one or more of the specified annotations.
4157
* N.B. the annotation type names are not normally fully qualified.
4258
*/
4359
public static boolean hasAtLeastOneAnnotation(AnnotatedNode node,
4460
String... annotations) {
45-
4661
for (AnnotationNode annotationNode : node.getAnnotations()) {
4762
for (String annotation : annotations) {
4863
if (annotation.equals(annotationNode.getClassNode().getName())) {
4964
return true;
5065
}
5166
}
5267
}
53-
5468
return false;
55-
5669
}
5770

58-
/**
59-
* Determine if a {@link ClassNode} has one or more of the specified annotations on the class
60-
* or any of its methods.
61-
* N.B. the type names are not normally fully qualified.
62-
*/
63-
public static boolean hasAtLeastOneAnnotation(ClassNode node, String... annotations) {
64-
for (AnnotationNode annotationNode : node.getAnnotations()) {
65-
for (String annotation : annotations) {
66-
if (annotation.equals(annotationNode.getClassNode().getName())) {
67-
return true;
68-
}
69-
}
70-
}
71-
72-
List<MethodNode> methods = node.getMethods();
73-
for (MethodNode method : methods) {
74-
for (AnnotationNode annotationNode : method.getAnnotations()) {
75-
for (String annotation : annotations) {
76-
if (annotation.equals(annotationNode.getClassNode().getName())) {
77-
return true;
78-
}
79-
}
80-
}
81-
}
82-
return false;
83-
}
84-
8571
/**
8672
* Determine if a {@link ClassNode} has one or more fields of the specified types or
8773
* method returning one or more of the specified types. N.B. the type names are not
8874
* normally fully qualified.
8975
*/
9076
public static boolean hasAtLeastOneFieldOrMethod(ClassNode node, String... types) {
91-
92-
Set<String> set = new HashSet<String>(Arrays.asList(types));
93-
List<FieldNode> fields = node.getFields();
94-
for (FieldNode field : fields) {
95-
if (set.contains(field.getType().getName())) {
77+
Set<String> typesSet = new HashSet<String>(Arrays.asList(types));
78+
for (FieldNode field : node.getFields()) {
79+
if (typesSet.contains(field.getType().getName())) {
9680
return true;
9781
}
9882
}
99-
List<MethodNode> methods = node.getMethods();
100-
for (MethodNode method : methods) {
101-
if (set.contains(method.getReturnType().getName())) {
83+
for (MethodNode method : node.getMethods()) {
84+
if (typesSet.contains(method.getReturnType().getName())) {
10285
return true;
10386
}
10487
}
105-
10688
return false;
107-
10889
}
10990

110-
/**
111-
* Determine if a {@link ClassNode} subclasses any of the specified types
112-
* N.B. the type names are not normally fully qualified.
113-
*/
114-
public static boolean subclasses(ClassNode node, String... types) {
115-
for (String type : types) {
116-
if (node.getSuperClass().getName().equals(type)) {
117-
return true;
118-
}
119-
}
120-
121-
return false;
122-
}
91+
/**
92+
* Determine if a {@link ClassNode} subclasses any of the specified types N.B. the
93+
* type names are not normally fully qualified.
94+
*/
95+
public static boolean subclasses(ClassNode node, String... types) {
96+
for (String type : types) {
97+
if (node.getSuperClass().getName().equals(type)) {
98+
return true;
99+
}
100+
}
101+
return false;
102+
}
123103

124104
}

spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/GroovyCompiler.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
*
6565
* @author Phillip Webb
6666
* @author Dave Syer
67+
* @author Andy Wilkinson
6768
*/
6869
public class GroovyCompiler {
6970

@@ -73,6 +74,8 @@ public class GroovyCompiler {
7374

7475
private ArtifactCoordinatesResolver artifactCoordinatesResolver;
7576

77+
private final ASTTransformation dependencyCoordinatesTransformation = new DefaultDependencyCoordinatesAstTransformation();
78+
7679
/**
7780
* Create a new {@link GroovyCompiler} instance.
7881
* @param configuration the compiler configuration
@@ -168,7 +171,6 @@ private void addAstTransformations(final CompilationUnit compilationUnit) {
168171
try {
169172
Field field = CompilationUnit.class.getDeclaredField("phaseOperations");
170173
field.setAccessible(true);
171-
172174
LinkedList[] phaseOperations = (LinkedList[]) field.get(compilationUnit);
173175
processConversionOperations(phaseOperations[Phases.CONVERSION]);
174176
}
@@ -186,13 +188,10 @@ private void processConversionOperations(LinkedList conversionOperations) {
186188
if (operation.getClass().getName()
187189
.startsWith(ASTTransformationVisitor.class.getName())) {
188190
conversionOperations.add(i, new CompilationUnit.SourceUnitOperation() {
189-
190-
private final ASTTransformation transformation = new DefaultDependencyCoordinatesAstTransformation();
191-
192191
@Override
193192
public void call(SourceUnit source) throws CompilationFailedException {
194-
this.transformation.visit(new ASTNode[] { source.getAST() },
195-
source);
193+
GroovyCompiler.this.dependencyCoordinatesTransformation.visit(
194+
new ASTNode[] { source.getAST() }, source);
196195
}
197196
});
198197
break;
@@ -312,6 +311,7 @@ private void transformGrabAnnotation(AnnotationNode grabAnnotation,
312311
.getGroupId(module));
313312
grabAnnotation.setMember("group", groupIdExpression);
314313
}
314+
315315
if (grabAnnotation.getMember("version") == null) {
316316
ConstantExpression versionExpression = new ConstantExpression(
317317
GroovyCompiler.this.artifactCoordinatesResolver

spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/PropertiesArtifactCoordinatesResolver.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@
2424
import java.util.Collections;
2525
import java.util.Properties;
2626

27+
/**
28+
* {@link ArtifactCoordinatesResolver} backed by a properties file.
29+
*
30+
* @author Andy Wilkinson
31+
*/
2732
final class PropertiesArtifactCoordinatesResolver implements ArtifactCoordinatesResolver {
2833

2934
private final GroovyClassLoader loader;
@@ -60,15 +65,15 @@ private void loadProperties() {
6065
try {
6166
properties.load(inputStream);
6267
}
63-
catch (IOException ioe) {
68+
catch (IOException ex) {
6469
// Swallow and continue
6570
}
6671
finally {
6772
inputStream.close();
6873
}
6974
}
7075
}
71-
catch (IOException e) {
76+
catch (IOException ex) {
7277
// Swallow and continue
7378
}
7479
this.properties = properties;

spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/autoconfigure/JUnitCompilerAutoConfiguration.java

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,28 +25,26 @@
2525

2626
/**
2727
* {@link CompilerAutoConfiguration} for JUnit
28-
*
28+
*
2929
* @author Greg Turnquist
3030
*/
3131
public class JUnitCompilerAutoConfiguration extends CompilerAutoConfiguration {
3232

33-
@Override
34-
public boolean matches(ClassNode classNode) {
35-
return AstUtils.hasAtLeastOneAnnotation(classNode, "Test");
36-
}
37-
38-
@Override
39-
public void applyDependencies(DependencyCustomizer dependencies)
40-
throws CompilationFailedException {
41-
dependencies.add("junit").add("spring-test").add("hamcrest-library");
42-
}
33+
@Override
34+
public boolean matches(ClassNode classNode) {
35+
return AstUtils.hasAtLeastOneAnnotation(classNode, "Test");
36+
}
4337

44-
@Override
45-
public void applyImports(ImportCustomizer imports) throws CompilationFailedException {
46-
imports.addStarImports("org.junit")
47-
.addStaticStars("org.junit.Assert").addImports()
48-
.addStaticStars("org.hamcrest.MatcherAssert")
49-
.addStaticStars("org.hamcrest.Matchers");
50-
}
38+
@Override
39+
public void applyDependencies(DependencyCustomizer dependencies)
40+
throws CompilationFailedException {
41+
dependencies.add("junit").add("spring-test").add("hamcrest-library");
42+
}
5143

44+
@Override
45+
public void applyImports(ImportCustomizer imports) throws CompilationFailedException {
46+
imports.addStarImports("org.junit").addStaticStars("org.junit.Assert")
47+
.addStaticStars("org.hamcrest.MatcherAssert")
48+
.addStaticStars("org.hamcrest.Matchers");
49+
}
5250
}

spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/autoconfigure/SpockCompilerAutoConfiguration.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,25 @@
2525

2626
/**
2727
* {@link CompilerAutoConfiguration} for Spock test framework
28-
*
28+
*
2929
* @author Greg Turnquist
3030
*/
3131
public class SpockCompilerAutoConfiguration extends CompilerAutoConfiguration {
3232

33-
@Override
34-
public boolean matches(ClassNode classNode) {
35-
return AstUtils.subclasses(classNode, "Specification");
36-
}
33+
@Override
34+
public boolean matches(ClassNode classNode) {
35+
return AstUtils.subclasses(classNode, "Specification");
36+
}
3737

38-
@Override
39-
public void applyDependencies(DependencyCustomizer dependencies)
40-
throws CompilationFailedException {
41-
dependencies.add("spock-core");
42-
}
38+
@Override
39+
public void applyDependencies(DependencyCustomizer dependencies)
40+
throws CompilationFailedException {
41+
dependencies.add("spock-core");
42+
}
4343

44-
@Override
45-
public void applyImports(ImportCustomizer imports) throws CompilationFailedException {
46-
imports.addStarImports("spock.lang");
47-
}
44+
@Override
45+
public void applyImports(ImportCustomizer imports) throws CompilationFailedException {
46+
imports.addStarImports("spock.lang");
47+
}
4848

4949
}

spring-boot-samples/spring-boot-sample-amqp/src/main/java/org/springframework/boot/sample/amqp/SampleAmqpSimpleApplication.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class SampleAmqpSimpleApplication {
3333

3434
@Autowired
3535
private AmqpTemplate amqpTemplate;
36-
36+
3737
@Autowired
3838
private ConnectionFactory connectionFactory;
3939

@@ -49,7 +49,8 @@ public Sender mySender() {
4949

5050
@Bean
5151
public SimpleMessageListenerContainer container() {
52-
SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(connectionFactory);
52+
SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(
53+
this.connectionFactory);
5354
Object listener = new Object() {
5455
@SuppressWarnings("unused")
5556
public void handleMessage(String foo) {
@@ -62,7 +63,6 @@ public void handleMessage(String foo) {
6263
return container;
6364
}
6465

65-
6666
public static void main(String[] args) throws Exception {
6767
SpringApplication.run(SampleAmqpSimpleApplication.class, args);
6868
}

0 commit comments

Comments
 (0)