Skip to content

Instantly share code, notes, and snippets.

@paulp
Created November 9, 2008 00:42
Show Gist options
  • Save paulp/23163 to your computer and use it in GitHub Desktop.
Save paulp/23163 to your computer and use it in GitHub Desktop.
/**
* Process an Expression type node reflectively; must return a JExpression.
*/
protected JExpression dispProcessExpression(Expression x) {
/*
* Note that we always prefer a JDT-computed constant value to the actual
* written expression. (Let's hope JDT is always right.) This means we
* don't have to write processExpression methods for the numerous JDT
* literal nodes because they ALWAYS have a constant value.
*/
JExpression result = null;
if (x != null && x.constant != null
&& x.constant != Constant.NotAConstant) {
result = (JExpression) dispatch("processConstant", x.constant);
}
if (result == null) {
// The expression was not a constant, so use the general logic.
result = (JExpression) dispatch("processExpression", x);
}
// Check if we need to box the resulting expression.
if (x != null) {
if ((x.implicitConversion & TypeIds.BOXING) != 0) {
result = autoboxUtils.box(result, implicitConversionTargetType(x));
} else if ((x.implicitConversion & TypeIds.UNBOXING) != 0) {
// This code can actually leave an unbox operation in
// an lvalue position, for example ++(x.intValue()).
// Such trees are cleaned up in FixAssignmentToUnbox.
JType typeToUnbox = (JType) typeMap.get(x.resolvedType);
if (!(typeToUnbox instanceof JClassType)) {
throw new InternalCompilerException(result,
"Attempt to unbox a non-class type: " + typeToUnbox.getName(),
null);
}
result = unbox(result, (JClassType) typeToUnbox);
}
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment