Java Code Examples for com.google.javascript.rhino.jstype.FunctionType#getTypeOfThis()

The following examples show how to use com.google.javascript.rhino.jstype.FunctionType#getTypeOfThis() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DeclarationGenerator.java    From clutz with MIT License 6 votes vote down vote up
/**
 * Special handling for simple typing returning polymorphic this type in TypeScript. Prefer
 * `func(): this` instead of `func<T>(this: T): T` when any params are not templatized.
 */
private boolean shouldEmitThisParam(FunctionType ftype) {
  final JSType typeOfThis = ftype.getTypeOfThis();
  if (typeOfThis == null
      || !typeOfThis.isTemplateType()
      || !typeOfThis.equals(ftype.getReturnType())) {
    return true;
  }

  for (Parameter parameter : ftype.getParameters()) {
    JSType paramType = parameter.getJSType();
    if (!paramType.isTemplatizedType()) {
      continue;
    }

    final TemplateTypeMap templateTypeMap = paramType.getTemplateTypeMap();
    for (TemplateType key : templateTypeMap.getTemplateKeys()) {
      if (templateTypeMap.getResolvedTemplateType(key).equals(typeOfThis)) {
        return true;
      }
    }
  }

  return false;
}
 
Example 2
Source File: DeclarationGenerator.java    From clutz with MIT License 6 votes vote down vote up
/**
 * 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<Parameter> 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(", ");
  }
}
 
Example 3
Source File: DeclarationGenerator.java    From clutz with MIT License 6 votes vote down vote up
private void visitFunctionDeclaration(FunctionType ftype, List<String> skipTemplateParams) {
  visitFunctionParameters(ftype, true, skipTemplateParams);
  JSType type = ftype.getReturnType();
  final JSType typeOfThis = ftype.getTypeOfThis();

  if (type == null) return;
  emit(":");
  // Closure conflates 'undefined' and 'void', and in general visitType always emits `undefined`
  // for that type.
  // In idiomatic TypeScript, `void` is used for function return types, and the "void",
  // "undefined" types are not the same.
  if (type.isVoidType()) {
    emit("void");
  } else if (typeOfThis != null && typeOfThis.isTemplateType() && typeOfThis.equals(type)) {
    // Special case: prefer polymorphic `this` type to templatized `this` param
    emit("this");
  } else {
    visitType(type);
  }
}
 
Example 4
Source File: TypeExpressionParser.java    From js-dossier with Apache License 2.0 4 votes vote down vote up
@Override
public Void caseFunctionType(FunctionType type) {
  if ("Function".equals(type.getReferenceName())) {
    currentExpression().getNamedTypeBuilder().setName("Function");
    return null;
  }

  com.github.jsdossier.proto.FunctionType.Builder functionType =
      currentExpression().getFunctionTypeBuilder();

  if (type.isConstructor()) {
    functionType.setIsConstructor(true);
    expressions.addLast(functionType.getInstanceTypeBuilder());
    type.getTypeOfThis().visit(this);
    expressions.removeLast();

  } else if (!type.getTypeOfThis().isUnknownType()
      || type.getTypeOfThis() instanceof NamedType) {
    expressions.addLast(functionType.getInstanceTypeBuilder());
    type.getTypeOfThis().visit(this);
    expressions.removeLast();
  }

  for (Node node : type.getParameters()) {
    TypeExpression.Builder parameterType = functionType.addParameterBuilder();
    expressions.addLast(parameterType);

    if (node.isVarArgs()) {
      parameterType.setIsVarargs(true);
    }

    if (node.getJSType() != null) {
      if (node.getJSType().isUnionType()) {
        caseUnionType((UnionType) node.getJSType(), node.isOptionalArg());
      } else {
        node.getJSType().visit(this);
      }
    }

    if (node.isOptionalArg()) {
      // Not sure if this is possible, but varargs implies optional and we only permit one
      // bit to be set.
      if (!parameterType.getIsVarargs()) {
        parameterType.setIsOptional(true);
      }
    }

    expressions.removeLast();
  }

  if (type.getReturnType() != null && !type.isConstructor()) {
    expressions.addLast(functionType.getReturnTypeBuilder());
    type.getReturnType().visit(this);
    expressions.removeLast();
  }
  return null;
}
 
Example 5
Source File: SymbolTable.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void enterScope(NodeTraversal t) {
  Symbol symbol = null;
  if (t.inGlobalScope()) {
    // Declare the global this at the first input root.
    // This is a bizarre place to put it, but we need some
    // location with a real file path (because all symbols
    // must have a path).
    // Note that root.lastChild.firstChild is the first non-extern input.
    Node firstInputRoot = t.getScopeRoot().getLastChild().getFirstChild();
    if (firstInputRoot != null) {
      symbol = addSymbol(
          GLOBAL_THIS,
          registry.getNativeType(JSTypeNative.GLOBAL_THIS),
          false /* declared */,
          globalScope,
          firstInputRoot);
      symbol.setDeclaration(new Reference(symbol, firstInputRoot));
    }
  } else {
    // Otherwise, declare a "this" property when possible.
    SymbolScope scope = scopes.get(t.getScopeRoot());
    Preconditions.checkNotNull(scope);
    Symbol scopeSymbol = getSymbolForScope(scope);
    if (scopeSymbol != null) {
      SymbolScope propScope = scopeSymbol.getPropertyScope();
      if (propScope != null) {
        // If a function is assigned multiple times, we only want
        // one addressable "this" symbol.
        symbol = propScope.getOwnSlot("this");
        if (symbol == null) {
          JSType rootType = t.getScopeRoot().getJSType();
          FunctionType fnType = rootType == null
              ? null : rootType.toMaybeFunctionType();
          JSType type = fnType == null
              ? null : fnType.getTypeOfThis();
          symbol = addSymbol(
              "this",
              type,
              false /* declared */,
              scope,
              t.getScopeRoot());
        }

        // TODO(nicksantos): It's non-obvious where the declaration of
        // the 'this' symbol should be. Figure this out later.
      }
    }
  }

  thisStack.add(symbol);
}
 
