#1332 False Positive: UnusedPrivateMethod
This commit is contained in:
@ -4,8 +4,10 @@
|
||||
package net.sourceforge.pmd.lang.java.symboltable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import net.sourceforge.pmd.lang.ast.Node;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTAllocationExpression;
|
||||
@ -310,19 +312,20 @@ public class ClassScope extends AbstractJavaScope {
|
||||
if (typeImage == null) {
|
||||
return null;
|
||||
}
|
||||
for (String qualified : this.getEnclosingScope(SourceFileScope.class).getQualifiedTypeNames().keySet()) {
|
||||
|
||||
Set<String> qualifiedNames = new LinkedHashSet<String>();
|
||||
qualifiedNames.addAll(this.getEnclosingScope(SourceFileScope.class).getQualifiedTypeNames().keySet());
|
||||
qualifiedNames.addAll(this.getEnclosingScope(SourceFileScope.class).getExplicitImports());
|
||||
|
||||
int nameLength = typeImage.length();
|
||||
|
||||
for (String qualified : qualifiedNames) {
|
||||
int fullLength = qualified.length();
|
||||
int nameLength = typeImage.length();
|
||||
if (qualified.endsWith(typeImage)
|
||||
&& (fullLength == nameLength || qualified.substring(0, fullLength - nameLength).endsWith("."))) {
|
||||
return qualified;
|
||||
}
|
||||
}
|
||||
for (String qualified : this.getEnclosingScope(SourceFileScope.class).getExplicitImports()) {
|
||||
if (qualified.endsWith(typeImage)) {
|
||||
return qualified;
|
||||
}
|
||||
}
|
||||
return typeImage;
|
||||
}
|
||||
|
||||
|
@ -1412,4 +1412,38 @@ public class UnusedPrivateMethod {
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
||||
<test-code>
|
||||
<description>#1332 False Positive: UnusedPrivateMethod</description>
|
||||
<expected-problems>0</expected-problems>
|
||||
<code><![CDATA[
|
||||
package com.acme;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.containsString;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
public class FooTest {
|
||||
|
||||
@Test
|
||||
public void testBar() {
|
||||
assertThat(createBar("", ""), containsString(""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFoo() {
|
||||
assertThat(createFoo(""), containsString(""));
|
||||
}
|
||||
|
||||
private String createFoo(String a) {
|
||||
return a;
|
||||
}
|
||||
|
||||
private String createBar(String b, String c) {
|
||||
return b + c;
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
</test-data>
|
||||
|
Reference in New Issue
Block a user