Package com.google.javascript.jscomp.ConcreteType

Examples of com.google.javascript.jscomp.ConcreteType.ConcreteFunctionType


             + "/** @constructor */ function A() {};\n"
             + "Foo.prototype.set.call(new Foo, new A);\n"
             + "var ret = Foo.prototype.get.call(new Foo);");

    ConcreteType fooP = getFunctionPrototype(getType("Foo"));
    ConcreteFunctionType gFun = getPropertyType(fooP, "get").toFunction();
    ConcreteFunctionType sFun = getPropertyType(fooP, "set").toFunction();

    assertTrue(isCalled(sFun));
    assertTrue(isCalled(gFun));
    assertTrue(isCalled(getType("A")));
    assertType("A", getType("ret"));
View Full Code Here


      }
    }
  }

  public void testEquals() {
    ConcreteFunctionType fun1 = createFunction("fun1");
    ConcreteFunctionType fun2 = createFunction("fun2");
    ConcreteType obj1 = fun1.getInstanceType();
    ConcreteType obj2 = fun2.getInstanceType();
    ConcreteType union1 = new ConcreteUnionType(fun1, fun2);
    ConcreteType union2 = new ConcreteUnionType(fun1, obj1);
    ConcreteType union3 = new ConcreteUnionType(fun1, obj1);

    checkEquality(Lists.newArrayList(fun1, fun2, obj1, obj2,
View Full Code Here

    assertEquals(union2, union3);
  }

  public void testUnionWith() {
    ConcreteFunctionType fun = createFunction("fun");
    ConcreteType obj = fun.getInstanceType();
    ConcreteType both = new ConcreteUnionType(fun, obj);

    assertTrue(fun.isSingleton());
    assertTrue(obj.isSingleton());
    assertFalse(both.isSingleton());
    assertFalse(NONE.isSingleton());
    assertFalse(ALL.isSingleton());
View Full Code Here

    assertEquals(c, a.unionWith(b));
    assertEquals(c, b.unionWith(a));
  }

  public void testIntersectionWith() {
    ConcreteFunctionType fun = createFunction("fun");
    ConcreteFunctionType fun2 = createFunction("fun2");
    ConcreteType obj = fun.getInstanceType();
    ConcreteType both = new ConcreteUnionType(fun, obj);

    assertEquals(NONE, fun.intersectWith(obj));
    assertEquals(NONE, obj.intersectWith(fun));
View Full Code Here

    assertEquals(NONE, ALL.intersectWith(NONE));
    assertEquals(NONE, NONE.intersectWith(ALL));
  }

  public void testFunction() {
    ConcreteFunctionType fun = createFunction("fun", "a", "b");
    assertTrue(fun.isFunction());
    assertNotNull(fun.getCallSlot());
    assertNotNull(fun.getReturnSlot());
    assertNotNull(fun.getParameterSlot(0));
    assertNotNull(fun.getParameterSlot(1));
    assertNull(fun.getParameterSlot(2));
    assertTrue(fun.getInstanceType().isInstance());
  }
View Full Code Here

    }
    assertNull(obj.getImplicitPrototype());
  }

  public void testGetX() {
    ConcreteFunctionType fun1 = createFunction("fun1");
    ConcreteFunctionType fun2 = createFunction("fun2");
    ConcreteInstanceType obj1 = fun1.getInstanceType();
    ConcreteInstanceType obj2 = fun2.getInstanceType();
    ConcreteType union1 = fun1.unionWith(obj1);
    ConcreteType union2 =
        union1.unionWith(fun2).unionWith(obj2);

    assertEqualSets(Lists.newArrayList(), NONE.getFunctions());
View Full Code Here

    JSType[] paramTypes = new JSType[paramNames.length];
    Arrays.fill(paramTypes, unknownType);
    decl.setJSType(
        typeRegistry.createConstructorType(name, decl, args, unknownType));

    return new ConcreteFunctionType(factory, decl, null);
  }
View Full Code Here

    /** {@inheritDoc} */
    @Override
    public ConcreteFunctionType createConcreteFunction(
        Node decl, StaticScope<ConcreteType> parent) {
      ConcreteFunctionType funcType = functionByDeclaration.get(decl);
      if (funcType == null) {
        functionByDeclaration.put(decl, funcType =
            new ConcreteFunctionType(this, decl, parent));
        if (decl.getJSType() != null) {
          functionByJSType.put((FunctionType) decl.getJSType(), funcType);
        }
      }
      return funcType;
View Full Code Here

        case Token.FUNCTION:
          // Function declaration, e.g. function Foo() {};
          if (NodeUtil.isFunctionDeclaration(n)) {
            if (!n.getJSType().isNoObjectType()) {
              ConcreteFunctionType type = createConcreteFunction(n, scope);
              scope.declareSlot(n.getFirstChild().getString(), n, type);

              if (inExterns && type.getInstanceType() != null) {
                // We must assume all extern types are instantiated since they
                // can be created by the browser itself.
                allInstantiatedTypes.add(type.getInstanceType());
              }
            }
          }
          break;

        case Token.ASSIGN:
          // Variable assignment, e.g. a = b;
          Node lhs = n.getFirstChild();
          if (inExterns) {
            // Again, we have to trust the externs.
            ConcreteScope scope;
            if (lhs.getType() == Token.GETPROP) {
              ConcreteType type = inferConcreteType(getTopScope(),
                  lhs.getFirstChild());
              scope = (ConcreteScope) type.getScope();
            } else {
              scope = getTopScope();
            }

            if (scope == null) break;

            ConcreteType type = inferConcreteType(getTopScope(), n);
            if (type.isNone() || type.isAll()) {
              break;
            }

            if (type.isFunction()) {
              JSType lhsType = lhs.getJSType();
              if (lhsType == null) {
                break;
              }
              FunctionType funType =
                  lhsType.restrictByNotNullOrUndefined().toMaybeFunctionType();
              if (funType == null) {
                break;
              }
              ConcreteType retType = createType(funType.getReturnType());
              retType = createUnionWithSubTypes(retType);
              ConcreteType newret = type.toFunction().getReturnSlot()
                  .getType().unionWith(retType);
              ((ConcreteScope) type.getScope()).declareSlot(
                  ConcreteFunctionType.RETURN_SLOT_NAME, n, newret);
            }
            scope.declareSlot(lhs.getLastChild().getString(), n, type);
          } else {
            addActions(createAssignmentActions(lhs, n.getLastChild(), n));
View Full Code Here

    @Override public StaticScope<ConcreteType> getRootScope() {
      return tt.getTopScope();
    }

    @Override public StaticScope<ConcreteType> getFunctionScope(Node decl) {
      ConcreteFunctionType func = tt.getConcreteFunction(decl);
      return (func != null) ?
          func.getScope() : (StaticScope<ConcreteType>) null;
    }
View Full Code Here

TOP

Related Classes of com.google.javascript.jscomp.ConcreteType.ConcreteFunctionType

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.