Example 6
Source File: TypedScopeCreator.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Creates a scope with all types declared. Declares newly discovered types
 * and type properties in the type registry.
 */
@Override
public Scope createScope(Node root, Scope parent) {
  // 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.
  Scope newScope = null;
  AbstractScopeBuilder scopeBuilder = null;
  if (parent == 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(compiler, functionAnalysisResults))
        .process(root.getFirstChild(), root.getLastChild());

    // Find all the classes in the global scope.
    newScope = createInitialScope(root);

    GlobalScopeBuilder globalScopeBuilder = new GlobalScopeBuilder(newScope);
    scopeBuilder = globalScopeBuilder;
    NodeTraversal.traverse(compiler, root, scopeBuilder);
  } else {
    newScope = new Scope(parent, root);
    LocalScopeBuilder localScopeBuilder = new LocalScopeBuilder(newScope);
    scopeBuilder = localScopeBuilder;
    localScopeBuilder.build();
  }

  scopeBuilder.resolveStubDeclarations();
  scopeBuilder.resolveTypes();

  // Gather the properties in each function that we found in the
  // global scope, if that function has a @this type that we can
  // build properties on.
  for (Node functionNode : scopeBuilder.nonExternFunctions) {
    JSType type = functionNode.getJSType();
    if (type != null && type.isFunctionType()) {
      FunctionType fnType = type.toMaybeFunctionType();
      JSType fnThisType = fnType.getTypeOfThis();
      if (!fnThisType.isUnknownType()) {
        NodeTraversal.traverse(compiler, functionNode.getLastChild(),
            scopeBuilder.new CollectProperties(fnThisType));
      }
    }
  }

  if (parent == null) {
    codingConvention.defineDelegateProxyPrototypeProperties(
        typeRegistry, newScope, delegateProxyPrototypes,
        delegateCallingConventions);
  }
  return newScope;
}
 
Example 7
Source File: Closure_95_TypedScopeCreator_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * Creates a scope with all types declared. Declares newly discovered types
 * and type properties in the type registry.
 */
