/** * If the superclass is final, this method returns an instance of the superclass. */ @Nullable private static ObjectType getSuperClassInstanceIfFinal(@Nullable JSType type) { if (type != null) { ObjectType obj = castToObject(type); FunctionType ctor = obj == null ? null : obj.getSuperClassConstructor(); JSDocInfo doc = ctor == null ? null : ctor.getJSDocInfo(); if (doc != null && doc.isFinal()) { return ctor.getInstanceType(); } } return null; }
/** * Emit a this parameter like `func(this: Foo)` in a function parameters. * * <p>TODO: emit for non-templatized this like `function(this: HTMLElement)` */ private void emitThisParameter(FunctionType ftype, Iterator<Node> parameters) { final JSType typeOfThis = ftype.getTypeOfThis(); // Don't emit for a constructor like `function(new: T)`. // A `this` parameter in a constructor is not allowed in TypeScript. if (typeOfThis == null || ftype.isConstructor()) { return; } final JSDocInfo jsDocInfo = ftype.getJSDocInfo(); // Emit for templatized this param like `function(this: T)` or JSDoc `@this` type. if (!typeOfThis.isTemplateType() && (jsDocInfo == null || jsDocInfo.getThisType() == null)) { return; } emitNoSpace("this :"); visitType(typeOfThis); if (parameters.hasNext()) { emit(", "); } }
private boolean isClassType(Node n) { ObjectType type = n.getJSType().restrictByNotNullOrUndefined().toMaybeObjectType(); if (type != null && type.isInstanceType()) { FunctionType ctor = type.getConstructor(); if (ctor != null) { JSDocInfo info = ctor.getJSDocInfo(); if (info != null && info.isConstructorOrInterface()) { return true; } } } return false; }
private boolean isClassType(Node n) { ObjectType type = n.getJSType().restrictByNotNullOrUndefined().toMaybeObjectType(); if (type != null && type.isInstanceType()) { FunctionType ctor = type.getConstructor(); if (ctor != null) { JSDocInfo info = ctor.getJSDocInfo(); if (info != null && info.isConstructorOrInterface()) { return true; } } } return false; }
if (type.isConstructor() && mustEmitConstructor(type) && !isPrivate(type.getJSDocInfo())) { maybeEmitJsDoc(type.getJSDocInfo(), /* ignoreParams */ false);