Search in sources :

Example 1 with AnnotatedElementFilter

use of org.revapi.java.filters.AnnotatedElementFilter 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);
    }
}
Also used : JavaElementForest(org.revapi.java.model.JavaElementForest) Revapi(org.revapi.Revapi) Element(org.revapi.Element) MethodParameterElement(org.revapi.java.model.MethodParameterElement) MethodElement(org.revapi.java.model.MethodElement) AnnotatedElement(java.lang.reflect.AnnotatedElement) API(org.revapi.API) AnalysisContext(org.revapi.AnalysisContext) AnnotatedElementFilter(org.revapi.java.filters.AnnotatedElementFilter)

Aggregations

AnnotatedElement (java.lang.reflect.AnnotatedElement)1 API (org.revapi.API)1 AnalysisContext (org.revapi.AnalysisContext)1 Element (org.revapi.Element)1 Revapi (org.revapi.Revapi)1 AnnotatedElementFilter (org.revapi.java.filters.AnnotatedElementFilter)1 JavaElementForest (org.revapi.java.model.JavaElementForest)1 MethodElement (org.revapi.java.model.MethodElement)1 MethodParameterElement (org.revapi.java.model.MethodParameterElement)1