public Scope createScope(Node root, Scope parent) {
  // 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.
  Scope newScope = null;
  AbstractScopeBuilder scopeBuilder = null;
  if (parent == null) {
    // Find all the classes in the global scope.
    newScope = createInitialScope(root);

    GlobalScopeBuilder globalScopeBuilder = new GlobalScopeBuilder(newScope);
    scopeBuilder = globalScopeBuilder;
    NodeTraversal.traverse(compiler, root, scopeBuilder);
  } else {
    newScope = new Scope(parent, root);
    LocalScopeBuilder localScopeBuilder = new LocalScopeBuilder(newScope);
    scopeBuilder = localScopeBuilder;
    localScopeBuilder.build();
  }

  scopeBuilder.resolveStubDeclarations();
  scopeBuilder.resolveTypes();

  // Gather the properties in each function that we found in the
  // global scope, if that function has a @this type that we can
  // build properties on.
  for (Node functionNode : scopeBuilder.nonExternFunctions) {
    JSType type = functionNode.getJSType();
    if (type != null && type instanceof FunctionType) {
      FunctionType fnType = (FunctionType) type;
      ObjectType fnThisType = fnType.getTypeOfThis();
      if (!fnThisType.isUnknownType()) {
        NodeTraversal.traverse(compiler, functionNode.getLastChild(),
            scopeBuilder.new CollectProperties(fnThisType));
      }
    }
  }

  if (parent == null) {
    codingConvention.defineDelegateProxyPrototypeProperties(
        typeRegistry, newScope, delegateProxyPrototypes);
  }
  return newScope;
}
 
Example 8
Source File: Closure_95_TypedScopeCreator_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * Creates a scope with all types declared. Declares newly discovered types
 * and type properties in the type registry.
 */
public Scope createScope(Node root, Scope parent) {
  // 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.
  Scope newScope = null;
  AbstractScopeBuilder scopeBuilder = null;
  if (parent == null) {
    // Find all the classes in the global scope.
    newScope = createInitialScope(root);

    GlobalScopeBuilder globalScopeBuilder = new GlobalScopeBuilder(newScope);
    scopeBuilder = globalScopeBuilder;
    NodeTraversal.traverse(compiler, root, scopeBuilder);
  } else {
    newScope = new Scope(parent, root);
    LocalScopeBuilder localScopeBuilder = new LocalScopeBuilder(newScope);
    scopeBuilder = localScopeBuilder;
    localScopeBuilder.build();
  }

  scopeBuilder.resolveStubDeclarations();
  scopeBuilder.resolveTypes();

  // Gather the properties in each function that we found in the
  // global scope, if that function has a @this type that we can
  // build properties on.
  for (Node functionNode : scopeBuilder.nonExternFunctions) {
    JSType type = functionNode.getJSType();
    if (type != null && type instanceof FunctionType) {
      FunctionType fnType = (FunctionType) type;
      ObjectType fnThisType = fnType.getTypeOfThis();
      if (!fnThisType.isUnknownType()) {
        NodeTraversal.traverse(compiler, functionNode.getLastChild(),
            scopeBuilder.new CollectProperties(fnThisType));
      }
    }
  }

  if (parent == null) {
    codingConvention.defineDelegateProxyPrototypeProperties(
        typeRegistry, newScope, delegateProxyPrototypes);
  }
  return newScope;
}
 
Example 9
Source File: Closure_54_TypedScopeCreator_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * Creates a scope with all types declared. Declares newly discovered types
 * and type properties in the type registry.
 */
@Override
public Scope createScope(Node root, Scope parent) {
  // 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.
  Scope newScope = null;
  AbstractScopeBuilder scopeBuilder = null;
  if (parent == null) {
    // Find all the classes in the global scope.
    newScope = createInitialScope(root);

    GlobalScopeBuilder globalScopeBuilder = new GlobalScopeBuilder(newScope);
    scopeBuilder = globalScopeBuilder;
    NodeTraversal.traverse(compiler, root, scopeBuilder);
  } else {
    newScope = new Scope(parent, root);
    LocalScopeBuilder localScopeBuilder = new LocalScopeBuilder(newScope);
    scopeBuilder = localScopeBuilder;
    localScopeBuilder.build();
  }

  scopeBuilder.resolveStubDeclarations();
  scopeBuilder.resolveTypes();

  // Gather the properties in each function that we found in the
  // global scope, if that function has a @this type that we can
  // build properties on.
  for (Node functionNode : scopeBuilder.nonExternFunctions) {
    JSType type = functionNode.getJSType();
    if (type != null && type.isFunctionType()) {
      FunctionType fnType = type.toMaybeFunctionType();
      ObjectType fnThisType = fnType.getTypeOfThis();
      if (!fnThisType.isUnknownType()) {
        NodeTraversal.traverse(compiler, functionNode.getLastChild(),
            scopeBuilder.new CollectProperties(fnThisType));
      }
    }
  }

  if (parent == null) {
    codingConvention.defineDelegateProxyPrototypeProperties(
        typeRegistry, newScope, delegateProxyPrototypes,
        delegateCallingConventions);
  }
  return newScope;
}
 
Example 10
Source File: Closure_54_TypedScopeCreator_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * Creates a scope with all types declared. Declares newly discovered types
 * and type properties in the type registry.
 */
@Override
public Scope createScope(Node root, Scope parent) {
  // 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.
  Scope newScope = null;
  AbstractScopeBuilder scopeBuilder = null;
  if (parent == null) {
    // Find all the classes in the global scope.
    newScope = createInitialScope(root);

    GlobalScopeBuilder globalScopeBuilder = new GlobalScopeBuilder(newScope);
    scopeBuilder = globalScopeBuilder;
    NodeTraversal.traverse(compiler, root, scopeBuilder);
  } else {
    newScope = new Scope(parent, root);
    LocalScopeBuilder localScopeBuilder = new LocalScopeBuilder(newScope);
    scopeBuilder = localScopeBuilder;
    localScopeBuilder.build();
  }

  scopeBuilder.resolveStubDeclarations();
  scopeBuilder.resolveTypes();

  // Gather the properties in each function that we found in the
  // global scope, if that function has a @this type that we can
  // build properties on.
  for (Node functionNode : scopeBuilder.nonExternFunctions) {
    JSType type = functionNode.getJSType();
    if (type != null && type.isFunctionType()) {
      FunctionType fnType = type.toMaybeFunctionType();
      ObjectType fnThisType = fnType.getTypeOfThis();
      if (!fnThisType.isUnknownType()) {
        NodeTraversal.traverse(compiler, functionNode.getLastChild(),
            scopeBuilder.new CollectProperties(fnThisType));
      }
    }
  }

  if (parent == null) {
    codingConvention.defineDelegateProxyPrototypeProperties(
        typeRegistry, newScope, delegateProxyPrototypes,
        delegateCallingConventions);
  }
  return newScope;
}
 
Example 11
Source File: Closure_43_TypedScopeCreator_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * Creates a scope with all types declared. Declares newly discovered types
 * and type properties in the type registry.
 */
@Override
public Scope createScope(Node root, Scope parent) {
  // 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.
  Scope newScope = null;
  AbstractScopeBuilder scopeBuilder = null;
  if (parent == null) {
    // Run a first-order analysis over the syntax tree.
    (new FirstOrderFunctionAnalyzer(compiler, functionAnalysisResults))
        .process(root.getFirstChild(), root.getLastChild());

    // Find all the classes in the global scope.
    newScope = createInitialScope(root);

    GlobalScopeBuilder globalScopeBuilder = new GlobalScopeBuilder(newScope);
    scopeBuilder = globalScopeBuilder;
    NodeTraversal.traverse(compiler, root, scopeBuilder);
  } else {
    newScope = new Scope(parent, root);
    LocalScopeBuilder localScopeBuilder = new LocalScopeBuilder(newScope);
    scopeBuilder = localScopeBuilder;
    localScopeBuilder.build();
  }

  scopeBuilder.resolveStubDeclarations();
  scopeBuilder.resolveTypes();

  // Gather the properties in each function that we found in the
  // global scope, if that function has a @this type that we can
  // build properties on.
  for (Node functionNode : scopeBuilder.nonExternFunctions) {
    JSType type = functionNode.getJSType();
    if (type != null && type.isFunctionType()) {
      FunctionType fnType = type.toMaybeFunctionType();
      ObjectType fnThisType = fnType.getTypeOfThis();
      if (!fnThisType.isUnknownType()) {
        NodeTraversal.traverse(compiler, functionNode.getLastChild(),
            scopeBuilder.new CollectProperties(fnThisType));
      }
    }
  }

  if (parent == null) {
    codingConvention.defineDelegateProxyPrototypeProperties(
        typeRegistry, newScope, delegateProxyPrototypes,
        delegateCallingConventions);
  }
  return newScope;
}
 
Example 12
Source File: Closure_43_TypedScopeCreator_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * Creates a scope with all types declared. Declares newly discovered types
 * and type properties in the type registry.
 */
@Override
public Scope createScope(Node root, Scope parent) {
  // 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.
  Scope newScope = null;
  AbstractScopeBuilder scopeBuilder = null;
  if (parent == null) {
    // Run a first-order analysis over the syntax tree.
    (new FirstOrderFunctionAnalyzer(compiler, functionAnalysisResults))
        .process(root.getFirstChild(), root.getLastChild());

    // Find all the classes in the global scope.
    newScope = createInitialScope(root);

    GlobalScopeBuilder globalScopeBuilder = new GlobalScopeBuilder(newScope);
    scopeBuilder = globalScopeBuilder;
    NodeTraversal.traverse(compiler, root, scopeBuilder);
  } else {
    newScope = new Scope(parent, root);
    LocalScopeBuilder localScopeBuilder = new LocalScopeBuilder(newScope);
    scopeBuilder = localScopeBuilder;
    localScopeBuilder.build();
  }

  scopeBuilder.resolveStubDeclarations();
  scopeBuilder.resolveTypes();

  // Gather the properties in each function that we found in the
  // global scope, if that function has a @this type that we can
  // build properties on.
  for (Node functionNode : scopeBuilder.nonExternFunctions) {
    JSType type = functionNode.getJSType();
    if (type != null && type.isFunctionType()) {
      FunctionType fnType = type.toMaybeFunctionType();
      ObjectType fnThisType = fnType.getTypeOfThis();
      if (!fnThisType.isUnknownType()) {
        NodeTraversal.traverse(compiler, functionNode.getLastChild(),
            scopeBuilder.new CollectProperties(fnThisType));
      }
    }
  }

  if (parent == null) {
    codingConvention.defineDelegateProxyPrototypeProperties(
        typeRegistry, newScope, delegateProxyPrototypes,
        delegateCallingConventions);
  }
  return newScope;
}
 
Example 13
Source File: Closure_48_TypedScopeCreator_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * Creates a scope with all types declared. Declares newly discovered types
 * and type properties in the type registry.
 */
@Override
public Scope createScope(Node root, Scope parent) {
  // 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.
  Scope newScope = null;
  AbstractScopeBuilder scopeBuilder = null;
  if (parent == null) {
    // Run a first-order analysis over the syntax tree.
    (new FirstOrderFunctionAnalyzer(compiler, functionAnalysisResults))
        .process(root.getFirstChild(), root.getLastChild());

    // Find all the classes in the global scope.
    newScope = createInitialScope(root);

    GlobalScopeBuilder globalScopeBuilder = new GlobalScopeBuilder(newScope);
    scopeBuilder = globalScopeBuilder;
    NodeTraversal.traverse(compiler, root, scopeBuilder);
  } else {
    newScope = new Scope(parent, root);
    LocalScopeBuilder localScopeBuilder = new LocalScopeBuilder(newScope);
    scopeBuilder = localScopeBuilder;
    localScopeBuilder.build();
  }

  scopeBuilder.resolveStubDeclarations();
  scopeBuilder.resolveTypes();

  // Gather the properties in each function that we found in the
  // global scope, if that function has a @this type that we can
  // build properties on.
  for (Node functionNode : scopeBuilder.nonExternFunctions) {
    JSType type = functionNode.getJSType();
    if (type != null && type.isFunctionType()) {
      FunctionType fnType = type.toMaybeFunctionType();
      ObjectType fnThisType = fnType.getTypeOfThis();
      if (!fnThisType.isUnknownType()) {
        NodeTraversal.traverse(compiler, functionNode.getLastChild(),
            scopeBuilder.new CollectProperties(fnThisType));
      }
    }
  }

  if (parent == null) {
    codingConvention.defineDelegateProxyPrototypeProperties(
        typeRegistry, newScope, delegateProxyPrototypes,
        delegateCallingConventions);
  }
  return newScope;
}
 
Example 14
Source File: Closure_48_TypedScopeCreator_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * Creates a scope with all types declared. Declares newly discovered types
 * and type properties in the type registry.
 */
@Override
public Scope createScope(Node root, Scope parent) {
  // 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.
  Scope newScope = null;
  AbstractScopeBuilder scopeBuilder = null;
  if (parent == null) {
    // Run a first-order analysis over the syntax tree.
    (new FirstOrderFunctionAnalyzer(compiler, functionAnalysisResults))
        .process(root.getFirstChild(), root.getLastChild());

    // Find all the classes in the global scope.
    newScope = createInitialScope(root);

    GlobalScopeBuilder globalScopeBuilder = new GlobalScopeBuilder(newScope);
    scopeBuilder = globalScopeBuilder;
    NodeTraversal.traverse(compiler, root, scopeBuilder);
  } else {
    newScope = new Scope(parent, root);
    LocalScopeBuilder localScopeBuilder = new LocalScopeBuilder(newScope);
    scopeBuilder = localScopeBuilder;
    localScopeBuilder.build();
  }

  scopeBuilder.resolveStubDeclarations();
  scopeBuilder.resolveTypes();

  // Gather the properties in each function that we found in the
  // global scope, if that function has a @this type that we can
  // build properties on.
  for (Node functionNode : scopeBuilder.nonExternFunctions) {
    JSType type = functionNode.getJSType();
    if (type != null && type.isFunctionType()) {
      FunctionType fnType = type.toMaybeFunctionType();
      ObjectType fnThisType = fnType.getTypeOfThis();
      if (!fnThisType.isUnknownType()) {
        NodeTraversal.traverse(compiler, functionNode.getLastChild(),
            scopeBuilder.new CollectProperties(fnThisType));
      }
    }
  }

  if (parent == null) {
    codingConvention.defineDelegateProxyPrototypeProperties(
        typeRegistry, newScope, delegateProxyPrototypes,
        delegateCallingConventions);
  }
  return newScope;
}
 
Example 15
Source File: Closure_70_TypedScopeCreator_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * Creates a scope with all types declared. Declares newly discovered types
 * and type properties in the type registry.
 */
public Scope createScope(Node root, Scope parent) {
  // 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.
  Scope newScope = null;
  AbstractScopeBuilder scopeBuilder = null;
  if (parent == null) {
    // Find all the classes in the global scope.
    newScope = createInitialScope(root);

    GlobalScopeBuilder globalScopeBuilder = new GlobalScopeBuilder(newScope);
    scopeBuilder = globalScopeBuilder;
    NodeTraversal.traverse(compiler, root, scopeBuilder);
  } else {
    newScope = new Scope(parent, root);
    LocalScopeBuilder localScopeBuilder = new LocalScopeBuilder(newScope);
    scopeBuilder = localScopeBuilder;
    localScopeBuilder.build();
  }

  scopeBuilder.resolveStubDeclarations();
  scopeBuilder.resolveTypes();

  // Gather the properties in each function that we found in the
  // global scope, if that function has a @this type that we can
  // build properties on.
  for (Node functionNode : scopeBuilder.nonExternFunctions) {
    JSType type = functionNode.getJSType();
    if (type != null && type instanceof FunctionType) {
      FunctionType fnType = (FunctionType) type;
      ObjectType fnThisType = fnType.getTypeOfThis();
      if (!fnThisType.isUnknownType()) {
        NodeTraversal.traverse(compiler, functionNode.getLastChild(),
            scopeBuilder.new CollectProperties(fnThisType));
      }
    }
  }

  if (parent == null) {
    codingConvention.defineDelegateProxyPrototypeProperties(
        typeRegistry, newScope, delegateProxyPrototypes);
  }
  return newScope;
}
 
Example 16
Source File: Closure_70_TypedScopeCreator_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * Creates a scope with all types declared. Declares newly discovered types
 * and type properties in the type registry.
 */
public Scope createScope(Node root, Scope parent) {
  // 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.
  Scope newScope = null;
  AbstractScopeBuilder scopeBuilder = null;
  if (parent == null) {
    // Find all the classes in the global scope.
    newScope = createInitialScope(root);

    GlobalScopeBuilder globalScopeBuilder = new GlobalScopeBuilder(newScope);
    scopeBuilder = globalScopeBuilder;
    NodeTraversal.traverse(compiler, root, scopeBuilder);
  } else {
    newScope = new Scope(parent, root);
    LocalScopeBuilder localScopeBuilder = new LocalScopeBuilder(newScope);
    scopeBuilder = localScopeBuilder;
    localScopeBuilder.build();
  }

  scopeBuilder.resolveStubDeclarations();
  scopeBuilder.resolveTypes();

  // Gather the properties in each function that we found in the
  // global scope, if that function has a @this type that we can
  // build properties on.
  for (Node functionNode : scopeBuilder.nonExternFunctions) {
    JSType type = functionNode.getJSType();
    if (type != null && type instanceof FunctionType) {
      FunctionType fnType = (FunctionType) type;
      ObjectType fnThisType = fnType.getTypeOfThis();
      if (!fnThisType.isUnknownType()) {
        NodeTraversal.traverse(compiler, functionNode.getLastChild(),
            scopeBuilder.new CollectProperties(fnThisType));
      }
    }
  }

  if (parent == null) {
    codingConvention.defineDelegateProxyPrototypeProperties(
        typeRegistry, newScope, delegateProxyPrototypes);
  }
  return newScope;
}
 
