Merge branch 'pr-128' into pmd/5.5.x

This commit is contained in:
Andreas Dangel
2016-11-26 11:10:13 +01:00
2 changed files with 11 additions and 10 deletions

View File

@ -9,6 +9,7 @@ import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
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;
public ClassScope(String className) {
this.className = className;
public ClassScope(final String className) {
this.className = Objects.requireNonNull(className);
anonymousInnerClassCounter.set(Integer.valueOf(1));
}
@ -152,10 +153,9 @@ public class ClassScope extends AbstractJavaScope {
}
protected Set<NameDeclaration> findVariableHere(JavaNameOccurrence occurrence) {
Set<NameDeclaration> result = new HashSet<>();
Map<MethodNameDeclaration, List<NameOccurrence>> methodDeclarations = getMethodDeclarations();
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()) {
// this could happen if you do this:
// 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
// and then we'll look up X.
if (!variableDeclarations.isEmpty()) {
result.add(variableDeclarations.keySet().iterator().next());
return result;
return Collections.<NameDeclaration>singleton(variableDeclarations.keySet().iterator().next());
}
result.add(methodDeclarations.keySet().iterator().next());
return result;
return Collections.<NameDeclaration>singleton(methodDeclarations.keySet().iterator().next());
}
Set<NameDeclaration> result = new HashSet<>();
if (occurrence.isMethodOrConstructorInvocation()) {
for (MethodNameDeclaration mnd : methodDeclarations.keySet()) {
if (mnd.getImage().equals(occurrence.getImage())) {
@ -414,8 +413,9 @@ public class ClassScope extends AbstractJavaScope {
if (child instanceof ASTName && !isMethodCall) {
ASTName name = (ASTName) child;
Scope s = name.getScope();
final JavaNameOccurrence nameOccurrence = new JavaNameOccurrence(name, name.getImage());
while (s != null) {
if (s.contains(new JavaNameOccurrence(name, name.getImage()))) {
if (s.contains(nameOccurrence)) {
break;
}
s = s.getParent();

View File

@ -28,6 +28,7 @@
* [#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
* [#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
* [#135](https://github.com/pmd/pmd/pull/135): \[apex] New ruleset for Apex security