Search in sources :

Example 1 with QualifiedNameResolver

use of net.sourceforge.pmd.lang.java.qname.QualifiedNameResolver in project pmd by pmd.

the class ParserTstUtil method getOrderedNodes.

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

Aggregations

StringReader (java.io.StringReader)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 LanguageVersionHandler (net.sourceforge.pmd.lang.LanguageVersionHandler)1 ASTCompilationUnit (net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit)1 JavaParserVisitor (net.sourceforge.pmd.lang.java.ast.JavaParserVisitor)1 DataFlowFacade (net.sourceforge.pmd.lang.java.dfa.DataFlowFacade)1 QualifiedNameResolver (net.sourceforge.pmd.lang.java.qname.QualifiedNameResolver)1 SymbolFacade (net.sourceforge.pmd.lang.java.symboltable.SymbolFacade)1