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

The following examples show how to use com.google.javascript.rhino.jstype.JSType#autobox() . 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: Nopol2017_0029_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * Emit a warning if we can prove that a property cannot possibly be
 * defined on an object. Note the difference between JS and a strictly
 * statically typed language: we're checking if the property
 * *cannot be defined*, whereas a java compiler would check if the
 * property *can be undefined*.
 */
private void checkPropertyAccess(JSType childType, String propName,
    NodeTraversal t, Node n) {
  // If the property type is unknown, check the object type to see if it
  // can ever be defined. We explicitly exclude CHECKED_UNKNOWN (for
  // properties where we've checked that it exists, or for properties on
  // objects that aren't in this binary).
  JSType propType = getJSType(n);
  if (propType.isEquivalentTo(typeRegistry.getNativeType(UNKNOWN_TYPE))) {
    childType = childType.autobox();
    ObjectType objectType = ObjectType.cast(childType);
    if (objectType != null) {
      // We special-case object types so that checks on enums can be
      // much stricter, and so that we can use hasProperty (which is much
      // faster in most cases).
      if (!objectType.hasProperty(propName) ||
          objectType.isEquivalentTo(
              typeRegistry.getNativeType(UNKNOWN_TYPE))) {
        if (objectType instanceof EnumType) {
          report(t, n, INEXISTENT_ENUM_ELEMENT, propName);
        } else {
          checkPropertyAccessHelper(objectType, propName, t, n);
        }
      }

    } else {
      checkPropertyAccessHelper(childType, propName, t, n);
    }
  }
}
 
Example 2
Source File: Nopol2017_0029_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * Emit a warning if we can prove that a property cannot possibly be
 * defined on an object. Note the difference between JS and a strictly
 * statically typed language: we're checking if the property
 * *cannot be defined*, whereas a java compiler would check if the
 * property *can be undefined*.
 */
private void checkPropertyAccess(JSType childType, String propName,
    NodeTraversal t, Node n) {
  // If the property type is unknown, check the object type to see if it
  // can ever be defined. We explicitly exclude CHECKED_UNKNOWN (for
  // properties where we've checked that it exists, or for properties on
  // objects that aren't in this binary).
  JSType propType = getJSType(n);
  if (propType.isEquivalentTo(typeRegistry.getNativeType(UNKNOWN_TYPE))) {
    childType = childType.autobox();
    ObjectType objectType = ObjectType.cast(childType);
    if (objectType != null) {
      // We special-case object types so that checks on enums can be
      // much stricter, and so that we can use hasProperty (which is much
      // faster in most cases).
      if (!objectType.hasProperty(propName) ||
          objectType.isEquivalentTo(
              typeRegistry.getNativeType(UNKNOWN_TYPE))) {
        if (objectType instanceof EnumType) {
          report(t, n, INEXISTENT_ENUM_ELEMENT, propName);
        } else {
          checkPropertyAccessHelper(objectType, propName, t, n);
        }
      }

    } else {
      checkPropertyAccessHelper(childType, propName, t, n);
    }
  }
}
 
Example 3
Source File: Closure_125_TypeCheck_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * Emit a warning if we can prove that a property cannot possibly be
 * defined on an object. Note the difference between JS and a strictly
 * statically typed language: we're checking if the property
 * *cannot be defined*, whereas a java compiler would check if the
 * property *can be undefined*.
 */
private void checkPropertyAccess(JSType childType, String propName,
    NodeTraversal t, Node n) {
  // If the property type is unknown, check the object type to see if it
  // can ever be defined. We explicitly exclude CHECKED_UNKNOWN (for
  // properties where we've checked that it exists, or for properties on
  // objects that aren't in this binary).
  JSType propType = getJSType(n);
  if (propType.isEquivalentTo(typeRegistry.getNativeType(UNKNOWN_TYPE))) {
    childType = childType.autobox();
    ObjectType objectType = ObjectType.cast(childType);
    if (objectType != null) {
      // We special-case object types so that checks on enums can be
      // much stricter, and so that we can use hasProperty (which is much
      // faster in most cases).
      if (!objectType.hasProperty(propName) ||
          objectType.isEquivalentTo(
              typeRegistry.getNativeType(UNKNOWN_TYPE))) {
        if (objectType instanceof EnumType) {
          report(t, n, INEXISTENT_ENUM_ELEMENT, propName);
        } else {
          checkPropertyAccessHelper(objectType, propName, t, n);
        }
      }

    } else {
      checkPropertyAccessHelper(childType, propName, t, n);
    }
  }
}
 
