Package com.google.javascript.jscomp.ConcreteType

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


    assertNull(fun.getParameterSlot(2));
    assertTrue(fun.getInstanceType().isInstance());
  }

  public void testInstance() {
    ConcreteInstanceType obj = createInstance("MyObj", "a", "b");
    assertTrue(obj.isInstance());
    assertNotNull(obj.getPropertySlot("a"));
    assertNotNull(obj.getPropertySlot("b"));
    assertNull(obj.getPropertySlot("c"));

    // The prototype chain should be: MyObj -> MyObj.prototype -> Object ->
    // Object.prototype -> null.
    for (int i = 0; i < 3; ++i) {
      assertNotNull(obj = obj.getImplicitPrototype());
      assertTrue(obj.isInstance());
    }
    assertNull(obj.getImplicitPrototype());
  }
View Full Code Here


  }

  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

    ObjectType objType = typeRegistry.createObjectType(name, null,
        typeRegistry.createObjectType(name + ".prototype", null, null));
    for (int i = 0; i < propNames.length; ++i) {
      objType.defineDeclaredProperty(propNames[i], unknownType, null);
    }
    return new ConcreteInstanceType(factory, objType);
  }
View Full Code Here

    /** {@inheritDoc} */
    @Override
    public ConcreteInstanceType createConcreteInstance(
        ObjectType instanceType) {
      ConcreteInstanceType instType = instanceByJSType.get(instanceType);
      if (instType == null) {
        instanceByJSType.put(instanceType,
            instType = new ConcreteInstanceType(this, instanceType));
      }
      return instType;
    }
View Full Code Here

    @Override
    public StaticScope<ConcreteType> createInstanceScope(
        ObjectType instanceType) {
      FakeScope parentScope = null;
      if (instanceType.getImplicitPrototype() != null) {
        ConcreteInstanceType prototype =
            createConcreteInstance(instanceType.getImplicitPrototype());
        parentScope = (FakeScope) prototype.getScope();
      }

      FakeScope scope = new FakeScope(parentScope);
      for (String propName : instanceType.getOwnPropertyNames()) {
        scope.addSlot(propName);
View Full Code Here

    }

    @Override public ConcreteType getTypeWithProperty(String field,
                                                      ConcreteType type) {
      if (type.isInstance()) {
        ConcreteInstanceType instanceType = (ConcreteInstanceType) type;
        return instanceType.getInstanceTypeWithProperty(field);
      } else if (type.isFunction()) {
        if ("prototype".equals(field)
            || codingConvention.isSuperClassReference(field)) {
          return type;
        }
View Full Code Here

      return null;
    }

    @Override public ConcreteType getInstanceFromPrototype(ConcreteType type) {
      if (type.isInstance()) {
        ConcreteInstanceType instanceType = (ConcreteInstanceType) type;
        if (instanceType.isFunctionPrototype()) {
          return instanceType.getConstructorType().getInstanceType();
        }
      }
      return null;
    }
View Full Code Here

        break;

      case Token.ARRAYLIT:
        ObjectType arrayType = (ObjectType) getTypeRegistry()
            .getNativeType(JSTypeNative.ARRAY_TYPE);
        ConcreteInstanceType inst = createConcreteInstance(arrayType);
        allInstantiatedTypes.add(inst);
        ret = inst;
        break;

      default:
View Full Code Here

  public ConcreteInstanceType createConcreteInstance(ObjectType instanceType) {
    // This should be an instance or function prototype object, not a function.
    Preconditions.checkArgument(
        !instanceType.isFunctionType() ||
        instanceType == getTypeRegistry().getNativeType(U2U_CONSTRUCTOR_TYPE));
    ConcreteInstanceType instType = instanceFromJSType.get(instanceType);
    if (instType == null) {
      instanceFromJSType.put(instanceType,
          instType = new ConcreteInstanceType(this, instanceType));
    }
    return instType;
  }
View Full Code Here

  public StaticScope<ConcreteType> createInstanceScope(
      ObjectType instanceType) {
    ConcreteScope parentScope = null;
    ObjectType implicitProto = instanceType.getImplicitPrototype();
    if (implicitProto != null && !implicitProto.isUnknownType()) {
      ConcreteInstanceType prototype = createConcreteInstance(implicitProto);
      parentScope = (ConcreteScope) prototype.getScope();
    }
    ConcreteScope scope = new ConcreteScope(parentScope);
    for (String propName : instanceType.getOwnPropertyNames()) {
      scope.declareSlot(propName, null);
    }
View Full Code Here

TOP

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

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.