當前位置: 首頁>>代碼示例>>Java>>正文


Java Type.isPrimitive方法代碼示例

本文整理匯總了Java中com.sun.tools.javac.code.Type.isPrimitive方法的典型用法代碼示例。如果您正苦於以下問題:Java Type.isPrimitive方法的具體用法?Java Type.isPrimitive怎麽用?Java Type.isPrimitive使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.sun.tools.javac.code.Type的用法示例。


在下文中一共展示了Type.isPrimitive方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: checkReturnExpression

import com.sun.tools.javac.code.Type; //導入方法依賴的package包/類
private Description checkReturnExpression(
    Tree tree, ExpressionTree retExpr, Symbol.MethodSymbol methodSymbol, VisitorState state) {
  Type returnType = methodSymbol.getReturnType();
  if (returnType.isPrimitive()) {
    // check for unboxing
    return doUnboxingCheck(state, retExpr);
  }
  if (returnType.toString().equals("java.lang.Void")) {
    return Description.NO_MATCH;
  }
  if (NullabilityUtil.fromUnannotatedPackage(methodSymbol, config)
      || Nullness.hasNullableAnnotation(methodSymbol)) {
    return Description.NO_MATCH;
  }
  if (mayBeNullExpr(state, retExpr)) {
    String message = "returning @Nullable expression from method with @NonNull return type";
    return createErrorDescriptionForNullAssignment(
        MessageTypes.RETURN_NULLABLE, tree, message, retExpr, state.getPath());
  }
  return Description.NO_MATCH;
}
 
開發者ID:uber,項目名稱:NullAway,代碼行數:22,代碼來源:NullAway.java

示例2: matchBinary

import com.sun.tools.javac.code.Type; //導入方法依賴的package包/類
@Override
public Description matchBinary(BinaryTree tree, VisitorState state) {
  ExpressionTree leftOperand = tree.getLeftOperand();
  ExpressionTree rightOperand = tree.getRightOperand();
  Type leftType = ASTHelpers.getType(leftOperand);
  Type rightType = ASTHelpers.getType(rightOperand);
  if (leftType == null || rightType == null) {
    throw new RuntimeException();
  }
  if (leftType.isPrimitive() && !rightType.isPrimitive()) {
    return doUnboxingCheck(state, rightOperand);
  }
  if (rightType.isPrimitive() && !leftType.isPrimitive()) {
    return doUnboxingCheck(state, leftOperand);
  }
  return Description.NO_MATCH;
}
 
開發者ID:uber,項目名稱:NullAway,代碼行數:18,代碼來源:NullAway.java

示例3: doUnboxingCheck

import com.sun.tools.javac.code.Type; //導入方法依賴的package包/類
/**
 * if any expression has non-primitive type, we should check that it can't be null as it is
 * getting unboxed
 *
 * @param expressions expressions to check
 * @return error Description if an error is found, otherwise NO_MATCH
 */
private Description doUnboxingCheck(VisitorState state, ExpressionTree... expressions) {
  for (ExpressionTree tree : expressions) {
    Type type = ASTHelpers.getType(tree);
    if (type == null) {
      throw new RuntimeException("was not expecting null type");
    }
    if (!type.isPrimitive()) {
      if (mayBeNullExpr(state, tree)) {
        return createErrorDescription(
            MessageTypes.UNBOX_NULLABLE, tree, "unboxing of a @Nullable value", state.getPath());
      }
    }
  }
  return Description.NO_MATCH;
}
 
開發者ID:uber,項目名稱:NullAway,代碼行數:23,代碼來源:NullAway.java

示例4: getKind

import com.sun.tools.javac.code.Type; //導入方法依賴的package包/類
/**
 * Retrieve the comparison kind associated with the given argument type pair.
 */