Example 4
Source File: Closure_125_TypeCheck_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * Emit a warning if we can prove that a property cannot possibly be
 * defined on an object. Note the difference between JS and a strictly
 * statically typed language: we're checking if the property
 * *cannot be defined*, whereas a java compiler would check if the
 * property *can be undefined*.
 */
private void checkPropertyAccess(JSType childType, String propName,
    NodeTraversal t, Node n) {
  // If the property type is unknown, check the object type to see if it
  // can ever be defined. We explicitly exclude CHECKED_UNKNOWN (for
  // properties where we've checked that it exists, or for properties on
  // objects that aren't in this binary).
  JSType propType = getJSType(n);
  if (propType.isEquivalentTo(typeRegistry.getNativeType(UNKNOWN_TYPE))) {
    childType = childType.autobox();
    ObjectType objectType = ObjectType.cast(childType);
    if (objectType != null) {
      // We special-case object types so that checks on enums can be
      // much stricter, and so that we can use hasProperty (which is much
      // faster in most cases).
      if (!objectType.hasProperty(propName) ||
          objectType.isEquivalentTo(
              typeRegistry.getNativeType(UNKNOWN_TYPE))) {
        if (objectType instanceof EnumType) {
          report(t, n, INEXISTENT_ENUM_ELEMENT, propName);
        } else {
          checkPropertyAccessHelper(objectType, propName, t, n);
        }
      }

    } else {
      checkPropertyAccessHelper(childType, propName, t, n);
    }
  }
}
 
Example 5
Source File: Closure_11_TypeCheck_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * Emit a warning if we can prove that a property cannot possibly be
 * defined on an object. Note the difference between JS and a strictly
 * statically typed language: we're checking if the property
 * *cannot be defined*, whereas a java compiler would check if the
 * property *can be undefined*.
 */
private void checkPropertyAccess(JSType childType, String propName,
    NodeTraversal t, Node n) {
  // If the property type is unknown, check the object type to see if it
  // can ever be defined. We explicitly exclude CHECKED_UNKNOWN (for
  // properties where we've checked that it exists, or for properties on
  // objects that aren't in this binary).
  JSType propType = getJSType(n);
  if (propType.isEquivalentTo(typeRegistry.getNativeType(UNKNOWN_TYPE))) {
    childType = childType.autobox();
    ObjectType objectType = ObjectType.cast(childType);
    if (objectType != null) {
      // We special-case object types so that checks on enums can be
      // much stricter, and so that we can use hasProperty (which is much
      // faster in most cases).
      if (!objectType.hasProperty(propName) ||
          objectType.isEquivalentTo(
              typeRegistry.getNativeType(UNKNOWN_TYPE))) {
        if (objectType instanceof EnumType) {
          report(t, n, INEXISTENT_ENUM_ELEMENT, propName);
        } else {
          checkPropertyAccessHelper(objectType, propName, t, n);
        }
      }

    } else {
      checkPropertyAccessHelper(childType, propName, t, n);
    }
  }
}
 
Example 6
Source File: Closure_11_TypeCheck_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * Emit a warning if we can prove that a property cannot possibly be
 * defined on an object. Note the difference between JS and a strictly
 * statically typed language: we're checking if the property
 * *cannot be defined*, whereas a java compiler would check if the
 * property *can be undefined*.
 */
private void checkPropertyAccess(JSType childType, String propName,
    NodeTraversal t, Node n) {
  // If the property type is unknown, check the object type to see if it
  // can ever be defined. We explicitly exclude CHECKED_UNKNOWN (for
  // properties where we've checked that it exists, or for properties on
  // objects that aren't in this binary).
  JSType propType = getJSType(n);
  if (propType.isEquivalentTo(typeRegistry.getNativeType(UNKNOWN_TYPE))) {
    childType = childType.autobox();
    ObjectType objectType = ObjectType.cast(childType);
    if (objectType != null) {
      // We special-case object types so that checks on enums can be
      // much stricter, and so that we can use hasProperty (which is much
      // faster in most cases).
      if (!objectType.hasProperty(propName) ||
          objectType.isEquivalentTo(
              typeRegistry.getNativeType(UNKNOWN_TYPE))) {
        if (objectType instanceof EnumType) {
          report(t, n, INEXISTENT_ENUM_ELEMENT, propName);
        } else {
          checkPropertyAccessHelper(objectType, propName, t, n);
        }
      }

    } else {
      checkPropertyAccessHelper(childType, propName, t, n);
    }
  }
}
 
