Added isVarargs() to ASTFormalParameter

git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@4795 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
Tom Copeland
2006-11-15 16:12:09 +00:00
parent 1a599ac62c
commit 6b14992df7
5 changed files with 44 additions and 1 deletions

View File

@ -1316,7 +1316,7 @@ void FormalParameter() :
{
( "final" {jjtThis.setFinal();} | Annotation() )*
Type()
[ "..." {checkForBadVariableArgumentsUsage();} ]
[ "..." {checkForBadVariableArgumentsUsage();} {jjtThis.setVarargs();} ]
VariableDeclaratorId()
}

View File

@ -0,0 +1,29 @@
package test.net.sourceforge.pmd.ast;
import net.sourceforge.pmd.PMD;
import net.sourceforge.pmd.TargetJDK1_4;
import net.sourceforge.pmd.TargetJDK1_5;
import net.sourceforge.pmd.ast.ASTBooleanLiteral;
import net.sourceforge.pmd.ast.ASTFormalParameter;
import test.net.sourceforge.pmd.testframework.ParserTst;
import java.util.Set;
public class ASTFormalParameterTest extends ParserTst {
public void testVarargs() throws Throwable {
Set ops = getNodes(new TargetJDK1_5(), ASTFormalParameter.class, TEST1);
ASTFormalParameter b = (ASTFormalParameter) ops.iterator().next();
if (!"x".equals(b.getImage())) {
assertTrue(b.isVarargs());
} else {
assertFalse(b.isVarargs());
}
}
private static final String TEST1 =
"class Foo { " + PMD.EOL +
" void bar(int x, int... others) {} " + PMD.EOL +
"} ";
}

View File

@ -5,6 +5,18 @@ package net.sourceforge.pmd.ast;
import net.sourceforge.pmd.Rule;
public class ASTFormalParameter extends AccessNode implements Dimensionable, CanSuppressWarnings {
private boolean isVarargs;
public void setVarargs() {
isVarargs = true;
}
public boolean isVarargs() {
return isVarargs;
}
public ASTFormalParameter(int id) {
super(id);
}

View File

@ -1564,6 +1564,7 @@ jjtn000.setModifiers(modifiers);
case ELLIPSIS:
jj_consume_token(ELLIPSIS);
checkForBadVariableArgumentsUsage();
jjtn000.setVarargs();
break;
default:
jj_la1[47] = jj_gen;

View File

@ -52,6 +52,7 @@
</subsection>
<subsection name="Contributors">
<ul>
<li>classens - Noted missing varargs setting in ASTFormalParameter</li>
<li>piair - Implemented StringBufferInstantiationWithChar, AvoidUsingOctalValues</li>
<li>Christopher Eagan - Reported bug in VariableNamingConventions</li>
<li>Jason Bennett - Noticed useless line in XSLT scripts, fix for UnnecessaryLocalBeforeReturn, wrote NPathComplexity rule, patches to improve CyclomaticComplexity rule, Implemented: UseCollectionIsEmpty, NcssTypeCount, NcssMethodCount, NcssConstructor</li>