Search in sources :

Example 1 with ASTName

use of net.sourceforge.pmd.lang.plsql.ast.ASTName in project pmd by pmd.

the class LocalScope method addNameOccurrence.

@Override
public Set<NameDeclaration> addNameOccurrence(NameOccurrence occ) {
    PLSQLNameOccurrence occurrence = (PLSQLNameOccurrence) occ;
    Set<NameDeclaration> declarations = findVariableHere(occurrence);
    if (!declarations.isEmpty() && !occurrence.isThisOrSuper()) {
        for (NameDeclaration decl : declarations) {
            List<NameOccurrence> nameOccurrences = getVariableDeclarations().get(decl);
            nameOccurrences.add(occurrence);
            Node n = occurrence.getLocation();
            if (n instanceof ASTName) {
                ((ASTName) n).setNameDeclaration(decl);
            }
        // TODO what to do with PrimarySuffix case?
        }
    }
    return declarations;
}
Also used : ASTName(net.sourceforge.pmd.lang.plsql.ast.ASTName) Node(net.sourceforge.pmd.lang.ast.Node) NameDeclaration(net.sourceforge.pmd.lang.symboltable.NameDeclaration) NameOccurrence(net.sourceforge.pmd.lang.symboltable.NameOccurrence)

Example 2 with ASTName

use of net.sourceforge.pmd.lang.plsql.ast.ASTName in project pmd by pmd.

the class NameFinder method checkForNameChild.

private void checkForNameChild(Node node) {
    if (node.getImage() != null) {
        add(new PLSQLNameOccurrence((PLSQLNode) node, node.getImage()));
    }
    if (node.jjtGetNumChildren() > 0 && node.jjtGetChild(0) instanceof ASTName) {
        ASTName grandchild = (ASTName) node.jjtGetChild(0);
        for (StringTokenizer st = new StringTokenizer(grandchild.getImage(), "."); st.hasMoreTokens(); ) {
            add(new PLSQLNameOccurrence(grandchild, st.nextToken()));
        }
    }
    if (node instanceof ASTPrimarySuffix) {
        ASTPrimarySuffix suffix = (ASTPrimarySuffix) node;
        if (suffix.isArguments()) {
            PLSQLNameOccurrence occurrence = names.get(names.size() - 1);
            occurrence.setIsMethodOrConstructorInvocation();
            ASTArguments args = (ASTArguments) ((ASTPrimarySuffix) node).jjtGetChild(0);
            occurrence.setArgumentCount(args.getArgumentCount());
        }
    // else if (suffix.jjtGetNumChildren() == 1
    // && suffix.jjtGetChild(0) instanceof ASTMemberSelector)
    // {
    // add(new NameOccurrence((SimpleNode)suffix.jjtGetChild(0),
    // suffix.jjtGetChild(0).getImage()));
    // }
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) ASTName(net.sourceforge.pmd.lang.plsql.ast.ASTName) PLSQLNode(net.sourceforge.pmd.lang.plsql.ast.PLSQLNode) ASTArguments(net.sourceforge.pmd.lang.plsql.ast.ASTArguments) ASTPrimarySuffix(net.sourceforge.pmd.lang.plsql.ast.ASTPrimarySuffix)

Example 3 with ASTName

use of net.sourceforge.pmd.lang.plsql.ast.ASTName in project pmd by pmd.

the class ClassScope method addNameOccurrence.

@Override
public Set<NameDeclaration> addNameOccurrence(NameOccurrence occ) {
    PLSQLNameOccurrence occurrence = (PLSQLNameOccurrence) occ;
    Set<NameDeclaration> declarations = findVariableHere(occurrence);
    Map<MethodNameDeclaration, List<NameOccurrence>> methodNames = getMethodDeclarations();
    if (!declarations.isEmpty() && occurrence.isMethodOrConstructorInvocation()) {
        for (NameDeclaration decl : declarations) {
            List<NameOccurrence> nameOccurrences = methodNames.get(decl);
            if (nameOccurrences == null) {
            // TODO may be a class name: Foo.this.super();
            } else {
                nameOccurrences.add(occurrence);
                Node n = occurrence.getLocation();
                if (n instanceof ASTName) {
                    ((ASTName) n).setNameDeclaration(decl);
                }
            // TODO what to do with PrimarySuffix case?
            }
        }
    } else if (!declarations.isEmpty() && !occurrence.isThisOrSuper()) {
        Map<VariableNameDeclaration, List<NameOccurrence>> variableNames = getVariableDeclarations();
        for (NameDeclaration decl : declarations) {
            List<NameOccurrence> nameOccurrences = variableNames.get(decl);
            if (nameOccurrences == null) {
            // TODO may be a class name
            } else {
                nameOccurrences.add(occurrence);
                Node n = occurrence.getLocation();
                if (n instanceof ASTName) {
                    ((ASTName) n).setNameDeclaration(decl);
                }
            // TODO what to do with PrimarySuffix case?
            }
        }
    }
    return declarations;
}
Also used : ASTName(net.sourceforge.pmd.lang.plsql.ast.ASTName) Node(net.sourceforge.pmd.lang.ast.Node) AbstractPLSQLNode(net.sourceforge.pmd.lang.plsql.ast.AbstractPLSQLNode) ArrayList(java.util.ArrayList) List(java.util.List) NameDeclaration(net.sourceforge.pmd.lang.symboltable.NameDeclaration) Map(java.util.Map) NameOccurrence(net.sourceforge.pmd.lang.symboltable.NameOccurrence)

Example 4 with ASTName

use of net.sourceforge.pmd.lang.plsql.ast.ASTName in project pmd by pmd.

the class MethodScope method addNameOccurrence.

@Override
public Set<NameDeclaration> addNameOccurrence(NameOccurrence occ) {
    PLSQLNameOccurrence occurrence = (PLSQLNameOccurrence) occ;
    Set<NameDeclaration> declarations = findVariableHere(occurrence);
    if (!declarations.isEmpty() && !occurrence.isThisOrSuper()) {
        for (NameDeclaration decl : declarations) {
            getVariableDeclarations().get(decl).add(occurrence);
            Node n = occurrence.getLocation();
            if (n instanceof ASTName) {
                ((ASTName) n).setNameDeclaration(decl);
            }
        // TODO what to do with PrimarySuffix case?
        }
    }
    return declarations;
}
Also used : ASTName(net.sourceforge.pmd.lang.plsql.ast.ASTName) AbstractPLSQLNode(net.sourceforge.pmd.lang.plsql.ast.AbstractPLSQLNode) Node(net.sourceforge.pmd.lang.ast.Node) NameDeclaration(net.sourceforge.pmd.lang.symboltable.NameDeclaration)

Aggregations

ASTName (net.sourceforge.pmd.lang.plsql.ast.ASTName)4 Node (net.sourceforge.pmd.lang.ast.Node)3 NameDeclaration (net.sourceforge.pmd.lang.symboltable.NameDeclaration)3 AbstractPLSQLNode (net.sourceforge.pmd.lang.plsql.ast.AbstractPLSQLNode)2 NameOccurrence (net.sourceforge.pmd.lang.symboltable.NameOccurrence)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 StringTokenizer (java.util.StringTokenizer)1 ASTArguments (net.sourceforge.pmd.lang.plsql.ast.ASTArguments)1 ASTPrimarySuffix (net.sourceforge.pmd.lang.plsql.ast.ASTPrimarySuffix)1 PLSQLNode (net.sourceforge.pmd.lang.plsql.ast.PLSQLNode)1