From d8344b067202c648e624bcff4c72161aa22ecf04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Mart=C3=ADn=20Sotuyo=20Dodero?= Date: Thu, 13 Oct 2016 17:47:27 -0300 Subject: [PATCH] Simplify varargs detection - Make use of our Java knowledge when analyzing Java code --- .../lang/java/symboltable/MethodNameDeclaration.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/symboltable/MethodNameDeclaration.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/symboltable/MethodNameDeclaration.java index 2561bad214..b1d0a6e1c1 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/symboltable/MethodNameDeclaration.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/symboltable/MethodNameDeclaration.java @@ -22,13 +22,13 @@ public class MethodNameDeclaration extends AbstractNameDeclaration { public boolean isVarargs() { ASTFormalParameters params = (ASTFormalParameters) node.jjtGetChild(0); - for (int i = 0; i < ((ASTMethodDeclarator) node).getParameterCount(); i++) { - ASTFormalParameter p = (ASTFormalParameter) params.jjtGetChild(i); - if (p.isVarargs()) { - return true; - } + if (params.getParameterCount() == 0) { + return false; } - return false; + + // If it's a varargs, it HAS to be the last parameter + ASTFormalParameter p = (ASTFormalParameter) params.jjtGetChild(params.getParameterCount() - 1); + return p.isVarargs(); } public ASTMethodDeclarator getMethodNameDeclaratorNode() {