Skip to content
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

feat(shadow): Build shadow element from class object. #569

Merged
merged 8 commits into from
Apr 22, 2016
Merged

feat(shadow): Build shadow element from class object. #569

merged 8 commits into from
Apr 22, 2016

Conversation

GerardPaligot
Copy link
Contributor

No description provided.

Assert.assertEquals(2,annot.names().length);
Assert.assertEquals("foo",annot.names()[0]);
Assert.assertEquals("bar",annot.names()[1]);
final CtAnnotation<SampleAnnotation> annotation = type.getAnnotation(type.getFactory().Annotation().createReference(SampleAnnotation.class));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do this change the return type of getAnnotation? is it backward compatible?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are two methods named getAnnotation(...):

  • getAnnotation(Class<Annotation>) which returns an Annotation.
  • getAnnotation(CtTypeReference) which returns an CtAnnotation<Annotation>.

@monperrus
Copy link
Collaborator

looks nice!

we have to find a good name for JScanner and add some API documentation.

also, we should add some documentation about this.

@GerardPaligot GerardPaligot changed the title feat(shadow): Build shadow element from class object. WIP feat(shadow): Build shadow element from class object. Apr 7, 2016
* Returns a subtype {@link CtExecutable} that corresponds to the reference
* even if its declaring type isn't in the Spoon source path.
*
* @return the executable declaration correspond to the reference.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: correspond -> that corresponds

@GerardPaligot GerardPaligot changed the title WIP feat(shadow): Build shadow element from class object. feat(shadow): Build shadow element from class object. Apr 19, 2016
*
* @return true if the element is a shadow element, otherwise false.
*/
boolean isShadow();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move to CtShadowable

@monperrus
Copy link
Collaborator

new feature: add documentation page

@GerardPaligot
Copy link
Contributor Author

For me:

Spoon analyzes source code. However, this source code may refer to libraries (as a field, parameter, or method return type). Those library may be or not in the classpath. The boundary between source and libraries is handled by the reference mechanism.

When you're consider a reference object (say, a TypeReference), there are three cases:

  • Case 1: the reference points to a code element for which the source code is present. In this case, reference.getDeclaration() returns this code element (e.g. TypeReference.getDeclaration returns the CtType representing the given java file). reference.getTypeDeclaration() is identical to reference.getDeclaration().
  • Case 2: the reference points to a code element for which the source code is NOT present, but for which the binary class is in the classpath (either the JVM classpath or the --source-classpath argument). In this case, reference.getDeclaration() returns null and reference.getTypeDeclaration returns a partial CtType built using runtime reflection. Those objects built using runtime reflection are called shadow objects; and you can identify them with method isShadow. (This also holds for getFieldDeclaration and getExecutableDeclaration)
  • Case 3: : the reference points to a code element for which the source code is NOT present, but for which the binary class is NOT in the classpath. This is called in Spoon the noclasspath mode. In this case, both reference.getDeclaration() and reference.getTypeDeclaration() return null. (This also holds for getFieldDeclaration and getExecutableDeclaration)

new CtScanner() {
@Override
public void scan(CtElement element) {
if (element != null && element.getClass().isAssignableFrom(CtShadowable.class)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should it be
CtShadowable.class.isAssignableFrom(element.getClass())
?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point.

@monperrus monperrus merged commit b2518c1 into INRIA:master Apr 22, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants