do not add slot variable names that declared after the current position

This commit is contained in:
Egor.Ushakov
2015-10-02 13:10:35 +03:00
parent 197110ff95
commit 4bd01a1dcf
@@ -309,22 +309,36 @@ public class LocalVariablesUtil {
private int myCurrentSlotIndex;
private final PsiElement myElement;
private final Stack<Integer> myIndexStack;
private boolean myReached = false;
public LocalVariableNameFinder(int startSlot, MultiMap<Integer, String> names, PsiElement element) {
myNames = names;
myCurrentSlotIndex = startSlot;
myElement = element;
myIndexStack = new Stack<Integer>();
}
private boolean shouldVisit(PsiElement scope) {
return PsiTreeUtil.isContextAncestor(scope, myElement, false);
return !myReached && PsiTreeUtil.isContextAncestor(scope, myElement, false);
}
@Override
public void visitElement(PsiElement element) {
if (element == myElement) {
myReached = true;
}
else {
super.visitElement(element);
}
}
@Override
public void visitLocalVariable(PsiLocalVariable variable) {
appendName(variable.getName());
myCurrentSlotIndex += getTypeSlotSize(variable.getType());
if (!myReached) {
appendName(variable.getName());
myCurrentSlotIndex += getTypeSlotSize(variable.getType());
}
}
public void visitSynchronizedStatement(PsiSynchronizedStatement statement) {