public static String debug(JExpression inst) { return inst.getClass()+" ["+inst.toSource()+"] @"+inst.getSourceInfo(); }
private JExpression simplify(JExpression result, Expression x) { if (x.constant != null && x.constant != Constant.NotAConstant) { // Prefer JDT-computed constant value to the actual written expression. result = getConstant(result.getSourceInfo(), x.constant); } return maybeBoxOrUnbox(result, x.implicitConversion); }
private JExpression maybeCast(JType expected, JExpression expression) { if (expected != expression.getType()) { // Must be a generic; insert a cast operation. JReferenceType toType = (JReferenceType) expected; return new JCastOperation(expression.getSourceInfo(), toType, expression); } else { return expression; } }
private JExpression box(JExpression original, int implicitConversion) { int typeId = (implicitConversion & TypeIds.IMPLICIT_CONVERSION_MASK) >> 4; ClassScope scope = curClass.scope; BaseTypeBinding primitiveType = (BaseTypeBinding) TypeBinding.wellKnownType(scope, typeId); ReferenceBinding boxType = (ReferenceBinding) scope.boxing(primitiveType); MethodBinding valueOfMethod = boxType.getExactMethod(VALUE_OF, new TypeBinding[]{primitiveType}, scope .compilationUnitScope()); assert valueOfMethod != null; // Add a cast to the correct primitive type if needed. JType targetPrimitiveType = typeMap.get(primitiveType); if (original.getType() != targetPrimitiveType) { original = new JCastOperation(original.getSourceInfo(), targetPrimitiveType, original); } JMethod boxMethod = typeMap.get(valueOfMethod); JMethodCall call = new JMethodCall(original.getSourceInfo(), null, boxMethod); call.addArg(original); return call; }
private JExpression unbox(JExpression original, int implicitConversion) { int typeId = implicitConversion & TypeIds.COMPILE_TYPE_MASK; ClassScope scope = curClass.scope; BaseTypeBinding primitiveType = (BaseTypeBinding) TypeBinding.wellKnownType(scope, typeId); ReferenceBinding boxType = (ReferenceBinding) scope.boxing(primitiveType); char[] selector = CharOperation.concat(primitiveType.simpleName, VALUE); MethodBinding valueMethod = boxType.getExactMethod(selector, NO_TYPES, scope.compilationUnitScope()); assert valueMethod != null; JMethod unboxMethod = typeMap.get(valueMethod); JMethodCall call = new JMethodCall(original.getSourceInfo(), original, unboxMethod); return call; }
curRef = maybeCast(castType, curRef); SourceInfo info = curRef.getSourceInfo();
info = expr.getSourceInfo().makeChild(SourceOrigin.UNKNOWN); final JMethodBody body = new JMethodBody(info); getSingleton = new JMethod(info, targetName, enclosing, type, false, true, true,