Also keep lambdas in a single scope
This commit is contained in:
@@ -24,6 +24,7 @@ public class LocalScope extends AbstractJavaScope {
|
||||
return getDeclarations(VariableNameDeclaration.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<NameDeclaration> addNameOccurrence(NameOccurrence occurrence) {
|
||||
JavaNameOccurrence javaOccurrence = (JavaNameOccurrence) occurrence;
|
||||
Set<NameDeclaration> declarations = findVariableHere(javaOccurrence);
|
||||
@@ -40,6 +41,7 @@ public class LocalScope extends AbstractJavaScope {
|
||||
return declarations;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addDeclaration(NameDeclaration nameDecl) {
|
||||
if (!(nameDecl instanceof VariableNameDeclaration || nameDecl instanceof ClassNameDeclaration)) {
|
||||
throw new IllegalArgumentException(
|
||||
@@ -49,6 +51,7 @@ public class LocalScope extends AbstractJavaScope {
|
||||
super.addDeclaration(nameDecl);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<NameDeclaration> findVariableHere(JavaNameOccurrence occurrence) {
|
||||
if (occurrence.isThisOrSuper() || occurrence.isMethodOrConstructorInvocation()) {
|
||||
return Collections.emptySet();
|
||||
@@ -61,6 +64,7 @@ public class LocalScope extends AbstractJavaScope {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "LocalScope:" + glomNames(getVariableDeclarations().keySet());
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ public class MethodScope extends AbstractJavaScope {
|
||||
return getDeclarations(VariableNameDeclaration.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<NameDeclaration> addNameOccurrence(NameOccurrence occurrence) {
|
||||
JavaNameOccurrence javaOccurrence = (JavaNameOccurrence) occurrence;
|
||||
Set<NameDeclaration> declarations = findVariableHere(javaOccurrence);
|
||||
@@ -47,6 +48,7 @@ public class MethodScope extends AbstractJavaScope {
|
||||
return declarations;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addDeclaration(NameDeclaration variableDecl) {
|
||||
if (!(variableDecl instanceof VariableNameDeclaration || variableDecl instanceof ClassNameDeclaration)) {
|
||||
throw new IllegalArgumentException(
|
||||
@@ -55,6 +57,7 @@ public class MethodScope extends AbstractJavaScope {
|
||||
super.addDeclaration(variableDecl);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<NameDeclaration> findVariableHere(JavaNameOccurrence occurrence) {
|
||||
if (occurrence.isThisOrSuper() || occurrence.isMethodOrConstructorInvocation()) {
|
||||
return Collections.emptySet();
|
||||
@@ -74,6 +77,7 @@ public class MethodScope extends AbstractJavaScope {
|
||||
return node.jjtGetChild(1).getImage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "MethodScope:" + glomNames(getVariableDeclarations().keySet());
|
||||
}
|
||||
|
||||
+1
@@ -205,6 +205,7 @@ public class ScopeAndDeclarationFinder extends JavaParserVisitorAdapter {
|
||||
// same applies to catch statements defining exceptions + the catch block, and for-blocks
|
||||
if (node.jjtGetParent() instanceof ASTMethodDeclaration
|
||||
|| node.jjtGetParent() instanceof ASTConstructorDeclaration
|
||||
|| node.jjtGetParent() instanceof ASTLambdaExpression
|
||||
|| node.jjtGetParent() instanceof ASTCatchStatement
|
||||
|| node.jjtGetParent() instanceof ASTForStatement) {
|
||||
super.visit(node, null);
|
||||
|
||||
Reference in New Issue
Block a user