Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_langtools
提交
f1f97dad
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看板
提交
f1f97dad
编写于
5月 27, 2014
作者:
D
dlsmith
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
8042338: Refactor Types.upperBound to treat wildcards and variables separately
Reviewed-by: vromero
上级
06a965cc
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
63 addition
and
100 deletion
+63
-100
src/share/classes/com/sun/tools/javac/api/JavacTrees.java
src/share/classes/com/sun/tools/javac/api/JavacTrees.java
+1
-1
src/share/classes/com/sun/tools/javac/code/Types.java
src/share/classes/com/sun/tools/javac/code/Types.java
+54
-91
src/share/classes/com/sun/tools/javac/comp/Attr.java
src/share/classes/com/sun/tools/javac/comp/Attr.java
+2
-2
src/share/classes/com/sun/tools/javac/comp/Check.java
src/share/classes/com/sun/tools/javac/comp/Check.java
+2
-2
src/share/classes/com/sun/tools/javac/comp/Lower.java
src/share/classes/com/sun/tools/javac/comp/Lower.java
+2
-2
src/share/classes/com/sun/tools/javac/comp/Resolve.java
src/share/classes/com/sun/tools/javac/comp/Resolve.java
+2
-2
未找到文件。
src/share/classes/com/sun/tools/javac/api/JavacTrees.java
浏览文件 @
f1f97dad
...
...
@@ -407,7 +407,7 @@ public class JavacTrees extends DocTrees {
paramTypes
=
lb
.
toList
();
}
ClassSymbol
sym
=
(
ClassSymbol
)
types
.
u
pperBound
(
tsym
.
type
).
tsym
;
ClassSymbol
sym
=
(
ClassSymbol
)
types
.
cvarU
pperBound
(
tsym
.
type
).
tsym
;
Symbol
msym
=
(
memberName
==
sym
.
name
)
?
findConstructor
(
sym
,
paramTypes
)
...
...
src/share/classes/com/sun/tools/javac/code/Types.java
浏览文件 @
f1f97dad
...
...
@@ -122,37 +122,34 @@ public class Types {
}
// </editor-fold>
// <editor-fold defaultstate="collapsed" desc="upperBound">
/**
* The "rvalue conversion".<br>
* The upper bound of most types is the type
* itself. Wildcards, on the other hand have upper
* and lower bounds.
* @param t a type
* @return the upper bound of the given type
*/
public
Type
upperBound
(
Type
t
)
{
return
upperBound
.
visit
(
t
).
unannotatedType
();
}
// where
private
final
MapVisitor
<
Void
>
upperBound
=
new
MapVisitor
<
Void
>()
{
// <editor-fold defaultstate="collapsed" desc="bounds">
/**
* Get a wildcard's upper bound, returning non-wildcards unchanged.
* @param t a type argument, either a wildcard or a type
*/
public
Type
wildUpperBound
(
Type
t
)
{
if
(
t
.
hasTag
(
WILDCARD
))
{
WildcardType
w
=
(
WildcardType
)
t
.
unannotatedType
();
if
(
w
.
isSuperBound
())
return
w
.
bound
==
null
?
syms
.
objectType
:
w
.
bound
.
bound
;
else
return
wildUpperBound
(
w
.
type
);
}
else
return
t
;
}
/**
* Get a capture variable's upper bound, returning other types unchanged.
* @param t a type
*/
public
Type
cvarUpperBound
(
Type
t
)
{
if
(
t
.
hasTag
(
TYPEVAR
))
{
TypeVar
v
=
(
TypeVar
)
t
.
unannotatedType
();
return
v
.
isCaptured
()
?
cvarUpperBound
(
v
.
bound
)
:
v
;
}
else
return
t
;
}
@Override
public
Type
visitWildcardType
(
WildcardType
t
,
Void
ignored
)
{
if
(
t
.
isSuperBound
())
return
t
.
bound
==
null
?
syms
.
objectType
:
t
.
bound
.
bound
;
else
return
visit
(
t
.
type
);
}
@Override
public
Type
visitCapturedType
(
CapturedType
t
,
Void
ignored
)
{
return
visit
(
t
.
bound
);
}
};
// </editor-fold>
// <editor-fold defaultstate="collapsed" desc="wildLowerBound">
/**
* Get a wildcard's lower bound, returning non-wildcards unchanged.
* @param t a type argument, either a wildcard or a type
...
...
@@ -164,9 +161,7 @@ public class Types {
}
else
return
t
;
}
// </editor-fold>
// <editor-fold defaultstate="collapsed" desc="cvarLowerBound">
/**
* Get a capture variable's lower bound, returning other types unchanged.
* @param t a type
...
...
@@ -904,7 +899,7 @@ public class Types {
syms
.
boundClass
);
changed
=
true
;
}
else
if
(
s
!=
orig
)
{
s
=
new
WildcardType
(
u
pperBound
(
s
),
s
=
new
WildcardType
(
wildU
pperBound
(
s
),
BoundKind
.
EXTENDS
,
syms
.
boundClass
);
changed
=
true
;
...
...
@@ -1113,7 +1108,7 @@ public class Types {
//check that u == t, where u has been set by Type.withTypeVar
return
s
.
isSuperBound
()
&&
!
s
.
isExtendsBound
()
&&
visit
(
t
,
u
pperBound
(
s
));
visit
(
t
,
wildU
pperBound
(
s
));
}
}
default
:
...
...
@@ -1140,7 +1135,7 @@ public class Types {
return
visit
(
s
,
t
);
if
(
s
.
isSuperBound
()
&&
!
s
.
isExtendsBound
())
return
visit
(
t
,
u
pperBound
(
s
))
&&
visit
(
t
,
wildLowerBound
(
s
));
return
visit
(
t
,
wildU
pperBound
(
s
))
&&
visit
(
t
,
wildLowerBound
(
s
));
if
(
t
.
isCompound
()
&&
s
.
isCompound
())
{
if
(!
visit
(
supertype
(
t
),
supertype
(
s
)))
...
...
@@ -1290,7 +1285,7 @@ public class Types {
switch
(
wt
.
kind
)
{
case
UNBOUND:
//similar to ? extends Object
case
EXTENDS:
{
Type
bound
=
u
pperBound
(
s
);
Type
bound
=
wildU
pperBound
(
s
);
undetvar
.
addBound
(
InferenceBound
.
UPPER
,
bound
,
this
);
break
;
}
...
...
@@ -1351,28 +1346,6 @@ public class Types {
// where
private
TypeRelation
containsType
=
new
TypeRelation
()
{
private
Type
U
(
Type
t
)
{
while
(
t
.
hasTag
(
WILDCARD
))
{
WildcardType
w
=
(
WildcardType
)
t
.
unannotatedType
();
if
(
w
.
isSuperBound
())
return
w
.
bound
==
null
?
syms
.
objectType
:
w
.
bound
.
bound
;
else
t
=
w
.
type
;
}
return
t
;
}
private
Type
L
(
Type
t
)
{
while
(
t
.
hasTag
(
WILDCARD
))
{
WildcardType
w
=
(
WildcardType
)
t
.
unannotatedType
();
if
(
w
.
isExtendsBound
())
return
syms
.
botType
;
else
t
=
w
.
type
;
}
return
t
;
}
public
Boolean
visitType
(
Type
t
,
Type
s
)
{
if
(
s
.
isPartial
())
return
containedBy
(
s
,
t
);
...
...
@@ -1384,13 +1357,13 @@ public class Types {
// System.err.println();
// System.err.format(" does %s contain %s?%n", t, s);
// System.err.format(" %s U(%s) <: U(%s) %s = %s%n",
//
upperBound(s), s, t, U
(t),
//
wildUpperBound(s), s, t, wildUpperBound
(t),
// t.isSuperBound()
// || isSubtypeNoCapture(
upperBound(s), U
(t)));
// || isSubtypeNoCapture(
wildUpperBound(s), wildUpperBound
(t)));
// System.err.format(" %s L(%s) <: L(%s) %s = %s%n",
//
L
(t), t, s, wildLowerBound(s),
//
wildLowerBound
(t), t, s, wildLowerBound(s),
// t.isExtendsBound()
// || isSubtypeNoCapture(
L
(t), wildLowerBound(s)));
// || isSubtypeNoCapture(
wildLowerBound
(t), wildLowerBound(s)));
// System.err.println();
// }
...
...
@@ -1402,8 +1375,9 @@ public class Types {
// debugContainsType(t, s);
return
isSameWildcard
(
t
,
s
)
||
isCaptureOf
(
s
,
t
)
||
((
t
.
isExtendsBound
()
||
isSubtypeNoCapture
(
L
(
t
),
wildLowerBound
(
s
)))
&&
(
t
.
isSuperBound
()
||
isSubtypeNoCapture
(
upperBound
(
s
),
U
(
t
))));
||
((
t
.
isExtendsBound
()
||
isSubtypeNoCapture
(
wildLowerBound
(
t
),
wildLowerBound
(
s
)))
&&
// TODO: JDK-8039214, cvarUpperBound call here is incorrect
(
t
.
isSuperBound
()
||
isSubtypeNoCapture
(
cvarUpperBound
(
wildUpperBound
(
s
)),
wildUpperBound
(
t
))));
}
}
...
...
@@ -1521,7 +1495,7 @@ public class Types {
@Override
public
Boolean
visitWildcardType
(
WildcardType
t
,
Type
s
)
{
return
isCastable
(
u
pperBound
(
t
),
s
,
warnStack
.
head
);
return
isCastable
(
wildU
pperBound
(
t
),
s
,
warnStack
.
head
);
}
@Override
...
...
@@ -1762,12 +1736,12 @@ public class Types {
if
(
t
.
isExtendsBound
())
{
if
(
s
.
isExtendsBound
())
return
!
isCastableRecursive
(
t
.
type
,
u
pperBound
(
s
));
return
!
isCastableRecursive
(
t
.
type
,
wildU
pperBound
(
s
));
else
if
(
s
.
isSuperBound
())
return
notSoftSubtypeRecursive
(
wildLowerBound
(
s
),
t
.
type
);
}
else
if
(
t
.
isSuperBound
())
{
if
(
s
.
isExtendsBound
())
return
notSoftSubtypeRecursive
(
t
.
type
,
u
pperBound
(
s
));
return
notSoftSubtypeRecursive
(
t
.
type
,
wildU
pperBound
(
s
));
}
return
false
;
}
...
...
@@ -1803,7 +1777,7 @@ public class Types {
noWarnings
);
}
if
(!
s
.
hasTag
(
WILDCARD
))
s
=
u
pperBound
(
s
);
s
=
cvarU
pperBound
(
s
);
return
!
isSubtype
(
t
,
relaxBound
(
s
));
}
...
...
@@ -1860,7 +1834,7 @@ public class Types {
// <editor-fold defaultstate="collapsed" desc="Array Utils">
public
boolean
isArray
(
Type
t
)
{
while
(
t
.
hasTag
(
WILDCARD
))
t
=
u
pperBound
(
t
);
t
=
wildU
pperBound
(
t
);
return
t
.
hasTag
(
ARRAY
);
}
...
...
@@ -1870,7 +1844,7 @@ public class Types {
public
Type
elemtype
(
Type
t
)
{
switch
(
t
.
getTag
())
{
case
WILDCARD:
return
elemtype
(
u
pperBound
(
t
));
return
elemtype
(
wildU
pperBound
(
t
));
case
ARRAY:
t
=
t
.
unannotatedType
();
return
((
ArrayType
)
t
).
elemtype
;
...
...
@@ -2073,7 +2047,7 @@ public class Types {
@Override
public
Type
visitWildcardType
(
WildcardType
t
,
Symbol
sym
)
{
return
memberType
(
u
pperBound
(
t
),
sym
);
return
memberType
(
wildU
pperBound
(
t
),
sym
);
}
@Override
...
...
@@ -2192,7 +2166,7 @@ public class Types {
@Override
public
Type
visitWildcardType
(
WildcardType
t
,
Boolean
recurse
)
{
return
erasure
(
u
pperBound
(
t
),
recurse
);
return
erasure
(
wildU
pperBound
(
t
),
recurse
);
}
@Override
...
...
@@ -2401,8 +2375,7 @@ public class Types {
if
(
t
.
hasErasedSupertypes
())
{
t
.
interfaces_field
=
erasureRecursive
(
interfaces
);
}
else
if
(
formals
.
nonEmpty
())
{
t
.
interfaces_field
=
upperBounds
(
subst
(
interfaces
,
formals
,
actuals
));
t
.
interfaces_field
=
subst
(
interfaces
,
formals
,
actuals
);
}
else
{
t
.
interfaces_field
=
interfaces
;
...
...
@@ -2971,7 +2944,7 @@ public class Types {
return
new
ClassType
(
outer1
,
typarams1
,
t
.
tsym
);
}
else
{
Type
st
=
subst
(
supertype
(
t
));
List
<
Type
>
is
=
upperBounds
(
subst
(
interfaces
(
t
)
));
List
<
Type
>
is
=
subst
(
interfaces
(
t
));
if
(
st
==
supertype
(
t
)
&&
is
==
interfaces
(
t
))
return
t
;
else
...
...
@@ -2988,7 +2961,7 @@ public class Types {
return
t
;
}
else
{
if
(
t
.
isExtendsBound
()
&&
bound
.
isExtendsBound
())
bound
=
u
pperBound
(
bound
);
bound
=
wildU
pperBound
(
bound
);
return
new
WildcardType
(
bound
,
t
.
kind
,
syms
.
boundClass
,
t
.
bound
);
}
}
...
...
@@ -3438,8 +3411,8 @@ public class Types {
TypePair
pair
=
new
TypePair
(
c1
,
c2
);
Type
m
;
if
(
mergeCache
.
add
(
pair
))
{
m
=
new
WildcardType
(
lub
(
u
pperBound
(
act1
.
head
),
u
pperBound
(
act2
.
head
)),
m
=
new
WildcardType
(
lub
(
wildU
pperBound
(
act1
.
head
),
wildU
pperBound
(
act2
.
head
)),
BoundKind
.
EXTENDS
,
syms
.
boundClass
);
mergeCache
.
remove
(
pair
);
...
...
@@ -4015,16 +3988,6 @@ public class Types {
// </editor-fold>
// <editor-fold defaultstate="collapsed" desc="Internal utility methods">
private
List
<
Type
>
upperBounds
(
List
<
Type
>
ss
)
{
if
(
ss
.
isEmpty
())
return
ss
;
Type
head
=
upperBound
(
ss
.
head
);
List
<
Type
>
tail
=
upperBounds
(
ss
.
tail
);
if
(
head
!=
ss
.
head
||
tail
!=
ss
.
tail
)
return
tail
.
prepend
(
head
);
else
return
ss
;
}
private
boolean
sideCast
(
Type
from
,
Type
to
,
Warner
warn
)
{
// We are casting from type $from$ to type $to$, which are
// non-final unrelated types. This method
...
...
@@ -4181,7 +4144,7 @@ public class Types {
@Override
public
Void
visitWildcardType
(
WildcardType
source
,
Type
target
)
throws
AdaptFailure
{
if
(
source
.
isExtendsBound
())
adaptRecursive
(
upperBound
(
source
),
u
pperBound
(
target
));
adaptRecursive
(
wildUpperBound
(
source
),
wildU
pperBound
(
target
));
else
if
(
source
.
isSuperBound
())
adaptRecursive
(
wildLowerBound
(
source
),
wildLowerBound
(
target
));
return
null
;
...
...
@@ -4198,7 +4161,7 @@ public class Types {
val
=
isSubtype
(
wildLowerBound
(
val
),
wildLowerBound
(
target
))
?
target
:
val
;
}
else
if
(
val
.
isExtendsBound
()
&&
target
.
isExtendsBound
())
{
val
=
isSubtype
(
upperBound
(
val
),
u
pperBound
(
target
))
val
=
isSubtype
(
wildUpperBound
(
val
),
wildU
pperBound
(
target
))
?
val
:
target
;
}
else
if
(!
isSameType
(
val
,
target
))
{
throw
new
AdaptFailure
();
...
...
@@ -4309,7 +4272,7 @@ public class Types {
}
public
Type
visitType
(
Type
t
,
Void
s
)
{
return
high
?
upperBound
(
t
)
:
t
;
return
t
;
}
@Override
...
...
src/share/classes/com/sun/tools/javac/comp/Attr.java
浏览文件 @
f1f97dad
...
...
@@ -1175,7 +1175,7 @@ public class Attr extends JCTree.Visitor {
//the Formal Parameter of a for-each loop is not in the scope when
//attributing the for-each expression; we mimick this by attributing
//the for-each expression first (against original scope).
Type
exprType
=
types
.
u
pperBound
(
attribExpr
(
tree
.
expr
,
loopEnv
));
Type
exprType
=
types
.
cvarU
pperBound
(
attribExpr
(
tree
.
expr
,
loopEnv
));
attribStat
(
tree
.
var
,
loopEnv
);
chk
.
checkNonVoid
(
tree
.
pos
(),
exprType
);
Type
elemtype
=
types
.
elemtype
(
exprType
);
// perhaps expr is an array?
...
...
@@ -1192,7 +1192,7 @@ public class Attr extends JCTree.Visitor {
List
<
Type
>
iterableParams
=
base
.
allparams
();
elemtype
=
iterableParams
.
isEmpty
()
?
syms
.
objectType
:
types
.
u
pperBound
(
iterableParams
.
head
);
:
types
.
wildU
pperBound
(
iterableParams
.
head
);
}
}
chk
.
checkType
(
tree
.
expr
.
pos
(),
elemtype
,
tree
.
var
.
sym
.
type
);
...
...
src/share/classes/com/sun/tools/javac/comp/Check.java
浏览文件 @
f1f97dad
...
...
@@ -618,10 +618,10 @@ public class Check {
if
(
a
.
isUnbound
())
{
return
true
;
}
else
if
(!
a
.
hasTag
(
WILDCARD
))
{
a
=
types
.
u
pperBound
(
a
);
a
=
types
.
cvarU
pperBound
(
a
);
return
types
.
isSubtype
(
a
,
bound
);
}
else
if
(
a
.
isExtendsBound
())
{
return
types
.
isCastable
(
bound
,
types
.
u
pperBound
(
a
),
types
.
noWarnings
);
return
types
.
isCastable
(
bound
,
types
.
wildU
pperBound
(
a
),
types
.
noWarnings
);
}
else
if
(
a
.
isSuperBound
())
{
return
!
types
.
notSoftSubtype
(
types
.
wildLowerBound
(
a
),
bound
);
}
...
...
src/share/classes/com/sun/tools/javac/comp/Lower.java
浏览文件 @
f1f97dad
...
...
@@ -3472,7 +3472,7 @@ public class Lower extends TreeTranslator {
private
void
visitIterableForeachLoop
(
JCEnhancedForLoop
tree
)
{
make_at
(
tree
.
expr
.
pos
());
Type
iteratorTarget
=
syms
.
objectType
;
Type
iterableType
=
types
.
asSuper
(
types
.
u
pperBound
(
tree
.
expr
.
type
),
Type
iterableType
=
types
.
asSuper
(
types
.
cvarU
pperBound
(
tree
.
expr
.
type
),
syms
.
iterableType
.
tsym
);
if
(
iterableType
.
getTypeArguments
().
nonEmpty
())
iteratorTarget
=
types
.
erasure
(
iterableType
.
getTypeArguments
().
head
);
...
...
@@ -3506,7 +3506,7 @@ public class Lower extends TreeTranslator {
List
.<
Type
>
nil
());
JCExpression
vardefinit
=
make
.
App
(
make
.
Select
(
make
.
Ident
(
itvar
),
next
));
if
(
tree
.
var
.
type
.
isPrimitive
())
vardefinit
=
make
.
TypeCast
(
types
.
u
pperBound
(
iteratorTarget
),
vardefinit
);
vardefinit
=
make
.
TypeCast
(
types
.
cvarU
pperBound
(
iteratorTarget
),
vardefinit
);
else
vardefinit
=
make
.
TypeCast
(
tree
.
var
.
type
,
vardefinit
);
JCVariableDecl
indexDef
=
(
JCVariableDecl
)
make
.
VarDef
(
tree
.
var
.
mods
,
...
...
src/share/classes/com/sun/tools/javac/comp/Resolve.java
浏览文件 @
f1f97dad
...
...
@@ -348,7 +348,7 @@ public class Resolve {
boolean
isAccessible
(
Env
<
AttrContext
>
env
,
Type
t
,
boolean
checkInner
)
{
return
(
t
.
hasTag
(
ARRAY
))
?
isAccessible
(
env
,
types
.
u
pperBound
(
types
.
elemtype
(
t
)))
?
isAccessible
(
env
,
types
.
cvarU
pperBound
(
types
.
elemtype
(
t
)))
:
isAccessible
(
env
,
t
.
tsym
,
checkInner
);
}
...
...
@@ -1011,7 +1011,7 @@ public class Resolve {
*/
private
Type
U
(
Type
found
)
{
return
found
==
pt
?
found
:
types
.
u
pperBound
(
found
);
found
:
types
.
cvarU
pperBound
(
found
);
}
@Override
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录