/** * @return true if the JSType has a user meaningful label. */ public boolean hasDisplayName() { String displayName = getDisplayName(); return displayName != null && !displayName.isEmpty(); }
/** * @return true if the JSType has a user meaningful label. */ public boolean hasDisplayName() { String displayName = getDisplayName(); return displayName != null && !displayName.isEmpty(); }
private void addEventizeClass(String className, JSType thatType) { String propertyJsTypeName = thatType.getDisplayName(); Set<String> eventize = eventizes.get(propertyJsTypeName); if (eventize == null) { eventize = new HashSet<String>(); eventizes.put(propertyJsTypeName, eventize); } eventize.add(className); }
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 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); }
public List<ClassReference> getExtendedInterfaces() { ArrayList<ClassReference> result = new ArrayList<ClassReference>(); for (JSTypeExpression jsTypeExpression : getComment().getExtendedInterfaces()) { String interfaceName = getModel().evaluate(jsTypeExpression).getDisplayName(); ClassReference reference = getModel().getClassReference(interfaceName); if (reference != null) result.add(reference); } return result; }
public List<ClassReference> getAllImplInterfaces() { ArrayList<ClassReference> result = new ArrayList<ClassReference>(); for (JSTypeExpression jsTypeExpression : getComment().getImplementedInterfaces()) { String interfaceName = getModel().evaluate(jsTypeExpression).getDisplayName(); ClassReference classReference = getModel().getClassReference(interfaceName); if (classReference != null) result.add(classReference); } return result; }
public List<ClassReference> getImplementedInterfaces() { ArrayList<ClassReference> result = new ArrayList<ClassReference>(); for (JSTypeExpression jsTypeExpression : getComment().getImplementedInterfaces()) { String interfaceName = getModel().evaluate(jsTypeExpression).getDisplayName(); ClassReference reference = getModel().getClassReference(interfaceName); if (reference != null) result.add(reference); } return result; }
public List<ClassReference> getAllImplInterfaces() { ArrayList<ClassReference> result = new ArrayList<ClassReference>(); for (JSTypeExpression jsTypeExpression : getComment().getImplementedInterfaces()) { String interfaceName = getModel().evaluate(jsTypeExpression).getDisplayName(); ClassReference classReference = getModel().getClassReference(interfaceName); if (classReference != null) result.add(classReference); } return result; }
public List<ClassReference> getAllImplInterfaces() { ArrayList<ClassReference> result = new ArrayList<ClassReference>(); for (JSTypeExpression jsTypeExpression : getComment().getImplementedInterfaces()) { String interfaceName = getModel().evaluate(jsTypeExpression).getDisplayName(); ClassReference classReference = getModel().getClassReference(interfaceName); if (classReference != null) result.add(classReference); } return result; }
/** * 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())); } } }
private boolean isPrivate(JSType type) { // Due to https://github.com/google/closure-compiler/issues/1975 we cannot obtain the JSDoc // for a typedef. Assume non-private as it is more common. // Closure creates a NamedType when the typedef is used in an union, eg: T | null. // Dereference the named type before checking if it is a typedef. NamedType nType = type.toMaybeNamedType(); if (typedefs.containsKey(type) || (nType != null && typedefs.containsKey(nType.getReferencedType()))) { return false; } // For unknown reasons, enum types do not keep their defining jsdoc info. if (type.isEnumType() || type.isEnumElementType()) { return isPrivate(type.getDisplayName()); } else { return isPrivate(type.getJSDocInfo()); } }
/** 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())); } } }
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(); }
public ClassReference getSuperClass() { if (getBaseName().equals("Object")) return null; JSTypeExpression baseType = getComment().getBaseType(); if (baseType != null) { JSType jsType = getModel().evaluate(baseType); if (jsType != null) return getModel().getClassReference(jsType.getDisplayName()); } else { return getModel().getObjectReference(); } return null; }
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(); }
public ClassReference getSuperClass() { if (getBaseName().equals("Object")) return null; JSTypeExpression baseType = getComment().getBaseType(); if (baseType != null) { JSType jsType = getModel().evaluate(baseType); if (jsType != null) return getModel().getClassReference(jsType.getDisplayName()); } else { return getModel().getObjectReference(); } return null; }
public ClassReference getSuperClass() { if (getBaseName().equals("Object")) return null; JSTypeExpression baseType = getComment().getBaseType(); if (baseType != null) { JSType jsType = getModel().evaluate(baseType); if (jsType != null) return getModel().getClassReference(jsType.getDisplayName()); } else { return getModel().getObjectReference(); } return null; }
private void addEventize(JSType thisType, JSType thatType) { if (collectorFilterType(thisType) || collectorFilterType(thatType) || thisType.isEquivalentTo(thatType)) { return; } String className = thisType.getDisplayName(); if (thatType.isUnionType()) { UnionType ut = thatType.toMaybeUnionType(); for (JSType type : ut.getAlternates()) { if (type.isObject()) { addEventizeClass(className, type); } } } else { addEventizeClass(className, thatType); } }
public boolean isMethodOverrideFromInterface(MethodReference reference) { boolean isMethodOverrideFromInterface = false; if (!hasImplementations()) { List<JSTypeExpression> implementedInterfaces = getComment().getImplementedInterfaces(); for (JSTypeExpression jsTypeExpression : implementedInterfaces) { String interfaceName = getModel().evaluate(jsTypeExpression).getDisplayName(); ClassReference classReference = getModel().getClassReference(interfaceName); if (classReference.hasSuperMethod(reference.getQualifiedName())) { isMethodOverrideFromInterface = true; break; } } } return isMethodOverrideFromInterface; }