com.google.common.collect.ImmutableClassToInstanceMap#Builder ( )源码实例Demo

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

源代码1 项目: 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,
          AnnotationProxyMaker.generateAnnotation(compound, annotationClazz));
    } catch (ClassNotFoundException e) {
      throw new IllegalArgumentException("Unrecognized annotation type", e);
    }
  }
  return builder.build();
}
 
private static ClassToInstanceMap<Context> getContextMap(UUID actionUUID, Player player, VirtualChestHandheldItem itemTemplate)
{
    ImmutableClassToInstanceMap.Builder<Context> contextBuilder = ImmutableClassToInstanceMap.builder();

    contextBuilder.put(Context.HANDHELD_ITEM, new HandheldItemContext(itemTemplate::matchItem));
    contextBuilder.put(Context.ACTION_UUID, new ActionUUIDContext(actionUUID));
    contextBuilder.put(Context.PLAYER, new PlayerContext(player));

    return contextBuilder.build();
}
 
源代码3 项目: 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();
}