Java Code Examples for com.google.javascript.rhino.jstype.JSType#isAllType()

The following examples show how to use com.google.javascript.rhino.jstype.JSType#isAllType() . 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: DisambiguateProperties.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
private void printErrorLocations(List<String> errors, JSType t) {
  if (!t.isObject() || t.isAllType()) {
    return;
  }

  if (t.isUnionType()) {
    for (JSType alt : t.toMaybeUnionType().getAlternates()) {
      printErrorLocations(errors, alt);
    }
    return;
  }

  for (JSError error : invalidationMap.get(t)) {
    if (errors.size() > MAX_INVALDIATION_WARNINGS_PER_PROPERTY) {
      return;
    }

    errors.add(
        t.toString() + " at " + error.sourceName + ":" + error.lineNumber);
  }
}
 
Example 2
Source File: Closure_118_DisambiguateProperties_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * Processes a GETPROP node.
 */
private void handleGetProp(NodeTraversal t, Node n) {
  String name = n.getLastChild().getString();
  T type = typeSystem.getType(getScope(), n.getFirstChild(), name);

  Property prop = getProperty(name);
  if (!prop.scheduleRenaming(n.getLastChild(),
                             processProperty(t, prop, type, null))) {
    if (propertiesToErrorFor.containsKey(name)) {
      String suggestion = "";
      if (type instanceof JSType) {
        JSType jsType = (JSType) type;
        if (jsType.isAllType() || jsType.isUnknownType()) {
          if (n.getFirstChild().isThis()) {
            suggestion = "The \"this\" object is unknown in the function," +
                "consider using @this";
          } else {
            String qName = n.getFirstChild().getQualifiedName();
            suggestion = "Consider casting " + qName +
                " if you know it's type.";
          }
        } else {
          List<String> errors = Lists.newArrayList();
          printErrorLocations(errors, jsType);
          if (!errors.isEmpty()) {
            suggestion = "Consider fixing errors for the following types:\n";
            suggestion += Joiner.on("\n").join(errors);
          }
        }
      }
      compiler.report(JSError.make(
          t.getSourceName(), n, propertiesToErrorFor.get(name),
          Warnings.INVALIDATION, name,
          (type == null ? "null" : type.toString()),
          n.toString(), suggestion));
    }
  }
}
 
Example 3
Source File: Closure_118_DisambiguateProperties_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * Processes a GETPROP node.
 */
private void handleGetProp(NodeTraversal t, Node n) {
  String name = n.getLastChild().getString();
  T type = typeSystem.getType(getScope(), n.getFirstChild(), name);

  Property prop = getProperty(name);
  if (!prop.scheduleRenaming(n.getLastChild(),
                             processProperty(t, prop, type, null))) {
    if (propertiesToErrorFor.containsKey(name)) {
      String suggestion = "";
      if (type instanceof JSType) {
        JSType jsType = (JSType) type;
        if (jsType.isAllType() || jsType.isUnknownType()) {
          if (n.getFirstChild().isThis()) {
            suggestion = "The \"this\" object is unknown in the function," +
                "consider using @this";
          } else {
            String qName = n.getFirstChild().getQualifiedName();
            suggestion = "Consider casting " + qName +
                " if you know it's type.";
          }
        } else {
          List<String> errors = Lists.newArrayList();
          printErrorLocations(errors, jsType);
          if (!errors.isEmpty()) {
            suggestion = "Consider fixing errors for the following types:\n";
            suggestion += Joiner.on("\n").join(errors);
          }
        }
      }
      compiler.report(JSError.make(
          t.getSourceName(), n, propertiesToErrorFor.get(name),
          Warnings.INVALIDATION, name,
          (type == null ? "null" : type.toString()),
          n.toString(), suggestion));
    }
  }
}
 
Example 4
Source File: DisambiguateProperties.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Processes a GETPROP node.
 */
private void handleGetProp(NodeTraversal t, Node n) {
  String name = n.getLastChild().getString();
  T type = typeSystem.getType(getScope(), n.getFirstChild(), name);

  Property prop = getProperty(name);
  if (!prop.scheduleRenaming(n.getLastChild(),
                             processProperty(t, prop, type, null))) {
    if (propertiesToErrorFor.containsKey(name)) {
      String suggestion = "";
      if (type instanceof JSType) {
        JSType jsType = (JSType) type;
        if (jsType.isAllType() || jsType.isUnknownType()) {
          if (n.getFirstChild().isThis()) {
            suggestion = "The \"this\" object is unknown in the function,"+
                "consider using @this";
          } else {
            String qName = n.getFirstChild().getQualifiedName();
            suggestion = "Consider casting " + qName +
                " if you know it's type.";
          }
        } else {
          List<String> errors = Lists.newArrayList();
          printErrorLocations(errors, jsType);
          if (!errors.isEmpty()) {
            suggestion = "Consider fixing errors for the following types:\n";
            suggestion += Joiner.on("\n").join(errors);
          }
        }
      }
      compiler.report(JSError.make(
          t.getSourceName(), n, propertiesToErrorFor.get(name),
          Warnings.INVALIDATION, name,
          (type == null ? "null" : type.toString()),
          n.toString(), suggestion));
    }
  }
}
 
Example 5
Source File: Closure_111_ClosureReverseAbstractInterpreter_t.java    From coming with MIT License 4 votes vote down vote up
@Override
protected JSType caseTopType(JSType topType) {
  return topType.isAllType() ?
      getNativeType(ARRAY_TYPE) : topType;
}