-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Establish the notion of annotation instance equivalence
The `AnnotationInstance.equals()` method provides _equality_. Two annotation instances are equal if, among others, they have identical annotation target. This is often not necessary. Therefore, this commit adds the `equivalentTo()` method, which provides _equivalence_. Two annotation instances are equivalent if they have the same name (the same annotation type) and the same members. No attention is paid to the annotation target.
- Loading branch information
Showing
7 changed files
with
77 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
core/src/test/java/org/jboss/jandex/test/AnnotationInstanceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package org.jboss.jandex.test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertNotEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.io.IOException; | ||
|
||
import org.jboss.jandex.AnnotationInstance; | ||
import org.jboss.jandex.Index; | ||
import org.jboss.jandex.test.util.IndexingUtil; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class AnnotationInstanceTest { | ||
@MyAnnotation("foo") | ||
static class Foo { | ||
} | ||
|
||
@MyAnnotation("foo") | ||
static class Foo2 { | ||
} | ||
|
||
@MyAnnotation("bar") | ||
static class Bar { | ||
} | ||
|
||
@Test | ||
public void equalityEquivalence() throws IOException { | ||
Index index = Index.of(Foo.class, Foo2.class, Bar.class); | ||
testEqualityEquivalence(index); | ||
testEqualityEquivalence(IndexingUtil.roundtrip(index)); | ||
} | ||
|
||
private void testEqualityEquivalence(Index index) { | ||
AnnotationInstance foo = index.getClassByName(Foo.class).declaredAnnotation(MyAnnotation.DOT_NAME); | ||
AnnotationInstance foo2 = index.getClassByName(Foo2.class).declaredAnnotation(MyAnnotation.DOT_NAME); | ||
AnnotationInstance bar = index.getClassByName(Bar.class).declaredAnnotation(MyAnnotation.DOT_NAME); | ||
|
||
assertNotNull(foo); | ||
assertNotNull(foo2); | ||
assertNotNull(bar); | ||
|
||
assertNotEquals(foo, foo2); | ||
assertNotEquals(foo, bar); | ||
assertNotEquals(foo2, bar); | ||
|
||
assertTrue(foo.equivalentTo(foo2)); | ||
assertFalse(foo.equivalentTo(bar)); | ||
assertFalse(foo2.equivalentTo(bar)); | ||
} | ||
} |