Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_langtools
提交
1992a1e5
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看板
提交
1992a1e5
编写于
8月 27, 2012
作者:
K
ksrini
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
7192068: (javac) provide a way for IDEs to produce Enclosing Method attributes.
Reviewed-by: jjg Contributed-by: jan.lahoda@oracle.com
上级
cb2fc295
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
49 addition
and
32 deletion
+49
-32
src/share/classes/com/sun/tools/javac/jvm/ClassReader.java
src/share/classes/com/sun/tools/javac/jvm/ClassReader.java
+28
-28
src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java
src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java
+21
-4
未找到文件。
src/share/classes/com/sun/tools/javac/jvm/ClassReader.java
浏览文件 @
1992a1e5
...
...
@@ -188,7 +188,7 @@ public class ClassReader implements Completer {
/** The current input pointer.
*/
int
bp
;
protected
int
bp
;
/** The objects of the constant pool.
*/
...
...
@@ -890,13 +890,13 @@ public class ClassReader implements Completer {
protected
enum
AttributeKind
{
CLASS
,
MEMBER
};
protected
abstract
class
AttributeReader
{
AttributeReader
(
Name
name
,
ClassFile
.
Version
version
,
Set
<
AttributeKind
>
kinds
)
{
protected
AttributeReader
(
Name
name
,
ClassFile
.
Version
version
,
Set
<
AttributeKind
>
kinds
)
{
this
.
name
=
name
;
this
.
version
=
version
;
this
.
kinds
=
kinds
;
}
boolean
accepts
(
AttributeKind
kind
)
{
protected
boolean
accepts
(
AttributeKind
kind
)
{
if
(
kinds
.
contains
(
kind
))
{
if
(
majorVersion
>
version
.
major
||
(
majorVersion
==
version
.
major
&&
minorVersion
>=
version
.
minor
))
return
true
;
...
...
@@ -915,11 +915,11 @@ public class ClassReader implements Completer {
return
false
;
}
abstract
void
read
(
Symbol
sym
,
int
attrLen
);
protected
abstract
void
read
(
Symbol
sym
,
int
attrLen
);
final
Name
name
;
final
ClassFile
.
Version
version
;
final
Set
<
AttributeKind
>
kinds
;
protected
final
Name
name
;
protected
final
ClassFile
.
Version
version
;
protected
final
Set
<
AttributeKind
>
kinds
;
}
protected
Set
<
AttributeKind
>
CLASS_ATTRIBUTE
=
...
...
@@ -936,7 +936,7 @@ public class ClassReader implements Completer {
// v45.3 attributes
new
AttributeReader
(
names
.
Code
,
V45_3
,
MEMBER_ATTRIBUTE
)
{
void
read
(
Symbol
sym
,
int
attrLen
)
{
protected
void
read
(
Symbol
sym
,
int
attrLen
)
{
if
(
readAllOfClassFile
||
saveParameterNames
)
((
MethodSymbol
)
sym
).
code
=
readCode
(
sym
);
else
...
...
@@ -945,7 +945,7 @@ public class ClassReader implements Completer {
},
new
AttributeReader
(
names
.
ConstantValue
,
V45_3
,
MEMBER_ATTRIBUTE
)
{
void
read
(
Symbol
sym
,
int
attrLen
)
{
protected
void
read
(
Symbol
sym
,
int
attrLen
)
{
Object
v
=
readPool
(
nextChar
());
// Ignore ConstantValue attribute if field not final.
if
((
sym
.
flags
()
&
FINAL
)
!=
0
)
...
...
@@ -954,13 +954,13 @@ public class ClassReader implements Completer {
},
new
AttributeReader
(
names
.
Deprecated
,
V45_3
,
CLASS_OR_MEMBER_ATTRIBUTE
)
{
void
read
(
Symbol
sym
,
int
attrLen
)
{
protected
void
read
(
Symbol
sym
,
int
attrLen
)
{
sym
.
flags_field
|=
DEPRECATED
;
}
},
new
AttributeReader
(
names
.
Exceptions
,
V45_3
,
CLASS_OR_MEMBER_ATTRIBUTE
)
{
void
read
(
Symbol
sym
,
int
attrLen
)
{
protected
void
read
(
Symbol
sym
,
int
attrLen
)
{
int
nexceptions
=
nextChar
();
List
<
Type
>
thrown
=
List
.
nil
();
for
(
int
j
=
0
;
j
<
nexceptions
;
j
++)
...
...
@@ -971,14 +971,14 @@ public class ClassReader implements Completer {
},
new
AttributeReader
(
names
.
InnerClasses
,
V45_3
,
CLASS_ATTRIBUTE
)
{
void
read
(
Symbol
sym
,
int
attrLen
)
{
protected
void
read
(
Symbol
sym
,
int
attrLen
)
{
ClassSymbol
c
=
(
ClassSymbol
)
sym
;
readInnerClasses
(
c
);
}
},
new
AttributeReader
(
names
.
LocalVariableTable
,
V45_3
,
CLASS_OR_MEMBER_ATTRIBUTE
)
{
void
read
(
Symbol
sym
,
int
attrLen
)
{
protected
void
read
(
Symbol
sym
,
int
attrLen
)
{
int
newbp
=
bp
+
attrLen
;
if
(
saveParameterNames
)
{
// Pick up parameter names from the variable table.
...
...
@@ -1014,7 +1014,7 @@ public class ClassReader implements Completer {
},
new
AttributeReader
(
names
.
SourceFile
,
V45_3
,
CLASS_ATTRIBUTE
)
{
void
read
(
Symbol
sym
,
int
attrLen
)
{
protected
void
read
(
Symbol
sym
,
int
attrLen
)
{
ClassSymbol
c
=
(
ClassSymbol
)
sym
;
Name
n
=
readName
(
nextChar
());
c
.
sourcefile
=
new
SourceFileObject
(
n
,
c
.
flatname
);
...
...
@@ -1022,7 +1022,7 @@ public class ClassReader implements Completer {
},
new
AttributeReader
(
names
.
Synthetic
,
V45_3
,
CLASS_OR_MEMBER_ATTRIBUTE
)
{
void
read
(
Symbol
sym
,
int
attrLen
)
{
protected
void
read
(
Symbol
sym
,
int
attrLen
)
{
// bridge methods are visible when generics not enabled
if
(
allowGenerics
||
(
sym
.
flags_field
&
BRIDGE
)
==
0
)
sym
.
flags_field
|=
SYNTHETIC
;
...
...
@@ -1032,7 +1032,7 @@ public class ClassReader implements Completer {
// standard v49 attributes
new
AttributeReader
(
names
.
EnclosingMethod
,
V49
,
CLASS_ATTRIBUTE
)
{
void
read
(
Symbol
sym
,
int
attrLen
)
{
protected
void
read
(
Symbol
sym
,
int
attrLen
)
{
int
newbp
=
bp
+
attrLen
;
readEnclosingMethodAttr
(
sym
);
bp
=
newbp
;
...
...
@@ -1041,11 +1041,11 @@ public class ClassReader implements Completer {
new
AttributeReader
(
names
.
Signature
,
V49
,
CLASS_OR_MEMBER_ATTRIBUTE
)
{
@Override
boolean
accepts
(
AttributeKind
kind
)
{
protected
boolean
accepts
(
AttributeKind
kind
)
{
return
super
.
accepts
(
kind
)
&&
allowGenerics
;
}
void
read
(
Symbol
sym
,
int
attrLen
)
{
protected
void
read
(
Symbol
sym
,
int
attrLen
)
{
if
(
sym
.
kind
==
TYP
)
{
ClassSymbol
c
=
(
ClassSymbol
)
sym
;
readingClassAttr
=
true
;
...
...
@@ -1074,31 +1074,31 @@ public class ClassReader implements Completer {
// v49 annotation attributes
new
AttributeReader
(
names
.
AnnotationDefault
,
V49
,
CLASS_OR_MEMBER_ATTRIBUTE
)
{
void
read
(
Symbol
sym
,
int
attrLen
)
{
protected
void
read
(
Symbol
sym
,
int
attrLen
)
{
attachAnnotationDefault
(
sym
);
}
},
new
AttributeReader
(
names
.
RuntimeInvisibleAnnotations
,
V49
,
CLASS_OR_MEMBER_ATTRIBUTE
)
{
void
read
(
Symbol
sym
,
int
attrLen
)
{
protected
void
read
(
Symbol
sym
,
int
attrLen
)
{
attachAnnotations
(
sym
);
}
},
new
AttributeReader
(
names
.
RuntimeInvisibleParameterAnnotations
,
V49
,
CLASS_OR_MEMBER_ATTRIBUTE
)
{
void
read
(
Symbol
sym
,
int
attrLen
)
{
protected
void
read
(
Symbol
sym
,
int
attrLen
)
{
attachParameterAnnotations
(
sym
);
}
},
new
AttributeReader
(
names
.
RuntimeVisibleAnnotations
,
V49
,
CLASS_OR_MEMBER_ATTRIBUTE
)
{
void
read
(
Symbol
sym
,
int
attrLen
)
{
protected
void
read
(
Symbol
sym
,
int
attrLen
)
{
attachAnnotations
(
sym
);
}
},
new
AttributeReader
(
names
.
RuntimeVisibleParameterAnnotations
,
V49
,
CLASS_OR_MEMBER_ATTRIBUTE
)
{
void
read
(
Symbol
sym
,
int
attrLen
)
{
protected
void
read
(
Symbol
sym
,
int
attrLen
)
{
attachParameterAnnotations
(
sym
);
}
},
...
...
@@ -1106,14 +1106,14 @@ public class ClassReader implements Completer {
// additional "legacy" v49 attributes, superceded by flags
new
AttributeReader
(
names
.
Annotation
,
V49
,
CLASS_OR_MEMBER_ATTRIBUTE
)
{
void
read
(
Symbol
sym
,
int
attrLen
)
{
protected
void
read
(
Symbol
sym
,
int
attrLen
)
{
if
(
allowAnnotations
)
sym
.
flags_field
|=
ANNOTATION
;
}
},
new
AttributeReader
(
names
.
Bridge
,
V49
,
MEMBER_ATTRIBUTE
)
{
void
read
(
Symbol
sym
,
int
attrLen
)
{
protected
void
read
(
Symbol
sym
,
int
attrLen
)
{
sym
.
flags_field
|=
BRIDGE
;
if
(!
allowGenerics
)
sym
.
flags_field
&=
~
SYNTHETIC
;
...
...
@@ -1121,13 +1121,13 @@ public class ClassReader implements Completer {
},
new
AttributeReader
(
names
.
Enum
,
V49
,
CLASS_OR_MEMBER_ATTRIBUTE
)
{
void
read
(
Symbol
sym
,
int
attrLen
)
{
protected
void
read
(
Symbol
sym
,
int
attrLen
)
{
sym
.
flags_field
|=
ENUM
;
}
},
new
AttributeReader
(
names
.
Varargs
,
V49
,
CLASS_OR_MEMBER_ATTRIBUTE
)
{
void
read
(
Symbol
sym
,
int
attrLen
)
{
protected
void
read
(
Symbol
sym
,
int
attrLen
)
{
if
(
allowVarargs
)
sym
.
flags_field
|=
VARARGS
;
}
...
...
@@ -1153,7 +1153,7 @@ public class ClassReader implements Completer {
void
readEnclosingMethodAttr
(
Symbol
sym
)
{
protected
void
readEnclosingMethodAttr
(
Symbol
sym
)
{
// sym is a nested class with an "Enclosing Method" attribute
// remove sym from it's current owners scope and place it in
// the scope specified by the attribute
...
...
src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java
浏览文件 @
1992a1e5
...
...
@@ -164,7 +164,7 @@ public class ClassWriter extends ClassFile {
/** Construct a class writer, given an options table.
*/
pr
ivate
ClassWriter
(
Context
context
)
{
pr
otected
ClassWriter
(
Context
context
)
{
context
.
put
(
classWriterKey
,
this
);
log
=
Log
.
instance
(
context
);
...
...
@@ -601,12 +601,20 @@ public class ClassWriter extends ClassFile {
* Returns the number of attributes written (0 or 1).
*/
int
writeEnclosingMethodAttribute
(
ClassSymbol
c
)
{
if
(!
target
.
hasEnclosingMethodAttribute
()
||
c
.
owner
.
kind
!=
MTH
&&
// neither a local class
if
(!
target
.
hasEnclosingMethodAttribute
())
return
0
;
return
writeEnclosingMethodAttribute
(
names
.
EnclosingMethod
,
c
);
}
/** Write the EnclosingMethod attribute with a specified name.
* Returns the number of attributes written (0 or 1).
*/
protected
int
writeEnclosingMethodAttribute
(
Name
attributeName
,
ClassSymbol
c
)
{
if
(
c
.
owner
.
kind
!=
MTH
&&
// neither a local class
c
.
name
!=
names
.
empty
)
// nor anonymous
return
0
;
int
alenIdx
=
writeAttr
(
names
.
EnclosingMethod
);
int
alenIdx
=
writeAttr
(
attributeName
);
ClassSymbol
enclClass
=
c
.
owner
.
enclClass
();
MethodSymbol
enclMethod
=
(
c
.
owner
.
type
==
null
// local to init block
...
...
@@ -1569,6 +1577,7 @@ public class ClassWriter extends ClassFile {
acount
+=
writeFlagAttrs
(
c
.
flags
());
acount
+=
writeJavaAnnotations
(
c
.
getAnnotationMirrors
());
acount
+=
writeEnclosingMethodAttribute
(
c
);
acount
+=
writeExtraClassAttributes
(
c
);
poolbuf
.
appendInt
(
JAVA_MAGIC
);
poolbuf
.
appendChar
(
target
.
minorVersion
);
...
...
@@ -1588,6 +1597,14 @@ public class ClassWriter extends ClassFile {
pool
=
c
.
pool
=
null
;
// to conserve space
}
/**Allows subclasses to write additional class attributes
*
* @return the number of attributes written
*/
protected
int
writeExtraClassAttributes
(
ClassSymbol
c
)
{
return
0
;
}
int
adjustFlags
(
final
long
flags
)
{
int
result
=
(
int
)
flags
;
if
((
flags
&
SYNTHETIC
)
!=
0
&&
!
target
.
useSyntheticFlag
())
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录