--- a/langtools/src/share/classes/com/sun/tools/javac/parser/JavacParser.java Wed Mar 03 16:05:34 2010 -0800
+++ b/langtools/src/share/classes/com/sun/tools/javac/parser/JavacParser.java Wed Mar 03 17:22:52 2010 -0800
@@ -1561,7 +1561,10 @@
JCNewClass newClass = classCreatorRest(newpos, null, typeArgs, t);
if (newClass.def != null) {
assert newClass.def.mods.annotations.isEmpty();
- newClass.def.mods.annotations = List.convert(JCAnnotation.class, newAnnotations);
+ if (newAnnotations.nonEmpty()) {
+ newClass.def.mods.pos = earlier(newClass.def.mods.pos, newAnnotations.head.pos);
+ newClass.def.mods.annotations = List.convert(JCAnnotation.class, newAnnotations);
+ }
}
return newClass;
} else {
@@ -3016,6 +3019,18 @@
return (oc >= 0) ? TreeInfo.opPrec(oc) : -1;
}
+ /**
+ * Return the lesser of two positions, making allowance for either one
+ * being unset.
+ */
+ static int earlier(int pos1, int pos2) {
+ if (pos1 == Position.NOPOS)
+ return pos2;
+ if (pos2 == Position.NOPOS)
+ return pos1;
+ return (pos1 < pos2 ? pos1 : pos2);
+ }
+
/** Return operation tag of binary operator represented by token,
* -1 if token is not a binary operator.
*/