Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_langtools
提交
d2c06c07
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看板
提交
d2c06c07
编写于
6月 21, 2012
作者:
J
jjg
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
7178297: provide mapping from doc comment position to source file position
Reviewed-by: mcimadamore, ksrini
上级
00ec38a2
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
108 addition
and
14 deletion
+108
-14
src/share/classes/com/sun/tools/javac/parser/JavaTokenizer.java
...are/classes/com/sun/tools/javac/parser/JavaTokenizer.java
+4
-0
src/share/classes/com/sun/tools/javac/parser/JavadocTokenizer.java
.../classes/com/sun/tools/javac/parser/JavadocTokenizer.java
+102
-13
src/share/classes/com/sun/tools/javac/parser/Tokens.java
src/share/classes/com/sun/tools/javac/parser/Tokens.java
+1
-0
src/share/classes/com/sun/tools/javac/tree/TreeInfo.java
src/share/classes/com/sun/tools/javac/tree/TreeInfo.java
+1
-1
未找到文件。
src/share/classes/com/sun/tools/javac/parser/JavaTokenizer.java
浏览文件 @
d2c06c07
...
@@ -780,6 +780,10 @@ public class JavaTokenizer {
...
@@ -780,6 +780,10 @@ public class JavaTokenizer {
return
null
;
return
null
;
}
}
public
int
getSourcePos
(
int
pos
)
{
return
-
1
;
}
public
CommentStyle
getStyle
()
{
public
CommentStyle
getStyle
()
{
return
cs
;
return
cs
;
}
}
...
...
src/share/classes/com/sun/tools/javac/parser/JavadocTokenizer.java
浏览文件 @
d2c06c07
/*
/*
* Copyright (c) 2004, 201
1
, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2004, 201
2
, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
*
* This code is free software; you can redistribute it and/or modify it
* This code is free software; you can redistribute it and/or modify it
...
@@ -62,19 +62,54 @@ public class JavadocTokenizer extends JavaTokenizer {
...
@@ -62,19 +62,54 @@ public class JavadocTokenizer extends JavaTokenizer {
@Override
@Override
protected
Comment
processComment
(
int
pos
,
int
endPos
,
CommentStyle
style
)
{
protected
Comment
processComment
(
int
pos
,
int
endPos
,
CommentStyle
style
)
{
char
[]
buf
=
reader
.
getRawCharacters
(
pos
,
endPos
);
char
[]
buf
=
reader
.
getRawCharacters
(
pos
,
endPos
);
return
new
JavadocComment
(
new
ColReader
(
fac
,
buf
,
buf
.
length
),
style
);
return
new
JavadocComment
(
new
DocReader
(
fac
,
buf
,
buf
.
length
,
pos
),
style
);
}
}
/**
/**
* This is a specialized version of UnicodeReader that keeps track of the
* This is a specialized version of UnicodeReader that keeps track of the
* column position within a given character stream (used for Javadoc processing).
* column position within a given character stream (used for Javadoc processing),
* and which builds a table for mapping positions in the comment string to
* positions in the source file.
*/
*/
static
class
Col
Reader
extends
UnicodeReader
{
static
class
Doc
Reader
extends
UnicodeReader
{
int
col
;
int
col
;
int
startPos
;
ColReader
(
ScannerFactory
fac
,
char
[]
input
,
int
inputLength
)
{
/**
* A buffer for building a table for mapping positions in {@link #sbuf}
* to positions in the source buffer.
*
* The array is organized as a series of pairs of integers: the first
* number in each pair specifies a position in the comment text,
* the second number in each pair specifies the corresponding position
* in the source buffer. The pairs are sorted in ascending order.
*
* Since the mapping function is generally continuous, with successive
* positions in the string corresponding to successive positions in the
* source buffer, the table only needs to record discontinuities in
* the mapping. The values of intermediate positions can be inferred.
*
* Discontinuities may occur in a number of places: when a newline
* is followed by whitespace and asterisks (which are ignored),
* when a tab is expanded into spaces, and when unicode escapes
* are used in the source buffer.
*
* Thus, to find the source position of any position, p, in the comment
* string, find the index, i, of the pair whose string offset
* ({@code pbuf[i] }) is closest to but not greater than p. Then,
* {@code sourcePos(p) = pbuf[i+1] + (p - pbuf[i]) }.
*/
int
[]
pbuf
=
new
int
[
128
];
/**
* The index of the next empty slot in the pbuf buffer.
*/
int
pp
=
0
;
DocReader
(
ScannerFactory
fac
,
char
[]
input
,
int
inputLength
,
int
startPos
)
{
super
(
fac
,
input
,
inputLength
);
super
(
fac
,
input
,
inputLength
);
this
.
startPos
=
startPos
;
}
}
@Override
@Override
...
@@ -147,19 +182,43 @@ public class JavadocTokenizer extends JavaTokenizer {
...
@@ -147,19 +182,43 @@ public class JavadocTokenizer extends JavaTokenizer {
break
;
break
;
}
}
}
}
@Override
public
void
putChar
(
char
ch
,
boolean
scan
)
{
// At this point, bp is the position of the current character in buf,
// and sp is the position in sbuf where this character will be put.
// Record a new entry in pbuf if pbuf is empty or if sp and its
// corresponding source position are not equidistant from the
// corresponding values in the latest entry in the pbuf array.
// (i.e. there is a discontinuity in the map function.)
if
((
pp
==
0
)
||
(
sp
-
pbuf
[
pp
-
2
]
!=
(
startPos
+
bp
)
-
pbuf
[
pp
-
1
]))
{
if
(
pp
+
1
>=
pbuf
.
length
)
{
int
[]
new_pbuf
=
new
int
[
pbuf
.
length
*
2
];
System
.
arraycopy
(
pbuf
,
0
,
new_pbuf
,
0
,
pbuf
.
length
);
pbuf
=
new_pbuf
;
}
pbuf
[
pp
]
=
sp
;
pbuf
[
pp
+
1
]
=
startPos
+
bp
;
pp
+=
2
;
}
super
.
putChar
(
ch
,
scan
);
}
}
}
protected
class
JavadocComment
extends
JavaTokenizer
.
BasicComment
<
Col
Reader
>
{
protected
class
JavadocComment
extends
JavaTokenizer
.
BasicComment
<
Doc
Reader
>
{
/**
/**
* Translated and stripped contents of doc comment
* Translated and stripped contents of doc comment
*/
*/
private
String
docComment
=
null
;
private
String
docComment
=
null
;
private
int
[]
docPosns
=
null
;
JavadocComment
(
ColReader
comment_
reader
,
CommentStyle
cs
)
{
JavadocComment
(
DocReader
reader
,
CommentStyle
cs
)
{
super
(
comment_
reader
,
cs
);
super
(
reader
,
cs
);
}
}
@Override
public
String
getText
()
{
public
String
getText
()
{
if
(!
scanned
&&
cs
==
CommentStyle
.
JAVADOC
)
{
if
(!
scanned
&&
cs
==
CommentStyle
.
JAVADOC
)
{
scanDocComment
();
scanDocComment
();
...
@@ -167,6 +226,33 @@ public class JavadocTokenizer extends JavaTokenizer {
...
@@ -167,6 +226,33 @@ public class JavadocTokenizer extends JavaTokenizer {
return
docComment
;
return
docComment
;
}
}
@Override
public
int
getSourcePos
(
int
pos
)
{
// Binary search to find the entry for which the string index is
// less than pos. Since docPosns is a list of pairs of integers
// we must make sure the index is always even.
// If we find an exact match for pos, the other item in the pair
// gives the source pos; otherwise, compute the source position
// relative to the best match found in the array.
if
(
pos
<
0
||
pos
>=
docComment
.
length
())
throw
new
StringIndexOutOfBoundsException
();
if
(
docPosns
==
null
)
return
-
1
;
int
start
=
0
;
int
end
=
docPosns
.
length
;
while
(
start
<
end
-
2
)
{
// find an even index midway between start and end
int
index
=
((
start
+
end
)
/
4
)
*
2
;
if
(
docPosns
[
index
]
<
pos
)
start
=
index
;
else
if
(
docPosns
[
index
]
==
pos
)
return
docPosns
[
index
+
1
];
else
end
=
index
;
}
return
docPosns
[
start
+
1
]
+
(
pos
-
docPosns
[
start
]);
}
@Override
@Override
@SuppressWarnings
(
"fallthrough"
)
@SuppressWarnings
(
"fallthrough"
)
protected
void
scanDocComment
()
{
protected
void
scanDocComment
()
{
...
@@ -209,7 +295,8 @@ public class JavadocTokenizer extends JavaTokenizer {
...
@@ -209,7 +295,8 @@ public class JavadocTokenizer extends JavaTokenizer {
// whitespace, then it consumes any stars, then it
// whitespace, then it consumes any stars, then it
// puts the rest of the line into our buffer.
// puts the rest of the line into our buffer.
while
(
comment_reader
.
bp
<
comment_reader
.
buflen
)
{
while
(
comment_reader
.
bp
<
comment_reader
.
buflen
)
{
int
begin_bp
=
comment_reader
.
bp
;
char
begin_ch
=
comment_reader
.
ch
;
// The wsLoop consumes whitespace from the beginning
// The wsLoop consumes whitespace from the beginning
// of each line.
// of each line.
wsLoop:
wsLoop:
...
@@ -263,10 +350,10 @@ public class JavadocTokenizer extends JavaTokenizer {
...
@@ -263,10 +350,10 @@ public class JavadocTokenizer extends JavaTokenizer {
break
outerLoop
;
break
outerLoop
;
}
}
}
else
if
(!
firstLine
)
{
}
else
if
(!
firstLine
)
{
//
The current line does not begin with a '*' so we will indent it.
//
The current line does not begin with a '*' so we will
for
(
int
i
=
1
;
i
<
comment_reader
.
col
;
i
++)
{
// treat it as comment
comment_reader
.
putChar
(
' '
,
false
)
;
comment_reader
.
bp
=
begin_bp
;
}
comment_reader
.
ch
=
begin_ch
;
}
}
// The textLoop processes the rest of the characters
// The textLoop processes the rest of the characters
// on the line, adding them to our buffer.
// on the line, adding them to our buffer.
...
@@ -334,6 +421,8 @@ public class JavadocTokenizer extends JavaTokenizer {
...
@@ -334,6 +421,8 @@ public class JavadocTokenizer extends JavaTokenizer {
// Store the text of the doc comment
// Store the text of the doc comment
docComment
=
comment_reader
.
chars
();
docComment
=
comment_reader
.
chars
();
docPosns
=
new
int
[
comment_reader
.
pp
];
System
.
arraycopy
(
comment_reader
.
pbuf
,
0
,
docPosns
,
0
,
docPosns
.
length
);
}
else
{
}
else
{
docComment
=
""
;
docComment
=
""
;
}
}
...
...
src/share/classes/com/sun/tools/javac/parser/Tokens.java
浏览文件 @
d2c06c07
...
@@ -294,6 +294,7 @@ public class Tokens {
...
@@ -294,6 +294,7 @@ public class Tokens {
}
}
String
getText
();
String
getText
();
int
getSourcePos
(
int
index
);
CommentStyle
getStyle
();
CommentStyle
getStyle
();
boolean
isDeprecated
();
boolean
isDeprecated
();
}
}
...
...
src/share/classes/com/sun/tools/javac/tree/TreeInfo.java
浏览文件 @
d2c06c07
...
@@ -285,7 +285,7 @@ public class TreeInfo {
...
@@ -285,7 +285,7 @@ public class TreeInfo {
DocCommentTable
docComments
=
(
tree
.
hasTag
(
JCTree
.
Tag
.
TOPLEVEL
))
DocCommentTable
docComments
=
(
tree
.
hasTag
(
JCTree
.
Tag
.
TOPLEVEL
))
?
((
JCCompilationUnit
)
tree
).
docComments
?
((
JCCompilationUnit
)
tree
).
docComments
:
env
.
toplevel
.
docComments
;
:
env
.
toplevel
.
docComments
;
return
docComments
.
getCommentText
(
tree
);
return
(
docComments
==
null
)
?
null
:
docComments
.
getCommentText
(
tree
);
}
}
/** The position of the first statement in a block, or the position of
/** The position of the first statement in a block, or the position of
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录