Java Code Examples for com.sun.tools.javac.code.Type#isPrimitive()
The following examples show how to use
com.sun.tools.javac.code.Type#isPrimitive() .
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: ExtensionTransformer.java From manifold with Apache License 2.0 | 6 votes |
/** Expand a boxing or unboxing conversion if needed. */ <T extends JCTree> T boxUnboxIfNeeded( Types types, TreeMaker make, Names names, T tree, Type type) { boolean havePrimitive = tree.type.isPrimitive(); if (havePrimitive == type.isPrimitive()) return tree; if (havePrimitive) { Type unboxedTarget = types.unboxedType(type); if (!unboxedTarget.hasTag(NONE)) { if (!types.isSubtype(tree.type, unboxedTarget)) //e.g. Character c = 89; tree.type = unboxedTarget.constType(tree.type.constValue()); return (T)boxPrimitive(types, make, names, (JCExpression)tree, type); } else { tree = (T)boxPrimitive(types, make, names, (JCExpression)tree); } } else { tree = (T)unbox(types, make, names, (JCExpression)tree, type); } return tree; }
Example 2
Source File: NullAway.java From NullAway with MIT License | 6 votes |
@Override public Description matchBinary(BinaryTree tree, VisitorState state) { if (!matchWithinClass) { return Description.NO_MATCH; } 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; }
Example 3
Source File: SrcClassUtil.java From manifold with Apache License 2.0 | 6 votes |
private String getValueForType( Type type ) { if( type.toString().equals( "boolean" ) ) { return "false"; } else if( type.isPrimitive() ) { return "0"; } else { String fqn = type.toString(); return "(" + fqn + ")null"; // cast to disambiguate when used as an argument } }
Example 4
Source File: Operators.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * 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; } }
Example 5
Source File: Lower.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** Unbox an object to a primitive value. */ JCExpression unbox(JCExpression tree, Type primitive) { Type unboxedType = types.unboxedType(tree.type); if (unboxedType.hasTag(NONE)) { unboxedType = primitive; if (!unboxedType.isPrimitive()) throw new AssertionError(unboxedType); make_at(tree.pos()); tree = make.TypeCast(types.boxedClass(unboxedType).type, tree); } else { // There must be a conversion from unboxedType to primitive. if (!types.isSubtype(unboxedType, primitive)) throw new AssertionError(tree); } make_at(tree.pos()); Symbol valueSym = lookupMethod(tree.pos(), unboxedType.tsym.name.append(names.Value), // x.intValue() tree.type, List.nil()); return make.App(make.Select(tree, valueSym)); }
Example 6
Source File: Lower.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** Expand a boxing or unboxing conversion if needed. */ @SuppressWarnings("unchecked") // XXX unchecked <T extends JCExpression> T boxIfNeeded(T tree, Type type) { boolean havePrimitive = tree.type.isPrimitive(); if (havePrimitive == type.isPrimitive()) return tree; if (havePrimitive) { Type unboxedTarget = types.unboxedType(type); if (!unboxedTarget.hasTag(NONE)) { if (!types.isSubtype(tree.type, unboxedTarget)) //e.g. Character c = 89; tree.type = unboxedTarget.constType(tree.type.constValue()); return (T)boxPrimitive(tree, types.erasure(type)); } else { tree = (T)boxPrimitive(tree); } } else { tree = (T)unbox(tree, type); } return tree; }
Example 7
Source File: Operators.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * 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; } }
Example 8
Source File: TypeHarness.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
/** 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; }
Example 9
Source File: TypeHarness.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
/** 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; }
Example 10
Source File: TypeHarness.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
/** 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; }
Example 11
Source File: Operators.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * 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; } }
Example 12
Source File: Infer.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override Type solve(UndetVar uv, InferenceContext inferenceContext) { Infer infer = inferenceContext.infer; List<Type> hibounds = filterBounds(uv, inferenceContext); //note: hibounds should have at least one element Type owntype = hibounds.tail.tail == null ? hibounds.head : infer.types.glb(hibounds); if (owntype.isPrimitive() || owntype.hasTag(ERROR)) { throw infer.inferenceException .setMessage("no.unique.maximal.instance.exists", uv.qtype, hibounds); } else { return owntype; } }
Example 13
Source File: UTypeVar.java From Refaster with Apache License 2.0 | 5 votes |
@Override @Nullable public Unifier visitType(Type target, @Nullable Unifier unifier) { // This is only called when we're trying to unify overloads, in which case // type variables don't matter. return !target.isPrimitive() ? unifier : null; }
Example 14
Source File: Check.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
void validateAnnotationType(DiagnosticPosition pos, Type type) { if (type.isPrimitive()) return; if (types.isSameType(type, syms.stringType)) return; if ((type.tsym.flags() & Flags.ENUM) != 0) return; if ((type.tsym.flags() & Flags.ANNOTATION) != 0) return; if (types.cvarLowerBound(type).tsym == syms.classType.tsym) return; if (types.isArray(type) && !types.isArray(types.elemtype(type))) { validateAnnotationType(pos, types.elemtype(type)); return; } log.error(pos, Errors.InvalidAnnotationMemberType); }
Example 15
Source File: ManAttr.java From manifold with Apache License 2.0 | 5 votes |
static Symbol.MethodSymbol resolveOperatorMethod( Types types, Tag tag, Type left, Type right ) { String opName = BINARY_OP_TO_NAME.get( tag ); if( opName == null ) { if( isComparableOperator( tag ) ) { opName = COMPARE_TO_USING; } else { return null; } } if( left instanceof Type.TypeVar ) { left = types.erasure( left ); } if( !(left.tsym instanceof Symbol.ClassSymbol) ) { return null; } int paramCount = opName.equals( COMPARE_TO_USING ) ? 2 : 1; Symbol.MethodSymbol methodSymbol = getMethodSymbol( types, left, right, opName, (Symbol.ClassSymbol)left.tsym, paramCount ); if( methodSymbol == null && paramCount == 2 && !left.isPrimitive() && isRelationalOperator( tag ) ) { // Support > >= < <= on any Comparable implementor methodSymbol = getMethodSymbol( types, left, right, COMPARE_TO, (Symbol.ClassSymbol)left.tsym, 1 ); } return methodSymbol; }
Example 16
Source File: TypeHarness.java From hottub with GNU General Public License v2.0 | 5 votes |
/** 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; }
Example 17
Source File: TypeHarness.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
/** 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; }
Example 18
Source File: TypeHarness.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** 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; }
Example 19
Source File: Infer.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * Generate constraints from the generic method's return type. If the method * call occurs in a context where a type T is expected, use the expected * type to derive more constraints on the generic method inference variables. */ Type generateReturnConstraints(JCTree tree, Attr.ResultInfo resultInfo, MethodType mt, InferenceContext inferenceContext) { InferenceContext rsInfoInfContext = resultInfo.checkContext.inferenceContext(); Type from = mt.getReturnType(); if (mt.getReturnType().containsAny(inferenceContext.inferencevars) && rsInfoInfContext != emptyContext) { from = types.capture(from); //add synthetic captured ivars for (Type t : from.getTypeArguments()) { if (t.hasTag(TYPEVAR) && ((TypeVar)t).isCaptured()) { inferenceContext.addVar((TypeVar)t); } } } Type qtype = inferenceContext.asUndetVar(from); Type to = resultInfo.pt; if (qtype.hasTag(VOID)) { to = syms.voidType; } else if (to.hasTag(NONE)) { to = from.isPrimitive() ? from : syms.objectType; } else if (qtype.hasTag(UNDETVAR)) { if (needsEagerInstantiation((UndetVar)qtype, to, inferenceContext) && (allowGraphInference || !to.isPrimitive())) { to = generateReferenceToTargetConstraint(tree, (UndetVar)qtype, to, resultInfo, inferenceContext); } } else if (rsInfoInfContext.free(resultInfo.pt)) { //propagation - cache captured vars qtype = inferenceContext.asUndetVar(rsInfoInfContext.cachedCapture(tree, from, !resultInfo.checkMode.updateTreeType())); } Assert.check(allowGraphInference || !rsInfoInfContext.free(to), "legacy inference engine cannot handle constraints on both sides of a subtyping assertion"); //we need to skip capture? Warner retWarn = new Warner(); if (!resultInfo.checkContext.compatible(qtype, rsInfoInfContext.asUndetVar(to), retWarn) || //unchecked conversion is not allowed in source 7 mode (!allowGraphInference && retWarn.hasLint(Lint.LintCategory.UNCHECKED))) { throw inferenceException .setMessage("infer.no.conforming.instance.exists", inferenceContext.restvars(), mt.getReturnType(), to); } return from; }
Example 20
Source File: TransTypes.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 3 votes |
/** Given an erased reference type, assume this type as the tree's type. * Then, coerce to some given target type unless target type is null. * This operation is used in situations like the following: * * <pre>{@code * class Cell<A> { A value; } * ... * Cell<Integer> cell; * Integer x = cell.value; * }</pre> * * Since the erasure of Cell.value is Object, but the type * of cell.value in the assignment is Integer, we need to * adjust the original type of cell.value to Object, and insert * a cast to Integer. That is, the last assignment becomes: * * <pre>{@code * Integer x = (Integer)cell.value; * }</pre> * * @param tree The expression tree whose type might need adjustment. * @param erasedType The expression's type after erasure. * @param target The target type, which is usually the erasure of the * expression's original type. */ JCExpression retype(JCExpression tree, Type erasedType, Type target) { // System.err.println("retype " + tree + " to " + erasedType);//DEBUG if (!erasedType.isPrimitive()) { if (target != null && target.isPrimitive()) { target = erasure(tree.type); } tree.type = erasedType; if (target != null) { return coerce(tree, target); } } return tree; }