微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

com.google.common.collect.ImmutableClassToInstanceMap的实例源码

项目:refactor-faster    文件UTemplater.java   
@SuppressWarnings("unchecked")
public static ImmutableClasstoInstanceMap<Annotation> annotationMap(Symbol symbol) {
  ImmutableClasstoInstanceMap.Builder<Annotation> builder = ImmutableClasstoInstanceMap.builder();
  for (Compound compound : symbol.getAnnotationMirrors()) {
    Name qualifiedAnnotationType =
        ((TypeElement) compound.getAnnotationType().asElement()).getQualifiedname();
    try {
      Class<? extends Annotation> annotationClazz = 
          Class.forName(qualifiedAnnotationType.toString()).asSubclass(Annotation.class);
      builder.put((Class) annotationClazz,AnnotationProxyMaker.generateAnnotation(compound,annotationClazz));
    } catch (ClassNotFoundException e) {
      throw new IllegalArgumentException("Unrecognized annotation type",e);
    }
  }
  return builder.build();
}
项目:refactor-faster    文件RefasterRule.java   
public static RefasterRule<?,?> create(String qualifiedTemplateClass,Collection<? extends Template<?>> beforeTemplates,@Nullable Template<?> afterTemplate,ImmutableClasstoInstanceMap<Annotation> annotations) {

  checkState(!beforeTemplates.isEmpty(),"No @BeforeTemplate was found in the specified class: %s",qualifiedTemplateClass);
  Class<?> templateType = beforeTemplates.iterator().next().getClass();
  for (Template<?> beforeTemplate : beforeTemplates) {
    checkState(beforeTemplate.getClass().equals(templateType),"Expected all templates to be of type %s but found template of type %s in %s",templateType,beforeTemplate.getClass(),qualifiedTemplateClass);
  }
  if (afterTemplate != null) {
    checkState(afterTemplate.getClass().equals(templateType),afterTemplate.getClass(),qualifiedTemplateClass);
  }
  @SuppressWarnings("unchecked")
  RefasterRule<?,?> result = new Autovalue_RefasterRule(
      qualifiedTemplateClass,ImmutableList.copyOf(beforeTemplates),afterTemplate,annotations);
  return result;
}
项目:refactor-faster    文件TemplatingTest.java   
@Test
public void genericTemplate() {
  compile(
      "import java.util.List;","class GenericTemplateExample {","  public <E> E example(List<E> list) {","    return list.get(0);","  }","}");
  assertEquals(
      ExpressionTemplate.create(
          ImmutableClasstoInstanceMap.<Annotation>builder().build(),ImmutableList.of(UTypeVar.create("E")),ImmutableMap.of("list",UClasstype.create("java.util.List",UTypeVar.create("E"))),UMethodInvocation.create(
              UMemberSelect.create(
                  UFreeIdent.create("list"),"get",UMethodType.create(UTypeVar.create("E"),UPrimitiveType.INT)),ULiteral.intLit(0)),UTypeVar.create("E")),UTemplater.createTemplate(context,getmethodDeclaration("example")));
}
项目:refactor-faster    文件TemplatingTest.java   
@Test
public void recursiveTypes() {
  compile(
      "class RecursiveTypeExample {","  public <E extends Enum<E>> E example(E e) {","    return e;","}");
  Template<?> template = UTemplater.createTemplate(context,getmethodDeclaration("example"));
  UTypeVar eVar = Iterables.getonlyElement(template.typeVariables());
  assertEquals(
      ExpressionTemplate.create(
          ImmutableClasstoInstanceMap.<Annotation>builder().build(),ImmutableList.of(UTypeVar.create("E",UClasstype.create("java.lang.Enum",eVar))),ImmutableMap.of("e",eVar),UFreeIdent.create("e"),template);
}
项目:error-prone    文件UTemplater.java   
@SuppressWarnings("unchecked")
public static ImmutableClasstoInstanceMap<Annotation> annotationMap(Symbol symbol) {
  ImmutableClasstoInstanceMap.Builder<Annotation> builder = ImmutableClasstoInstanceMap.builder();
  for (Compound compound : symbol.getAnnotationMirrors()) {
    Name qualifiedAnnotationType =
        ((TypeElement) compound.getAnnotationType().asElement()).getQualifiedname();
    try {
      Class<? extends Annotation> annotationClazz =
          Class.forName(qualifiedAnnotationType.toString()).asSubclass(Annotation.class);
      builder.put(
          (Class) annotationClazz,e);
    }
  }
  return builder.build();
}
项目:error-prone    文件TemplatingTest.java   
@Test
public void genericTemplate() {
  compile(
      "import java.util.List;",getmethodDeclaration("example")));
}
项目:error-prone    文件TemplatingTest.java   
@Test
public void recursiveTypes() {
  compile(
      "class RecursiveTypeExample {",getmethodDeclaration("example"));
  UTypeVar eVar = Iterables.getonlyElement(template.templateTypeVariables());
  assertEquals(
      ExpressionTemplate.create(
          ImmutableClasstoInstanceMap.<Annotation>builder().build(),template);
}
项目:Refaster    文件UTemplater.java   
@SuppressWarnings("unchecked")
public static ImmutableClasstoInstanceMap<Annotation> annotationMap(Symbol symbol) {
  ImmutableClasstoInstanceMap.Builder<Annotation> builder = ImmutableClasstoInstanceMap.builder();
  for (Compound compound : symbol.getAnnotationMirrors()) {
    Name qualifiedAnnotationType =
        ((TypeElement) compound.getAnnotationType().asElement()).getQualifiedname();
    try {
      Class<? extends Annotation> annotationClazz = 
          Class.forName(qualifiedAnnotationType.toString()).asSubclass(Annotation.class);
      builder.put((Class) annotationClazz,e);
    }
  }
  return builder.build();
}
项目:Refaster    文件RefasterRule.java   
public static RefasterRule<?,annotations);
  return result;
}
项目:Refaster    文件TemplatingTest.java   
@Test
public void genericTemplate() {
  compile(
      "import java.util.List;",getmethodDeclaration("example")));
}
项目:Refaster    文件TemplatingTest.java   
@Test
public void recursiveTypes() {
  compile(
      "class RecursiveTypeExample {",template);
}
项目:nabl    文件StrategoTerms.java   
private <T extends IStrategoTerm> T putAttachments(T term,ImmutableClasstoInstanceMap<Object> attachments) {
    Optional<TermOrigin> origin = TermOrigin.get(attachments);
    if(origin.isPresent()) {
        origin.get().put(term);
    }

    Optional<TermIndex> index = TermIndex.get(attachments);
    if(index.isPresent()) {
        term = StrategoTermIndices.put(index.get(),term,termFactory);
    }

    StrategoAnnotations annotations = attachments.getInstance(StrategoAnnotations.class);
    if(annotations != null) {
        @SuppressWarnings({ "unchecked" }) T result = (T) termFactory.copyAttachments(term,termFactory.annotateTerm(term,termFactory.makeList(annotations.getAnnotationList())));
        term = result;
    }

    return term;
}
项目:nabl    文件StrategoTerms.java   
public ITerm fromStratego(IStrategoTerm term) {
    ImmutableClasstoInstanceMap<Object> attachments = getAttachments(term);
    ITerm rawTerm = match(term,StrategoTerms.<ITerm>cases(
        // @formatter:off
        appl -> TB.newAppl(appl.getConstructor().getName(),Arrays.asList(appl.getAllSubterms()).stream().map(this::fromStratego).collect(Collectors.toList())),tuple -> TB.newTuple(Arrays.asList(tuple.getAllSubterms()).stream().map(this::fromStratego).collect(Collectors.toList())),this::fromStrategoList,integer -> TB.newInt(integer.intValue()),real -> { throw new IllegalArgumentException("Real values are not supported."); },string -> TB.newString(string.stringValue())
        // @formatter:on
    )).withAttachments(attachments);
    return M.<ITerm>cases(
        // @formatter:off
        M.appl2(VAR_CTOR,M.stringValue(),(v,resource,name) ->
                TB.newVar(resource,name).withAttachments(v.getAttachments())),M.appl1(LIST_CTOR,M.list(),(t,xs) -> TB.newList(xs).withAttachments(t.getAttachments())),M.appl2(LISTTAIL_CTOR,M.term(),xs,ys) ->
                TB.newListTail(xs,(IListTerm) ys).withAttachments(t.getAttachments()))
        // @formatter:on
    ).match(rawTerm).orElse(rawTerm);
}
项目:hashsdn-controller    文件RootBindingAwarebroker.java   
public void start() {
    checkState(controllerRoot == null,"Binding Aware broker was already started.");
    LOG.info("Starting Binding Aware broker: {}",identifier);

    controllerRoot = new RootSalInstance(getRpcProviderRegistry(),getNotificationbroker());

    final ImmutableClasstoInstanceMap.Builder<BindingAwareService> consBuilder = ImmutableClasstoInstanceMap
            .builder();

    consBuilder.put(NotificationService.class,getRoot());
    consBuilder.put(RpcConsumerRegistry.class,getRoot());
    if (databroker != null) {
        consBuilder.put(Databroker.class,databroker);
    }
    consBuilder.put(MountPointService.class,mountService);

    supportedConsumerServices = consBuilder.build();
    final ImmutableClasstoInstanceMap.Builder<BindingAwareService> provBuilder = ImmutableClasstoInstanceMap
            .builder();
    provBuilder.putAll(supportedConsumerServices).put(NotificationProviderService.class,getRoot())
            .put(RpcProviderRegistry.class,getRoot());
    if (notificationPublishService != null) {
        provBuilder.put(NotificationPublishService.class,notificationPublishService);
    }

    supportedProviderServices = provBuilder.build();
}
项目:FinanceAnalytics    文件ServiceContext.java   
/**
 * Returns a copy of this context with the map of services added.
 * <p>
 * If any services are provided that are already registered,the service registry
 * will be updated with the provided services.
 * 
 * @param services  a map of services objects keyed by their class,not null
 * @return an updated service context
 */
