-
-
Notifications
You must be signed in to change notification settings - Fork 349
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(annot): Reference to an annotation field as an invocation. (#660)
- Loading branch information
1 parent
0b3390f
commit 92a1975
Showing
7 changed files
with
107 additions
and
3 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
30 changes: 30 additions & 0 deletions
30
src/test/java/spoon/test/reference/AnnotationFieldReferenceTest.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,30 @@ | ||
package spoon.test.reference; | ||
|
||
import org.junit.Test; | ||
import spoon.reflect.code.CtInvocation; | ||
import spoon.reflect.declaration.CtExecutable; | ||
import spoon.reflect.declaration.CtField; | ||
import spoon.reflect.declaration.CtMethod; | ||
import spoon.reflect.factory.Factory; | ||
import spoon.reflect.visitor.filter.TypeFilter; | ||
import spoon.test.reference.testclasses.Mole; | ||
import spoon.test.reference.testclasses.Parameter; | ||
import spoon.testing.utils.ModelUtils; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotNull; | ||
|
||
public class AnnotationFieldReferenceTest { | ||
@Test | ||
public void testAnnotationFieldReference() throws Exception { | ||
final Factory factory = ModelUtils.build(Parameter.class, Mole.class); | ||
final CtMethod<Object> make = factory.Class().get(Mole.class).getMethod("make", factory.Type().createReference(Parameter.class)); | ||
final CtInvocation<?> annotationInv = make.getElements(new TypeFilter<CtInvocation<?>>(CtInvocation.class)).get(0); | ||
final CtExecutable<?> executableDeclaration = annotationInv.getExecutable().getExecutableDeclaration(); | ||
assertNotNull(executableDeclaration); | ||
final CtField<?> value = factory.Annotation().get(Parameter.class).getField("value"); | ||
assertNotNull(value); | ||
assertEquals(value.getSimpleName(), executableDeclaration.getSimpleName()); | ||
assertEquals(value.getType(), executableDeclaration.getType()); | ||
} | ||
} |
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,7 @@ | ||
package spoon.test.reference.testclasses; | ||
|
||
public class Mole { | ||
private void make(Parameter p) { | ||
p.value(); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
src/test/java/spoon/test/reference/testclasses/Parameter.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,5 @@ | ||
package spoon.test.reference.testclasses; | ||
|
||
public @interface Parameter { | ||
String value(); | ||
} |