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

ctVisitTypeReference() doesn't visit RHS instanceof occurrences #349

Closed
leventov opened this issue Sep 28, 2015 · 6 comments
Closed

ctVisitTypeReference() doesn't visit RHS instanceof occurrences #349

leventov opened this issue Sep 28, 2015 · 6 comments

Comments

@leventov
Copy link
Contributor

The fix I came up with is

--- a/src/main/java/spoon/reflect/visitor/CtScanner.java
+++ b/src/main/java/spoon/reflect/visitor/CtScanner.java
@@ -466,6 +466,9 @@ public abstract class CtScanner implements CtVisitor {
                scan(literal.getAnnotations());
                scan(literal.getType());
                scanReferences(literal.getTypeCasts());
+               T value = literal.getValue();
+               if (value instanceof CtReference)
+                       scan((CtReference) value);
                exit(literal);
        }

But I'm not sure this is the "right" way.

@GerardPaligot
Copy link
Contributor

I don't understand this issue. What is the link between CtTypeReference, CtRHSReceiver and CtLiteral?

@leventov
Copy link
Contributor Author

Sorry I was not precise.

If I try to scan all references, by calling ctElement.getElements((CtTypeReference<?> ref) -> ...) it doesn't visit references on RHS of isntanceof.

I proposed a possible fix in the issue body. But since from JLS perspective there are no such term as "type literal", probably "right" solution would be create a special class of expression for instanceof, say CtInstanceof

@leventov
Copy link
Contributor Author

leventov commented Oct 9, 2015

@monperrus monperrus changed the title ctVisitTypeReference() doesn't visit RHS instanceof occurances ctVisitTypeReference() doesn't visit RHS instanceof occurrences Oct 12, 2015
@GerardPaligot
Copy link
Contributor

The real question here is: why the right hand operand is a CtLiteral and not directly a CtTypeReference? ...

@monperrus Any idea? That sounds good for you to change the right hand operand from CtLiteral to CtTypeReference?

@leventov
Copy link
Contributor Author

@GerardPaligot I think because instanceof is CtBinaryOperator, which has two CtExpressions, the right one should represent a type, but couldn't be just CtTypeReference (because CtTypeReference is not a CtExpression).

JLS classify isntanceof as binary operation, but it special case the type on instanceof's RHS: it is not a literal, or expression

@GerardPaligot
Copy link
Contributor

@GerardPaligot I think because instanceof is CtBinaryOperator, which has two CtExpressions, the right one should represent a type, but couldn't be just CtTypeReference (because CtTypeReference is not a CtExpression).

This is exactly what I want changed! Deprecate the right hand operand expression and create a new one (typed by CtTypeReference).

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

No branches or pull requests

3 participants