public ServiceContext with(Map<Class<?>,Object> services) {
  // We have to calculate which of the original objects need to be
  // retained as ImmutableMap.Builder won't allow a key to be put
  // more than once
  ArgumentChecker.noNulls(services,"services");
  Map<Class<?>,Object> unchanged = Maps.difference(_services,services).entriesOnlyOnLeft();
  ImmutableClasstoInstanceMap<Object> combined = ImmutableClasstoInstanceMap.builder()
          .putAll(services)
          .putAll(unchanged)
          .build();
  return new ServiceContext(combined);
}
项目:tensorics-core    文件Coordinates.java   
/**
 * Creates a class to instance map,from the given coordinates. The map will contain the classes of the coordinates
 * as keys and the coordinates themselves as values. Duplicate keys (dimensions) are not allowed and will result in
 * an {@link IllegalArgumentException}.
 * 
 * @param coordinates the coordinates to be added to the map
 * @return an immutable map from dimensions (coordinate classes) to coordinate
 * @throws IllegalArgumentException if more than one coordinate per dimension are provided
 * @deprecated
 */
@Deprecated
public static <C> ClasstoInstanceMap<C> mapOf(Iterable<? extends C> coordinates) {
    ImmutableClasstoInstanceMap.Builder<C> coordinateBuilder = ImmutableClasstoInstanceMap.builder();
    for (C coordinate : coordinates) {
        @SuppressWarnings("unchecked")
        Class<C> coordinateClass = (Class<C>) coordinate.getClass();
        coordinateBuilder.put(coordinateClass,coordinate);
    }
    return coordinateBuilder.build();
}
项目:tensorics-core    文件ImmutableOptionRegistry.java   
private <T1 extends Option<T1>> ImmutableOptionRegistry(Collection<T> options) {
    /*
     * we first have to create a mutable map,because the collection might contain options of the same class,where
     * later ones will override prevIoUs ones. This would not be allowed by the builder of the immutable map.
     */
    ClasstoInstanceMap<T> mutableOptions = MutableClasstoInstanceMap.create();
    addToMap(mutableOptions,options);
    this.options = ImmutableClasstoInstanceMap.copyOf(mutableOptions);
}
项目:refactor-faster    文件BlockTemplate.java   
public static BlockTemplate create(
    Iterable<UTypeVar> typeVariables,Map<String,? extends UType> expressionArgumentTypes,UStatement... templateStatements) {
  return create(
      ImmutableClasstoInstanceMap.<Annotation>builder().build(),typeVariables,expressionArgumentTypes,ImmutableList.copyOf(templateStatements));
}
项目:refactor-faster    文件BlockTemplate.java   
public static BlockTemplate create(
    ImmutableClasstoInstanceMap<Annotation> annotations,Iterable<UTypeVar> typeVariables,Iterable<? extends UStatement> templateStatements) {
  return new Autovalue_BlockTemplate(
      annotations,ImmutableList.copyOf(typeVariables),ImmutableMap.copyOf(expressionArgumentTypes),ImmutableList.copyOf(templateStatements));        
}
项目:refactor-faster    文件BugCheckerTransformer.java   
@SuppressWarnings("unchecked")
@Override
public ImmutableClasstoInstanceMap<Annotation> annotations() {
  ImmutableClasstoInstanceMap.Builder<Annotation> builder = ImmutableClasstoInstanceMap.builder();
  for (Annotation annotation : checker().getClass().getDeclaredAnnotations()) {
    builder.put((Class) annotation.annotationType(),annotation);
  }
  return builder.build();
}
项目:refactor-faster    文件ExpressionTemplate.java   
public static ExpressionTemplate create(
    Map<String,UExpression expression,UType returnType) {
  return create(
      ImmutableClasstoInstanceMap.<Annotation>builder().build(),ImmutableList.<UTypeVar>of(),expression,returnType);
}
项目:refactor-faster    文件ExpressionTemplate.java   
public static ExpressionTemplate create(
    ImmutableClasstoInstanceMap<Annotation> annotations,UType returnType) {
  return new Autovalue_ExpressionTemplate(
      annotations,returnType);
}
项目:refactor-faster    文件TemplatingTest.java   
@Test
public void genericmethodInvocation() {
  compile(
      "import java.util.Collections;","import java.util.List;","  public <E> List<E> example(List<E> list) {","    return Collections.unmodifiableList(list);","}");
  UTypeVar tvar = UTypeVar.create("T");
  UTypeVar eVar = UTypeVar.create("E");
  assertEquals(
      ExpressionTemplate.create(
          ImmutableClasstoInstanceMap.<Annotation>builder().build(),ImmutableList.of(eVar),eVar)),UMethodInvocation.create(
              UStaticIdent.create(
                  "java.util.Collections","unmodifiableList",UForAll.create(
                      ImmutableList.of(tvar),UMethodType.create(
                          UClasstype.create("java.util.List",tvar),UClasstype.create(
                              "java.util.List",UWildcardType.create(BoundKind.EXTENDS,tvar))))),UFreeIdent.create("list")),getmethodDeclaration("example")));
}
项目:refactor-faster    文件UnificationTest.java   
@Test
public void recursiveType() {
  /*
   * Template:
   * <E extends Enum<E>> String example(E e) {
   *  return e.name();
   * }
   */
  UTypeVar eTypeVar = UTypeVar.create("E");
  eTypeVar.setUpperBound(UClasstype.create("java.lang.Enum",eTypeVar));
  ExpressionTemplate template = ExpressionTemplate.create(
      ImmutableClasstoInstanceMap.<Annotation>builder().build(),ImmutableList.of(eTypeVar),ImmutableMap.of("value",eTypeVar),UMethodInvocation.create(
          UMemberSelect.create(UFreeIdent.create("value"),"name",UMethodType.create(UClasstype.create("java.lang.String")))),UClasstype.create("java.lang.String"));
  compile(
      "import java.math.RoundingMode;","class RecursiveTypeExample {","  public void example() {","    System.out.println(RoundingMode.FLOOR.name());","}");
  expectMatches(template,Match.create(ImmutableMap.of(
          "value","RoundingMode.FLOOR","E","java.math.RoundingMode")));
}
项目:error-prone    文件RefasterRule.java   
public static RefasterRule<?,?> create(
    String qualifiedTemplateClass,Collection<? extends Template<?>> afterTemplates) {
  return create(
      qualifiedTemplateClass,beforeTemplates,afterTemplates,ImmutableClasstoInstanceMap.<Annotation>builder().build());
}
项目:error-prone    文件RefasterRule.java   
public static RefasterRule<?,Collection<? extends Template<?>> afterTemplates,ImmutableClasstoInstanceMap<Annotation> annotations) {

  checkState(
      !beforeTemplates.isEmpty(),qualifiedTemplateClass);
  Class<?> templateType = beforeTemplates.iterator().next().getClass();
  for (Template<?> beforeTemplate : beforeTemplates) {
    checkState(
        beforeTemplate.getClass().equals(templateType),qualifiedTemplateClass);
  }
  for (Template<?> afterTemplate : afterTemplates) {
    checkState(
        afterTemplate.getClass().equals(templateType),qualifiedTemplateClass);
  }
  @SuppressWarnings({"unchecked","rawtypes"})
  RefasterRule<?,?> result =
      new Autovalue_RefasterRule(
          qualifiedTemplateClass,ImmutableList.copyOf(afterTemplates),annotations);
  return result;
}
项目:error-prone    文件BlockTemplate.java   
public static BlockTemplate create(
    Iterable<UTypeVar> typeVariables,ImmutableList.copyOf(templateStatements));
}
项目:error-prone    文件BlockTemplate.java   
public static BlockTemplate create(
    ImmutableClasstoInstanceMap<Annotation> annotations,ImmutableList.copyOf(templateStatements));
}
项目:error-prone    文件ExpressionTemplate.java   
public static ExpressionTemplate create(
    Map<String,returnType);
}
项目:error-prone    文件ExpressionTemplate.java   
public static ExpressionTemplate create(
    ImmutableClasstoInstanceMap<Annotation> annotations,returnType);
}
项目:error-prone    文件PlaceholderMethod.java   
static PlaceholderMethod create(
    CharSequence name,UType returnType,ImmutableMap<UVariableDecl,ImmutableClasstoInstanceMap<Annotation>> parameters,ClasstoInstanceMap<Annotation> annotations) {
  final boolean allowsIdentity = annotations.getInstance(Placeholder.class).allowsIdentity();
  final Class<? extends Matcher<? super ExpressionTree>> matchesClass =
      annotations.containsKey(Matches.class)
          ? UTemplater.getValue(annotations.getInstance(Matches.class))
          : null;
  final Class<? extends Matcher<? super ExpressionTree>> notMatchesClass =
      annotations.containsKey(NotMatches.class)
          ? UTemplater.getValue(annotations.getInstance(NotMatches.class))
          : null;
  final Predicate<Tree.Kind> allowedKinds =
      annotations.containsKey(OfKind.class)
          ? Predicates.<Tree.Kind>in(Arrays.asList(annotations.getInstance(OfKind.class).value()))
          : Predicates.<Tree.Kind>alwaysTrue();
  class PlaceholderMatcher implements Serializable,Matcher<ExpressionTree> {

    @Override
    public boolean matches(ExpressionTree t,VisitorState state) {
      try {
        return (allowsIdentity || !(t instanceof PlaceholderParamIdent))
            && (matchesClass == null || matchesClass.newInstance().matches(t,state))
            && (notMatchesClass == null || !notMatchesClass.newInstance().matches(t,state))
            && allowedKinds.apply(t.getKind());
      } catch (InstantiationException | illegalaccessexception e) {
        throw new RuntimeException(e);
      }
    }
  }
  return new Autovalue_PlaceholderMethod(
      StringName.of(name),returnType,parameters,new PlaceholderMatcher(),ImmutableClasstoInstanceMap.<Annotation,Annotation>copyOf(annotations));
}
项目:error-prone    文件PlaceholderMethod.java   
/** Parameters which must be referenced in any tree matched to this placeholder. */
Set<UVariableDecl> requiredParameters() {
  return Maps.filterValues(
          annotatedParameters(),(ImmutableClasstoInstanceMap<Annotation> annotations) ->
              !annotations.containsKey(MayOptionallyUse.class))
      .keySet();
}
项目:error-prone    文件TemplatingTest.java   
@Test
public void genericmethodInvocation() {
  compile(
      "import java.util.Collections;",getmethodDeclaration("example")));
}
项目:error-prone    文件UnificationTest.java   
@Test
public void recursiveType() {
  /*
   * Template:
   * <E extends Enum<E>> String example(E e) {
   *  return e.name();
   * }
   */
  UTypeVar eTypeVar = UTypeVar.create("E");
  eTypeVar.setUpperBound(UClasstype.create("java.lang.Enum",eTypeVar));
  ExpressionTemplate template =
      ExpressionTemplate.create(
          ImmutableClasstoInstanceMap.<Annotation>builder().build(),UMethodInvocation.create(
              UMemberSelect.create(
                  UFreeIdent.create("value"),"}");
  expectMatches(
      template,Match.create(
          ImmutableMap.of(
              "value","java.math.RoundingMode")));
}
项目:Refaster    文件BlockTemplate.java   
public static BlockTemplate create(
    Iterable<UTypeVar> typeVariables,ImmutableList.copyOf(templateStatements));
}
项目:Refaster    文件BlockTemplate.java   
public static BlockTemplate create(
    ImmutableClasstoInstanceMap<Annotation> annotations,ImmutableList.copyOf(templateStatements));        
}
项目:Refaster    文件BugCheckerTransformer.java   
@SuppressWarnings("unchecked")
@Override
public ImmutableClasstoInstanceMap<Annotation> annotations() {
  ImmutableClasstoInstanceMap.Builder<Annotation> builder = ImmutableClasstoInstanceMap.builder();
  for (Annotation annotation : checker().getClass().getDeclaredAnnotations()) {
    builder.put((Class) annotation.annotationType(),annotation);
  }
  return builder.build();
}
项目:Refaster    文件ExpressionTemplate.java   
public static ExpressionTemplate create(
    Map<String,returnType);
}
项目:Refaster    文件ExpressionTemplate.java   
public static ExpressionTemplate create(
    ImmutableClasstoInstanceMap<Annotation> annotations,returnType);
}
项目:Refaster    文件TemplatingTest.java   
@Test
public void genericmethodInvocation() {
  compile(
      "import java.util.Collections;",getmethodDeclaration("example")));
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。