Search in sources :

Example 1 with ASTFormalParameter

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;
}
Also used : VariableAccess(net.sourceforge.pmd.lang.dfa.VariableAccess) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) NameDeclaration(net.sourceforge.pmd.lang.symboltable.NameDeclaration) ASTFormalParameter(net.sourceforge.pmd.lang.plsql.ast.ASTFormalParameter) Map(java.util.Map) PLSQLNameOccurrence(net.sourceforge.pmd.lang.plsql.symboltable.PLSQLNameOccurrence) NameOccurrence(net.sourceforge.pmd.lang.symboltable.NameOccurrence)

Example 2 with ASTFormalParameter

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();
}
Also used : ASTFormalParameters(net.sourceforge.pmd.lang.plsql.ast.ASTFormalParameters) ASTFormalParameter(net.sourceforge.pmd.lang.plsql.ast.ASTFormalParameter)

Example 3 with ASTFormalParameter

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;
}
Also used : AbstractPLSQLNode(net.sourceforge.pmd.lang.plsql.ast.AbstractPLSQLNode) Node(net.sourceforge.pmd.lang.ast.Node) ASTFormalParameters(net.sourceforge.pmd.lang.plsql.ast.ASTFormalParameters) ASTFormalParameter(net.sourceforge.pmd.lang.plsql.ast.ASTFormalParameter)

Aggregations

ASTFormalParameter (net.sourceforge.pmd.lang.plsql.ast.ASTFormalParameter)3 ASTFormalParameters (net.sourceforge.pmd.lang.plsql.ast.ASTFormalParameters)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 Node (net.sourceforge.pmd.lang.ast.Node)1 VariableAccess (net.sourceforge.pmd.lang.dfa.VariableAccess)1 AbstractPLSQLNode (net.sourceforge.pmd.lang.plsql.ast.AbstractPLSQLNode)1 PLSQLNameOccurrence (net.sourceforge.pmd.lang.plsql.symboltable.PLSQLNameOccurrence)1 NameDeclaration (net.sourceforge.pmd.lang.symboltable.NameDeclaration)1 NameOccurrence (net.sourceforge.pmd.lang.symboltable.NameOccurrence)1