com.google.javascript.rhino.ErrorReporter Java Examples

The following examples show how to use com.google.javascript.rhino.ErrorReporter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NamedType.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
private void handleUnresolvedType(
    ErrorReporter t, boolean ignoreForwardReferencedTypes) {
  if (registry.isLastGeneration()) {
    boolean isForwardDeclared =
        ignoreForwardReferencedTypes &&
        registry.isForwardDeclaredType(reference);
    if (!isForwardDeclared && registry.isLastGeneration()) {
      t.warning("Bad type annotation. Unknown type " + reference,
          sourceName, lineno, charno);
    } else {
      setReferencedType(
          registry.getNativeObjectType(
              JSTypeNative.NO_RESOLVED_TYPE));

      if (registry.isLastGeneration() && validator != null) {
        validator.apply(getReferencedType());
      }
    }

    setResolvedTypeInternal(getReferencedType());
  } else {
    setResolvedTypeInternal(this);
  }
}
 
Example #2
Source File: UnionType.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Override
JSType resolveInternal(ErrorReporter t, StaticScope<JSType> scope) {
  setResolvedTypeInternal(this); // for circularly defined types.

  boolean changed = false;
  ImmutableList.Builder<JSType> resolvedTypes = ImmutableList.builder();
  for (JSType alternate : alternates) {
    JSType newAlternate = alternate.resolve(t, scope);
    changed |= (alternate != newAlternate);
    resolvedTypes.add(alternate);
  }
  if (changed) {
    Collection<JSType> newAlternates = resolvedTypes.build();
    Preconditions.checkState(
        newAlternates.hashCode() == this.hashcode);
    alternates = newAlternates;
  }
  return this;
}
 
Example #3
Source File: Closure_4_NamedType_t.java    From coming with MIT License 6 votes vote down vote up
private void handleUnresolvedType(
    ErrorReporter t, boolean ignoreForwardReferencedTypes) {
  if (registry.isLastGeneration()) {
    boolean isForwardDeclared =
        ignoreForwardReferencedTypes &&
        registry.isForwardDeclaredType(reference);
    if (!isForwardDeclared && registry.isLastGeneration()) {
      t.warning("Bad type annotation. Unknown type " + reference,
          sourceName, lineno, charno);
    } else {
      setReferencedType(
          registry.getNativeObjectType(
              JSTypeNative.NO_RESOLVED_TYPE));

      if (registry.isLastGeneration() && validator != null) {
        validator.apply(getReferencedType());
      }
    }

    setResolvedTypeInternal(getReferencedType());
  } else {
    setResolvedTypeInternal(this);
  }
}
 
Example #4
Source File: NamedType.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
private void setReferencedAndResolvedType(JSType type, ErrorReporter t,
    StaticScope<JSType> enclosing) {
  if (validator != null) {
    validator.apply(type);
  }
  setReferencedType(type);
  checkEnumElementCycle(t);
  checkProtoCycle(t);
  setResolvedTypeInternal(getReferencedType());
}
 
Example #5
Source File: NamedType.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Resolves a named type by looking it up in the registry.
 * @return True if we resolved successfully.
 */
private boolean resolveViaRegistry(
    ErrorReporter t, StaticScope<JSType> enclosing) {
  JSType type = registry.getType(reference);
  if (type != null) {
    setReferencedAndResolvedType(type, t, enclosing);
    return true;
  }
  return false;
}
 
Example #6
Source File: Closure_33_PrototypeObjectType_t.java    From coming with MIT License 5 votes vote down vote up
@Override
JSType resolveInternal(ErrorReporter t, StaticScope<JSType> scope) {
  setResolvedTypeInternal(this);

  ObjectType implicitPrototype = getImplicitPrototype();
  if (implicitPrototype != null) {
    implicitPrototypeFallback =
        (ObjectType) implicitPrototype.resolve(t, scope);
  }
  for (Property prop : properties.values()) {
    prop.setType(safeResolve(prop.getType(), t, scope));
  }
  return this;
}
 
Example #7
Source File: NamedType.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
JSType getTypedefType(ErrorReporter t, StaticSlot<JSType> slot, String name) {
  JSType type = slot.getType();
  if (type != null) {
    return type;
  }
  handleUnresolvedType(t, true);
  return null;
}
 
