Skip to content

Commit c669724

Browse files
committed
Deprecate AnnotationContainer#add
1 parent b11839d commit c669724

File tree

6 files changed

+57
-8
lines changed

6 files changed

+57
-8
lines changed

initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/code/SourceCodeProjectGenerationConfiguration.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ public class SourceCodeProjectGenerationConfiguration {
3939
@Bean
4040
public MainApplicationTypeCustomizer<TypeDeclaration> springBootApplicationAnnotator() {
4141
return (typeDeclaration) -> typeDeclaration.annotations()
42-
.add(ClassName.of("org.springframework.boot.autoconfigure.SpringBootApplication"));
42+
.addSingle(ClassName.of("org.springframework.boot.autoconfigure.SpringBootApplication"));
4343
}
4444

4545
@Bean
4646
public TestApplicationTypeCustomizer<TypeDeclaration> junitJupiterSpringBootTestTypeCustomizer() {
4747
return (typeDeclaration) -> typeDeclaration.annotations()
48-
.add(ClassName.of("org.springframework.boot.test.context.SpringBootTest"));
48+
.addSingle(ClassName.of("org.springframework.boot.test.context.SpringBootTest"));
4949
}
5050

5151
/**

initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/code/groovy/GroovyProjectGenerationDefaultContributorsConfiguration.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ TestApplicationTypeCustomizer<GroovyTypeDeclaration> junitJupiterTestMethodContr
6666
GroovyMethodDeclaration method = GroovyMethodDeclaration.method("contextLoads")
6767
.returning("void")
6868
.body(CodeBlock.of(""));
69-
method.annotations().add(ClassName.of("org.junit.jupiter.api.Test"));
69+
method.annotations().addSingle(ClassName.of("org.junit.jupiter.api.Test"));
7070
typeDeclaration.addMethodDeclaration(method);
7171
};
7272
}
@@ -93,7 +93,7 @@ ServletInitializerCustomizer<GroovyTypeDeclaration> javaServletInitializerCustom
9393
.parameters(
9494
Parameter.of("application", "org.springframework.boot.builder.SpringApplicationBuilder"))
9595
.body(CodeBlock.ofStatement("application.sources($L)", description.getApplicationName()));
96-
configure.annotations().add(ClassName.of(Override.class));
96+
configure.annotations().addSingle(ClassName.of(Override.class));
9797
typeDeclaration.addMethodDeclaration(configure);
9898
};
9999
}

initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/code/java/JavaProjectGenerationDefaultContributorsConfiguration.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ TestApplicationTypeCustomizer<JavaTypeDeclaration> junitJupiterTestMethodContrib
6161
JavaMethodDeclaration method = JavaMethodDeclaration.method("contextLoads")
6262
.returning("void")
6363
.body(CodeBlock.of(""));
64-
method.annotations().add(ClassName.of("org.junit.jupiter.api.Test"));
64+
method.annotations().addSingle(ClassName.of("org.junit.jupiter.api.Test"));
6565
typeDeclaration.addMethodDeclaration(method);
6666
};
6767
}
@@ -85,7 +85,7 @@ ServletInitializerCustomizer<JavaTypeDeclaration> javaServletInitializerCustomiz
8585
Parameter.of("application", "org.springframework.boot.builder.SpringApplicationBuilder"))
8686
.body(CodeBlock.ofStatement("return application.sources($L.class)",
8787
description.getApplicationName()));
88-
configure.annotations().add(ClassName.of(Override.class));
88+
configure.annotations().addSingle(ClassName.of(Override.class));
8989
typeDeclaration.addMethodDeclaration(configure);
9090
};
9191
}

initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/code/kotlin/KotlinProjectGenerationDefaultContributorsConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ TestApplicationTypeCustomizer<KotlinTypeDeclaration> junitJupiterTestMethodContr
5757
return (typeDeclaration) -> {
5858
KotlinFunctionDeclaration function = KotlinFunctionDeclaration.function("contextLoads")
5959
.body(CodeBlock.of(""));
60-
function.annotations().add(ClassName.of("org.junit.jupiter.api.Test"));
60+
function.annotations().addSingle(ClassName.of("org.junit.jupiter.api.Test"));
6161
typeDeclaration.addFunctionDeclaration(function);
6262
};
6363
}

initializr-generator/src/main/java/io/spring/initializr/generator/language/Parameter.java

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,10 @@ public Builder type(String type) {
145145
* Annotate the parameter with the specified annotation.
146146
* @param className the class of the annotation
147147
* @return this for method chaining
148+
* @deprecated in favor of {@link #singleAnnotate(ClassName)} and
149+
* {@link #repeatableAnnotate(ClassName)}
148150
*/
151+
@Deprecated(forRemoval = true)
149152
public Builder annotate(ClassName className) {
150153
return annotate(className, null);
151154
}
@@ -156,12 +159,58 @@ public Builder annotate(ClassName className) {
156159
* @param className the class of the annotation
157160
* @param annotation a consumer of the builder
158161
* @return this for method chaining
162+
* @deprecated in favor of {@link #singleAnnotate(ClassName, Consumer)} and
163+
* {@link #singleAnnotate(ClassName)}
159164
*/
165+
@Deprecated(forRemoval = true)
166+
@SuppressWarnings("removal")
160167
public Builder annotate(ClassName className, Consumer<Annotation.Builder> annotation) {
161168
this.annotations.add(className, annotation);
162169
return this;
163170
}
164171

172+
/**
173+
* Annotate the parameter with the specified single annotation.
174+
* @param className the class of the annotation
175+
* @return this for method chaining
176+
*/
177+
public Builder singleAnnotate(ClassName className) {
178+
return singleAnnotate(className, null);
179+
}
180+
181+
/**
182+
* Annotate the parameter with the specified single annotation, customized by the
183+
* specified consumer.
184+
* @param className the class of the annotation
185+
* @param annotation a consumer of the builder
186+
* @return this for method chaining
187+
*/
188+
public Builder singleAnnotate(ClassName className, Consumer<Annotation.Builder> annotation) {
189+
this.annotations.addSingle(className, annotation);
190+
return this;
191+
}
192+
193+
/**
194+
* Annotate the parameter with the specified repeatable annotation.
195+
* @param className the class of the annotation
196+
* @return this for method chaining
197+
*/
198+
public Builder repeatableAnnotate(ClassName className) {
199+
return repeatableAnnotate(className, null);
200+
}
201+
202+
/**
203+
* Annotate the parameter with the specified repeatable annotation, customized by
204+
* the specified consumer.
205+
* @param className the class of the annotation
206+
* @param annotation a consumer of the builder
207+
* @return this for method chaining
208+
*/
209+
public Builder repeatableAnnotate(ClassName className, Consumer<Annotation.Builder> annotation) {
210+
this.annotations.addRepeatable(className, annotation);
211+
return this;
212+
}
213+
165214
public Parameter build() {
166215
return new Parameter(this);
167216
}

initializr-generator/src/main/java/io/spring/initializr/generator/language/kotlin/KotlinPropertyDeclaration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ public AccessorBuilder<?> withAnnotation(ClassName className) {
281281
* @return this for method chaining
282282
*/
283283
public AccessorBuilder<?> withAnnotation(ClassName className, Consumer<Annotation.Builder> annotation) {
284-
this.annotations.add(className, annotation);
284+
this.annotations.addSingle(className, annotation);
285285
return this;
286286
}
287287

0 commit comments

Comments
 (0)