Search in sources :

Example 1 with AbstractPLSQLNode

use of net.sourceforge.pmd.lang.plsql.ast.AbstractPLSQLNode 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

Node (net.sourceforge.pmd.lang.ast.Node)1 ASTFormalParameter (net.sourceforge.pmd.lang.plsql.ast.ASTFormalParameter)1 ASTFormalParameters (net.sourceforge.pmd.lang.plsql.ast.ASTFormalParameters)1 AbstractPLSQLNode (net.sourceforge.pmd.lang.plsql.ast.AbstractPLSQLNode)1