Search in sources :

Example 1 with InclusionFilter

use of org.revapi.java.compilation.InclusionFilter in project revapi by revapi.

the class JavaApiAnalyzer method getArchiveAnalyzer.

@Nonnull
@Override
public ArchiveAnalyzer getArchiveAnalyzer(@Nonnull API api) {
    boolean ignoreMissingAnnotations = configuration.isIgnoreMissingAnnotations();
    InclusionFilter inclusionFilter = composeInclusionFilter(configuration);
    return new JavaArchiveAnalyzer(api, compilationExecutor, configuration.getMissingClassReporting(), ignoreMissingAnnotations, inclusionFilter);
}
Also used : InclusionFilter(org.revapi.java.compilation.InclusionFilter) Nonnull(javax.annotation.Nonnull)

Example 2 with InclusionFilter

use of org.revapi.java.compilation.InclusionFilter in project revapi by revapi.

the class JavaApiAnalyzer method composeInclusionFilter.

private static InclusionFilter composeInclusionFilter(AnalysisConfiguration config) {
    final Set<Pattern> inclClasses = config.getClassInclusionFilters();
    final Set<Pattern> exclClasses = config.getClassExclusionFilters();
    final Set<Pattern> inclPkgs = config.getPackageInclusionFilters();
    final Set<Pattern> exclPkgs = config.getPackageExclusionFilters();
    return new InclusionFilter() {

        @Override
        public boolean accepts(String typeBinaryName, String typeCanonicalName) {
            for (Pattern p : inclClasses) {
                if (p.matcher(typeCanonicalName).matches()) {
                    return true;
                }
            }
            int lastDot = typeBinaryName.lastIndexOf('.');
            String pkg = lastDot == -1 ? "" : typeBinaryName.substring(0, lastDot);
            for (Pattern p : inclPkgs) {
                if (p.matcher(pkg).matches()) {
                    return true;
                }
            }
            return false;
        }

        @Override
        public boolean rejects(String typeBinaryName, String typeCanonicalName) {
            for (Pattern p : exclClasses) {
                if (p.matcher(typeCanonicalName).matches()) {
                    return true;
                }
            }
            int lastDot = typeBinaryName.lastIndexOf('.');
            String pkg = lastDot == -1 ? "" : typeBinaryName.substring(0, lastDot);
            for (Pattern p : exclPkgs) {
                if (p.matcher(pkg).matches()) {
                    return true;
                }
            }
            return false;
        }

        @Override
        public boolean defaultCase() {
            return inclClasses.isEmpty() && inclPkgs.isEmpty();
        }
    };
}
Also used : Pattern(java.util.regex.Pattern) InclusionFilter(org.revapi.java.compilation.InclusionFilter)

Aggregations

InclusionFilter (org.revapi.java.compilation.InclusionFilter)2 Pattern (java.util.regex.Pattern)1 Nonnull (javax.annotation.Nonnull)1