Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_langtools
提交
f21ff357
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看板
提交
f21ff357
编写于
9月 25, 2013
作者:
J
jjg
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
8025407: TypeAnnotations does not use Context
Reviewed-by: jfranck
上级
7bb3a933
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
49 addition
and
36 deletion
+49
-36
src/share/classes/com/sun/tools/javac/code/TypeAnnotations.java
...are/classes/com/sun/tools/javac/code/TypeAnnotations.java
+42
-33
src/share/classes/com/sun/tools/javac/comp/Attr.java
src/share/classes/com/sun/tools/javac/comp/Attr.java
+4
-2
src/share/classes/com/sun/tools/javac/comp/MemberEnter.java
src/share/classes/com/sun/tools/javac/comp/MemberEnter.java
+3
-1
未找到文件。
src/share/classes/com/sun/tools/javac/code/TypeAnnotations.java
浏览文件 @
f21ff357
...
...
@@ -31,10 +31,7 @@ import javax.lang.model.type.TypeKind;
import
javax.tools.JavaFileObject
;
import
com.sun.tools.javac.code.Attribute
;
import
com.sun.tools.javac.code.Attribute.TypeCompound
;
import
com.sun.tools.javac.code.Flags
;
import
com.sun.tools.javac.code.Kinds
;
import
com.sun.tools.javac.code.Type.AnnotatedType
;
import
com.sun.tools.javac.code.Type.ArrayType
;
import
com.sun.tools.javac.code.Type.CapturedType
;
...
...
@@ -49,7 +46,6 @@ import com.sun.tools.javac.code.Type.Visitor;
import
com.sun.tools.javac.code.Type.WildcardType
;
import
com.sun.tools.javac.code.TypeAnnotationPosition.TypePathEntry
;
import
com.sun.tools.javac.code.TypeAnnotationPosition.TypePathEntryKind
;
import
com.sun.tools.javac.code.TypeTag
;
import
com.sun.tools.javac.code.Symbol.VarSymbol
;
import
com.sun.tools.javac.code.Symbol.MethodSymbol
;
import
com.sun.tools.javac.comp.Annotate
;
...
...
@@ -70,6 +66,7 @@ import com.sun.tools.javac.tree.JCTree.JCVariableDecl;
import
com.sun.tools.javac.tree.TreeScanner
;
import
com.sun.tools.javac.tree.JCTree.*
;
import
com.sun.tools.javac.util.Assert
;
import
com.sun.tools.javac.util.Context
;
import
com.sun.tools.javac.util.List
;
import
com.sun.tools.javac.util.ListBuffer
;
import
com.sun.tools.javac.util.Log
;
...
...
@@ -83,8 +80,28 @@ import com.sun.tools.javac.util.Names;
* and determine the TypeAnnotationPositions for all type annotations.
*/
public
class
TypeAnnotations
{
// Class cannot be instantiated.
private
TypeAnnotations
()
{}
protected
static
final
Context
.
Key
<
TypeAnnotations
>
typeAnnosKey
=
new
Context
.
Key
<
TypeAnnotations
>();
public
static
TypeAnnotations
instance
(
Context
context
)
{
TypeAnnotations
instance
=
context
.
get
(
typeAnnosKey
);
if
(
instance
==
null
)
instance
=
new
TypeAnnotations
(
context
);
return
instance
;
}
final
Log
log
;
final
Names
names
;
final
Symtab
syms
;
final
Annotate
annotate
;
protected
TypeAnnotations
(
Context
context
)
{
context
.
put
(
typeAnnosKey
,
this
);
names
=
Names
.
instance
(
context
);
log
=
Log
.
instance
(
context
);
syms
=
Symtab
.
instance
(
context
);
annotate
=
Annotate
.
instance
(
context
);
}
/**
* Separate type annotations from declaration annotations and
...
...
@@ -95,15 +112,14 @@ public class TypeAnnotations {
* adds an Annotator to the correct Annotate queue for
* later processing.
*/
public
static
void
organizeTypeAnnotationsSignatures
(
final
Symtab
syms
,
final
Names
names
,
final
Log
log
,
final
Env
<
AttrContext
>
env
,
final
JCClassDecl
tree
,
final
Annotate
annotate
)
{
public
void
organizeTypeAnnotationsSignatures
(
final
Env
<
AttrContext
>
env
,
final
JCClassDecl
tree
)
{
annotate
.
afterRepeated
(
new
Annotator
()
{
@Override
public
void
enterAnnotation
()
{
JavaFileObject
oldSource
=
log
.
useSource
(
env
.
toplevel
.
sourcefile
);
try
{
new
TypeAnnotationPositions
(
syms
,
names
,
log
,
true
).
scan
(
tree
);
new
TypeAnnotationPositions
(
true
).
scan
(
tree
);
}
finally
{
log
.
useSource
(
oldSource
);
}
...
...
@@ -115,8 +131,8 @@ public class TypeAnnotations {
* This version only visits types in bodies, that is, field initializers,
* top-level blocks, and method bodies, and should be called from Attr.
*/
public
static
void
organizeTypeAnnotationsBodies
(
Symtab
syms
,
Names
names
,
Log
log
,
JCClassDecl
tree
)
{
new
TypeAnnotationPositions
(
syms
,
names
,
log
,
false
).
scan
(
tree
);
public
void
organizeTypeAnnotationsBodies
(
JCClassDecl
tree
)
{
new
TypeAnnotationPositions
(
false
).
scan
(
tree
);
}
public
enum
AnnotationType
{
DECLARATION
,
TYPE
,
BOTH
};
...
...
@@ -125,8 +141,7 @@ public class TypeAnnotations {
* Determine whether an annotation is a declaration annotation,
* a type annotation, or both.
*/
public
static
AnnotationType
annotationType
(
Symtab
syms
,
Names
names
,
Attribute
.
Compound
a
,
Symbol
s
)
{
public
AnnotationType
annotationType
(
Attribute
.
Compound
a
,
Symbol
s
)
{
Attribute
.
Compound
atTarget
=
a
.
type
.
tsym
.
attribute
(
syms
.
annotationTargetType
.
tsym
);
if
(
atTarget
==
null
)
{
...
...
@@ -215,17 +230,11 @@ public class TypeAnnotations {
}
private
static
class
TypeAnnotationPositions
extends
TreeScanner
{
private
class
TypeAnnotationPositions
extends
TreeScanner
{
private
final
Symtab
syms
;
private
final
Names
names
;
private
final
Log
log
;
private
final
boolean
sigOnly
;
private
TypeAnnotationPositions
(
Symtab
syms
,
Names
names
,
Log
log
,
boolean
sigOnly
)
{
this
.
syms
=
syms
;
this
.
names
=
names
;
this
.
log
=
log
;
TypeAnnotationPositions
(
boolean
sigOnly
)
{
this
.
sigOnly
=
sigOnly
;
}
...
...
@@ -265,7 +274,7 @@ public class TypeAnnotations {
ListBuffer
<
Attribute
.
TypeCompound
>
typeAnnos
=
new
ListBuffer
<
Attribute
.
TypeCompound
>();
for
(
Attribute
.
Compound
a
:
annotations
)
{
switch
(
annotationType
(
syms
,
names
,
a
,
sym
))
{
switch
(
annotationType
(
a
,
sym
))
{
case
DECLARATION:
declAnnos
.
append
(
a
);
break
;
...
...
@@ -301,7 +310,7 @@ public class TypeAnnotations {
}
// type is non-null and annotations are added to that type
type
=
typeWithAnnotations
(
typetree
,
type
,
typeAnnotations
,
log
);
type
=
typeWithAnnotations
(
typetree
,
type
,
typeAnnotations
);
if
(
sym
.
getKind
()
==
ElementKind
.
METHOD
)
{
sym
.
type
.
asMethodType
().
restype
=
type
;
...
...
@@ -352,8 +361,8 @@ public class TypeAnnotations {
//
// As a side effect the method sets the type annotation position of "annotations".
// Note that it is assumed that all annotations share the same position.
private
static
Type
typeWithAnnotations
(
final
JCTree
typetree
,
final
Type
type
,
final
List
<
Attribute
.
TypeCompound
>
annotations
,
Log
log
)
{
private
Type
typeWithAnnotations
(
final
JCTree
typetree
,
final
Type
type
,
final
List
<
Attribute
.
TypeCompound
>
annotations
)
{
// System.out.printf("typeWithAnnotations(typetree: %s, type: %s, annotations: %s)%n",
// typetree, type, annotations);
if
(
annotations
.
isEmpty
())
{
...
...
@@ -400,7 +409,7 @@ public class TypeAnnotations {
arTree
=
arrayTypeTree
(
arTree
.
elemtype
);
depth
=
depth
.
append
(
TypePathEntry
.
ARRAY
);
}
Type
arelemType
=
typeWithAnnotations
(
arTree
.
elemtype
,
arType
.
elemtype
,
annotations
,
log
);
Type
arelemType
=
typeWithAnnotations
(
arTree
.
elemtype
,
arType
.
elemtype
,
annotations
);
tomodify
.
elemtype
=
arelemType
;
{
// All annotations share the same position; modify the first one.
...
...
@@ -417,7 +426,7 @@ public class TypeAnnotations {
// There is a TypeKind, but no TypeTag.
JCTypeUnion
tutree
=
(
JCTypeUnion
)
typetree
;
JCExpression
fst
=
tutree
.
alternatives
.
get
(
0
);
Type
res
=
typeWithAnnotations
(
fst
,
fst
.
type
,
annotations
,
log
);
Type
res
=
typeWithAnnotations
(
fst
,
fst
.
type
,
annotations
);
fst
.
type
=
res
;
// TODO: do we want to set res as first element in uct.alternatives?
// UnionClassType uct = (com.sun.tools.javac.code.Type.UnionClassType)type;
...
...
@@ -505,7 +514,7 @@ public class TypeAnnotations {
}
}
private
static
JCArrayTypeTree
arrayTypeTree
(
JCTree
typetree
)
{
private
JCArrayTypeTree
arrayTypeTree
(
JCTree
typetree
)
{
if
(
typetree
.
getKind
()
==
JCTree
.
Kind
.
ARRAY_TYPE
)
{
return
(
JCArrayTypeTree
)
typetree
;
}
else
if
(
typetree
.
getKind
()
==
JCTree
.
Kind
.
ANNOTATED_TYPE
)
{
...
...
@@ -532,7 +541,7 @@ public class TypeAnnotations {
* @param annotations The annotations to insert.
* @return A copy of type that contains the annotations.
*/
private
static
Type
typeWithAnnotations
(
final
Type
type
,
private
Type
typeWithAnnotations
(
final
Type
type
,
final
Type
stopAt
,
final
List
<
Attribute
.
TypeCompound
>
annotations
)
{
Visitor
<
Type
,
List
<
TypeCompound
>>
visitor
=
...
...
@@ -619,7 +628,7 @@ public class TypeAnnotations {
return
type
.
accept
(
visitor
,
annotations
);
}
private
static
Attribute
.
TypeCompound
toTypeCompound
(
Attribute
.
Compound
a
,
TypeAnnotationPosition
p
)
{
private
Attribute
.
TypeCompound
toTypeCompound
(
Attribute
.
Compound
a
,
TypeAnnotationPosition
p
)
{
// It is safe to alias the position.
return
new
Attribute
.
TypeCompound
(
a
,
p
);
}
...
...
@@ -953,7 +962,7 @@ public class TypeAnnotations {
}
}
private
static
void
locateNestedTypes
(
Type
type
,
TypeAnnotationPosition
p
)
{
private
void
locateNestedTypes
(
Type
type
,
TypeAnnotationPosition
p
)
{
// The number of "steps" to get from the full type to the
// left-most outer type.
ListBuffer
<
TypePathEntry
>
depth
=
new
ListBuffer
<>();
...
...
@@ -970,7 +979,7 @@ public class TypeAnnotations {
}
}
private
static
int
methodParamIndex
(
List
<
JCTree
>
path
,
JCTree
param
)
{
private
int
methodParamIndex
(
List
<
JCTree
>
path
,
JCTree
param
)
{
List
<
JCTree
>
curr
=
path
;
while
(
curr
.
head
.
getTag
()
!=
Tag
.
METHODDEF
&&
curr
.
head
.
getTag
()
!=
Tag
.
LAMBDA
)
{
...
...
@@ -1284,7 +1293,7 @@ public class TypeAnnotations {
}
}
private
static
void
setTypeAnnotationPos
(
List
<
JCAnnotation
>
annotations
,
private
void
setTypeAnnotationPos
(
List
<
JCAnnotation
>
annotations
,
TypeAnnotationPosition
position
)
{
for
(
JCAnnotation
anno
:
annotations
)
{
// attribute might be null during DeferredAttr;
...
...
src/share/classes/com/sun/tools/javac/comp/Attr.java
浏览文件 @
f21ff357
...
...
@@ -93,6 +93,7 @@ public class Attr extends JCTree.Visitor {
final
Types
types
;
final
JCDiagnostic
.
Factory
diags
;
final
Annotate
annotate
;
final
TypeAnnotations
typeAnnotations
;
final
DeferredLintHandler
deferredLintHandler
;
public
static
Attr
instance
(
Context
context
)
{
...
...
@@ -121,6 +122,7 @@ public class Attr extends JCTree.Visitor {
types
=
Types
.
instance
(
context
);
diags
=
JCDiagnostic
.
Factory
.
instance
(
context
);
annotate
=
Annotate
.
instance
(
context
);
typeAnnotations
=
TypeAnnotations
.
instance
(
context
);
deferredLintHandler
=
DeferredLintHandler
.
instance
(
context
);
Options
options
=
Options
.
instance
(
context
);
...
...
@@ -2228,7 +2230,7 @@ public class Attr extends JCTree.Visitor {
// empty annotations, if only declaration annotations were given.
// This method will raise an error for such a type.
for
(
JCAnnotation
ai
:
annotations
)
{
if
(
TypeAnnotations
.
annotationType
(
syms
,
names
,
ai
.
attribute
,
sym
)
==
TypeAnnotations
.
AnnotationType
.
DECLARATION
)
{
if
(
typeAnnotations
.
annotationType
(
ai
.
attribute
,
sym
)
==
TypeAnnotations
.
AnnotationType
.
DECLARATION
)
{
log
.
error
(
ai
.
pos
(),
"annotation.type.not.applicable"
);
}
}
...
...
@@ -4339,7 +4341,7 @@ public class Attr extends JCTree.Visitor {
}
if
(
allowTypeAnnos
)
{
// Correctly organize the postions of the type annotations
TypeAnnotations
.
organizeTypeAnnotationsBodies
(
this
.
syms
,
this
.
names
,
this
.
log
,
tree
);
typeAnnotations
.
organizeTypeAnnotationsBodies
(
tree
);
// Check type annotations applicability rules
validateTypeAnnotations
(
tree
);
...
...
src/share/classes/com/sun/tools/javac/comp/MemberEnter.java
浏览文件 @
f21ff357
...
...
@@ -79,6 +79,7 @@ public class MemberEnter extends JCTree.Visitor implements Completer {
private
final
ClassReader
reader
;
private
final
Todo
todo
;
private
final
Annotate
annotate
;
private
final
TypeAnnotations
typeAnnotations
;
private
final
Types
types
;
private
final
JCDiagnostic
.
Factory
diags
;
private
final
Source
source
;
...
...
@@ -105,6 +106,7 @@ public class MemberEnter extends JCTree.Visitor implements Completer {
reader
=
ClassReader
.
instance
(
context
);
todo
=
Todo
.
instance
(
context
);
annotate
=
Annotate
.
instance
(
context
);
typeAnnotations
=
TypeAnnotations
.
instance
(
context
);
types
=
Types
.
instance
(
context
);
diags
=
JCDiagnostic
.
Factory
.
instance
(
context
);
source
=
Source
.
instance
(
context
);
...
...
@@ -1164,7 +1166,7 @@ public class MemberEnter extends JCTree.Visitor implements Completer {
}
}
if
(
allowTypeAnnos
)
{
TypeAnnotations
.
organizeTypeAnnotationsSignatures
(
syms
,
names
,
log
,
env
,
tree
,
annotat
e
);
typeAnnotations
.
organizeTypeAnnotationsSignatures
(
env
,
tre
e
);
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录