Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_langtools
提交
a6055937
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看板
提交
a6055937
编写于
6月 17, 2015
作者:
A
asaha
浏览文件
操作
浏览文件
下载
差异文件
Merge
上级
0b7529e5
ce11a11f
变更
22
隐藏空白更改
内联
并排
Showing
22 changed file
with
733 addition
and
90 deletion
+733
-90
.hgtags
.hgtags
+1
-0
src/share/classes/com/sun/tools/javac/code/Scope.java
src/share/classes/com/sun/tools/javac/code/Scope.java
+9
-5
src/share/classes/com/sun/tools/javac/code/Types.java
src/share/classes/com/sun/tools/javac/code/Types.java
+57
-33
src/share/classes/com/sun/tools/javac/comp/Attr.java
src/share/classes/com/sun/tools/javac/comp/Attr.java
+11
-2
src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java
src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java
+21
-11
src/share/classes/com/sun/tools/javac/comp/Resolve.java
src/share/classes/com/sun/tools/javac/comp/Resolve.java
+1
-1
src/share/classes/com/sun/tools/javac/jvm/Gen.java
src/share/classes/com/sun/tools/javac/jvm/Gen.java
+8
-1
src/share/classes/com/sun/tools/javac/resources/javac_ja.properties
...classes/com/sun/tools/javac/resources/javac_ja.properties
+2
-2
src/share/classes/com/sun/tools/javac/resources/javac_zh_CN.properties
...sses/com/sun/tools/javac/resources/javac_zh_CN.properties
+2
-2
src/share/classes/com/sun/tools/javac/tree/TreeInfo.java
src/share/classes/com/sun/tools/javac/tree/TreeInfo.java
+13
-0
test/tools/javac/7153958/CPoolRefClassContainingInlinedCts.java
...ools/javac/7153958/CPoolRefClassContainingInlinedCts.java
+87
-30
test/tools/javac/7153958/pkg/ClassToBeStaticallyImportedA.java
...tools/javac/7153958/pkg/ClassToBeStaticallyImportedA.java
+3
-3
test/tools/javac/7153958/pkg/ClassToBeStaticallyImportedB.java
...tools/javac/7153958/pkg/ClassToBeStaticallyImportedB.java
+29
-0
test/tools/javac/annotations/neg/AnonSubclass.java
test/tools/javac/annotations/neg/AnonSubclass.java
+13
-0
test/tools/javac/annotations/neg/AnonSubclass.out
test/tools/javac/annotations/neg/AnonSubclass.out
+2
-0
test/tools/javac/annotations/neg/pkg/AnonSubclassOnPkg.java
test/tools/javac/annotations/neg/pkg/AnonSubclassOnPkg.java
+28
-0
test/tools/javac/annotations/neg/pkg/package-info.java
test/tools/javac/annotations/neg/pkg/package-info.java
+12
-0
test/tools/javac/annotations/neg/pkg/package-info.out
test/tools/javac/annotations/neg/pkg/package-info.out
+2
-0
test/tools/javac/expression/DeeplyChainedNonPolyExpressionTest.java
.../javac/expression/DeeplyChainedNonPolyExpressionTest.java
+178
-0
test/tools/javac/scope/RemoveSymbolTest.java
test/tools/javac/scope/RemoveSymbolTest.java
+77
-0
test/tools/javac/scope/RemoveSymbolUnitTest.java
test/tools/javac/scope/RemoveSymbolUnitTest.java
+95
-0
test/tools/javac/types/ScopeListenerTest.java
test/tools/javac/types/ScopeListenerTest.java
+82
-0
未找到文件。
.hgtags
浏览文件 @
a6055937
...
...
@@ -438,3 +438,4 @@ ecb7e46b820f293bb644f92bc1af3ede53bceced jdk8u60-b16
87dcdc1fd75bf827c8a4596b183de7ea73cb75e1 jdk8u60-b17
e7e42c79861ea1ab7495de5f238c01f98035a8a8 jdk8u60-b18
0366d7f1faa12ed35694571c151524e0847f05ff jdk8u60-b19
976523f1d5626bdb6dd47883e2734614b64a5e61 jdk8u60-b20
src/share/classes/com/sun/tools/javac/code/Scope.java
浏览文件 @
a6055937
/*
* Copyright (c) 1999, 201
3
, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 201
5
, 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
...
...
@@ -241,12 +241,16 @@ public class Scope {
listeners
=
listeners
.
prepend
(
sl
);
}
/** Remove symbol from this scope. Used when an inner class
* attribute tells us that the class isn't a package member.
/** Remove symbol from this scope.
*/
public
void
remove
(
Symbol
sym
)
{
public
void
remove
(
final
Symbol
sym
)
{
Assert
.
check
(
shared
==
0
);
Entry
e
=
lookup
(
sym
.
name
);
Entry
e
=
lookup
(
sym
.
name
,
new
Filter
<
Symbol
>()
{
@Override
public
boolean
accepts
(
Symbol
candidate
)
{
return
candidate
==
sym
;
}
});
if
(
e
.
scope
==
null
)
return
;
// remove e from table and shadowed list;
...
...
src/share/classes/com/sun/tools/javac/code/Types.java
浏览文件 @
a6055937
...
...
@@ -2694,74 +2694,98 @@ public class Types {
// </editor-fold>
// <editor-fold defaultstate="collapsed" desc="compute transitive closure of all members in given site">
class
MembersClosureCache
extends
SimpleVisitor
<
CompoundScope
,
Boolean
>
{
class
MembersClosureCache
extends
SimpleVisitor
<
Scope
.
CompoundScope
,
Void
>
{
private
WeakHashMap
<
TypeSymbol
,
Entry
>
_map
=
new
WeakHashMap
<
TypeSymbol
,
Entry
>();
private
Map
<
TypeSymbol
,
CompoundScope
>
_map
=
new
HashMap
<>();
class
Entry
{
final
boolean
skipInterfaces
;
final
CompoundScope
compoundScope
;
Set
<
TypeSymbol
>
seenTypes
=
new
HashSet
<>();
class
MembersScope
extends
CompoundScope
{
CompoundScope
scope
;
public
MembersScope
(
CompoundScope
scope
)
{
super
(
scope
.
owner
);
this
.
scope
=
scope
;
}
Filter
<
Symbol
>
combine
(
final
Filter
<
Symbol
>
sf
)
{
return
new
Filter
<
Symbol
>()
{
@Override
public
boolean
accepts
(
Symbol
s
)
{
return
!
s
.
owner
.
isInterface
()
&&
(
sf
==
null
||
sf
.
accepts
(
s
));
}
};
}
public
Entry
(
boolean
skipInterfaces
,
CompoundScope
compoundScope
)
{
this
.
skipInterfaces
=
skipInterfaces
;
this
.
compoundScope
=
compoundScope
;
@Override
public
Iterable
<
Symbol
>
getElements
(
Filter
<
Symbol
>
sf
)
{
return
scope
.
getElements
(
combine
(
sf
));
}
@Override
public
Iterable
<
Symbol
>
getElementsByName
(
Name
name
,
Filter
<
Symbol
>
sf
)
{
return
scope
.
getElementsByName
(
name
,
combine
(
sf
));
}
boolean
matches
(
boolean
skipInterfaces
)
{
return
this
.
skipInterfaces
==
skipInterfaces
;
@Override
public
int
getMark
()
{
return
scope
.
getMark
();
}
}
List
<
TypeSymbol
>
seenTypes
=
List
.
nil
()
;
CompoundScope
nilScope
;
/** members closure visitor methods **/
public
CompoundScope
visitType
(
Type
t
,
Boolean
skipInterface
)
{
return
null
;
public
CompoundScope
visitType
(
Type
t
,
Void
_unused
)
{
if
(
nilScope
==
null
)
{
nilScope
=
new
CompoundScope
(
syms
.
noSymbol
);
}
return
nilScope
;
}
@Override
public
CompoundScope
visitClassType
(
ClassType
t
,
Boolean
skipInterface
)
{
if
(
seenTypes
.
contains
(
t
.
tsym
))
{
public
CompoundScope
visitClassType
(
ClassType
t
,
Void
_unused
)
{
if
(
!
seenTypes
.
add
(
t
.
tsym
))
{
//this is possible when an interface is implemented in multiple
//superclasses, or when a class
s
hierarchy is circular - in such
//superclasses, or when a class hierarchy is circular - in such
//cases we don't need to recurse (empty scope is returned)
return
new
CompoundScope
(
t
.
tsym
);
}
try
{
seenTypes
=
seenTypes
.
prepen
d
(
t
.
tsym
);
seenTypes
.
ad
d
(
t
.
tsym
);
ClassSymbol
csym
=
(
ClassSymbol
)
t
.
tsym
;
Entry
e
=
_map
.
get
(
csym
);
if
(
e
==
null
||
!
e
.
matches
(
skipInterface
))
{
CompoundScope
membersClosure
=
new
CompoundScope
(
csym
);
if
(!
skipInterface
)
{
for
(
Type
i
:
interfaces
(
t
))
{
membersClosure
.
addSubScope
(
visit
(
i
,
skipInterface
));
}
CompoundScope
membersClosure
=
_map
.
get
(
csym
);
if
(
membersClosure
==
null
)
{
membersClosure
=
new
CompoundScope
(
csym
);
for
(
Type
i
:
interfaces
(
t
))
{
membersClosure
.
addSubScope
(
visit
(
i
,
null
));
}
membersClosure
.
addSubScope
(
visit
(
supertype
(
t
),
skipInterface
));
membersClosure
.
addSubScope
(
visit
(
supertype
(
t
),
null
));
membersClosure
.
addSubScope
(
csym
.
members
());
e
=
new
Entry
(
skipInterface
,
membersClosure
);
_map
.
put
(
csym
,
e
);
_map
.
put
(
csym
,
membersClosure
);
}
return
e
.
compoundScop
e
;
return
membersClosur
e
;
}
finally
{
seenTypes
=
seenTypes
.
tail
;
seenTypes
.
remove
(
t
.
tsym
)
;
}
}
@Override
public
CompoundScope
visitTypeVar
(
TypeVar
t
,
Boolean
skipInterface
)
{
return
visit
(
t
.
getUpperBound
(),
skipInterface
);
public
CompoundScope
visitTypeVar
(
TypeVar
t
,
Void
_unused
)
{
return
visit
(
t
.
getUpperBound
(),
null
);
}
}
private
MembersClosureCache
membersCache
=
new
MembersClosureCache
();
public
CompoundScope
membersClosure
(
Type
site
,
boolean
skipInterface
)
{
return
membersCache
.
visit
(
site
,
skipInterface
);
CompoundScope
cs
=
membersCache
.
visit
(
site
,
null
);
if
(
cs
==
null
)
Assert
.
error
(
"type "
+
site
);
return
skipInterface
?
membersCache
.
new
MembersScope
(
cs
)
:
cs
;
}
// </editor-fold>
...
...
src/share/classes/com/sun/tools/javac/comp/Attr.java
浏览文件 @
a6055937
...
...
@@ -825,9 +825,18 @@ public class Attr extends JCTree.Visitor {
}
public
void
visitClassDef
(
JCClassDecl
tree
)
{
// Local classes have not been entered yet, so we need to do it now:
if
((
env
.
info
.
scope
.
owner
.
kind
&
(
VAR
|
MTH
))
!=
0
)
// Local and anonymous classes have not been entered yet, so we need to
// do it now.
if
((
env
.
info
.
scope
.
owner
.
kind
&
(
VAR
|
MTH
))
!=
0
)
{
enter
.
classEnter
(
tree
,
env
);
}
else
{
// If this class declaration is part of a class level annotation,
// as in @MyAnno(new Object() {}) class MyClass {}, enter it in
// order to simplify later steps and allow for sensible error
// messages.
if
(
env
.
tree
.
hasTag
(
NEWCLASS
)
&&
TreeInfo
.
isInAnnotation
(
env
,
tree
))
enter
.
classEnter
(
tree
,
env
);
}
ClassSymbol
c
=
tree
.
sym
;
if
(
c
==
null
)
{
...
...
src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java
浏览文件 @
a6055937
...
...
@@ -1256,6 +1256,9 @@ public class DeferredAttr extends JCTree.Visitor {
return
isSimpleReceiver
(((
JCAnnotatedType
)
rec
).
underlyingType
);
case
APPLY:
return
true
;
case
NEWCLASS:
JCNewClass
nc
=
(
JCNewClass
)
rec
;
return
nc
.
encl
==
null
&&
nc
.
def
==
null
&&
!
TreeInfo
.
isDiamond
(
nc
);
default
:
return
false
;
}
...
...
@@ -1310,17 +1313,24 @@ public class DeferredAttr extends JCTree.Visitor {
Type
site
;
if
(
rec
!=
null
)
{
if
(
rec
.
hasTag
(
APPLY
))
{
Symbol
recSym
=
quicklyResolveMethod
(
env
,
(
JCMethodInvocation
)
rec
);
if
(
recSym
==
null
)
return
null
;
Symbol
resolvedReturnType
=
analyzeCandidateMethods
(
recSym
,
syms
.
errSymbol
,
returnSymbolAnalyzer
);
if
(
resolvedReturnType
==
null
)
return
null
;
site
=
resolvedReturnType
.
type
;
}
else
{
site
=
attribSpeculative
(
rec
,
env
,
attr
.
unknownTypeExprInfo
).
type
;
switch
(
rec
.
getTag
())
{
case
APPLY:
Symbol
recSym
=
quicklyResolveMethod
(
env
,
(
JCMethodInvocation
)
rec
);
if
(
recSym
==
null
)
return
null
;
Symbol
resolvedReturnType
=
analyzeCandidateMethods
(
recSym
,
syms
.
errSymbol
,
returnSymbolAnalyzer
);
if
(
resolvedReturnType
==
null
)
return
null
;
site
=
resolvedReturnType
.
type
;
break
;
case
NEWCLASS:
JCNewClass
nc
=
(
JCNewClass
)
rec
;
site
=
attribSpeculative
(
nc
.
clazz
,
env
,
attr
.
unknownTypeExprInfo
).
type
;
break
;
default
:
site
=
attribSpeculative
(
rec
,
env
,
attr
.
unknownTypeExprInfo
).
type
;
break
;
}
}
else
{
site
=
env
.
enclClass
.
sym
.
type
;
...
...
src/share/classes/com/sun/tools/javac/comp/Resolve.java
浏览文件 @
a6055937
...
...
@@ -271,7 +271,7 @@ public class Resolve {
* the one of its outer environment
*/
protected
static
boolean
isStatic
(
Env
<
AttrContext
>
env
)
{
return
env
.
info
.
staticLevel
>
env
.
outer
.
info
.
staticLevel
;
return
env
.
outer
!=
null
&&
env
.
info
.
staticLevel
>
env
.
outer
.
info
.
staticLevel
;
}
/** An environment is an "initializer" if it is a constructor or
...
...
src/share/classes/com/sun/tools/javac/jvm/Gen.java
浏览文件 @
a6055937
...
...
@@ -514,6 +514,10 @@ public class Gen extends JCTree.Visitor {
clinitTAs
.
addAll
(
getAndRemoveNonFieldTAs
(
sym
));
}
else
{
checkStringConstant
(
vdef
.
init
.
pos
(),
sym
.
getConstValue
());
/* if the init contains a reference to an external class, add it to the
* constant's pool
*/
vdef
.
init
.
accept
(
classReferenceVisitor
);
}
}
break
;
...
...
@@ -2431,9 +2435,12 @@ public class Gen extends JCTree.Visitor {
&&
!
allowGenerics
// no Miranda methods available with generics
)
implementInterfaceMethods
(
c
);
cdef
.
defs
=
normalizeDefs
(
cdef
.
defs
,
c
);
c
.
pool
=
pool
;
pool
.
reset
();
/* method normalizeDefs() can add references to external classes into the constant pool
* so it should be called after pool.reset()
*/
cdef
.
defs
=
normalizeDefs
(
cdef
.
defs
,
c
);
generateReferencesToPrunedTree
(
c
,
pool
);
Env
<
GenContext
>
localEnv
=
new
Env
<
GenContext
>(
cdef
,
new
GenContext
());
...
...
src/share/classes/com/sun/tools/javac/resources/javac_ja.properties
浏览文件 @
a6055937
#
# Copyright (c) 1999, 201
4
, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 1999, 201
5
, 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
...
...
@@ -133,7 +133,7 @@ javac.msg.usage=\u4F7F\u7528\u65B9\u6CD5: {0} <options> <source files>\n\u4F7F\u
javac.msg.usage.nonstandard.footer
=
\u3053\u
308C
\u3089\u
306F
\u
975E
\u
6A19
\u
6E96
\u
30AA
\u
30D7
\u
30B7
\u
30E7
\u
30F3
\u3067\u3042\u
308A
\u
4E88
\u
544A
\u
306A
\u3057\u
306B
\u5909\u
66F4
\u3055\u
308C
\u
308B
\u3053\u3068\u
304C
\u3042\u
308A
\u
307E
\u3059\u3002
javac.msg.bug
=
\u
30B3
\u
30F3
\u
30D1
\u
30A4
\u
30E9
\u3067\u
4F8B
\u5916\u
304C
\u
767A
\u
751F
\u3057\u
307E
\u3057\u
305F({0})
\u3002
Bug Parade
\u3067\u
91CD
\u8907\u
304C
\u
306A
\u3044\u
304B
\u3092\u3054\u
78BA
\u
8A8D
\u
306E
\u3046\u3048\u3001
Java Developer Connection (http://java.sun.com/webapps/bugreport
)
\u3067
bug
\u
306E
\u
767B
\u9332\u3092\u
304A
\u9858\u3044\u3044\u
305F
\u3057\u
307E
\u3059\u3002\u
30EC
\u
30DD
\u
30FC
\u
30C8
\u
306B
\u
306F
\u3001\u
305D
\u
306E
\u
30D7
\u
30ED
\u
30B0
\u
30E9
\u
30E0
\u3068\u
4E0B
\u
8A18
\u
306E
\u
8A3A
\u
65AD
\u5185\u
5BB9
\u3092\u
542B
\u3081\u3066\u
304F
\u3060\u3055\u3044\u3002\u3054\u5354\u
529B
\u3042\u
308A
\u
304C
\u3068\u3046\u3054\u3056\u3044\u
307E
\u3059\u3002
javac.msg.bug
=
\u
30B3
\u
30F3
\u
30D1
\u
30A4
\u
30E9
\u3067\u
4F8B
\u5916\u
304C
\u
767A
\u
751F
\u3057\u
307E
\u3057\u
305F({0})
\u3002
\u
30C7
\u
30FC
\u
30BF
\u
30D9
\u
30FC
\u
30B9
\u3067\u
91CD
\u8907\u
304C
\u
306A
\u3044\u
304B
\u3092\u3054\u
78BA
\u
8A8D
\u
306E
\u3046\u3048\u3001
Java Bug Database (http://bugreport.java.com/bugreport/
)
\u3067
bug
\u
306E
\u
767B
\u9332\u3092\u
304A
\u9858\u3044\u3044\u
305F
\u3057\u
307E
\u3059\u3002\u
30EC
\u
30DD
\u
30FC
\u
30C8
\u
306B
\u
306F
\u3001\u
305D
\u
306E
\u
30D7
\u
30ED
\u
30B0
\u
30E9
\u
30E0
\u3068\u
4E0B
\u
8A18
\u
306E
\u
8A3A
\u
65AD
\u5185\u
5BB9
\u3092\u
542B
\u3081\u3066\u
304F
\u3060\u3055\u3044\u3002\u3054\u5354\u
529B
\u3042\u
308A
\u
304C
\u3068\u3046\u3054\u3056\u3044\u
307E
\u3059\u3002
javac.msg.io
=
\n\n\u5165\u
51FA
\u
529B
\u
30A8
\u
30E9
\u
30FC
\u
304C
\u
767A
\u
751F
\u3057\u
307E
\u3057\u
305F
\u3002\n\u
8A73
\u
7D30
\u
306F
\u
6B21
\u
306E
\u
30B9
\u
30BF
\u
30C3
\u
30AF
\u
30FB
\u
30C8
\u
30EC
\u
30FC
\u
30B9
\u3067\u
8ABF
\u
67FB
\u3057\u3066\u
304F
\u3060\u3055\u3044\u3002\n
...
...
src/share/classes/com/sun/tools/javac/resources/javac_zh_CN.properties
浏览文件 @
a6055937
#
# Copyright (c) 1999, 201
3
, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 1999, 201
5
, 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
...
...
@@ -133,7 +133,7 @@ javac.msg.usage=\u7528\u6CD5: {0} <options> <source files>\n-help \u7528\u4E8E\u
javac.msg.usage.nonstandard.footer
=
\u
8FD9
\u
4E9B
\u9009\u9879\u
90FD
\u
662F
\u
975E
\u6807\u
51C6
\u9009\u9879
,
\u5982\u6709\u
66F4
\u6539
,
\u6055\u
4E0D
\u
53E6
\u
884C
\u
901A
\u
77E5
\u3002
javac.msg.bug
=
\u
7F16
\u
8BD1
\u5668
({0})
\u
4E2D
\u
51FA
\u
73B0
\u
5F02
\u
5E38
\u9519\u
8BEF
\u3002
\u5982\u
679C
\u5728
Bug Parade
\u
4E2D
\u
6CA1
\u6709\u
627E
\u5230\u
8BE5
\u9519\u
8BEF,
\u
8BF7
\u5728
Java Developer Connection (http://java.sun.com/webapps/bugreport)
\u
4E2D
\u
5EFA
\u
7ACB Bug
\u3002\u
8BF7
\u5728\u
62A5
\u
544A
\u
4E2D
\u9644\u
4E0A
\u
60A8
\u7684\u
7A0B
\u
5E8F
\u
548C
\u
4EE5
\u
4E0B
\u
8BCA
\u
65AD
\u
4FE1
\u
606F
\u3002\u
8C22
\u
8C22
\u3002
javac.msg.bug
=
\u
7F16
\u
8BD1
\u5668
({0})
\u
4E2D
\u
51FA
\u
73B0
\u
5F02
\u
5E38
\u9519\u
8BEF
\u3002
\u5982\u
679C
\u5728
Java Bug Database (http://bugreport.java.com/bugreport/)
\u
4E2D
\u
6CA1
\u6709\u
627E
\u5230\u
8BE5
\u9519\u
8BEF,
\u
8BF7
\u5728\u
8BE5
\u6570\u
636E
\u
5E93
\u
4E2D
\u
5EFA
\u
7ACB Bug
\u3002\u
8BF7
\u5728\u
62A5
\u
544A
\u
4E2D
\u9644\u
4E0A
\u
60A8
\u7684\u
7A0B
\u
5E8F
\u
548C
\u
4EE5
\u
4E0B
\u
8BCA
\u
65AD
\u
4FE1
\u
606F
\u3002\u
8C22
\u
8C22
\u3002
javac.msg.io
=
\n\n\u
53D1
\u
751F
\u
8F93
\u5165
/
\u
8F93
\u
51FA
\u9519\u
8BEF
\u3002\n\u6709\u5173\u
8BE6
\u
7EC6
\u
4FE1
\u
606F,
\u
8BF7
\u
53C2
\u9605\u
4EE5
\u
4E0B
\u5806\u6808\u
8DDF
\u
8E2A
\u3002\n
...
...
src/share/classes/com/sun/tools/javac/tree/TreeInfo.java
浏览文件 @
a6055937
...
...
@@ -28,6 +28,7 @@ package com.sun.tools.javac.tree;
import
com.sun.source.tree.Tree
;
import
com.sun.source.util.TreePath
;
import
com.sun.tools.javac.code.*
;
import
com.sun.tools.javac.comp.AttrContext
;
import
com.sun.tools.javac.comp.Env
;
...
...
@@ -351,6 +352,18 @@ public class TreeInfo {
return
(
lit
.
typetag
==
BOT
);
}
/** Return true iff this tree is a child of some annotation. */
public
static
boolean
isInAnnotation
(
Env
<?>
env
,
JCTree
tree
)
{
TreePath
tp
=
TreePath
.
getPath
(
env
.
toplevel
,
tree
);
if
(
tp
!=
null
)
{
for
(
Tree
t
:
tp
)
{
if
(
t
.
getKind
()
==
Tree
.
Kind
.
ANNOTATION
)
return
true
;
}
}
return
false
;
}
public
static
String
getCommentText
(
Env
<?>
env
,
JCTree
tree
)
{
DocCommentTable
docComments
=
(
tree
.
hasTag
(
JCTree
.
Tag
.
TOPLEVEL
))
?
((
JCCompilationUnit
)
tree
).
docComments
...
...
test/tools/javac/7153958/CPoolRefClassContainingInlinedCts.java
浏览文件 @
a6055937
/*
* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012,
2015,
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
...
...
@@ -25,9 +25,9 @@
/*
* @test
* @bug 7153958
* @bug 7153958
8073372
* @summary add constant pool reference to class containing inlined constants
* @compile pkg/ClassToBeStaticallyImported.java CPoolRefClassContainingInlinedCts.java
* @compile pkg/ClassToBeStaticallyImported
A.java pkg/ClassToBeStaticallyImportedB
.java CPoolRefClassContainingInlinedCts.java
* @run main CPoolRefClassContainingInlinedCts
*/
...
...
@@ -38,7 +38,8 @@ import com.sun.tools.classfile.ConstantPoolException;
import
java.io.File
;
import
java.io.IOException
;
import
static
pkg
.
ClassToBeStaticallyImported
.
staticField
;
import
static
pkg
.
ClassToBeStaticallyImportedA
.
staticFieldA
;
import
static
pkg
.
ClassToBeStaticallyImportedB
.
staticFieldB
;
public
class
CPoolRefClassContainingInlinedCts
{
...
...
@@ -54,10 +55,14 @@ public class CPoolRefClassContainingInlinedCts {
void
checkClassName
(
String
className
)
{
switch
(
className
)
{
case
"SimpleAssignClass"
:
case
"BinaryExpClass"
:
case
"UnaryExpClass"
:
case
"CastClass"
:
case
"ParensClass"
:
case
"CondClass"
:
case
"IfClass"
:
case
"pkg/ClassToBeStaticallyImported"
:
case
"SimpleAssignClassA"
:
case
"BinaryExpClassA"
:
case
"UnaryExpClassA"
:
case
"CastClassA"
:
case
"ParensClassA"
:
case
"CondClassA"
:
case
"IfClassA"
:
case
"pkg/ClassToBeStaticallyImportedA"
:
case
"SimpleAssignClassB"
:
case
"BinaryExpClassB"
:
case
"UnaryExpClassB"
:
case
"CastClassB"
:
case
"ParensClassB"
:
case
"CondClassB"
:
case
"IfClassB"
:
case
"pkg/ClassToBeStaticallyImportedB"
:
numberOfReferencedClassesToBeChecked
++;
}
}
...
...
@@ -76,59 +81,111 @@ public class CPoolRefClassContainingInlinedCts {
}
i
+=
cpInfo
.
size
();
}
if
(
numberOfReferencedClassesToBeChecked
!=
8
)
{
if
(
numberOfReferencedClassesToBeChecked
!=
16
)
{
throw
new
AssertionError
(
"Class reference missing in the constant pool"
);
}
}
private
int
assign
=
SimpleAssignClass
.
x
;
private
int
binary
=
BinaryExpClass
.
x
+
1
;
private
int
unary
=
-
UnaryExpClass
.
x
;
private
int
cast
=
(
int
)
CastClass
.
x
;
private
int
parens
=
(
ParensClass
.
x
);
private
int
cond
=
(
CondClass
.
x
==
1
)
?
1
:
2
;
private
static
int
ifConstant
;
private
static
int
importStatic
;
private
int
assign
A
=
SimpleAssignClassA
.
x
;
private
int
binary
A
=
BinaryExpClassA
.
x
+
1
;
private
int
unary
A
=
-
UnaryExpClassA
.
x
;
private
int
cast
A
=
(
int
)
CastClassA
.
x
;
private
int
parens
A
=
(
ParensClassA
.
x
);
private
int
cond
A
=
(
CondClassA
.
x
==
1
)
?
1
:
2
;
private
static
int
ifConstant
A
;
private
static
int
importStatic
A
;
static
{
if
(
IfClass
.
x
==
1
)
{
ifConstant
=
1
;
if
(
IfClass
A
.
x
==
1
)
{
ifConstant
A
=
1
;
}
else
{
ifConstant
=
2
;
ifConstant
A
=
2
;
}
}
static
{
if
(
staticField
==
1
)
{
importStatic
=
1
;
if
(
staticField
A
==
1
)
{
importStatic
A
=
1
;
}
else
{
importStatic
=
2
;
importStatic
A
=
2
;
}
}
// now as final constants
private
static
final
int
assignB
=
SimpleAssignClassB
.
x
;
private
static
final
int
binaryB
=
BinaryExpClassB
.
x
+
1
;
private
static
final
int
unaryB
=
-
UnaryExpClassB
.
x
;
private
static
final
int
castB
=
(
int
)
CastClassB
.
x
;
private
static
final
int
parensB
=
(
ParensClassB
.
x
);
private
static
final
int
condB
=
(
CondClassB
.
x
==
1
)
?
1
:
2
;
private
static
final
int
ifConstantB
;
private
static
final
int
importStaticB
;
static
{
if
(
IfClassB
.
x
==
1
)
{
ifConstantB
=
1
;
}
else
{
ifConstantB
=
2
;
}
}
static
{
if
(
staticFieldB
==
1
)
{
importStaticB
=
1
;
}
else
{
importStaticB
=
2
;
}
}
}
class
SimpleAssignClassA
{
public
static
final
int
x
=
1
;
}
class
SimpleAssignClassB
{
public
static
final
int
x
=
1
;
}
class
BinaryExpClassA
{
public
static
final
int
x
=
1
;
}
class
BinaryExpClassB
{
public
static
final
int
x
=
1
;
}
class
UnaryExpClassA
{
public
static
final
int
x
=
1
;
}
class
UnaryExpClassB
{
public
static
final
int
x
=
1
;
}
class
CastClassA
{
public
static
final
int
x
=
1
;
}
class
SimpleAssignClass
{
class
CastClassB
{
public
static
final
int
x
=
1
;
}
class
BinaryExpClass
{
class
ParensClassA
{
public
static
final
int
x
=
1
;
}
class
UnaryExpClass
{
class
ParensClassB
{
public
static
final
int
x
=
1
;
}
class
C
astClass
{
class
C
ondClassA
{
public
static
final
int
x
=
1
;
}
class
ParensClass
{
class
CondClassB
{
public
static
final
int
x
=
1
;
}
class
CondClass
{
class
IfClassA
{
public
static
final
int
x
=
1
;
}
class
IfClass
{
class
IfClass
B
{
public
static
final
int
x
=
1
;
}
test/tools/javac/7153958/pkg/ClassToBeStaticallyImported.java
→
test/tools/javac/7153958/pkg/ClassToBeStaticallyImported
A
.java
浏览文件 @
a6055937
/*
* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012,
2015,
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
...
...
@@ -24,6 +24,6 @@
*/
package
pkg
;
public
class
ClassToBeStaticallyImported
{
public
static
final
int
staticField
=
1
;
public
class
ClassToBeStaticallyImported
A
{
public
static
final
int
staticField
A
=
1
;
}
test/tools/javac/7153958/pkg/ClassToBeStaticallyImportedB.java
0 → 100644
浏览文件 @
a6055937
/*
* Copyright (c) 2012, 2015, 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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.
*/
package
pkg
;
public
class
ClassToBeStaticallyImportedB
{
public
static
final
int
staticFieldB
=
1
;
}
test/tools/javac/annotations/neg/AnonSubclass.java
0 → 100644
浏览文件 @
a6055937
/*
* @test /nodynamiccopyright/
* @bug 8028389
* @summary javac should output a proper error message when given something
* like new Object(){} as annotation argument.
*
* @compile/fail/ref=AnonSubclass.out -XDrawDiagnostics AnonSubclass.java
*/
@AnonSubclass
(
new
Object
(){})
@interface
AnonSubclass
{
String
value
();
}
test/tools/javac/annotations/neg/AnonSubclass.out
0 → 100644
浏览文件 @
a6055937
AnonSubclass.java:10:15: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: compiler.misc.anonymous.class: java.lang.Object, java.lang.String)
1 error
test/tools/javac/annotations/neg/pkg/AnonSubclassOnPkg.java
0 → 100644
浏览文件 @
a6055937
/*
* 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.
*/
package
pkg
;
@interface
AnonSubclassOnPkg
{
String
value
();
}
test/tools/javac/annotations/neg/pkg/package-info.java
0 → 100644
浏览文件 @
a6055937
/*
* @test /nodynamiccopyright/
* @bug 8028389
* @summary javac should output a proper error message when given something
* like new Object(){} as annotation argument.
*
* @compile AnonSubclassOnPkg.java
* @compile/fail/ref=package-info.out -XDrawDiagnostics package-info.java
*/
@AnonSubclassOnPkg
(
new
Object
(){})
package
pkg
;
test/tools/javac/annotations/neg/pkg/package-info.out
0 → 100644
浏览文件 @
a6055937
package-info.java:11:20: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: compiler.misc.anonymous.class: java.lang.Object, java.lang.String)
1 error
test/tools/javac/expression/DeeplyChainedNonPolyExpressionTest.java
0 → 100644
浏览文件 @
a6055937
/*
* Copyright (c) 2015, 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 8079613
* @summary Ensure that compiler ascertains a class of patently non-poly expressions as such
* @run main/timeout=10 DeeplyChainedNonPolyExpressionTest
*/
public
class
DeeplyChainedNonPolyExpressionTest
{
static
class
JSO
{
JSO
put
(
String
s
,
Object
y
)
{
return
null
;
}
JSO
put
(
java
.
lang
.
String
x
,
java
.
util
.
Collection
<
String
>
y
)
{
return
null
;
}
JSO
put
(
java
.
lang
.
String
x
,
int
y
)
{
return
null
;
}
JSO
put
(
java
.
lang
.
String
x
,
long
y
)
{
return
null
;
}
JSO
put
(
java
.
lang
.
String
x
,
double
y
)
{
return
null
;
}
JSO
put
(
java
.
lang
.
String
x
,
java
.
util
.
Map
<
String
,
String
>
y
)
{
return
null
;
}
JSO
put
(
java
.
lang
.
String
x
,
boolean
y
)
{
return
null
;
}
}
static
class
JSA
{
JSA
put
(
Object
o
)
{
return
null
;
}
JSA
put
(
int
i
,
Object
x
)
{
return
null
;
}
JSA
put
(
boolean
x
)
{
return
null
;
}
JSA
put
(
int
x
)
{
return
null
;
}
JSA
put
(
int
i
,
int
x
)
{
return
null
;
}
JSA
put
(
int
x
,
boolean
y
)
{
return
null
;
}
JSA
put
(
int
i
,
long
x
)
{
return
null
;
}
JSA
put
(
long
x
)
{
return
null
;
}
JSA
put
(
java
.
util
.
Collection
<
String
>
x
)
{
return
null
;
}
JSA
put
(
int
i
,
java
.
util
.
Collection
<
String
>
x
)
{
return
null
;
}
JSA
put
(
int
i
,
java
.
util
.
Map
<
String
,
String
>
x
)
{
return
null
;
}
JSA
put
(
java
.
util
.
Map
<
String
,
String
>
x
)
{
return
null
;
}
JSA
put
(
int
i
,
double
x
)
{
return
null
;
}
JSA
put
(
double
x
)
{
return
null
;
}
}
public
static
void
main
(
String
[]
args
)
{
}
public
static
void
foo
()
{
new
JSO
()
.
put
(
"s"
,
new
JSA
())
.
put
(
"s"
,
new
JSA
())
.
put
(
"s"
,
new
JSO
()
.
put
(
"s"
,
new
JSO
()
.
put
(
"s"
,
new
JSA
().
put
(
"s"
))
.
put
(
"s"
,
new
JSA
())
.
put
(
"s"
,
new
JSO
()
.
put
(
"s"
,
new
JSO
()
.
put
(
"s"
,
new
JSA
().
put
(
"s"
).
put
(
"s"
))
.
put
(
"s"
,
new
JSA
())
.
put
(
"s"
,
new
JSO
()
.
put
(
"s"
,
new
JSO
()
.
put
(
"s"
,
new
JSA
().
put
(
"s"
).
put
(
"s"
).
put
(
"s"
)
.
put
(
"s"
).
put
(
"s"
).
put
(
"s"
)
.
put
(
"s"
).
put
(
"s"
))
.
put
(
"s"
,
new
JSA
())
.
put
(
"s"
,
new
JSO
()
.
put
(
"s"
,
new
JSO
()
.
put
(
"s"
,
new
JSA
().
put
(
"s"
))
.
put
(
"s"
,
new
JSA
())
)
)
)
)
)
.
put
(
"s"
,
new
JSO
()
.
put
(
"s"
,
new
JSA
().
put
(
"s"
))
.
put
(
"s"
,
new
JSA
())
.
put
(
"s"
,
new
JSO
()
.
put
(
"s"
,
new
JSO
()
.
put
(
"s"
,
new
JSA
().
put
(
"s"
).
put
(
"s"
))
.
put
(
"s"
,
new
JSA
())
.
put
(
"s"
,
new
JSO
()
.
put
(
"s"
,
new
JSO
()
.
put
(
"s"
,
new
JSA
().
put
(
"s"
).
put
(
"s"
).
put
(
"s"
)
.
put
(
"s"
).
put
(
"s"
).
put
(
"s"
)
.
put
(
"s"
).
put
(
"s"
))
.
put
(
"s"
,
new
JSA
())
.
put
(
"s"
,
new
JSO
()
.
put
(
"s"
,
new
JSO
()
.
put
(
"s"
,
new
JSA
().
put
(
"s"
))
.
put
(
"s"
,
new
JSA
()))
)
)
)
)
)
)
)
)
);
}
}
test/tools/javac/scope/RemoveSymbolTest.java
0 → 100644
浏览文件 @
a6055937
/*
* Copyright (c) 2015, 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 8080842
* @summary Ensure Scope impl can cope with remove() when a field and method share the name.
* @run main RemoveSymbolTest
*/
import
java.util.Iterator
;
import
java.util.LinkedList
;
public
class
RemoveSymbolTest
<
W
>
implements
Iterable
<
W
>
{
static
class
Widget
{
private
String
name
;
Widget
(
String
s
)
{
name
=
s
;
}
@Override
public
String
toString
()
{
return
name
;
}
}
private
LinkedList
<
W
>
data
;
// Instantiate an Iterable instance using a Lambda expression.
// Causes ClassFormatError if a local variable of type Widget is named after one of the methods.
private
final
Iterable
<
W
>
myIterator1
=
()
->
new
Iterator
<
W
>()
{
private
W
hasNext
=
null
;
private
int
index
=
0
;
@Override
public
boolean
hasNext
()
{
return
index
<
data
.
size
();
}
@Override
public
W
next
()
{
return
data
.
get
(
index
++);
}
};
// Instantiate an Iterable instance using an anonymous class.
// Always works fine regardless of the name of the local variable.
private
final
Iterable
<
W
>
myIterator2
=
new
Iterable
<
W
>()
{
@Override
public
Iterator
<
W
>
iterator
()
{
return
new
Iterator
<
W
>()
{
private
W
hasNext
=
null
;
private
int
index
=
0
;
@Override
public
boolean
hasNext
()
{
return
index
<
data
.
size
();
}
@Override
public
W
next
()
{
return
data
.
get
(
index
++);
}
};
}
};
public
RemoveSymbolTest
()
{
data
=
new
LinkedList
<>();
}
public
void
add
(
W
e
)
{
data
.
add
(
e
);
}
@Override
public
String
toString
()
{
return
data
.
toString
();
}
@Override
public
Iterator
<
W
>
iterator
()
{
return
myIterator1
.
iterator
();
}
public
static
void
main
(
String
[]
args
)
{
RemoveSymbolTest
<
Widget
>
widgets
=
new
RemoveSymbolTest
<>();
widgets
.
add
(
new
Widget
(
"W1"
));
widgets
.
add
(
new
Widget
(
"W2"
));
widgets
.
add
(
new
Widget
(
"W3"
));
System
.
out
.
println
(
".foreach() call: "
);
widgets
.
forEach
(
w
->
System
.
out
.
println
(
w
+
" "
));
}
}
test/tools/javac/scope/RemoveSymbolUnitTest.java
0 → 100644
浏览文件 @
a6055937
/*
* Copyright (c) 2015 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 8080842
* @summary Ensure Scope impl can cope with remove() when a field and method share the name.
*/
import
com.sun.tools.javac.util.*
;
import
com.sun.tools.javac.code.*
;
import
com.sun.tools.javac.code.Scope.*
;
import
com.sun.tools.javac.code.Symbol.*
;
import
com.sun.tools.javac.file.JavacFileManager
;
public
class
RemoveSymbolUnitTest
{
Context
context
;
Names
names
;
Symtab
symtab
;
public
static
void
main
(
String
...
args
)
throws
Exception
{
new
RemoveSymbolUnitTest
().
run
();
}
public
void
run
()
{
context
=
new
Context
();
JavacFileManager
.
preRegister
(
context
);
// required by ClassReader which is required by Symtab
names
=
Names
.
instance
(
context
);
symtab
=
Symtab
.
instance
(
context
);
Name
hasNext
=
names
.
fromString
(
"hasNext"
);
ClassSymbol
clazz
=
new
ClassSymbol
(
0
,
names
.
fromString
(
"X"
),
Type
.
noType
,
symtab
.
unnamedPackage
);
VarSymbol
v
=
new
VarSymbol
(
0
,
hasNext
,
Type
.
noType
,
clazz
);
MethodSymbol
m
=
new
MethodSymbol
(
0
,
hasNext
,
Type
.
noType
,
clazz
);
// Try enter and remove in different shuffled combinations.
// working with fresh scope each time.
Scope
cs
=
new
Scope
(
clazz
);
cs
.
enter
(
v
);
cs
.
enter
(
m
);
cs
.
remove
(
v
);
Symbol
s
=
cs
.
lookup
(
hasNext
).
sym
;
if
(
s
!=
m
)
throw
new
AssertionError
(
"Wrong symbol"
);
cs
=
new
Scope
(
clazz
);
cs
.
enter
(
m
);
cs
.
enter
(
v
);
cs
.
remove
(
v
);
s
=
cs
.
lookup
(
hasNext
).
sym
;
if
(
s
!=
m
)
throw
new
AssertionError
(
"Wrong symbol"
);
cs
=
new
Scope
(
clazz
);
cs
.
enter
(
v
);
cs
.
enter
(
m
);
cs
.
remove
(
m
);
s
=
cs
.
lookup
(
hasNext
).
sym
;
if
(
s
!=
v
)
throw
new
AssertionError
(
"Wrong symbol"
);
cs
=
new
Scope
(
clazz
);
cs
.
enter
(
m
);
cs
.
enter
(
v
);
cs
.
remove
(
m
);
s
=
cs
.
lookup
(
hasNext
).
sym
;
if
(
s
!=
v
)
throw
new
AssertionError
(
"Wrong symbol"
);
}
}
test/tools/javac/types/ScopeListenerTest.java
0 → 100644
浏览文件 @
a6055937
/*
* Copyright (c) 2015, 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 8039262
* @summary Ensure that using Types.membersClosure does not increase the number of listeners on the
* class's members Scope.
*/
import
com.sun.tools.javac.code.Scope
;
import
com.sun.tools.javac.code.Symbol
;
import
com.sun.tools.javac.code.Symtab
;
import
com.sun.tools.javac.code.Types
;
import
com.sun.tools.javac.file.JavacFileManager
;
import
com.sun.tools.javac.util.Context
;
import
com.sun.tools.javac.util.Names
;
import
java.lang.reflect.Field
;
import
java.util.Collection
;
public
class
ScopeListenerTest
{
public
static
void
main
(
String
[]
args
)
throws
Exception
{
new
ScopeListenerTest
().
run
();
}
void
run
()
throws
Exception
{
Context
context
=
new
Context
();
JavacFileManager
.
preRegister
(
context
);
Types
types
=
Types
.
instance
(
context
);
Symtab
syms
=
Symtab
.
instance
(
context
);
Names
names
=
Names
.
instance
(
context
);
types
.
membersClosure
(
syms
.
stringType
,
true
);
types
.
membersClosure
(
syms
.
stringType
,
false
);
Field
listenersField
=
Scope
.
class
.
getDeclaredField
(
"listeners"
);
listenersField
.
setAccessible
(
true
);
int
listenerCount
=
((
Collection
)
listenersField
.
get
(
syms
.
stringType
.
tsym
.
members
())).
size
();
for
(
int
i
=
0
;
i
<
100
;
i
++)
{
types
.
membersClosure
(
syms
.
stringType
,
true
);
types
.
membersClosure
(
syms
.
stringType
,
false
);
}
int
newListenerCount
=
((
Collection
)
listenersField
.
get
(
syms
.
stringType
.
tsym
.
members
())).
size
();
if
(
listenerCount
!=
newListenerCount
)
{
throw
new
AssertionError
(
"Orig listener count: "
+
listenerCount
+
"; new listener count: "
+
newListenerCount
);
}
for
(
Symbol
s
:
types
.
membersClosure
(
syms
.
stringType
,
true
).
getElements
())
;
for
(
Symbol
s
:
types
.
membersClosure
(
syms
.
stringType
,
false
).
getElementsByName
(
names
.
fromString
(
"substring"
)))
;
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录