Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_langtools
提交
4b9418e2
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看板
提交
4b9418e2
编写于
7月 26, 2010
作者:
J
jjg
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
6957438: improve code for generating warning messages containing option names
Reviewed-by: mcimadamore
上级
9542ea6d
变更
15
隐藏空白更改
内联
并排
Showing
15 changed file
with
263 addition
and
105 deletion
+263
-105
src/share/classes/com/sun/tools/javac/code/Lint.java
src/share/classes/com/sun/tools/javac/code/Lint.java
+1
-0
src/share/classes/com/sun/tools/javac/comp/Attr.java
src/share/classes/com/sun/tools/javac/comp/Attr.java
+8
-4
src/share/classes/com/sun/tools/javac/comp/Check.java
src/share/classes/com/sun/tools/javac/comp/Check.java
+11
-9
src/share/classes/com/sun/tools/javac/comp/Flow.java
src/share/classes/com/sun/tools/javac/comp/Flow.java
+7
-4
src/share/classes/com/sun/tools/javac/comp/Resolve.java
src/share/classes/com/sun/tools/javac/comp/Resolve.java
+11
-11
src/share/classes/com/sun/tools/javac/file/Paths.java
src/share/classes/com/sun/tools/javac/file/Paths.java
+14
-7
src/share/classes/com/sun/tools/javac/resources/compiler.properties
...classes/com/sun/tools/javac/resources/compiler.properties
+38
-30
src/share/classes/com/sun/tools/javac/util/AbstractDiagnosticFormatter.java
...com/sun/tools/javac/util/AbstractDiagnosticFormatter.java
+8
-0
src/share/classes/com/sun/tools/javac/util/AbstractLog.java
src/share/classes/com/sun/tools/javac/util/AbstractLog.java
+32
-0
src/share/classes/com/sun/tools/javac/util/BasicDiagnosticFormatter.java
...es/com/sun/tools/javac/util/BasicDiagnosticFormatter.java
+8
-7
src/share/classes/com/sun/tools/javac/util/JCDiagnostic.java
src/share/classes/com/sun/tools/javac/util/JCDiagnostic.java
+108
-30
src/share/classes/com/sun/tools/javac/util/MandatoryWarningHandler.java
...ses/com/sun/tools/javac/util/MandatoryWarningHandler.java
+14
-3
test/tools/javac/diags/examples/CountWarn.java
test/tools/javac/diags/examples/CountWarn.java
+1
-0
test/tools/javac/diags/examples/CountWarnPlural.java
test/tools/javac/diags/examples/CountWarnPlural.java
+1
-0
test/tools/javac/diags/examples/Error.java
test/tools/javac/diags/examples/Error.java
+1
-0
未找到文件。
src/share/classes/com/sun/tools/javac/code/Lint.java
浏览文件 @
4b9418e2
...
@@ -119,6 +119,7 @@ public class Lint
...
@@ -119,6 +119,7 @@ public class Lint
this
.
suppressedValues
=
other
.
suppressedValues
.
clone
();
this
.
suppressedValues
=
other
.
suppressedValues
.
clone
();
}
}
@Override
public
String
toString
()
{
public
String
toString
()
{
return
"Lint:[values"
+
values
+
" suppressedValues"
+
suppressedValues
+
"]"
;
return
"Lint:[values"
+
values
+
" suppressedValues"
+
suppressedValues
+
"]"
;
}
}
...
...
src/share/classes/com/sun/tools/javac/comp/Attr.java
浏览文件 @
4b9418e2
...
@@ -3111,7 +3111,8 @@ public class Attr extends JCTree.Visitor {
...
@@ -3111,7 +3111,8 @@ public class Attr extends JCTree.Visitor {
Scope
.
Entry
e
=
c
.
members
().
lookup
(
names
.
serialVersionUID
);
Scope
.
Entry
e
=
c
.
members
().
lookup
(
names
.
serialVersionUID
);
while
(
e
.
scope
!=
null
&&
e
.
sym
.
kind
!=
VAR
)
e
=
e
.
next
();
while
(
e
.
scope
!=
null
&&
e
.
sym
.
kind
!=
VAR
)
e
=
e
.
next
();
if
(
e
.
scope
==
null
)
{
if
(
e
.
scope
==
null
)
{
log
.
warning
(
tree
.
pos
(),
"missing.SVUID"
,
c
);
log
.
warning
(
Lint
.
LintCategory
.
SERIAL
,
tree
.
pos
(),
"missing.SVUID"
,
c
);
return
;
return
;
}
}
...
@@ -3119,15 +3120,18 @@ public class Attr extends JCTree.Visitor {
...
@@ -3119,15 +3120,18 @@ public class Attr extends JCTree.Visitor {
VarSymbol
svuid
=
(
VarSymbol
)
e
.
sym
;
VarSymbol
svuid
=
(
VarSymbol
)
e
.
sym
;
if
((
svuid
.
flags
()
&
(
STATIC
|
FINAL
))
!=
if
((
svuid
.
flags
()
&
(
STATIC
|
FINAL
))
!=
(
STATIC
|
FINAL
))
(
STATIC
|
FINAL
))
log
.
warning
(
TreeInfo
.
diagnosticPositionFor
(
svuid
,
tree
),
"improper.SVUID"
,
c
);
log
.
warning
(
Lint
.
LintCategory
.
SERIAL
,
TreeInfo
.
diagnosticPositionFor
(
svuid
,
tree
),
"improper.SVUID"
,
c
);
// check that it is long
// check that it is long
else
if
(
svuid
.
type
.
tag
!=
TypeTags
.
LONG
)
else
if
(
svuid
.
type
.
tag
!=
TypeTags
.
LONG
)
log
.
warning
(
TreeInfo
.
diagnosticPositionFor
(
svuid
,
tree
),
"long.SVUID"
,
c
);
log
.
warning
(
Lint
.
LintCategory
.
SERIAL
,
TreeInfo
.
diagnosticPositionFor
(
svuid
,
tree
),
"long.SVUID"
,
c
);
// check constant
// check constant
else
if
(
svuid
.
getConstValue
()
==
null
)
else
if
(
svuid
.
getConstValue
()
==
null
)
log
.
warning
(
TreeInfo
.
diagnosticPositionFor
(
svuid
,
tree
),
"constant.SVUID"
,
c
);
log
.
warning
(
Lint
.
LintCategory
.
SERIAL
,
TreeInfo
.
diagnosticPositionFor
(
svuid
,
tree
),
"constant.SVUID"
,
c
);
}
}
private
Type
capture
(
Type
type
)
{
private
Type
capture
(
Type
type
)
{
...
...
src/share/classes/com/sun/tools/javac/comp/Check.java
浏览文件 @
4b9418e2
...
@@ -111,13 +111,13 @@ public class Check {
...
@@ -111,13 +111,13 @@ public class Check {
boolean
enforceMandatoryWarnings
=
source
.
enforceMandatoryWarnings
();
boolean
enforceMandatoryWarnings
=
source
.
enforceMandatoryWarnings
();
deprecationHandler
=
new
MandatoryWarningHandler
(
log
,
verboseDeprecated
,
deprecationHandler
=
new
MandatoryWarningHandler
(
log
,
verboseDeprecated
,
enforceMandatoryWarnings
,
"deprecated"
);
enforceMandatoryWarnings
,
"deprecated"
,
LintCategory
.
DEPRECATION
);
uncheckedHandler
=
new
MandatoryWarningHandler
(
log
,
verboseUnchecked
,
uncheckedHandler
=
new
MandatoryWarningHandler
(
log
,
verboseUnchecked
,
enforceMandatoryWarnings
,
"unchecked"
);
enforceMandatoryWarnings
,
"unchecked"
,
LintCategory
.
UNCHECKED
);
unsafeVarargsHandler
=
new
MandatoryWarningHandler
(
log
,
verboseVarargs
,
unsafeVarargsHandler
=
new
MandatoryWarningHandler
(
log
,
verboseVarargs
,
enforceMandatoryWarnings
,
"varargs"
);
enforceMandatoryWarnings
,
"varargs"
,
LintCategory
.
VARARGS
);
sunApiHandler
=
new
MandatoryWarningHandler
(
log
,
verboseSunApi
,
sunApiHandler
=
new
MandatoryWarningHandler
(
log
,
verboseSunApi
,
enforceMandatoryWarnings
,
"sunapi"
);
enforceMandatoryWarnings
,
"sunapi"
,
null
);
}
}
/** Switch: generics enabled?
/** Switch: generics enabled?
...
@@ -209,7 +209,7 @@ public class Check {
...
@@ -209,7 +209,7 @@ public class Check {
public
void
warnStatic
(
DiagnosticPosition
pos
,
String
msg
,
Object
...
args
)
{
public
void
warnStatic
(
DiagnosticPosition
pos
,
String
msg
,
Object
...
args
)
{
if
(
lint
.
isEnabled
(
LintCategory
.
STATIC
))
if
(
lint
.
isEnabled
(
LintCategory
.
STATIC
))
log
.
warning
(
pos
,
msg
,
args
);
log
.
warning
(
LintCategory
.
STATIC
,
pos
,
msg
,
args
);
}
}
/**
/**
...
@@ -929,7 +929,8 @@ public class Check {
...
@@ -929,7 +929,8 @@ public class Check {
!
TreeInfo
.
isDiamond
(
tree
)
&&
!
TreeInfo
.
isDiamond
(
tree
)
&&
!
env
.
enclClass
.
name
.
isEmpty
()
&&
//anonymous or intersection
!
env
.
enclClass
.
name
.
isEmpty
()
&&
//anonymous or intersection
tree
.
type
.
isRaw
())
{
tree
.
type
.
isRaw
())
{
log
.
warning
(
tree
.
pos
(),
"raw.class.use"
,
tree
.
type
,
tree
.
type
.
tsym
.
type
);
log
.
warning
(
Lint
.
LintCategory
.
RAW
,
tree
.
pos
(),
"raw.class.use"
,
tree
.
type
,
tree
.
type
.
tsym
.
type
);
}
}
}
}
...
@@ -2156,7 +2157,8 @@ public class Check {
...
@@ -2156,7 +2157,8 @@ public class Check {
(
s
.
flags
()
&
DEPRECATED
)
!=
0
&&
(
s
.
flags
()
&
DEPRECATED
)
!=
0
&&
!
syms
.
deprecatedType
.
isErroneous
()
&&
!
syms
.
deprecatedType
.
isErroneous
()
&&
s
.
attribute
(
syms
.
deprecatedType
.
tsym
)
==
null
)
{
s
.
attribute
(
syms
.
deprecatedType
.
tsym
)
==
null
)
{
log
.
warning
(
pos
,
"missing.deprecated.annotation"
);
log
.
warning
(
Lint
.
LintCategory
.
DEP_ANN
,
pos
,
"missing.deprecated.annotation"
);
}
}
}
}
...
@@ -2307,7 +2309,7 @@ public class Check {
...
@@ -2307,7 +2309,7 @@ public class Check {
int
opc
=
((
OperatorSymbol
)
operator
).
opcode
;
int
opc
=
((
OperatorSymbol
)
operator
).
opcode
;
if
(
opc
==
ByteCodes
.
idiv
||
opc
==
ByteCodes
.
imod
if
(
opc
==
ByteCodes
.
idiv
||
opc
==
ByteCodes
.
imod
||
opc
==
ByteCodes
.
ldiv
||
opc
==
ByteCodes
.
lmod
)
{
||
opc
==
ByteCodes
.
ldiv
||
opc
==
ByteCodes
.
lmod
)
{
log
.
warning
(
pos
,
"div.zero"
);
log
.
warning
(
Lint
.
LintCategory
.
DIVZERO
,
pos
,
"div.zero"
);
}
}
}
}
}
}
...
@@ -2317,7 +2319,7 @@ public class Check {
...
@@ -2317,7 +2319,7 @@ public class Check {
*/
*/
void
checkEmptyIf
(
JCIf
tree
)
{
void
checkEmptyIf
(
JCIf
tree
)
{
if
(
tree
.
thenpart
.
getTag
()
==
JCTree
.
SKIP
&&
tree
.
elsepart
==
null
&&
lint
.
isEnabled
(
Lint
.
LintCategory
.
EMPTY
))
if
(
tree
.
thenpart
.
getTag
()
==
JCTree
.
SKIP
&&
tree
.
elsepart
==
null
&&
lint
.
isEnabled
(
Lint
.
LintCategory
.
EMPTY
))
log
.
warning
(
tree
.
thenpart
.
pos
(),
"empty.if"
);
log
.
warning
(
Lint
.
LintCategory
.
EMPTY
,
tree
.
thenpart
.
pos
(),
"empty.if"
);
}
}
/** Check that symbol is unique in given scope.
/** Check that symbol is unique in given scope.
...
...
src/share/classes/com/sun/tools/javac/comp/Flow.java
浏览文件 @
4b9418e2
...
@@ -942,7 +942,8 @@ public class Flow extends TreeScanner {
...
@@ -942,7 +942,8 @@ public class Flow extends TreeScanner {
alive
&&
alive
&&
lint
.
isEnabled
(
Lint
.
LintCategory
.
FALLTHROUGH
)
&&
lint
.
isEnabled
(
Lint
.
LintCategory
.
FALLTHROUGH
)
&&
c
.
stats
.
nonEmpty
()
&&
l
.
tail
.
nonEmpty
())
c
.
stats
.
nonEmpty
()
&&
l
.
tail
.
nonEmpty
())
log
.
warning
(
l
.
tail
.
head
.
pos
(),
log
.
warning
(
Lint
.
LintCategory
.
FALLTHROUGH
,
l
.
tail
.
head
.
pos
(),
"possible.fall-through.into.case"
);
"possible.fall-through.into.case"
);
}
}
if
(!
hasDefault
)
{
if
(!
hasDefault
)
{
...
@@ -1081,8 +1082,9 @@ public class Flow extends TreeScanner {
...
@@ -1081,8 +1082,9 @@ public class Flow extends TreeScanner {
thrown
=
chk
.
union
(
thrown
,
thrownPrev
);
thrown
=
chk
.
union
(
thrown
,
thrownPrev
);
if
(!
loopPassTwo
&&
if
(!
loopPassTwo
&&
lint
.
isEnabled
(
Lint
.
LintCategory
.
FINALLY
))
{
lint
.
isEnabled
(
Lint
.
LintCategory
.
FINALLY
))
{
log
.
warning
(
TreeInfo
.
diagEndPos
(
tree
.
finalizer
),
log
.
warning
(
Lint
.
LintCategory
.
FINALLY
,
"finally.cannot.complete"
);
TreeInfo
.
diagEndPos
(
tree
.
finalizer
),
"finally.cannot.complete"
);
}
}
}
else
{
}
else
{
thrown
=
chk
.
union
(
thrown
,
chk
.
diff
(
thrownInTry
,
caughtInTry
));
thrown
=
chk
.
union
(
thrown
,
chk
.
diff
(
thrownInTry
,
caughtInTry
));
...
@@ -1353,7 +1355,8 @@ public class Flow extends TreeScanner {
...
@@ -1353,7 +1355,8 @@ public class Flow extends TreeScanner {
&&
lint
.
isEnabled
(
Lint
.
LintCategory
.
CAST
)
&&
lint
.
isEnabled
(
Lint
.
LintCategory
.
CAST
)
&&
types
.
isSameType
(
tree
.
expr
.
type
,
tree
.
clazz
.
type
)
&&
types
.
isSameType
(
tree
.
expr
.
type
,
tree
.
clazz
.
type
)
&&
!(
ignoreAnnotatedCasts
&&
containsTypeAnnotation
(
tree
.
clazz
)))
{
&&
!(
ignoreAnnotatedCasts
&&
containsTypeAnnotation
(
tree
.
clazz
)))
{
log
.
warning
(
tree
.
pos
(),
"redundant.cast"
,
tree
.
expr
.
type
);
log
.
warning
(
Lint
.
LintCategory
.
CAST
,
tree
.
pos
(),
"redundant.cast"
,
tree
.
expr
.
type
);
}
}
}
}
...
...
src/share/classes/com/sun/tools/javac/comp/Resolve.java
浏览文件 @
4b9418e2
...
@@ -1797,13 +1797,13 @@ public class Resolve {
...
@@ -1797,13 +1797,13 @@ public class Resolve {
return
null
;
return
null
;
if
(
isOperator
(
name
))
{
if
(
isOperator
(
name
))
{
return
diags
.
create
(
dkind
,
false
,
log
.
currentSource
(),
pos
,
return
diags
.
create
(
dkind
,
log
.
currentSource
(),
pos
,
"operator.cant.be.applied"
,
name
,
argtypes
);
"operator.cant.be.applied"
,
name
,
argtypes
);
}
}
boolean
hasLocation
=
false
;
boolean
hasLocation
=
false
;
if
(!
site
.
tsym
.
name
.
isEmpty
())
{
if
(!
site
.
tsym
.
name
.
isEmpty
())
{
if
(
site
.
tsym
.
kind
==
PCK
&&
!
site
.
tsym
.
exists
())
{
if
(
site
.
tsym
.
kind
==
PCK
&&
!
site
.
tsym
.
exists
())
{
return
diags
.
create
(
dkind
,
false
,
log
.
currentSource
(),
pos
,
return
diags
.
create
(
dkind
,
log
.
currentSource
(),
pos
,
"doesnt.exist"
,
site
.
tsym
);
"doesnt.exist"
,
site
.
tsym
);
}
}
hasLocation
=
true
;
hasLocation
=
true
;
...
@@ -1814,13 +1814,13 @@ public class Resolve {
...
@@ -1814,13 +1814,13 @@ public class Resolve {
Name
idname
=
isConstructor
?
site
.
tsym
.
name
:
name
;
Name
idname
=
isConstructor
?
site
.
tsym
.
name
:
name
;
String
errKey
=
getErrorKey
(
kindname
,
typeargtypes
.
nonEmpty
(),
hasLocation
);
String
errKey
=
getErrorKey
(
kindname
,
typeargtypes
.
nonEmpty
(),
hasLocation
);
if
(
hasLocation
)
{
if
(
hasLocation
)
{
return
diags
.
create
(
dkind
,
false
,
log
.
currentSource
(),
pos
,
return
diags
.
create
(
dkind
,
log
.
currentSource
(),
pos
,
errKey
,
kindname
,
idname
,
//symbol kindname, name
errKey
,
kindname
,
idname
,
//symbol kindname, name
typeargtypes
,
argtypes
,
//type parameters and arguments (if any)
typeargtypes
,
argtypes
,
//type parameters and arguments (if any)
typeKindName
(
site
),
site
);
//location kindname, type
typeKindName
(
site
),
site
);
//location kindname, type
}
}
else
{
else
{
return
diags
.
create
(
dkind
,
false
,
log
.
currentSource
(),
pos
,
return
diags
.
create
(
dkind
,
log
.
currentSource
(),
pos
,
errKey
,
kindname
,
idname
,
//symbol kindname, name
errKey
,
kindname
,
idname
,
//symbol kindname, name
typeargtypes
,
argtypes
);
//type parameters and arguments (if any)
typeargtypes
,
argtypes
);
//type parameters and arguments (if any)
}
}
...
@@ -1886,12 +1886,12 @@ public class Resolve {
...
@@ -1886,12 +1886,12 @@ public class Resolve {
return
null
;
return
null
;
if
(
isOperator
(
name
))
{
if
(
isOperator
(
name
))
{
return
diags
.
create
(
dkind
,
false
,
log
.
currentSource
(),
return
diags
.
create
(
dkind
,
log
.
currentSource
(),
pos
,
"operator.cant.be.applied"
,
name
,
argtypes
);
pos
,
"operator.cant.be.applied"
,
name
,
argtypes
);
}
}
else
{
else
{
Symbol
ws
=
sym
.
asMemberOf
(
site
,
types
);
Symbol
ws
=
sym
.
asMemberOf
(
site
,
types
);
return
diags
.
create
(
dkind
,
false
,
log
.
currentSource
(),
pos
,
return
diags
.
create
(
dkind
,
log
.
currentSource
(),
pos
,
"cant.apply.symbol"
+
(
explanation
!=
null
?
".1"
:
""
),
"cant.apply.symbol"
+
(
explanation
!=
null
?
".1"
:
""
),
kindName
(
ws
),
kindName
(
ws
),
ws
.
name
==
names
.
init
?
ws
.
owner
.
name
:
ws
.
name
,
ws
.
name
==
names
.
init
?
ws
.
owner
.
name
:
ws
.
name
,
...
@@ -1974,18 +1974,18 @@ public class Resolve {
...
@@ -1974,18 +1974,18 @@ public class Resolve {
else
if
((
sym
.
flags
()
&
PUBLIC
)
!=
0
else
if
((
sym
.
flags
()
&
PUBLIC
)
!=
0
||
(
env
!=
null
&&
this
.
site
!=
null
||
(
env
!=
null
&&
this
.
site
!=
null
&&
!
isAccessible
(
env
,
this
.
site
)))
{
&&
!
isAccessible
(
env
,
this
.
site
)))
{
return
diags
.
create
(
dkind
,
false
,
log
.
currentSource
(),
return
diags
.
create
(
dkind
,
log
.
currentSource
(),
pos
,
"not.def.access.class.intf.cant.access"
,
pos
,
"not.def.access.class.intf.cant.access"
,
sym
,
sym
.
location
());
sym
,
sym
.
location
());
}
}
else
if
((
sym
.
flags
()
&
(
PRIVATE
|
PROTECTED
))
!=
0
)
{
else
if
((
sym
.
flags
()
&
(
PRIVATE
|
PROTECTED
))
!=
0
)
{
return
diags
.
create
(
dkind
,
false
,
log
.
currentSource
(),
return
diags
.
create
(
dkind
,
log
.
currentSource
(),
pos
,
"report.access"
,
sym
,
pos
,
"report.access"
,
sym
,
asFlagSet
(
sym
.
flags
()
&
(
PRIVATE
|
PROTECTED
)),
asFlagSet
(
sym
.
flags
()
&
(
PRIVATE
|
PROTECTED
)),
sym
.
location
());
sym
.
location
());
}
}
else
{
else
{
return
diags
.
create
(
dkind
,
false
,
log
.
currentSource
(),
return
diags
.
create
(
dkind
,
log
.
currentSource
(),
pos
,
"not.def.public.cant.access"
,
sym
,
sym
.
location
());
pos
,
"not.def.public.cant.access"
,
sym
,
sym
.
location
());
}
}
}
}
...
@@ -2011,7 +2011,7 @@ public class Resolve {
...
@@ -2011,7 +2011,7 @@ public class Resolve {
Symbol
errSym
=
((
sym
.
kind
==
TYP
&&
sym
.
type
.
tag
==
CLASS
)
Symbol
errSym
=
((
sym
.
kind
==
TYP
&&
sym
.
type
.
tag
==
CLASS
)
?
types
.
erasure
(
sym
.
type
).
tsym
?
types
.
erasure
(
sym
.
type
).
tsym
:
sym
);
:
sym
);
return
diags
.
create
(
dkind
,
false
,
log
.
currentSource
(),
pos
,
return
diags
.
create
(
dkind
,
log
.
currentSource
(),
pos
,
"non-static.cant.be.ref"
,
kindName
(
sym
),
errSym
);
"non-static.cant.be.ref"
,
kindName
(
sym
),
errSym
);
}
}
}
}
...
@@ -2048,7 +2048,7 @@ public class Resolve {
...
@@ -2048,7 +2048,7 @@ public class Resolve {
}
}
Name
sname
=
pair
.
sym
.
name
;
Name
sname
=
pair
.
sym
.
name
;
if
(
sname
==
names
.
init
)
sname
=
pair
.
sym
.
owner
.
name
;
if
(
sname
==
names
.
init
)
sname
=
pair
.
sym
.
owner
.
name
;
return
diags
.
create
(
dkind
,
false
,
log
.
currentSource
(),
return
diags
.
create
(
dkind
,
log
.
currentSource
(),
pos
,
"ref.ambiguous"
,
sname
,
pos
,
"ref.ambiguous"
,
sname
,
kindName
(
pair
.
sym
),
kindName
(
pair
.
sym
),
pair
.
sym
,
pair
.
sym
,
...
...
src/share/classes/com/sun/tools/javac/file/Paths.java
浏览文件 @
4b9418e2
...
@@ -246,7 +246,8 @@ public class Paths {
...
@@ -246,7 +246,8 @@ public class Paths {
private
void
addDirectory
(
File
dir
,
boolean
warn
)
{
private
void
addDirectory
(
File
dir
,
boolean
warn
)
{
if
(!
dir
.
isDirectory
())
{
if
(!
dir
.
isDirectory
())
{
if
(
warn
)
if
(
warn
)
log
.
warning
(
"dir.path.element.not.found"
,
dir
);
log
.
warning
(
Lint
.
LintCategory
.
PATH
,
"dir.path.element.not.found"
,
dir
);
return
;
return
;
}
}
...
@@ -280,8 +281,10 @@ public class Paths {
...
@@ -280,8 +281,10 @@ public class Paths {
if
(!
fsInfo
.
exists
(
file
))
{
if
(!
fsInfo
.
exists
(
file
))
{
/* No such file or directory exists */
/* No such file or directory exists */
if
(
warn
)
if
(
warn
)
{
log
.
warning
(
"path.element.not.found"
,
file
);
log
.
warning
(
Lint
.
LintCategory
.
PATH
,
"path.element.not.found"
,
file
);
}
}
else
if
(
fsInfo
.
isFile
(
file
))
{
}
else
if
(
fsInfo
.
isFile
(
file
))
{
/* File is an ordinary file. */
/* File is an ordinary file. */
if
(!
isArchive
(
file
))
{
if
(!
isArchive
(
file
))
{
...
@@ -290,12 +293,16 @@ public class Paths {
...
@@ -290,12 +293,16 @@ public class Paths {
try
{
try
{
ZipFile
z
=
new
ZipFile
(
file
);
ZipFile
z
=
new
ZipFile
(
file
);
z
.
close
();
z
.
close
();
if
(
warn
)
if
(
warn
)
{
log
.
warning
(
"unexpected.archive.file"
,
file
);
log
.
warning
(
Lint
.
LintCategory
.
PATH
,
"unexpected.archive.file"
,
file
);
}
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
// FIXME: include e.getLocalizedMessage in warning
// FIXME: include e.getLocalizedMessage in warning
if
(
warn
)
if
(
warn
)
{
log
.
warning
(
"invalid.archive.file"
,
file
);
log
.
warning
(
Lint
.
LintCategory
.
PATH
,
"invalid.archive.file"
,
file
);
}
return
;
return
;
}
}
}
}
...
...
src/share/classes/com/sun/tools/javac/resources/compiler.properties
浏览文件 @
4b9418e2
...
@@ -697,25 +697,31 @@ compiler.misc.resume.abort=\
...
@@ -697,25 +697,31 @@ compiler.misc.resume.abort=\
compiler.warn.warning
=
\
compiler.warn.warning
=
\
warning:
\u0020
warning:
\u0020
## Warning messages may also include the following prefix to identify a
## lint option
compiler.warn.lintOption
=
\
[{0}]
\u0020
compiler.warn.constant.SVUID
=
\
compiler.warn.constant.SVUID
=
\
[serial]
serialVersionUID must be constant in class {0}
serialVersionUID must be constant in class {0}
compiler.warn.dir.path.element.not.found
=
\
compiler.warn.dir.path.element.not.found
=
\
[path]
bad path element "{0}": no such directory
bad path element "{0}": no such directory
compiler.warn.finally.cannot.complete
=
\
compiler.warn.finally.cannot.complete
=
\
[finally]
finally clause cannot complete normally
finally clause cannot complete normally
compiler.warn.has.been.deprecated
=
\
compiler.warn.has.been.deprecated
=
\
[deprecation]
{0} in {1} has been deprecated
{0} in {1} has been deprecated
compiler.warn.sun.proprietary
=
\
compiler.warn.sun.proprietary
=
\
{0} is internal proprietary API and may be removed in a future release
{0} is internal proprietary API and may be removed in a future release
compiler.warn.illegal.char.for.encoding
=
\
compiler.warn.illegal.char.for.encoding
=
\
unmappable character for encoding {0}
unmappable character for encoding {0}
compiler.warn.improper.SVUID
=
\
compiler.warn.improper.SVUID
=
\
[serial]
serialVersionUID must be declared static final in class {0}
serialVersionUID must be declared static final in class {0}
compiler.warn.inexact.non-varargs.call
=
\
compiler.warn.inexact.non-varargs.call
=
\
non-varargs call of varargs method with inexact argument type for last parameter;
\n\
non-varargs call of varargs method with inexact argument type for last parameter;
\n\
...
@@ -723,10 +729,10 @@ cast to {0} for a varargs call\n\
...
@@ -723,10 +729,10 @@ cast to {0} for a varargs call\n\
cast to {1} for a non-varargs call and to suppress this warning
cast to {1} for a non-varargs call and to suppress this warning
compiler.warn.long.SVUID
=
\
compiler.warn.long.SVUID
=
\
[serial]
serialVersionUID must be of type long in class {0}
serialVersionUID must be of type long in class {0}
compiler.warn.missing.SVUID
=
\
compiler.warn.missing.SVUID
=
\
[serial]
serializable class {0} has no definition of serialVersionUID
serializable class {0} has no definition of serialVersionUID
compiler.warn.override.varargs.missing
=
\
compiler.warn.override.varargs.missing
=
\
{0}; overridden method has no ''...''
{0}; overridden method has no ''...''
...
@@ -737,13 +743,15 @@ compiler.warn.override.bridge=\
...
@@ -737,13 +743,15 @@ compiler.warn.override.bridge=\
compiler.warn.pkg-info.already.seen
=
\
compiler.warn.pkg-info.already.seen
=
\
a package-info.java file has already been seen for package {0}
a package-info.java file has already been seen for package {0}
compiler.warn.path.element.not.found
=
\
compiler.warn.path.element.not.found
=
\
[path] bad path element "{0}": no such file or directory
bad path element "{0}": no such file or directory
compiler.warn.possible.fall-through.into.case
=
\
compiler.warn.possible.fall-through.into.case
=
\
[fallthrough]
possible fall-through into case
possible fall-through into case
compiler.warn.redundant.cast
=
\
compiler.warn.redundant.cast
=
\
[cast]
redundant cast to {0}
redundant cast to {0}
compiler.warn.position.overflow
=
\
compiler.warn.position.overflow
=
\
Position encoding overflows at line {0}
Position encoding overflows at line {0}
...
@@ -753,7 +761,7 @@ compiler.warn.big.major.version=\
...
@@ -753,7 +761,7 @@ compiler.warn.big.major.version=\
It is recommended that the compiler be upgraded.
It is recommended that the compiler be upgraded.
compiler.warn.static.not.qualified.by.type
=
\
compiler.warn.static.not.qualified.by.type
=
\
[static]
static {0} should be qualified by type name, {1}, instead of by an expression
static {0} should be qualified by type name, {1}, instead of by an expression
# Warnings related to annotation processing
# Warnings related to annotation processing
compiler.warn.proc.package.does.not.exist
=
\
compiler.warn.proc.package.does.not.exist
=
\
...
@@ -808,38 +816,38 @@ compiler.warn.twr.explicit.close.call=\
...
@@ -808,38 +816,38 @@ compiler.warn.twr.explicit.close.call=\
compiler.warn.automatic.resource.not.referenced
=
\
compiler.warn.automatic.resource.not.referenced
=
\
[arm] automatic resource {0} is never referenced in body of corresponding try statement
[arm] automatic resource {0} is never referenced in body of corresponding try statement
compiler.warn.unchecked.assign
=
\
compiler.warn.unchecked.assign
=
\
[unchecked]
unchecked assignment: {0} to {1}
unchecked assignment: {0} to {1}
compiler.warn.unchecked.assign.to.var
=
\
compiler.warn.unchecked.assign.to.var
=
\
[unchecked]
unchecked assignment to variable {0} as member of raw type {1}
unchecked assignment to variable {0} as member of raw type {1}
compiler.warn.unchecked.call.mbr.of.raw.type
=
\
compiler.warn.unchecked.call.mbr.of.raw.type
=
\
[unchecked]
unchecked call to {0} as a member of the raw type {1}
unchecked call to {0} as a member of the raw type {1}
compiler.warn.unchecked.cast.to.type
=
\
compiler.warn.unchecked.cast.to.type
=
\
[unchecked]
unchecked cast to type {0}
unchecked cast to type {0}
compiler.warn.unchecked.meth.invocation.applied
=
\
compiler.warn.unchecked.meth.invocation.applied
=
\
[unchecked]
unchecked method invocation: {0} {1} in {4} {5} is applied to given types
\n\
unchecked method invocation: {0} {1} in {4} {5} is applied to given types
\n\
required: {2}
\n\
required: {2}
\n\
found: {3}
found: {3}
compiler.warn.unchecked.generic.array.creation
=
\
compiler.warn.unchecked.generic.array.creation
=
\
[unchecked]
unchecked generic array creation for varargs parameter of type {0}
unchecked generic array creation for varargs parameter of type {0}
compiler.warn.varargs.non.reifiable.type
=
\
compiler.warn.varargs.non.reifiable.type
=
\
[varargs]
Possible heap pollution from parameterized vararg type {0}
Possible heap pollution from parameterized vararg type {0}
compiler.warn.missing.deprecated.annotation
=
\
compiler.warn.missing.deprecated.annotation
=
\
[dep-ann]
deprecated item is not annotated with @Deprecated
deprecated item is not annotated with @Deprecated
compiler.warn.invalid.archive.file
=
\
compiler.warn.invalid.archive.file
=
\
[path]
Unexpected file on path: {0}
Unexpected file on path: {0}
compiler.warn.unexpected.archive.file
=
\
compiler.warn.unexpected.archive.file
=
\
[path]
Unexpected extension for archive file: {0}
Unexpected extension for archive file: {0}
compiler.warn.div.zero
=
\
compiler.warn.div.zero
=
\
[divzero]
division by zero
division by zero
compiler.warn.empty.if
=
\
compiler.warn.empty.if
=
\
[empty]
empty statement after if
empty statement after if
compiler.warn.annotation.method.not.found
=
\
compiler.warn.annotation.method.not.found
=
\
Cannot find annotation method ''{1}()'' in type ''{0}''
Cannot find annotation method ''{1}()'' in type ''{0}''
...
@@ -848,7 +856,7 @@ compiler.warn.annotation.method.not.found.reason=\
...
@@ -848,7 +856,7 @@ compiler.warn.annotation.method.not.found.reason=\
Cannot find annotation method ''{1}()'' in type ''{0}'': {2}
Cannot find annotation method ''{1}()'' in type ''{0}'': {2}
compiler.warn.raw.class.use
=
\
compiler.warn.raw.class.use
=
\
[rawtypes]
found raw type: {0}
\n\
found raw type: {0}
\n\
missing type parameters for generic class {1}
missing type parameters for generic class {1}
#####
#####
...
@@ -1006,13 +1014,13 @@ compiler.misc.possible.loss.of.precision=\
...
@@ -1006,13 +1014,13 @@ compiler.misc.possible.loss.of.precision=\
possible loss of precision
possible loss of precision
compiler.misc.unchecked.assign
=
\
compiler.misc.unchecked.assign
=
\
[unchecked]
unchecked conversion
unchecked conversion
# compiler.misc.storecheck=\
# compiler.misc.storecheck=\
#
[unchecked]
assignment might cause later store checks to fail
# assignment might cause later store checks to fail
# compiler.misc.unchecked=\
# compiler.misc.unchecked=\
#
[unchecked]
assigned array cannot dynamically check its stores
# assigned array cannot dynamically check its stores
compiler.misc.unchecked.cast.to.type
=
\
compiler.misc.unchecked.cast.to.type
=
\
[unchecked]
unchecked cast
unchecked cast
compiler.misc.assignment.from.super-bound
=
\
compiler.misc.assignment.from.super-bound
=
\
assignment from super-bound type {0}
assignment from super-bound type {0}
...
@@ -1182,11 +1190,11 @@ compiler.err.override.incompatible.ret=\
...
@@ -1182,11 +1190,11 @@ compiler.err.override.incompatible.ret=\
return type {1} is not compatible with {2}
return type {1} is not compatible with {2}
compiler.warn.override.unchecked.ret
=
\
compiler.warn.override.unchecked.ret
=
\
[unchecked]
{0}
\n\
{0}
\n\
return type requires unchecked conversion from {1} to {2}
return type requires unchecked conversion from {1} to {2}
compiler.warn.override.unchecked.thrown
=
\
compiler.warn.override.unchecked.thrown
=
\
[unchecked]
{0}
\n\
{0}
\n\
overridden method does not throw {1}
overridden method does not throw {1}
## The following are all possible strings for the first argument ({0}) of the
## The following are all possible strings for the first argument ({0}) of the
...
...
src/share/classes/com/sun/tools/javac/util/AbstractDiagnosticFormatter.java
浏览文件 @
4b9418e2
...
@@ -38,6 +38,7 @@ import com.sun.tools.javac.api.DiagnosticFormatter.Configuration.DiagnosticPart;
...
@@ -38,6 +38,7 @@ import com.sun.tools.javac.api.DiagnosticFormatter.Configuration.DiagnosticPart;
import
com.sun.tools.javac.api.DiagnosticFormatter.Configuration.MultilineLimit
;
import
com.sun.tools.javac.api.DiagnosticFormatter.Configuration.MultilineLimit
;
import
com.sun.tools.javac.api.DiagnosticFormatter.PositionKind
;
import
com.sun.tools.javac.api.DiagnosticFormatter.PositionKind
;
import
com.sun.tools.javac.api.Formattable
;
import
com.sun.tools.javac.api.Formattable
;
import
com.sun.tools.javac.code.Lint.LintCategory
;
import
com.sun.tools.javac.code.Printer
;
import
com.sun.tools.javac.code.Printer
;
import
com.sun.tools.javac.code.Symbol
;
import
com.sun.tools.javac.code.Symbol
;
import
com.sun.tools.javac.code.Type
;
import
com.sun.tools.javac.code.Type
;
...
@@ -285,6 +286,13 @@ public abstract class AbstractDiagnosticFormatter implements DiagnosticFormatter
...
@@ -285,6 +286,13 @@ public abstract class AbstractDiagnosticFormatter implements DiagnosticFormatter
return
buf
.
toString
();
return
buf
.
toString
();
}
}
protected
String
formatLintCategory
(
JCDiagnostic
d
,
Locale
l
)
{
LintCategory
lc
=
d
.
getLintCategory
();
if
(
lc
==
null
)
return
""
;
return
localize
(
l
,
"compiler.warn.lintOption"
,
lc
.
option
);
}
/**
/**
* Converts a String into a locale-dependent representation accordingly to a given locale.
* Converts a String into a locale-dependent representation accordingly to a given locale.
*
*
...
...
src/share/classes/com/sun/tools/javac/util/AbstractLog.java
浏览文件 @
4b9418e2
...
@@ -29,6 +29,7 @@ import java.util.HashMap;
...
@@ -29,6 +29,7 @@ import java.util.HashMap;
import
java.util.Map
;
import
java.util.Map
;
import
javax.tools.JavaFileObject
;
import
javax.tools.JavaFileObject
;
import
com.sun.tools.javac.code.Lint.LintCategory
;
import
com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition
;
import
com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition
;
import
com.sun.tools.javac.util.JCDiagnostic.SimpleDiagnosticPosition
;
import
com.sun.tools.javac.util.JCDiagnostic.SimpleDiagnosticPosition
;
...
@@ -112,6 +113,16 @@ public abstract class AbstractLog {
...
@@ -112,6 +113,16 @@ public abstract class AbstractLog {
report
(
diags
.
warning
(
source
,
null
,
key
,
args
));
report
(
diags
.
warning
(
source
,
null
,
key
,
args
));
}
}
/** Report a lint warning, unless suppressed by the -nowarn option or the
* maximum number of warnings has been reached.
* @param lc The lint category for the diagnostic
* @param key The key for the localized warning message.
* @param args Fields of the warning message.
*/
public
void
warning
(
LintCategory
lc
,
String
key
,
Object
...
args
)
{
report
(
diags
.
warning
(
lc
,
key
,
args
));
}
/** Report a warning, unless suppressed by the -nowarn option or the
/** Report a warning, unless suppressed by the -nowarn option or the
* maximum number of warnings has been reached.
* maximum number of warnings has been reached.
* @param pos The source position at which to report the warning.
* @param pos The source position at which to report the warning.
...
@@ -122,6 +133,17 @@ public abstract class AbstractLog {
...
@@ -122,6 +133,17 @@ public abstract class AbstractLog {
report
(
diags
.
warning
(
source
,
pos
,
key
,
args
));
report
(
diags
.
warning
(
source
,
pos
,
key
,
args
));
}
}
/** Report a lint warning, unless suppressed by the -nowarn option or the
* maximum number of warnings has been reached.
* @param lc The lint category for the diagnostic
* @param pos The source position at which to report the warning.
* @param key The key for the localized warning message.
* @param args Fields of the warning message.
*/
public
void
warning
(
LintCategory
lc
,
DiagnosticPosition
pos
,
String
key
,
Object
...
args
)
{
report
(
diags
.
warning
(
lc
,
source
,
pos
,
key
,
args
));
}
/** Report a warning, unless suppressed by the -nowarn option or the
/** Report a warning, unless suppressed by the -nowarn option or the
* maximum number of warnings has been reached.
* maximum number of warnings has been reached.
* @param pos The source position at which to report the warning.
* @param pos The source position at which to report the warning.
...
@@ -141,6 +163,16 @@ public abstract class AbstractLog {
...
@@ -141,6 +163,16 @@ public abstract class AbstractLog {
report
(
diags
.
mandatoryWarning
(
source
,
pos
,
key
,
args
));
report
(
diags
.
mandatoryWarning
(
source
,
pos
,
key
,
args
));
}
}
/** Report a warning.
* @param lc The lint category for the diagnostic
* @param pos The source position at which to report the warning.
* @param key The key for the localized warning message.
* @param args Fields of the warning message.
*/
public
void
mandatoryWarning
(
LintCategory
lc
,
DiagnosticPosition
pos
,
String
key
,
Object
...
args
)
{
report
(
diags
.
mandatoryWarning
(
lc
,
source
,
pos
,
key
,
args
));
}
/** Provide a non-fatal notification, unless suppressed by the -nowarn option.
/** Provide a non-fatal notification, unless suppressed by the -nowarn option.
* @param key The key for the localized notification message.
* @param key The key for the localized notification message.
* @param args Fields of the notint an error or warning message:
* @param args Fields of the notint an error or warning message:
...
...
src/share/classes/com/sun/tools/javac/util/BasicDiagnosticFormatter.java
浏览文件 @
4b9418e2
...
@@ -73,7 +73,6 @@ public class BasicDiagnosticFormatter extends AbstractDiagnosticFormatter {
...
@@ -73,7 +73,6 @@ public class BasicDiagnosticFormatter extends AbstractDiagnosticFormatter {
* @param opts list of command-line options
* @param opts list of command-line options
* @param msgs JavacMessages object used for i18n
* @param msgs JavacMessages object used for i18n
*/
*/
@SuppressWarnings
(
"fallthrough"
)
public
BasicDiagnosticFormatter
(
Options
options
,
JavacMessages
msgs
)
{
public
BasicDiagnosticFormatter
(
Options
options
,
JavacMessages
msgs
)
{
super
(
msgs
,
new
BasicConfiguration
(
options
));
super
(
msgs
,
new
BasicConfiguration
(
options
));
}
}
...
@@ -189,6 +188,8 @@ public class BasicDiagnosticFormatter extends AbstractDiagnosticFormatter {
...
@@ -189,6 +188,8 @@ public class BasicDiagnosticFormatter extends AbstractDiagnosticFormatter {
}
}
case
'm'
:
case
'm'
:
return
formatMessage
(
d
,
l
);
return
formatMessage
(
d
,
l
);
case
'L'
:
return
formatLintCategory
(
d
,
l
);
case
'_'
:
case
'_'
:
return
" "
;
return
" "
;
case
'%'
:
case
'%'
:
...
@@ -244,9 +245,9 @@ public class BasicDiagnosticFormatter extends AbstractDiagnosticFormatter {
...
@@ -244,9 +245,9 @@ public class BasicDiagnosticFormatter extends AbstractDiagnosticFormatter {
setFormat
(
BasicFormatKind
.
DEFAULT_POS_FORMAT
,
formats
[
0
]);
setFormat
(
BasicFormatKind
.
DEFAULT_POS_FORMAT
,
formats
[
0
]);
}
}
}
}
String
s
ourcePosition
=
null
;
String
s
rcPos
=
null
;
if
((((
s
ourcePosition
=
options
.
get
(
"sourcePosition"
))
!=
null
))
&&
if
((((
s
rcPos
=
options
.
get
(
"sourcePosition"
))
!=
null
))
&&
s
ourcePosition
.
equals
(
"bottom"
))
s
rcPos
.
equals
(
"bottom"
))
setSourcePosition
(
SourcePosition
.
BOTTOM
);
setSourcePosition
(
SourcePosition
.
BOTTOM
);
else
else
setSourcePosition
(
SourcePosition
.
AFTER_SUMMARY
);
setSourcePosition
(
SourcePosition
.
AFTER_SUMMARY
);
...
@@ -289,9 +290,9 @@ public class BasicDiagnosticFormatter extends AbstractDiagnosticFormatter {
...
@@ -289,9 +290,9 @@ public class BasicDiagnosticFormatter extends AbstractDiagnosticFormatter {
//where
//where
private
void
initFormat
()
{
private
void
initFormat
()
{
availableFormats
=
new
HashMap
<
BasicFormatKind
,
String
>();
availableFormats
=
new
HashMap
<
BasicFormatKind
,
String
>();
setFormat
(
BasicFormatKind
.
DEFAULT_POS_FORMAT
,
"%f:%l:%_%t%m"
);
setFormat
(
BasicFormatKind
.
DEFAULT_POS_FORMAT
,
"%f:%l:%_%t%
L%
m"
);
setFormat
(
BasicFormatKind
.
DEFAULT_NO_POS_FORMAT
,
"%p%m"
);
setFormat
(
BasicFormatKind
.
DEFAULT_NO_POS_FORMAT
,
"%p%
L%
m"
);
setFormat
(
BasicFormatKind
.
DEFAULT_CLASS_FORMAT
,
"%f:%_%t%m"
);
setFormat
(
BasicFormatKind
.
DEFAULT_CLASS_FORMAT
,
"%f:%_%t%
L%
m"
);
}
}
//where
//where
private
void
initIndentation
()
{
private
void
initIndentation
()
{
...
...
src/share/classes/com/sun/tools/javac/util/JCDiagnostic.java
浏览文件 @
4b9418e2
...
@@ -32,6 +32,7 @@ import javax.tools.Diagnostic;
...
@@ -32,6 +32,7 @@ import javax.tools.Diagnostic;
import
javax.tools.JavaFileObject
;
import
javax.tools.JavaFileObject
;
import
com.sun.tools.javac.api.DiagnosticFormatter
;
import
com.sun.tools.javac.api.DiagnosticFormatter
;
import
com.sun.tools.javac.code.Lint.LintCategory
;
import
com.sun.tools.javac.tree.JCTree
;
import
com.sun.tools.javac.tree.JCTree
;
import
static
com
.
sun
.
tools
.
javac
.
util
.
JCDiagnostic
.
DiagnosticType
.*;
import
static
com
.
sun
.
tools
.
javac
.
util
.
JCDiagnostic
.
DiagnosticType
.*;
...
@@ -82,86 +83,143 @@ public class JCDiagnostic implements Diagnostic<JavaFileObject> {
...
@@ -82,86 +83,143 @@ public class JCDiagnostic implements Diagnostic<JavaFileObject> {
*/
*/
public
JCDiagnostic
error
(
public
JCDiagnostic
error
(
DiagnosticSource
source
,
DiagnosticPosition
pos
,
String
key
,
Object
...
args
)
{
DiagnosticSource
source
,
DiagnosticPosition
pos
,
String
key
,
Object
...
args
)
{
return
create
(
ERROR
,
true
,
source
,
pos
,
key
,
args
);
return
create
(
ERROR
,
null
,
true
,
source
,
pos
,
key
,
args
);
}
}
/**
/**
* Create a warning diagnostic that will not be hidden by the -nowarn or -Xlint:none options.
* Create a warning diagnostic that will not be hidden by the -nowarn or -Xlint:none options.
* @param source The source of the compilation unit, if any, in which to report the warning.
* @param source The source of the compilation unit, if any, in which to report the warning.
* @param pos The source position at which to report the warning.
* @param pos The source position at which to report the warning.
* @param key The key for the localized
error
message.
* @param key The key for the localized
warning
message.
* @param args Fields of the
error
message.
* @param args Fields of the
warning
message.
* @see MandatoryWarningHandler
* @see MandatoryWarningHandler
*/
*/
public
JCDiagnostic
mandatoryWarning
(
public
JCDiagnostic
mandatoryWarning
(
DiagnosticSource
source
,
DiagnosticPosition
pos
,
String
key
,
Object
...
args
)
{
DiagnosticSource
source
,
DiagnosticPosition
pos
,
String
key
,
Object
...
args
)
{
return
create
(
WARNING
,
true
,
source
,
pos
,
key
,
args
);
return
create
(
WARNING
,
null
,
true
,
source
,
pos
,
key
,
args
);
}
}
/**
/**
* Create a warning diagnostic.
* Create a warning diagnostic that will not be hidden by the -nowarn or -Xlint:none options.
* @param lc The lint category for the diagnostic
* @param source The source of the compilation unit, if any, in which to report the warning.
* @param source The source of the compilation unit, if any, in which to report the warning.
* @param pos The source position at which to report the warning.
* @param pos The source position at which to report the warning.
* @param key The key for the localized warning message.
* @param args Fields of the warning message.
* @see MandatoryWarningHandler
*/
public
JCDiagnostic
mandatoryWarning
(
LintCategory
lc
,
DiagnosticSource
source
,
DiagnosticPosition
pos
,
String
key
,
Object
...
args
)
{
return
create
(
WARNING
,
lc
,
true
,
source
,
pos
,
key
,
args
);
}
/**
* Create a warning diagnostic.
* @param lc The lint category for the diagnostic
* @param key The key for the localized error message.
* @param key The key for the localized error message.
* @param args Fields of the error message.
* @param args Fields of the warning message.
* @see MandatoryWarningHandler
*/
public
JCDiagnostic
warning
(
LintCategory
lc
,
String
key
,
Object
...
args
)
{
return
create
(
WARNING
,
lc
,
false
,
null
,
null
,
key
,
args
);
}
/**
* Create a warning diagnostic.
* @param source The source of the compilation unit, if any, in which to report the warning.
* @param pos The source position at which to report the warning.
* @param key The key for the localized warning message.
* @param args Fields of the warning message.
*/
*/
public
JCDiagnostic
warning
(
public
JCDiagnostic
warning
(
DiagnosticSource
source
,
DiagnosticPosition
pos
,
String
key
,
Object
...
args
)
{
DiagnosticSource
source
,
DiagnosticPosition
pos
,
String
key
,
Object
...
args
)
{
return
create
(
WARNING
,
false
,
source
,
pos
,
key
,
args
);
return
create
(
WARNING
,
null
,
false
,
source
,
pos
,
key
,
args
);
}
/**
* Create a warning diagnostic.
* @param lc The lint category for the diagnostic
* @param source The source of the compilation unit, if any, in which to report the warning.
* @param pos The source position at which to report the warning.
* @param key The key for the localized warning message.
* @param args Fields of the warning message.
* @see MandatoryWarningHandler
*/
public
JCDiagnostic
warning
(
LintCategory
lc
,
DiagnosticSource
source
,
DiagnosticPosition
pos
,
String
key
,
Object
...
args
)
{
return
create
(
WARNING
,
lc
,
false
,
source
,
pos
,
key
,
args
);
}
}
/**
/**
* Create a note diagnostic that will not be hidden by the -nowarn or -Xlint:none options.
* Create a note diagnostic that will not be hidden by the -nowarn or -Xlint:none options.
* @param key The key for the localized
error
message.
* @param key The key for the localized message.
* @param args Fields of the
error
message.
* @param args Fields of the message.
* @see MandatoryWarningHandler
* @see MandatoryWarningHandler
*/
*/
public
JCDiagnostic
mandatoryNote
(
DiagnosticSource
source
,
String
key
,
Object
...
args
)
{
public
JCDiagnostic
mandatoryNote
(
DiagnosticSource
source
,
String
key
,
Object
...
args
)
{
return
create
(
NOTE
,
true
,
source
,
null
,
key
,
args
);
return
create
(
NOTE
,
null
,
true
,
source
,
null
,
key
,
args
);
}
}
/**
/**
* Create a note diagnostic.
* Create a note diagnostic.
* @param key The key for the localized error message.
* @param key The key for the localized error message.
* @param args Fields of the
error
message.
* @param args Fields of the message.
*/
*/
public
JCDiagnostic
note
(
String
key
,
Object
...
args
)
{
public
JCDiagnostic
note
(
String
key
,
Object
...
args
)
{
return
create
(
NOTE
,
false
,
null
,
null
,
key
,
args
);
return
create
(
NOTE
,
null
,
false
,
null
,
null
,
key
,
args
);
}
}
/**
/**
* Create a note diagnostic.
* Create a note diagnostic.
* @param source The source of the compilation unit, if any, in which to report the note.
* @param source The source of the compilation unit, if any, in which to report the note.
* @param pos The source position at which to report the note.
* @param pos The source position at which to report the note.
* @param key The key for the localized
error
message.
* @param key The key for the localized message.
* @param args Fields of the
error
message.
* @param args Fields of the message.
*/
*/
public
JCDiagnostic
note
(
public
JCDiagnostic
note
(
DiagnosticSource
source
,
DiagnosticPosition
pos
,
String
key
,
Object
...
args
)
{
DiagnosticSource
source
,
DiagnosticPosition
pos
,
String
key
,
Object
...
args
)
{
return
create
(
NOTE
,
false
,
source
,
pos
,
key
,
args
);
return
create
(
NOTE
,
null
,
false
,
source
,
pos
,
key
,
args
);
}
}
/**
/**
* Create a fragment diagnostic, for use as an argument in other diagnostics
* Create a fragment diagnostic, for use as an argument in other diagnostics
* @param key The key for the localized
error
message.
* @param key The key for the localized message.
* @param args Fields of the
error
message.
* @param args Fields of the message.
*/
*/
public
JCDiagnostic
fragment
(
String
key
,
Object
...
args
)
{
public
JCDiagnostic
fragment
(
String
key
,
Object
...
args
)
{
return
create
(
FRAGMENT
,
false
,
null
,
null
,
key
,
args
);
return
create
(
FRAGMENT
,
null
,
false
,
null
,
null
,
key
,
args
);
}
/**
* Create a new diagnostic of the given kind, which is not mandatory and which has
* no lint category.
* @param kind The diagnostic kind
* @param ls The lint category, if applicable, or null
* @param source The source of the compilation unit, if any, in which to report the message.
* @param pos The source position at which to report the message.
* @param key The key for the localized message.
* @param args Fields of the message.
*/
public
JCDiagnostic
create
(
DiagnosticType
kind
,
DiagnosticSource
source
,
DiagnosticPosition
pos
,
String
key
,
Object
...
args
)
{
return
create
(
kind
,
null
,
false
,
source
,
pos
,
key
,
args
);
}
}
/**
/**
* Create a new diagnostic of the given kind.
* Create a new diagnostic of the given kind.
* @param kind The diagnostic kind
* @param kind The diagnostic kind
* @param lc The lint category, if applicable, or null
* @param isMandatory is diagnostic mandatory?
* @param isMandatory is diagnostic mandatory?
* @param source The source of the compilation unit, if any, in which to report the
not
e.
* @param source The source of the compilation unit, if any, in which to report the
messag
e.
* @param pos The source position at which to report the
not
e.
* @param pos The source position at which to report the
messag
e.
* @param key The key for the localized
error
message.
* @param key The key for the localized message.
* @param args Fields of the
error
message.
* @param args Fields of the message.
*/
*/
public
JCDiagnostic
create
(
public
JCDiagnostic
create
(
DiagnosticType
kind
,
boolean
isMandatory
,
DiagnosticSource
source
,
DiagnosticPosition
pos
,
String
key
,
Object
...
args
)
{
DiagnosticType
kind
,
LintCategory
lc
,
boolean
isMandatory
,
DiagnosticSource
source
,
DiagnosticPosition
pos
,
String
key
,
Object
...
args
)
{
return
new
JCDiagnostic
(
formatter
,
kind
,
isMandatory
,
source
,
pos
,
qualify
(
kind
,
key
),
args
);
return
new
JCDiagnostic
(
formatter
,
kind
,
lc
,
isMandatory
,
source
,
pos
,
qualify
(
kind
,
key
),
args
);
}
}
protected
String
qualify
(
DiagnosticType
t
,
String
key
)
{
protected
String
qualify
(
DiagnosticType
t
,
String
key
)
{
...
@@ -181,6 +239,7 @@ public class JCDiagnostic implements Diagnostic<JavaFileObject> {
...
@@ -181,6 +239,7 @@ public class JCDiagnostic implements Diagnostic<JavaFileObject> {
public
static
JCDiagnostic
fragment
(
String
key
,
Object
...
args
)
{
public
static
JCDiagnostic
fragment
(
String
key
,
Object
...
args
)
{
return
new
JCDiagnostic
(
getFragmentFormatter
(),
return
new
JCDiagnostic
(
getFragmentFormatter
(),
FRAGMENT
,
FRAGMENT
,
null
,
false
,
false
,
null
,
null
,
null
,
null
,
...
@@ -274,30 +333,34 @@ public class JCDiagnostic implements Diagnostic<JavaFileObject> {
...
@@ -274,30 +333,34 @@ public class JCDiagnostic implements Diagnostic<JavaFileObject> {
private
final
int
line
;
private
final
int
line
;
private
final
int
column
;
private
final
int
column
;
private
final
String
key
;
private
final
String
key
;
protected
Object
[]
args
;
protected
final
Object
[]
args
;
private
boolean
mandatory
;
private
final
boolean
mandatory
;
private
final
LintCategory
lintCategory
;
/**
/**
* Create a diagnostic object.
* Create a diagnostic object.
* @param
messages the resource for localized messages
* @param
fomatter the formatter to use for the diagnostic
* @param dt the type of diagnostic
* @param dt the type of diagnostic
* @param name the name of the source file, or null if none.
* @param lc the lint category for the diagnostic
* @param source the name of the source file, or null if none.
* @param pos the character offset within the source file, if given.
* @param pos the character offset within the source file, if given.
* @param key a resource key to identify the text of the diagnostic
* @param key a resource key to identify the text of the diagnostic
* @param args arguments to be included in the text of the diagnostic
* @param args arguments to be included in the text of the diagnostic
*/
*/
protected
JCDiagnostic
(
DiagnosticFormatter
<
JCDiagnostic
>
formatter
,
protected
JCDiagnostic
(
DiagnosticFormatter
<
JCDiagnostic
>
formatter
,
DiagnosticType
dt
,
DiagnosticType
dt
,
LintCategory
lc
,
boolean
mandatory
,
boolean
mandatory
,
DiagnosticSource
source
,
DiagnosticSource
source
,
DiagnosticPosition
pos
,
DiagnosticPosition
pos
,
String
key
,
String
key
,
Object
...
args
)
{
Object
...
args
)
{
if
(
source
==
null
&&
pos
!=
null
&&
pos
.
getPreferredPosition
()
!=
Position
.
NOPOS
)
if
(
source
==
null
&&
pos
!=
null
&&
pos
.
getPreferredPosition
()
!=
Position
.
NOPOS
)
throw
new
IllegalArgumentException
();
throw
new
IllegalArgumentException
();
this
.
defaultFormatter
=
formatter
;
this
.
defaultFormatter
=
formatter
;
this
.
type
=
dt
;
this
.
type
=
dt
;
this
.
lintCategory
=
lc
;
this
.
mandatory
=
mandatory
;
this
.
mandatory
=
mandatory
;
this
.
source
=
source
;
this
.
source
=
source
;
this
.
position
=
pos
;
this
.
position
=
pos
;
...
@@ -341,6 +404,20 @@ public class JCDiagnostic implements Diagnostic<JavaFileObject> {
...
@@ -341,6 +404,20 @@ public class JCDiagnostic implements Diagnostic<JavaFileObject> {
return
mandatory
;
return
mandatory
;
}
}
/**
* Check whether this diagnostic has an associated lint category.
*/
public
boolean
hasLintCategory
()
{
return
(
lintCategory
!=
null
);
}
/**
* Get the associated lint category, or null if none.
*/
public
LintCategory
getLintCategory
()
{
return
lintCategory
;
}
/**
/**
* Get the name of the source file referred to by this diagnostic.
* Get the name of the source file referred to by this diagnostic.
* @return the name of the source referred to with this diagnostic, or null if none
* @return the name of the source referred to with this diagnostic, or null if none
...
@@ -467,6 +544,7 @@ public class JCDiagnostic implements Diagnostic<JavaFileObject> {
...
@@ -467,6 +544,7 @@ public class JCDiagnostic implements Diagnostic<JavaFileObject> {
public
MultilineDiagnostic
(
JCDiagnostic
other
,
List
<
JCDiagnostic
>
subdiagnostics
)
{
public
MultilineDiagnostic
(
JCDiagnostic
other
,
List
<
JCDiagnostic
>
subdiagnostics
)
{
super
(
other
.
defaultFormatter
,
super
(
other
.
defaultFormatter
,
other
.
getType
(),
other
.
getType
(),
other
.
getLintCategory
(),
other
.
isMandatory
(),
other
.
isMandatory
(),
other
.
getDiagnosticSource
(),
other
.
getDiagnosticSource
(),
other
.
position
,
other
.
position
,
...
...
src/share/classes/com/sun/tools/javac/util/MandatoryWarningHandler.java
浏览文件 @
4b9418e2
...
@@ -29,6 +29,7 @@ import java.util.HashSet;
...
@@ -29,6 +29,7 @@ import java.util.HashSet;
import
java.util.Set
;
import
java.util.Set
;
import
javax.tools.JavaFileObject
;
import
javax.tools.JavaFileObject
;
import
com.sun.tools.javac.code.Lint.LintCategory
;
import
com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition
;
import
com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition
;
...
@@ -105,13 +106,16 @@ public class MandatoryWarningHandler {
...
@@ -105,13 +106,16 @@ public class MandatoryWarningHandler {
* True if mandatory warnings and notes are being enforced.
* True if mandatory warnings and notes are being enforced.
* @param prefix A common prefix for the set of message keys for
* @param prefix A common prefix for the set of message keys for
* the messages that may be generated.
* the messages that may be generated.
* @param lc An associated lint category for the warnings, or null if none.
*/
*/
public
MandatoryWarningHandler
(
Log
log
,
boolean
verbose
,
public
MandatoryWarningHandler
(
Log
log
,
boolean
verbose
,
boolean
enforceMandatory
,
String
prefix
)
{
boolean
enforceMandatory
,
String
prefix
,
LintCategory
lc
)
{
this
.
log
=
log
;
this
.
log
=
log
;
this
.
verbose
=
verbose
;
this
.
verbose
=
verbose
;
this
.
prefix
=
prefix
;
this
.
prefix
=
prefix
;
this
.
enforceMandatory
=
enforceMandatory
;
this
.
enforceMandatory
=
enforceMandatory
;
this
.
lintCategory
=
lc
;
}
}
/**
/**
...
@@ -234,16 +238,23 @@ public class MandatoryWarningHandler {
...
@@ -234,16 +238,23 @@ public class MandatoryWarningHandler {
*/
*/
private
final
boolean
enforceMandatory
;
private
final
boolean
enforceMandatory
;
/**
* A LintCategory to be included in point-of-use diagnostics to indicate
* how messages might be suppressed (i.e. with @SuppressWarnings).
*/
private
final
LintCategory
lintCategory
;
/**
/**
* Reports a mandatory warning to the log. If mandatory warnings
* Reports a mandatory warning to the log. If mandatory warnings
* are not being enforced, treat this as an ordinary warning.
* are not being enforced, treat this as an ordinary warning.
*/
*/
private
void
logMandatoryWarning
(
DiagnosticPosition
pos
,
String
msg
,
private
void
logMandatoryWarning
(
DiagnosticPosition
pos
,
String
msg
,
Object
...
args
)
{
Object
...
args
)
{
// Note: the following log methods are safe if lintCategory is null.
if
(
enforceMandatory
)
if
(
enforceMandatory
)
log
.
mandatoryWarning
(
pos
,
msg
,
args
);
log
.
mandatoryWarning
(
lintCategory
,
pos
,
msg
,
args
);
else
else
log
.
warning
(
pos
,
msg
,
args
);
log
.
warning
(
lintCategory
,
pos
,
msg
,
args
);
}
}
/**
/**
...
...
test/tools/javac/diags/examples/CountWarn.java
浏览文件 @
4b9418e2
...
@@ -23,6 +23,7 @@
...
@@ -23,6 +23,7 @@
// key: compiler.misc.count.warn
// key: compiler.misc.count.warn
// key: compiler.warn.warning
// key: compiler.warn.warning
// key: compiler.warn.lintOption
// key: compiler.warn.prob.found.req
// key: compiler.warn.prob.found.req
// key: compiler.misc.unchecked.assign
// key: compiler.misc.unchecked.assign
// options: -Xlint:unchecked
// options: -Xlint:unchecked
...
...
test/tools/javac/diags/examples/CountWarnPlural.java
浏览文件 @
4b9418e2
...
@@ -23,6 +23,7 @@
...
@@ -23,6 +23,7 @@
// key: compiler.misc.count.warn.plural
// key: compiler.misc.count.warn.plural
// key: compiler.warn.warning
// key: compiler.warn.warning
// key: compiler.warn.lintOption
// key: compiler.warn.prob.found.req
// key: compiler.warn.prob.found.req
// key: compiler.misc.unchecked.assign
// key: compiler.misc.unchecked.assign
// options: -Xlint:unchecked
// options: -Xlint:unchecked
...
...
test/tools/javac/diags/examples/Error.java
浏览文件 @
4b9418e2
...
@@ -25,6 +25,7 @@
...
@@ -25,6 +25,7 @@
// key: compiler.err.warnings.and.werror
// key: compiler.err.warnings.and.werror
// key: compiler.warn.raw.class.use
// key: compiler.warn.raw.class.use
// key: compiler.warn.warning
// key: compiler.warn.warning
// key: compiler.warn.lintOption
// key: compiler.misc.count.error
// key: compiler.misc.count.error
// key: compiler.misc.count.warn
// key: compiler.misc.count.warn
// key: compiler.misc.kindname.interface
// key: compiler.misc.kindname.interface
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录