-
-
Notifications
You must be signed in to change notification settings - Fork 349
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
getDeclaration of CtLocalVariable does not find declarations in for loops #868
Comments
Seems reasonable. |
msteinbeck
pushed a commit
to msteinbeck/spoon
that referenced
this issue
Sep 30, 2016
monperrus
pushed a commit
that referenced
this issue
Oct 4, 2016
sjd78
pushed a commit
to sjd78/spoon
that referenced
this issue
Nov 3, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have the following (stripped version) code:
As you can see,
i
is a for loop variable that is referenced multiple times, for example byneu.getEntryAt(i)
. I'm using aCtScanner
to find declarations that are not referenced, also known as unused code. Nevertheless, if my visitor visits any variable reference referencingi
,getDeclaration()
is not able toi's
declaration. The reason for this error is obvious, CtLocalVariableReferenceImpl traverses all parent blocks one after another and checks whether a statement of the current examined block is a CtLocalVariable and, if true, whether the variable is the one we are looking for. In case of a CtForLoop (let's call itloop
), this code is missingloop
's declarations (i
in our example). One solution to fix this error is to check whether a statement is a for loop (or any other statements allowing to declare variables in a new scope-lambdas maybe). However, you may have a better idea that is less brittle.The text was updated successfully, but these errors were encountered: