Package com.google.javascript.rhino.jstype

Examples of com.google.javascript.rhino.jstype.FunctionType


    /**
     * Look for the super class implementation up the tree.
     */
    private void recordSuperClassPrototypePropUse(
        FunctionType classType, String prop, Reference ref) {
      FunctionType superClass = classType.getSuperClassConstructor();
      while (superClass != null) {
        if (superClass.getPrototype().hasOwnProperty(prop)) {
          graph.connect(getNamedContainingFunction(), ref,
              graph.defineNameIfNotExists(
                 superClass.getReferenceName() + ".prototype." + prop, false));
          return;
        } else {
          superClass = superClass.getSuperClassConstructor();
        }
      }
    }
View Full Code Here


        if (constructor != null) {
          JSType ownerType = constructor.getJSType();
          if (ownerType != null
              && ownerType.isFunctionType()
              && ownerType.isConstructor()) {
            FunctionType functionType = ((FunctionType) ownerType);
            return functionType.getInstanceType();
          }
        }
      }
      return registry.getNativeType(JSTypeNative.UNKNOWN_TYPE);
    }
View Full Code Here

    if (valueType != null) {
      switch (key.getType()) {
        case Token.GETTER_DEF:
          // GET must always return a function type.
          if (valueType.isFunctionType()) {
            FunctionType fntype = valueType.toMaybeFunctionType();
            valueType = fntype.getReturnType();
          } else {
            return null;
          }
          break;
        case Token.SETTER_DEF:
          if (valueType.isFunctionType()) {
            // SET must always return a function type.
            FunctionType fntype = valueType.toMaybeFunctionType();
            Node param = fntype.getParametersNode().getFirstChild();
            // SET function must always have one parameter.
            valueType = param.getJSType();
          } else {
            return null;
          }
View Full Code Here

   * adding the original this pointer type to the beginning of the
   * argument type list and replacing the this pointer type with
   * NO_TYPE.
   */
  private void fixFunctionType(Node functionNode) {
    FunctionType type = JSType.toMaybeFunctionType(functionNode.getJSType());
    if (type != null) {
      JSTypeRegistry typeRegistry = compiler.getTypeRegistry();

      List<JSType> parameterTypes = Lists.newArrayList();
      parameterTypes.add(type.getTypeOfThis());

      for (Node param : type.getParameters()) {
        parameterTypes.add(param.getJSType());
      }

      ObjectType thisType =
          typeRegistry.getNativeObjectType(JSTypeNative.UNKNOWN_TYPE);
      JSType returnType = type.getReturnType();

      JSType newType = typeRegistry.createFunctionType(
          thisType, returnType, parameterTypes);
      functionNode.setJSType(newType);
    }
View Full Code Here

        MemoizedScopeCreator scopeCreator = (MemoizedScopeCreator) creator;
        String newSrc = scriptRoot.getSourceFileName();
        for (Var var : scopeCreator.getAllSymbols()) {
          JSType type = var.getType();
          if (type != null) {
            FunctionType fnType = type.toMaybeFunctionType();
            if (fnType != null
                && newSrc.equals(NodeUtil.getSourceName(fnType.getSource()))) {
              fnType.setSource(null);
            }
          }
        }
        scopeCreator.removeScopesForScript(originalRoot.getSourceFileName());
      }
View Full Code Here

      functionSideEffectMap.put(node, sideEffectInfo);

      if (inExterns) {
        JSType jstype = node.getJSType();
        boolean knownLocalResult = false;
        FunctionType functionType = JSType.toMaybeFunctionType(jstype);
        if (functionType != null) {
          JSType jstypeReturn = functionType.getReturnType();
          if (isLocalValueType(jstypeReturn)) {
            knownLocalResult = true;
          }
        }
        if (!knownLocalResult) {
View Full Code Here

   * have an implicit return type. See unit tests.
   *
   * @return If a return type is expected, returns it. Otherwise, returns null.
   */
  private JSType explicitReturnExpected(Node scope) {
    FunctionType scopeType = JSType.toMaybeFunctionType(scope.getJSType());

    if (scopeType == null) {
      return null;
    }

    if (isEmptyFunction(scope)) {
      return null;
    }

    if (scopeType.isConstructor()) {
      return null;
    }

    JSType returnType = scopeType.getReturnType();

    if (returnType == null) {
      return null;
    }

View Full Code Here

    if (type == null || type.isUnknownType()) {
      return type;
    } else if (type.isNominalConstructor()) {
      return (type.toMaybeFunctionType()).getInstanceType();
    } else if (type.isFunctionPrototypeType()) {
      FunctionType owner = ((ObjectType) type).getOwnerFunction();
      if (owner.isConstructor()) {
        return owner.getInstanceType();
      }
    }
    return type;
  }
View Full Code Here

        visitFunction(n);
      }
    }

    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 = Sets.newTreeSet(ALPHA);
      Iterables.addAll(stuff, funType.getAllImplementedInterfaces());
      for (ObjectType interfaceType : stuff) {
        nodeToInsertAfter =
            addMarker(funType, nodeToInsertAfter, interfaceType);
      }
    }
View Full Code Here

    /**
     * Insert checks for the parameters of the function.
     */
    private void visitFunction(Node n) {
      FunctionType funType = JSType.toMaybeFunctionType(n.getJSType());
      Node block = n.getLastChild();
      Node paramName = NodeUtil.getFunctionParameters(n).getFirstChild();
      Node insertionPoint = null;

      // To satisfy normalization constraints, the type checking must be
      // added after any inner function declarations.
      for (Node next = block.getFirstChild();
           next != null && NodeUtil.isFunctionDeclaration(next);
           next = next.getNext()) {
        insertionPoint = next;
      }

      for (Node paramType : funType.getParameters()) {
        // Can this ever happen?
        if (paramName == null) {
          return;
        }

View Full Code Here

TOP

Related Classes of com.google.javascript.rhino.jstype.FunctionType

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.