-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #270 from Ladicek/inner-constructor-type-annotations
Fix parsing type annotations on constructors of inner classes
- Loading branch information
Showing
11 changed files
with
114 additions
and
15 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
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
72 changes: 72 additions & 0 deletions
72
core/src/test/java/org/jboss/jandex/test/TypeAnnotationOnInnerClassConstructorTest.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,72 @@ | ||
package org.jboss.jandex.test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.io.IOException; | ||
|
||
import org.jboss.jandex.AnnotationInstance; | ||
import org.jboss.jandex.AnnotationTarget; | ||
import org.jboss.jandex.ClassInfo; | ||
import org.jboss.jandex.Index; | ||
import org.jboss.jandex.MethodInfo; | ||
import org.jboss.jandex.Type; | ||
import org.jboss.jandex.TypeTarget; | ||
import org.jboss.jandex.test.util.IndexingUtil; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class TypeAnnotationOnInnerClassConstructorTest { | ||
@MyAnnotation("top-level") | ||
TypeAnnotationOnInnerClassConstructorTest() { | ||
} | ||
|
||
class InnerClass { | ||
@MyAnnotation("inner") | ||
public InnerClass() { | ||
} | ||
|
||
class InnerInnerClass { | ||
@MyAnnotation("inner-inner") | ||
public InnerInnerClass() { | ||
} | ||
} | ||
} | ||
|
||
@Test | ||
public void test() throws IOException { | ||
Index index = Index.of(TypeAnnotationOnInnerClassConstructorTest.class, InnerClass.class, | ||
InnerClass.InnerInnerClass.class); | ||
test(index); | ||
test(IndexingUtil.roundtrip(index)); | ||
} | ||
|
||
private void test(Index index) { | ||
testConstructor(index.getClassByName(TypeAnnotationOnInnerClassConstructorTest.class), "top-level"); | ||
testConstructor(index.getClassByName(InnerClass.class), "inner"); | ||
testConstructor(index.getClassByName(InnerClass.InnerInnerClass.class), "inner-inner"); | ||
|
||
for (AnnotationInstance annotation : index.getAnnotations(MyAnnotation.DOT_NAME)) { | ||
assertTrue(annotation.target().kind() == AnnotationTarget.Kind.METHOD | ||
|| annotation.target().kind() == AnnotationTarget.Kind.TYPE); | ||
|
||
if (annotation.target().kind() == AnnotationTarget.Kind.TYPE) { | ||
TypeTarget typeAnnotationTarget = annotation.target().asType(); | ||
assertEquals(AnnotationTarget.Kind.METHOD, typeAnnotationTarget.enclosingTarget().kind()); | ||
assertTrue(typeAnnotationTarget.enclosingTarget().asMethod().isConstructor()); | ||
assertEquals(Type.Kind.VOID, typeAnnotationTarget.target().kind()); | ||
} | ||
} | ||
} | ||
|
||
private void testConstructor(ClassInfo clazz, String annotationValue) { | ||
assertEquals(1, clazz.constructors().size()); | ||
|
||
MethodInfo ctor = clazz.constructors().get(0); | ||
assertTrue(ctor.hasAnnotation(MyAnnotation.DOT_NAME)); | ||
assertEquals(annotationValue, ctor.annotation(MyAnnotation.DOT_NAME).value().asString()); | ||
|
||
Type ctorType = ctor.returnType(); | ||
assertTrue(ctorType.hasAnnotation(MyAnnotation.DOT_NAME)); | ||
assertEquals(annotationValue, ctorType.annotation(MyAnnotation.DOT_NAME).value().asString()); | ||
} | ||
} |
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