Skip to content

Commit

Permalink
fix LocalVariableScopeFunction - loops, tryWithResource
Browse files Browse the repository at this point in the history
  • Loading branch information
pvojtechovsky committed Jan 30, 2017
1 parent 439f251 commit b07c20e
Showing 1 changed file with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@
import java.util.List;

import spoon.SpoonException;
import spoon.reflect.code.CtBodyHolder;
import spoon.reflect.code.CtLocalVariable;
import spoon.reflect.code.CtStatement;
import spoon.reflect.code.CtStatementList;
import spoon.reflect.declaration.CtElement;
import spoon.reflect.visitor.Filter;
import spoon.reflect.visitor.chain.CtConsumableFunction;
import spoon.reflect.visitor.chain.CtConsumer;
import spoon.reflect.visitor.chain.CtQuery;
Expand Down Expand Up @@ -50,7 +53,19 @@ public LocalVariableScopeFunction() {

@Override
public void apply(CtLocalVariable<?> localVariable, CtConsumer<Object> outputConsumer) {
CtStatementList statements = localVariable.getParent(CtStatementList.class);
CtStatementList statements = localVariable.map(new ParentFunction()).select(new Filter(){
@Override
public boolean matches(CtElement element) {
if(element instanceof CtStatementList) {
return true;
}
if(element instanceof CtBodyHolder) {
//match loops, try, catch, CtTryWithResource
return true;
}
return false;
}
}).first();
if (statements == null) {
//cannot search for variable references of variable which has no parent statement list/block
return;
Expand Down

0 comments on commit b07c20e

Please sign in to comment.