Merge branch 'pr-225'
This commit is contained in:
@ -387,6 +387,15 @@ public class ClassScope extends AbstractJavaScope {
|
||||
return qualified;
|
||||
}
|
||||
|
||||
// Is it an inner class of an explicit import?
|
||||
int dotIndex = typeImage.indexOf('.');
|
||||
if (dotIndex != -1) {
|
||||
qualified = findQualifiedName(typeImage.substring(0, dotIndex), fileScope.getExplicitImports());
|
||||
if (qualified != null) {
|
||||
return qualified.concat(typeImage.substring(dotIndex));
|
||||
}
|
||||
}
|
||||
|
||||
return typeImage;
|
||||
}
|
||||
|
||||
|
@ -471,6 +471,18 @@ public class TypeSet {
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean couldResolve(String name) {
|
||||
/*
|
||||
* We can always try!
|
||||
* If a file used an explicit import on A.Inner, the class loader will register
|
||||
* A.Inner can't be resolved even if A$Inner can.
|
||||
* If a second file used A.Inner without an explicit import, we would end here,
|
||||
* super.couldResolve("A.Inner") will return false, but we CAN resolve it as A$Inner.
|
||||
*/
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public void setASTCompilationUnitPackage(String pkg) {
|
||||
|
@ -162,6 +162,14 @@ public class ClassScopeTest extends STBBaseTst {
|
||||
assertEquals("(String,String...)", mnd.getParameterDisplaySignature());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNestedClassesOfImportResolution() {
|
||||
parseCode(NESTED_CLASSES_OF_IMPORT);
|
||||
final ASTClassOrInterfaceDeclaration n = acu.findDescendantsOfType(ASTClassOrInterfaceDeclaration.class).get(0);
|
||||
final ClassScope c = (ClassScope) n.getScope();
|
||||
assertEquals(EnumTest.class, c.resolveType("TheInnerClass.EnumTest"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNestedClassesResolution() {
|
||||
parseForClass(InnerClass.class);
|
||||
@ -350,4 +358,10 @@ public class ClassScopeTest extends STBBaseTst {
|
||||
+ "public class Foo {" + PMD.EOL
|
||||
+ " public EnumTest e;" + PMD.EOL
|
||||
+ "}" + PMD.EOL;
|
||||
|
||||
private static final String NESTED_CLASSES_OF_IMPORT =
|
||||
"import net.sourceforge.pmd.lang.java.symboltable.testdata.InnerClass.TheInnerClass;" + PMD.EOL
|
||||
+ "public class Foo {" + PMD.EOL
|
||||
+ " public TheInnerClass.EnumTest e;" + PMD.EOL
|
||||
+ "}" + PMD.EOL;
|
||||
}
|
||||
|
Reference in New Issue
Block a user