Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_langtools
提交
011cfc49
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看板
提交
011cfc49
编写于
11月 12, 2008
作者:
M
mcimadamore
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
6768932: Add support for multiline diagnostics
Summary: Added basic support for multiline/tabular diagnostics Reviewed-by: jjg
上级
4c767743
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
132 addition
and
9 deletion
+132
-9
src/share/classes/com/sun/tools/javac/util/AbstractDiagnosticFormatter.java
...com/sun/tools/javac/util/AbstractDiagnosticFormatter.java
+64
-2
src/share/classes/com/sun/tools/javac/util/AbstractLog.java
src/share/classes/com/sun/tools/javac/util/AbstractLog.java
+6
-0
src/share/classes/com/sun/tools/javac/util/JCDiagnostic.java
src/share/classes/com/sun/tools/javac/util/JCDiagnostic.java
+39
-2
src/share/classes/com/sun/tools/javac/util/LayoutCharacters.java
...re/classes/com/sun/tools/javac/util/LayoutCharacters.java
+4
-0
src/share/classes/com/sun/tools/javac/util/Log.java
src/share/classes/com/sun/tools/javac/util/Log.java
+4
-4
src/share/classes/com/sun/tools/javac/util/MandatoryWarningHandler.java
...ses/com/sun/tools/javac/util/MandatoryWarningHandler.java
+1
-1
src/share/classes/com/sun/tools/javac/util/RawDiagnosticFormatter.java
...sses/com/sun/tools/javac/util/RawDiagnosticFormatter.java
+14
-0
未找到文件。
src/share/classes/com/sun/tools/javac/util/AbstractDiagnosticFormatter.java
浏览文件 @
011cfc49
...
...
@@ -27,13 +27,13 @@ package com.sun.tools.javac.util;
import
java.util.Collection
;
import
java.util.Locale
;
import
javax.tools.JavaFileObject
;
import
java.util.ResourceBundle
;
import
com.sun.tools.javac.api.DiagnosticFormatter
;
import
com.sun.tools.javac.api.Formattable
;
import
com.sun.tools.javac.api.DiagnosticFormatter.PositionKind
;
import
com.sun.tools.javac.file.JavacFileManager
;
import
static
com
.
sun
.
tools
.
javac
.
util
.
JCDiagnostic
.
DiagnosticType
.*;
import
static
com
.
sun
.
tools
.
javac
.
util
.
LayoutCharacters
.*;
/**
* This abstract class provides a basic implementation of the functionalities that should be provided
...
...
@@ -72,8 +72,13 @@ public abstract class AbstractDiagnosticFormatter implements DiagnosticFormatter
public
String
formatMessage
(
JCDiagnostic
d
,
Locale
l
)
{
//this code should rely on the locale settings but it's not! See RFE 6443132
StringBuilder
buf
=
new
StringBuilder
();
Collection
<
String
>
args
=
formatArguments
(
d
,
l
);
return
localize
(
l
,
d
.
getCode
(),
args
.
toArray
());
buf
.
append
(
localize
(
l
,
d
.
getCode
(),
args
.
toArray
()));
if
(
d
.
isMultiline
())
{
buf
.
append
(
formatSubdiagnostics
(
d
,
l
));
}
return
buf
.
toString
();
}
public
String
formatKind
(
JCDiagnostic
d
,
Locale
l
)
{
...
...
@@ -165,6 +170,23 @@ public abstract class AbstractDiagnosticFormatter implements DiagnosticFormatter
return
sbuf
.
toString
();
}
/**
* Format all the subdiagnostics attached to a given diagnostic
*
* @param d diagnostic whose subdiagnostics are to be formatted
* @param l locale object to be used for i18n
* @return string representation of the subdiagnostics
*/
protected
String
formatSubdiagnostics
(
JCDiagnostic
d
,
Locale
l
)
{
StringBuilder
buf
=
new
StringBuilder
();
for
(
JCDiagnostic
d2
:
d
.
getSubdiagnostics
())
{
buf
.
append
(
'\n'
);
String
subdiagMsg
=
format
(
d2
,
l
);
buf
.
append
(
indent
(
subdiagMsg
,
DiagInc
));
}
return
buf
.
toString
();
}
/** Format the faulty source code line and point to the error.
* @param d The diagnostic for which the error line should be printed
*/
...
...
@@ -201,4 +223,44 @@ public abstract class AbstractDiagnosticFormatter implements DiagnosticFormatter
public
boolean
displaySource
(
JCDiagnostic
d
)
{
return
showSource
&&
d
.
getType
()
!=
FRAGMENT
;
}
/**
* Creates a string with a given amount of empty spaces. Useful for
* indenting the text of a diagnostic message.
*
* @param nSpaces the amount of spaces to be added to the result string
* @return the indentation string
*/
protected
String
indentString
(
int
nSpaces
)
{
String
spaces
=
" "
;
if
(
nSpaces
<=
spaces
.
length
())
return
spaces
.
substring
(
0
,
nSpaces
);
else
{
StringBuilder
buf
=
new
StringBuilder
();
for
(
int
i
=
0
;
i
<
nSpaces
;
i
++)
buf
.
append
(
" "
);
return
buf
.
toString
();
}
}
/**
* Indent a string by prepending a given amount of empty spaces to each line
* of the string
*
* @param s the string to be indented
* @param nSpaces the amount of spaces that should be prepended to each line
* of the string
* @return an indented string
*/
protected
String
indent
(
String
s
,
int
nSpaces
)
{
String
indent
=
indentString
(
nSpaces
);
StringBuilder
buf
=
new
StringBuilder
();
String
nl
=
""
;
for
(
String
line
:
s
.
split
(
"\n"
))
{
buf
.
append
(
nl
);
buf
.
append
(
indent
+
line
);
nl
=
"\n"
;
}
return
buf
.
toString
();
}
}
src/share/classes/com/sun/tools/javac/util/AbstractLog.java
浏览文件 @
011cfc49
...
...
@@ -67,6 +67,12 @@ public abstract class AbstractLog {
return
s
;
}
/** Return the underlying diagnostic source
*/
public
DiagnosticSource
currentSource
()
{
return
source
;
}
/** Report an error, unless another error was already reported at same
* source position.
* @param key The key for the localized error message.
...
...
src/share/classes/com/sun/tools/javac/util/JCDiagnostic.java
浏览文件 @
011cfc49
...
...
@@ -289,7 +289,7 @@ public class JCDiagnostic implements Diagnostic<JavaFileObject> {
this
.
source
=
source
;
this
.
position
=
pos
;
this
.
key
=
key
;
this
.
args
=
args
;
this
.
args
=
args
;
int
n
=
(
pos
==
null
?
Position
.
NOPOS
:
pos
.
getPreferredPosition
());
if
(
n
==
Position
.
NOPOS
||
source
==
null
)
...
...
@@ -308,6 +308,18 @@ public class JCDiagnostic implements Diagnostic<JavaFileObject> {
return
type
;
}
/**
* Get the subdiagnostic list
* @return subdiagnostic list
*/
public
List
<
JCDiagnostic
>
getSubdiagnostics
()
{
return
List
.
nil
();
}
public
boolean
isMultiline
()
{
return
false
;
}
/**
* Check whether or not this diagnostic is required to be shown.
* @return true if this diagnostic is required to be shown.
...
...
@@ -440,7 +452,32 @@ public class JCDiagnostic implements Diagnostic<JavaFileObject> {
}
public
String
getMessage
(
Locale
locale
)
{
// RFE 6406133: JCDiagnostic.getMessage ignores locale argument
return
defaultFormatter
.
formatMessage
(
this
,
locale
);
}
public
static
class
MultilineDiagnostic
extends
JCDiagnostic
{
private
final
List
<
JCDiagnostic
>
subdiagnostics
;
public
MultilineDiagnostic
(
JCDiagnostic
other
,
List
<
JCDiagnostic
>
subdiagnostics
)
{
super
(
other
.
defaultFormatter
,
other
.
getType
(),
other
.
isMandatory
(),
other
.
getDiagnosticSource
(),
other
.
position
,
other
.
getCode
(),
other
.
getArgs
());
this
.
subdiagnostics
=
subdiagnostics
;
}
@Override
public
List
<
JCDiagnostic
>
getSubdiagnostics
()
{
return
subdiagnostics
;
}
@Override
public
boolean
isMultiline
()
{
return
true
;
}
}
}
src/share/classes/com/sun/tools/javac/util/LayoutCharacters.java
浏览文件 @
011cfc49
...
...
@@ -39,6 +39,10 @@ public interface LayoutCharacters {
*/
final
static
int
TabInc
=
8
;
/** Diagnostic standard indentation
*/
final
static
int
DiagInc
=
2
;
/** Tabulator character.
*/
final
static
byte
TAB
=
0x8
;
...
...
src/share/classes/com/sun/tools/javac/util/Log.java
浏览文件 @
011cfc49
...
...
@@ -190,9 +190,9 @@ public class Log extends AbstractLog {
getSource
(
name
).
setEndPosTable
(
table
);
}
/** Return current source
nam
e.
/** Return current source
fil
e.
*/
public
JavaFileObject
currentSource
()
{
public
JavaFileObject
currentSource
File
()
{
return
source
==
null
?
null
:
source
.
getFile
();
}
...
...
@@ -395,7 +395,7 @@ public class Log extends AbstractLog {
printLines
(
errWriter
,
"error: "
+
msg
);
}
else
{
int
line
=
source
.
getLineNumber
(
pos
);
JavaFileObject
file
=
currentSourc
e
();
JavaFileObject
file
=
source
.
getFil
e
();
if
(
file
!=
null
)
printLines
(
errWriter
,
JavacFileManager
.
getJavacFileName
(
file
)
+
":"
+
...
...
@@ -408,7 +408,7 @@ public class Log extends AbstractLog {
/** report an error:
*/
public
void
rawError
(
int
pos
,
String
msg
)
{
if
(
nerrors
<
MaxErrors
&&
shouldReport
(
currentSource
(),
pos
))
{
if
(
nerrors
<
MaxErrors
&&
shouldReport
(
currentSource
File
(),
pos
))
{
printRawError
(
pos
,
msg
);
prompt
();
nerrors
++;
...
...
src/share/classes/com/sun/tools/javac/util/MandatoryWarningHandler.java
浏览文件 @
011cfc49
...
...
@@ -118,7 +118,7 @@ public class MandatoryWarningHandler {
* Report a mandatory warning.
*/
public
void
report
(
DiagnosticPosition
pos
,
String
msg
,
Object
...
args
)
{
JavaFileObject
currentSource
=
log
.
currentSource
();
JavaFileObject
currentSource
=
log
.
currentSource
File
();
if
(
verbose
)
{
if
(
sourcesWithReportedWarnings
==
null
)
...
...
src/share/classes/com/sun/tools/javac/util/RawDiagnosticFormatter.java
浏览文件 @
011cfc49
...
...
@@ -84,6 +84,20 @@ public class RawDiagnosticFormatter extends AbstractDiagnosticFormatter {
return
s
;
}
@Override
protected
String
formatSubdiagnostics
(
JCDiagnostic
d
,
Locale
l
)
{
StringBuilder
buf
=
new
StringBuilder
();
String
sep
=
""
;
buf
.
append
(
",{"
);
for
(
JCDiagnostic
d2
:
d
.
getSubdiagnostics
())
{
buf
.
append
(
sep
);
buf
.
append
(
"("
+
format
(
d2
,
l
)
+
")"
);
sep
=
","
;
}
buf
.
append
(
'}'
);
return
buf
.
toString
();
}
@Override
protected
String
localize
(
Locale
l
,
String
s
,
Object
...
args
)
{
StringBuffer
buf
=
new
StringBuffer
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录