@Override public final boolean isConstructor() { return referencedType.isConstructor(); }
@Override public boolean isConstructor() { return referencedType.isConstructor(); }
private boolean isOrdinaryFunction(JSType ftype) { // Closure represents top-level functions as classes because they might be new-able. // This happens through externs es3.js which has Function marked as constructor. // See https://github.com/angular/closure-to-dts/issues/90 boolean ordinaryFunctionAppearingAsClass = ftype.isConstructor() && "Function".equals(ftype.getDisplayName()); return ftype.isOrdinaryFunction() || ordinaryFunctionAppearingAsClass; }
private boolean isConstructor(Node n) { // If type checking is enabled (not just a per-file lint check), // we can check constructor properties too. But it isn't required. JSType type = n.getJSType(); return type != null && (type.isConstructor() || type.isInterface()); }
private boolean isConstructor(Node n) { // If type checking is enabled (not just a per-file lint check), // we can check constructor properties too. But it isn't required. JSType type = n.getJSType(); return type != null && (type.isConstructor() || type.isInterface()); } }
private boolean couldBeAConstructor(JSType type) { return type.isConstructor() || type.isEmptyType() || type.isUnknownType(); }
private JSType getInstanceTypeForClassNode(Node classNode) { checkArgument(classNode.isClass(), classNode); final JSType constructorType = classNode.getJSType(); final JSType result; if (constructorType != null) { checkArgument(constructorType.isConstructor(), classNode); result = JSType.toMaybeFunctionType(constructorType).getInstanceType(); } else { result = null; } return result; }
private boolean isAliasedClassOrInterface(TypedVar symbol, JSType type) { // Confusingly typedefs are constructors. However, they cannot be aliased AFAICT. if (type.isNoType()) return false; if (!type.isConstructor() && !type.isInterface()) return false; String symbolName = symbol.getName(); String typeName = type.getDisplayName(); // Turns out that for aliases the symbol and type name differ. return !symbolName.equals(typeName) || KNOWN_CLASS_ALIASES.containsKey(symbolName); }
private static boolean typesAreRelated(JSType expected, JSType actual) { if (actual.isConstructor() && expected.isConstructor()) { // All constructors can cast to one another, even if they're incompatible. // If both types are constructors then compare the instance types instead. actual = actual.toMaybeFunctionType().getInstanceType(); expected = expected.toMaybeFunctionType().getInstanceType(); } actual = firstNonNull(actual.autobox(), actual); return actual.canCastTo(expected); }
private JSType maybeGetInstanceTypeFromPrototypeRef(Node src) { JSType ownerType = getJSType(src.getFirstChild()); if (ownerType.isConstructor()) { FunctionType functionType = ownerType.toMaybeFunctionType(); return functionType.getInstanceType(); } return null; }
private JSType maybeGetInstanceTypeFromPrototypeRef(Node src) { JSType ownerType = getJSType(src.getFirstChild()); if (ownerType.isFunctionType() && ownerType.isConstructor()) { FunctionType functionType = ((FunctionType) ownerType); return functionType.getInstanceType(); } return null; }
private boolean isMatchingType(Node n, JSType src) { src = src.restrictByNotNullOrUndefined(); JSType dest = getJSType(n).restrictByNotNullOrUndefined(); if (invalidatingTypes.isInvalidating(dest)) { return false; } if (dest.isConstructor() || src.isConstructor()) { // instead of using .isSubtypeOf for functions, check the prototype chain, since the // FunctionType subtyping semantics is not what we want. // This case is for ES6 class-side inheritance return hasInPrototypeChain(dest.toMaybeFunctionType(), src.toMaybeFunctionType()); } return dest.isSubtypeOf(src); }
@Override public boolean isStaticProperty() { Node lhs = assignNode.getFirstChild(); if (lhs.isGetProp()) { // something.propName = someValue Node getPropLhs = lhs.getFirstChild(); JSType typeI = getPropLhs.getJSType(); return typeI != null && (typeI.isConstructor() || typeI.isInterface()); } else { return false; } }
static boolean isConstructor(Node fnNode) { if (fnNode == null || !fnNode.isFunction()) { return false; } JSType type = fnNode.getJSType(); JSDocInfo jsDocInfo = getBestJSDocInfo(fnNode); return (type != null && type.isConstructor()) || (jsDocInfo != null && jsDocInfo.isConstructor()) || isEs6Constructor(fnNode); }
/** * Returns true for types that are class like, i.e. that define a constructor or interface, but * excludes typedefs and the built-in constructor functions such as {@code Function}. */ private boolean isClassLike(JSType propType) { // Confusingly, the typedef type returns true on isConstructor checks, so we need to filter // the NoType through this utility method. return !isTypedef(propType) && (propType.isConstructor() || propType.isInterface()) // "Function" is a constructor, but does not define a new type for our purposes. && !propType.toMaybeObjectType().isNativeObjectType() && !propType.isFunctionPrototypeType(); }
private JSType evalInstanceOf(Node ttlAst, NameResolver nameResolver) { JSType type = evalInternal(getCallArgument(ttlAst, 0), nameResolver); if (type.isUnknownType() || !type.isConstructor()) { reportWarning(ttlAst, INVALID_CTOR, type.getDisplayName()); return getUnknownType(); } return ((FunctionType) type).getInstanceType(); }
private JSType evalInstanceOf(Node ttlAst, NameResolver nameResolver) { JSType type = evalInternal(getCallArgument(ttlAst, 0), nameResolver); if (type.isUnknownType() || !type.isConstructor()) { reportWarning(ttlAst, INVALID_CTOR, type.getDisplayName()); return getUnknownType(); } return type.toMaybeFunctionType().getInstanceType(); }
/** * @param constructor A constructor function defined by a call, which may be a mixin application. * The constructor implements at least one interface. If the constructor is missing some * properties of the inherited interfaces, this method declares these properties. */ private static void addMissingInterfaceProperties(JSType constructor) { if (constructor != null && constructor.isConstructor()) { FunctionType f = constructor.toMaybeFunctionType(); ObjectType proto = f.getPrototype(); for (ObjectType interf : f.getImplementedInterfaces()) { for (String pname : interf.getPropertyNames()) { if (!proto.hasProperty(pname)) { proto.defineDeclaredProperty(pname, interf.getPropertyType(pname), null); } } } } }
/** * Checks if a constructor is trying to override a final class. */ private void checkFinalClassOverrides(NodeTraversal t, Node fn, Node parent) { JSType type = fn.getJSType().toMaybeFunctionType(); if (type != null && type.isConstructor()) { JSType finalParentClass = getFinalParentClass(getClassOfMethod(fn, parent)); if (finalParentClass != null) { compiler.report( t.makeError(fn, EXTEND_FINAL_CLASS, type.getDisplayName(), finalParentClass.getDisplayName())); } } }
/** Checks if a constructor is trying to override a final class. */ private void checkFinalClassOverrides(Node ctor, NodeTraversal t) { if (!isFunctionOrClass(ctor)) { return; } JSType type = ctor.getJSType().toMaybeFunctionType(); if (type != null && type.isConstructor()) { JSType finalParentClass = getSuperClassInstanceIfFinal(bestInstanceTypeForMethodOrCtor(ctor)); if (finalParentClass != null) { compiler.report( t.makeError( ctor, EXTEND_FINAL_CLASS, type.getDisplayName(), finalParentClass.getDisplayName())); } } }