forked from phoedos/pmd
Fix for 2904832. ClassTypeResolver was clobbering the importedClasses in populateImports set by populateClassName. Changed to clobber at ASTCompilationUnit, then everyone adds to the map.
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/branches/pmd/4.2.x@7005 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
parent
aaeaefad1a
commit
d836721675
@ -8,6 +8,7 @@ Fixed bug 2645268 - ClassCastException in UselessOperationOnImmutable.getDeclara
|
||||
Fixed bug 2724653 - AvoidThreadGroup reports false positives
|
||||
Fixed bug 2835074 - False -: DoubleCheckedLocking with reversed null check
|
||||
Fixed bug 2826119 - False +: DoubleCheckedLocking warning with volatile field
|
||||
Fixed bug 2904832 - Type resolution not working for ASTType when using an inner class
|
||||
|
||||
Correct -benchmark reporting of Rule visits via the RuleChain
|
||||
Fix issue with Type Resolution incorrectly handling of Classes with same name as a java.lang Class.
|
||||
|
@ -16,6 +16,7 @@ import net.sourceforge.pmd.ast.ASTClassOrInterfaceType;
|
||||
import net.sourceforge.pmd.ast.ASTCompilationUnit;
|
||||
import net.sourceforge.pmd.ast.ASTExpression;
|
||||
import net.sourceforge.pmd.ast.ASTFieldDeclaration;
|
||||
import net.sourceforge.pmd.ast.ASTFormalParameter;
|
||||
import net.sourceforge.pmd.ast.ASTImportDeclaration;
|
||||
import net.sourceforge.pmd.ast.ASTLiteral;
|
||||
import net.sourceforge.pmd.ast.ASTNullLiteral;
|
||||
@ -98,11 +99,6 @@ public class ClassTypeResolverTest {
|
||||
|
||||
@Test
|
||||
public void testInnerClass() throws ClassNotFoundException {
|
||||
if (TestDescriptor.inRegressionTestMode()) {
|
||||
// skip this test if we're only running regression tests
|
||||
return;
|
||||
}
|
||||
|
||||
ASTCompilationUnit acu = parseAndTypeResolveForClass(InnerClass.class);
|
||||
Class<?> theInnerClass = Class.forName("test.net.sourceforge.pmd.typeresolution.testdata.InnerClass$TheInnerClass");
|
||||
// Outer class
|
||||
@ -113,6 +109,9 @@ public class ClassTypeResolverTest {
|
||||
// Inner class
|
||||
assertEquals(theInnerClass,
|
||||
outerClassDeclaration.getFirstChildOfType(ASTClassOrInterfaceDeclaration.class).getType());
|
||||
// Method parameter as inner class
|
||||
ASTFormalParameter formalParameter = typeDeclaration.getFirstChildOfType(ASTFormalParameter.class);
|
||||
assertEquals(theInnerClass, formalParameter.getTypeNode().getType());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -3,4 +3,7 @@ package test.net.sourceforge.pmd.typeresolution.testdata;
|
||||
public class InnerClass {
|
||||
public class TheInnerClass {
|
||||
}
|
||||
|
||||
public void foo(TheInnerClass arg) {
|
||||
}
|
||||
}
|
||||
|
@ -141,6 +141,7 @@ public class ClassTypeResolver extends JavaParserVisitorAdapter {
|
||||
String className = null;
|
||||
try {
|
||||
importedOnDemand = new ArrayList<String>();
|
||||
importedClasses = new HashMap<String, String>();
|
||||
className = getClassName(node);
|
||||
if (className != null) {
|
||||
populateClassName(node, className);
|
||||
@ -642,8 +643,6 @@ public class ClassTypeResolver extends JavaParserVisitorAdapter {
|
||||
*/
|
||||
private void populateImports(ASTCompilationUnit node) {
|
||||
List<ASTImportDeclaration> theImportDeclarations = node.findChildrenOfType(ASTImportDeclaration.class);
|
||||
importedClasses = new HashMap<String, String>();
|
||||
|
||||
importedClasses.putAll(myJavaLang);
|
||||
|
||||
// go through the imports
|
||||
@ -661,7 +660,7 @@ public class ClassTypeResolver extends JavaParserVisitorAdapter {
|
||||
|
||||
private void populateClassName(ASTCompilationUnit node, String className) throws ClassNotFoundException {
|
||||
node.setType(pmdClassLoader.loadClass(className));
|
||||
importedClasses = pmdClassLoader.getImportedClasses(className);
|
||||
importedClasses.putAll(pmdClassLoader.getImportedClasses(className));
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user