Search in sources :

Example 1 with NominalTypeBuilderOti

use of com.google.javascript.rhino.jstype.NominalTypeBuilderOti in project closure-compiler by google.

the class TypedScopeCreator method createScopeInternal.

private TypedScope createScopeInternal(Node root, TypedScope typedParent) {
    // Constructing the global scope is very different than constructing
    // inner scopes, because only global scopes can contain named classes that
    // show up in the type registry.
    TypedScope newScope = null;
    AbstractScopeBuilder scopeBuilder = null;
    if (typedParent == null) {
        JSType globalThis = typeRegistry.getNativeObjectType(JSTypeNative.GLOBAL_THIS);
        // Mark the main root, the externs root, and the src root
        // with the global this type.
        root.setJSType(globalThis);
        root.getFirstChild().setJSType(globalThis);
        root.getLastChild().setJSType(globalThis);
        // Run a first-order analysis over the syntax tree.
        new FirstOrderFunctionAnalyzer().process(root.getFirstChild(), root.getLastChild());
        // Find all the classes in the global scope.
        newScope = createInitialScope(root);
        scopeBuilder = new GlobalScopeBuilder(newScope);
    } else {
        newScope = new TypedScope(typedParent, root);
        scopeBuilder = new LocalScopeBuilder(newScope);
    }
    scopeBuilder.build();
    scopeBuilder.resolveStubDeclarations();
    if (typedParent == null) {
        List<NominalTypeBuilder> delegateProxies = new ArrayList<>();
        for (FunctionType delegateProxyCtor : delegateProxyCtors) {
            delegateProxies.add(new NominalTypeBuilderOti(delegateProxyCtor, delegateProxyCtor.getInstanceType()));
        }
        codingConvention.defineDelegateProxyPrototypeProperties(typeRegistry, delegateProxies, delegateCallingConventions);
    }
    newScope.setTypeResolver(scopeBuilder);
    return newScope;
}
Also used : NominalTypeBuilderOti(com.google.javascript.rhino.jstype.NominalTypeBuilderOti) JSType(com.google.javascript.rhino.jstype.JSType) FunctionType(com.google.javascript.rhino.jstype.FunctionType) ArrayList(java.util.ArrayList) NominalTypeBuilder(com.google.javascript.rhino.NominalTypeBuilder)

Example 2 with NominalTypeBuilderOti

use of com.google.javascript.rhino.jstype.NominalTypeBuilderOti in project closure-compiler by google.

the class ClosureCodingConventionTest method testApplySubclassRelationship.

public void testApplySubclassRelationship() {
    JSTypeRegistry registry = new JSTypeRegistry(null);
    Node nodeA = new Node(Token.FUNCTION);
    FunctionType ctorA = registry.createConstructorType("A", nodeA, new Node(Token.PARAM_LIST), null, null, false);
    Node nodeB = new Node(Token.FUNCTION);
    FunctionType ctorB = registry.createConstructorType("B", nodeB, new Node(Token.PARAM_LIST), null, null, false);
    conv.applySubclassRelationship(new NominalTypeBuilderOti(ctorA, ctorA.getInstanceType()), new NominalTypeBuilderOti(ctorB, ctorB.getInstanceType()), SubclassType.INHERITS);
    assertTrue(ctorB.getPrototype().hasOwnProperty("constructor"));
    assertEquals(nodeB, ctorB.getPrototype().getPropertyNode("constructor"));
    assertTrue(ctorB.hasOwnProperty("superClass_"));
    assertEquals(nodeB, ctorB.getPropertyNode("superClass_"));
}
Also used : JSTypeRegistry(com.google.javascript.rhino.jstype.JSTypeRegistry) NominalTypeBuilderOti(com.google.javascript.rhino.jstype.NominalTypeBuilderOti) Node(com.google.javascript.rhino.Node) FunctionType(com.google.javascript.rhino.jstype.FunctionType)

Aggregations

FunctionType (com.google.javascript.rhino.jstype.FunctionType)2 NominalTypeBuilderOti (com.google.javascript.rhino.jstype.NominalTypeBuilderOti)2 Node (com.google.javascript.rhino.Node)1 NominalTypeBuilder (com.google.javascript.rhino.NominalTypeBuilder)1 JSType (com.google.javascript.rhino.jstype.JSType)1 JSTypeRegistry (com.google.javascript.rhino.jstype.JSTypeRegistry)1 ArrayList (java.util.ArrayList)1