private ComparisonKind getKind(Type arg1, Type arg2) {
    boolean arg1Primitive = arg1.isPrimitive();
    boolean arg2Primitive = arg2.isPrimitive();
    if (arg1Primitive && arg2Primitive) {
        return ComparisonKind.NUMERIC_OR_BOOLEAN;
    } else if (arg1Primitive) {
        return unaryPromotion(arg2).isPrimitive() ?
                ComparisonKind.NUMERIC_OR_BOOLEAN : ComparisonKind.INVALID;
    } else if (arg2Primitive) {
        return unaryPromotion(arg1).isPrimitive() ?
                ComparisonKind.NUMERIC_OR_BOOLEAN : ComparisonKind.INVALID;
    } else {
        return arg1.isNullOrReference() && arg2.isNullOrReference() ?
                ComparisonKind.REFERENCE : ComparisonKind.INVALID;
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:20,代碼來源:Operators.java

示例5: matchAssignment

import com.sun.tools.javac.code.Type; //導入方法依賴的package包/類
@Override
public Description matchAssignment(AssignmentTree tree, VisitorState state) {
  if (!matchWithinClass) {
    return Description.NO_MATCH;
  }
  Type lhsType = ASTHelpers.getType(tree.getVariable());
  if (lhsType != null && lhsType.isPrimitive()) {
    return doUnboxingCheck(state, tree.getExpression());
  }
  Symbol assigned = ASTHelpers.getSymbol(tree.getVariable());
  if (assigned == null || assigned.getKind() != ElementKind.FIELD) {
    // not a field of nullable type
    return Description.NO_MATCH;
  }

  if (Nullness.hasNullableAnnotation(assigned)) {
    // field already annotated
    return Description.NO_MATCH;
  }
  ExpressionTree expression = tree.getExpression();
  if (mayBeNullExpr(state, expression)) {
    String message = "assigning @Nullable expression to @NonNull field";
    return createErrorDescriptionForNullAssignment(
        MessageTypes.ASSIGN_FIELD_NULLABLE, tree, message, expression, state.getPath());
  }
  return Description.NO_MATCH;
}
 
開發者ID:uber,項目名稱:NullAway,代碼行數:28,代碼來源:NullAway.java

示例6: stringPromotion

import com.sun.tools.javac.code.Type; //導入方法依賴的package包/類
/**
 * This routine applies following mappings:
 * - if input type is primitive, apply numeric promotion
 * - if input type is either 'void', 'null' or 'String' leave it untouched
 * - otherwise return 'Object'
 */
private Type stringPromotion(Type t) {
    if (t.isPrimitive()) {
        return unaryPromotion(t);
    } else if (t.hasTag(TypeTag.VOID) || t.hasTag(TypeTag.BOT) ||
            types.isSameType(t, syms.stringType)) {
        return t;
    } else if (t.hasTag(TypeTag.TYPEVAR)) {
        return stringPromotion(t.getUpperBound());
    } else {
        return syms.objectType;
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:19,代碼來源:Operators.java

示例7: pathToType

import com.sun.tools.javac.code.Type; //導入方法依賴的package包/類
private Type pathToType(TreePath tp, Tree tree) {
    if (tree instanceof ConditionalExpressionTree) {
        // Conditionals always wind up as Object -- this corrects
        ConditionalExpressionTree cet = (ConditionalExpressionTree) tree;
        Type tmt = pathToType(new TreePath(tp, cet.getTrueExpression()));
        Type tmf = pathToType(new TreePath(tp, cet.getFalseExpression()));
        if (!tmt.isPrimitive() && !tmf.isPrimitive()) {
            Type lub = types.lub(tmt, tmf);
            // System.err.printf("cond ? %s : %s  --  lub = %s\n",
            //             varTypeName(tmt), varTypeName(tmf), varTypeName(lub));
            return lub;
        }
    }
    return pathToType(tp);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:16,代碼來源:ExpressionToTypeInfo.java

示例8: box

import com.sun.tools.javac.code.Type; //導入方法依賴的package包/類
/** compute the boxed type associated with 't' */
public Type box(Type t) {
    if (!t.isPrimitive()) {
        throw new AssertionError("Cannot box non-primitive type: " + t);
    }
    return types.boxedClass(t).type;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:8,代碼來源:TypeHarness.java

示例9: getValueForType

import com.sun.tools.javac.code.Type; //導入方法依賴的package包/類
private String getValueForType( Type type )
{
  if( type.toString().equals( "boolean" ) )
  {
    return "false";
  }
  else if( type.isPrimitive() )
  {
    return "0";
  }
  else
  {
    return "null";
  }
}
 
開發者ID:manifold-systems,項目名稱:manifold,代碼行數:16,代碼來源:SrcClassUtil.java


注:本文中的com.sun.tools.javac.code.Type.isPrimitive方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。