Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_langtools
提交
5f1c7194
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看板
提交
5f1c7194
编写于
3月 07, 2013
作者:
V
vromero
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
8009138: javac, equals-hashCode warning tuning
Reviewed-by: mcimadamore
上级
b7bf3363
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
99 addition
and
8 deletion
+99
-8
src/share/classes/com/sun/tools/javac/code/Symbol.java
src/share/classes/com/sun/tools/javac/code/Symbol.java
+1
-1
src/share/classes/com/sun/tools/javac/code/Symtab.java
src/share/classes/com/sun/tools/javac/code/Symtab.java
+2
-0
src/share/classes/com/sun/tools/javac/comp/Attr.java
src/share/classes/com/sun/tools/javac/comp/Attr.java
+1
-1
src/share/classes/com/sun/tools/javac/comp/Check.java
src/share/classes/com/sun/tools/javac/comp/Check.java
+21
-3
src/share/classes/com/sun/tools/javac/resources/compiler.properties
...classes/com/sun/tools/javac/resources/compiler.properties
+1
-1
test/tools/javac/6563143/EqualsHashCodeWarningTest.java
test/tools/javac/6563143/EqualsHashCodeWarningTest.java
+71
-0
test/tools/javac/6563143/EqualsHashCodeWarningTest.out
test/tools/javac/6563143/EqualsHashCodeWarningTest.out
+2
-0
test/tools/javac/6563143/OverridesEqualsButNotHashCodeTest.out
...tools/javac/6563143/OverridesEqualsButNotHashCodeTest.out
+0
-2
未找到文件。
src/share/classes/com/sun/tools/javac/code/Symbol.java
浏览文件 @
5f1c7194
...
...
@@ -237,7 +237,7 @@ public abstract class Symbol implements Element {
}
/** Has this symbol an empty name? This includes anonymous
* inner class
s
es.
* inner classes.
*/
public
boolean
isAnonymous
()
{
return
name
.
isEmpty
();
...
...
src/share/classes/com/sun/tools/javac/code/Symtab.java
浏览文件 @
5f1c7194
...
...
@@ -148,6 +148,7 @@ public class Symtab {
public
final
Type
listType
;
public
final
Type
collectionsType
;
public
final
Type
comparableType
;
public
final
Type
comparatorType
;
public
final
Type
arraysType
;
public
final
Type
iterableType
;
public
final
Type
iteratorType
;
...
...
@@ -502,6 +503,7 @@ public class Symtab {
listType
=
enterClass
(
"java.util.List"
);
collectionsType
=
enterClass
(
"java.util.Collections"
);
comparableType
=
enterClass
(
"java.lang.Comparable"
);
comparatorType
=
enterClass
(
"java.util.Comparator"
);
arraysType
=
enterClass
(
"java.util.Arrays"
);
iterableType
=
target
.
hasIterable
()
?
enterClass
(
"java.lang.Iterable"
)
...
...
src/share/classes/com/sun/tools/javac/comp/Attr.java
浏览文件 @
5f1c7194
...
...
@@ -4016,7 +4016,7 @@ public class Attr extends JCTree.Visitor {
attribClassBody
(
env
,
c
);
chk
.
checkDeprecatedAnnotation
(
env
.
tree
.
pos
(),
c
);
chk
.
checkClassOverrideEqualsAndHash
(
env
.
tree
.
pos
(),
c
);
chk
.
checkClassOverrideEqualsAndHash
IfNeeded
(
env
.
tree
.
pos
(),
c
);
}
finally
{
env
.
info
.
returnResult
=
prevReturnRes
;
log
.
useSource
(
prev
);
...
...
src/share/classes/com/sun/tools/javac/comp/Check.java
浏览文件 @
5f1c7194
...
...
@@ -1972,14 +1972,32 @@ public class Check {
}
};
public
void
checkClassOverrideEqualsAndHash
(
DiagnosticPosition
pos
,
public
void
checkClassOverrideEqualsAndHashIfNeeded
(
DiagnosticPosition
pos
,
ClassSymbol
someClass
)
{
/* At present, annotations cannot possibly have a method that is override
* equivalent with Object.equals(Object) but in any case the condition is
* fine for completeness.
*/
if
(
someClass
==
(
ClassSymbol
)
syms
.
objectType
.
tsym
||
someClass
.
isInterface
()
||
someClass
.
isEnum
()
||
(
someClass
.
flags
()
&
ANNOTATION
)
!=
0
||
(
someClass
.
flags
()
&
ABSTRACT
)
!=
0
)
return
;
//anonymous inner classes implementing interfaces need especial treatment
if
(
someClass
.
isAnonymous
())
{
List
<
Type
>
interfaces
=
types
.
interfaces
(
someClass
.
type
);
if
(
interfaces
!=
null
&&
!
interfaces
.
isEmpty
()
&&
interfaces
.
head
.
tsym
==
syms
.
comparatorType
.
tsym
)
return
;
}
checkClassOverrideEqualsAndHash
(
pos
,
someClass
);
}
private
void
checkClassOverrideEqualsAndHash
(
DiagnosticPosition
pos
,
ClassSymbol
someClass
)
{
if
(
lint
.
isEnabled
(
LintCategory
.
OVERRIDES
))
{
MethodSymbol
equalsAtObject
=
(
MethodSymbol
)
syms
.
objectType
.
tsym
.
members
().
lookup
(
names
.
equals
).
sym
;
MethodSymbol
hashCodeAtObject
=
(
MethodSymbol
)
syms
.
objectType
.
tsym
.
members
().
lookup
(
names
.
hashCode
).
sym
;
boolean
overridesEquals
=
types
.
implementation
(
equalsAtObject
,
someClass
,
false
,
equalsHasCodeFilter
).
owner
==
someClass
;
boolean
overridesHashCode
=
types
.
implementation
(
hashCodeAtObject
,
...
...
@@ -1987,7 +2005,7 @@ public class Check {
if
(
overridesEquals
&&
!
overridesHashCode
)
{
log
.
warning
(
LintCategory
.
OVERRIDES
,
pos
,
"override.equals.but.not.hashcode"
,
someClass
.
fullname
);
"override.equals.but.not.hashcode"
,
someClass
);
}
}
}
...
...
src/share/classes/com/sun/tools/javac/resources/compiler.properties
浏览文件 @
5f1c7194
...
...
@@ -2077,7 +2077,7 @@ compiler.warn.override.unchecked.thrown=\
{0}
\n\
overridden method does not throw {1}
# 0:
class name
# 0:
symbol
compiler.warn.override.equals.but.not.hashcode
=
\
Class {0} overrides equals, but neither it nor any superclass overrides hashCode method
...
...
test/tools/javac/6563143/
OverridesEqualsButNotHashCode
Test.java
→
test/tools/javac/6563143/
EqualsHashCodeWarning
Test.java
浏览文件 @
5f1c7194
/*
* @test /nodynamiccopyright/
* @bug 6563143 8008436
* @bug 6563143 8008436
8009138
* @summary javac should issue a warning for overriding equals without hashCode
* @summary javac should not issue a warning for overriding equals without hasCode
* @summary javac, equals-hashCode warning tuning
* if hashCode has been overriden by a superclass
* @compile/ref=
OverridesEqualsButNotHashCodeTest.out -Xlint:overrides -XDrawDiagnostics OverridesEqualsButNotHashCode
Test.java
* @compile/ref=
EqualsHashCodeWarningTest.out -Xlint:overrides -XDrawDiagnostics EqualsHashCodeWarning
Test.java
*/
public
class
OverridesEqualsButNotHashCodeTest
{
import
java.util.Comparator
;
public
class
EqualsHashCodeWarningTest
{
@Override
public
boolean
equals
(
Object
o
)
{
return
o
==
this
;
...
...
@@ -17,20 +20,32 @@ public class OverridesEqualsButNotHashCodeTest {
public
int
hashCode
()
{
return
0
;
}
public
Comparator
m
()
{
return
new
Comparator
()
{
@Override
public
boolean
equals
(
Object
o
)
{
return
true
;}
@Override
public
int
compare
(
Object
o1
,
Object
o2
)
{
return
0
;
}
};
}
}
class
SubClass
extends
OverridesEqualsButNotHashCode
Test
{
class
SubClass
extends
EqualsHashCodeWarning
Test
{
@Override
public
boolean
equals
(
Object
o
)
{
return
o
==
this
;
return
true
;
}
}
@SuppressWarnings
(
"overrides"
)
class
NoWarning
{
class
DontWarnMe
{
@Override
public
boolean
equals
(
Object
o
)
{
return
o
==
this
;
return
true
;
}
}
...
...
@@ -40,3 +55,17 @@ class DoWarnMe {
return
o
==
this
;
}
}
abstract
class
IamAbstractGetMeOutOfHere
{
public
boolean
equals
(
Object
o
){
return
true
;}
}
interface
I
{
public
boolean
equals
(
Object
o
);
}
enum
E
{
A
,
B
}
@interface
anno
{}
test/tools/javac/6563143/EqualsHashCodeWarningTest.out
0 → 100644
浏览文件 @
5f1c7194
EqualsHashCodeWarningTest.java:52:1: compiler.warn.override.equals.but.not.hashcode: DoWarnMe
1 warning
test/tools/javac/6563143/OverridesEqualsButNotHashCodeTest.out
已删除
100644 → 0
浏览文件 @
b7bf3363
OverridesEqualsButNotHashCodeTest.java:37:1: compiler.warn.override.equals.but.not.hashcode: DoWarnMe
1 warning
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录