Package com.google.javascript.rhino.jstype

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


      }
    }

    private void visitReturn(NodeTraversal t, Node n) {
      Node function = t.getEnclosingFunction();
      FunctionType funType = function.getJSType().toMaybeFunctionType();

      Node retValue = n.getFirstChild();
      if (retValue == null) {
        return;
      }

      Node checkNode = createCheckTypeCallNode(
          funType.getReturnType(), retValue.cloneTree());

      if (checkNode == null) {
        return;
      }
View Full Code Here


  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);

    Node nodeB = new Node(Token.FUNCTION);
    FunctionType ctorB = registry.createConstructorType("B", nodeB,
        new Node(Token.PARAM_LIST), null, null);

    conv.applySubclassRelationship(ctorA, ctorB, SubclassType.INHERITS);

    assertTrue(ctorB.getPrototype().hasOwnProperty("constructor"));
    assertEquals(nodeB, ctorB.getPrototype().getPropertyNode("constructor"));

    assertTrue(ctorB.hasOwnProperty("superClass_"));
    assertEquals(nodeB, ctorB.getPropertyNode("superClass_"));
  }
View Full Code Here

    List<FunctionType> subtypes = ((ObjectType) getLastCompiler()
        .getTypeRegistry().getType("Error")).getConstructor().getSubTypes();
    for (FunctionType type : subtypes) {
      String typeName = type.getInstanceType().toString();
      FunctionType typeInRegistry = ((ObjectType) getLastCompiler()
          .getTypeRegistry().getType(typeName)).getConstructor();
      assertSame(type, typeInRegistry);
    }
  }
View Full Code Here

        JSType type = n.getJSType();
        if (type == null || type.isUnknownType()) {
          return;
        }

        FunctionType funType = type.toMaybeFunctionType();
        Node paramNode = NodeUtil.getFunctionParameters(n).getFirstChild();
        List<Integer> positionalDisposedParameters = Lists.newArrayList();

        if (jsDocInfo.disposesOf("*")) {
          positionalDisposedParameters.add(DISPOSE_ALL);
        } else {
          // Parameter types
          int index = 0;
          for (Node p : funType.getParameters()) {
              // Bail out if the paramNode is not there.
              if (paramNode == null) {
                break;
              }
              if (jsDocInfo.disposesOf(paramNode.getString())) {
View Full Code Here

      if (callTarget.isGetProp()
          && callTarget.getLastChild().getString().equals("bind")) {
        Node maybeFn = callTarget.getFirstChild();
        JSType maybeFnType = maybeFn.getJSType();
        FunctionType fnType = null;
        if (useTypeInfo && maybeFnType != null) {
          fnType = maybeFnType.restrictByNotNullOrUndefined()
              .toMaybeFunctionType();
        }
View Full Code Here

        String restrictedDecl = getTypeFromValue(value);
        if (name == null || restrictedDecl == null) {
          throw new InvalidRequirementSpec("bad prop value");
        }

        FunctionType restrictedCallType = ConformanceUtil.evaluateTypeString(
            compiler, restrictedDecl).toMaybeFunctionType();
        if (restrictedCallType == null) {
          throw new InvalidRequirementSpec("invalid conformance type");
        }
        builder.add(new Restriction(name, restrictedCallType));
View Full Code Here

        String restrictedDecl = getTypeFromValue(value);
        if (type == null || property == null || restrictedDecl == null) {
          throw new InvalidRequirementSpec("bad prop value");
        }

        FunctionType restrictedCallType = ConformanceUtil.evaluateTypeString(
            compiler, restrictedDecl).toMaybeFunctionType();
        if (restrictedCallType == null) {
          throw new InvalidRequirementSpec("invalid conformance type");
        }
        builder.add(new Restriction(type, property, restrictedCallType));
View Full Code Here

    }
    return null;
  }

  private SymbolScope getScopeInFunction(Symbol sym) {
    FunctionType type = sym.getFunctionType();
    if (type == null) {
      return null;
    }

    Node functionNode = type.getSource();
    if (functionNode == null) {
      return null;
    }

    return scopes.get(functionNode);
View Full Code Here

  /**
   * Gets the symbol for the prototype if this is the symbol for a constructor
   * or interface.
   */
  public Symbol getSymbolForInstancesOf(Symbol sym) {
    FunctionType fn = sym.getFunctionType();
    if (fn != null && fn.isNominalConstructor()) {
      return getSymbolForInstancesOf(fn);
    }
    return null;
  }
View Full Code Here

    } else if (type.isNominalConstructor()) {
      return linkToCtor ?
          globalScope.getSlot("Function") :
          getSymbolDeclaredBy(type.toMaybeFunctionType());
    } else if (type.isFunctionPrototypeType()) {
      FunctionType ownerFn = ((ObjectType) type).getOwnerFunction();
      if (!ownerFn.isConstructor() && !ownerFn.isInterface()) {
        return null;
      }
      return linkToCtor ?
          getSymbolDeclaredBy(ownerFn) :
          getSymbolForInstancesOf(ownerFn);
    } else if (type.isInstanceType()) {
      FunctionType ownerFn = ((ObjectType) type).getConstructor();
      return linkToCtor ?
          getSymbolDeclaredBy(ownerFn) :
          getSymbolForInstancesOf(ownerFn);
    } else if (type.isFunctionType()) {
      return linkToCtor ?
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.