8065132: Parameter annotations not updated when synthetic parameters are prepended
Cause javac to add synthetic parameters to Runtime[In]VisibleParameterAnnotations attributes Reviewed-by: jjg, jfranck
This commit is contained in:
parent
bdf693fcc5
commit
590188542e
langtools
src/jdk.compiler/share/classes/com/sun/tools/javac/jvm
test
lib/annotations/annotations/classfile
tools/javac/annotations
@ -640,6 +640,27 @@ public class ClassWriter extends ClassFile {
|
||||
}
|
||||
|
||||
|
||||
private void writeParamAnnotations(List<VarSymbol> params,
|
||||
RetentionPolicy retention) {
|
||||
for (VarSymbol s : params) {
|
||||
ListBuffer<Attribute.Compound> buf = new ListBuffer<>();
|
||||
for (Attribute.Compound a : s.getRawAttributes())
|
||||
if (types.getRetention(a) == retention)
|
||||
buf.append(a);
|
||||
databuf.appendChar(buf.length());
|
||||
for (Attribute.Compound a : buf)
|
||||
writeCompoundAttribute(a);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void writeParamAnnotations(MethodSymbol m,
|
||||
RetentionPolicy retention) {
|
||||
databuf.appendByte(m.params.length() + m.extraParams.length());
|
||||
writeParamAnnotations(m.extraParams, retention);
|
||||
writeParamAnnotations(m.params, retention);
|
||||
}
|
||||
|
||||
/** Write method parameter annotations;
|
||||
* return number of attributes written.
|
||||
*/
|
||||
@ -662,31 +683,13 @@ public class ClassWriter extends ClassFile {
|
||||
int attrCount = 0;
|
||||
if (hasVisible) {
|
||||
int attrIndex = writeAttr(names.RuntimeVisibleParameterAnnotations);
|
||||
databuf.appendByte(m.params.length());
|
||||
for (VarSymbol s : m.params) {
|
||||
ListBuffer<Attribute.Compound> buf = new ListBuffer<>();
|
||||
for (Attribute.Compound a : s.getRawAttributes())
|
||||
if (types.getRetention(a) == RetentionPolicy.RUNTIME)
|
||||
buf.append(a);
|
||||
databuf.appendChar(buf.length());
|
||||
for (Attribute.Compound a : buf)
|
||||
writeCompoundAttribute(a);
|
||||
}
|
||||
writeParamAnnotations(m, RetentionPolicy.RUNTIME);
|
||||
endAttr(attrIndex);
|
||||
attrCount++;
|
||||
}
|
||||
if (hasInvisible) {
|
||||
int attrIndex = writeAttr(names.RuntimeInvisibleParameterAnnotations);
|
||||
databuf.appendByte(m.params.length());
|
||||
for (VarSymbol s : m.params) {
|
||||
ListBuffer<Attribute.Compound> buf = new ListBuffer<>();
|
||||
for (Attribute.Compound a : s.getRawAttributes())
|
||||
if (types.getRetention(a) == RetentionPolicy.CLASS)
|
||||
buf.append(a);
|
||||
databuf.appendChar(buf.length());
|
||||
for (Attribute.Compound a : buf)
|
||||
writeCompoundAttribute(a);
|
||||
}
|
||||
writeParamAnnotations(m, RetentionPolicy.CLASS);
|
||||
endAttr(attrIndex);
|
||||
attrCount++;
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
198
langtools/test/tools/javac/annotations/SyntheticParameters.java
Normal file
198
langtools/test/tools/javac/annotations/SyntheticParameters.java
Normal file
@ -0,0 +1,198 @@
|
||||
/*
|
||||
* 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
|
||||
* @bug 8065132
|
||||
* @summary Test generation of annotations on inner class parameters.
|
||||
* @library /lib/annotations/
|
||||
* @run main SyntheticParameters
|
||||
*/
|
||||
|
||||
import annotations.classfile.ClassfileInspector;
|
||||
|
||||
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,
|
||||
null,
|
||||
new ExpectedParameterAnnotation[] {
|
||||
(ExpectedParameterAnnotation)
|
||||
// Assert there is no annotation on the
|
||||
// this$0 parameter.
|
||||
new ExpectedParameterAnnotation(
|
||||
"<init>",
|
||||
0,
|
||||
"A",
|
||||
true,
|
||||
0),
|
||||
(ExpectedParameterAnnotation)
|
||||
// Assert there is an annotation on the
|
||||
// first parameter.
|
||||
new ExpectedParameterAnnotation(
|
||||
"<init>",
|
||||
1,
|
||||
"A",
|
||||
true,
|
||||
1),
|
||||
(ExpectedParameterAnnotation)
|
||||
new ExpectedParameterAnnotation(
|
||||
"foo",
|
||||
0,
|
||||
"A",
|
||||
true,
|
||||
1),
|
||||
(ExpectedParameterAnnotation)
|
||||
new ExpectedParameterAnnotation(
|
||||
"foo",
|
||||
1,
|
||||
"A",
|
||||
true,
|
||||
0),
|
||||
(ExpectedParameterAnnotation)
|
||||
// Assert there is no annotation on the
|
||||
// this$0 parameter.
|
||||
new ExpectedParameterAnnotation(
|
||||
"<init>",
|
||||
0,
|
||||
"B",
|
||||
false,
|
||||
0),
|
||||
(ExpectedParameterAnnotation)
|
||||
// Assert there is an annotation on the
|
||||
// first parameter.
|
||||
new ExpectedParameterAnnotation(
|
||||
"<init>",
|
||||
1,
|
||||
"B",
|
||||
false,
|
||||
1),
|
||||
(ExpectedParameterAnnotation)
|
||||
new ExpectedParameterAnnotation(
|
||||
"foo",
|
||||
0,
|
||||
"B",
|
||||
false,
|
||||
1),
|
||||
(ExpectedParameterAnnotation)
|
||||
new ExpectedParameterAnnotation(
|
||||
"foo",
|
||||
1,
|
||||
"B",
|
||||
false,
|
||||
0)
|
||||
},
|
||||
null);
|
||||
private static final Expected Foo_expected =
|
||||
new Expected("SyntheticParameters$Foo",
|
||||
null,
|
||||
null,
|
||||
new ExpectedParameterAnnotation[] {
|
||||
(ExpectedParameterAnnotation)
|
||||
// Assert there is no annotation on the
|
||||
// $enum$name parameter.
|
||||
new ExpectedParameterAnnotation(
|
||||
"<init>",
|
||||
0,
|
||||
"A",
|
||||
true,
|
||||
0),
|
||||
(ExpectedParameterAnnotation)
|
||||
// Assert there is no annotation on the
|
||||
// $enum$ordinal parameter.
|
||||
new ExpectedParameterAnnotation(
|
||||
"<init>",
|
||||
1,
|
||||
"A",
|
||||
true,
|
||||
0),
|
||||
(ExpectedParameterAnnotation)
|
||||
// Assert there is an annotation on the
|
||||
// first parameter.
|
||||
new ExpectedParameterAnnotation(
|
||||
"<init>",
|
||||
2,
|
||||
"A",
|
||||
true,
|
||||
1),
|
||||
(ExpectedParameterAnnotation)
|
||||
// Assert there is no annotation on the
|
||||
// $enum$name parameter.
|
||||
new ExpectedParameterAnnotation(
|
||||
"<init>",
|
||||
0,
|
||||
"B",
|
||||
false,
|
||||
0),
|
||||
(ExpectedParameterAnnotation)
|
||||
// Assert there is no annotation on the
|
||||
// $enum$ordinal parameter.
|
||||
new ExpectedParameterAnnotation(
|
||||
"<init>",
|
||||
1,
|
||||
"B",
|
||||
false,
|
||||
0),
|
||||
(ExpectedParameterAnnotation)
|
||||
// Assert there is an annotation on the
|
||||
// first parameter.
|
||||
new ExpectedParameterAnnotation(
|
||||
"<init>",
|
||||
2,
|
||||
"B",
|
||||
false,
|
||||
1)
|
||||
},
|
||||
null);
|
||||
|
||||
public static void main(String... args) throws Exception {
|
||||
new SyntheticParameters().run(
|
||||
new ClassFile[] { getClassFile(Inner_class, Inner.class),
|
||||
getClassFile(Foo_class, Foo.class) },
|
||||
new Expected[] { Inner_expected, Foo_expected });
|
||||
}
|
||||
|
||||
public class Inner {
|
||||
public Inner(@A @B int a) {}
|
||||
public void foo(@A @B int a, int b) {}
|
||||
}
|
||||
|
||||
public static enum Foo {
|
||||
ONE(null);
|
||||
Foo(@A @B Object a) {}
|
||||
}
|
||||
}
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@interface A {}
|
||||
|
||||
@Retention(RetentionPolicy.CLASS)
|
||||
@interface B {}
|
@ -24,10 +24,12 @@
|
||||
/*
|
||||
* @test SyntheticParameters
|
||||
* @summary Test generation of annotations on inner class parameters.
|
||||
* @build ClassfileInspector
|
||||
* @library /lib/annotations/
|
||||
* @run main SyntheticParameters
|
||||
*/
|
||||
|
||||
import annotations.classfile.ClassfileInspector;
|
||||
|
||||
import java.io.*;
|
||||
import java.lang.annotation.*;
|
||||
|
||||
@ -111,7 +113,8 @@ public class SyntheticParameters extends ClassfileInspector {
|
||||
|
||||
public static void main(String... args) throws Exception {
|
||||
new SyntheticParameters().run(
|
||||
new ClassFile[] { getClassFile(Inner_class), getClassFile(Foo_class) },
|
||||
new ClassFile[] { getClassFile(Inner_class, Inner.class),
|
||||
getClassFile(Foo_class, Foo.class) },
|
||||
new Expected[] { Inner_expected, Foo_expected });
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user