Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell11
提交
18c5f1f2
D
dragonwell11
项目概览
openanolis
/
dragonwell11
通知
7
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dragonwell11
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
18c5f1f2
编写于
6月 24, 2009
作者:
T
tbell
浏览文件
操作
浏览文件
下载
差异文件
Merge
上级
6b1a4008
fd35e834
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
471 addition
and
235 deletion
+471
-235
langtools/src/share/classes/com/sun/tools/javac/code/Kinds.java
...ols/src/share/classes/com/sun/tools/javac/code/Kinds.java
+9
-2
langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java
...ools/src/share/classes/com/sun/tools/javac/comp/Attr.java
+2
-2
langtools/src/share/classes/com/sun/tools/javac/comp/Resolve.java
...s/src/share/classes/com/sun/tools/javac/comp/Resolve.java
+335
-217
langtools/src/share/classes/com/sun/tools/javac/util/AbstractDiagnosticFormatter.java
...com/sun/tools/javac/util/AbstractDiagnosticFormatter.java
+1
-1
langtools/src/share/classes/com/sun/tools/javac/util/AbstractLog.java
...c/share/classes/com/sun/tools/javac/util/AbstractLog.java
+1
-1
langtools/src/share/classes/com/sun/tools/javac/util/DiagnosticSource.java
...re/classes/com/sun/tools/javac/util/DiagnosticSource.java
+12
-1
langtools/src/share/classes/com/sun/tools/javac/util/JCDiagnostic.java
.../share/classes/com/sun/tools/javac/util/JCDiagnostic.java
+21
-7
langtools/src/share/classes/com/sun/tools/javac/util/RichDiagnosticFormatter.java
...ses/com/sun/tools/javac/util/RichDiagnosticFormatter.java
+24
-4
langtools/test/tools/javac/api/6852595/T6852595.java
langtools/test/tools/javac/api/6852595/T6852595.java
+66
-0
未找到文件。
langtools/src/share/classes/com/sun/tools/javac/code/Kinds.java
浏览文件 @
18c5f1f2
...
@@ -95,6 +95,7 @@ public class Kinds {
...
@@ -95,6 +95,7 @@ public class Kinds {
ANNOTATION
(
"kindname.interface"
),
ANNOTATION
(
"kindname.interface"
),
CONSTRUCTOR
(
"kindname.constructor"
),
CONSTRUCTOR
(
"kindname.constructor"
),
INTERFACE
(
"kindname.interface"
),
INTERFACE
(
"kindname.interface"
),
ENUM
(
"kindname.enum"
),
STATIC
(
"kindname.static"
),
STATIC
(
"kindname.static"
),
TYPEVAR
(
"kindname.type.variable"
),
TYPEVAR
(
"kindname.type.variable"
),
BOUND
(
"kindname.type.variable.bound"
),
BOUND
(
"kindname.type.variable.bound"
),
...
@@ -145,11 +146,15 @@ public class Kinds {
...
@@ -145,11 +146,15 @@ public class Kinds {
return
KindName
.
PACKAGE
;
return
KindName
.
PACKAGE
;
case
ENUM:
case
ENUM:
return
KindName
.
ENUM
;
case
ANNOTATION_TYPE:
case
ANNOTATION_TYPE:
case
INTERFACE:
case
CLASS:
case
CLASS:
return
KindName
.
CLASS
;
return
KindName
.
CLASS
;
case
INTERFACE:
return
KindName
.
INTERFACE
;
case
TYPE_PARAMETER:
case
TYPE_PARAMETER:
return
KindName
.
TYPEVAR
;
return
KindName
.
TYPEVAR
;
...
@@ -160,8 +165,10 @@ public class Kinds {
...
@@ -160,8 +165,10 @@ public class Kinds {
case
EXCEPTION_PARAMETER:
case
EXCEPTION_PARAMETER:
return
KindName
.
VAR
;
return
KindName
.
VAR
;
case
METHOD:
case
CONSTRUCTOR:
case
CONSTRUCTOR:
return
KindName
.
CONSTRUCTOR
;
case
METHOD:
case
STATIC_INIT:
case
STATIC_INIT:
case
INSTANCE_INIT:
case
INSTANCE_INIT:
return
KindName
.
METHOD
;
return
KindName
.
METHOD
;
...
...
langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java
浏览文件 @
18c5f1f2
...
@@ -303,7 +303,7 @@ public class Attr extends JCTree.Visitor {
...
@@ -303,7 +303,7 @@ public class Attr extends JCTree.Visitor {
public
Env
<
AttrContext
>
attribExprToTree
(
JCTree
expr
,
Env
<
AttrContext
>
env
,
JCTree
tree
)
{
public
Env
<
AttrContext
>
attribExprToTree
(
JCTree
expr
,
Env
<
AttrContext
>
env
,
JCTree
tree
)
{
breakTree
=
tree
;
breakTree
=
tree
;
JavaFileObject
prev
=
log
.
useSource
(
null
);
JavaFileObject
prev
=
log
.
useSource
(
env
.
toplevel
.
sourcefile
);
try
{
try
{
attribExpr
(
expr
,
env
);
attribExpr
(
expr
,
env
);
}
catch
(
BreakAttr
b
)
{
}
catch
(
BreakAttr
b
)
{
...
@@ -317,7 +317,7 @@ public class Attr extends JCTree.Visitor {
...
@@ -317,7 +317,7 @@ public class Attr extends JCTree.Visitor {
public
Env
<
AttrContext
>
attribStatToTree
(
JCTree
stmt
,
Env
<
AttrContext
>
env
,
JCTree
tree
)
{
public
Env
<
AttrContext
>
attribStatToTree
(
JCTree
stmt
,
Env
<
AttrContext
>
env
,
JCTree
tree
)
{
breakTree
=
tree
;
breakTree
=
tree
;
JavaFileObject
prev
=
log
.
useSource
(
null
);
JavaFileObject
prev
=
log
.
useSource
(
env
.
toplevel
.
sourcefile
);
try
{
try
{
attribStat
(
stmt
,
env
);
attribStat
(
stmt
,
env
);
}
catch
(
BreakAttr
b
)
{
}
catch
(
BreakAttr
b
)
{
...
...
langtools/src/share/classes/com/sun/tools/javac/comp/Resolve.java
浏览文件 @
18c5f1f2
...
@@ -82,15 +82,15 @@ public class Resolve {
...
@@ -82,15 +82,15 @@ public class Resolve {
syms
=
Symtab
.
instance
(
context
);
syms
=
Symtab
.
instance
(
context
);
varNotFound
=
new
varNotFound
=
new
ResolveError
(
ABSENT_VAR
,
syms
.
errSymbol
,
"variable not found"
);
SymbolNotFoundError
(
ABSENT_VAR
);
wrongMethod
=
new
wrongMethod
=
new
ResolveError
(
WRONG_MTH
,
syms
.
errSymbol
,
"method not found"
);
InapplicableSymbolError
(
syms
.
errSymbol
);
wrongMethods
=
new
wrongMethods
=
new
ResolveError
(
WRONG_MTHS
,
syms
.
errSymbol
,
"wrong methods"
);
InapplicableSymbolsError
(
syms
.
errSymbol
);
methodNotFound
=
new
methodNotFound
=
new
ResolveError
(
ABSENT_MTH
,
syms
.
errSymbol
,
"method not found"
);
SymbolNotFoundError
(
ABSENT_MTH
);
typeNotFound
=
new
typeNotFound
=
new
ResolveError
(
ABSENT_TYP
,
syms
.
errSymbol
,
"type not found"
);
SymbolNotFoundError
(
ABSENT_TYP
);
names
=
Names
.
instance
(
context
);
names
=
Names
.
instance
(
context
);
log
=
Log
.
instance
(
context
);
log
=
Log
.
instance
(
context
);
...
@@ -110,11 +110,11 @@ public class Resolve {
...
@@ -110,11 +110,11 @@ public class Resolve {
/** error symbols, which are returned when resolution fails
/** error symbols, which are returned when resolution fails
*/
*/
final
Resolve
Error
varNotFound
;
final
SymbolNotFound
Error
varNotFound
;
final
Resolve
Error
wrongMethod
;
final
InapplicableSymbol
Error
wrongMethod
;
final
Resolve
Error
wrongMethods
;
final
InapplicableSymbols
Error
wrongMethods
;
final
Resolve
Error
methodNotFound
;
final
SymbolNotFound
Error
methodNotFound
;
final
Resolve
Error
typeNotFound
;
final
SymbolNotFound
Error
typeNotFound
;
/* ************************************************************************
/* ************************************************************************
* Identifier resolution
* Identifier resolution
...
@@ -710,13 +710,13 @@ public class Resolve {
...
@@ -710,13 +710,13 @@ public class Resolve {
return
new
AmbiguityError
(
m1
,
m2
);
return
new
AmbiguityError
(
m1
,
m2
);
case
AMBIGUOUS:
case
AMBIGUOUS:
AmbiguityError
e
=
(
AmbiguityError
)
m2
;
AmbiguityError
e
=
(
AmbiguityError
)
m2
;
Symbol
err1
=
mostSpecific
(
m1
,
e
.
sym
1
,
env
,
site
,
allowBoxing
,
useVarargs
);
Symbol
err1
=
mostSpecific
(
m1
,
e
.
sym
,
env
,
site
,
allowBoxing
,
useVarargs
);
Symbol
err2
=
mostSpecific
(
m1
,
e
.
sym2
,
env
,
site
,
allowBoxing
,
useVarargs
);
Symbol
err2
=
mostSpecific
(
m1
,
e
.
sym2
,
env
,
site
,
allowBoxing
,
useVarargs
);
if
(
err1
==
err2
)
return
err1
;
if
(
err1
==
err2
)
return
err1
;
if
(
err1
==
e
.
sym
1
&&
err2
==
e
.
sym2
)
return
m2
;
if
(
err1
==
e
.
sym
&&
err2
==
e
.
sym2
)
return
m2
;
if
(
err1
instanceof
AmbiguityError
&&
if
(
err1
instanceof
AmbiguityError
&&
err2
instanceof
AmbiguityError
&&
err2
instanceof
AmbiguityError
&&
((
AmbiguityError
)
err1
).
sym
1
==
((
AmbiguityError
)
err2
).
sym1
)
((
AmbiguityError
)
err1
).
sym
==
((
AmbiguityError
)
err2
).
sym
)
return
new
AmbiguityError
(
m1
,
m2
);
return
new
AmbiguityError
(
m1
,
m2
);
else
else
return
new
AmbiguityError
(
err1
,
err2
);
return
new
AmbiguityError
(
err1
,
err2
);
...
@@ -1192,18 +1192,12 @@ public class Resolve {
...
@@ -1192,18 +1192,12 @@ public class Resolve {
List
<
Type
>
argtypes
,
List
<
Type
>
argtypes
,
List
<
Type
>
typeargtypes
)
{
List
<
Type
>
typeargtypes
)
{
if
(
sym
.
kind
>=
AMBIGUOUS
)
{
if
(
sym
.
kind
>=
AMBIGUOUS
)
{
// printscopes(site.tsym.members());//DEBUG
ResolveError
errSym
=
(
ResolveError
)
sym
;
if
(!
site
.
isErroneous
()
&&
if
(!
site
.
isErroneous
()
&&
!
Type
.
isErroneous
(
argtypes
)
&&
!
Type
.
isErroneous
(
argtypes
)
&&
(
typeargtypes
==
null
||
!
Type
.
isErroneous
(
typeargtypes
)))
(
typeargtypes
==
null
||
!
Type
.
isErroneous
(
typeargtypes
)))
((
ResolveError
)
sym
).
report
(
log
,
pos
,
site
,
name
,
argtypes
,
typeargtypes
);
logResolveError
(
errSym
,
pos
,
site
,
name
,
argtypes
,
typeargtypes
);
do
{
sym
=
errSym
.
access
(
name
,
qualified
?
site
.
tsym
:
syms
.
noSymbol
);
sym
=
((
ResolveError
)
sym
).
sym
;
}
while
(
sym
.
kind
>=
AMBIGUOUS
);
if
(
sym
==
syms
.
errSymbol
// preserve the symbol name through errors
||
((
sym
.
kind
&
ERRONEOUS
)
==
0
// make sure an error symbol is returned
&&
(
sym
.
kind
&
TYP
)
!=
0
))
sym
=
types
.
createErrorType
(
name
,
qualified
?
site
.
tsym
:
syms
.
noSymbol
,
sym
.
type
).
tsym
;
}
}
return
sym
;
return
sym
;
}
}
...
@@ -1583,7 +1577,19 @@ public class Resolve {
...
@@ -1583,7 +1577,19 @@ public class Resolve {
public
void
logAccessError
(
Env
<
AttrContext
>
env
,
JCTree
tree
,
Type
type
)
{
public
void
logAccessError
(
Env
<
AttrContext
>
env
,
JCTree
tree
,
Type
type
)
{
AccessError
error
=
new
AccessError
(
env
,
type
.
getEnclosingType
(),
type
.
tsym
);
AccessError
error
=
new
AccessError
(
env
,
type
.
getEnclosingType
(),
type
.
tsym
);
error
.
report
(
log
,
tree
.
pos
(),
type
.
getEnclosingType
(),
null
,
null
,
null
);
logResolveError
(
error
,
tree
.
pos
(),
type
.
getEnclosingType
(),
null
,
null
,
null
);
}
//where
private
void
logResolveError
(
ResolveError
error
,
DiagnosticPosition
pos
,
Type
site
,
Name
name
,
List
<
Type
>
argtypes
,
List
<
Type
>
typeargtypes
)
{
JCDiagnostic
d
=
error
.
getDiagnostic
(
JCDiagnostic
.
DiagnosticType
.
ERROR
,
pos
,
site
,
name
,
argtypes
,
typeargtypes
);
if
(
d
!=
null
)
log
.
report
(
d
);
}
}
private
final
LocalizedString
noArgs
=
new
LocalizedString
(
"compiler.misc.no.args"
);
private
final
LocalizedString
noArgs
=
new
LocalizedString
(
"compiler.misc.no.args"
);
...
@@ -1592,164 +1598,280 @@ public class Resolve {
...
@@ -1592,164 +1598,280 @@ public class Resolve {
return
argtypes
.
isEmpty
()
?
noArgs
:
argtypes
;
return
argtypes
.
isEmpty
()
?
noArgs
:
argtypes
;
}
}
/** Root class for resolve errors.
/**
* Instances of this class indicate "Symbol not found".
* Root class for resolution errors. Subclass of ResolveError
* Instances of subclass indicate other errors.
* represent a different kinds of resolution error - as such they must
* specify how they map into concrete compiler diagnostics.
*/
*/
private
class
ResolveError
extends
Symbol
{
private
abstract
class
ResolveError
extends
Symbol
{
/** The name of the kind of error, for debugging only. */
final
String
debugName
;
ResolveError
(
int
kind
,
S
ymbol
sym
,
S
tring
debugName
)
{
ResolveError
(
int
kind
,
String
debugName
)
{
super
(
kind
,
0
,
null
,
null
,
null
);
super
(
kind
,
0
,
null
,
null
,
null
);
this
.
debugName
=
debugName
;
this
.
debugName
=
debugName
;
this
.
sym
=
sym
;
}
}
/** The name of the kind of error, for debugging only.
@Override
*/
final
String
debugName
;
/** The symbol that was determined by resolution, or errSymbol if none
* was found.
*/
final
Symbol
sym
;
/** The symbol that was a close mismatch, or null if none was found.
* wrongSym is currently set if a simgle method with the correct name, but
* the wrong parameters was found.
*/
Symbol
wrongSym
;
/** An auxiliary explanation set in case of instantiation errors.
*/
JCDiagnostic
explanation
;
public
<
R
,
P
>
R
accept
(
ElementVisitor
<
R
,
P
>
v
,
P
p
)
{
public
<
R
,
P
>
R
accept
(
ElementVisitor
<
R
,
P
>
v
,
P
p
)
{
throw
new
AssertionError
();
throw
new
AssertionError
();
}
}
/** Print the (debug only) name of the kind of error.
@Override
*/
public
String
toString
()
{
public
String
toString
()
{
return
debugName
+
" wrongSym="
+
wrongSym
+
" explanation="
+
explanation
;
return
debugName
;
}
}
/** Update wrongSym and explanation and return this.
@Override
*/
public
boolean
exists
()
{
ResolveError
setWrongSym
(
Symbol
sym
,
JCDiagnostic
explanation
)
{
return
false
;
this
.
wrongSym
=
sym
;
this
.
explanation
=
explanation
;
return
this
;
}
}
/** Update wrongSym and return this.
/**
* Create an external representation for this erroneous symbol to be
* used during attribution - by default this returns the symbol of a
* brand new error type which stores the original type found
* during resolution.
*
* @param name the name used during resolution
* @param location the location from which the symbol is accessed
*/
*/
ResolveError
setWrongSym
(
Symbol
sym
)
{
protected
Symbol
access
(
Name
name
,
TypeSymbol
location
)
{
this
.
wrongSym
=
sym
;
return
types
.
createErrorType
(
name
,
location
,
syms
.
errSymbol
.
type
).
tsym
;
this
.
explanation
=
null
;
}
return
this
;
/**
* Create a diagnostic representing this resolution error.
*
* @param dkind The kind of the diagnostic to be created (e.g error).
* @param pos The position to be used for error reporting.
* @param site The original type from where the selection took place.
* @param name The name of the symbol to be resolved.
* @param argtypes The invocation's value arguments,
* if we looked for a method.
* @param typeargtypes The invocation's type arguments,
* if we looked for a method.
*/
abstract
JCDiagnostic
getDiagnostic
(
JCDiagnostic
.
DiagnosticType
dkind
,
DiagnosticPosition
pos
,
Type
site
,
Name
name
,
List
<
Type
>
argtypes
,
List
<
Type
>
typeargtypes
);
/**
* A name designates an operator if it consists
* of a non-empty sequence of operator symbols +-~!/*%&|^<>=
*/
boolean
isOperator
(
Name
name
)
{
int
i
=
0
;
while
(
i
<
name
.
getByteLength
()
&&
"+-~!*/%&|^<>="
.
indexOf
(
name
.
getByteAt
(
i
))
>=
0
)
i
++;
return
i
>
0
&&
i
==
name
.
getByteLength
();
}
}
}
/**
* This class is the root class of all resolution errors caused by
* an invalid symbol being found during resolution.
*/
abstract
class
InvalidSymbolError
extends
ResolveError
{
/** The invalid symbol found during resolution */
Symbol
sym
;
InvalidSymbolError
(
int
kind
,
Symbol
sym
,
String
debugName
)
{
super
(
kind
,
debugName
);
this
.
sym
=
sym
;
}
@Override
public
boolean
exists
()
{
public
boolean
exists
()
{
switch
(
kind
)
{
return
true
;
case
HIDDEN:
case
ABSENT_VAR:
case
ABSENT_MTH:
case
ABSENT_TYP:
return
false
;
default
:
return
true
;
}
}
}
/** Report error.
@Override
* @param log The error log to be used for error reporting.
public
String
toString
()
{
* @param pos The position to be used for error reporting.
return
super
.
toString
()
+
" wrongSym="
+
sym
;
* @param site The original type from where the selection took place.
}
* @param name The name of the symbol to be resolved.
* @param argtypes The invocation's value arguments,
@Override
* if we looked for a method.
public
Symbol
access
(
Name
name
,
TypeSymbol
location
)
{
* @param typeargtypes The invocation's type arguments,
if
(
sym
.
kind
>=
AMBIGUOUS
)
* if we looked for a method.
return
((
ResolveError
)
sym
).
access
(
name
,
location
);
*/
else
if
((
sym
.
kind
&
ERRONEOUS
)
==
0
&&
(
sym
.
kind
&
TYP
)
!=
0
)
void
report
(
Log
log
,
DiagnosticPosition
pos
,
Type
site
,
Name
name
,
return
types
.
createErrorType
(
name
,
location
,
sym
.
type
).
tsym
;
List
<
Type
>
argtypes
,
List
<
Type
>
typeargtypes
)
{
else
if
(
argtypes
==
null
)
return
sym
;
argtypes
=
List
.
nil
();
}
if
(
typeargtypes
==
null
)
}
typeargtypes
=
List
.
nil
();
if
(
name
!=
names
.
error
)
{
/**
KindName
kindname
=
absentKind
(
kind
);
* InvalidSymbolError error class indicating that a symbol matching a
Name
idname
=
name
;
* given name does not exists in a given site.
if
(
kind
>=
WRONG_MTHS
&&
kind
<=
ABSENT_MTH
)
{
*/
if
(
isOperator
(
name
))
{
class
SymbolNotFoundError
extends
ResolveError
{
log
.
error
(
pos
,
"operator.cant.be.applied"
,
name
,
argtypes
);
SymbolNotFoundError
(
int
kind
)
{
return
;
super
(
kind
,
"symbol not found error"
);
}
}
if
(
name
==
names
.
init
)
{
kindname
=
KindName
.
CONSTRUCTOR
;
@Override
idname
=
site
.
tsym
.
name
;
JCDiagnostic
getDiagnostic
(
JCDiagnostic
.
DiagnosticType
dkind
,
}
DiagnosticPosition
pos
,
}
Type
site
,
if
(
kind
==
WRONG_MTH
)
{
Name
name
,
Symbol
ws
=
wrongSym
.
asMemberOf
(
site
,
types
);
List
<
Type
>
argtypes
,
log
.
error
(
pos
,
List
<
Type
>
typeargtypes
)
{
"cant.apply.symbol"
+
(
explanation
!=
null
?
".1"
:
""
),
argtypes
=
argtypes
==
null
?
List
.<
Type
>
nil
()
:
argtypes
;
kindname
,
typeargtypes
=
typeargtypes
==
null
?
List
.<
Type
>
nil
()
:
typeargtypes
;
ws
.
name
==
names
.
init
?
ws
.
owner
.
name
:
ws
.
name
,
if
(
name
==
names
.
error
)
methodArguments
(
ws
.
type
.
getParameterTypes
()),
return
null
;
methodArguments
(
argtypes
),
kindName
(
ws
.
owner
),
if
(
isOperator
(
name
))
{
ws
.
owner
.
type
,
return
diags
.
create
(
dkind
,
false
,
log
.
currentSource
(),
pos
,
explanation
);
"operator.cant.be.applied"
,
name
,
argtypes
);
}
else
if
(!
site
.
tsym
.
name
.
isEmpty
())
{
}
if
(
site
.
tsym
.
kind
==
PCK
&&
!
site
.
tsym
.
exists
())
boolean
hasLocation
=
false
;
log
.
error
(
pos
,
"doesnt.exist"
,
site
.
tsym
);
if
(!
site
.
tsym
.
name
.
isEmpty
())
{
else
{
if
(
site
.
tsym
.
kind
==
PCK
&&
!
site
.
tsym
.
exists
())
{
String
errKey
=
getErrorKey
(
"cant.resolve.location"
,
return
diags
.
create
(
dkind
,
false
,
log
.
currentSource
(),
pos
,
argtypes
,
typeargtypes
,
"doesnt.exist"
,
site
.
tsym
);
kindname
);
log
.
error
(
pos
,
errKey
,
kindname
,
idname
,
//symbol kindname, name
typeargtypes
,
argtypes
,
//type parameters and arguments (if any)
typeKindName
(
site
),
site
);
//location kindname, type
}
}
else
{
String
errKey
=
getErrorKey
(
"cant.resolve"
,
argtypes
,
typeargtypes
,
kindname
);
log
.
error
(
pos
,
errKey
,
kindname
,
idname
,
//symbol kindname, name
typeargtypes
,
argtypes
);
//type parameters and arguments (if any)
}
}
hasLocation
=
true
;
}
boolean
isConstructor
=
kind
==
ABSENT_MTH
&&
name
==
names
.
table
.
names
.
init
;
KindName
kindname
=
isConstructor
?
KindName
.
CONSTRUCTOR
:
absentKind
(
kind
);
Name
idname
=
isConstructor
?
site
.
tsym
.
name
:
name
;
String
errKey
=
getErrorKey
(
kindname
,
typeargtypes
.
nonEmpty
(),
hasLocation
);
if
(
hasLocation
)
{
return
diags
.
create
(
dkind
,
false
,
log
.
currentSource
(),
pos
,
errKey
,
kindname
,
idname
,
//symbol kindname, name
typeargtypes
,
argtypes
,
//type parameters and arguments (if any)
typeKindName
(
site
),
site
);
//location kindname, type
}
else
{
return
diags
.
create
(
dkind
,
false
,
log
.
currentSource
(),
pos
,
errKey
,
kindname
,
idname
,
//symbol kindname, name
typeargtypes
,
argtypes
);
//type parameters and arguments (if any)
}
}
}
}
//where
//where
String
getErrorKey
(
String
key
,
List
<
Type
>
argtypes
,
List
<
Type
>
typeargtypes
,
KindName
kindname
)
{
private
String
getErrorKey
(
KindName
kindname
,
boolean
hasTypeArgs
,
boolean
hasLocation
)
{
String
suffix
=
""
;
String
key
=
"cant.resolve"
;
String
suffix
=
hasLocation
?
".location"
:
""
;
switch
(
kindname
)
{
switch
(
kindname
)
{
case
METHOD:
case
METHOD:
case
CONSTRUCTOR:
{
case
CONSTRUCTOR:
{
suffix
+=
".args"
;
suffix
+=
".args"
;
suffix
+=
typeargtypes
.
nonEmpty
()
?
".params"
:
""
;
suffix
+=
hasTypeArgs
?
".params"
:
""
;
}
}
}
}
return
key
+
suffix
;
return
key
+
suffix
;
}
}
}
/**
* InvalidSymbolError error class indicating that a given symbol
* (either a method, a constructor or an operand) is not applicable
* given an actual arguments/type argument list.
*/
class
InapplicableSymbolError
extends
InvalidSymbolError
{
/** An auxiliary explanation set in case of instantiation errors. */
JCDiagnostic
explanation
;
InapplicableSymbolError
(
Symbol
sym
)
{
super
(
WRONG_MTH
,
sym
,
"inapplicable symbol error"
);
}
/** A name designates an operator if it consists
/** Update sym and explanation and return this.
* of a non-empty sequence of operator symbols +-~!/*%&|^<>=
*/
*/
boolean
isOperator
(
Name
name
)
{
InapplicableSymbolError
setWrongSym
(
Symbol
sym
,
JCDiagnostic
explanation
)
{
int
i
=
0
;
this
.
sym
=
sym
;
while
(
i
<
name
.
getByteLength
()
&&
this
.
explanation
=
explanation
;
"+-~!*/%&|^<>="
.
indexOf
(
name
.
getByteAt
(
i
))
>=
0
)
i
++;
return
this
;
return
i
>
0
&&
i
==
name
.
getByteLength
();
}
/** Update sym and return this.
*/
InapplicableSymbolError
setWrongSym
(
Symbol
sym
)
{
this
.
sym
=
sym
;
this
.
explanation
=
null
;
return
this
;
}
@Override
public
String
toString
()
{
return
super
.
toString
()
+
" explanation="
+
explanation
;
}
@Override
JCDiagnostic
getDiagnostic
(
JCDiagnostic
.
DiagnosticType
dkind
,
DiagnosticPosition
pos
,
Type
site
,
Name
name
,
List
<
Type
>
argtypes
,
List
<
Type
>
typeargtypes
)
{
if
(
name
==
names
.
error
)
return
null
;
if
(
isOperator
(
name
))
{
return
diags
.
create
(
dkind
,
false
,
log
.
currentSource
(),
pos
,
"operator.cant.be.applied"
,
name
,
argtypes
);
}
else
{
Symbol
ws
=
sym
.
asMemberOf
(
site
,
types
);
return
diags
.
create
(
dkind
,
false
,
log
.
currentSource
(),
pos
,
"cant.apply.symbol"
+
(
explanation
!=
null
?
".1"
:
""
),
kindName
(
ws
),
ws
.
name
==
names
.
init
?
ws
.
owner
.
name
:
ws
.
name
,
methodArguments
(
ws
.
type
.
getParameterTypes
()),
methodArguments
(
argtypes
),
kindName
(
ws
.
owner
),
ws
.
owner
.
type
,
explanation
);
}
}
@Override
public
Symbol
access
(
Name
name
,
TypeSymbol
location
)
{
return
types
.
createErrorType
(
name
,
location
,
syms
.
errSymbol
.
type
).
tsym
;
}
}
/**
* ResolveError error class indicating that a set of symbols
* (either methods, constructors or operands) is not applicable
* given an actual arguments/type argument list.
*/
class
InapplicableSymbolsError
extends
ResolveError
{
InapplicableSymbolsError
(
Symbol
sym
)
{
super
(
WRONG_MTHS
,
"inapplicable symbols"
);
}
@Override
JCDiagnostic
getDiagnostic
(
JCDiagnostic
.
DiagnosticType
dkind
,
DiagnosticPosition
pos
,
Type
site
,
Name
name
,
List
<
Type
>
argtypes
,
List
<
Type
>
typeargtypes
)
{
return
new
SymbolNotFoundError
(
ABSENT_MTH
).
getDiagnostic
(
dkind
,
pos
,
site
,
name
,
argtypes
,
typeargtypes
);
}
}
}
}
/** Resolve error class indicating that a symbol is not accessible.
/**
* An InvalidSymbolError error class indicating that a symbol is not
* accessible from a given site
*/
*/
class
AccessError
extends
ResolveError
{
class
AccessError
extends
InvalidSymbolError
{
private
Env
<
AttrContext
>
env
;
private
Type
site
;
AccessError
(
Symbol
sym
)
{
AccessError
(
Symbol
sym
)
{
this
(
null
,
null
,
sym
);
this
(
null
,
null
,
sym
);
...
@@ -1763,111 +1885,107 @@ public class Resolve {
...
@@ -1763,111 +1885,107 @@ public class Resolve {
log
.
error
(
"proc.messager"
,
sym
+
" @ "
+
site
+
" is inaccessible."
);
log
.
error
(
"proc.messager"
,
sym
+
" @ "
+
site
+
" is inaccessible."
);
}
}
private
Env
<
AttrContext
>
env
;
@Override
private
Type
site
;
public
boolean
exists
()
{
return
false
;
}
/** Report error.
@Override
* @param log The error log to be used for error reporting.
JCDiagnostic
getDiagnostic
(
JCDiagnostic
.
DiagnosticType
dkind
,
* @param pos The position to be used for error reporting.
DiagnosticPosition
pos
,
* @param site The original type from where the selection took place.
Type
site
,
* @param name The name of the symbol to be resolved.
Name
name
,
* @param argtypes The invocation's value arguments,
List
<
Type
>
argtypes
,
* if we looked for a method.
List
<
Type
>
typeargtypes
)
{
* @param typeargtypes The invocation's type arguments,
if
(
sym
.
owner
.
type
.
tag
==
ERROR
)
* if we looked for a method.
return
null
;
*/
void
report
(
Log
log
,
DiagnosticPosition
pos
,
Type
site
,
Name
name
,
if
(
sym
.
name
==
names
.
init
&&
sym
.
owner
!=
site
.
tsym
)
{
List
<
Type
>
argtypes
,
List
<
Type
>
typeargtypes
)
{
return
new
SymbolNotFoundError
(
ABSENT_MTH
).
getDiagnostic
(
dkind
,
if
(
sym
.
owner
.
type
.
tag
!=
ERROR
)
{
pos
,
site
,
name
,
argtypes
,
typeargtypes
);
if
(
sym
.
name
==
names
.
init
&&
sym
.
owner
!=
site
.
tsym
)
}
new
ResolveError
(
ABSENT_MTH
,
sym
.
owner
,
"absent method "
+
sym
).
report
(
else
if
((
sym
.
flags
()
&
PUBLIC
)
!=
0
log
,
pos
,
site
,
name
,
argtypes
,
typeargtypes
);
||
(
env
!=
null
&&
this
.
site
!=
null
if
((
sym
.
flags
()
&
PUBLIC
)
!=
0
&&
!
isAccessible
(
env
,
this
.
site
)))
{
||
(
env
!=
null
&&
this
.
site
!=
null
return
diags
.
create
(
dkind
,
false
,
log
.
currentSource
(),
&&
!
isAccessible
(
env
,
this
.
site
)))
pos
,
"not.def.access.class.intf.cant.access"
,
log
.
error
(
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
)
{
log
.
error
(
pos
,
"report.access"
,
sym
,
return
diags
.
create
(
dkind
,
false
,
log
.
currentSource
(),
asFlagSet
(
sym
.
flags
()
&
(
PRIVATE
|
PROTECTED
)),
pos
,
"report.access"
,
sym
,
sym
.
location
());
asFlagSet
(
sym
.
flags
()
&
(
PRIVATE
|
PROTECTED
)),
else
sym
.
location
());
log
.
error
(
pos
,
"not.def.public.cant.access"
,
}
sym
,
sym
.
location
());
else
{
return
diags
.
create
(
dkind
,
false
,
log
.
currentSource
(),
pos
,
"not.def.public.cant.access"
,
sym
,
sym
.
location
());
}
}
}
}
}
}
/** Resolve error class indicating that an instance member was accessed
/**
* from a static context.
* InvalidSymbolError error class indicating that an instance member
* has erroneously been accessed from a static context.
*/
*/
class
StaticError
extends
ResolveError
{
class
StaticError
extends
InvalidSymbolError
{
StaticError
(
Symbol
sym
)
{
StaticError
(
Symbol
sym
)
{
super
(
STATICERR
,
sym
,
"static error"
);
super
(
STATICERR
,
sym
,
"static error"
);
}
}
/** Report error.
@Override
* @param log The error log to be used for error reporting.
JCDiagnostic
getDiagnostic
(
JCDiagnostic
.
DiagnosticType
dkind
,
* @param pos The position to be used for error reporting.
DiagnosticPosition
pos
,
* @param site The original type from where the selection took place.
Type
site
,
* @param name The name of the symbol to be resolved.
Name
name
,
* @param argtypes The invocation's value arguments,
List
<
Type
>
argtypes
,
* if we looked for a method.
List
<
Type
>
typeargtypes
)
{
* @param typeargtypes The invocation's type arguments,
* if we looked for a method.
*/
void
report
(
Log
log
,
DiagnosticPosition
pos
,
Type
site
,
Name
name
,
List
<
Type
>
argtypes
,
List
<
Type
>
typeargtypes
)
{
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
);
log
.
error
(
pos
,
"non-static.cant.be.ref"
,
return
diags
.
create
(
dkind
,
false
,
log
.
currentSource
(),
pos
,
kindName
(
sym
),
errSym
);
"non-static.cant.be.ref"
,
kindName
(
sym
),
errSym
);
}
}
}
}
/** Resolve error class indicating an ambiguous reference.
/**
* InvalidSymbolError error class indicating that a pair of symbols
* (either methods, constructors or operands) are ambiguous
* given an actual arguments/type argument list.
*/
*/
class
AmbiguityError
extends
ResolveError
{
class
AmbiguityError
extends
InvalidSymbolError
{
Symbol
sym1
;
/** The other maximally specific symbol */
Symbol
sym2
;
Symbol
sym2
;
AmbiguityError
(
Symbol
sym1
,
Symbol
sym2
)
{
AmbiguityError
(
Symbol
sym1
,
Symbol
sym2
)
{
super
(
AMBIGUOUS
,
sym1
,
"ambiguity error"
);
super
(
AMBIGUOUS
,
sym1
,
"ambiguity error"
);
this
.
sym1
=
sym1
;
this
.
sym2
=
sym2
;
this
.
sym2
=
sym2
;
}
}
/** Report error.
@Override
* @param log The error log to be used for error reporting.
JCDiagnostic
getDiagnostic
(
JCDiagnostic
.
DiagnosticType
dkind
,
* @param pos The position to be used for error reporting.
DiagnosticPosition
pos
,
* @param site The original type from where the selection took place.
Type
site
,
* @param name The name of the symbol to be resolved.
Name
name
,
* @param argtypes The invocation's value arguments,
List
<
Type
>
argtypes
,
* if we looked for a method.
List
<
Type
>
typeargtypes
)
{
* @param typeargtypes The invocation's type arguments,
* if we looked for a method.
*/
void
report
(
Log
log
,
DiagnosticPosition
pos
,
Type
site
,
Name
name
,
List
<
Type
>
argtypes
,
List
<
Type
>
typeargtypes
)
{
AmbiguityError
pair
=
this
;
AmbiguityError
pair
=
this
;
while
(
true
)
{
while
(
true
)
{
if
(
pair
.
sym
1
.
kind
==
AMBIGUOUS
)
if
(
pair
.
sym
.
kind
==
AMBIGUOUS
)
pair
=
(
AmbiguityError
)
pair
.
sym
1
;
pair
=
(
AmbiguityError
)
pair
.
sym
;
else
if
(
pair
.
sym2
.
kind
==
AMBIGUOUS
)
else
if
(
pair
.
sym2
.
kind
==
AMBIGUOUS
)
pair
=
(
AmbiguityError
)
pair
.
sym2
;
pair
=
(
AmbiguityError
)
pair
.
sym2
;
else
break
;
else
break
;
}
}
Name
sname
=
pair
.
sym1
.
name
;
Name
sname
=
pair
.
sym
.
name
;
if
(
sname
==
names
.
init
)
sname
=
pair
.
sym1
.
owner
.
name
;
if
(
sname
==
names
.
init
)
sname
=
pair
.
sym
.
owner
.
name
;
log
.
error
(
pos
,
"ref.ambiguous"
,
sname
,
return
diags
.
create
(
dkind
,
false
,
log
.
currentSource
(),
kindName
(
pair
.
sym1
),
pos
,
"ref.ambiguous"
,
sname
,
pair
.
sym1
,
kindName
(
pair
.
sym
),
pair
.
sym1
.
location
(
site
,
types
),
pair
.
sym
,
pair
.
sym
.
location
(
site
,
types
),
kindName
(
pair
.
sym2
),
kindName
(
pair
.
sym2
),
pair
.
sym2
,
pair
.
sym2
,
pair
.
sym2
.
location
(
site
,
types
));
pair
.
sym2
.
location
(
site
,
types
));
...
...
langtools/src/share/classes/com/sun/tools/javac/util/AbstractDiagnosticFormatter.java
浏览文件 @
18c5f1f2
...
@@ -109,7 +109,7 @@ public abstract class AbstractDiagnosticFormatter implements DiagnosticFormatter
...
@@ -109,7 +109,7 @@ public abstract class AbstractDiagnosticFormatter implements DiagnosticFormatter
return
formatDiagnostic
(
d
,
locale
);
return
formatDiagnostic
(
d
,
locale
);
}
}
abstract
String
formatDiagnostic
(
JCDiagnostic
d
,
Locale
locale
);
protected
abstract
String
formatDiagnostic
(
JCDiagnostic
d
,
Locale
locale
);
public
String
formatPosition
(
JCDiagnostic
d
,
PositionKind
pk
,
Locale
l
)
{
public
String
formatPosition
(
JCDiagnostic
d
,
PositionKind
pk
,
Locale
l
)
{
assert
(
d
.
getPosition
()
!=
Position
.
NOPOS
);
assert
(
d
.
getPosition
()
!=
Position
.
NOPOS
);
...
...
langtools/src/share/classes/com/sun/tools/javac/util/AbstractLog.java
浏览文件 @
18c5f1f2
...
@@ -58,7 +58,7 @@ public abstract class AbstractLog {
...
@@ -58,7 +58,7 @@ public abstract class AbstractLog {
protected
DiagnosticSource
getSource
(
JavaFileObject
file
)
{
protected
DiagnosticSource
getSource
(
JavaFileObject
file
)
{
if
(
file
==
null
)
if
(
file
==
null
)
return
null
;
return
DiagnosticSource
.
NO_SOURCE
;
DiagnosticSource
s
=
sourceMap
.
get
(
file
);
DiagnosticSource
s
=
sourceMap
.
get
(
file
);
if
(
s
==
null
)
{
if
(
s
==
null
)
{
s
=
new
DiagnosticSource
(
file
,
this
);
s
=
new
DiagnosticSource
(
file
,
this
);
...
...
langtools/src/share/classes/com/sun/tools/javac/util/DiagnosticSource.java
浏览文件 @
18c5f1f2
...
@@ -46,11 +46,22 @@ import static com.sun.tools.javac.util.LayoutCharacters.*;
...
@@ -46,11 +46,22 @@ import static com.sun.tools.javac.util.LayoutCharacters.*;
* deletion without notice.</b>
* deletion without notice.</b>
*/
*/
public
class
DiagnosticSource
{
public
class
DiagnosticSource
{
/* constant DiagnosticSource to be used when sourcefile is missing */
public
static
final
DiagnosticSource
NO_SOURCE
=
new
DiagnosticSource
()
{
@Override
protected
boolean
findLine
(
int
pos
)
{
return
false
;
}
};
public
DiagnosticSource
(
JavaFileObject
fo
,
AbstractLog
log
)
{
public
DiagnosticSource
(
JavaFileObject
fo
,
AbstractLog
log
)
{
this
.
fileObject
=
fo
;
this
.
fileObject
=
fo
;
this
.
log
=
log
;
this
.
log
=
log
;
}
}
private
DiagnosticSource
()
{}
/** Return the underlying file object handled by this
/** Return the underlying file object handled by this
* DiagnosticSource object.
* DiagnosticSource object.
*/
*/
...
@@ -134,7 +145,7 @@ public class DiagnosticSource {
...
@@ -134,7 +145,7 @@ public class DiagnosticSource {
/** Find the line in the buffer that contains the current position
/** Find the line in the buffer that contains the current position
* @param pos Character offset into the buffer
* @param pos Character offset into the buffer
*/
*/
pr
ivate
boolean
findLine
(
int
pos
)
{
pr
otected
boolean
findLine
(
int
pos
)
{
if
(
pos
==
Position
.
NOPOS
)
if
(
pos
==
Position
.
NOPOS
)
return
false
;
return
false
;
...
...
langtools/src/share/classes/com/sun/tools/javac/util/JCDiagnostic.java
浏览文件 @
18c5f1f2
...
@@ -83,7 +83,7 @@ public class JCDiagnostic implements Diagnostic<JavaFileObject> {
...
@@ -83,7 +83,7 @@ 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
new
JCDiagnostic
(
formatter
,
ERROR
,
true
,
source
,
pos
,
qualify
(
ERROR
,
key
)
,
args
);
return
create
(
ERROR
,
true
,
source
,
pos
,
key
,
args
);
}
}
/**
/**
...
@@ -96,7 +96,7 @@ public class JCDiagnostic implements Diagnostic<JavaFileObject> {
...
@@ -96,7 +96,7 @@ public class JCDiagnostic implements Diagnostic<JavaFileObject> {
*/
*/
public
JCDiagnostic
mandatoryWarning
(
public
JCDiagnostic
mandatoryWarning
(
DiagnosticSource
source
,
DiagnosticPosition
pos
,
String
key
,
Object
...
args
)
{
DiagnosticSource
source
,
DiagnosticPosition
pos
,
String
key
,
Object
...
args
)
{
return
new
JCDiagnostic
(
formatter
,
WARNING
,
true
,
source
,
pos
,
qualify
(
WARNING
,
key
)
,
args
);
return
create
(
WARNING
,
true
,
source
,
pos
,
key
,
args
);
}
}
/**
/**
...
@@ -108,7 +108,7 @@ public class JCDiagnostic implements Diagnostic<JavaFileObject> {
...
@@ -108,7 +108,7 @@ public class JCDiagnostic implements Diagnostic<JavaFileObject> {
*/
*/
public
JCDiagnostic
warning
(
public
JCDiagnostic
warning
(
DiagnosticSource
source
,
DiagnosticPosition
pos
,
String
key
,
Object
...
args
)
{
DiagnosticSource
source
,
DiagnosticPosition
pos
,
String
key
,
Object
...
args
)
{
return
new
JCDiagnostic
(
formatter
,
WARNING
,
false
,
source
,
pos
,
qualify
(
WARNING
,
key
)
,
args
);
return
create
(
WARNING
,
false
,
source
,
pos
,
key
,
args
);
}
}
/**
/**
...
@@ -118,7 +118,7 @@ public class JCDiagnostic implements Diagnostic<JavaFileObject> {
...
@@ -118,7 +118,7 @@ public class JCDiagnostic implements Diagnostic<JavaFileObject> {
* @see MandatoryWarningHandler
* @see MandatoryWarningHandler
*/
*/
public
JCDiagnostic
mandatoryNote
(
DiagnosticSource
source
,
String
key
,
Object
...
args
)
{
public
JCDiagnostic
mandatoryNote
(
DiagnosticSource
source
,
String
key
,
Object
...
args
)
{
return
new
JCDiagnostic
(
formatter
,
NOTE
,
true
,
source
,
null
,
qualify
(
NOTE
,
key
)
,
args
);
return
create
(
NOTE
,
true
,
source
,
null
,
key
,
args
);
}
}
/**
/**
...
@@ -127,7 +127,7 @@ public class JCDiagnostic implements Diagnostic<JavaFileObject> {
...
@@ -127,7 +127,7 @@ public class JCDiagnostic implements Diagnostic<JavaFileObject> {
* @param args Fields of the error message.
* @param args Fields of the error message.
*/
*/
public
JCDiagnostic
note
(
String
key
,
Object
...
args
)
{
public
JCDiagnostic
note
(
String
key
,
Object
...
args
)
{
return
note
(
null
,
null
,
key
,
args
);
return
create
(
NOTE
,
false
,
null
,
null
,
key
,
args
);
}
}
/**
/**
...
@@ -139,7 +139,7 @@ public class JCDiagnostic implements Diagnostic<JavaFileObject> {
...
@@ -139,7 +139,7 @@ public class JCDiagnostic implements Diagnostic<JavaFileObject> {
*/
*/
public
JCDiagnostic
note
(
public
JCDiagnostic
note
(
DiagnosticSource
source
,
DiagnosticPosition
pos
,
String
key
,
Object
...
args
)
{
DiagnosticSource
source
,
DiagnosticPosition
pos
,
String
key
,
Object
...
args
)
{
return
new
JCDiagnostic
(
formatter
,
NOTE
,
false
,
source
,
pos
,
qualify
(
NOTE
,
key
)
,
args
);
return
create
(
NOTE
,
false
,
source
,
pos
,
key
,
args
);
}
}
/**
/**
...
@@ -148,7 +148,21 @@ public class JCDiagnostic implements Diagnostic<JavaFileObject> {
...
@@ -148,7 +148,21 @@ public class JCDiagnostic implements Diagnostic<JavaFileObject> {
* @param args Fields of the error message.
* @param args Fields of the error message.
*/
*/
public
JCDiagnostic
fragment
(
String
key
,
Object
...
args
)
{
public
JCDiagnostic
fragment
(
String
key
,
Object
...
args
)
{
return
new
JCDiagnostic
(
formatter
,
FRAGMENT
,
false
,
null
,
null
,
qualify
(
FRAGMENT
,
key
),
args
);
return
create
(
FRAGMENT
,
false
,
null
,
null
,
key
,
args
);
}
/**
* Create a new diagnostic of the given kind.
* @param kind The diagnostic kind
* @param isMandatory is diagnostic mandatory?
* @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 key The key for the localized error message.
* @param args Fields of the error message.
*/
public
JCDiagnostic
create
(
DiagnosticType
kind
,
boolean
isMandatory
,
DiagnosticSource
source
,
DiagnosticPosition
pos
,
String
key
,
Object
...
args
)
{
return
new
JCDiagnostic
(
formatter
,
kind
,
isMandatory
,
source
,
pos
,
qualify
(
kind
,
key
),
args
);
}
}
protected
String
qualify
(
DiagnosticType
t
,
String
key
)
{
protected
String
qualify
(
DiagnosticType
t
,
String
key
)
{
...
...
langtools/src/share/classes/com/sun/tools/javac/util/RichDiagnosticFormatter.java
浏览文件 @
18c5f1f2
...
@@ -68,7 +68,10 @@ public class RichDiagnosticFormatter extends
...
@@ -68,7 +68,10 @@ public class RichDiagnosticFormatter extends
final
JavacMessages
messages
;
final
JavacMessages
messages
;
/* name simplifier used by this formatter */
/* name simplifier used by this formatter */
ClassNameSimplifier
nameSimplifier
;
protected
ClassNameSimplifier
nameSimplifier
;
/* type/symbol printer used by this formatter */
private
RichPrinter
printer
;
/* map for keeping track of a where clause associated to a given type */
/* map for keeping track of a where clause associated to a given type */
Map
<
WhereClauseKind
,
Map
<
Type
,
JCDiagnostic
>>
whereClauses
;
Map
<
WhereClauseKind
,
Map
<
Type
,
JCDiagnostic
>>
whereClauses
;
...
@@ -83,7 +86,7 @@ public class RichDiagnosticFormatter extends
...
@@ -83,7 +86,7 @@ public class RichDiagnosticFormatter extends
protected
RichDiagnosticFormatter
(
Context
context
)
{
protected
RichDiagnosticFormatter
(
Context
context
)
{
super
((
AbstractDiagnosticFormatter
)
Log
.
instance
(
context
).
getDiagnosticFormatter
());
super
((
AbstractDiagnosticFormatter
)
Log
.
instance
(
context
).
getDiagnosticFormatter
());
this
.
formatter
.
setPrinter
(
printer
);
setRichPrinter
(
new
RichPrinter
()
);
this
.
syms
=
Symtab
.
instance
(
context
);
this
.
syms
=
Symtab
.
instance
(
context
);
this
.
diags
=
JCDiagnostic
.
Factory
.
instance
(
context
);
this
.
diags
=
JCDiagnostic
.
Factory
.
instance
(
context
);
this
.
types
=
Types
.
instance
(
context
);
this
.
types
=
Types
.
instance
(
context
);
...
@@ -116,6 +119,23 @@ public class RichDiagnosticFormatter extends
...
@@ -116,6 +119,23 @@ public class RichDiagnosticFormatter extends
return
sb
.
toString
();
return
sb
.
toString
();
}
}
/**
* Sets the type/symbol printer used by this formatter.
* @param printer the rich printer to be set
*/
protected
void
setRichPrinter
(
RichPrinter
printer
)
{
this
.
printer
=
printer
;
formatter
.
setPrinter
(
printer
);
}
/**
* Gets the type/symbol printer used by this formatter.
* @return type/symbol rich printer
*/
protected
RichPrinter
getRichPrinter
()
{
return
printer
;
}
/**
/**
* Preprocess a given diagnostic by looking both into its arguments and into
* Preprocess a given diagnostic by looking both into its arguments and into
* its subdiagnostics (if any). This preprocessing is responsible for
* its subdiagnostics (if any). This preprocessing is responsible for
...
@@ -217,7 +237,7 @@ public class RichDiagnosticFormatter extends
...
@@ -217,7 +237,7 @@ public class RichDiagnosticFormatter extends
* name belong to different packages - in this case the formatter reverts
* name belong to different packages - in this case the formatter reverts
* to fullnames as compact names might lead to a confusing diagnostic.
* to fullnames as compact names might lead to a confusing diagnostic.
*/
*/
class
ClassNameSimplifier
{
protected
class
ClassNameSimplifier
{
/* table for keeping track of all short name usages */
/* table for keeping track of all short name usages */
Map
<
Name
,
List
<
Symbol
>>
nameClashes
=
new
HashMap
<
Name
,
List
<
Symbol
>>();
Map
<
Name
,
List
<
Symbol
>>
nameClashes
=
new
HashMap
<
Name
,
List
<
Symbol
>>();
...
@@ -272,7 +292,7 @@ public class RichDiagnosticFormatter extends
...
@@ -272,7 +292,7 @@ public class RichDiagnosticFormatter extends
* discovered during type/symbol preprocessing. This printer is set on the delegate
* discovered during type/symbol preprocessing. This printer is set on the delegate
* formatter so that rich type/symbol info can be properly rendered.
* formatter so that rich type/symbol info can be properly rendered.
*/
*/
protected
Printer
printer
=
new
Printer
()
{
protected
class
RichPrinter
extends
Printer
{
@Override
@Override
public
String
localize
(
Locale
locale
,
String
key
,
Object
...
args
)
{
public
String
localize
(
Locale
locale
,
String
key
,
Object
...
args
)
{
...
...
langtools/test/tools/javac/api/6852595/T6852595.java
0 → 100644
浏览文件 @
18c5f1f2
/*
* Copyright 2009 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 6852595
* @summary Accessing scope using JSR199 API on erroneous tree causes Illegal Argument Exception
* @author mcimadamore
*/
import
java.io.IOException
;
import
java.net.URI
;
import
java.util.Arrays
;
import
java.util.List
;
import
javax.tools.JavaCompiler
;
import
javax.tools.JavaFileObject
;
import
javax.tools.SimpleJavaFileObject
;
import
javax.tools.ToolProvider
;
import
com.sun.source.util.JavacTask
;
import
com.sun.source.tree.*
;
import
com.sun.source.util.TreePath
;
import
com.sun.source.util.Trees
;
import
com.sun.tools.javac.api.JavacTrees
;
import
com.sun.tools.javac.tree.JCTree.*
;
import
static
javax
.
tools
.
JavaFileObject
.
Kind
;
public
class
T6852595
{
public
static
void
main
(
String
[]
args
)
throws
IOException
{
JavaFileObject
sfo
=
new
SimpleJavaFileObject
(
URI
.
create
(
"myfo:/Test.java"
),
Kind
.
SOURCE
)
{
public
CharSequence
getCharContent
(
boolean
ignoreEncodingErrors
)
{
return
"class BadName { Object o = j; }"
;
}
};
List
<?
extends
JavaFileObject
>
files
=
Arrays
.
asList
(
sfo
);
JavaCompiler
tool
=
ToolProvider
.
getSystemJavaCompiler
();
JavacTask
ct
=
(
JavacTask
)
tool
.
getTask
(
null
,
null
,
null
,
null
,
null
,
files
);
Iterable
<?
extends
CompilationUnitTree
>
compUnits
=
ct
.
parse
();
CompilationUnitTree
cu
=
compUnits
.
iterator
().
next
();
ClassTree
cdef
=
(
ClassTree
)
cu
.
getTypeDecls
().
get
(
0
);
JCVariableDecl
vdef
=
(
JCVariableDecl
)
cdef
.
getMembers
().
get
(
0
);
TreePath
path
=
TreePath
.
getPath
(
cu
,
vdef
.
init
);
Trees
.
instance
(
ct
).
getScope
(
path
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录