Java Code Examples for com.google.javascript.rhino.jstype.ObjectType#isEmptyType()

The following examples show how to use com.google.javascript.rhino.jstype.ObjectType#isEmptyType() . 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: Closure_125_TypeCheck_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * Given a constructor or an interface type, find out whether the unknown
 * type is a supertype of the current type.
 */
private static boolean hasUnknownOrEmptySupertype(FunctionType ctor) {
  Preconditions.checkArgument(ctor.isConstructor() || ctor.isInterface());
  Preconditions.checkArgument(!ctor.isUnknownType());

  // The type system should notice inheritance cycles on its own
  // and break the cycle.
  while (true) {
    ObjectType maybeSuperInstanceType =
        ctor.getPrototype().getImplicitPrototype();
    if (maybeSuperInstanceType == null) {
      return false;
    }
    if (maybeSuperInstanceType.isUnknownType() ||
        maybeSuperInstanceType.isEmptyType()) {
      return true;
    }
    ctor = maybeSuperInstanceType.getConstructor();
    if (ctor == null) {
      return false;
    }
    Preconditions.checkState(ctor.isConstructor() || ctor.isInterface());
  }
}
 
Example 2
Source File: Closure_41_FunctionTypeBuilder_s.java    From coming with MIT License 6 votes vote down vote up
@Override
public boolean apply(JSType type) {
  ObjectType objectType = ObjectType.cast(type);
  if (objectType == null) {
    reportError(BAD_IMPLEMENTED_TYPE, fnName);
    return false;
  } else if (objectType.isEmptyType()) {
    reportWarning(RESOLVED_TAG_EMPTY, "@implements", fnName);
    return false;
  } else if (objectType.isUnknownType()) {
    if (hasMoreTagsToResolve(objectType)) {
      return true;
    } else {
      reportWarning(RESOLVED_TAG_EMPTY, "@implements", fnName);
      return false;
    }
  } else {
    return true;
  }
}
 
Example 3
Source File: Closure_41_FunctionTypeBuilder_s.java    From coming with MIT License 6 votes vote down vote up
@Override
public boolean apply(JSType type) {
  ObjectType objectType = ObjectType.cast(type);
  if (objectType == null) {
    reportWarning(EXTENDS_NON_OBJECT, fnName, type.toString());
    return false;
  } else if (objectType.isEmptyType()) {
    reportWarning(RESOLVED_TAG_EMPTY, "@extends", fnName);
    return false;
  } else if (objectType.isUnknownType()) {
    if (hasMoreTagsToResolve(objectType)) {
      return true;
    } else {
      reportWarning(RESOLVED_TAG_EMPTY, "@extends", fnName);
      return false;
    }
  } else {
    return true;
  }
}
 
Example 4
Source File: Closure_11_TypeCheck_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * Given a constructor or an interface type, find out whether the unknown
 * type is a supertype of the current type.
 */
private static boolean hasUnknownOrEmptySupertype(FunctionType ctor) {
  Preconditions.checkArgument(ctor.isConstructor() || ctor.isInterface());
  Preconditions.checkArgument(!ctor.isUnknownType());

  // The type system should notice inheritance cycles on its own
  // and break the cycle.
  while (true) {
    ObjectType maybeSuperInstanceType =
        ctor.getPrototype().getImplicitPrototype();
    if (maybeSuperInstanceType == null) {
      return false;
    }
    if (maybeSuperInstanceType.isUnknownType() ||
        maybeSuperInstanceType.isEmptyType()) {
      return true;
    }
    ctor = maybeSuperInstanceType.getConstructor();
    if (ctor == null) {
      return false;
    }
    Preconditions.checkState(ctor.isConstructor() || ctor.isInterface());
  }
}
 
Example 5
Source File: Closure_11_TypeCheck_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * Given a constructor or an interface type, find out whether the unknown
 * type is a supertype of the current type.
 */
