Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_langtools
提交
2ac88bb5
D
dragonwell8_langtools
项目概览
openanolis
/
dragonwell8_langtools
通知
0
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dragonwell8_langtools
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
2ac88bb5
编写于
6月 01, 2013
作者:
V
vromero
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
6695379: Copy method annotations and parameter annotations to synthetic bridge methods
Reviewed-by: mcimadamore
上级
50b0b601
变更
7
显示空白变更内容
内联
并排
Showing
7 changed file
with
155 addition
and
21 deletion
+155
-21
src/share/classes/com/sun/tools/javac/comp/TransTypes.java
src/share/classes/com/sun/tools/javac/comp/TransTypes.java
+30
-0
src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java
src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java
+9
-11
test/tools/javac/6889255/T6889255.java
test/tools/javac/6889255/T6889255.java
+3
-3
test/tools/javac/MethodParameters/ClassFileVisitor.java
test/tools/javac/MethodParameters/ClassFileVisitor.java
+9
-3
test/tools/javac/MethodParameters/ReflectionVisitor.java
test/tools/javac/MethodParameters/ReflectionVisitor.java
+1
-3
test/tools/javac/MethodParameters/Tester.java
test/tools/javac/MethodParameters/Tester.java
+0
-1
test/tools/javac/T6695379/AnnotationsAreNotCopiedToBridgeMethodsTest.java
.../T6695379/AnnotationsAreNotCopiedToBridgeMethodsTest.java
+103
-0
未找到文件。
src/share/classes/com/sun/tools/javac/comp/TransTypes.java
浏览文件 @
2ac88bb5
...
@@ -258,6 +258,14 @@ public class TransTypes extends TreeTranslator {
...
@@ -258,6 +258,14 @@ public class TransTypes extends TreeTranslator {
meth
.
name
,
meth
.
name
,
bridgeType
,
bridgeType
,
origin
);
origin
);
/* once JDK-6996415 is solved it should be checked if this approach can
* be applied to method addOverrideBridgesIfNeeded
*/
bridge
.
params
=
createBridgeParams
(
impl
,
bridge
,
bridgeType
);
if
(
impl
.
annotations
!=
null
)
{
bridge
.
annotations
.
setAttributes
(
impl
.
annotations
);
}
if
(!
hypothetical
)
{
if
(!
hypothetical
)
{
JCMethodDecl
md
=
make
.
MethodDef
(
bridge
,
null
);
JCMethodDecl
md
=
make
.
MethodDef
(
bridge
,
null
);
...
@@ -292,6 +300,28 @@ public class TransTypes extends TreeTranslator {
...
@@ -292,6 +300,28 @@ public class TransTypes extends TreeTranslator {
overridden
.
put
(
bridge
,
meth
);
overridden
.
put
(
bridge
,
meth
);
}
}
private
List
<
VarSymbol
>
createBridgeParams
(
MethodSymbol
impl
,
MethodSymbol
bridge
,
Type
bridgeType
)
{
List
<
VarSymbol
>
bridgeParams
=
null
;
if
(
impl
.
params
!=
null
)
{
bridgeParams
=
List
.
nil
();
List
<
VarSymbol
>
implParams
=
impl
.
params
;
Type
.
MethodType
mType
=
(
Type
.
MethodType
)
bridgeType
;
List
<
Type
>
argTypes
=
mType
.
argtypes
;
while
(
implParams
.
nonEmpty
()
&&
argTypes
.
nonEmpty
())
{
VarSymbol
param
=
new
VarSymbol
(
implParams
.
head
.
flags
()
|
SYNTHETIC
,
implParams
.
head
.
name
,
argTypes
.
head
,
bridge
);
if
(
implParams
.
head
.
annotations
!=
null
)
{
param
.
annotations
.
setAttributes
(
implParams
.
head
.
annotations
);
}
bridgeParams
=
bridgeParams
.
append
(
param
);
implParams
=
implParams
.
tail
;
argTypes
=
argTypes
.
tail
;
}
}
return
bridgeParams
;
}
/** Add bridge if given symbol is a non-private, non-static member
/** Add bridge if given symbol is a non-private, non-static member
* of the given class, which is either defined in the class or non-final
* of the given class, which is either defined in the class or non-final
* inherited, and one of the two following conditions holds:
* inherited, and one of the two following conditions holds:
...
...
src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java
浏览文件 @
2ac88bb5
...
@@ -31,7 +31,6 @@ import java.util.Map;
...
@@ -31,7 +31,6 @@ import java.util.Map;
import
java.util.Set
;
import
java.util.Set
;
import
java.util.HashSet
;
import
java.util.HashSet
;
import
javax.lang.model.type.TypeKind
;
import
javax.tools.JavaFileManager
;
import
javax.tools.JavaFileManager
;
import
javax.tools.FileObject
;
import
javax.tools.FileObject
;
import
javax.tools.JavaFileObject
;
import
javax.tools.JavaFileObject
;
...
@@ -39,9 +38,6 @@ import javax.tools.JavaFileObject;
...
@@ -39,9 +38,6 @@ import javax.tools.JavaFileObject;
import
com.sun.tools.javac.code.*
;
import
com.sun.tools.javac.code.*
;
import
com.sun.tools.javac.code.Attribute.RetentionPolicy
;
import
com.sun.tools.javac.code.Attribute.RetentionPolicy
;
import
com.sun.tools.javac.code.Attribute.TypeCompound
;
import
com.sun.tools.javac.code.Attribute.TypeCompound
;
import
static
com
.
sun
.
tools
.
javac
.
code
.
BoundKind
.
EXTENDS
;
import
static
com
.
sun
.
tools
.
javac
.
code
.
BoundKind
.
SUPER
;
import
static
com
.
sun
.
tools
.
javac
.
code
.
BoundKind
.
UNBOUND
;
import
com.sun.tools.javac.code.Symbol.*
;
import
com.sun.tools.javac.code.Symbol.*
;
import
com.sun.tools.javac.code.Type.*
;
import
com.sun.tools.javac.code.Type.*
;
import
com.sun.tools.javac.code.Types.UniqueType
;
import
com.sun.tools.javac.code.Types.UniqueType
;
...
@@ -674,7 +670,8 @@ public class ClassWriter extends ClassFile {
...
@@ -674,7 +670,8 @@ public class ClassWriter extends ClassFile {
int
writeParameterAttrs
(
MethodSymbol
m
)
{
int
writeParameterAttrs
(
MethodSymbol
m
)
{
boolean
hasVisible
=
false
;
boolean
hasVisible
=
false
;
boolean
hasInvisible
=
false
;
boolean
hasInvisible
=
false
;
if
(
m
.
params
!=
null
)
for
(
VarSymbol
s
:
m
.
params
)
{
if
(
m
.
params
!=
null
)
{
for
(
VarSymbol
s
:
m
.
params
)
{
for
(
Attribute
.
Compound
a
:
s
.
getRawAttributes
())
{
for
(
Attribute
.
Compound
a
:
s
.
getRawAttributes
())
{
switch
(
types
.
getRetention
(
a
))
{
switch
(
types
.
getRetention
(
a
))
{
case
SOURCE:
break
;
case
SOURCE:
break
;
...
@@ -684,6 +681,7 @@ public class ClassWriter extends ClassFile {
...
@@ -684,6 +681,7 @@ public class ClassWriter extends ClassFile {
}
}
}
}
}
}
}
int
attrCount
=
0
;
int
attrCount
=
0
;
if
(
hasVisible
)
{
if
(
hasVisible
)
{
...
...
test/tools/javac/6889255/T6889255.java
浏览文件 @
2ac88bb5
/*
/*
* Copyright (c) 2009, 201
2
, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2009, 201
3
, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
*
* This code is free software; you can redistribute it and/or modify it
* This code is free software; you can redistribute it and/or modify it
...
@@ -429,9 +429,9 @@ public class T6889255 {
...
@@ -429,9 +429,9 @@ public class T6889255 {
// -- no Code attribute for the LocalVariableTable attribute
// -- no Code attribute for the LocalVariableTable attribute
if
((
v
.
owner
.
flags
()
&
Flags
.
ABSTRACT
)
!=
0
)
if
((
v
.
owner
.
flags
()
&
Flags
.
ABSTRACT
)
!=
0
)
return
"arg"
+
(
i
-
1
);
return
"arg"
+
(
i
-
1
);
// bridge methods use
xN
// bridge methods use
argN. No LVT for them anymore
if
((
v
.
owner
.
flags
()
&
Flags
.
BRIDGE
)
!=
0
)
if
((
v
.
owner
.
flags
()
&
Flags
.
BRIDGE
)
!=
0
)
return
"
x
"
+
(
i
-
1
);
return
"
arg
"
+
(
i
-
1
);
// The rest of this method assumes the local conventions in the test program
// The rest of this method assumes the local conventions in the test program
Type
t
=
v
.
type
;
Type
t
=
v
.
type
;
...
...
test/tools/javac/MethodParameters/ClassFileVisitor.java
浏览文件 @
2ac88bb5
...
@@ -21,10 +21,8 @@
...
@@ -21,10 +21,8 @@
* questions.
* questions.
*/
*/
import
com.sun.tools.classfile.*
;
import
java.io.*
;
import
java.io.*
;
import
javax.lang.model.element.*
;
import
com.sun.tools.classfile.*
;
import
java.util.*
;
/**
/**
* The {@code ClassFileVisitor} reads a class file using the
* The {@code ClassFileVisitor} reads a class file using the
...
@@ -150,6 +148,7 @@ class ClassFileVisitor extends Tester.Visitor {
...
@@ -150,6 +148,7 @@ class ClassFileVisitor extends Tester.Visitor {
public
int
mNumParams
;
public
int
mNumParams
;
public
boolean
mSynthetic
;
public
boolean
mSynthetic
;
public
boolean
mIsConstructor
;
public
boolean
mIsConstructor
;
public
boolean
mIsBridge
;
public
String
prefix
;
public
String
prefix
;
void
visitMethod
(
Method
method
,
StringBuilder
sb
)
throws
Exception
{
void
visitMethod
(
Method
method
,
StringBuilder
sb
)
throws
Exception
{
...
@@ -162,6 +161,7 @@ class ClassFileVisitor extends Tester.Visitor {
...
@@ -162,6 +161,7 @@ class ClassFileVisitor extends Tester.Visitor {
mSynthetic
=
method
.
access_flags
.
is
(
AccessFlags
.
ACC_SYNTHETIC
);
mSynthetic
=
method
.
access_flags
.
is
(
AccessFlags
.
ACC_SYNTHETIC
);
mIsConstructor
=
mName
.
equals
(
"<init>"
);
mIsConstructor
=
mName
.
equals
(
"<init>"
);
prefix
=
cname
+
"."
+
mName
+
"() - "
;
prefix
=
cname
+
"."
+
mName
+
"() - "
;
mIsBridge
=
method
.
access_flags
.
is
(
AccessFlags
.
ACC_BRIDGE
);
sb
.
append
(
cname
).
append
(
"."
).
append
(
mName
).
append
(
"("
);
sb
.
append
(
cname
).
append
(
"."
).
append
(
mName
).
append
(
"("
);
...
@@ -320,6 +320,12 @@ class ClassFileVisitor extends Tester.Visitor {
...
@@ -320,6 +320,12 @@ class ClassFileVisitor extends Tester.Visitor {
}
else
if
(
isEnum
&&
mNumParams
==
1
&&
index
==
0
&&
mName
.
equals
(
"valueOf"
))
{
}
else
if
(
isEnum
&&
mNumParams
==
1
&&
index
==
0
&&
mName
.
equals
(
"valueOf"
))
{
expect
=
"name"
;
expect
=
"name"
;
allowMandated
=
true
;
allowMandated
=
true
;
}
else
if
(
mIsBridge
)
{
allowSynthetic
=
true
;
/* you can't expect an special name for bridges' parameters.
* The name of the original parameters are now copied.
*/
expect
=
null
;
}
}
if
(
mandated
)
sb
.
append
(
"!"
);
if
(
mandated
)
sb
.
append
(
"!"
);
if
(
synthetic
)
sb
.
append
(
"!!"
);
if
(
synthetic
)
sb
.
append
(
"!!"
);
...
...
test/tools/javac/MethodParameters/ReflectionVisitor.java
浏览文件 @
2ac88bb5
...
@@ -22,8 +22,6 @@
...
@@ -22,8 +22,6 @@
*/
*/
import
java.io.*
;
import
java.io.*
;
import
java.util.*
;
import
java.net.*
;
import
java.lang.reflect.*
;
import
java.lang.reflect.*
;
/**
/**
...
@@ -250,7 +248,7 @@ public class ReflectionVisitor extends Tester.Visitor {
...
@@ -250,7 +248,7 @@ public class ReflectionVisitor extends Tester.Visitor {
String
expect
=
m
.
isSynthetic
()
?
(
"arg"
+
i
)
:
((++
c
)
+
param
);
String
expect
=
m
.
isSynthetic
()
?
(
"arg"
+
i
)
:
((++
c
)
+
param
);
param
=
p
.
getName
();
param
=
p
.
getName
();
sb
.
append
(
sep
).
append
(
param
);
sb
.
append
(
sep
).
append
(
param
);
if
(!
expect
.
equals
(
param
))
{
if
(!
m
.
isBridge
()
&&
!
expect
.
equals
(
param
))
{
error
(
prefix
+
"param["
+
i
+
"]='"
error
(
prefix
+
"param["
+
i
+
"]='"
+
param
+
"' expected '"
+
expect
+
"'"
);
+
param
+
"' expected '"
+
expect
+
"'"
);
break
;
break
;
...
...
test/tools/javac/MethodParameters/Tester.java
浏览文件 @
2ac88bb5
...
@@ -22,7 +22,6 @@
...
@@ -22,7 +22,6 @@
*/
*/
import
java.io.*
;
import
java.io.*
;
import
java.util.*
;
import
java.lang.reflect.Constructor
;
import
java.lang.reflect.Constructor
;
/**
/**
...
...
test/tools/javac/T6695379/AnnotationsAreNotCopiedToBridgeMethodsTest.java
0 → 100644
浏览文件 @
2ac88bb5
/*
* Copyright (c) 2013, 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
* @bug 6695379
* @summary Copy method annotations and parameter annotations to synthetic
* bridge methods
* @run main AnnotationsAreNotCopiedToBridgeMethodsTest
*/
import
java.lang.annotation.ElementType
;
import
java.lang.annotation.Target
;
import
java.io.BufferedInputStream
;
import
java.lang.annotation.Retention
;
import
java.lang.annotation.RetentionPolicy
;
import
java.nio.file.Files
;
import
java.nio.file.Path
;
import
java.nio.file.Paths
;
import
com.sun.tools.classfile.AccessFlags
;
import
com.sun.tools.classfile.Attribute
;
import
com.sun.tools.classfile.Attributes
;
import
com.sun.tools.classfile.ClassFile
;
import
com.sun.tools.classfile.Method
;
import
com.sun.tools.javac.util.Assert
;
public
class
AnnotationsAreNotCopiedToBridgeMethodsTest
{
public
static
void
main
(
String
[]
args
)
throws
Exception
{
new
AnnotationsAreNotCopiedToBridgeMethodsTest
().
run
();
}
void
run
()
throws
Exception
{
checkClassFile
(
Paths
.
get
(
System
.
getProperty
(
"test.classes"
),
this
.
getClass
().
getSimpleName
()
+
"$CovariantReturnType.class"
));
checkClassFile
(
Paths
.
get
(
System
.
getProperty
(
"test.classes"
),
this
.
getClass
().
getSimpleName
()
+
"$CovariantReturnType$VisibilityChange.class"
));
}
void
checkClassFile
(
final
Path
cfilePath
)
throws
Exception
{
ClassFile
classFile
=
ClassFile
.
read
(
new
BufferedInputStream
(
Files
.
newInputStream
(
cfilePath
)));
for
(
Method
method
:
classFile
.
methods
)
{
if
(
method
.
access_flags
.
is
(
AccessFlags
.
ACC_BRIDGE
))
{
checkForAttr
(
method
.
attributes
,
"Annotations hasn't been copied to bridge method"
,
Attribute
.
RuntimeVisibleAnnotations
,
Attribute
.
RuntimeVisibleParameterAnnotations
);
}
}
}
void
checkForAttr
(
Attributes
attrs
,
String
errorMsg
,
String
...
attrNames
)
{
for
(
String
attrName
:
attrNames
)
{
Assert
.
checkNonNull
(
attrs
.
get
(
attrName
),
errorMsg
);
}
}
@Target
(
value
=
{
ElementType
.
PARAMETER
})
@Retention
(
RetentionPolicy
.
RUNTIME
)
@interface
ParamAnnotation
{}
@Target
(
value
=
{
ElementType
.
METHOD
})
@Retention
(
RetentionPolicy
.
RUNTIME
)
@interface
MethodAnnotation
{}
abstract
class
T
<
A
,
B
>
{
B
m
(
A
a
){
return
null
;}
}
class
CovariantReturnType
extends
T
<
Integer
,
Integer
>
{
@MethodAnnotation
Integer
m
(
@ParamAnnotation
Integer
i
)
{
return
i
;
}
public
class
VisibilityChange
extends
CovariantReturnType
{}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录