forked from phoedos/pmd
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:
@ -1316,7 +1316,7 @@ void FormalParameter() :
|
||||
{
|
||||
( "final" {jjtThis.setFinal();} | Annotation() )*
|
||||
Type()
|
||||
[ "..." {checkForBadVariableArgumentsUsage();} ]
|
||||
[ "..." {checkForBadVariableArgumentsUsage();} {jjtThis.setVarargs();} ]
|
||||
VariableDeclaratorId()
|
||||
}
|
||||
|
||||
|
@ -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 +
|
||||
"} ";
|
||||
|
||||
}
|
@ -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);
|
||||
}
|
||||
|
@ -1564,6 +1564,7 @@ jjtn000.setModifiers(modifiers);
|
||||
case ELLIPSIS:
|
||||
jj_consume_token(ELLIPSIS);
|
||||
checkForBadVariableArgumentsUsage();
|
||||
jjtn000.setVarargs();
|
||||
break;
|
||||
default:
|
||||
jj_la1[47] = jj_gen;
|
||||
|
@ -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>
|
||||
|
Reference in New Issue
Block a user