提交 825650a5 编写于 作者: E emc

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
上级 d3392644
......@@ -2716,9 +2716,10 @@ public class Lower extends TreeTranslator {
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);
......@@ -2741,6 +2742,17 @@ public class Lower extends TreeTranslator {
}
}
//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())) {
......@@ -2771,8 +2783,10 @@ public class Lower extends TreeTranslator {
// 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
......
/*
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test SyntheticParameters
* @summary Test generation of annotations on inner class parameters.
* @build ClassfileInspector
* @run main SyntheticParameters
*/
import java.io.*;
import java.lang.annotation.*;
import com.sun.tools.classfile.*;
public class SyntheticParameters extends ClassfileInspector {
private static final String Inner_class = "SyntheticParameters$Inner.class";
private static final String Foo_class = "SyntheticParameters$Foo.class";
private static final Expected Inner_expected =
new Expected("SyntheticParameters$Inner",
null,
new ExpectedMethodTypeAnnotation[] {
(ExpectedMethodTypeAnnotation)
// Assert there is no annotation on the
// this$0 parameter.
new ExpectedMethodTypeAnnotation.Builder(
"<init>",
"A",
TypeAnnotation.TargetType.METHOD_FORMAL_PARAMETER,
false,
0).setParameterIndex(0).build(),
(ExpectedMethodTypeAnnotation)
// Assert there is an annotation on the
// first parameter.
new ExpectedMethodTypeAnnotation.Builder(
"<init>",
"A",
TypeAnnotation.TargetType.METHOD_FORMAL_PARAMETER,
false,
1).setParameterIndex(1).build(),
(ExpectedMethodTypeAnnotation)
new ExpectedMethodTypeAnnotation.Builder(
"foo",
"A",
TypeAnnotation.TargetType.METHOD_FORMAL_PARAMETER,
false,
1).setParameterIndex(0).build(),
(ExpectedMethodTypeAnnotation)
new ExpectedMethodTypeAnnotation.Builder(
"foo",
"A",
TypeAnnotation.TargetType.METHOD_FORMAL_PARAMETER,
false,
0).setParameterIndex(1).build()
},
null);
private static final Expected Foo_expected =
new Expected("SyntheticParameters$Foo",
null,
new ExpectedMethodTypeAnnotation[] {
(ExpectedMethodTypeAnnotation)
// Assert there is no annotation on the
// $enum$name parameter.
new ExpectedMethodTypeAnnotation.Builder(
"<init>",
"A",
TypeAnnotation.TargetType.METHOD_FORMAL_PARAMETER,
false,
0).setParameterIndex(0).build(),
(ExpectedMethodTypeAnnotation)
// Assert there is no annotation on the
// $enum$ordinal parameter.
new ExpectedMethodTypeAnnotation.Builder(
"<init>",
"A",
TypeAnnotation.TargetType.METHOD_FORMAL_PARAMETER,
false,
0).setParameterIndex(1).build(),
(ExpectedMethodTypeAnnotation)
// Assert there is an annotation on the
// first parameter.
new ExpectedMethodTypeAnnotation.Builder(
"<init>",
"A",
TypeAnnotation.TargetType.METHOD_FORMAL_PARAMETER,
false,
1).setParameterIndex(2).build()
},
null);
public static void main(String... args) throws Exception {
new SyntheticParameters().run(
new ClassFile[] { getClassFile(Inner_class), getClassFile(Foo_class) },
new Expected[] { Inner_expected, Foo_expected });
}
public class Inner {
public Inner(@A int a) {}
public void foo(@A int a, int b) {}
}
public static enum Foo {
ONE(null);
Foo(@A Object a) {}
}
}
@Target({ElementType.TYPE_USE})
@interface A {}
......@@ -46,7 +46,7 @@ public class Constructors {
@TADescriptions({
@TADescription(annotation = "TA", type = METHOD_RETURN, genericLocation = {1, 0}),
@TADescription(annotation = "TB", type = METHOD_RETURN, genericLocation = {1, 0}),
@TADescription(annotation = "TC", type = METHOD_FORMAL_PARAMETER, paramIndex = 0)
@TADescription(annotation = "TC", type = METHOD_FORMAL_PARAMETER, paramIndex = 1)
})
@TestClass("Test$Inner")
public String innerClass() {
......@@ -61,7 +61,7 @@ public class Constructors {
@TADescription(annotation = "TB", type = METHOD_RETURN, genericLocation = {1, 0}),
@TADescription(annotation = "TC", type = METHOD_RECEIVER),
@TADescription(annotation = "TD", type = METHOD_RETURN, genericLocation = {1, 0}),
@TADescription(annotation = "TE", type = METHOD_FORMAL_PARAMETER, paramIndex = 0)
@TADescription(annotation = "TE", type = METHOD_FORMAL_PARAMETER, paramIndex = 1)
})
@TestClass("Test$Inner")
public String innerClass2() {
......@@ -77,7 +77,7 @@ public class Constructors {
@TADescription(annotation = "TC", type = METHOD_RETURN, genericLocation = {1, 0, 1, 0}),
@TADescription(annotation = "TD", type = METHOD_RECEIVER, genericLocation = {1, 0}),
@TADescription(annotation = "TE", type = METHOD_RETURN, genericLocation = {1, 0, 1, 0}),
@TADescription(annotation = "TF", type = METHOD_FORMAL_PARAMETER, paramIndex = 0)
@TADescription(annotation = "TF", type = METHOD_FORMAL_PARAMETER, paramIndex = 1)
})
@TestClass("Outer$Middle$Inner")
public String innerClass3() {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册