Search in sources :

Example 1 with CorrespondenceComparatorDeducer

use of org.revapi.CorrespondenceComparatorDeducer in project revapi by revapi.

the class JavaApiAnalyzer method getCorrespondenceDeducer.

@Override
@Nonnull
public CorrespondenceComparatorDeducer getCorrespondenceDeducer() {
    return (l1, l2) -> {
        if (l1.isEmpty() || l2.isEmpty()) {
            return Comparator.naturalOrder();
        }
        // quickly peek inside to see if there even can be methods in the lists - all of the elements in either list
        // will have a common parent and parents of both lists will have the same type or be both null.
        Element parent = l1.get(0).getParent();
        if (!(parent instanceof TypeElement)) {
            return Comparator.naturalOrder();
        }
        IdentityHashMap<MethodElement, Integer> c1MethodOrder = new IdentityHashMap<>(l1.size());
        IdentityHashMap<MethodElement, Integer> c2MethodOrder = new IdentityHashMap<>(l2.size());
        // this will reorder the methods in the lists and will also fill in the method order indices in the maps
        // so that they can be used for comparisons below
        determineOrder(l1, l2, c1MethodOrder, c2MethodOrder);
        // and return a comparator
        return (e1, e2) -> {
            int ret = JavaElementFactory.compareByType(e1, e2);
            if (ret != 0) {
                return ret;
            }
            // let's just look that up.
            if (e1 instanceof MethodElement && e2 instanceof MethodElement) {
                MethodElement m1 = (MethodElement) e1;
                MethodElement m2 = (MethodElement) e2;
                return c1MethodOrder.get(m1) - c2MethodOrder.get(m2);
            } else {
                return e1.compareTo(e2);
            }
        };
    };
}
Also used : DifferenceAnalyzer(org.revapi.DifferenceAnalyzer) CompilationValve(org.revapi.java.compilation.CompilationValve) BiFunction(java.util.function.BiFunction) Element(org.revapi.Element) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CoIterator(org.revapi.CoIterator) Charset(java.nio.charset.Charset) Util(org.revapi.java.spi.Util) Map(java.util.Map) ArchiveAnalyzer(org.revapi.ArchiveAnalyzer) ThreadFactory(java.util.concurrent.ThreadFactory) ApiAnalyzer(org.revapi.ApiAnalyzer) Nonnull(javax.annotation.Nonnull) InclusionFilter(org.revapi.java.compilation.InclusionFilter) ExecutorService(java.util.concurrent.ExecutorService) Nullable(javax.annotation.Nullable) API(org.revapi.API) CorrespondenceComparatorDeducer(org.revapi.CorrespondenceComparatorDeducer) ProbingEnvironment(org.revapi.java.compilation.ProbingEnvironment) IdentityHashMap(java.util.IdentityHashMap) Iterator(java.util.Iterator) AnalysisContext(org.revapi.AnalysisContext) Collection(java.util.Collection) TypeElement(org.revapi.java.model.TypeElement) Set(java.util.Set) IOException(java.io.IOException) ServiceLoader(java.util.ServiceLoader) Reader(java.io.Reader) Types(javax.lang.model.util.Types) InputStreamReader(java.io.InputStreamReader) Executors(java.util.concurrent.Executors) JavaElementFactory(org.revapi.java.model.JavaElementFactory) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) StringReader(java.io.StringReader) TreeMap(java.util.TreeMap) MethodElement(org.revapi.java.model.MethodElement) Check(org.revapi.java.spi.Check) ModelNode(org.jboss.dmr.ModelNode) Pattern(java.util.regex.Pattern) Comparator(java.util.Comparator) TypeElement(org.revapi.java.model.TypeElement) Element(org.revapi.Element) TypeElement(org.revapi.java.model.TypeElement) MethodElement(org.revapi.java.model.MethodElement) IdentityHashMap(java.util.IdentityHashMap) MethodElement(org.revapi.java.model.MethodElement) Nonnull(javax.annotation.Nonnull)

Aggregations

IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1 StringReader (java.io.StringReader)1 Charset (java.nio.charset.Charset)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1 IdentityHashMap (java.util.IdentityHashMap)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 ServiceLoader (java.util.ServiceLoader)1 Set (java.util.Set)1 TreeMap (java.util.TreeMap)1 ExecutorService (java.util.concurrent.ExecutorService)1 Executors (java.util.concurrent.Executors)1 ThreadFactory (java.util.concurrent.ThreadFactory)1 BiFunction (java.util.function.BiFunction)1