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;
}
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_"));
}
Aggregations