public final ObjectType getRawType() { TemplatizedType t = toMaybeTemplatizedType(); return t == null ? this : t.getReferencedType(); }
/** Returns an integer that uniquely identifies a JSType. */ private int getIntForType(JSType type) { // Templatized types don't exist at runtime, so collapse to raw type if (type != null && type.isTemplatizedType()) { type = type.toMaybeTemplatizedType().getReferencedType(); } if (intForType.containsKey(type)) { return intForType.get(type).intValue(); } int newInt = intForType.size() + 1; intForType.put(type, newInt); return newInt; }
private boolean isArray(JSType type) { if (type.isArrayType()) { return true; } TemplatizedType templatizedType = type.toMaybeTemplatizedType(); return templatizedType != null && templatizedType.getReferencedType().isArrayType(); }
public final JSType evaluate(JSTypeExpression expression) { JSType jsType = null; if (expression != null) { try { jsType = expression.evaluate(null, jscompiler.getTypeRegistry()); if (jsType.isTemplatizedType()) { jsType = ((TemplatizedType)jsType).getReferencedType(); } } catch (Exception e) { e.printStackTrace(); } } return jsType; }
@Override public JSType caseTemplatizedType(TemplatizedType type) { boolean changed = false; ObjectType beforeBaseType = type.getReferencedType(); ObjectType afterBaseType = ObjectType.cast(beforeBaseType.visit(this)); if (beforeBaseType != afterBaseType) { changed = true; } ImmutableList.Builder<JSType> builder = ImmutableList.builder(); for (JSType beforeTemplateType : type.getTemplateTypes()) { JSType afterTemplateType = beforeTemplateType.visit(this); if (beforeTemplateType != afterTemplateType) { changed = true; } builder.add(afterTemplateType); } if (changed) { type = registry.createTemplatizedType(afterBaseType, builder.build()); } return type; }
@Override public JSType caseTemplatizedType(TemplatizedType type) { boolean changed = false; ObjectType beforeBaseType = type.getReferencedType(); ObjectType afterBaseType = ObjectType.cast(beforeBaseType.visit(this)); if (beforeBaseType != afterBaseType) { changed = true; } ImmutableList.Builder<JSType> builder = ImmutableList.builder(); for (JSType beforeTemplateType : type.getTemplateTypes()) { JSType afterTemplateType = beforeTemplateType.visit(this); if (beforeTemplateType != afterTemplateType) { changed = true; } builder.add(afterTemplateType); } if (changed) { type = registry.createTemplatizedType(afterBaseType, builder.build()); } return type; }
/** * 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 !isReasonableObjectPropertyKey(templatizedType.getTemplateTypes().get(0)); } else { return false; } }
/** * 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; } }
private static boolean areTypesEquivalentIgnoringGenerics(JSType a, JSType b) { boolean equivalent = a.isEquivalentTo(b); if (equivalent) { return true; } if (a.isTemplatizedType()) { return a.toMaybeTemplatizedType().getReferencedType().isEquivalentTo(b); } return false; }
return ((TemplatizedType)jsType).getReferencedType().toString();
private JSType evalRawTypeOf(Node ttlAst, NameResolver nameResolver) { ImmutableList<Node> params = getCallParams(ttlAst); JSType type = evalInternal(params.get(0), nameResolver); if (!type.isTemplatizedType()) { reportWarning(ttlAst, TEMPTYPE_INVALID, "rawTypeOf", type.toString()); return getUnknownType(); } return ((TemplatizedType) type).getReferencedType(); }
/** * Checks that the prototype is an implicit prototype of this object. Since * each object has an implicit prototype, an implicit prototype's * implicit prototype is also this implicit prototype's. * * @param prototype any prototype based object * * @return {@code true} if {@code prototype} is {@code equal} to any * object in this object's implicit prototype chain. */ final boolean isImplicitPrototype(ObjectType prototype) { for (ObjectType current = this; current != null; current = current.getImplicitPrototype()) { if (current.isTemplatizedType()) { current = current.toMaybeTemplatizedType().getReferencedType(); } if (current.isEquivalentTo(prototype)) { return true; } } return false; }
/** * Checks that the prototype is an implicit prototype of this object. Since * each object has an implicit prototype, an implicit prototype's * implicit prototype is also this implicit prototype's. * * @param prototype any prototype based object * * @return {@code true} if {@code prototype} is {@code equal} to any * object in this object's implicit prototype chain. */ final boolean isImplicitPrototype(ObjectType prototype) { for (ObjectType current = this; current != null; current = current.getImplicitPrototype()) { if (current.isTemplatizedType()) { current = current.toMaybeTemplatizedType().getReferencedType(); } if (current.isEquivalentTo(prototype)) { return true; } } return false; }
private Void emitTemplatizedType(TemplatizedType type, boolean inImplementsExtendsPosition) { ObjectType referencedType = type.getReferencedType(); String templateTypeName = getAbsoluteName(type); if (typeRegistry.getNativeType(ARRAY_TYPE).equals(referencedType)
private boolean containsArray(JSType type) { // Check if type is itself an array if (type.isArrayType()) { return true; } TemplatizedType templatizedType = type.toMaybeTemplatizedType(); if (templatizedType != null && templatizedType.getReferencedType().isArrayType()) { return true; } // Check if this is a union that contains an array if (type.isUnionType()) { JSType arrayType = compiler.getTypeRegistry().getNativeType(JSTypeNative.ARRAY_TYPE); for (JSType alternate : type.toMaybeUnionType().getAlternates()) { if (alternate.isSubtypeOf(arrayType)) { return true; } } } return false; }
public List<ClassReference> getInterfaces() { ArrayList<ClassReference> result = new ArrayList<ClassReference>(); List<JSTypeExpression> implementedInterfaces = getComment().getImplementedInterfaces(); for (JSTypeExpression jsTypeExpression : implementedInterfaces) { JSType jsType = getModel().evaluate(jsTypeExpression); if (jsType.isTemplatizedType()) { jsType = ((TemplatizedType)jsType).getReferencedType(); } String interfaceName = jsType.getDisplayName(); ClassReference interfaceReference = getModel().getClassReference(interfaceName); if (interfaceReference != null) result.add(interfaceReference); else { DummyNode node = new DummyNode(); String externName = AbstractCompilerPass.getSourceFileName(this.getNode().getStaticSourceFile().getName(), getModel()); node.setSourcePath(externName); node.setLine(this.getNode().getLineno()); UnresolvedClassReferenceProblem problem = new UnresolvedClassReferenceProblem(node, interfaceName); getModel().problems.add(problem); } } return result; }
if (declaredSuper != null && declaredSuper.isTemplatizedType()) { declaredSuper = declaredSuper.toMaybeTemplatizedType().getReferencedType();
if (declaredSuper != null && declaredSuper.isTemplatizedType()) { declaredSuper = declaredSuper.toMaybeTemplatizedType().getReferencedType();
if (templatizedType.getReferencedType().isArrayType()) { return isStringifiable(templatizedType.getTemplateTypes().get(0));
if (templatizedType.getReferencedType().isArrayType()) { return isReasonableObjectPropertyKey(templatizedType.getTemplateTypes().get(0));