Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_langtools
提交
5ea82baa
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看板
提交
5ea82baa
编写于
12月 09, 2010
作者:
J
jjg
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
6985202: no access to doc comments from Tree API
Reviewed-by: mcimadamore
上级
13c8be5a
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
174 addition
and
0 deletion
+174
-0
src/share/classes/com/sun/source/util/Trees.java
src/share/classes/com/sun/source/util/Trees.java
+6
-0
src/share/classes/com/sun/tools/javac/api/JavacTrees.java
src/share/classes/com/sun/tools/javac/api/JavacTrees.java
+11
-0
test/tools/javac/api/TestDocComments.java
test/tools/javac/api/TestDocComments.java
+157
-0
未找到文件。
src/share/classes/com/sun/source/util/Trees.java
浏览文件 @
5ea82baa
...
...
@@ -162,6 +162,12 @@ public abstract class Trees {
*/
public
abstract
Scope
getScope
(
TreePath
path
);
/**
* Gets the doc comment, if any, for the Tree node identified by a given TreePath.
* Returns null if no doc comment was found.
*/
public
abstract
String
getDocComment
(
TreePath
path
);
/**
* Checks whether a given type is accessible in a given scope.
* @param scope the scope to be checked
...
...
src/share/classes/com/sun/tools/javac/api/JavacTrees.java
浏览文件 @
5ea82baa
...
...
@@ -228,6 +228,17 @@ public class JavacTrees extends Trees {
return
new
JavacScope
(
getAttrContext
(
path
));
}
public
String
getDocComment
(
TreePath
path
)
{
CompilationUnitTree
t
=
path
.
getCompilationUnit
();
if
(
t
instanceof
JCTree
.
JCCompilationUnit
)
{
JCCompilationUnit
cu
=
(
JCCompilationUnit
)
t
;
if
(
cu
.
docComments
!=
null
)
{
return
cu
.
docComments
.
get
(
path
.
getLeaf
());
}
}
return
null
;
}
public
boolean
isAccessible
(
Scope
scope
,
TypeElement
type
)
{
if
(
scope
instanceof
JavacScope
&&
type
instanceof
ClassSymbol
)
{
Env
<
AttrContext
>
env
=
((
JavacScope
)
scope
).
env
;
...
...
test/tools/javac/api/TestDocComments.java
0 → 100644
浏览文件 @
5ea82baa
/*
* Copyright (c) 2010, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/* @test
* @bug 6985202
* @summary no access to doc comments from Tree API
*/
import
java.io.*
;
import
java.util.*
;
import
javax.tools.*
;
import
com.sun.source.tree.*
;
import
com.sun.source.util.*
;
import
com.sun.tools.javac.api.JavacTool
;
/**
* class-TestDocComments.
*/
public
class
TestDocComments
{
/**
* method-main.
*/
public
static
void
main
(
String
...
args
)
throws
Exception
{
new
TestDocComments
().
run
();
}
/**
* method-run.
*/
void
run
()
throws
Exception
{
File
testSrc
=
new
File
(
System
.
getProperty
(
"test.src"
));
File
file
=
new
File
(
testSrc
,
"TestDocComments.java"
);
JavacTool
tool
=
JavacTool
.
create
();
StandardJavaFileManager
fm
=
tool
.
getStandardFileManager
(
null
,
null
,
null
);
StringWriter
sw
=
new
StringWriter
();
PrintWriter
pw
=
new
PrintWriter
(
sw
);
Iterable
<?
extends
JavaFileObject
>
fileObjects
=
fm
.
getJavaFileObjects
(
file
);
JavacTask
task
=
tool
.
getTask
(
pw
,
fm
,
null
,
null
,
null
,
fileObjects
);
Iterable
<?
extends
CompilationUnitTree
>
units
=
task
.
parse
();
Trees
trees
=
Trees
.
instance
(
task
);
CommentScanner
s
=
new
CommentScanner
();
int
n
=
s
.
scan
(
units
,
trees
);
if
(
n
!=
12
)
error
(
"Unexpected number of doc comments found: "
+
n
);
if
(
errors
>
0
)
throw
new
Exception
(
errors
+
" errors occurred"
);
}
/**
* class-CommentScanner.
*/
class
CommentScanner
extends
TreePathScanner
<
Integer
,
Trees
>
{
/**
* method-visitClass.
*/
@Override
public
Integer
visitClass
(
ClassTree
t
,
Trees
trees
)
{
return
reduce
(
super
.
visitClass
(
t
,
trees
),
check
(
trees
,
"class-"
+
t
.
getSimpleName
()
+
"."
));
}
/**
* method-visitMethod.
*/
@Override
public
Integer
visitMethod
(
MethodTree
t
,
Trees
trees
)
{
return
reduce
(
super
.
visitMethod
(
t
,
trees
),
check
(
trees
,
"method-"
+
t
.
getName
()
+
"."
));
}
/**
* method-visitVariable.
*/
@Override
public
Integer
visitVariable
(
VariableTree
t
,
Trees
trees
)
{
// for simplicity, only check fields, not parameters or local decls
int
n
=
(
getCurrentPath
().
getParentPath
().
getLeaf
().
getKind
()
==
Tree
.
Kind
.
CLASS
)
?
check
(
trees
,
"field-"
+
t
.
getName
()
+
"."
)
:
0
;
return
reduce
(
super
.
visitVariable
(
t
,
trees
),
n
);
}
/**
* method-reduce.
*/
@Override
public
Integer
reduce
(
Integer
i1
,
Integer
i2
)
{
return
(
i1
==
null
)
?
i2
:
(
i2
==
null
)
?
i1
:
Integer
.
valueOf
(
i1
+
i2
);
}
/**
* method-check.
*/
int
check
(
Trees
trees
,
String
expect
)
{
TreePath
p
=
getCurrentPath
();
String
dc
=
trees
.
getDocComment
(
p
);
if
(
dc
!=
null
&&
dc
.
trim
().
equals
(
expect
))
return
1
;
Tree
.
Kind
k
=
p
.
getLeaf
().
getKind
();
if
(
dc
==
null
)
error
(
"no doc comment for "
+
k
);
else
error
(
"unexpected doc comment for "
+
k
+
"\nexpect: "
+
expect
+
"\nfound: "
+
dc
);
return
0
;
}
}
/**
* method-nullCheck.
*/
int
nullCheck
(
Integer
i
)
{
return
(
i
==
null
)
?
0
:
i
;
}
/**
* method-error.
*/
void
error
(
String
msg
)
{
System
.
err
.
println
(
"Error: "
+
msg
);
errors
++;
}
/**
* field-errors.
*/
int
errors
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录