use of net.sourceforge.pmd.lang.java.ast.ASTFormalParameter in project pmd by pmd.
the class MethodArgumentCouldBeFinalRule method lookForViolation.
private void lookForViolation(Scope scope, Object data) {
Map<VariableNameDeclaration, List<NameOccurrence>> decls = scope.getDeclarations(VariableNameDeclaration.class);
for (Map.Entry<VariableNameDeclaration, List<NameOccurrence>> entry : decls.entrySet()) {
VariableNameDeclaration var = entry.getKey();
AccessNode node = var.getAccessNodeParent();
if (!node.isFinal() && node instanceof ASTFormalParameter && !assigned(entry.getValue())) {
addViolation(data, node, var.getImage());
}
}
}
use of net.sourceforge.pmd.lang.java.ast.ASTFormalParameter in project pmd-eclipse-plugin by pmd.
the class ASTUtil method parameterTypes.
public static String parameterTypes(ASTMethodDeclaration node) {
StringBuilder sb = new StringBuilder();
for (int ix = 0; ix < node.jjtGetNumChildren(); ix++) {
Node sn = node.jjtGetChild(ix);
if (sn instanceof ASTMethodDeclarator) {
List<ASTFormalParameter> allParams = ((ASTMethodDeclarator) sn).findDescendantsOfType(ASTFormalParameter.class);
for (ASTFormalParameter formalParam : allParams) {
AbstractNode param = formalParam.getFirstDescendantOfType(ASTClassOrInterfaceType.class);
if (param == null) {
param = formalParam.getFirstDescendantOfType(ASTPrimitiveType.class);
}
if (param == null) {
continue;
}
sb.append(param.getImage()).append(", ");
}
}
}
int length = sb.length();
return length == 0 ? "" : sb.toString().substring(0, length - 2);
}
use of net.sourceforge.pmd.lang.java.ast.ASTFormalParameter in project pmd by pmd.
the class QualifiedNameResolver method getOperationName.
/**
* Returns a normalized method name (not Java-canonical!).
*/
private static String getOperationName(String methodName, ASTFormalParameters params) {
StringBuilder sb = new StringBuilder();
sb.append(methodName);
sb.append('(');
boolean first = true;
for (ASTFormalParameter param : params) {
if (!first) {
sb.append(", ");
}
first = false;
sb.append(param.getTypeNode().getTypeImage());
if (param.isVarargs()) {
sb.append("...");
}
}
sb.append(')');
return sb.toString();
}
use of net.sourceforge.pmd.lang.java.ast.ASTFormalParameter in project pmd by pmd.
the class ArrayIsStoredDirectlyRule method visit.
@Override
public Object visit(ASTMethodDeclaration node, Object data) {
final ASTFormalParameters params = node.getFirstDescendantOfType(ASTFormalParameters.class);
ASTFormalParameter[] arrs = getArrays(params);
checkAll(data, arrs, node.findDescendantsOfType(ASTBlockStatement.class));
return data;
}
use of net.sourceforge.pmd.lang.java.ast.ASTFormalParameter in project pmd by pmd.
the class MethodNameDeclaration method hashCode.
@Override
public int hashCode() {
int hash = node.getImage().hashCode() * 31 + ((ASTMethodDeclarator) node).getParameterCount();
ASTFormalParameters myParams = (ASTFormalParameters) node.jjtGetChild(0);
for (int i = 0; i < ((ASTMethodDeclarator) node).getParameterCount(); i++) {
ASTFormalParameter myParam = (ASTFormalParameter) myParams.jjtGetChild(i);
Node myTypeNode = myParam.getTypeNode().jjtGetChild(0);
String myTypeImg;
if (myTypeNode instanceof ASTPrimitiveType) {
myTypeImg = myTypeNode.getImage();
} else {
myTypeImg = myTypeNode.jjtGetChild(0).getImage();
}
hash = hash * 31 + myTypeImg.hashCode();
}
return hash;
}
Aggregations