com.google.common.base.Equivalence#Wrapper ( )源码实例Demo

下面列出了com.google.common.base.Equivalence#Wrapper ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: compile-testing   文件: TreeDiffer.java
static MethodSignature create(
    CompilationUnitTree compilationUnitTree, MethodTree tree, Trees trees) {
  ImmutableList.Builder<Equivalence.Wrapper<TypeMirror>> parameterTypes =
      ImmutableList.builder();
  for (VariableTree parameter : tree.getParameters()) {
    parameterTypes.add(
        MoreTypes.equivalence()
            .wrap(trees.getTypeMirror(trees.getPath(compilationUnitTree, parameter))));
  }
  return new AutoValue_TreeDiffer_MethodSignature(
      tree.getName().toString(), parameterTypes.build());
}
 
源代码2 项目: dagger2-sample   文件: BindingGraph.java
private Optional<RequestResolver> getOwningResolver(ProvisionBinding provisionBinding) {
  Optional<Equivalence.Wrapper<AnnotationMirror>> bindingScope =
      provisionBinding.wrappedScope();
  for (RequestResolver requestResolver : getResolverLineage()) {
    if (bindingScope.equals(requestResolver.targetScope)
        || requestResolver.explicitProvisionBindings.containsValue(provisionBinding)) {
      return Optional.of(requestResolver);
    }
  }
  return Optional.absent();
}
 
源代码3 项目: auto   文件: SerializableAutoValueExtension.java
ProxyGenerator(
    TypeName outerClassTypeName,
    ImmutableList<TypeVariableName> typeVariableNames,
    ImmutableList<PropertyMirror> propertyMirrors,
    ImmutableMap<Equivalence.Wrapper<TypeMirror>, Serializer> serializersMap) {
  this.outerClassTypeName = outerClassTypeName;
  this.typeVariableNames = typeVariableNames;
  this.propertyMirrors = propertyMirrors;
  this.serializersMap = serializersMap;
}
 
源代码4 项目: dagger2-sample   文件: Util.java
/**
 * Wraps an {@link Optional} of a type in an {@code Optional} of a {@link Wrapper} for that type.
 */
static <T> Optional<Equivalence.Wrapper<T>> wrapOptionalInEquivalence(
    Equivalence<T> equivalence, Optional<T> optional) {
  return optional.isPresent()
      ? Optional.of(equivalence.wrap(optional.get()))
      : Optional.<Equivalence.Wrapper<T>>absent();
}
 
源代码5 项目: auto   文件: TypeVariables.java
/**
 * Tests whether a given parameter can be given to a static method like
 * {@code ImmutableMap.copyOf} to produce a value that can be assigned to the given target type.
 *
 * <p>For example, suppose we have this method in {@code ImmutableMap}:<br>
 * {@code static <K, V> ImmutableMap<K, V> copyOf(Map<? extends K, ? extends V>)}<br>
 * and we want to know if we can do this:
 *
 * <pre>
 * {@code ImmutableMap<String, Integer> actualParameter = ...;}
 * {@code ImmutableMap<String, Number> target = ImmutableMap.copyOf(actualParameter);}
 * </pre>
 *
 * We will infer {@code K=String}, {@code V=Number} based on the target type, and then rewrite the
 * formal parameter type from<br>
 * {@code Map<? extends K, ? extends V>} to<br>
 * {@code Map<? extends String, ? extends Number>}. Then we can check whether
 * {@code actualParameter} is assignable to that.
 *
 * <p>The logic makes some simplifying assumptions, which are met for the {@code copyOf} and
 * {@code of} methods that we use this for. The method must be static, it must have exactly one
 * parameter, and it must have type parameters without bounds that are the same as the type
 * parameters of its return type. We can see that these assumptions are met for the
 * {@code ImmutableMap.copyOf} example above.
 */
static boolean canAssignStaticMethodResult(
    ExecutableElement method,
    TypeMirror actualParameterType,
    TypeMirror targetType,
    Types typeUtils) {
  if (!targetType.getKind().equals(TypeKind.DECLARED)
      || !method.getModifiers().contains(Modifier.STATIC)
      || method.getParameters().size() != 1) {
    return false;
  }
  List<? extends TypeParameterElement> typeParameters = method.getTypeParameters();
  List<? extends TypeMirror> targetTypeArguments =
      MoreTypes.asDeclared(targetType).getTypeArguments();
  if (typeParameters.size() != targetTypeArguments.size()) {
    return false;
  }
  Map<Equivalence.Wrapper<TypeVariable>, TypeMirror> typeVariables = new LinkedHashMap<>();
  for (int i = 0; i < typeParameters.size(); i++) {
    TypeVariable v = MoreTypes.asTypeVariable(typeParameters.get(i).asType());
    typeVariables.put(MoreTypes.equivalence().wrap(v), targetTypeArguments.get(i));
  }
  TypeMirror formalParameterType = method.getParameters().get(0).asType();
  SubstitutionVisitor substitutionVisitor = new SubstitutionVisitor(typeVariables, typeUtils);
  TypeMirror substitutedParameterType = substitutionVisitor.visit(formalParameterType, null);
  if (substitutedParameterType.getKind().equals(TypeKind.WILDCARD)) {
    // If the target type is Optional<? extends Foo> then <T> T Optional.of(T) will give us
    // ? extends Foo here, and typeUtils.isAssignable will return false. But we can in fact
    // give a Foo as an argument, so we just replace ? extends Foo with Foo.
    WildcardType wildcard = MoreTypes.asWildcard(substitutedParameterType);
    if (wildcard.getExtendsBound() != null) {
      substitutedParameterType = wildcard.getExtendsBound();
    }
  }
  return typeUtils.isAssignable(actualParameterType, substitutedParameterType);
}
 
