/** * {@inheritDoc} */ public boolean matches(T target) { Set<TypeDescription> duplicates = new HashSet<TypeDescription>(); for (TypeDefinition typeDefinition : target.getDeclaringType()) { if (matches(target, typeDefinition) || matches(target, typeDefinition.getInterfaces(), duplicates)) { return true; } } return false; }
/** * {@inheritDoc} */ public boolean matches(T target) { Set<TypeDescription> previous = new HashSet<TypeDescription>(); for (TypeDefinition typeDefinition : target) { if (!previous.add(typeDefinition.asErasure())) { // Main type can be an interface. return false; // Avoids a life-lock when encountering a recursive type-definition. } else if (matcher.matches(typeDefinition.asGenericType())) { return true; } LinkedList<TypeDefinition> interfaceTypes = new LinkedList<TypeDefinition>(typeDefinition.getInterfaces()); while (!interfaceTypes.isEmpty()) { TypeDefinition interfaceType = interfaceTypes.removeFirst(); if (previous.add(interfaceType.asErasure())) { if (matcher.matches(interfaceType.asGenericType())) { return true; } else { interfaceTypes.addAll(interfaceType.getInterfaces()); } } } } return false; }
/** * Matches a method against a list of types. * * @param target The method that is matched as a target. * @param typeDefinitions The type definitions to check if they declare a method with the same signature as {@code target}. * @param duplicates A set containing duplicate interfaces that do not need to be revisited. * @return {@code true} if any type defines a method with the same signature as the {@code target} method. */ private boolean matches(MethodDescription target, List<? extends TypeDefinition> typeDefinitions, Set<TypeDescription> duplicates) { for (TypeDefinition anInterface : typeDefinitions) { if (duplicates.add(anInterface.asErasure()) && (matches(target, anInterface) || matches(target, anInterface.getInterfaces(), duplicates))) { return true; } } return false; }
/** * {@inheritDoc} */ public MethodGraph.Linked compile(TypeDefinition typeDefinition, TypeDescription viewPoint) { Map<TypeDefinition, Key.Store<T>> snapshots = new HashMap<TypeDefinition, Key.Store<T>>(); Key.Store<?> rootStore = doAnalyze(typeDefinition, snapshots, isVirtual().and(isVisibleTo(viewPoint))); TypeDescription.Generic superClass = typeDefinition.getSuperClass(); List<TypeDescription.Generic> interfaceTypes = typeDefinition.getInterfaces(); Map<TypeDescription, MethodGraph> interfaceGraphs = new HashMap<TypeDescription, MethodGraph>(); for (TypeDescription.Generic interfaceType : interfaceTypes) { interfaceGraphs.put(interfaceType.asErasure(), snapshots.get(interfaceType).asGraph(merger)); } return new Linked.Delegation(rootStore.asGraph(merger), superClass == null ? Empty.INSTANCE : snapshots.get(superClass).asGraph(merger), interfaceGraphs); }
@Override public boolean matches(MethodDescription target) { return target.getDeclaringType().getInterfaces().asErasures() .filter(isAnnotatedWith(Remote.class)) .filter(isDeclaredInInterfaceHierarchy(target)).size() > 0; } }
/** * Analyzes the given type description without checking if it is already presented in the key store. * * @param typeDefinition The type to analyze. * @param snapshots A map containing snapshots of key stores for previously analyzed types. * @param relevanceMatcher A matcher for filtering methods that should be included in the graph. * @return A key store describing the provided type. */ protected Key.Store<T> doAnalyze(TypeDefinition typeDefinition, Map<TypeDefinition, Key.Store<T>> snapshots, ElementMatcher<? super MethodDescription> relevanceMatcher) { Key.Store<T> store = analyzeNullable(typeDefinition.getSuperClass(), snapshots, relevanceMatcher); Key.Store<T> interfaceStore = new Key.Store<T>(); for (TypeDescription.Generic interfaceType : typeDefinition.getInterfaces()) { interfaceStore = interfaceStore.combineWith(analyze(interfaceType.accept(visitor), interfaceType, snapshots, relevanceMatcher)); } return store.inject(interfaceStore).registerTopLevel(typeDefinition.getDeclaredMethods().filter(relevanceMatcher), harmonizer); }