private StringStatus getStringStatus(JReferenceType type) {
   JClassType stringType = program.getTypeJavaLangString();
   if (type.isNullType()) {
     return StringStatus.NULL;
   } else if (program.typeOracle.castSucceedsTrivially(type, stringType)) {
     return StringStatus.STRING;
   } else if (program.typeOracle.castFailsTrivially(type, stringType)) {
     return StringStatus.NOTSTRING;
   } else {
     return StringStatus.UNKNOWN;
   }
 }
Example #2
0
  /** Returns an ast node representing the expression {@code expression != null}. */
  public static JExpression createOptimizedNotNullComparison(
      JProgram program, SourceInfo info, JExpression expression) {
    JReferenceType type = (JReferenceType) expression.getType();
    if (type.isNullType()) {
      return program.getLiteralBoolean(false);
    }

    if (!type.canBeNull()) {
      return createOptimizedMultiExpression(expression, program.getLiteralBoolean(true));
    }

    return new JBinaryOperation(
        info,
        program.getTypePrimitiveBoolean(),
        JBinaryOperator.NEQ,
        expression,
        program.getLiteralNull());
  }