Skip to content

Commit

Permalink
#395: checkIfAnnotationsChanged() no longer tracks changes of the ann…
Browse files Browse the repository at this point in the history
…otation class but only of the values
  • Loading branch information
siom79 committed Apr 23, 2024
1 parent 278d5a9 commit 599da82
Show file tree
Hide file tree
Showing 8 changed files with 215 additions and 236 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
String label();
}

@TestAnnotation(name = "recursion", list = {"r", "r2"}, type = @TestAnnotation.Type(label = "test-recursion"))
String name() default "default-name";
String[] list();
Type type();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
}

String name() default "default-name";
@TestAnnotation(name = "recursion", list = {"r", "r2"}, type = @TestAnnotation.Type(label = "test-recursion"))
String[] list();
Type type();
}
399 changes: 200 additions & 199 deletions japicmp/src/main/java/japicmp/compat/CompatibilityChanges.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ public String toString()
+ "]";
}




private JApiChangeStatus evaluateChangeStatus(JApiChangeStatus changeStatus) {
if (changeStatus == JApiChangeStatus.UNCHANGED) {
if (oldValue.isPresent() && newValue.isPresent()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,12 @@ public boolean equals(Object o) {
public int hashCode() {
return Objects.hash(type);
}

@Override
public String toString() {
final StringBuffer sb = new StringBuffer("JApiCompatibilityChange{");
sb.append("type=").append(type);
sb.append('}');
return sb.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ public enum JApiCompatibilityChangeType {
ANNOTATION_ADDED(true, true, JApiSemanticVersionLevel.PATCH),
ANNOTATION_DEPRECATED_ADDED(true, true, JApiSemanticVersionLevel.MINOR),
ANNOTATION_MODIFIED(true, true, JApiSemanticVersionLevel.PATCH),
ANNOTATION_MODIFIED_INCOMPATIBLE(true, true, JApiSemanticVersionLevel.PATCH),
ANNOTATION_REMOVED(true, true, JApiSemanticVersionLevel.PATCH),
CLASS_REMOVED(false, false, JApiSemanticVersionLevel.MAJOR),
CLASS_NOW_ABSTRACT(false, false, JApiSemanticVersionLevel.MAJOR),
Expand Down
37 changes: 5 additions & 32 deletions japicmp/src/test/java/japicmp/compat/CompatibilityChangesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2615,19 +2615,18 @@ public void testAnnotationOnClassModified() throws Exception {
public List<CtClass> createOldClasses(ClassPool classPool) throws Exception {
CtClass anAnnotation = CtAnnotationBuilder.create().name("japicmp.MyAnnotation").addToClassPool(classPool);
CtMethodBuilder.create().name("foo").returnType(CtClass.intType).publicAccess().addToClass(anAnnotation);
CtClass aClass = CtClassBuilder.create().name("japicmp.Test").withAnnotation("japicmp.MyAnnotation").addToClassPool(classPool);
return Arrays.asList(aClass, anAnnotation);
return Collections.singletonList(anAnnotation);
}

@Override
public List<CtClass> createNewClasses(ClassPool classPool) {
CtClass anAnnotation = CtAnnotationBuilder.create().name("japicmp.MyAnnotation").addToClassPool(classPool);
CtClass aClass = CtClassBuilder.create().name("japicmp.Test").withAnnotation("japicmp.MyAnnotation").addToClassPool(classPool);
return Arrays.asList(aClass, anAnnotation);
return Arrays.asList(anAnnotation);
}
});
JApiClass jApiClass = getJApiClass(jApiClasses, "japicmp.Test");
assertThat(jApiClass.getCompatibilityChanges(), hasItem(new JApiCompatibilityChange(JApiCompatibilityChangeType.ANNOTATION_MODIFIED_INCOMPATIBLE)));
JApiClass jApiClass = getJApiClass(jApiClasses, "japicmp.MyAnnotation");
JApiMethod jApiMethod = getJApiMethod(jApiClass.getMethods(), "foo");
assertThat(jApiMethod.getCompatibilityChanges(), hasItem(new JApiCompatibilityChange(JApiCompatibilityChangeType.METHOD_REMOVED)));
}

@Test
Expand Down Expand Up @@ -2677,30 +2676,4 @@ public List<CtClass> createNewClasses(ClassPool classPool) throws Exception {
JApiMethod jApiMethod = getJApiMethod(jApiClass.getMethods(), "method");
assertThat(jApiMethod.getCompatibilityChanges(), hasItem(new JApiCompatibilityChange(JApiCompatibilityChangeType.ANNOTATION_REMOVED)));
}

@Test
public void testAnnotationOnMethodModified() throws Exception {
JarArchiveComparatorOptions options = new JarArchiveComparatorOptions();
List<JApiClass> jApiClasses = ClassesHelper.compareClasses(options, new ClassesHelper.ClassesGenerator() {
@Override
public List<CtClass> createOldClasses(ClassPool classPool) throws Exception {
CtClass anAnnotation = CtAnnotationBuilder.create().name("japicmp.MyAnnotation").addToClassPool(classPool);
CtMethodBuilder.create().name("foo").returnType(CtClass.intType).publicAccess().addToClass(anAnnotation);
CtClass aClass = CtClassBuilder.create().name("japicmp.Test").addToClassPool(classPool);
CtMethodBuilder.create().publicAccess().name("method").withAnnotation("japicmp.MyAnnotation").addToClass(aClass);
return Arrays.asList(aClass, anAnnotation);
}

@Override
public List<CtClass> createNewClasses(ClassPool classPool) throws Exception {
CtClass anAnnotation = CtAnnotationBuilder.create().name("japicmp.MyAnnotation").addToClassPool(classPool);
CtClass aClass = CtClassBuilder.create().name("japicmp.Test").addToClassPool(classPool);
CtMethodBuilder.create().publicAccess().name("method").withAnnotation("japicmp.MyAnnotation").addToClass(aClass);
return Arrays.asList(aClass, anAnnotation);
}
});
JApiClass jApiClass = getJApiClass(jApiClasses, "japicmp.Test");
JApiMethod jApiMethod = getJApiMethod(jApiClass.getMethods(), "method");
assertThat(jApiMethod.getCompatibilityChanges(), hasItem(new JApiCompatibilityChange(JApiCompatibilityChangeType.ANNOTATION_MODIFIED_INCOMPATIBLE)));
}
}
1 change: 0 additions & 1 deletion src/site/markdown/MavenPlugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,6 @@ for each check. This allows you to customize the following verifications:
| ANNOTATION_ADDED | true | true | PATCH |
| ANNOTATION_DEPRECATED_ADDED | true | true | MINOR |
| ANNOTATION_MODIFIED | true | true | PATCH |
| ANNOTATION_MODIFIED_INCOMPATIBLE | true | true | PATCH |
| ANNOTATION_REMOVED | true | true | PATCH |
| CLASS_REMOVED | false | false | MAJOR |
| CLASS_NOW_ABSTRACT | false | false | MAJOR |
Expand Down

0 comments on commit 599da82

Please sign in to comment.