use of net.sourceforge.pmd.lang.java.ast.JavaParserVisitor in project pmd by pmd.
the class ParserTstUtil method buildDFA.
public static ASTCompilationUnit buildDFA(String javaCode) {
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 }, new Collector<>(ASTCompilationUnit.class));
jpv.visit(cu, null);
new SymbolFacade().initializeWith(cu);
new DataFlowFacade().initializeWith(languageVersionHandler.getDataFlowHandler(), cu);
return cu;
}
use of net.sourceforge.pmd.lang.java.ast.JavaParserVisitor in project pmd by pmd.
the class ParserTstUtil method getNodes.
public static <E> Set<E> getNodes(LanguageVersion languageVersion, Class<E> clazz, String javaCode) {
Collector<E> coll = new Collector<>(clazz);
LanguageVersionHandler languageVersionHandler = languageVersion.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);
return (Set<E>) coll.getCollection();
}
use of net.sourceforge.pmd.lang.java.ast.JavaParserVisitor 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();
}
Aggregations