本文整理汇总了Java中com.google.common.collect.ImmutableClassToInstanceMap.containsKey方法的典型用法代码示例。如果您正苦于以下问题:Java ImmutableClassToInstanceMap.containsKey方法的具体用法?Java ImmutableClassToInstanceMap.containsKey怎么用?Java ImmutableClassToInstanceMap.containsKey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.collect.ImmutableClassToInstanceMap
的用法示例。
在下文中一共展示了ImmutableClassToInstanceMap.containsKey方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createTemplate
import com.google.common.collect.ImmutableClassToInstanceMap; //导入方法依赖的package包/类
/**
* Returns a template based on a method. One-line methods starting with a {@code return} statement
* are guessed to be expression templates, and all other methods are guessed to be block
* templates.
*/
public static Template<?> createTemplate(Context context, MethodTree decl) {
MethodSymbol declSym = ASTHelpers.getSymbol(decl);
ImmutableClassToInstanceMap<Annotation> annotations = UTemplater.annotationMap(declSym);
ImmutableMap<String, VarSymbol> freeExpressionVars = freeExpressionVariables(decl);
Context subContext = new SubContext(context);
if (annotations.containsKey(AlsoReverseTernary.class)) {
subContext.put(AlsoReverseTernary.class, annotations.getInstance(AlsoReverseTernary.class));
}
final UTemplater templater = new UTemplater(freeExpressionVars, subContext);
ImmutableMap<String, UType> expressionVarTypes = ImmutableMap.copyOf(
Maps.transformValues(freeExpressionVars, new Function<VarSymbol, UType>() {
@Override
public UType apply(VarSymbol sym) {
return templater.template(sym.type);
}
}));
UType genericType = templater.template(declSym.type);
List<UTypeVar> typeParameters;
UMethodType methodType;
if (genericType instanceof UForAll) {
UForAll forAllType = (UForAll) genericType;
typeParameters = forAllType.getTypeVars();
methodType = (UMethodType) forAllType.getQuantifiedType();
} else if (genericType instanceof UMethodType) {
typeParameters = ImmutableList.of();
methodType = (UMethodType) genericType;
} else {
throw new IllegalArgumentException(
"Expected genericType to be either a ForAll or a UMethodType, but was " + genericType);
}
List<? extends StatementTree> bodyStatements = decl.getBody().getStatements();
if (bodyStatements.size() == 1
&& Iterables.getOnlyElement(bodyStatements).getKind() == Kind.RETURN
&& context.get(REQUIRE_BLOCK_KEY) == null) {
ExpressionTree expression =
((ReturnTree) Iterables.getOnlyElement(bodyStatements)).getExpression();
return ExpressionTemplate.create(
annotations, typeParameters, expressionVarTypes,
templater.template(expression), methodType.getReturnType());
} else {
List<UStatement> templateStatements = new ArrayList<>();
for (StatementTree statement : bodyStatements) {
templateStatements.add(templater.template(statement));
}
return BlockTemplate.create(annotations,
typeParameters, expressionVarTypes, templateStatements);
}
}