Example #8
Source File: Closure_82_JSType_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * Force this type to resolve, even if the registry is in a lazy
 * resolving mode.
 * @see #resolve
 */
public final JSType forceResolve(ErrorReporter t, StaticScope<JSType> scope) {
  ResolveMode oldResolveMode = registry.getResolveMode();
  registry.setResolveMode(ResolveMode.IMMEDIATE);
  JSType result = resolve(t, scope);
  registry.setResolveMode(oldResolveMode);
  return result;
}
 
Example #9
Source File: NamedType.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Resolves a named type by looking up its first component in the scope, and
 * subsequent components as properties. The scope must have been fully
 * parsed and a symbol table constructed.
 */
private void resolveViaProperties(ErrorReporter t,
                                  StaticScope<JSType> enclosing) {
  JSType value = lookupViaProperties(t, enclosing);
  // last component of the chain
  if (value != null && value.isFunctionType() &&
      (value.isConstructor() || value.isInterface())) {
    FunctionType functionType = value.toMaybeFunctionType();
    setReferencedAndResolvedType(
        functionType.getInstanceType(), t, enclosing);
  } else if (value != null && value.isNoObjectType()) {
    setReferencedAndResolvedType(
        registry.getNativeFunctionType(
            JSTypeNative.NO_OBJECT_TYPE).getInstanceType(), t, enclosing);
  } else if (value instanceof EnumType) {
    setReferencedAndResolvedType(
        ((EnumType) value).getElementsType(), t, enclosing);
  } else {
    // We've been running into issues where people forward-declare
    // non-named types. (This is legitimate...our dependency management
    // code doubles as our forward-declaration code.)
    //
    // So if the type does resolve to an actual value, but it's not named,
    // then don't respect the forward declaration.
    handleUnresolvedType(t, value == null || value.isUnknownType());
  }
}
 
