下面列出了com.google.common.collect.SetMultimap#values ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public Set<Element> process(SetMultimap<Class<? extends Annotation>, Element> elementsByAnnotation) {
for (Element element : elementsByAnnotation.values()) {
TypeElement combinedStateTypeElement = (TypeElement) element;
try {
CombinedStateElement combinedStateElement = CombinedStateElement.parseCombinedElement(combinedStateTypeElement, env);
if (combinedStateElement == null) continue;
ClassName stateClassName = emmitCombinedStateImplementation(combinedStateElement);
emmitCombinedReducer(env, combinedStateElement, stateClassName);
} catch (ValidationException ve) {
env.printError(ve.getElement(), ve.getMessage());
} catch (Exception e) {
env.printError(element, "Internal processor error:\n" + e.getMessage());
e.printStackTrace();
}
}
return Collections.emptySet();
}
@Override
public Set<Element> process(SetMultimap<Class<? extends Annotation>, Element> elementsByAnnotation) {
for (Element element : elementsByAnnotation.values()) {
try {
ActionCreatorElement creatorElement = ActionCreatorElement.parse(element, env);
knownActionCreators.put(env.getElements().getBinaryName((TypeElement) element).toString(), creatorElement);
emitActionCreator(creatorElement, env);
} catch (ValidationException ve) {
env.printError(ve.getElement(), ve.getMessage());
} catch (Exception e) {
e.printStackTrace();
env.printError(element, "Internal processor error:\n " + e.getMessage());
}
}
return Collections.emptySet();
}
/**
* Returns the set of all non-private methods from {@code type}, including methods that it
* inherits from its ancestors. Inherited methods that are overridden are not included in the
* result. So if {@code type} defines {@code public String toString()}, the returned set will
* contain that method, but not the {@code toString()} method defined by {@code Object}.
* <p/>
* <p>The returned set may contain more than one method with the same signature, if
* {@code type} inherits those methods from different ancestors. For example, if it
* inherits from unrelated interfaces {@code One} and {@code Two} which each define
* {@code void foo();}, and if it does not itself override the {@code foo()} method,
* then both {@code One.foo()} and {@code Two.foo()} will be in the returned set.
*
* @param type the type whose own and inherited methods are to be returned
* @param elementUtils an {@link Elements} object, typically returned by
* {@link javax.annotation.processing.AbstractProcessor#processingEnv processingEnv}<!--
* -->.{@link javax.annotation.processing.ProcessingEnvironment.getElementUtils()
* getElementUtils()}
*/
public static ImmutableSet<ExecutableElement> getLocalAndInheritedMethods(
TypeElement type, Elements elementUtils) {
SetMultimap<String, ExecutableElement> methodMap = LinkedHashMultimap.create();
getLocalAndInheritedMethods(getPackage(type), type, methodMap);
// Find methods that are overridden. We do this using `Elements.overrides`, which means
// that it is inherently a quadratic operation, since we have to compare every method against
// every other method. We reduce the performance impact by (a) grouping methods by name, since
// a method cannot override another method with a different name, and (b) making sure that
// methods in ancestor types precede those in descendant types, which means we only have to
// check a method against the ones that follow it in that order.
Set<ExecutableElement> overridden = new LinkedHashSet<ExecutableElement>();
for (String methodName : methodMap.keySet()) {
List<ExecutableElement> methodList = ImmutableList.copyOf(methodMap.get(methodName));
for (int i = 0; i < methodList.size(); i++) {
ExecutableElement methodI = methodList.get(i);
for (int j = i + 1; j < methodList.size(); j++) {
ExecutableElement methodJ = methodList.get(j);
if (elementUtils.overrides(methodJ, methodI, type)) {
overridden.add(methodI);
}
}
}
}
Set<ExecutableElement> methods = new LinkedHashSet<ExecutableElement>(methodMap.values());
methods.removeAll(overridden);
return ImmutableSet.copyOf(methods);
}
@NonNull
public Set<ExecutableElement> getLocalAndInheritedMethods(TypeElement type, ConditionCallback<ExecutableElement> includeMethodCallback) {
SetMultimap<String, ExecutableElement> methodMap = LinkedHashMultimap.create();
getLocalAndInheritedMethods(getPackage(type), type, methodMap, includeMethodCallback);
// Find methods that are overridden. We do this using `Elements.overrides`, which means
// that it is inherently a quadratic operation, since we have to compare every method against
// every other method. We reduce the performance impact by (a) grouping methods by name, since
// a method cannot override another method with a different name, and (b) making sure that
// methods in ancestor types precede those in descendant types, which means we only have to
// check a method against the ones that follow it in that order.
Set<ExecutableElement> overridden = new LinkedHashSet<>();
final Elements elementUtils = this.elementUtils;
for (String methodName : methodMap.keySet()) {
List<ExecutableElement> methodList = ImmutableList.copyOf(methodMap.get(methodName));
for (int i = 0; i < methodList.size(); i++) {
ExecutableElement methodI = methodList.get(i);
for (int j = i + 1; j < methodList.size(); j++) {
ExecutableElement methodJ = methodList.get(j);
if (elementUtils.overrides(methodJ, methodI, type)) {
overridden.add(methodI);
}
}
}
}
Set<ExecutableElement> methods = new LinkedHashSet<>(methodMap.values());
methods.removeAll(overridden);
return methods;
}
/**
* Computes labels of additional dependencies that can be provided by aspects that this rule
* can require from its direct dependencies.
*/
public Collection<? extends Label> getAspectLabelsSuperset(DependencyFilter predicate) {
if (!hasAspects()) {
return ImmutableList.of();
}
SetMultimap<Attribute, Label> labels = LinkedHashMultimap.create();
for (Attribute attribute : this.getAttributes()) {
for (Aspect candidateClass : attribute.getAspects(this)) {
AspectDefinition.addAllAttributesOfAspect(Rule.this, labels, candidateClass, predicate);
}
}
return labels.values();
}
@Override
public Collection<V> values() {
final SetMultimap<K, V> setMultimap = get();
return (setMultimap == null) ? EMPTY_SETMULTIMAP.values()
: setMultimap.values();
}