private void visitPossibleClassDeclaration( @Nullable FunctionType funType, Node insertionPoint, MarkerInserter inserter) { // Validate the class type. if (funType == null || funType.getSource() == null || !funType.isConstructor()) { return; } @Nullable String className = NodeUtil.getName(funType.getSource()); // Assemble the marker names. Class marker first, then interfaces sorted aphabetically. ArrayList<String> markerNames = new ArrayList<>(); for (ObjectType interfaceType : funType.getAllImplementedInterfaces()) { markerNames.add("implements__" + interfaceType.getReferenceName()); } markerNames.sort(Comparator.naturalOrder()); // Sort to ensure deterministic output. if (className != null) { // We can't generate markers for anonymous classes, but there's also no way to specify them // as a parameter type, so there will never be any checks for them either. markerNames.add(0, "instance_of__" + className); } // Insert the markers. for (String markerName : markerNames) { insertionPoint = inserter.insert(markerName, className, insertionPoint); } }
private void visitFunction(Node n) { FunctionType funType = n.getJSType().toMaybeFunctionType(); if (funType != null && !funType.isConstructor()) { return; } Node nodeToInsertAfter = findNodeToInsertAfter(n); nodeToInsertAfter = addMarker(funType, nodeToInsertAfter, null); TreeSet<ObjectType> stuff = new TreeSet<ObjectType>(ALPHA); Iterables.addAll(stuff, funType.getAllImplementedInterfaces()); for (ObjectType interfaceType : stuff) { nodeToInsertAfter = addMarker(funType, nodeToInsertAfter, interfaceType); } }
/** * Expect that all properties on interfaces that this type implements are * implemented and correctly typed. */ void expectAllInterfaceProperties(NodeTraversal t, Node n, FunctionType type) { ObjectType instance = type.getInstanceType(); for (ObjectType implemented : type.getAllImplementedInterfaces()) { if (implemented.getImplicitPrototype() != null) { for (String prop : implemented.getImplicitPrototype().getOwnPropertyNames()) { expectInterfaceProperty(t, n, instance, implemented, prop); } } } }
/** * Expect that all properties on interfaces that this type implements are * implemented and correctly typed. */ void expectAllInterfaceProperties(NodeTraversal t, Node n, FunctionType type) { ObjectType instance = type.getInstanceType(); for (ObjectType implemented : type.getAllImplementedInterfaces()) { if (implemented.getImplicitPrototype() != null) { for (String prop : implemented.getImplicitPrototype().getOwnPropertyNames()) { expectInterfaceProperty(t, n, instance, implemented, prop); } } } }
/** * check whether or not this function type has implemented * the given interface * if this function is an interface, check whether or not * this interface has extended the given interface * @param interfaceType the interface type * @return true if implemented */ public boolean explicitlyImplOrExtInterface(FunctionType interfaceType) { Preconditions.checkArgument(interfaceType.isInterface()); for (ObjectType implementedInterface : getAllImplementedInterfaces()) { FunctionType ctor = implementedInterface.getConstructor(); if (ctor != null && ctor.checkEquivalenceHelper( interfaceType, EquivalenceMethod.IDENTITY)) { return true; } } for (ObjectType implementedInterface : getExtendedInterfaces()) { FunctionType ctor = implementedInterface.getConstructor(); if (ctor != null && ctor.checkEquivalenceHelper( interfaceType, EquivalenceMethod.IDENTITY)) { return true; } else if (ctor != null) { return ctor.explicitlyImplOrExtInterface(interfaceType); } } return false; }
if (ctorType.isConstructor()) { for (JSType implementedInterface : ctorType.getAllImplementedInterfaces()) { if (implementedInterface.isUnknownType() || implementedInterface.isEmptyType()) { continue;
if (ctorType.isConstructor()) { for (JSType implementedInterface : ctorType.getAllImplementedInterfaces()) { if (implementedInterface.isUnknownType() || implementedInterface.isEmptyType()) {