@Override public final boolean isInstanceType() { return referencedType.isInstanceType(); }
@Override public boolean isInstanceType() { return referencedType.isInstanceType(); }
/** * @return true if n MUST be a prototype name reference. */ private boolean isPrototypeNameReference(Node n) { if (!n.isGetProp()) { return false; } JSType type = getType(n.getFirstChild()); if (type.isUnknownType() || type.isUnionType()) { return false; } return (type.isInstanceType() || type.autoboxesTo() != null); }
private String getName(JSType type) { if (type.isInstanceType()) { return ((ObjectType) type).getReferenceName(); } else if (type.isNullType() || type.isBooleanValueType() || type.isNumberValueType() || type.isStringValueType() || type.isVoidType()) { return type.toString(); } else { // Type unchecked at runtime, so we don't care about the sorting order. return ""; } } };
private String getName(JSType type) { if (type.isInstanceType()) { return ((ObjectType) type).getReferenceName(); } else if (type.isNullType() || type.isBooleanValueType() || type.isNumberValueType() || type.isStringValueType() || type.isVoidType()) { return type.toString(); } else { // Type unchecked at runtime, so we don't care about the sorting order. return ""; } } };
private boolean isDefaultExport(TypedVar symbol) { if (symbol.getType() == null) return true; ObjectType otype = symbol.getType().toMaybeObjectType(); if (otype != null && otype.getOwnPropertyNames().size() == 0) return true; return !symbol.getType().isObject() || symbol.getType().isInterface() || symbol.getType().isInstanceType() || symbol.getType().isEnumType() || symbol.getType().isFunctionType() || isTypedef(symbol.getType()); }
private FunctionType getOrCreateInterface() { FunctionType fnType = null; JSType type = typeRegistry.getType(getScopeDeclaredIn(), fnName); if (type != null && type.isInstanceType()) { FunctionType ctor = type.toMaybeObjectType().getConstructor(); if (ctor.isInterface()) { fnType = ctor; fnType.setSource(contents.getSourceNode()); } } if (fnType == null) { fnType = typeRegistry.createInterfaceType( fnName, contents.getSourceNode(), templateTypeNames, makesStructs); if (!fnName.isEmpty()) { typeRegistry.declareTypeForExactScope( getScopeDeclaredIn(), fnName, fnType.getInstanceType()); } maybeSetBaseType(fnType); } return fnType; } private void reportWarning(DiagnosticType warning, String ... args) {
/** * Returns the type that best represents the instance type for {@code type}. * * <ul> * <li>Prototype type => The instance type having that prototype * <li>Instance type => The type * <li>Constructor type => The type that constructor instantiates * <li>Object-literal type => The type * </ul> */ @Nullable private static ObjectType instanceTypeFor(JSType type) { if (type == null) { return null; } else if (type.isUnionType()) { return null; // A union has no meaningful instance type. } else if (type.isInstanceType() || type.isUnknownType()) { return type.toMaybeObjectType(); } else if (type.isConstructor() || type.isInterface()) { return type.toMaybeFunctionType().getInstanceType(); } else if (type.isFunctionPrototypeType()) { return instanceTypeFor(type.toMaybeObjectType().getOwnerFunction()); } return type.toMaybeObjectType(); }
boolean isInstanceObject = existingType.isInstanceType(); if (isInstanceObject || fnName.equals("Function")) { FunctionType existingFn =
IR.string(type.toString())); } else if (type.isInstanceType()) { ObjectType objType = (ObjectType) type;
|| type.isVoidType()) { return IR.call(jsCode("valueChecker"), IR.string(type.toString())); } else if (type.isInstanceType()) { ObjectType objType = (ObjectType) type;
boolean isInstanceObject = existingType.isInstanceType(); if (isInstanceObject || fnName.equals("Function")) { FunctionType existingFn =
} else if (type.isInstanceType()) { FunctionType ownerFn = ((ObjectType) type).getConstructor(); return linkToCtor ? getSymbolDeclaredBy(ownerFn) : getSymbolForInstancesOf(ownerFn);
getSymbolDeclaredBy(ownerFn) : getSymbolForInstancesOf(ownerFn); } else if (type.isInstanceType()) { FunctionType ownerFn = ((ObjectType) type).getConstructor(); return linkToCtor ?
@Test public void test_types() throws IOException { compile("types_param.js"); ClassReference reference = model.getClassReference("Foo"); JSType jsType1 = getJSType("test1", true, "arg1"); JSType jsType2 = getJSType("test2", true, "arg1"); JSType jsType3 = getJSType("test3", true, "arg1"); JSType jsType4 = getJSType("test4", true, "arg1"); JSType jsType5 = getJSType("test5", true, "arg1"); JSType jsType6 = getJSType("test6", true, "arg1"); assertTrue(jsType1.isString()); assertTrue(jsType2.isUnionType()); assertTrue(jsType3.isRecordType()); assertTrue(jsType4.isUnionType()); assertTrue(jsType5.isInstanceType()); assertTrue(jsType6.isFunctionType()); assertEquals("String", JSTypeUtils.toParamTypeString(reference.getStaticMethod("test1"), "arg1")); assertEquals("foo.bar.Baz", JSTypeUtils.toParamTypeString(reference.getStaticMethod("test2"), "arg1")); assertEquals("Object /* {myNum: number, myObject: ?} */", JSTypeUtils.toParamTypeString(reference.getStaticMethod("test3"), "arg1")); assertEquals("Number", JSTypeUtils.toParamTypeString(reference.getStaticMethod("test4"), "arg1")); assertEquals("Object", JSTypeUtils.toParamTypeString(reference.getStaticMethod("test5"), "arg1")); assertEquals("Function /* function(string, boolean): ? */", JSTypeUtils.toParamTypeString(reference.getStaticMethod("test6"), "arg1")); }