Java Code Examples for com.google.common.collect.SetMultimap#values()

The following examples show how to use com.google.common.collect.SetMultimap#values() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CombinedStateProcessingStep.java    From reductor with Apache License 2.0 6 votes vote down vote up
@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();
}
 
Example 2
Source File: ActionCreatorProcessingStep.java    From reductor with Apache License 2.0 6 votes vote down vote up
@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();
}
 
Example 3
Source File: MoreElements.java    From auto-parcel with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example 4
Source File: Environment.java    From sqlitemagic with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example 5
Source File: Rule.java    From bazel with Apache License 2.0 5 votes vote down vote up
/**
 * 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();
}
 
Example 6
Source File: SetMultimapExpression.java    From gef with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public Collection<V> values() {
	final SetMultimap<K, V> setMultimap = get();
	return (setMultimap == null) ? EMPTY_SETMULTIMAP.values()
			: setMultimap.values();
}