Example #10
Source File: Closure_82_JSType_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * Resolve this type in the given scope.
 *
 * The returned value must be equal to {@code this}, as defined by
 * {@link #isEquivalentTo}. It may or may not be the same object. This method
 * may modify the internal state of {@code this}, as long as it does
 * so in a way that preserves Object equality.
 *
 * For efficiency, we should only resolve a type once per compilation job.
 * For incremental compilations, one compilation job may need the
 * artifacts from a previous generation, so we will eventually need
 * a generational flag instead of a boolean one.
 */
public final JSType resolve(ErrorReporter t, StaticScope<JSType> scope) {
  if (resolved) {
    // TODO(nicksantos): Check to see if resolve() looped back on itself.
    // Preconditions.checkNotNull(resolveResult);
    if (resolveResult == null) {
      return registry.getNativeType(JSTypeNative.UNKNOWN_TYPE);
    }
    return resolveResult;
  }
  resolved = true;
  resolveResult = resolveInternal(t, scope);
  resolveResult.setResolvedTypeInternal(resolveResult);
  return resolveResult;
}
 
Example #11
Source File: Closure_4_NamedType_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * Resolves a named type by looking up its first component in the scope, and
 * subsequent components as properties. The scope must have been fully
 * parsed and a symbol table constructed.
 */
private void resolveViaProperties(ErrorReporter t,
                                  StaticScope<JSType> enclosing) {
  JSType value = lookupViaProperties(t, enclosing);
  // last component of the chain
  if (value != null && value.isFunctionType() &&
      (value.isConstructor() || value.isInterface())) {
    FunctionType functionType = value.toMaybeFunctionType();
    setReferencedAndResolvedType(
        functionType.getInstanceType(), t, enclosing);
  } else if (value != null && value.isNoObjectType()) {
    setReferencedAndResolvedType(
        registry.getNativeFunctionType(
            JSTypeNative.NO_OBJECT_TYPE).getInstanceType(), t, enclosing);
  } else if (value instanceof EnumType) {
    setReferencedAndResolvedType(
        ((EnumType) value).getElementsType(), t, enclosing);
  } else {
    // We've been running into issues where people forward-declare
    // non-named types. (This is legitimate...our dependency management
    // code doubles as our forward-declaration code.)
    //
    // So if the type does resolve to an actual value, but it's not named,
    // then don't respect the forward declaration.
    handleUnresolvedType(t, value == null || value.isUnknownType());
  }
}
 
Example #12
Source File: Asserts.java    From ng-closure-runner with MIT License 5 votes vote down vote up
/** @return The resolved type */
public static JSType assertValidResolve(
    JSType type, StaticScope<JSType> scope) {
  ErrorReporter t = TestErrorReporter.forNoExpectedReports();
  JSType resolvedType = type.resolve(t, scope);
  assertTypeEquals("JSType#resolve should not affect object equality",
      type, resolvedType);
  return resolvedType;
}
 
Example #13
Source File: Closure_4_NamedType_s.java    From coming with MIT License 5 votes vote down vote up
private void handleTypeCycle(ErrorReporter t) {
  setReferencedType(
      registry.getNativeObjectType(JSTypeNative.UNKNOWN_TYPE));
  t.warning("Cycle detected in inheritance chain of type " + reference,
      sourceName, lineno, charno);
  setResolvedTypeInternal(getReferencedType());
}
 
Example #14
Source File: Closure_4_NamedType_s.java    From coming with MIT License 5 votes vote down vote up
private void checkEnumElementCycle(ErrorReporter t) {
  JSType referencedType = getReferencedType();
  if (referencedType instanceof EnumElementType &&
      ((EnumElementType) referencedType).getPrimitiveType() == this) {
    handleTypeCycle(t);
  }
}
 
Example #15
Source File: Closure_4_NamedType_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * Resolves a type by looking up its first component in the scope, and
 * subsequent components as properties. The scope must have been fully
 * parsed and a symbol table constructed.
 * @return The type of the symbol, or null if the type could not be found.
 */
private JSType lookupViaProperties( ErrorReporter t,
    StaticScope<JSType> enclosing) {
  String[] componentNames = reference.split("\\.", -1);
  if (componentNames[0].length() == 0) {
    return null;
  }
  StaticSlot<JSType> slot = enclosing.getSlot(componentNames[0]);
  if (slot == null) {
    return null;
  }
  // If the first component has a type of 'Unknown', then any type
  // names using it should be regarded as silently 'Unknown' rather than be
  // noisy about it.
  JSType slotType = slot.getType();
  if (slotType == null || slotType.isAllType() || slotType.isNoType()) {
    return null;
  }
  JSType value = getTypedefType(t, slot, componentNames[0]);
  if (value == null) {
    return null;
  }

  // resolving component by component
  for (int i = 1; i < componentNames.length; i++) {
    ObjectType parentClass = ObjectType.cast(value);
    if (parentClass == null) {
      return null;
    }
    if (componentNames[i].length() == 0) {
      return null;
    }
    value = parentClass.getPropertyType(componentNames[i]);
  }
  return value;
}
 
Example #16
Source File: PrototypeObjectType.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Override
JSType resolveInternal(ErrorReporter t, StaticScope<JSType> scope) {
  setResolvedTypeInternal(this);

  ObjectType implicitPrototype = getImplicitPrototype();
  if (implicitPrototype != null) {
    implicitPrototypeFallback =
        (ObjectType) implicitPrototype.resolve(t, scope);
  }
  for (Property prop : properties.values()) {
    prop.setType(safeResolve(prop.getType(), t, scope));
  }
  return this;
}
 
Example #17
Source File: Closure_39_PrototypeObjectType_s.java    From coming with MIT License 5 votes vote down vote up
@Override
JSType resolveInternal(ErrorReporter t, StaticScope<JSType> scope) {
  setResolvedTypeInternal(this);

  ObjectType implicitPrototype = getImplicitPrototype();
  if (implicitPrototype != null) {
    implicitPrototypeFallback =
        (ObjectType) implicitPrototype.resolve(t, scope);
  }
  for (Property prop : properties.values()) {
    prop.setType(safeResolve(prop.getType(), t, scope));
  }
  return this;
}
 
Example #18
Source File: Closure_39_PrototypeObjectType_t.java    From coming with MIT License 5 votes vote down vote up
@Override
JSType resolveInternal(ErrorReporter t, StaticScope<JSType> scope) {
  setResolvedTypeInternal(this);

  ObjectType implicitPrototype = getImplicitPrototype();
  if (implicitPrototype != null) {
    implicitPrototypeFallback =
        (ObjectType) implicitPrototype.resolve(t, scope);
  }
  for (Property prop : properties.values()) {
    prop.setType(safeResolve(prop.getType(), t, scope));
  }
  return this;
}
 
Example #19
Source File: Closure_4_NamedType_s.java    From coming with MIT License 5 votes vote down vote up
private void setReferencedAndResolvedType(JSType type, ErrorReporter t,
    StaticScope<JSType> enclosing) {
  if (validator != null) {
    validator.apply(type);
  }
  setReferencedType(type);
  checkEnumElementCycle(t);
  setResolvedTypeInternal(getReferencedType());
}
 
Example #20
Source File: Closure_4_NamedType_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * Resolves a named type by looking it up in the registry.
 * @return True if we resolved successfully.
 */
private boolean resolveViaRegistry(
    ErrorReporter t, StaticScope<JSType> enclosing) {
  JSType type = registry.getType(reference);
  if (type != null) {
    setReferencedAndResolvedType(type, t, enclosing);
    return true;
  }
  return false;
}
 
Example #21
Source File: Closure_4_NamedType_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * Resolve the referenced type within the enclosing scope.
 */
@Override
JSType resolveInternal(ErrorReporter t, StaticScope<JSType> enclosing) {
  // TODO(user): Investigate whether it is really necessary to keep two
  // different mechanisms for resolving named types, and if so, which order
  // makes more sense. Now, resolution via registry is first in order to
  // avoid triggering the warnings built into the resolution via properties.
  boolean resolved = resolveViaRegistry(t, enclosing);
  if (detectImplicitPrototypeCycle()) {
    handleTypeCycle(t);
  }

  if (resolved) {
    super.resolveInternal(t, enclosing);
    finishPropertyContinuations();
    return registry.isLastGeneration() ?
        getReferencedType() : this;
  }

  resolveViaProperties(t, enclosing);
  if (detectImplicitPrototypeCycle()) {
    handleTypeCycle(t);
  }

  super.resolveInternal(t, enclosing);
  if (isResolved()) {
    finishPropertyContinuations();
  }
  return registry.isLastGeneration() ?
      getReferencedType() : this;
}
 
Example #22
Source File: NamedType.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
private void handleTypeCycle(ErrorReporter t) {
  setReferencedType(
      registry.getNativeObjectType(JSTypeNative.UNKNOWN_TYPE));
  t.warning("Cycle detected in inheritance chain of type " + reference,
      sourceName, lineno, charno);
  setResolvedTypeInternal(getReferencedType());
}
 
Example #23
Source File: Closure_4_NamedType_t.java    From coming with MIT License 5 votes vote down vote up
private void handleTypeCycle(ErrorReporter t) {
  setReferencedType(
      registry.getNativeObjectType(JSTypeNative.UNKNOWN_TYPE));
  t.warning("Cycle detected in inheritance chain of type " + reference,
      sourceName, lineno, charno);
  setResolvedTypeInternal(getReferencedType());
}
 
Example #24
Source File: Closure_4_NamedType_t.java    From coming with MIT License 5 votes vote down vote up
private void setReferencedAndResolvedType(JSType type, ErrorReporter t,
    StaticScope<JSType> enclosing) {
  if (validator != null) {
    validator.apply(type);
  }
  setReferencedType(type);
  checkEnumElementCycle(t);
  setResolvedTypeInternal(getReferencedType());
}
 
Example #25
Source File: Closure_4_NamedType_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * Resolves a type by looking up its first component in the scope, and
 * subsequent components as properties. The scope must have been fully
 * parsed and a symbol table constructed.
 * @return The type of the symbol, or null if the type could not be found.
 */
private JSType lookupViaProperties( ErrorReporter t,
    StaticScope<JSType> enclosing) {
  String[] componentNames = reference.split("\\.", -1);
  if (componentNames[0].length() == 0) {
    return null;
  }
  StaticSlot<JSType> slot = enclosing.getSlot(componentNames[0]);
  if (slot == null) {
    return null;
  }
  // If the first component has a type of 'Unknown', then any type
  // names using it should be regarded as silently 'Unknown' rather than be
  // noisy about it.
  JSType slotType = slot.getType();
  if (slotType == null || slotType.isAllType() || slotType.isNoType()) {
    return null;
  }
  JSType value = getTypedefType(t, slot, componentNames[0]);
  if (value == null) {
    return null;
  }

  // resolving component by component
  for (int i = 1; i < componentNames.length; i++) {
    ObjectType parentClass = ObjectType.cast(value);
    if (parentClass == null) {
      return null;
    }
    if (componentNames[i].length() == 0) {
      return null;
    }
    value = parentClass.getPropertyType(componentNames[i]);
  }
  return value;
}
 
Example #26
Source File: NamedType.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Resolves a type by looking up its first component in the scope, and
 * subsequent components as properties. The scope must have been fully
 * parsed and a symbol table constructed.
 * @return The type of the symbol, or null if the type could not be found.
 */
private JSType lookupViaProperties( ErrorReporter t,
    StaticScope<JSType> enclosing) {
  String[] componentNames = reference.split("\\.", -1);
  if (componentNames[0].length() == 0) {
    return null;
  }
  StaticSlot<JSType> slot = enclosing.getSlot(componentNames[0]);
  if (slot == null) {
    return null;
  }
  // If the first component has a type of 'Unknown', then any type
  // names using it should be regarded as silently 'Unknown' rather than be
  // noisy about it.
  JSType slotType = slot.getType();
  if (slotType == null || slotType.isAllType() || slotType.isNoType()) {
    return null;
  }
  JSType value = getTypedefType(t, slot, componentNames[0]);
  if (value == null) {
    return null;
  }

  // resolving component by component
  for (int i = 1; i < componentNames.length; i++) {
    ObjectType parentClass = ObjectType.cast(value);
    if (parentClass == null) {
      return null;
    }
    if (componentNames[i].length() == 0) {
      return null;
    }
    value = parentClass.getPropertyType(componentNames[i]);
  }
  return value;
}
 
Example #27
Source File: Closure_4_NamedType_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * Resolves a named type by looking it up in the registry.
 * @return True if we resolved successfully.
 */
private boolean resolveViaRegistry(
    ErrorReporter t, StaticScope<JSType> enclosing) {
  JSType type = registry.getType(reference);
  if (type != null) {
    setReferencedAndResolvedType(type, t, enclosing);
    return true;
  }
  return false;
}
 
Example #28
Source File: Closure_4_NamedType_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * Resolve the referenced type within the enclosing scope.
 */
@Override
JSType resolveInternal(ErrorReporter t, StaticScope<JSType> enclosing) {
  // TODO(user): Investigate whether it is really necessary to keep two
  // different mechanisms for resolving named types, and if so, which order
  // makes more sense. Now, resolution via registry is first in order to
  // avoid triggering the warnings built into the resolution via properties.
  boolean resolved = resolveViaRegistry(t, enclosing);
  if (detectInheritanceCycle()) {
    handleTypeCycle(t);
  }

  if (resolved) {
    super.resolveInternal(t, enclosing);
    finishPropertyContinuations();
    return registry.isLastGeneration() ?
        getReferencedType() : this;
  }

  resolveViaProperties(t, enclosing);
  if (detectInheritanceCycle()) {
    handleTypeCycle(t);
  }

  super.resolveInternal(t, enclosing);
  if (isResolved()) {
    finishPropertyContinuations();
  }
  return registry.isLastGeneration() ?
      getReferencedType() : this;
}
 
Example #29
Source File: Closure_46_RecordType_t.java    From coming with MIT License 5 votes vote down vote up
@Override
JSType resolveInternal(ErrorReporter t, StaticScope<JSType> scope) {
  for (Map.Entry<String, JSType> entry : properties.entrySet()) {
    JSType type = entry.getValue();
    JSType resolvedType = type.resolve(t, scope);
    if (type != resolvedType) {
      properties.put(entry.getKey(), resolvedType);
    }
  }
  return super.resolveInternal(t, scope);
}
 
Example #30
Source File: patch1-Closure-7-Nopol2017_patch1-Closure-7-Nopol2017_s.java    From coming with MIT License 5 votes vote down vote up
/** @return The resolved type */
public static JSType assertValidResolve(
    JSType type, StaticScope<JSType> scope) {
  ErrorReporter t = TestErrorReporter.forNoExpectedReports();
  JSType resolvedType = type.resolve(t, scope);
  assertTypeEquals("JSType#resolve should not affect object equality",
      type, resolvedType);
  return resolvedType;
}