src/share/classes/com/sun/tools/javac/comp/Lower.java
Print this page
rev 2608 : 8029012: parameter_index for type annotation not updated after outer.this added
Summary: Fix javac's handling of type annotations when synthetic parameters are added
Reviewed-by: jjg, mcimadamore
@@ -2714,13 +2714,14 @@
"enum" + target.syntheticNameChar() +
"ordinal"),
syms.intType, tree.sym);
ordParam.mods.flags |= SYNTHETIC; ordParam.sym.flags_field |= SYNTHETIC;
+ MethodSymbol m = tree.sym;
tree.params = tree.params.prepend(ordParam).prepend(nameParam);
+ incrementParamTypeAnnoIndexes(m, 2);
- MethodSymbol m = tree.sym;
m.extraParams = m.extraParams.prepend(ordParam.sym);
m.extraParams = m.extraParams.prepend(nameParam.sym);
Type olderasure = m.erasure(types);
m.erasure_field = new MethodType(
olderasure.getParameterTypes().prepend(syms.intType).prepend(syms.stringType),
@@ -2739,10 +2740,21 @@
currentMethodDef = prevMethodDef;
currentMethodSym = prevMethodSym;
}
}
//where
+ private void incrementParamTypeAnnoIndexes(MethodSymbol m,
+ int amount) {
+ for (final Attribute.TypeCompound anno : m.getRawTypeAttributes()) {
+ // Increment the parameter_index of any existing formal
+ // parameter annotations.
+ if (anno.position.type == TargetType.METHOD_FORMAL_PARAMETER) {
+ anno.position.parameter_index += amount;
+ }
+ }
+ }
+
private void visitMethodDefInternal(JCMethodDecl tree) {
if (tree.name == names.init &&
(currentClass.isInner() || currentClass.isLocal())) {
// We are seeing a constructor of an inner class.
MethodSymbol m = tree.sym;
@@ -2769,12 +2781,14 @@
}
// Add this$n (if needed) in front of and free variables behind
// constructor parameter list.
tree.params = tree.params.appendList(fvdefs);
- if (currentClass.hasOuterInstance())
+ if (currentClass.hasOuterInstance()) {
tree.params = tree.params.prepend(otdef);
+ incrementParamTypeAnnoIndexes(m, 1);
+ }
// If this is an initial constructor, i.e., it does not start with
// this(...), insert initializers for this$n and proxies
// before (pre-1.4, after) the call to superclass constructor.
JCStatement selfCall = translate(tree.body.stats.head);