private static boolean hasUnknownOrEmptySupertype(FunctionType ctor) {
  Preconditions.checkArgument(ctor.isConstructor() || ctor.isInterface());
  Preconditions.checkArgument(!ctor.isUnknownType());

  // The type system should notice inheritance cycles on its own
  // and break the cycle.
  while (true) {
    ObjectType maybeSuperInstanceType =
        ctor.getPrototype().getImplicitPrototype();
    if (maybeSuperInstanceType == null) {
      return false;
    }
    if (maybeSuperInstanceType.isUnknownType() ||
        maybeSuperInstanceType.isEmptyType()) {
      return true;
    }
    ctor = maybeSuperInstanceType.getConstructor();
    if (ctor == null) {
      return false;
    }
    Preconditions.checkState(ctor.isConstructor() || ctor.isInterface());
  }
}
 
Example 6
Source File: Closure_41_FunctionTypeBuilder_t.java    From coming with MIT License 6 votes vote down vote up
@Override
public boolean apply(JSType type) {
  ObjectType objectType = ObjectType.cast(type);
  if (objectType == null) {
    reportWarning(EXTENDS_NON_OBJECT, fnName, type.toString());
    return false;
  } else if (objectType.isEmptyType()) {
    reportWarning(RESOLVED_TAG_EMPTY, "@extends", fnName);
    return false;
  } else if (objectType.isUnknownType()) {
    if (hasMoreTagsToResolve(objectType)) {
      return true;
    } else {
      reportWarning(RESOLVED_TAG_EMPTY, "@extends", fnName);
      return false;
    }
  } else {
    return true;
  }
}
 
Example 7
Source File: Closure_66_TypeCheck_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * Given a constructor or an interface type, find out whether the unknown
 * type is a supertype of the current type.
 */
private static boolean hasUnknownOrEmptySupertype(FunctionType ctor) {
  Preconditions.checkArgument(ctor.isConstructor() || ctor.isInterface());
  Preconditions.checkArgument(!ctor.isUnknownType());

  // The type system should notice inheritance cycles on its own
  // and break the cycle.
  while (true) {
    ObjectType maybeSuperInstanceType =
        ctor.getPrototype().getImplicitPrototype();
    if (maybeSuperInstanceType == null) {
      return false;
    }
    if (maybeSuperInstanceType.isUnknownType() ||
        maybeSuperInstanceType.isEmptyType()) {
      return true;
    }
    ctor = maybeSuperInstanceType.getConstructor();
    if (ctor == null) {
      return false;
    }
    Preconditions.checkState(ctor.isConstructor() || ctor.isInterface());
  }
}
 
Example 8
Source File: TypeCheck.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Given a constructor or an interface type, find out whether the unknown
 * type is a supertype of the current type.
 */
private static boolean hasUnknownOrEmptySupertype(FunctionType ctor) {
  Preconditions.checkArgument(ctor.isConstructor() || ctor.isInterface());
  Preconditions.checkArgument(!ctor.isUnknownType());

  // The type system should notice inheritance cycles on its own
  // and break the cycle.
  while (true) {
    ObjectType maybeSuperInstanceType =
        ctor.getPrototype().getImplicitPrototype();
    if (maybeSuperInstanceType == null) {
      return false;
    }
    if (maybeSuperInstanceType.isUnknownType() ||
        maybeSuperInstanceType.isEmptyType()) {
      return true;
    }
    ctor = maybeSuperInstanceType.getConstructor();
    if (ctor == null) {
      return false;
    }
    Preconditions.checkState(ctor.isConstructor() || ctor.isInterface());
  }
}
 
Example 9
Source File: Closure_66_TypeCheck_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * Given a constructor or an interface type, find out whether the unknown
 * type is a supertype of the current type.
 */
