Added getParameterMap
This commit is contained in:
@ -5,6 +5,9 @@
|
||||
|
||||
package net.sourceforge.pmd.lang.java.ast;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class ASTConstructorDeclaration extends AbstractJavaAccessNode implements ASTMethodOrConstructorDeclaration {
|
||||
|
||||
private boolean containsComment;
|
||||
@ -49,4 +52,18 @@ public class ASTConstructorDeclaration extends AbstractJavaAccessNode implements
|
||||
}
|
||||
return qualifiedName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getParameterMap() {
|
||||
Map<String, String> result = new LinkedHashMap<>();
|
||||
ASTFormalParameters params = getFirstDescendantOfType(ASTFormalParameters.class);
|
||||
|
||||
for (int i = 0; i < params.getParameterCount(); i++) {
|
||||
// append type image of param
|
||||
String typeImage = params.jjtGetChild(i).getFirstChildOfType(ASTType.class).getTypeImage();
|
||||
String paramName = params.jjtGetChild(i).jjtGetChild(1).getImage();
|
||||
result.put(paramName, typeImage);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,9 @@
|
||||
|
||||
package net.sourceforge.pmd.lang.java.ast;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import net.sourceforge.pmd.lang.ast.Node;
|
||||
import net.sourceforge.pmd.lang.dfa.DFAGraphMethod;
|
||||
|
||||
@ -41,6 +44,20 @@ public class ASTMethodDeclaration extends AbstractJavaAccessNode implements DFAG
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getParameterMap() {
|
||||
Map<String, String> result = new LinkedHashMap<>();
|
||||
ASTFormalParameters params = getFirstDescendantOfType(ASTFormalParameters.class);
|
||||
|
||||
for (int i = 0; i < params.getParameterCount(); i++) {
|
||||
// append type image of param
|
||||
String typeImage = params.jjtGetChild(i).getFirstChildOfType(ASTType.class).getTypeImage();
|
||||
String paramName = params.jjtGetChild(i).jjtGetChild(1).getImage();
|
||||
result.put(paramName, typeImage);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return getMethodName();
|
||||
}
|
||||
|
@ -4,6 +4,8 @@
|
||||
|
||||
package net.sourceforge.pmd.lang.java.ast;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import net.sourceforge.pmd.lang.ast.Node;
|
||||
|
||||
/**
|
||||
@ -11,4 +13,14 @@ import net.sourceforge.pmd.lang.ast.Node;
|
||||
*/
|
||||
public interface ASTMethodOrConstructorDeclaration extends QualifiableNode, Node, AccessNode, JavaNode {
|
||||
|
||||
/**
|
||||
* Returns a map of parameter names to their type image. Iterating over its keys yields the parameters in the
|
||||
* right order.
|
||||
*
|
||||
* @return A map of parameter names to their type image.
|
||||
*/
|
||||
Map<String, String> getParameterMap();
|
||||
|
||||
// TODO could use a default implementation when we change the compiler version to 1.8
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user