Package com.google.javascript.rhino

Examples of com.google.javascript.rhino.SimpleErrorReporter


    assertTrue(typeRegistry.hasNamespace("a.b"));
    assertTrue(typeRegistry.hasNamespace("a.b.Foo"));
  }

  public void testGenerationIncrementing1() {
    SimpleErrorReporter reporter = new SimpleErrorReporter();
    final JSTypeRegistry typeRegistry = new JSTypeRegistry(reporter);

    StaticScope<JSType> scope = new AbstractStaticScope<JSType>() {
          @Override
          public StaticSlot<JSType> getSlot(final String name) {
            return new SimpleSlot(
                name,
                typeRegistry.getNativeType(JSTypeNative.UNKNOWN_TYPE),
                false);
          }
        };

    ObjectType namedType =
        (ObjectType) typeRegistry.getType(scope, "Foo", null, 0, 0);
    ObjectType subNamed =
        typeRegistry.createObjectType(typeRegistry.createObjectType(namedType));

    // Subclass of named type is initially unresolved.
    typeRegistry.setLastGeneration(false);
    typeRegistry.resolveTypesInScope(scope);
    assertTrue(subNamed.isUnknownType());

    // Subclass of named type is still unresolved, even though the named type is
    // now present in the registry.
    typeRegistry.declareType("Foo",
                             typeRegistry.createAnonymousObjectType(null));
    typeRegistry.resolveTypesInScope(scope);
    assertTrue(subNamed.isUnknownType());

    assertNull("Unexpected errors: " + reporter.errors(),
        reporter.errors());
    assertNull("Unexpected warnings: " + reporter.warnings(),
        reporter.warnings());

    // After incrementing the generation, resolve works again.
    typeRegistry.incrementGeneration();
    typeRegistry.setLastGeneration(true);
    typeRegistry.resolveTypesInScope(scope);
View Full Code Here


    typeRegistry.resolveTypesInScope(scope);
    assertFalse(subNamed.isUnknownType());
  }

  public void testGenerationIncrementing2() {
    SimpleErrorReporter reporter = new SimpleErrorReporter();
    final JSTypeRegistry typeRegistry = new JSTypeRegistry(reporter);

    StaticScope<JSType> scope = new AbstractStaticScope<JSType>() {
          @Override
          public StaticSlot<JSType> getSlot(final String name) {
            return new SimpleSlot(
                name,
                typeRegistry.getNativeType(JSTypeNative.UNKNOWN_TYPE),
                false);
          }
        };

    ObjectType namedType =
        (ObjectType) typeRegistry.getType(scope, "Foo", null, 0, 0);
    FunctionType functionType = typeRegistry.createFunctionType(namedType);

    // Subclass of named type is initially unresolved.
    typeRegistry.setLastGeneration(false);
    typeRegistry.resolveTypesInScope(scope);
    assertTrue(functionType.getReturnType().isUnknownType());
    functionType.resolve(reporter, scope);
    assertTrue(functionType.getReturnType().isUnknownType());

    // Subclass of named type is still unresolved, even though the named type is
    // now present in the registry.
    typeRegistry.declareType("Foo",
                             typeRegistry.createAnonymousObjectType(null));
    typeRegistry.resolveTypesInScope(scope);
    assertTrue(functionType.getReturnType().isUnknownType());

    assertNull("Unexpected errors: " + reporter.errors(),
        reporter.errors());
    assertNull("Unexpected warnings: " + reporter.warnings(),
        reporter.warnings());

    // After incrementing the generation, resolve works again.
    typeRegistry.incrementGeneration();
    typeRegistry.setLastGeneration(true);
    typeRegistry.resolveTypesInScope(scope);
View Full Code Here

    forwardDeclaredNamedType =
        new NamedType(registry, "forwardDeclared", "source", 1, 0);
    registry.forwardDeclareType("forwardDeclared");
    forwardDeclaredNamedType.resolve(
        new SimpleErrorReporter(), EMPTY_SCOPE);

    types = ImmutableList.of(
        NO_OBJECT_TYPE,
        NO_RESOLVED_TYPE,
        NO_TYPE,
View Full Code Here

    forwardDeclaredNamedType =
        new NamedType(registry, "forwardDeclared", "source", 1, 0);
    registry.forwardDeclareType("forwardDeclared");
    forwardDeclaredNamedType.resolve(
        new SimpleErrorReporter(), EMPTY_SCOPE);

    types = ImmutableList.of(
        NO_OBJECT_TYPE,
        NO_RESOLVED_TYPE,
        NO_TYPE,
View Full Code Here

    assertTrue(typeRegistry.hasNamespace("a.b"));
    assertTrue(typeRegistry.hasNamespace("a.b.Foo"));
  }

  public void testGenerationIncrementing1() {
    SimpleErrorReporter reporter = new SimpleErrorReporter();
    final JSTypeRegistry typeRegistry = new JSTypeRegistry(reporter);

    StaticScope<JSType> scope = new AbstractStaticScope<JSType>() {
          @Override
          public StaticSlot<JSType> getSlot(final String name) {
            return new SimpleSlot(
                name,
                typeRegistry.getNativeType(JSTypeNative.UNKNOWN_TYPE),
                false);
          }
        };

    ObjectType namedType =
        (ObjectType) typeRegistry.getType(scope, "Foo", null, 0, 0);
    ObjectType subNamed =
        typeRegistry.createObjectType(typeRegistry.createObjectType(namedType));

    // Subclass of named type is initially unresolved.
    typeRegistry.setLastGeneration(false);
    typeRegistry.resolveTypesInScope(scope);
    assertTrue(subNamed.isUnknownType());

    // Subclass of named type is still unresolved, even though the named type is
    // now present in the registry.
    typeRegistry.declareType("Foo", typeRegistry.createAnonymousObjectType());
    typeRegistry.resolveTypesInScope(scope);
    assertTrue(subNamed.isUnknownType());

    assertNull("Unexpected errors: " + reporter.errors(),
        reporter.errors());
    assertNull("Unexpected warnings: " + reporter.warnings(),
        reporter.warnings());

    // After incrementing the generation, resolve works again.
    typeRegistry.incrementGeneration();
    typeRegistry.setLastGeneration(true);
    typeRegistry.resolveTypesInScope(scope);
View Full Code Here

    typeRegistry.resolveTypesInScope(scope);
    assertFalse(subNamed.isUnknownType());
  }

  public void testGenerationIncrementing2() {
    SimpleErrorReporter reporter = new SimpleErrorReporter();
    final JSTypeRegistry typeRegistry = new JSTypeRegistry(reporter);

    StaticScope<JSType> scope = new AbstractStaticScope<JSType>() {
          @Override
          public StaticSlot<JSType> getSlot(final String name) {
            return new SimpleSlot(
                name,
                typeRegistry.getNativeType(JSTypeNative.UNKNOWN_TYPE),
                false);
          }
        };

    ObjectType namedType =
        (ObjectType) typeRegistry.getType(scope, "Foo", null, 0, 0);
    FunctionType functionType = typeRegistry.createFunctionType(namedType);

    // Subclass of named type is initially unresolved.
    typeRegistry.setLastGeneration(false);
    typeRegistry.resolveTypesInScope(scope);
    assertTrue(functionType.getReturnType().isUnknownType());
    functionType.resolve(reporter, scope);
    assertTrue(functionType.getReturnType().isUnknownType());

    // Subclass of named type is still unresolved, even though the named type is
    // now present in the registry.
    typeRegistry.declareType("Foo", typeRegistry.createAnonymousObjectType());
    typeRegistry.resolveTypesInScope(scope);
    assertTrue(functionType.getReturnType().isUnknownType());

    assertNull("Unexpected errors: " + reporter.errors(),
        reporter.errors());
    assertNull("Unexpected warnings: " + reporter.warnings(),
        reporter.warnings());

    // After incrementing the generation, resolve works again.
    typeRegistry.incrementGeneration();
    typeRegistry.setLastGeneration(true);
    typeRegistry.resolveTypesInScope(scope);
View Full Code Here

    typeRegistry.resolveTypesInScope(scope);
    assertFalse(functionType.getReturnType().isUnknownType());
  }

  public void testTypeResolutionModes() {
    SimpleErrorReporter reporter = new SimpleErrorReporter();

    JSTypeRegistry lazyExprRegistry = new JSTypeRegistry(reporter);
    lazyExprRegistry.setResolveMode(ResolveMode.LAZY_EXPRESSIONS);

    JSTypeRegistry lazyNameRegistry = new JSTypeRegistry(reporter);
    lazyNameRegistry.setResolveMode(ResolveMode.LAZY_NAMES);

    JSTypeRegistry immediateRegistry = new JSTypeRegistry(reporter);
    immediateRegistry.setResolveMode(ResolveMode.IMMEDIATE);

    Node expr = new Node(Token.QMARK, Node.newString("foo"));
    StaticScope<JSType> empty = MapBasedScope.emptyScope();

    JSType type = lazyExprRegistry.createFromTypeNodes(
        expr, "source.js", empty);
    assertTrue(type instanceof UnresolvedTypeExpression);
    assertTrue(type.isUnknownType());
    assertEquals("?", type.toString());
    assertNull("Unexpected warnings: " + reporter.warnings(),
        reporter.warnings());

    type = lazyNameRegistry.createFromTypeNodes(
        expr, "source.js", empty);
    assertTrue(type instanceof UnionType);
    assertTrue(type.isUnknownType());
    assertEquals("(foo|null)", type.toString());
    assertNull("Unexpected warnings: " + reporter.warnings(),
        reporter.warnings());

    type = immediateRegistry.createFromTypeNodes(
        expr, "source.js", empty);
    assertTrue(type instanceof UnknownType);
    assertEquals("Expected warnings", 1, reporter.warnings().size());
  }
View Full Code Here

    assertTrue(type instanceof UnknownType);
    assertEquals("Expected warnings", 1, reporter.warnings().size());
  }

  public void testForceResolve() {
    SimpleErrorReporter reporter = new SimpleErrorReporter();

    JSTypeRegistry lazyExprRegistry = new JSTypeRegistry(reporter);
    lazyExprRegistry.setResolveMode(ResolveMode.LAZY_EXPRESSIONS);

    Node expr = new Node(Token.QMARK, Node.newString("foo"));
    StaticScope<JSType> empty = MapBasedScope.emptyScope();

    JSType type = lazyExprRegistry.createFromTypeNodes(
        expr, "source.js", empty);
    assertFalse(type.isResolved());
    assertTrue(type.forceResolve(reporter, empty).isResolved());
    assertEquals("Expected warnings", 1, reporter.warnings().size());
  }
View Full Code Here

    assertEquals("Expected warnings", 1, reporter.warnings().size());
  }

  public void testAllTypeResolvesImmediately() {
    JSTypeRegistry lazyExprRegistry = new JSTypeRegistry(
        new SimpleErrorReporter());
    lazyExprRegistry.setResolveMode(ResolveMode.LAZY_EXPRESSIONS);

    Node expr = new Node(Token.STAR);
    JSType type = lazyExprRegistry.createFromTypeNodes(
        expr, "source.js", MapBasedScope.emptyScope());
View Full Code Here

TOP

Related Classes of com.google.javascript.rhino.SimpleErrorReporter

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.