private static boolean hasUnknownOrEmptySupertype(FunctionType ctor) {
  Preconditions.checkArgument(ctor.isConstructor() || ctor.isInterface());
  Preconditions.checkArgument(!ctor.isUnknownType());

  // The type system should notice inheritance cycles on its own
  // and break the cycle.
  while (true) {
    ObjectType maybeSuperInstanceType =
        ctor.getPrototype().getImplicitPrototype();
    if (maybeSuperInstanceType == null) {
      return false;
    }
    if (maybeSuperInstanceType.isUnknownType() ||
        maybeSuperInstanceType.isEmptyType()) {
      return true;
    }
    ctor = maybeSuperInstanceType.getConstructor();
    if (ctor == null) {
      return false;
    }
    Preconditions.checkState(ctor.isConstructor() || ctor.isInterface());
  }
}
 
Example 10
Source File: Closure_125_TypeCheck_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * Given a constructor or an interface type, find out whether the unknown
 * type is a supertype of the current type.
 */
private static boolean hasUnknownOrEmptySupertype(FunctionType ctor) {
  Preconditions.checkArgument(ctor.isConstructor() || ctor.isInterface());
  Preconditions.checkArgument(!ctor.isUnknownType());

  // The type system should notice inheritance cycles on its own
  // and break the cycle.
  while (true) {
    ObjectType maybeSuperInstanceType =
        ctor.getPrototype().getImplicitPrototype();
    if (maybeSuperInstanceType == null) {
      return false;
    }
    if (maybeSuperInstanceType.isUnknownType() ||
        maybeSuperInstanceType.isEmptyType()) {
      return true;
    }
    ctor = maybeSuperInstanceType.getConstructor();
    if (ctor == null) {
      return false;
    }
    Preconditions.checkState(ctor.isConstructor() || ctor.isInterface());
  }
}
 
Example 11
Source File: Nopol2017_0051_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * Given a constructor or an interface type, find out whether the unknown
 * type is a supertype of the current type.
 */
private static boolean hasUnknownOrEmptySupertype(FunctionType ctor) {
  Preconditions.checkArgument(ctor.isConstructor() || ctor.isInterface());
  Preconditions.checkArgument(!ctor.isUnknownType());

  // The type system should notice inheritance cycles on its own
  // and break the cycle.
  while (true) {
    ObjectType maybeSuperInstanceType =
        ctor.getPrototype().getImplicitPrototype();
    if (maybeSuperInstanceType == null) {
      return false;
    }
    if (maybeSuperInstanceType.isUnknownType() ||
        maybeSuperInstanceType.isEmptyType()) {
      return true;
    }
    ctor = maybeSuperInstanceType.getConstructor();
    if (ctor == null) {
      return false;
    }
    Preconditions.checkState(ctor.isConstructor() || ctor.isInterface());
  }
}
 
Example 12
Source File: InlineProperties.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/** Returns true if properties on this type should not be renamed. */
private boolean isInvalidatingType(JSType type) {
  if (type.isUnionType()) {
    type = type.restrictByNotNullOrUndefined();
    if (type.isUnionType()) {
      for (JSType alt : type.toMaybeUnionType().getAlternates()) {
        if (isInvalidatingType(alt)) {
          return true;
        }
      }
      return false;
    }
  }
  ObjectType objType = ObjectType.cast(type);
  return objType == null
      || invalidatingTypes.contains(objType)
      || !objType.hasReferenceName()
      || objType.isUnknownType()
      || objType.isEmptyType() /* unresolved types */
      || objType.isEnumType()
      || objType.autoboxesTo() != null;
}
 
Example 13
Source File: Closure_69_TypeCheck_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * Given a constructor or an interface type, find out whether the unknown
 * type is a supertype of the current type.
 */
