-
-
Notifications
You must be signed in to change notification settings - Fork 346
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
review fix: contract CtAnnotation and array of values #1935
Merged
Merged
Changes from 11 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
74f9e21
Add new tests regarding shadow classes and annotations
surli 78a176f
Fix tests and add some documentations
surli a994277
Fix checkstyle
surli e9d60f0
Fix warning to info in CtElementImpl. Fix test contract
surli 9a29204
Add new method CtAnnotation#getTypedValue
surli 7c409b4
Revert "Fix tests and add some documentations"
surli 672ecac
Fix test
surli 1e908e8
Improve documentation
surli 9e167ec
Fix checkstyle
surli 295dea9
Fix tests
surli 2b16898
Fix test AnnotationValues
surli f6998f7
Fix tests and add contract
surli a4dc1bc
Change getDeclaration to getTypeDeclaration
surli 49acee3
Change from getTypedValue to getWrappedValue
surli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,6 +37,7 @@ | |
import spoon.reflect.declaration.CtType; | ||
import spoon.reflect.eval.PartialEvaluator; | ||
import spoon.reflect.path.CtRole; | ||
import spoon.reflect.reference.CtArrayTypeReference; | ||
import spoon.reflect.reference.CtFieldReference; | ||
import spoon.reflect.reference.CtTypeReference; | ||
import spoon.reflect.visitor.CtVisitor; | ||
|
@@ -357,6 +358,31 @@ public <T extends CtExpression> T getValue(String key) { | |
return (T) this.elementValues.get(key); | ||
} | ||
|
||
@Override | ||
public <T extends CtExpression> T getTypedValue(String key) { | ||
CtExpression ctExpression = this.getValue(key); | ||
|
||
if (ctExpression instanceof CtLiteral) { | ||
CtTypeReference typeReference = this.getAnnotationType(); | ||
CtType type = typeReference.getDeclaration(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use getTypeDeclaration? |
||
if (type != null) { | ||
CtMethod method = type.getMethod(key); | ||
if (method != null) { | ||
CtTypeReference returnType = method.getType(); | ||
if (returnType instanceof CtArrayTypeReference) { | ||
CtNewArray newArray = getFactory().Core().createNewArray(); | ||
CtArrayTypeReference typeReference2 = this.getFactory().createArrayTypeReference(); | ||
typeReference2.setComponentType(ctExpression.getType().clone()); | ||
newArray.setType(typeReference); | ||
newArray.addElement(ctExpression); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
return (T) newArray; | ||
} | ||
} | ||
} | ||
} | ||
return (T) ctExpression; | ||
} | ||
|
||
public Map<String, Object> getElementValues() { | ||
TreeMap<String, Object> res = new TreeMap<>(); | ||
for (Entry<String, CtExpression> elementValue : elementValues.entrySet()) { | ||
|
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
8 changes: 8 additions & 0 deletions
8
src/test/java/spoon/test/annotation/testclasses/shadow/ClassRetention.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,8 @@ | ||
package spoon.test.annotation.testclasses.shadow; | ||
|
||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
|
||
@Retention(value = RetentionPolicy.CLASS) | ||
public @interface ClassRetention { | ||
} |
16 changes: 16 additions & 0 deletions
16
src/test/java/spoon/test/annotation/testclasses/shadow/DumbKlass.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,16 @@ | ||
package spoon.test.annotation.testclasses.shadow; | ||
|
||
public class DumbKlass { | ||
|
||
@StandardRetention | ||
public void foo() { } | ||
|
||
@ClassRetention | ||
public void fooClass() {} | ||
|
||
@RuntimeRetention(role = "bidule") | ||
public void barOneValue() {} | ||
|
||
@RuntimeRetention(role = { "bidule"}) | ||
public void barMultipleValues() { } | ||
} |
9 changes: 9 additions & 0 deletions
9
src/test/java/spoon/test/annotation/testclasses/shadow/RuntimeRetention.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,9 @@ | ||
package spoon.test.annotation.testclasses.shadow; | ||
|
||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
|
||
@Retention(value = RetentionPolicy.RUNTIME) | ||
public @interface RuntimeRetention { | ||
String[] role(); | ||
} |
4 changes: 4 additions & 0 deletions
4
src/test/java/spoon/test/annotation/testclasses/shadow/StandardRetention.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,4 @@ | ||
package spoon.test.annotation.testclasses.shadow; | ||
|
||
public @interface StandardRetention { | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add
@Derived
to this method... otherwise the metamodel based code will be confused.