Example 17
Source File: Closure_17_TypedScopeCreator_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * Creates a scope with all types declared. Declares newly discovered types
 * and type properties in the type registry.
 */
@Override
public Scope createScope(Node root, Scope parent) {
  // 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.
  Scope newScope = null;
  AbstractScopeBuilder scopeBuilder = null;
  if (parent == null) {
    // Run a first-order analysis over the syntax tree.
    (new FirstOrderFunctionAnalyzer(compiler, functionAnalysisResults))
        .process(root.getFirstChild(), root.getLastChild());

    // Find all the classes in the global scope.
    newScope = createInitialScope(root);

    GlobalScopeBuilder globalScopeBuilder = new GlobalScopeBuilder(newScope);
    scopeBuilder = globalScopeBuilder;
    NodeTraversal.traverse(compiler, root, scopeBuilder);
  } else {
    newScope = new Scope(parent, root);
    LocalScopeBuilder localScopeBuilder = new LocalScopeBuilder(newScope);
    scopeBuilder = localScopeBuilder;
    localScopeBuilder.build();
  }

  scopeBuilder.resolveStubDeclarations();
  scopeBuilder.resolveTypes();

  // Gather the properties in each function that we found in the
  // global scope, if that function has a @this type that we can
  // build properties on.
  for (Node functionNode : scopeBuilder.nonExternFunctions) {
    JSType type = functionNode.getJSType();
    if (type != null && type.isFunctionType()) {
      FunctionType fnType = type.toMaybeFunctionType();
      ObjectType fnThisType = fnType.getTypeOfThis();
      if (!fnThisType.isUnknownType()) {
        NodeTraversal.traverse(compiler, functionNode.getLastChild(),
            scopeBuilder.new CollectProperties(fnThisType));
      }
    }
  }

  if (parent == null) {
    codingConvention.defineDelegateProxyPrototypeProperties(
        typeRegistry, newScope, delegateProxyPrototypes,
        delegateCallingConventions);
  }
  return newScope;
}
 
Example 18
Source File: Closure_17_TypedScopeCreator_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * Creates a scope with all types declared. Declares newly discovered types
 * and type properties in the type registry.
 */
@Override
public Scope createScope(Node root, Scope parent) {
  // 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.
  Scope newScope = null;
  AbstractScopeBuilder scopeBuilder = null;
  if (parent == null) {
    // Run a first-order analysis over the syntax tree.
    (new FirstOrderFunctionAnalyzer(compiler, functionAnalysisResults))
        .process(root.getFirstChild(), root.getLastChild());

    // Find all the classes in the global scope.
    newScope = createInitialScope(root);

    GlobalScopeBuilder globalScopeBuilder = new GlobalScopeBuilder(newScope);
    scopeBuilder = globalScopeBuilder;
    NodeTraversal.traverse(compiler, root, scopeBuilder);
  } else {
    newScope = new Scope(parent, root);
    LocalScopeBuilder localScopeBuilder = new LocalScopeBuilder(newScope);
    scopeBuilder = localScopeBuilder;
    localScopeBuilder.build();
  }

  scopeBuilder.resolveStubDeclarations();
  scopeBuilder.resolveTypes();

  // Gather the properties in each function that we found in the
  // global scope, if that function has a @this type that we can
  // build properties on.
  for (Node functionNode : scopeBuilder.nonExternFunctions) {
    JSType type = functionNode.getJSType();
    if (type != null && type.isFunctionType()) {
      FunctionType fnType = type.toMaybeFunctionType();
      ObjectType fnThisType = fnType.getTypeOfThis();
      if (!fnThisType.isUnknownType()) {
        NodeTraversal.traverse(compiler, functionNode.getLastChild(),
            scopeBuilder.new CollectProperties(fnThisType));
      }
    }
  }

  if (parent == null) {
    codingConvention.defineDelegateProxyPrototypeProperties(
        typeRegistry, newScope, delegateProxyPrototypes,
        delegateCallingConventions);
  }
  return newScope;
}
 
