本文整理汇总了Java中com.google.javascript.rhino.jstype.TemplatizedType类的典型用法代码示例。如果您正苦于以下问题:Java TemplatizedType类的具体用法?Java TemplatizedType怎么用?Java TemplatizedType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TemplatizedType类属于com.google.javascript.rhino.jstype包,在下文中一共展示了TemplatizedType类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: caseTemplatizedType
import com.google.javascript.rhino.jstype.TemplatizedType; //导入依赖的package包/类
@Override
public Void caseTemplatizedType(TemplatizedType type) {
type.getReferencedType().visit(this);
Iterator<JSType> types = type.getTemplateTypes().iterator();
if (currentExpression().getNamedType() == null) {
throw new IllegalStateException("unexpected templatized type structure");
}
com.github.jsdossier.proto.NamedType.Builder namedType =
currentExpression().getNamedTypeBuilder();
while (types.hasNext()) {
JSType templateType = types.next();
expressions.addLast(namedType.addTemplateTypeBuilder());
templateType.visit(this);
expressions.removeLast();
}
return null;
}
示例2: caseTemplatizedType
import com.google.javascript.rhino.jstype.TemplatizedType; //导入依赖的package包/类
@Override
public TypeReference caseTemplatizedType(TemplatizedType type) {
if (type.getReferencedType().isArrayType()) {
TypeReference arrayType = PredefinedTypeReference.OBJECT;
if (type.getTemplateTypes().size() == 1) {
arrayType =
new TypeReferenceCreator(
referenceContext == IN_HERITAGE_CLAUSE ? IN_TYPE_ARGUMENTS : REGULAR)
.visit(type.getTemplateTypes().get(0));
}
if (referenceContext == IN_HERITAGE_CLAUSE) {
// In java you cannot extends classic array. In this case create a parametrized reference
// to JsArray class.
return new ParametrizedTypeReference(
visit(type.getReferencedType()), newArrayList(arrayType));
} else {
// Convert array type to classic java array where it's valid.
return new ArrayTypeReference(arrayType);
}
}
TypeReference templatizedType = visit(type.getReferencedType());
TypeReferenceCreator typeArgumentsReferenceCreator =
new TypeReferenceCreator(IN_TYPE_ARGUMENTS);
List<TypeReference> templates =
type.getTemplateTypes()
.stream()
.map(typeArgumentsReferenceCreator::visit)
.collect(toList());
return new ParametrizedTypeReference(templatizedType, templates);
}
示例3: specialCaseMapEntries
import com.google.javascript.rhino.jstype.TemplatizedType; //导入依赖的package包/类
/**
* Closure Compiler does not support tuple types, and thus cannot express the proper type for
* "Map<K, V>.entries()", which is an IterableIterator of a [K, V] tuple. The tighter tuple type
* [K, V] allows destructuring loops "for (const [x, y] of ...)" with the tuple values getting
* the right types assigned.
*
* <p>Given that maps are very common, as are for loops over them, this special cases methods
* called "entries" that have the right return type.
*/
private boolean specialCaseMapEntries(String propName, FunctionType propertyType) {
if (propertyType.getMaxArity() != 0
|| !propName.equals("entries")
|| !propertyType.getReturnType().isTemplatizedType()) {
return false;
}
TemplatizedType ttType = propertyType.getReturnType().toMaybeTemplatizedType();
ImmutableList<JSType> ttypes = ttType.getTemplateTypes();
if (!isTemplateOf(ttType, "IteratorIterable")
|| ttypes.size() != 1
|| !isTemplateOf(ttypes.get(0), "Array")) {
return false;
}
JSType arrayMembers = ttypes.get(0).toMaybeTemplatizedType().getTemplateTypes().get(0);
if (!arrayMembers.isUnionType()
|| arrayMembers.toMaybeUnionType().getAlternatesWithoutStructuralTyping().size() != 2) {
return false;
}
emit("(): IterableIterator<[");
Iterator<JSType> it =
arrayMembers.toMaybeUnionType().getAlternatesWithoutStructuralTyping().iterator();
visitType(it.next());
emit(",");
visitType(it.next());
emit("]>;");
emitBreak();
return true;
}
示例4: isObjectTypeWithNonStringifiableKey
import com.google.javascript.rhino.jstype.TemplatizedType; //导入依赖的package包/类
/**
* Checks whether current type is Object type with non-stringifable key.
*/
private boolean isObjectTypeWithNonStringifiableKey(JSType type) {
if (!type.isTemplatizedType()) {
return false;
}
TemplatizedType templatizedType = type.toMaybeTemplatizedType();
if (templatizedType.getReferencedType().isNativeObjectType()
&& templatizedType.getTemplateTypes().size() > 1) {
return !isStringifiable(templatizedType.getTemplateTypes().get(0));
} else {
return false;
}
}
示例5: caseTemplatizedType
import com.google.javascript.rhino.jstype.TemplatizedType; //导入依赖的package包/类
public Set<String> caseTemplatizedType(TemplatizedType type) {
// Visit the type arguments.
// SomeType.<T1, T2>
for (JSType templateType : type.getTemplateTypes()) {
visitOnce(templateType);
}
return externProperties;
}
示例6: emitTemplatizedType
import com.google.javascript.rhino.jstype.TemplatizedType; //导入依赖的package包/类
private Void emitTemplatizedType(
TemplatizedType type, boolean extendingInstanceClass, boolean inImplementsExtendsPosition) {
ObjectType referencedType = type.getReferencedType();
String templateTypeName =
extendingInstanceClass
? getAbsoluteName(type) + INSTANCE_CLASS_SUFFIX
: getAbsoluteName(type);
if (typeRegistry.getNativeType(ARRAY_TYPE).equals(referencedType)
&& type.getTemplateTypes().size() == 1) {
// As per TS type grammar, array types require primary types.
// https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md#a-grammar
if (inImplementsExtendsPosition) {
emit("Array<");
}
visitTypeAsPrimary(type.getTemplateTypes().get(0));
emit(inImplementsExtendsPosition ? ">" : "[]");
return null;
}
if (!opts.emitPlatformExterns) {
switch (type.getDisplayName()) {
// Arguments<?> and NodeList<?> in es3 externs are correspondingly
// IArguments and NodeList interfaces (not-parametrized) in lib.d.ts.
case "Arguments":
emit("IArguments");
return null;
case "NodeList":
emit("NodeList");
return null;
case "MessageEvent":
emit("MessageEvent");
return null;
case "IThenable":
templateTypeName = "PromiseLike";
break;
case "IArrayLike":
templateTypeName = "ArrayLike";
break;
case "IteratorIterable":
templateTypeName = "IterableIterator";
break;
case "IIterableResult":
templateTypeName = "IteratorResult";
break;
default:
break;
}
}
if (type.getTemplateTypes().isEmpty()) {
// In Closure, subtypes of `TemplatizedType`s that do not take type arguments are still
// represented by templatized types.
emit(templateTypeName);
typesUsed.add(type.getDisplayName());
return null;
}
Iterator<JSType> it = type.getTemplateTypes().iterator();
if (typeRegistry.getNativeType(OBJECT_TYPE).equals(referencedType)) {
emit("{");
emitIndexSignature(it.next(), it.next(), false);
emit("}");
return null;
}
emit(templateTypeName);
typesUsed.add(type.getDisplayName());
emitGenericTypeArguments(it);
return null;
}
示例7: caseTemplatizedType
import com.google.javascript.rhino.jstype.TemplatizedType; //导入依赖的package包/类
@Override
public Void caseTemplatizedType(TemplatizedType type) {
emitTemplatizedType(type, emitInstanceForObject, true);
return null;
}
示例8: createTemplatizedType
import com.google.javascript.rhino.jstype.TemplatizedType; //导入依赖的package包/类
protected TemplatizedType createTemplatizedType(
ObjectType baseType, ImmutableList<JSType> templatizedTypes) {
return registry.createTemplatizedType(baseType, templatizedTypes);
}
示例9: isStringifiable
import com.google.javascript.rhino.jstype.TemplatizedType; //导入依赖的package包/类
/**
* Checks whether type is stringifiable. Stringifiable is a type that can be converted to string
* and give unique results for different objects. For example objects have native toString()
* method that on chrome returns "[object Object]" for all objects making it useless when used
* as keys. At the same time native types like numbers can be safely converted to strings and
* used as keys. Also user might have provided custom toString() methods for a class making it
* suitable for using as key.
*/
private boolean isStringifiable(JSType type) {
// Check built-in types
if (type.isUnknownType() || type.isNumber() || type.isString() || type.isBooleanObjectType()
|| type.isBooleanValueType() || type.isDateType() || type.isRegexpType()
|| type.isInterface() || type.isRecordType() || type.isNullType() || type.isVoidType()) {
return true;
}
// For enums check that underlying type is stringifiable.
if (type.toMaybeEnumElementType() != null) {
return isStringifiable(type.toMaybeEnumElementType().getPrimitiveType());
}
// Array is stringifiable if it doesn't have template type or if it does have it, the template
// type must be also stringifiable.
// Good: Array, Array.<number>
// Bad: Array.<!Object>
if (type.isArrayType()) {
return true;
}
if (type.isTemplatizedType()) {
TemplatizedType templatizedType = type.toMaybeTemplatizedType();
if (templatizedType.getReferencedType().isArrayType()) {
return isStringifiable(templatizedType.getTemplateTypes().get(0));
}
}
// Named types are usually @typedefs. For such types we need to check underlying type specified
// in @typedef annotation.
if (type instanceof NamedType) {
return isStringifiable(((NamedType) type).getReferencedType());
}
// For union type every alternate must be stringifiable.
if (type.isUnionType()) {
for (JSType alternateType : type.toMaybeUnionType().getAlternates()) {
if (!isStringifiable(alternateType)) {
return false;
}
}
return true;
}
// Handle interfaces and classes.
if (type.isObject()) {
ObjectType objectType = type.toMaybeObjectType();
JSType constructor = objectType.getConstructor();
// Interfaces considered stringifiable as user might implement toString() method in
// classes-implementations.
if (constructor != null && constructor.isInterface()) {
return true;
}
// This is user-defined class so check if it has custom toString() method.
return classHasToString(objectType);
}
return false;
}
示例10: caseTemplatizedType
import com.google.javascript.rhino.jstype.TemplatizedType; //导入依赖的package包/类
@Override
public JSType caseTemplatizedType(TemplatizedType type) {
return caseObjectType(type);
}
示例11: stripTemplateTypeInformation
import com.google.javascript.rhino.jstype.TemplatizedType; //导入依赖的package包/类
private static JSType stripTemplateTypeInformation(JSType type) {
if (type.isTemplatizedType()) {
return ((TemplatizedType) type).getReferencedType();
}
return type;
}
示例12: caseTemplatizedType
import com.google.javascript.rhino.jstype.TemplatizedType; //导入依赖的package包/类
@Override
public Object caseTemplatizedType(TemplatizedType type) {
return null;
}