Search in sources :

Example 1 with PLSQLParserVisitor

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

the class PLSQLRuleChainVisitor method indexNodes.

@Override
protected void indexNodes(List<Node> nodes, RuleContext ctx) {
    LOGGER.entering(CLASS_NAME, "indexNodes");
    PLSQLParserVisitor plsqlParserVistor = new PLSQLParserVisitorAdapter() {

        // Perform a visitation of the AST to index nodes which need
        // visiting by type
        @Override
        public Object visit(PLSQLNode node, Object data) {
            indexNode(node);
            return super.visit(node, data);
        }
    };
    for (int i = 0; i < nodes.size(); i++) {
        plsqlParserVistor.visit((ASTInput) nodes.get(i), ctx);
    }
    LOGGER.exiting(CLASS_NAME, "indexNodes");
}
Also used : PLSQLParserVisitor(net.sourceforge.pmd.lang.plsql.ast.PLSQLParserVisitor) PLSQLNode(net.sourceforge.pmd.lang.plsql.ast.PLSQLNode) PLSQLParserVisitorAdapter(net.sourceforge.pmd.lang.plsql.ast.PLSQLParserVisitorAdapter)

Example 2 with PLSQLParserVisitor

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

the class AbstractPLSQLParserTst method getNodes.

public <E> Set<E> getNodes(LanguageVersion languageVersion, Class<E> clazz, String plsqlCode) {
    Collector<E> coll = new Collector<>(clazz);
    LanguageVersionHandler languageVersionHandler = languageVersion.getLanguageVersionHandler();
    ASTInput cu = (ASTInput) languageVersionHandler.getParser(languageVersionHandler.getDefaultParserOptions()).parse(null, new StringReader(plsqlCode));
    PLSQLParserVisitor jpv = (PLSQLParserVisitor) Proxy.newProxyInstance(PLSQLParserVisitor.class.getClassLoader(), new Class[] { PLSQLParserVisitor.class }, coll);
    jpv.visit(cu, null);
    return (Set<E>) coll.getCollection();
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) PLSQLParserVisitor(net.sourceforge.pmd.lang.plsql.ast.PLSQLParserVisitor) StringReader(java.io.StringReader) ASTInput(net.sourceforge.pmd.lang.plsql.ast.ASTInput) LanguageVersionHandler(net.sourceforge.pmd.lang.LanguageVersionHandler)

Example 3 with PLSQLParserVisitor

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

the class AbstractPLSQLParserTst method buildDFA.

public ASTInput buildDFA(String plsqlCode) {
    LanguageVersionHandler languageVersionHandler = LanguageRegistry.getLanguage(PLSQLLanguageModule.NAME).getDefaultVersion().getLanguageVersionHandler();
    ASTInput cu = (ASTInput) languageVersionHandler.getParser(languageVersionHandler.getDefaultParserOptions()).parse(null, new StringReader(plsqlCode));
    PLSQLParserVisitor jpv = (PLSQLParserVisitor) Proxy.newProxyInstance(PLSQLParserVisitor.class.getClassLoader(), new Class[] { PLSQLParserVisitor.class }, new Collector<>(ASTInput.class));
    jpv.visit(cu, null);
    new SymbolFacade().initializeWith(cu);
    new DataFlowFacade().initializeWith(languageVersionHandler.getDataFlowHandler(), cu);
    return cu;
}
Also used : PLSQLParserVisitor(net.sourceforge.pmd.lang.plsql.ast.PLSQLParserVisitor) SymbolFacade(net.sourceforge.pmd.lang.plsql.symboltable.SymbolFacade) StringReader(java.io.StringReader) DataFlowFacade(net.sourceforge.pmd.lang.plsql.dfa.DataFlowFacade) ASTInput(net.sourceforge.pmd.lang.plsql.ast.ASTInput) LanguageVersionHandler(net.sourceforge.pmd.lang.LanguageVersionHandler)

Example 4 with PLSQLParserVisitor

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

the class AbstractPLSQLParserTst method getOrderedNodes.

public <E> List<E> getOrderedNodes(Class<E> clazz, String plsqlCode) {
    Collector<E> coll = new Collector<>(clazz, new ArrayList<E>());
    LanguageVersionHandler languageVersionHandler = LanguageRegistry.getLanguage(PLSQLLanguageModule.NAME).getDefaultVersion().getLanguageVersionHandler();
    ASTInput cu = (ASTInput) languageVersionHandler.getParser(languageVersionHandler.getDefaultParserOptions()).parse(null, new StringReader(plsqlCode));
    PLSQLParserVisitor jpv = (PLSQLParserVisitor) Proxy.newProxyInstance(PLSQLParserVisitor.class.getClassLoader(), new Class[] { PLSQLParserVisitor.class }, coll);
    jpv.visit(cu, null);
    SymbolFacade sf = new SymbolFacade();
    sf.initializeWith(cu);
    DataFlowFacade dff = new DataFlowFacade();
    dff.initializeWith(languageVersionHandler.getDataFlowHandler(), cu);
    return (List<E>) coll.getCollection();
}
Also used : PLSQLParserVisitor(net.sourceforge.pmd.lang.plsql.ast.PLSQLParserVisitor) SymbolFacade(net.sourceforge.pmd.lang.plsql.symboltable.SymbolFacade) StringReader(java.io.StringReader) DataFlowFacade(net.sourceforge.pmd.lang.plsql.dfa.DataFlowFacade) ASTInput(net.sourceforge.pmd.lang.plsql.ast.ASTInput) ArrayList(java.util.ArrayList) List(java.util.List) LanguageVersionHandler(net.sourceforge.pmd.lang.LanguageVersionHandler)

Aggregations

PLSQLParserVisitor (net.sourceforge.pmd.lang.plsql.ast.PLSQLParserVisitor)4 StringReader (java.io.StringReader)3 LanguageVersionHandler (net.sourceforge.pmd.lang.LanguageVersionHandler)3 ASTInput (net.sourceforge.pmd.lang.plsql.ast.ASTInput)3 DataFlowFacade (net.sourceforge.pmd.lang.plsql.dfa.DataFlowFacade)2 SymbolFacade (net.sourceforge.pmd.lang.plsql.symboltable.SymbolFacade)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1 PLSQLNode (net.sourceforge.pmd.lang.plsql.ast.PLSQLNode)1 PLSQLParserVisitorAdapter (net.sourceforge.pmd.lang.plsql.ast.PLSQLParserVisitorAdapter)1