use of net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit 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.ASTCompilationUnit in project pmd by pmd.
the class ProjectMemoizerTest method memoizationTest.
@Test
public void memoizationTest() {
ASTCompilationUnit acu = ParserTstUtil.parseJavaDefaultVersion(MetricsVisitorTestData.class);
List<Integer> expected = visitWith(acu, true);
List<Integer> real = visitWith(acu, false);
assertEquals(expected, real);
}
use of net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit in project pmd by pmd.
the class SignatureTest method testGetterDetection.
@Test
public void testGetterDetection() {
ASTCompilationUnit compilationUnit = parseJava17(GetterDetection.class);
compilationUnit.jjtAccept(new JavaParserVisitorAdapter() {
@Override
public Object visit(ASTMethodDeclaration node, Object data) {
assertEquals(Role.GETTER_OR_SETTER, Role.get(node));
return data;
}
}, null);
}
use of net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit in project pmd by pmd.
the class JavaMultifileVisitorTest method testOperationsAreThere.
@Test
public void testOperationsAreThere() {
ASTCompilationUnit acu = parseAndVisitForClass(MultifileVisitorTestData2.class);
final ProjectMirror toplevel = PackageStats.INSTANCE;
final JavaOperationSigMask opMask = new JavaOperationSigMask();
// We could parse qnames from string but probably simpler to do that
acu.jjtAccept(new JavaParserVisitorAdapter() {
@Override
public Object visit(ASTMethodDeclaration node, Object data) {
assertTrue(toplevel.hasMatchingSig(node.getQualifiedName(), opMask));
return data;
}
}, null);
}
use of net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit in project pmd by pmd.
the class JavaMultifileVisitorTest method parseAndVisitForClass.
static ASTCompilationUnit parseAndVisitForClass(Class<?> clazz) {
ASTCompilationUnit acu = ParserTstUtil.parseJavaDefaultVersion(clazz);
LanguageVersionHandler handler = ParserTstUtil.getDefaultLanguageVersionHandler();
handler.getQualifiedNameResolutionFacade(JavaMultifileVisitorTest.class.getClassLoader()).start(acu);
handler.getTypeResolutionFacade(JavaMultifileVisitorTest.class.getClassLoader()).start(acu);
handler.getMultifileFacade().start(acu);
return acu;
}
Aggregations