本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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;
}
}
示例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;
}
示例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;
}
}
示例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);
}
示例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;
}
示例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";
}
}