private static boolean hasUnknownOrEmptySupertype(FunctionType ctor) {
  Preconditions.checkArgument(ctor.isConstructor() || ctor.isInterface());
  Preconditions.checkArgument(!ctor.isUnknownType());

  // The type system should notice inheritance cycles on its own
  // and break the cycle.
  while (true) {
    ObjectType maybeSuperInstanceType =
        ctor.getPrototype().getImplicitPrototype();
    if (maybeSuperInstanceType == null) {
      return false;
    }
    if (maybeSuperInstanceType.isUnknownType() ||
        maybeSuperInstanceType.isEmptyType()) {
      return true;
    }
    ctor = maybeSuperInstanceType.getConstructor();
    if (ctor == null) {
      return false;
    }
    Preconditions.checkState(ctor.isConstructor() || ctor.isInterface());
  }
}
 
Example 14
Source File: Closure_69_TypeCheck_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * Make sure that the access of this property is ok.
 */
private void checkPropertyAccess(JSType childType, String propName,
    NodeTraversal t, Node n) {
  ObjectType objectType = childType.dereference();
  if (objectType != null) {
    JSType propType = getJSType(n);
    if ((!objectType.hasProperty(propName) ||
         objectType.equals(typeRegistry.getNativeType(UNKNOWN_TYPE))) &&
        propType.equals(typeRegistry.getNativeType(UNKNOWN_TYPE))) {
      if (objectType instanceof EnumType) {
        report(t, n, INEXISTENT_ENUM_ELEMENT, propName);
      } else if (!objectType.isEmptyType() &&
          reportMissingProperties && !isPropertyTest(n)) {
        if (!typeRegistry.canPropertyBeDefined(objectType, propName)) {
          report(t, n, INEXISTENT_PROPERTY, propName,
              validator.getReadableJSTypeName(n.getFirstChild(), true));
        }
      }
    }
  } else {
    // TODO(nicksantos): might want to flag the access on a non object when
    // it's impossible to get a property from this type.
  }
}
 
Example 15
Source File: Closure_69_TypeCheck_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * Given a constructor or an interface type, find out whether the unknown
 * type is a supertype of the current type.
 */
private static boolean hasUnknownOrEmptySupertype(FunctionType ctor) {
  Preconditions.checkArgument(ctor.isConstructor() || ctor.isInterface());
  Preconditions.checkArgument(!ctor.isUnknownType());

  // The type system should notice inheritance cycles on its own
  // and break the cycle.
  while (true) {
    ObjectType maybeSuperInstanceType =
        ctor.getPrototype().getImplicitPrototype();
    if (maybeSuperInstanceType == null) {
      return false;
    }
    if (maybeSuperInstanceType.isUnknownType() ||
        maybeSuperInstanceType.isEmptyType()) {
      return true;
    }
    ctor = maybeSuperInstanceType.getConstructor();
    if (ctor == null) {
      return false;
    }
    Preconditions.checkState(ctor.isConstructor() || ctor.isInterface());
  }
}
 
Example 16
Source File: AmbiguateProperties.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/** Returns true if properties on this type should not be renamed. */
private boolean isInvalidatingType(JSType type) {
  if (type.isUnionType()) {
    type = type.restrictByNotNullOrUndefined();
    if (type.isUnionType()) {
      for (JSType alt : type.toMaybeUnionType().getAlternates()) {
        if (isInvalidatingType(alt)) {
          return true;
        }
      }
      return false;
    }
  }
  ObjectType objType = ObjectType.cast(type);
  return objType == null
      || invalidatingTypes.contains(objType)
      || !objType.hasReferenceName()
      || objType.isUnknownType()
      || objType.isEmptyType() /* unresolved types */
      || objType.isEnumType()
      || objType.autoboxesTo() != null;
}
 
Example 17
Source File: Nopol2017_0029_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * Given a constructor or an interface type, find out whether the unknown
 * type is a supertype of the current type.
 */
