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

The following examples show how to use com.google.javascript.rhino.jstype.JSType#toMaybeEnumType() . 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 6 votes vote down vote up
/**
 * <p>Checks enum aliases.
 *
 * <p>We verify that the enum element type of the enum used
 * for initialization is a subtype of the enum element type of
 * the enum the value is being copied in.</p>
 *
 * <p>Example:</p>
 * <pre>var myEnum = myOtherEnum;</pre>
 *
 * <p>Enum aliases are irregular, so we need special code for this :(</p>
 *
 * @param value the value used for initialization of the enum
 */
private void checkEnumAlias(
    NodeTraversal t, JSDocInfo declInfo, Node value) {
  if (declInfo == null || !declInfo.hasEnumParameterType()) {
    return;
  }

  JSType valueType = getJSType(value);
  if (!valueType.isEnumType()) {
    return;
  }

  EnumType valueEnumType = valueType.toMaybeEnumType();
  JSType valueEnumPrimitiveType =
      valueEnumType.getElementsType().getPrimitiveType();
  validator.expectCanAssignTo(t, value, valueEnumPrimitiveType,
      declInfo.getEnumParameterType().evaluate(t.getScope(), typeRegistry),
      "incompatible enum element types");
}
 
Example 2
Source File: Nopol2017_0029_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * <p>Checks enum aliases.
 *
 * <p>We verify that the enum element type of the enum used
 * for initialization is a subtype of the enum element type of
 * the enum the value is being copied in.</p>
 *
 * <p>Example:</p>
 * <pre>var myEnum = myOtherEnum;</pre>
 *
 * <p>Enum aliases are irregular, so we need special code for this :(</p>
 *
 * @param value the value used for initialization of the enum
 */
private void checkEnumAlias(
    NodeTraversal t, JSDocInfo declInfo, Node value) {
  if (declInfo == null || !declInfo.hasEnumParameterType()) {
    return;
  }

  JSType valueType = getJSType(value);
  if (!valueType.isEnumType()) {
    return;
  }

  EnumType valueEnumType = valueType.toMaybeEnumType();
  JSType valueEnumPrimitiveType =
      valueEnumType.getElementsType().getPrimitiveType();
  validator.expectCanAssignTo(t, value, valueEnumPrimitiveType,
      declInfo.getEnumParameterType().evaluate(t.getScope(), typeRegistry),
      "incompatible enum element types");
}
 
Example 3
Source File: Closure_125_TypeCheck_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * <p>Checks enum aliases.
 *
 * <p>We verify that the enum element type of the enum used
 * for initialization is a subtype of the enum element type of
 * the enum the value is being copied in.</p>
 *
 * <p>Example:</p>
 * <pre>var myEnum = myOtherEnum;</pre>
 *
 * <p>Enum aliases are irregular, so we need special code for this :(</p>
 *
 * @param value the value used for initialization of the enum
 */
private void checkEnumAlias(
    NodeTraversal t, JSDocInfo declInfo, Node value) {
  if (declInfo == null || !declInfo.hasEnumParameterType()) {
    return;
  }

  JSType valueType = getJSType(value);
  if (!valueType.isEnumType()) {
    return;
  }

  EnumType valueEnumType = valueType.toMaybeEnumType();
  JSType valueEnumPrimitiveType =
      valueEnumType.getElementsType().getPrimitiveType();
  validator.expectCanAssignTo(t, value, valueEnumPrimitiveType,
      declInfo.getEnumParameterType().evaluate(t.getScope(), typeRegistry),
      "incompatible enum element types");
}
 
Example 4
Source File: Closure_125_TypeCheck_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * <p>Checks enum aliases.
 *
 * <p>We verify that the enum element type of the enum used
 * for initialization is a subtype of the enum element type of
 * the enum the value is being copied in.</p>
 *
 * <p>Example:</p>
 * <pre>var myEnum = myOtherEnum;</pre>
 *
 * <p>Enum aliases are irregular, so we need special code for this :(</p>
 *
 * @param value the value used for initialization of the enum
 */
private void checkEnumAlias(
    NodeTraversal t, JSDocInfo declInfo, Node value) {
  if (declInfo == null || !declInfo.hasEnumParameterType()) {
    return;
  }

  JSType valueType = getJSType(value);
  if (!valueType.isEnumType()) {
    return;
  }

  EnumType valueEnumType = valueType.toMaybeEnumType();
  JSType valueEnumPrimitiveType =
      valueEnumType.getElementsType().getPrimitiveType();
  validator.expectCanAssignTo(t, value, valueEnumPrimitiveType,
      declInfo.getEnumParameterType().evaluate(t.getScope(), typeRegistry),
      "incompatible enum element types");
}
 
Example 5
Source File: Closure_11_TypeCheck_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * <p>Checks enum aliases.
 *
 * <p>We verify that the enum element type of the enum used
 * for initialization is a subtype of the enum element type of
 * the enum the value is being copied in.</p>
 *
 * <p>Example:</p>
 * <pre>var myEnum = myOtherEnum;</pre>
 *
 * <p>Enum aliases are irregular, so we need special code for this :(</p>
 *
 * @param value the value used for initialization of the enum
 */
private void checkEnumAlias(
    NodeTraversal t, JSDocInfo declInfo, Node value) {
  if (declInfo == null || !declInfo.hasEnumParameterType()) {
    return;
  }

  JSType valueType = getJSType(value);
  if (!valueType.isEnumType()) {
    return;
  }

  EnumType valueEnumType = valueType.toMaybeEnumType();
  JSType valueEnumPrimitiveType =
      valueEnumType.getElementsType().getPrimitiveType();
  validator.expectCanAssignTo(t, value, valueEnumPrimitiveType,
      declInfo.getEnumParameterType().evaluate(t.getScope(), typeRegistry),
      "incompatible enum element types");
}
 
Example 6
Source File: Closure_11_TypeCheck_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * <p>Checks enum aliases.
 *
 * <p>We verify that the enum element type of the enum used
 * for initialization is a subtype of the enum element type of
 * the enum the value is being copied in.</p>
 *
 * <p>Example:</p>
 * <pre>var myEnum = myOtherEnum;</pre>
 *
 * <p>Enum aliases are irregular, so we need special code for this :(</p>
 *
 * @param value the value used for initialization of the enum
 */
private void checkEnumAlias(
    NodeTraversal t, JSDocInfo declInfo, Node value) {
  if (declInfo == null || !declInfo.hasEnumParameterType()) {
    return;
  }

  JSType valueType = getJSType(value);
  if (!valueType.isEnumType()) {
    return;
  }

  EnumType valueEnumType = valueType.toMaybeEnumType();
  JSType valueEnumPrimitiveType =
      valueEnumType.getElementsType().getPrimitiveType();
  validator.expectCanAssignTo(t, value, valueEnumPrimitiveType,
      declInfo.getEnumParameterType().evaluate(t.getScope(), typeRegistry),
      "incompatible enum element types");
}
 
Example 7
Source File: Closure_2_TypeCheck_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * <p>Checks enum aliases.
 *
 * <p>We verify that the enum element type of the enum used
 * for initialization is a subtype of the enum element type of
 * the enum the value is being copied in.</p>
 *
 * <p>Example:</p>
 * <pre>var myEnum = myOtherEnum;</pre>
 *
 * <p>Enum aliases are irregular, so we need special code for this :(</p>
 *
 * @param value the value used for initialization of the enum
 */
private void checkEnumAlias(
    NodeTraversal t, JSDocInfo declInfo, Node value) {
  if (declInfo == null || !declInfo.hasEnumParameterType()) {
    return;
  }

  JSType valueType = getJSType(value);
  if (!valueType.isEnumType()) {
    return;
  }

  EnumType valueEnumType = valueType.toMaybeEnumType();
  JSType valueEnumPrimitiveType =
      valueEnumType.getElementsType().getPrimitiveType();
  validator.expectCanAssignTo(t, value, valueEnumPrimitiveType,
      declInfo.getEnumParameterType().evaluate(t.getScope(), typeRegistry),
      "incompatible enum element types");
}
 
Example 8
Source File: Closure_2_TypeCheck_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * <p>Checks enum aliases.
 *
 * <p>We verify that the enum element type of the enum used
 * for initialization is a subtype of the enum element type of
 * the enum the value is being copied in.</p>
 *
 * <p>Example:</p>
 * <pre>var myEnum = myOtherEnum;</pre>
 *
 * <p>Enum aliases are irregular, so we need special code for this :(</p>
 *
 * @param value the value used for initialization of the enum
 */
private void checkEnumAlias(
    NodeTraversal t, JSDocInfo declInfo, Node value) {
  if (declInfo == null || !declInfo.hasEnumParameterType()) {
    return;
  }

  JSType valueType = getJSType(value);
  if (!valueType.isEnumType()) {
    return;
  }

  EnumType valueEnumType = valueType.toMaybeEnumType();
  JSType valueEnumPrimitiveType =
      valueEnumType.getElementsType().getPrimitiveType();
  validator.expectCanAssignTo(t, value, valueEnumPrimitiveType,
      declInfo.getEnumParameterType().evaluate(t.getScope(), typeRegistry),
      "incompatible enum element types");
}
 
Example 9
Source File: TypeCheck.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * <p>Checks enum aliases.
 *
 * <p>We verify that the enum element type of the enum used
 * for initialization is a subtype of the enum element type of
 * the enum the value is being copied in.</p>
 *
 * <p>Example:</p>
 * <pre>var myEnum = myOtherEnum;</pre>
 *
 * <p>Enum aliases are irregular, so we need special code for this :(</p>
 *
 * @param value the value used for initialization of the enum
 */
private void checkEnumAlias(
    NodeTraversal t, JSDocInfo declInfo, Node value) {
  if (declInfo == null || !declInfo.hasEnumParameterType()) {
    return;
  }

  JSType valueType = getJSType(value);
  if (!valueType.isEnumType()) {
    return;
  }

  EnumType valueEnumType = valueType.toMaybeEnumType();
  JSType valueEnumPrimitiveType =
      valueEnumType.getElementsType().getPrimitiveType();
  validator.expectCanAssignTo(t, value, valueEnumPrimitiveType,
      declInfo.getEnumParameterType().evaluate(t.getScope(), typeRegistry),
      "incompatible enum element types");
}