本文整理汇总了Java中com.google.javascript.rhino.jstype.TemplateType类的典型用法代码示例。如果您正苦于以下问题:Java TemplateType类的具体用法?Java TemplateType怎么用?Java TemplateType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TemplateType类属于com.google.javascript.rhino.jstype包,在下文中一共展示了TemplateType类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: inferTemplateTypesFromParameters
import com.google.javascript.rhino.jstype.TemplateType; //导入依赖的package包/类
private Map<TemplateType, JSType> inferTemplateTypesFromParameters(
FunctionType fnType, Node call) {
if (fnType.getTemplateKeys().isEmpty()) {
return Collections.emptyMap();
}
Map<TemplateType, JSType> resolvedTypes = Maps.newIdentityHashMap();
Node callTarget = call.getFirstChild();
if (NodeUtil.isGet(callTarget)) {
Node obj = callTarget.getFirstChild();
maybeResolveTemplatedType(
fnType.getTypeOfThis(),
getJSType(obj),
resolvedTypes);
}
if (call.hasMoreThanOneChild()) {
maybeResolveTemplateTypeFromNodes(
fnType.getParameters(),
call.getChildAtIndex(1).siblings(),
resolvedTypes);
}
return resolvedTypes;
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:26,代码来源:TypeInference.java
示例2: maybeResolveTemplateTypeFromNodes
import com.google.javascript.rhino.jstype.TemplateType; //导入依赖的package包/类
private void maybeResolveTemplateTypeFromNodes(
Iterator<Node> declParams,
Iterator<Node> callParams,
Map<TemplateType, JSType> resolvedTypes) {
while (declParams.hasNext() && callParams.hasNext()) {
Node declParam = declParams.next();
maybeResolveTemplatedType(
getJSType(declParam),
getJSType(callParams.next()),
resolvedTypes);
if (declParam.isVarArgs()) {
while (callParams.hasNext()) {
maybeResolveTemplatedType(
getJSType(declParam),
getJSType(callParams.next()),
resolvedTypes);
}
}
}
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:21,代码来源:TypeInference.java
示例3: inferTemplatedTypesForCall
import com.google.javascript.rhino.jstype.TemplateType; //导入依赖的package包/类
/**
* For functions with function(this: T, ...) and T as parameters, type
* inference will set the type of this on a function literal argument to the
* the actual type of T.
*/
private boolean inferTemplatedTypesForCall(
Node n, FunctionType fnType) {
if (fnType.getTemplateKeys().isEmpty()) {
return false;
}
// Try to infer the template types
Map<TemplateType, JSType> inferred = inferTemplateTypesFromParameters(
fnType, n);
// Replace all template types. If we couldn't find a replacement, we
// replace it with UNKNOWN.
TemplateTypeReplacer replacer = new TemplateTypeReplacer(
registry, inferred);
Node callTarget = n.getFirstChild();
FunctionType replacementFnType = fnType.visit(replacer)
.toMaybeFunctionType();
Preconditions.checkNotNull(replacementFnType);
callTarget.setJSType(replacementFnType);
n.setJSType(replacementFnType.getReturnType());
return replacer.madeChanges;
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:31,代码来源:TypeInference.java
示例4: maybeResolveTemplateTypeFromNodes
import com.google.javascript.rhino.jstype.TemplateType; //导入依赖的package包/类
private void maybeResolveTemplateTypeFromNodes(
Iterator<Node> declParams,
Iterator<Node> callParams,
Map<TemplateType, JSType> resolvedTypes,
Set<JSType> seenTypes) {
while (declParams.hasNext() && callParams.hasNext()) {
Node declParam = declParams.next();
maybeResolveTemplatedType(
getJSType(declParam),
getJSType(callParams.next()),
resolvedTypes, seenTypes);
if (declParam.isVarArgs()) {
while (callParams.hasNext()) {
maybeResolveTemplatedType(
getJSType(declParam),
getJSType(callParams.next()),
resolvedTypes, seenTypes);
}
}
}
}
开发者ID:google,项目名称:closure-compiler,代码行数:22,代码来源:TypeInference.java
示例5: caseTemplateType
import com.google.javascript.rhino.jstype.TemplateType; //导入依赖的package包/类
@Override
public JSType caseTemplateType(TemplateType type) {
if (replacements.hasTemplateKey(type)) {
if (hasVisitedType(type) || !replacements.hasTemplateType(type)) {
// If we have already encountered this TemplateType during replacement
// (i.e. there is a reference loop), or there is no JSType substitution
// for the TemplateType, return the TemplateType type itself.
return type;
} else {
JSType replacement = replacements.getTemplateType(type);
visitedTypes.push(type);
JSType visitedReplacement = replacement.visit(this);
visitedTypes.pop();
return visitedReplacement;
}
} else {
return type;
}
}
开发者ID:nicks,项目名称:closure-compiler-old,代码行数:22,代码来源:TemplateTypeMapReplacer.java
示例6: visitTemplateTypes
import com.google.javascript.rhino.jstype.TemplateType; //导入依赖的package包/类
/**
* Emits template types for a given type. For example for <code>T<A,B></code>, this method will
* emit <code><A,B></code>.
*
* @param type the type in question
* @param alreadyEmittedTemplateType when visiting methods the class template types will be
* reported by closure, but should not be emitted.
* @param isDeclaration isDeclaration {@pre true} if this type declares the template types,
* {@pre false} if it instantiates a generic type. In the former case, Clutz emits defaults
* for the template parameters.
*/
private void visitTemplateTypes(
ObjectType type, List<String> alreadyEmittedTemplateType, boolean isDeclaration) {
if (type.hasAnyTemplateTypes() && !type.getTemplateTypeMap().isEmpty()) {
List<String> realTemplateType = new ArrayList<>();
for (TemplateType templateType : type.getTemplateTypeMap().getTemplateKeys()) {
String displayName = templateType.getDisplayName();
// Some template variables can be already defined at the class definition.
// Closure and TypeScript disagree in that case, in closure redeclaring a class template
// variable at a method does nothing, but in Typescript it introduces a new variable.
// To preserve the semantics from closure we skip emitting redeclared variables.
if (alreadyEmittedTemplateType.contains(displayName)) {
continue;
}
if (displayName.contains("IObject#")) {
displayName = normalizeIObjectTemplateName(type, displayName);
}
// When we emit partial programs, we cannot differentiate whether Foo
// is a plain type or a generic type for which closure infers '?' as
// all type arguments.
// To support this usecase we emit ' = any' for all generic args.
if (opts.partialInput && isDeclaration) {
displayName += " = any";
}
if (displayName != null) {
realTemplateType.add(displayName);
}
}
if (!realTemplateType.isEmpty()) {
emit("<");
emit(Joiner.on(" , ").join(realTemplateType));
emit(">");
}
}
}
开发者ID:angular,项目名称:clutz,代码行数:51,代码来源:DeclarationGenerator.java
示例7: maybeEmitSymbolIterator
import com.google.javascript.rhino.jstype.TemplateType; //导入依赖的package包/类
/**
* Emits a [Symbol.iterator] property on the class if it extends Iterator.
*
* <p>JSCompiler does not understand nor represent Symbol properties, so we cannot just emit the
* property in the loop above, and must guess on the actual return type of the iterator method.
*/
private void maybeEmitSymbolIterator(JSType instanceType) {
if (instanceType == null) {
return;
}
// iteratorIterableType and iterableType can be null if they were not found in the current
// run's externs definitions.
JSType implemented;
String returnType;
if (iteratorIterableType != null && instanceType.isSubtype(iteratorIterableType)) {
implemented = iteratorIterableType;
returnType = "IterableIterator";
} else if (iterableType != null && instanceType.isSubtype(iterableType)) {
implemented = iterableType;
returnType = "Iterator";
} else {
return;
}
emitComment("Symbol.iterator inserted by Clutz for Iterable subtype");
emit("[Symbol.iterator](): ");
// The actual implementation of iterator could be an arbitrary subtype of Iterable. Emit
// the type of the interface as the next best thing.
emit(returnType);
emit("<");
TemplateType templateType = implemented.getTemplateTypeMap().getTemplateKeys().get(0);
TemplateTypeMap ttMap = instanceType.getTemplateTypeMap();
// Known issue: ttMap does not expose getUnresolvedTemplateType, which would be required
// to correctly emit unbound template parameters, e.g. "<T>".
JSType resolvedTemplateType = ttMap.getResolvedTemplateType(templateType);
visitType(resolvedTemplateType, false, false);
emit(">");
emit(";");
emitBreak();
}
开发者ID:angular,项目名称:clutz,代码行数:40,代码来源:DeclarationGenerator.java
示例8: resolvedTemplateType
import com.google.javascript.rhino.jstype.TemplateType; //导入依赖的package包/类
private void resolvedTemplateType(
Map<TemplateType, JSType> map, TemplateType template, JSType resolved) {
JSType previous = map.get(template);
if (!resolved.isUnknownType()) {
if (previous == null) {
map.put(template, resolved);
} else {
JSType join = previous.getLeastSupertype(resolved);
map.put(template, join);
}
}
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:13,代码来源:TypeInference.java
示例9: caseTemplateType
import com.google.javascript.rhino.jstype.TemplateType; //导入依赖的package包/类
@Override
public JSType caseTemplateType(TemplateType type) {
madeChanges = true;
JSType replacement = replacements.get(type);
return replacement != null ?
replacement : registry.getNativeType(UNKNOWN_TYPE);
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:8,代码来源:TypeInference.java
示例10: getDeclaredTypeInAnnotation
import com.google.javascript.rhino.jstype.TemplateType; //导入依赖的package包/类
/**
* Returns the type specified in a JSDoc annotation near a GETPROP or NAME.
*
* Extracts type information from either the {@code @type} tag or from
* the {@code @return} and {@code @param} tags.
*/
private JSType getDeclaredTypeInAnnotation(Node node, JSDocInfo info) {
JSType jsType = null;
if (info != null) {
if (info.hasType()) {
ImmutableList<TemplateType> ownerTypeKeys = ImmutableList.of();
Node ownerNode = NodeUtil.getBestLValueOwner(node);
String ownerName = NodeUtil.getBestLValueName(ownerNode);
ObjectType ownerType = null;
if (ownerName != null) {
TypedVar ownerVar = scope.getVar(ownerName);
if (ownerVar != null) {
ownerType = getPrototypeOwnerType(
ObjectType.cast(ownerVar.getType()));
if (ownerType != null) {
ownerTypeKeys =
ownerType.getTemplateTypeMap().getTemplateKeys();
}
}
}
if (!ownerTypeKeys.isEmpty()) {
typeRegistry.setTemplateTypeNames(ownerTypeKeys);
}
jsType = info.getType().evaluate(scope, typeRegistry);
if (!ownerTypeKeys.isEmpty()) {
typeRegistry.clearTemplateTypeNames();
}
} else if (FunctionTypeBuilder.isFunctionTypeDeclaration(info)) {
String fnName = node.getQualifiedName();
jsType = createFunctionTypeFromNodes(
null, fnName, info, node);
}
}
return jsType;
}
开发者ID:google,项目名称:closure-compiler,代码行数:45,代码来源:TypedScopeCreator.java
示例11: inferTemplateTypesFromParameters
import com.google.javascript.rhino.jstype.TemplateType; //导入依赖的package包/类
private Map<TemplateType, JSType> inferTemplateTypesFromParameters(
FunctionType fnType, Node call) {
if (fnType.getTemplateTypeMap().getTemplateKeys().isEmpty()) {
return Collections.emptyMap();
}
Map<TemplateType, JSType> resolvedTypes = Maps.newIdentityHashMap();
Set<JSType> seenTypes = Sets.newIdentityHashSet();
Node callTarget = call.getFirstChild();
if (NodeUtil.isGet(callTarget)) {
Node obj = callTarget.getFirstChild();
maybeResolveTemplatedType(
fnType.getTypeOfThis(),
getJSType(obj).restrictByNotNullOrUndefined(),
resolvedTypes,
seenTypes);
}
if (call.hasMoreThanOneChild()) {
maybeResolveTemplateTypeFromNodes(
fnType.getParameters(),
call.getSecondChild().siblings(),
resolvedTypes,
seenTypes);
}
return resolvedTypes;
}
开发者ID:google,项目名称:closure-compiler,代码行数:29,代码来源:TypeInference.java
示例12: resolvedTemplateType
import com.google.javascript.rhino.jstype.TemplateType; //导入依赖的package包/类
private static void resolvedTemplateType(
Map<TemplateType, JSType> map, TemplateType template, JSType resolved) {
JSType previous = map.get(template);
if (!resolved.isUnknownType()) {
if (previous == null) {
map.put(template, resolved);
} else {
JSType join = previous.getLeastSupertype(resolved);
map.put(template, join);
}
}
}
开发者ID:google,项目名称:closure-compiler,代码行数:13,代码来源:TypeInference.java
示例13: buildTypeVariables
import com.google.javascript.rhino.jstype.TemplateType; //导入依赖的package包/类
/**
* Build the type environment where type transformations will be evaluated.
* It only considers the template type variables that do not have a type
* transformation.
*/
private Map<String, JSType> buildTypeVariables(
Map<TemplateType, JSType> inferredTypes) {
Map<String, JSType> typeVars = new LinkedHashMap<>();
for (Entry<TemplateType, JSType> e : inferredTypes.entrySet()) {
// Only add the template type that do not have a type transformation
if (!e.getKey().isTypeTransformation()) {
typeVars.put(e.getKey().getReferenceName(), e.getValue());
}
}
return typeVars;
}
开发者ID:google,项目名称:closure-compiler,代码行数:17,代码来源:TypeInference.java
示例14: evaluateTypeTransformations
import com.google.javascript.rhino.jstype.TemplateType; //导入依赖的package包/类
/**
* This function will evaluate the type transformations associated to the
* template types
*/
private Map<TemplateType, JSType> evaluateTypeTransformations(
ImmutableList<TemplateType> templateTypes,
Map<TemplateType, JSType> inferredTypes) {
Map<String, JSType> typeVars = null;
Map<TemplateType, JSType> result = null;
TypeTransformation ttlObj = null;
for (TemplateType type : templateTypes) {
if (type.isTypeTransformation()) {
// Lazy initialization when the first type transformation is found
if (ttlObj == null) {
ttlObj = new TypeTransformation(compiler, syntacticScope);
typeVars = buildTypeVariables(inferredTypes);
result = new LinkedHashMap<>();
}
// Evaluate the type transformation expression using the current
// known types for the template type variables
@SuppressWarnings({"unchecked", "rawtypes"})
JSType transformedType = (JSType) ttlObj.eval(
type.getTypeTransformation(),
(ImmutableMap) ImmutableMap.copyOf(typeVars));
result.put(type, transformedType);
// Add the transformed type to the type variables
typeVars.put(type.getReferenceName(), transformedType);
}
}
return result;
}
开发者ID:google,项目名称:closure-compiler,代码行数:34,代码来源:TypeInference.java
示例15: inferTemplatedTypesForCall
import com.google.javascript.rhino.jstype.TemplateType; //导入依赖的package包/类
/**
* For functions that use template types, specialize the function type for
* the call target based on the call-site specific arguments.
* Specifically, this enables inference to set the type of any function
* literal parameters based on these inferred types.
*/
private boolean inferTemplatedTypesForCall(Node n, FunctionType fnType) {
ImmutableList<TemplateType> keys = fnType.getTemplateTypeMap().getTemplateKeys();
if (keys.isEmpty()) {
return false;
}
// Try to infer the template types
Map<TemplateType, JSType> rawInferrence = inferTemplateTypesFromParameters(fnType, n);
Map<TemplateType, JSType> inferred = Maps.newIdentityHashMap();
for (TemplateType key : keys) {
JSType type = rawInferrence.get(key);
if (type == null) {
type = unknownType;
}
inferred.put(key, type);
}
// Try to infer the template types using the type transformations
Map<TemplateType, JSType> typeTransformations = evaluateTypeTransformations(keys, inferred);
if (typeTransformations != null) {
inferred.putAll(typeTransformations);
}
// Replace all template types. If we couldn't find a replacement, we
// replace it with UNKNOWN.
TemplateTypeReplacer replacer = new TemplateTypeReplacer(registry, inferred);
Node callTarget = n.getFirstChild();
FunctionType replacementFnType = fnType.visit(replacer).toMaybeFunctionType();
checkNotNull(replacementFnType);
callTarget.setJSType(replacementFnType);
n.setJSType(replacementFnType.getReturnType());
return replacer.madeChanges;
}
开发者ID:google,项目名称:closure-compiler,代码行数:42,代码来源:TypeInference.java
示例16: traverseNew
import com.google.javascript.rhino.jstype.TemplateType; //导入依赖的package包/类
private FlowScope traverseNew(Node n, FlowScope scope) {
scope = traverseChildren(n, scope);
Node constructor = n.getFirstChild();
JSType constructorType = constructor.getJSType();
JSType type = null;
if (constructorType != null) {
constructorType = constructorType.restrictByNotNullOrUndefined();
if (constructorType.isUnknownType()) {
type = unknownType;
} else {
FunctionType ct = constructorType.toMaybeFunctionType();
if (ct == null && constructorType instanceof FunctionType) {
// If constructorType is a NoObjectType, then toMaybeFunctionType will
// return null. But NoObjectType implements the FunctionType
// interface, precisely because it can validly construct objects.
ct = (FunctionType) constructorType;
}
if (ct != null && ct.isConstructor()) {
backwardsInferenceFromCallSite(n, ct);
// If necessary, create a TemplatizedType wrapper around the instance
// type, based on the types of the constructor parameters.
ObjectType instanceType = ct.getInstanceType();
Map<TemplateType, JSType> inferredTypes =
inferTemplateTypesFromParameters(ct, n);
if (inferredTypes.isEmpty()) {
type = instanceType;
} else {
type = registry.createTemplatizedType(instanceType, inferredTypes);
}
}
}
}
n.setJSType(type);
return scope;
}
开发者ID:google,项目名称:closure-compiler,代码行数:38,代码来源:TypeInference.java
示例17: hasVisitedType
import com.google.javascript.rhino.jstype.TemplateType; //导入依赖的package包/类
/**
* Checks if the specified type has already been visited during the Visitor's
* traversal of a JSType.
*/
private boolean hasVisitedType(TemplateType type) {
for (TemplateType visitedType : visitedTypes) {
if (visitedType == type) {
return true;
}
}
return false;
}
开发者ID:nicks,项目名称:closure-compiler-old,代码行数:13,代码来源:TemplateTypeMapReplacer.java
示例18: getDeclaredTypeInAnnotation
import com.google.javascript.rhino.jstype.TemplateType; //导入依赖的package包/类
/**
* Returns the type specified in a JSDoc annotation near a GETPROP or NAME.
*
* Extracts type information from either the {@code @type} tag or from
* the {@code @return} and {@code @param} tags.
*/
private JSType getDeclaredTypeInAnnotation(Node node, JSDocInfo info) {
JSType jsType = null;
if (info != null) {
if (info.hasType()) {
ImmutableList<TemplateType> ownerTypeKeys = ImmutableList.of();
Node ownerNode = NodeUtil.getBestLValueOwner(node);
String ownerName = NodeUtil.getBestLValueName(ownerNode);
ObjectType ownerType = null;
if (ownerName != null) {
Var ownerVar = scope.getVar(ownerName);
if (ownerVar != null) {
ownerType = getPrototypeOwnerType(
ObjectType.cast(ownerVar.getType()));
if (ownerType != null) {
ownerTypeKeys =
ownerType.getTemplateTypeMap().getTemplateKeys();
}
}
}
if (!ownerTypeKeys.isEmpty()) {
typeRegistry.setTemplateTypeNames(ownerTypeKeys);
}
jsType = info.getType().evaluate(scope, typeRegistry);
if (!ownerTypeKeys.isEmpty()) {
typeRegistry.clearTemplateTypeNames();
}
} else if (FunctionTypeBuilder.isFunctionTypeDeclaration(info)) {
String fnName = node.getQualifiedName();
jsType = createFunctionTypeFromNodes(
null, fnName, info, node);
}
}
return jsType;
}
开发者ID:nicks,项目名称:closure-compiler-old,代码行数:45,代码来源:TypedScopeCreator.java
示例19: inferTemplateTypesFromParameters
import com.google.javascript.rhino.jstype.TemplateType; //导入依赖的package包/类
private Map<TemplateType, JSType> inferTemplateTypesFromParameters(
FunctionType fnType, Node call) {
if (fnType.getTemplateTypeMap().getTemplateKeys().isEmpty()) {
return Collections.emptyMap();
}
Map<TemplateType, JSType> resolvedTypes = Maps.newIdentityHashMap();
Set<JSType> seenTypes = Sets.newIdentityHashSet();
Node callTarget = call.getFirstChild();
if (NodeUtil.isGet(callTarget)) {
Node obj = callTarget.getFirstChild();
maybeResolveTemplatedType(
fnType.getTypeOfThis(),
getJSType(obj),
resolvedTypes,
seenTypes);
}
if (call.hasMoreThanOneChild()) {
maybeResolveTemplateTypeFromNodes(
fnType.getParameters(),
call.getChildAtIndex(1).siblings(),
resolvedTypes,
seenTypes);
}
return resolvedTypes;
}
开发者ID:nicks,项目名称:closure-compiler-old,代码行数:29,代码来源:TypeInference.java
示例20: inferTemplatedTypesForCall
import com.google.javascript.rhino.jstype.TemplateType; //导入依赖的package包/类
/**
* For functions with function(this: T, ...) and T as parameters, type
* inference will set the type of this on a function literal argument to the
* the actual type of T.
*/
private boolean inferTemplatedTypesForCall(
Node n, FunctionType fnType) {
final ImmutableList<TemplateType> keys = fnType.getTemplateTypeMap()
.getTemplateKeys();
if (keys.isEmpty()) {
return false;
}
// Try to infer the template types
Map<TemplateType, JSType> inferred = Maps.filterKeys(
inferTemplateTypesFromParameters(fnType, n),
new Predicate<TemplateType>() {
@Override
public boolean apply(TemplateType key) {
return keys.contains(key);
}}
);
// Replace all template types. If we couldn't find a replacement, we
// replace it with UNKNOWN.
TemplateTypeReplacer replacer = new TemplateTypeReplacer(
registry, inferred);
Node callTarget = n.getFirstChild();
FunctionType replacementFnType = fnType.visit(replacer)
.toMaybeFunctionType();
Preconditions.checkNotNull(replacementFnType);
callTarget.setJSType(replacementFnType);
n.setJSType(replacementFnType.getReturnType());
return replacer.madeChanges;
}
开发者ID:nicks,项目名称:closure-compiler-old,代码行数:40,代码来源:TypeInference.java
注:本文中的com.google.javascript.rhino.jstype.TemplateType类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论