源代码6 项目: auto   文件: Mirrors.java
/**
 * Unwraps an {@link Optional} of a {@link Equivalence.Wrapper} into an {@code Optional} of the
 * underlying type.
 */
static <T> Optional<T> unwrapOptionalEquivalence(
    Optional<Equivalence.Wrapper<T>> wrappedOptional) {
  return wrappedOptional.isPresent()
      ? Optional.of(wrappedOptional.get().get())
      : Optional.<T>absent();
}
 
源代码7 项目: dagger2-sample   文件: MethodSignature.java
static MethodSignature fromExecutableType(String methodName, ExecutableType methodType) {
  checkNotNull(methodType);
  ImmutableList.Builder<Equivalence.Wrapper<TypeMirror>> parameters = ImmutableList.builder();
  ImmutableList.Builder<Equivalence.Wrapper<TypeMirror>> thrownTypes = ImmutableList.builder();
  for (TypeMirror parameter : methodType.getParameterTypes()) {
    parameters.add(MoreTypes.equivalence().wrap(parameter));
  }
  for (TypeMirror thrownType : methodType.getThrownTypes()) {
    thrownTypes.add(MoreTypes.equivalence().wrap(thrownType));
  }
  return new AutoValue_MethodSignature(
      methodName,
      parameters.build(),
      thrownTypes.build());
}
 
源代码8 项目: grakn   文件: ReasonerUtils.java
private static <B, S extends B> Map<Equivalence.Wrapper<B>, Integer> getCardinalityMap(Collection<S> coll, Equivalence<B> equiv) {
    Map<Equivalence.Wrapper<B>, Integer> count = new HashMap<>();
    for (S obj : coll) count.merge(equiv.wrap(obj), 1, Integer::sum);
    return count;
}
 
源代码9 项目: grakn   文件: MultilevelSemanticCache.java
@Override
Equivalence.Wrapper<ReasonerAtomicQuery> queryToKey(ReasonerAtomicQuery query) {
    return unifierType().equivalence().wrap(query);
}
 
源代码10 项目: grakn   文件: QueryCollection.java
public boolean contains(Equivalence.Wrapper<ReasonerQueryImpl> q){
    return wrappedCollection.contains(q);
}
 
源代码11 项目: grakn   文件: QuerySet.java
public static QuerySet create(Collection<Equivalence.Wrapper<ReasonerQueryImpl>> queries){
    return new QuerySet(queries.stream().map(Equivalence.Wrapper::get).collect(Collectors.toSet()));
}
 
源代码12 项目: RetroFacebook   文件: TypeMirrorSet.java
private Equivalence.Wrapper<TypeMirror> wrap(TypeMirror typeMirror) {
  return MoreTypes.equivalence().wrap(typeMirror);
}
 
源代码13 项目: dagger2-sample   文件: Key.java
/**
 * The type represented by this key.
 *
 * As documented in {@link TypeMirror}, equals and hashCode aren't implemented to represent
 * logical equality, so {@link MoreTypes#equivalence()} wraps this type.
 */
abstract Equivalence.Wrapper<TypeMirror> wrappedType();
 
源代码14 项目: dagger2-sample   文件: ComponentDescriptor.java
/**
 * An optional annotation constraining the scope of this component wrapped in an
 * {@link com.google.common.base.Equivalence.Wrapper} to preserve comparison semantics of
 * {@link AnnotationMirror}.
 */
abstract Optional<Equivalence.Wrapper<AnnotationMirror>> wrappedScope();
 
源代码15 项目: dagger2-sample   文件: ProvisionBinding.java
/**
 * An optional annotation constraining the scope of this component wrapped in an
 * {@link com.google.common.base.Equivalence.Wrapper} to preserve comparison semantics of
 * {@link AnnotationMirror}.
 */
abstract Optional<Equivalence.Wrapper<AnnotationMirror>> wrappedScope();
 
源代码16 项目: compile-testing   文件: TreeDiffer.java
abstract ImmutableList<Equivalence.Wrapper<TypeMirror>> parameterTypes(); 
源代码17 项目: auto   文件: Key.java
abstract Equivalence.Wrapper<TypeMirror> type(); 
源代码18 项目: dagger2-sample   文件: MethodSignature.java
abstract ImmutableList<Equivalence.Wrapper<TypeMirror>> thrownTypes(); 
源代码19 项目: dagger2-sample   文件: MethodSignature.java
abstract ImmutableList<Equivalence.Wrapper<TypeMirror>> parameterTypes(); 
源代码20 项目: auto   文件: Key.java
abstract Optional<Equivalence.Wrapper<AnnotationMirror>> qualifierWrapper();