use of net.sourceforge.pmd.lang.plsql.ast.ASTFormalParameter in project pmd by pmd.
the class VariableAccessVisitor method markUsages.
private List<VariableAccess> markUsages(DataFlowNode inode) {
// undefinitions was once a field... seems like it works fine as a local
List<VariableAccess> undefinitions = new ArrayList<>();
Set<Map<NameDeclaration, List<NameOccurrence>>> variableDeclarations = collectDeclarations(inode);
for (Map<NameDeclaration, List<NameOccurrence>> declarations : variableDeclarations) {
for (Map.Entry<NameDeclaration, List<NameOccurrence>> entry : declarations.entrySet()) {
NameDeclaration vnd = entry.getKey();
if (vnd.getNode().jjtGetParent() instanceof ASTFormalParameter) {
// no definition/undefinition/references for parameters
continue;
} else if (vnd.getNode().jjtGetParent().getFirstDescendantOfType(ASTVariableOrConstantInitializer.class) != null) {
// add definition for initialized variables
addVariableAccess(vnd.getNode(), new VariableAccess(VariableAccess.DEFINITION, vnd.getImage()), inode.getFlow());
}
undefinitions.add(new VariableAccess(VariableAccess.UNDEFINITION, vnd.getImage()));
for (NameOccurrence occurrence : entry.getValue()) {
addAccess(occurrence, inode);
}
}
}
return undefinitions;
}
use of net.sourceforge.pmd.lang.plsql.ast.ASTFormalParameter in project pmd by pmd.
the class MethodNameDeclaration method getParameterDisplaySignature.
public String getParameterDisplaySignature() {
StringBuilder sb = new StringBuilder("(");
ASTFormalParameters params = (ASTFormalParameters) node.jjtGetChild(0);
// no need to trim at the end
for (int i = 0; i < ((ASTMethodDeclarator) node).getParameterCount(); i++) {
ASTFormalParameter p = (ASTFormalParameter) params.jjtGetChild(i);
sb.append(p.getTypeNode().getTypeImage());
// if (p.isVarargs()) {
// sb.append("...");
// }
sb.append(',');
}
if (sb.charAt(sb.length() - 1) == ',') {
sb.deleteCharAt(sb.length() - 1);
}
sb.append(')');
return sb.toString();
}
use of net.sourceforge.pmd.lang.plsql.ast.ASTFormalParameter in project pmd by pmd.
the class MethodNameDeclaration method equals.
@Override
public boolean equals(Object o) {
if (!(o instanceof MethodNameDeclaration)) {
return false;
}
MethodNameDeclaration other = (MethodNameDeclaration) o;
// compare name
if (!other.node.getImage().equals(node.getImage())) {
return false;
}
// params, too
if (((ASTMethodDeclarator) other.node).getParameterCount() != ((ASTMethodDeclarator) node).getParameterCount()) {
return false;
}
// compare parameter types
// SRT ASTFormalParameters myParams = (ASTFormalParameters)
// node.jjtGetChild(0);
// SRT ASTFormalParameters otherParams = (ASTFormalParameters)
// other.node.jjtGetChild(0);
ASTFormalParameters myParams = node.getFirstDescendantOfType(ASTFormalParameters.class);
ASTFormalParameters otherParams = other.node.getFirstDescendantOfType(ASTFormalParameters.class);
for (int i = 0; i < ((ASTMethodDeclarator) node).getParameterCount(); i++) {
ASTFormalParameter myParam = (ASTFormalParameter) myParams.jjtGetChild(i);
ASTFormalParameter otherParam = (ASTFormalParameter) otherParams.jjtGetChild(i);
// Compare vararg
// if (myParam.isVarargs() != otherParam.isVarargs()) {
// return false;
// }
Node myTypeNode = myParam.getTypeNode().jjtGetChild(0);
Node otherTypeNode = otherParam.getTypeNode().jjtGetChild(0);
// compare primitive vs reference type
if (myTypeNode.getClass() != otherTypeNode.getClass()) {
return false;
}
// simple comparison of type images
// this can be fooled by one method using "String"
// and the other method using "java.lang.String"
// once we get real types in here that should get fixed
String myTypeImg;
String otherTypeImg;
// if (myTypeNode instanceof ASTPrimitiveType) {
// myTypeImg = myTypeNode.getImage();
// otherTypeImg = otherTypeNode.getImage();
// } else {
myTypeImg = ((AbstractPLSQLNode) myTypeNode.jjtGetChild(0)).getImage();
otherTypeImg = ((AbstractPLSQLNode) otherTypeNode.jjtGetChild(0)).getImage();
if (!myTypeImg.equals(otherTypeImg)) {
return false;
}
// if type is ASTPrimitiveType and is an array, make sure the other
// one is also
}
return true;
}
Aggregations