Example 19
Source File: Nopol2017_0027_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * Creates a scope with all types declared. Declares newly discovered types
 * and type properties in the type registry.
 */
@Override
public Scope createScope(Node root, Scope parent) {
  // 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.
  Scope newScope = null;
  AbstractScopeBuilder scopeBuilder = null;
  if (parent == null) {
    // Run a first-order analysis over the syntax tree.
    (new FirstOrderFunctionAnalyzer(compiler, functionAnalysisResults))
        .process(root.getFirstChild(), root.getLastChild());

    // Find all the classes in the global scope.
    newScope = createInitialScope(root);

    GlobalScopeBuilder globalScopeBuilder = new GlobalScopeBuilder(newScope);
    scopeBuilder = globalScopeBuilder;
    NodeTraversal.traverse(compiler, root, scopeBuilder);
  } else {
    newScope = new Scope(parent, root);
    LocalScopeBuilder localScopeBuilder = new LocalScopeBuilder(newScope);
    scopeBuilder = localScopeBuilder;
    localScopeBuilder.build();
  }

  scopeBuilder.resolveStubDeclarations();
  scopeBuilder.resolveTypes();

  // Gather the properties in each function that we found in the
  // global scope, if that function has a @this type that we can
  // build properties on.
  for (Node functionNode : scopeBuilder.nonExternFunctions) {
    JSType type = functionNode.getJSType();
    if (type != null && type.isFunctionType()) {
      FunctionType fnType = type.toMaybeFunctionType();
      ObjectType fnThisType = fnType.getTypeOfThis();
      if (!fnThisType.isUnknownType()) {
        NodeTraversal.traverse(compiler, functionNode.getLastChild(),
            scopeBuilder.new CollectProperties(fnThisType));
      }
    }
  }

  if (parent == null) {
    codingConvention.defineDelegateProxyPrototypeProperties(
        typeRegistry, newScope, delegateProxyPrototypes,
        delegateCallingConventions);
  }
  return newScope;
}
 
Example 20
Source File: Nopol2017_0027_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * Creates a scope with all types declared. Declares newly discovered types
 * and type properties in the type registry.
 */
@Override
public Scope createScope(Node root, Scope parent) {
  // 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.
  Scope newScope = null;
  AbstractScopeBuilder scopeBuilder = null;
  if (parent == null) {
    // Run a first-order analysis over the syntax tree.
    (new FirstOrderFunctionAnalyzer(compiler, functionAnalysisResults))
        .process(root.getFirstChild(), root.getLastChild());

    // Find all the classes in the global scope.
    newScope = createInitialScope(root);

    GlobalScopeBuilder globalScopeBuilder = new GlobalScopeBuilder(newScope);
    scopeBuilder = globalScopeBuilder;
    NodeTraversal.traverse(compiler, root, scopeBuilder);
  } else {
    newScope = new Scope(parent, root);
    LocalScopeBuilder localScopeBuilder = new LocalScopeBuilder(newScope);
    scopeBuilder = localScopeBuilder;
    localScopeBuilder.build();
  }

  scopeBuilder.resolveStubDeclarations();
  scopeBuilder.resolveTypes();

  // Gather the properties in each function that we found in the
  // global scope, if that function has a @this type that we can
  // build properties on.
  for (Node functionNode : scopeBuilder.nonExternFunctions) {
    JSType type = functionNode.getJSType();
    if (type != null && type.isFunctionType()) {
      FunctionType fnType = type.toMaybeFunctionType();
      ObjectType fnThisType = fnType.getTypeOfThis();
      if (!fnThisType.isUnknownType()) {
        NodeTraversal.traverse(compiler, functionNode.getLastChild(),
            scopeBuilder.new CollectProperties(fnThisType));
      }
    }
  }

  if (parent == null) {
    codingConvention.defineDelegateProxyPrototypeProperties(
        typeRegistry, newScope, delegateProxyPrototypes,
        delegateCallingConventions);
  }
  return newScope;
}