Example 7
Source File: Closure_2_TypeCheck_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * Emit a warning if we can prove that a property cannot possibly be
 * defined on an object. Note the difference between JS and a strictly
 * statically typed language: we're checking if the property
 * *cannot be defined*, whereas a java compiler would check if the
 * property *can be undefined*.
 */
private void checkPropertyAccess(JSType childType, String propName,
    NodeTraversal t, Node n) {
  // If the property type is unknown, check the object type to see if it
  // can ever be defined. We explicitly exclude CHECKED_UNKNOWN (for
  // properties where we've checked that it exists, or for properties on
  // objects that aren't in this binary).
  JSType propType = getJSType(n);
  if (propType.isEquivalentTo(typeRegistry.getNativeType(UNKNOWN_TYPE))) {
    childType = childType.autobox();
    ObjectType objectType = ObjectType.cast(childType);
    if (objectType != null) {
      // We special-case object types so that checks on enums can be
      // much stricter, and so that we can use hasProperty (which is much
      // faster in most cases).
      if (!objectType.hasProperty(propName) ||
          objectType.isEquivalentTo(
              typeRegistry.getNativeType(UNKNOWN_TYPE))) {
        if (objectType instanceof EnumType) {
          report(t, n, INEXISTENT_ENUM_ELEMENT, propName);
        } else {
          checkPropertyAccessHelper(objectType, propName, t, n);
        }
      }

    } else {
      checkPropertyAccessHelper(childType, propName, t, n);
    }
  }
}
 
Example 8
Source File: Closure_2_TypeCheck_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * Emit a warning if we can prove that a property cannot possibly be
 * defined on an object. Note the difference between JS and a strictly
 * statically typed language: we're checking if the property
 * *cannot be defined*, whereas a java compiler would check if the
 * property *can be undefined*.
 */
private void checkPropertyAccess(JSType childType, String propName,
    NodeTraversal t, Node n) {
  // If the property type is unknown, check the object type to see if it
  // can ever be defined. We explicitly exclude CHECKED_UNKNOWN (for
  // properties where we've checked that it exists, or for properties on
  // objects that aren't in this binary).
  JSType propType = getJSType(n);
  if (propType.isEquivalentTo(typeRegistry.getNativeType(UNKNOWN_TYPE))) {
    childType = childType.autobox();
    ObjectType objectType = ObjectType.cast(childType);
    if (objectType != null) {
      // We special-case object types so that checks on enums can be
      // much stricter, and so that we can use hasProperty (which is much
      // faster in most cases).
      if (!objectType.hasProperty(propName) ||
          objectType.isEquivalentTo(
              typeRegistry.getNativeType(UNKNOWN_TYPE))) {
        if (objectType instanceof EnumType) {
          report(t, n, INEXISTENT_ENUM_ELEMENT, propName);
        } else {
          checkPropertyAccessHelper(objectType, propName, t, n);
        }
      }

    } else {
      checkPropertyAccessHelper(childType, propName, t, n);
    }
  }
}
 
Example 9
Source File: TypeCheck.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Emit a warning if we can prove that a property cannot possibly be
 * defined on an object. Note the difference between JS and a strictly
 * statically typed language: we're checking if the property
 * *cannot be defined*, whereas a java compiler would check if the
 * property *can be undefined*.
 */
private void checkPropertyAccess(JSType childType, String propName,
    NodeTraversal t, Node n) {
  // If the property type is unknown, check the object type to see if it
  // can ever be defined. We explicitly exclude CHECKED_UNKNOWN (for
  // properties where we've checked that it exists, or for properties on
  // objects that aren't in this binary).
  JSType propType = getJSType(n);
  if (propType.isEquivalentTo(typeRegistry.getNativeType(UNKNOWN_TYPE))) {
    childType = childType.autobox();
    ObjectType objectType = ObjectType.cast(childType);
    if (objectType != null) {
      // We special-case object types so that checks on enums can be
      // much stricter, and so that we can use hasProperty (which is much
      // faster in most cases).
      if (!objectType.hasProperty(propName) ||
          objectType.isEquivalentTo(
              typeRegistry.getNativeType(UNKNOWN_TYPE))) {
        if (objectType instanceof EnumType) {
          report(t, n, INEXISTENT_ENUM_ELEMENT, propName);
        } else {
          checkPropertyAccessHelper(objectType, propName, t, n);
        }
      }

    } else {
      checkPropertyAccessHelper(childType, propName, t, n);
    }
  }
}