forked from phoedos/pmd
Fix NullPointerException in ClassScope.resolveGenericType()
This commit is contained in:
@ -502,8 +502,11 @@ public class ClassScope extends AbstractJavaScope {
|
||||
private Class<?> resolveGenericType(Node argument, String typeImage) {
|
||||
List<ASTTypeParameter> types = new ArrayList<ASTTypeParameter>();
|
||||
// first search only within the same method
|
||||
types.addAll(argument.getFirstParentOfType(ASTClassOrInterfaceBodyDeclaration.class).findDescendantsOfType(
|
||||
ASTTypeParameter.class));
|
||||
ASTClassOrInterfaceBodyDeclaration firstParentOfType =
|
||||
argument.getFirstParentOfType(ASTClassOrInterfaceBodyDeclaration.class);
|
||||
if (firstParentOfType != null) {
|
||||
types.addAll(firstParentOfType.findDescendantsOfType(ASTTypeParameter.class));
|
||||
}
|
||||
|
||||
// then search class level types
|
||||
ASTClassOrInterfaceDeclaration enclosingClassOrEnum = argument
|
||||
|
@ -34,6 +34,11 @@ public class ClassScopeTest extends STBBaseTst {
|
||||
parseCode15(ENUM_SCOPE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEnumTypeParameter() {
|
||||
parseCode15(ENUM_TYPE_PARAMETER);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVarArgsEmpty() {
|
||||
parseCode15(
|
||||
@ -387,6 +392,15 @@ public class ClassScopeTest extends STBBaseTst {
|
||||
" public abstract String getFilterableString(TreeNode node);" + PMD.EOL +
|
||||
"}";
|
||||
|
||||
private static final String ENUM_TYPE_PARAMETER =
|
||||
"public enum Foo {" + PMD.EOL +
|
||||
" BAR(isCustomer(BazEnum.FOO_BAR));" + PMD.EOL +
|
||||
" Foo(boolean isCustomer) { }" + PMD.EOL +
|
||||
" private static boolean isCustomer(BazEnum baz) {" + PMD.EOL +
|
||||
" return false;" + PMD.EOL +
|
||||
" }" + PMD.EOL +
|
||||
"}";
|
||||
|
||||
public static junit.framework.Test suite() {
|
||||
return new junit.framework.JUnit4TestAdapter(ClassScopeTest.class);
|
||||
}
|
||||
|
Reference in New Issue
Block a user