[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[jdt-core-dev] TypeReferences vs NameReferences in type cast expressions.
|
Hello past & present (and future) jdt/core developers,
I am hoping you can shed some light on this oddity in the parser
code. Thanks in advance for any insights you can share.
Here is a fragment of the java grammar :
CastExpression ::= PushLPAREN Name PushRPAREN InsideCastExpressionLL1
UnaryExpressionNotPlusMinus
InsideCastExpressionLL1 ::= $empty
/.$putCase consumeInsideCastExpressionLL1(); $break ./
org.eclipse.jdt.internal.compiler.parser.Parser.consumeInsideCastExpressionLL1()
looks like:
protected void consumeInsideCastExpressionLL1() {
// InsideCastExpressionLL1 ::= $empty
pushOnExpressionStack(getUnspecifiedReferenceOptimized());
} and
where getUnspecifiedReferenceOptimized() constructs a SingleNameReference
or QualifiedNameReference as the case demands.
Now that is puzzling - why would we construct a NameReference instead of a
TypeReference here ? Intuitively as well per spec the Name
here is guaranteed to be a Typename (JLS3.0, page 128, 6.5.1)
The 4 other productions for CastExpression use TypeReference and the
production above is the only one that constructs a NameReference.
Do you recall how and why this came about ?
To give some context as to why this matters - JSR308 adds type annotations
to java and so TypeReferences must now be enhanced to capture annotations.
Name here is really a TypeReference, but if it was coded to be a
NameReference for some unalterable reason, we would need to add annotations
fields to these types also - something I would like to avoid very much.
I will make the change to TypeReference and see what breaks, in the
meantime would appreciate any inputs you have.
Thanks!
Srikanth.