Merge branch 'pr-128' into pmd/5.5.x
This commit is contained in:
@ -9,6 +9,7 @@ import java.util.HashSet;
|
|||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import net.sourceforge.pmd.lang.ast.Node;
|
import net.sourceforge.pmd.lang.ast.Node;
|
||||||
@ -66,12 +67,12 @@ public class ClassScope extends AbstractJavaScope {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private String className;
|
private final String className;
|
||||||
|
|
||||||
private boolean isEnum;
|
private boolean isEnum;
|
||||||
|
|
||||||
public ClassScope(String className) {
|
public ClassScope(final String className) {
|
||||||
this.className = className;
|
this.className = Objects.requireNonNull(className);
|
||||||
anonymousInnerClassCounter.set(Integer.valueOf(1));
|
anonymousInnerClassCounter.set(Integer.valueOf(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -152,10 +153,9 @@ public class ClassScope extends AbstractJavaScope {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected Set<NameDeclaration> findVariableHere(JavaNameOccurrence occurrence) {
|
protected Set<NameDeclaration> findVariableHere(JavaNameOccurrence occurrence) {
|
||||||
Set<NameDeclaration> result = new HashSet<>();
|
|
||||||
Map<MethodNameDeclaration, List<NameOccurrence>> methodDeclarations = getMethodDeclarations();
|
Map<MethodNameDeclaration, List<NameOccurrence>> methodDeclarations = getMethodDeclarations();
|
||||||
Map<VariableNameDeclaration, List<NameOccurrence>> variableDeclarations = getVariableDeclarations();
|
Map<VariableNameDeclaration, List<NameOccurrence>> variableDeclarations = getVariableDeclarations();
|
||||||
if (occurrence.isThisOrSuper() || occurrence.getImage() != null && occurrence.getImage().equals(className)) {
|
if (occurrence.isThisOrSuper() || className.equals(occurrence.getImage())) {
|
||||||
if (variableDeclarations.isEmpty() && methodDeclarations.isEmpty()) {
|
if (variableDeclarations.isEmpty() && methodDeclarations.isEmpty()) {
|
||||||
// this could happen if you do this:
|
// this could happen if you do this:
|
||||||
// public class Foo {
|
// public class Foo {
|
||||||
@ -173,13 +173,12 @@ public class ClassScope extends AbstractJavaScope {
|
|||||||
// we'll look up Foo just to get a handle to the class scope
|
// we'll look up Foo just to get a handle to the class scope
|
||||||
// and then we'll look up X.
|
// and then we'll look up X.
|
||||||
if (!variableDeclarations.isEmpty()) {
|
if (!variableDeclarations.isEmpty()) {
|
||||||
result.add(variableDeclarations.keySet().iterator().next());
|
return Collections.<NameDeclaration>singleton(variableDeclarations.keySet().iterator().next());
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
result.add(methodDeclarations.keySet().iterator().next());
|
return Collections.<NameDeclaration>singleton(methodDeclarations.keySet().iterator().next());
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Set<NameDeclaration> result = new HashSet<>();
|
||||||
if (occurrence.isMethodOrConstructorInvocation()) {
|
if (occurrence.isMethodOrConstructorInvocation()) {
|
||||||
for (MethodNameDeclaration mnd : methodDeclarations.keySet()) {
|
for (MethodNameDeclaration mnd : methodDeclarations.keySet()) {
|
||||||
if (mnd.getImage().equals(occurrence.getImage())) {
|
if (mnd.getImage().equals(occurrence.getImage())) {
|
||||||
@ -414,8 +413,9 @@ public class ClassScope extends AbstractJavaScope {
|
|||||||
if (child instanceof ASTName && !isMethodCall) {
|
if (child instanceof ASTName && !isMethodCall) {
|
||||||
ASTName name = (ASTName) child;
|
ASTName name = (ASTName) child;
|
||||||
Scope s = name.getScope();
|
Scope s = name.getScope();
|
||||||
|
final JavaNameOccurrence nameOccurrence = new JavaNameOccurrence(name, name.getImage());
|
||||||
while (s != null) {
|
while (s != null) {
|
||||||
if (s.contains(new JavaNameOccurrence(name, name.getImage()))) {
|
if (s.contains(nameOccurrence)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
s = s.getParent();
|
s = s.getParent();
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
* [#124](https://github.com/pmd/pmd/pull/124): \[java] CPD: Properly handle enums with `-ignore-identifiers`
|
* [#124](https://github.com/pmd/pmd/pull/124): \[java] CPD: Properly handle enums with `-ignore-identifiers`
|
||||||
* [#126](https://github.com/pmd/pmd/pull/126): \[java] Avoid creating a new String to qualify types
|
* [#126](https://github.com/pmd/pmd/pull/126): \[java] Avoid creating a new String to qualify types
|
||||||
* [#127](https://github.com/pmd/pmd/pull/127): \[java] Don't look twice for the same variables
|
* [#127](https://github.com/pmd/pmd/pull/127): \[java] Don't look twice for the same variables
|
||||||
|
* [#128](https://github.com/pmd/pmd/pull/128): \[java] Minor optimizations to type resolution
|
||||||
* [#129](https://github.com/pmd/pmd/pull/129): \[plsql] Added correct parse of IS [NOT] NULL and multiline DML
|
* [#129](https://github.com/pmd/pmd/pull/129): \[plsql] Added correct parse of IS [NOT] NULL and multiline DML
|
||||||
* [#135](https://github.com/pmd/pmd/pull/135): \[apex] New ruleset for Apex security
|
* [#135](https://github.com/pmd/pmd/pull/135): \[apex] New ruleset for Apex security
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user