private static boolean hasUnknownOrEmptySupertype(FunctionType ctor) {
  Preconditions.checkArgument(ctor.isConstructor() || ctor.isInterface());
  Preconditions.checkArgument(!ctor.isUnknownType());

  // The type system should notice inheritance cycles on its own
  // and break the cycle.
  while (true) {
    ObjectType maybeSuperInstanceType =
        ctor.getPrototype().getImplicitPrototype();
    if (maybeSuperInstanceType == null) {
      return false;
    }
    if (maybeSuperInstanceType.isUnknownType() ||
        maybeSuperInstanceType.isEmptyType()) {
      return true;
    }
    ctor = maybeSuperInstanceType.getConstructor();
    if (ctor == null) {
      return false;
    }
    Preconditions.checkState(ctor.isConstructor() || ctor.isInterface());
  }
}
 
Example 18
Source File: Closure_96_TypeCheck_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * Make sure that the access of this property is ok.
 */
private void checkPropertyAccess(JSType childType, String propName,
    NodeTraversal t, Node n) {
  ObjectType objectType = childType.dereference();
  if (objectType != null) {
    JSType propType = getJSType(n);
    if ((!objectType.hasProperty(propName) ||
         objectType.equals(typeRegistry.getNativeType(UNKNOWN_TYPE))) &&
        propType.equals(typeRegistry.getNativeType(UNKNOWN_TYPE))) {
      if (objectType instanceof EnumType) {
        report(t, n, INEXISTENT_ENUM_ELEMENT, propName);
      } else if (!objectType.isEmptyType() &&
          reportMissingProperties && !isPropertyTest(n)) {
        if (!typeRegistry.canPropertyBeDefined(objectType, propName)) {
          report(t, n, INEXISTENT_PROPERTY, propName,
              validator.getReadableJSTypeName(n.getFirstChild(), true));
        }
      }
    }
  } else {
    // TODO(nicksantos): might want to flag the access on a non object when
    // it's impossible to get a property from this type.
  }
}
 
Example 19
Source File: Nopol2017_0051_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * Given a constructor or an interface type, find out whether the unknown
 * type is a supertype of the current type.
 */
private static boolean hasUnknownOrEmptySupertype(FunctionType ctor) {
  Preconditions.checkArgument(ctor.isConstructor() || ctor.isInterface());
  Preconditions.checkArgument(!ctor.isUnknownType());

  // The type system should notice inheritance cycles on its own
  // and break the cycle.
  while (true) {
    ObjectType maybeSuperInstanceType =
        ctor.getPrototype().getImplicitPrototype();
    if (maybeSuperInstanceType == null) {
      return false;
    }
    if (maybeSuperInstanceType.isUnknownType() ||
        maybeSuperInstanceType.isEmptyType()) {
      return true;
    }
    ctor = maybeSuperInstanceType.getConstructor();
    if (ctor == null) {
      return false;
    }
    Preconditions.checkState(ctor.isConstructor() || ctor.isInterface());
  }
}
 
Example 20
Source File: Nopol2017_0051_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * Make sure that the access of this property is ok.
 */
private void checkPropertyAccess(JSType childType, String propName,
    NodeTraversal t, Node n) {
  ObjectType objectType = childType.dereference();
  if (objectType != null) {
    JSType propType = getJSType(n);
    if ((!objectType.hasProperty(propName) ||
         objectType.equals(typeRegistry.getNativeType(UNKNOWN_TYPE))) &&
        propType.equals(typeRegistry.getNativeType(UNKNOWN_TYPE))) {
      if (objectType instanceof EnumType) {
        report(t, n, INEXISTENT_ENUM_ELEMENT, propName);
      } else if (!objectType.isEmptyType() &&
          reportMissingProperties && !isPropertyTest(n)) {
        if (!typeRegistry.canPropertyBeDefined(objectType, propName)) {
          report(t, n, INEXISTENT_PROPERTY, propName,
              validator.getReadableJSTypeName(n.getFirstChild(), true));
        }
      }
    }
  } else {
    // TODO(nicksantos): might want to flag the access on a non object when
    // it's impossible to get a property from this type.
  }
}