本文整理汇总了Java中com.google.common.collect.ImmutableClassToInstanceMap类的典型用法代码示例。如果您正苦于以下问题:Java ImmutableClassToInstanceMap类的具体用法?Java ImmutableClassToInstanceMap怎么用?Java ImmutableClassToInstanceMap使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ImmutableClassToInstanceMap类属于com.google.common.collect包,在下文中一共展示了ImmutableClassToInstanceMap类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: annotationMap
import com.google.common.collect.ImmutableClassToInstanceMap; //导入依赖的package包/类
@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();
}
示例2: create
import com.google.common.collect.ImmutableClassToInstanceMap; //导入依赖的package包/类
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),
"Expected all templates to be of type %s but found template of type %s in %s",
templateType, afterTemplate.getClass(), qualifiedTemplateClass);
}
@SuppressWarnings("unchecked")
RefasterRule<?, ?> result = new AutoValue_RefasterRule(
qualifiedTemplateClass, ImmutableList.copyOf(beforeTemplates), afterTemplate, annotations);
return result;
}
示例3: genericTemplate
import com.google.common.collect.ImmutableClassToInstanceMap; //导入依赖的package包/类
@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")));
}
示例4: recursiveTypes
import com.google.common.collect.ImmutableClassToInstanceMap; //导入依赖的package包/类
@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"),
eVar),
template);
}
示例5: annotationMap
import com.google.common.collect.ImmutableClassToInstanceMap; //导入依赖的package包/类
@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();
}
示例6: genericTemplate
import com.google.common.collect.ImmutableClassToInstanceMap; //导入依赖的package包/类
@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")));
}
示例7: recursiveTypes
import com.google.common.collect.ImmutableClassToInstanceMap; //导入依赖的package包/类
@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.templateTypeVariables());
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"),
eVar),
template);
}
示例8: putAttachments
import com.google.common.collect.ImmutableClassToInstanceMap; //导入依赖的package包/类
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;
}
示例9: fromStratego
import com.google.common.collect.ImmutableClassToInstanceMap; //导入依赖的package包/类
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(), 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.list(), M.term(), (t,xs,ys) ->
TB.newListTail(xs, (IListTerm) ys).withAttachments(t.getAttachments()))
// @formatter:on
).match(rawTerm).orElse(rawTerm);
}
示例10: start
import com.google.common.collect.ImmutableClassToInstanceMap; //导入依赖的package包/类
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();
}
示例11: with
import com.google.common.collect.ImmutableClassToInstanceMap; //导入依赖的package包/类
/**
* 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);
}
示例12: mapOf
import com.google.common.collect.ImmutableClassToInstanceMap; //导入依赖的package包/类
/**
* 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();
}
示例13: ImmutableOptionRegistry
import com.google.common.collect.ImmutableClassToInstanceMap; //导入依赖的package包/类
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);
}
示例14: create
import com.google.common.collect.ImmutableClassToInstanceMap; //导入依赖的package包/类
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));
}
示例15: annotations
import com.google.common.collect.ImmutableClassToInstanceMap; //导入依赖的package包/类
@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();
}