use of org.revapi.java.model.JavaElementForest in project revapi by revapi.
the class AnnotatedElementFilterTest method testWith.
private void testWith(String configJSON, Consumer<List<Element>> test) throws Exception {
ArchiveAndCompilationPath archive = createCompiledJar("test.jar", "annotationfilter/NonPublic.java", "annotationfilter/NonPublicClass.java", "annotationfilter/Public.java", "annotationfilter/PublicClass.java", "annotationfilter/UndecisiveClass.java");
try {
JavaArchiveAnalyzer analyzer = new JavaArchiveAnalyzer(new API(Arrays.asList(new ShrinkwrapArchive(archive.archive)), null), Executors.newSingleThreadExecutor(), null, false, InclusionFilter.acceptAll());
JavaElementForest forest = analyzer.analyze();
AnnotatedElementFilter filter = new AnnotatedElementFilter();
Revapi r = new Revapi(emptySet(), emptySet(), emptySet(), singleton(AnnotatedElementFilter.class));
AnalysisContext ctx = AnalysisContext.builder(r).withConfigurationFromJSON(configJSON).build();
AnalysisContext filterCtx = r.prepareAnalysis(ctx).getFirstConfigurationOrNull(AnnotatedElementFilter.class);
filter.initialize(filterCtx);
List<Element> results = forest.search(Element.class, true, filter, null);
analyzer.getCompilationValve().removeCompiledResults();
test.accept(results);
} finally {
deleteDir(archive.compilationPath);
}
}
use of org.revapi.java.model.JavaElementForest in project revapi by revapi.
the class JavaArchiveAnalyzerTest method testSimple.
@Test
public void testSimple() throws Exception {
ArchiveAndCompilationPath archive = createCompiledJar("test.jar", "misc/A.java", "misc/B.java", "misc/C.java", "misc/D.java", "misc/I.java");
JavaArchiveAnalyzer analyzer = new JavaArchiveAnalyzer(new API(Arrays.asList(new ShrinkwrapArchive(archive.archive)), null), Executors.newSingleThreadExecutor(), null, false, InclusionFilter.acceptAll());
try {
JavaElementForest forest = analyzer.analyze();
Assert.assertEquals(6, forest.getRoots().size());
} finally {
deleteDir(archive.compilationPath);
analyzer.getCompilationValve().removeCompiledResults();
}
}
use of org.revapi.java.model.JavaElementForest in project revapi by revapi.
the class JavaArchiveAnalyzerTest method testTypeParametersDragIntoAPI.
@Test
public void testTypeParametersDragIntoAPI() throws Exception {
ArchiveAndCompilationPath compRes = createCompiledJar("a.jar", "misc/Generics.java", "misc/GenericsParams.java");
JavaArchive api = ShrinkWrap.create(JavaArchive.class, "api.jar").addAsResource(compRes.compilationPath.resolve("Generics.class").toFile(), "Generics.class");
JavaArchive sup = ShrinkWrap.create(JavaArchive.class, "sup.jar").addAsResource(compRes.compilationPath.resolve("GenericsParams.class").toFile(), "GenericsParams.class").addAsResource(compRes.compilationPath.resolve("GenericsParams$TypeParam.class").toFile(), "GenericsParams$TypeParam.class").addAsResource(compRes.compilationPath.resolve("GenericsParams$ExtendsBound.class").toFile(), "GenericsParams$ExtendsBound.class").addAsResource(compRes.compilationPath.resolve("GenericsParams$SuperBound.class").toFile(), "GenericsParams$SuperBound.class").addAsResource(compRes.compilationPath.resolve("GenericsParams$TypeVar.class").toFile(), "GenericsParams$TypeVar.class").addAsResource(compRes.compilationPath.resolve("GenericsParams$TypeVarIface.class").toFile(), "GenericsParams$TypeVarIface.class").addAsResource(compRes.compilationPath.resolve("GenericsParams$TypeVarImpl.class").toFile(), "GenericsParams$TypeVarImpl.class").addAsResource(compRes.compilationPath.resolve("GenericsParams$Unused.class").toFile(), "GenericsParams$Unused.class");
JavaArchiveAnalyzer analyzer = new JavaArchiveAnalyzer(new API(Arrays.asList(new ShrinkwrapArchive(api)), Arrays.asList(new ShrinkwrapArchive(sup))), Executors.newSingleThreadExecutor(), null, false, InclusionFilter.acceptAll());
try {
JavaElementForest forest = analyzer.analyze();
Set<TypeElement> roots = forest.getRoots();
Assert.assertEquals(7, roots.size());
Assert.assertTrue(roots.stream().anyMatch(hasName("class Generics<T extends GenericsParams.TypeVar, GenericsParams.TypeVarIface, U extends Generics<GenericsParams.TypeVarImpl, ?>>")));
Assert.assertTrue(roots.stream().anyMatch(hasName("class GenericsParams.ExtendsBound")));
Assert.assertTrue(roots.stream().anyMatch(hasName("class GenericsParams.SuperBound")));
Assert.assertTrue(roots.stream().anyMatch(hasName("class GenericsParams.TypeParam")));
Assert.assertTrue(roots.stream().anyMatch(hasName("class GenericsParams.TypeVar")));
Assert.assertTrue(roots.stream().anyMatch(hasName("interface GenericsParams.TypeVarIface")));
Assert.assertTrue(roots.stream().anyMatch(hasName("class GenericsParams.TypeVarImpl")));
Assert.assertFalse(roots.stream().anyMatch(hasName("class GenericsParams.Unused")));
} finally {
deleteDir(compRes.compilationPath);
analyzer.getCompilationValve().removeCompiledResults();
}
}
use of org.revapi.java.model.JavaElementForest in project revapi by revapi.
the class JavaArchiveAnalyzerTest method testPreventRecursionWhenConstructingInheritedMembers.
@Test
public void testPreventRecursionWhenConstructingInheritedMembers() throws Exception {
ArchiveAndCompilationPath archive = createCompiledJar("a.jar", "misc/MemberInheritsOwner.java");
JavaArchiveAnalyzer analyzer = new JavaArchiveAnalyzer(new API(Arrays.asList(new ShrinkwrapArchive(archive.archive)), null), Executors.newSingleThreadExecutor(), null, false, InclusionFilter.acceptAll());
try {
JavaElementForest forest = analyzer.analyze();
forest.getRoots();
Assert.assertEquals(1, forest.getRoots().size());
Predicate<Element> findMethod = c -> "method void MemberInheritsOwner::method()".equals(c.getFullHumanReadableString());
Predicate<Element> findMember1 = c -> "interface MemberInheritsOwner.Member1".equals(c.getFullHumanReadableString());
Predicate<Element> findMember2 = c -> "interface MemberInheritsOwner.Member2".equals(c.getFullHumanReadableString());
Element root = forest.getRoots().first();
Assert.assertEquals(3, root.getChildren().size());
Assert.assertTrue(root.getChildren().stream().anyMatch(findMethod));
Assert.assertTrue(root.getChildren().stream().anyMatch(findMember1));
Assert.assertTrue(root.getChildren().stream().anyMatch(findMember2));
Assert.assertEquals(1, root.getChildren().stream().filter(findMember1).findFirst().get().getChildren().size());
Assert.assertEquals(1, root.getChildren().stream().filter(findMember2).findFirst().get().getChildren().size());
} finally {
deleteDir(archive.compilationPath);
analyzer.getCompilationValve().removeCompiledResults();
}
}
use of org.revapi.java.model.JavaElementForest in project revapi by revapi.
the class JavaArchiveAnalyzerTest method testWithSupplementary.
@Test
public void testWithSupplementary() throws Exception {
ArchiveAndCompilationPath compRes = createCompiledJar("a.jar", "v1/supplementary/a/A.java", "v1/supplementary/b/B.java", "v1/supplementary/a/C.java");
JavaArchive api = ShrinkWrap.create(JavaArchive.class, "api.jar").addAsResource(compRes.compilationPath.resolve("A.class").toFile(), "A.class");
JavaArchive sup = ShrinkWrap.create(JavaArchive.class, "sup.jar").addAsResource(compRes.compilationPath.resolve("B.class").toFile(), "B.class").addAsResource(compRes.compilationPath.resolve("B$T$1.class").toFile(), "B$T$1.class").addAsResource(compRes.compilationPath.resolve("B$T$1$TT$1.class").toFile(), "B$T$1$TT$1.class").addAsResource(compRes.compilationPath.resolve("B$T$2.class").toFile(), "B$T$2.class").addAsResource(compRes.compilationPath.resolve("C.class").toFile(), "C.class").addAsResource(compRes.compilationPath.resolve("B$UsedByIgnoredClass.class").toFile(), "B$UsedByIgnoredClass.class").addAsResource(compRes.compilationPath.resolve("A$PrivateEnum.class").toFile(), "A$PrivateEnum.class");
JavaArchiveAnalyzer analyzer = new JavaArchiveAnalyzer(new API(Arrays.asList(new ShrinkwrapArchive(api)), Arrays.asList(new ShrinkwrapArchive(sup))), Executors.newSingleThreadExecutor(), null, false, InclusionFilter.acceptAll());
try {
JavaElementForest forest = analyzer.analyze();
Assert.assertEquals(3, forest.getRoots().size());
Iterator<TypeElement> roots = forest.getRoots().iterator();
TypeElement A = roots.next();
TypeElement B_T$1 = roots.next();
TypeElement B_T$2 = roots.next();
Assert.assertEquals("A", A.getCanonicalName());
Assert.assertEquals("A", A.getDeclaringElement().getQualifiedName().toString());
Assert.assertEquals("B.T$1", B_T$1.getCanonicalName());
Assert.assertEquals("B.T$1", B_T$1.getDeclaringElement().getQualifiedName().toString());
Assert.assertEquals("B.T$2", B_T$2.getCanonicalName());
Assert.assertEquals("B.T$2", B_T$2.getDeclaringElement().getQualifiedName().toString());
} finally {
deleteDir(compRes.compilationPath);
analyzer.getCompilationValve().removeCompiledResults();
}
}
Aggregations