Skip to content

Commit 52797ec

Browse files
authored
Issue #20120 - Introduce new DeprecatedInfo annotation (PR #8)
* Create DeprecatedInfo annotation * Adjust javadoc * Add annotation processor * Add .DS_Store to gitignore * Move pkgs * Move pkgs 2 * More pkg renaming * Create processor * Add more validation to processor * Bump up version * Fix compilation errors
1 parent 4919d2e commit 52797ec

20 files changed

Lines changed: 114 additions & 16 deletions

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@ build
66

77
# Intellij IDEA folder
88
.idea
9+
10+
# macOS system files
11+
.DS_Store

build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,11 @@ dependencies {
4141
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
4242
implementation 'jakarta.annotation:jakarta.annotation-api:3.0.0'
4343
implementation 'org.slf4j:slf4j-api:2.0.12'
44+
implementation 'com.google.auto.service:auto-service:1.1.1'
4445

4546
compileOnly 'org.projectlombok:lombok:1.18.30'
4647
annotationProcessor 'org.projectlombok:lombok:1.18.30'
48+
annotationProcessor 'com.google.auto.service:auto-service:1.1.1'
4749

4850
testImplementation 'org.junit.jupiter:junit-jupiter:5.9.3'
4951
testImplementation 'org.assertj:assertj-core:3.25.3'
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.ziro.espresso.annotations;
2+
3+
import java.lang.annotation.Documented;
4+
import java.lang.annotation.ElementType;
5+
import java.lang.annotation.Retention;
6+
import java.lang.annotation.RetentionPolicy;
7+
import java.lang.annotation.Target;
8+
9+
/**
10+
* Provides additional context for deprecated elements.
11+
* <p>
12+
* This annotation should be used in conjunction with {@code @Deprecated} to provide
13+
* information about when the element was deprecated and when it's scheduled for removal.
14+
* </p>
15+
*/
16+
@Documented
17+
@Retention(RetentionPolicy.RUNTIME)
18+
@Target({
19+
ElementType.CONSTRUCTOR,
20+
ElementType.FIELD,
21+
ElementType.LOCAL_VARIABLE,
22+
ElementType.METHOD,
23+
ElementType.PACKAGE,
24+
ElementType.MODULE,
25+
ElementType.PARAMETER,
26+
ElementType.TYPE
27+
})
28+
public @interface DeprecatedInfo {
29+
30+
/**
31+
* Reference to the story/issue where this element was marked as deprecated.
32+
* This field is mandatory.
33+
*
34+
* @return the story/issue reference where the element was deprecated
35+
*/
36+
String deprecatedIn();
37+
38+
/**
39+
* Reference to the story/issue where this element is scheduled for removal.
40+
* This field is mandatory.
41+
*
42+
* @return the story/issue reference for removal
43+
*/
44+
String removingIn();
45+
}

src/main/java/com/ziro/espresso/javax/annotation/extensions/NonNullByDefault.java renamed to src/main/java/com/ziro/espresso/annotations/NonNullByDefault.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.ziro.espresso.javax.annotation.extensions;
1+
package com.ziro.espresso.annotations;
22

33
import jakarta.annotation.Nonnull;
44
import java.lang.annotation.Documented;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
@NonNullByDefault
2+
package com.ziro.espresso.annotations;
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package com.ziro.espresso.annotations.processors;
2+
3+
import com.google.auto.service.AutoService;
4+
import com.ziro.espresso.annotations.DeprecatedInfo;
5+
import java.util.Set;
6+
import javax.annotation.processing.*;
7+
import javax.lang.model.SourceVersion;
8+
import javax.lang.model.element.Element;
9+
import javax.lang.model.element.TypeElement;
10+
import javax.tools.Diagnostic;
11+
12+
@SupportedAnnotationTypes("com.ziro.espresso.annotations.DeprecatedInfo")
13+
@SupportedSourceVersion(SourceVersion.RELEASE_17)
14+
@AutoService(Processor.class)
15+
public class DeprecatedInfoValidator extends AbstractProcessor {
16+
17+
@Override
18+
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
19+
for (Element element : roundEnv.getElementsAnnotatedWith(DeprecatedInfo.class)) {
20+
DeprecatedInfo info = element.getAnnotation(DeprecatedInfo.class);
21+
22+
if (info.deprecatedIn().trim().isEmpty()) {
23+
processingEnv
24+
.getMessager()
25+
.printMessage(Diagnostic.Kind.ERROR, "deprecatedIn must not be empty", element);
26+
}
27+
28+
if (info.removingIn().trim().isEmpty()) {
29+
processingEnv
30+
.getMessager()
31+
.printMessage(Diagnostic.Kind.ERROR, "removingIn must not be empty", element);
32+
}
33+
34+
if (element.getAnnotationMirrors().stream()
35+
.noneMatch(mirror -> mirror.getAnnotationType().toString().equals("java.lang.Deprecated"))) {
36+
37+
processingEnv
38+
.getMessager()
39+
.printMessage(
40+
Diagnostic.Kind.ERROR,
41+
"@DeprecatedInfo must be used together with @Deprecated",
42+
element);
43+
}
44+
}
45+
46+
return false;
47+
}
48+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
@NonNullByDefault
22
package com.ziro.espresso.collections;
33

4-
import com.ziro.espresso.javax.annotation.extensions.NonNullByDefault;
4+
import com.ziro.espresso.annotations.NonNullByDefault;

src/main/java/com/ziro/espresso/fluent/exceptions/AbstractFluentExceptionSupport.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import com.google.common.base.Strings;
44
import com.google.common.base.Throwables;
5-
import com.ziro.espresso.javax.annotation.extensions.NonNullByDefault;
5+
import com.ziro.espresso.annotations.NonNullByDefault;
66
import jakarta.annotation.Nullable;
77
import java.util.Optional;
88
import java.util.function.Supplier;

src/main/java/com/ziro/espresso/fluent/exceptions/ExceptionDetailsStage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.ziro.espresso.fluent.exceptions;
22

3-
import com.ziro.espresso.javax.annotation.extensions.NonNullByDefault;
3+
import com.ziro.espresso.annotations.NonNullByDefault;
44
import java.util.function.Supplier;
55

66
/**

src/main/java/com/ziro/espresso/fluent/exceptions/SystemUnhandledException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.ziro.espresso.fluent.exceptions;
22

3-
import com.ziro.espresso.javax.annotation.extensions.NonNullByDefault;
3+
import com.ziro.espresso.annotations.NonNullByDefault;
44
import jakarta.annotation.Nonnull;
55

66
/**

0 commit comments

Comments
 (0)