Added workaround to prevent AccessorClassGenerationRule from crashing

git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@2059 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
Tom Copeland
2003-07-01 13:53:43 +00:00
parent e11923a5e8
commit b64dc670ae
3 changed files with 31 additions and 16 deletions

View File

@ -2,6 +2,7 @@
Added new rules: VariableNamingConventionsRule, MethodNamingConventionsRule, ClassNamingConventionsRule
Fixed bug 583047 - ASTName column numbers are now correct
Fixed bug 761048 - Symbol table now creates a scope level for anonymous inner classes
Fixed bug 763529 - AccessorClassGenerationRule no longer crashes when given a final inner class
ASTViewer now shows node images and modifiers
ASTViewer now saves last edited text to ~/.pmd_astviewer
Moved the PMD Swing UI into a separate module - pmd-swingui.

View File

@ -5,6 +5,22 @@ import net.sourceforge.pmd.rules.AccessorClassGenerationRule;
public class AccessorClassGenerationRuleTest extends RuleTst {
public void testInnerClassHasPrivateConstructor() throws Throwable {
runTestFromString(TEST1, 1, new AccessorClassGenerationRule());
}
public void testInnerClassHasPublicConstructor() throws Throwable {
runTestFromString(TEST2, 0, new AccessorClassGenerationRule());
}
public void testOuterClassHasPrivateConstructor() throws Throwable {
runTestFromString(TEST3, 1, new AccessorClassGenerationRule());
}
public void testFinalInnerClass() throws Throwable {
runTestFromString(TEST4, 0, new AccessorClassGenerationRule());
}
private static final String TEST1 =
"public class Foo1 {" + PMD.EOL +
" public class InnerClass {" + PMD.EOL +
@ -38,15 +54,11 @@ public class AccessorClassGenerationRuleTest extends RuleTst {
" }" + PMD.EOL +
"}";
public void testInnerClassHasPrivateConstructor() throws Throwable {
runTestFromString(TEST1, 1, new AccessorClassGenerationRule());
}
public void testInnerClassHasPublicConstructor() throws Throwable {
runTestFromString(TEST2, 0, new AccessorClassGenerationRule());
}
public void testOuterClassHasPrivateConstructor() throws Throwable {
runTestFromString(TEST3, 1, new AccessorClassGenerationRule());
}
private static final String TEST4 =
"public class Foo {" + PMD.EOL +
" void method() {" + PMD.EOL +
" final class Inner {}; " + PMD.EOL +
" Inner i = new Inner();" + PMD.EOL +
" }" + PMD.EOL +
"}";
}

View File

@ -201,7 +201,6 @@ public class AccessorClassGenerationRule extends AbstractRule {
}
private void processRule(RuleContext ctx) {
// try {
//check constructors of outerIterator
//against allocations of innerIterator
for (Iterator outerIterator = classDataList.iterator(); outerIterator.hasNext();) {
@ -227,10 +226,6 @@ public class AccessorClassGenerationRule extends AbstractRule {
}
}
}
// }
// catch(Exception e){
// e.printStackTrace();
// }
}
/**
@ -324,6 +319,13 @@ public class AccessorClassGenerationRule extends AbstractRule {
}
public Object visit(ASTAllocationExpression node, Object data) {
// TODO
// this is a hack to bail out here
// but I'm not sure why this is happening
// TODO
if (classID == -1) {
return data;
}
AllocData ad = new AllocData(node, getPackageName(), getCurrentClassData().getClassQualifyingNamesList());
if (ad.isArray() == false) {
getCurrentClassData().addInstantiation(ad);