@Override public boolean isStructuralType() { FunctionType constructor = this.getConstructor(); return constructor != null && constructor.isStructuralInterface(); }
@Override public boolean isStructuralType() { FunctionType constructor = this.getConstructor(); return constructor != null && constructor.isStructuralInterface(); }
private void appendInterfaceAnnotations(StringBuilder sb, FunctionType funType) { Set<String> interfaces = new TreeSet<>(); for (ObjectType interfaceType : funType.getAncestorInterfaces()) { interfaces.add(interfaceType.toAnnotationString(Nullability.IMPLICIT)); } for (String interfaze : interfaces) { sb.append(" * "); appendAnnotation(sb, "extends", interfaze); sb.append("\n"); } if (funType.isStructuralInterface()) { sb.append(" * @record\n"); } else { sb.append(" * @interface\n"); } }
private boolean isStructuralInterfacePrototype(JSType type) { return type.isFunctionPrototypeType() && type.toObjectType().getOwnerFunction().isStructuralInterface(); } }
private static boolean isStructuralInterfacePrototype(JSType type) { if (!type.isFunctionPrototypeType()) { return false; } FunctionType constructor = type.toObjectType().getOwnerFunction(); return constructor != null && constructor.isStructuralInterface(); }
/** * Checks that the annotations in {@code info} are compatible with the aliased {@code type}. * Any errors will be reported at {@code n}, which should be the qualified name node. */ private void checkFunctionAliasAnnotations(Node n, FunctionType type, JSDocInfo info) { if (info == null) { return; } String annotation = null; if (info.usesImplicitMatch()) { if (!type.isStructuralInterface()) { annotation = "@record"; } } else if (info.isInterface()) { if (!type.isInterface()) { annotation = "@interface"; } } else if (info.isConstructor() && !type.isConstructor()) { annotation = "@constructor"; } // TODO(sdh): consider checking @template, @param, @return, and/or @this. if (annotation != null // TODO(sdh): Remove this extra check once TypeScript stops passing us duplicate // conflicting externs. In particular, TS considers everything an interface, but Closure // externs mark most things as @constructor. The load order is not always the same, so // the error can show up in either the generated TS externs file or in our own extern. && (!n.isFromExterns() || annotation.equals("@record"))) { report(JSError.make(n, INCOMPATIBLE_ALIAS_ANNOTATION, annotation, n.getQualifiedName())); } }