/*
* Rely on JDT's computed constant value to deal with an
* AnnotationElementValue expression whose resolved type is a primitive or
* a string.
*/
Constant constant = elementValueExpression.constant;
int expectedTypeId = expectedElementValueType.id;
if (expectedElementValueType.isArrayType()) {
/*
* This can happen when an element value is an array with a single
* element. In this case JLS 3.0 section 9.7 allows for the
* ArrayInitializer expression to be implicit. Since, element values can
* only be single dimensional arrays, we take the leaf type of the
* expected array type as our resultant element value type.
*/
assert (!elementValueExpression.resolvedType.isArrayType() && expectedElementValueType.dimensions() == 1);
expectedTypeId = expectedElementValueType.leafComponentType().id;
}
if (elementValueExpression.resolvedType.id != expectedTypeId) {
/*
* Narrowing and widening conversions are handled by the following
* Constant.castTo call. JDT wants the upper four bits of this mask to
* be the target type id and the lower four bits to be the source type
* id. See Constant.castTo for more details.
*/
constant = constant.castTo((expectedTypeId << 4)
+ elementValueExpression.resolvedType.id);
}
elementValue = getConstantValue(constant);
} else if (elementValueExpression instanceof ClassLiteralAccess) {