Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_langtools
提交
6eeac523
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看板
提交
6eeac523
编写于
9月 09, 2010
作者:
J
jjg
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
6983239: TreeScanner does not scan default value for method
Reviewed-by: mcimadamore
上级
51f5224b
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
345 addition
and
123 deletion
+345
-123
src/share/classes/com/sun/source/util/TreeScanner.java
src/share/classes/com/sun/source/util/TreeScanner.java
+1
-0
test/tools/javac/api/T6392782.java
test/tools/javac/api/T6392782.java
+6
-5
test/tools/javac/tree/AbstractTreeScannerTest.java
test/tools/javac/tree/AbstractTreeScannerTest.java
+15
-118
test/tools/javac/tree/JavacTreeScannerTest.java
test/tools/javac/tree/JavacTreeScannerTest.java
+155
-0
test/tools/javac/tree/SourceTreeScannerTest.java
test/tools/javac/tree/SourceTreeScannerTest.java
+168
-0
未找到文件。
src/share/classes/com/sun/source/util/TreeScanner.java
浏览文件 @
6eeac523
...
@@ -141,6 +141,7 @@ public class TreeScanner<R,P> implements TreeVisitor<R,P> {
...
@@ -141,6 +141,7 @@ public class TreeScanner<R,P> implements TreeVisitor<R,P> {
r
=
scanAndReduce
(
node
.
getReceiverAnnotations
(),
p
,
r
);
r
=
scanAndReduce
(
node
.
getReceiverAnnotations
(),
p
,
r
);
r
=
scanAndReduce
(
node
.
getThrows
(),
p
,
r
);
r
=
scanAndReduce
(
node
.
getThrows
(),
p
,
r
);
r
=
scanAndReduce
(
node
.
getBody
(),
p
,
r
);
r
=
scanAndReduce
(
node
.
getBody
(),
p
,
r
);
r
=
scanAndReduce
(
node
.
getDefaultValue
(),
p
,
r
);
return
r
;
return
r
;
}
}
...
...
test/tools/javac/api/T6392782.java
浏览文件 @
6eeac523
...
@@ -47,12 +47,12 @@ public class T6392782 {
...
@@ -47,12 +47,12 @@ public class T6392782 {
check
(
scanner
,
6
,
scanner
.
scan
(
trees
,
null
));
check
(
scanner
,
6
,
scanner
.
scan
(
trees
,
null
));
CountNodes
nodeCounter
=
new
CountNodes
();
CountNodes
nodeCounter
=
new
CountNodes
();
// 3
83 nodes with the regular parser; 384
nodes with EndPosParser
// 3
59 nodes with the regular parser; 360
nodes with EndPosParser
// We automatically swith to EndPosParser when calling JavacTask.parse()
// We automatically swit
c
h to EndPosParser when calling JavacTask.parse()
check
(
nodeCounter
,
3
84
,
nodeCounter
.
scan
(
trees
,
null
));
check
(
nodeCounter
,
3
60
,
nodeCounter
.
scan
(
trees
,
null
));
CountIdentifiers
idCounter
=
new
CountIdentifiers
();
CountIdentifiers
idCounter
=
new
CountIdentifiers
();
check
(
idCounter
,
10
6
,
idCounter
.
scan
(
trees
,
null
));
check
(
idCounter
,
10
7
,
idCounter
.
scan
(
trees
,
null
));
}
}
private
static
void
check
(
TreeScanner
<?,?>
scanner
,
int
expect
,
int
found
)
{
private
static
void
check
(
TreeScanner
<?,?>
scanner
,
int
expect
,
int
found
)
{
...
@@ -73,10 +73,11 @@ public class T6392782 {
...
@@ -73,10 +73,11 @@ public class T6392782 {
}
}
}
}
// example from TreeScanner javadoc
static
class
CountNodes
extends
TreeScanner
<
Integer
,
Void
>
{
static
class
CountNodes
extends
TreeScanner
<
Integer
,
Void
>
{
@Override
@Override
public
Integer
scan
(
Tree
node
,
Void
p
)
{
public
Integer
scan
(
Tree
node
,
Void
p
)
{
if
(
node
==
null
)
return
0
;
Integer
n
=
super
.
scan
(
node
,
p
);
Integer
n
=
super
.
scan
(
node
,
p
);
return
(
n
==
null
?
0
:
n
)
+
1
;
return
(
n
==
null
?
0
:
n
)
+
1
;
}
}
...
...
test/tools/javac/tree/TreeScannerTest.java
→
test/tools/javac/tree/
Abstract
TreeScannerTest.java
浏览文件 @
6eeac523
...
@@ -21,57 +21,20 @@
...
@@ -21,57 +21,20 @@
* questions.
* questions.
*/
*/
/**
* Utility and test program to check javac's internal TreeScanner class.
* The program can be run standalone, or as a jtreg test. For info on
* command line args, run program with no args.
*
* <p>
* jtreg: Note that by using the -r switch in the test description below, this test
* will process all java files in the langtools/test directory, thus implicitly
* covering any new language features that may be tested in this test suite.
*/
/*
* @test
* @bug 6923080
* @summary TreeScanner.visitNewClass should scan tree.typeargs
* @run main TreeScannerTest -q -r .
*/
import
java.io.*
;
import
java.io.*
;
import
java.lang.reflect.*
;
import
java.lang.reflect.*
;
import
java.util.*
;
import
java.util.*
;
import
javax.tools.*
;
import
javax.tools.*
;
import
com.sun.source.tree.CompilationUnitTree
;
import
com.sun.source.tree.CompilationUnitTree
;
import
com.sun.source.tree.Tree
;
import
com.sun.source.util.JavacTask
;
import
com.sun.source.util.JavacTask
;
import
com.sun.tools.javac.api.JavacTool
;
import
com.sun.tools.javac.api.JavacTool
;
import
com.sun.tools.javac.tree.
*
;
import
com.sun.tools.javac.tree.
JCTree
;
import
com.sun.tools.javac.tree.JCTree.
*
;
import
com.sun.tools.javac.tree.JCTree.
JCCompilationUnit
;
import
com.sun.tools.javac.util.List
;
import
com.sun.tools.javac.util.List
;
public
class
TreeScannerTest
{
public
abstract
class
AbstractTreeScannerTest
{
/**
* Main entry point.
* If test.src is set, program runs in jtreg mode, and will throw an Error
* if any errors arise, otherwise System.exit will be used. In jtreg mode,
* the default base directory for file args is the value of ${test.src}.
* In jtreg mode, the -r option can be given to change the default base
* directory to the root test directory.
*/
public
static
void
main
(
String
...
args
)
{
String
testSrc
=
System
.
getProperty
(
"test.src"
);
File
baseDir
=
(
testSrc
==
null
)
?
null
:
new
File
(
testSrc
);
boolean
ok
=
new
TreeScannerTest
().
run
(
baseDir
,
args
);
if
(!
ok
)
{
if
(
testSrc
!=
null
)
// jtreg mode
throw
new
Error
(
"failed"
);
else
System
.
exit
(
1
);
}
}
/**
/**
* Run the program. A base directory can be provided for file arguments.
* Run the program. A base directory can be provided for file arguments.
...
@@ -120,6 +83,7 @@ public class TreeScannerTest {
...
@@ -120,6 +83,7 @@ public class TreeScannerTest {
if
(
fileCount
!=
1
)
if
(
fileCount
!=
1
)
System
.
err
.
println
(
fileCount
+
" files read"
);
System
.
err
.
println
(
fileCount
+
" files read"
);
System
.
err
.
println
(
treeCount
+
" tree nodes compared"
);
if
(
errors
>
0
)
if
(
errors
>
0
)
System
.
err
.
println
(
errors
+
" errors"
);
System
.
err
.
println
(
errors
+
" errors"
);
...
@@ -132,7 +96,7 @@ public class TreeScannerTest {
...
@@ -132,7 +96,7 @@ public class TreeScannerTest {
*/
*/
void
usage
(
PrintStream
out
)
{
void
usage
(
PrintStream
out
)
{
out
.
println
(
"Usage:"
);
out
.
println
(
"Usage:"
);
out
.
println
(
" java
TreeScannerTest
options... files..."
);
out
.
println
(
" java
"
+
getClass
().
getName
()
+
"
options... files..."
);
out
.
println
(
""
);
out
.
println
(
""
);
out
.
println
(
"where options include:"
);
out
.
println
(
"where options include:"
);
out
.
println
(
"-q Quiet: don't report on inapplicable files"
);
out
.
println
(
"-q Quiet: don't report on inapplicable files"
);
...
@@ -162,8 +126,7 @@ public class TreeScannerTest {
...
@@ -162,8 +126,7 @@ public class TreeScannerTest {
if
(
verbose
)
if
(
verbose
)
System
.
err
.
println
(
file
);
System
.
err
.
println
(
file
);
fileCount
++;
fileCount
++;
ScanTester
t
=
new
ScanTester
();
treeCount
+=
test
(
read
(
file
));
t
.
test
(
read
(
file
));
}
catch
(
ParseException
e
)
{
}
catch
(
ParseException
e
)
{
if
(!
quiet
)
{
if
(!
quiet
)
{
error
(
"Error parsing "
+
file
+
"\n"
+
e
.
getMessage
());
error
(
"Error parsing "
+
file
+
"\n"
+
e
.
getMessage
());
...
@@ -178,6 +141,8 @@ public class TreeScannerTest {
...
@@ -178,6 +141,8 @@ public class TreeScannerTest {
error
(
"File "
+
file
+
" ignored"
);
error
(
"File "
+
file
+
" ignored"
);
}
}
abstract
int
test
(
JCCompilationUnit
t
);
/**
/**
* Read a file.
* Read a file.
* @param file the file to be read
* @param file the file to be read
...
@@ -222,20 +187,24 @@ public class TreeScannerTest {
...
@@ -222,20 +187,24 @@ public class TreeScannerTest {
* @param t the tree node
* @param t the tree node
* @param label an indication of the error
* @param label an indication of the error
*/
*/
void
error
(
JavaFileObject
file
,
JCTree
t
,
String
msg
)
{
void
error
(
JavaFileObject
file
,
Tree
tree
,
String
msg
)
{
JCTree
t
=
(
JCTree
)
tree
;
error
(
file
.
getName
()
+
":"
+
getLine
(
file
,
t
)
+
": "
+
msg
+
" "
+
trim
(
t
,
64
));
error
(
file
.
getName
()
+
":"
+
getLine
(
file
,
t
)
+
": "
+
msg
+
" "
+
trim
(
t
,
64
));
}
}
/**
/**
* Get a trimmed string for a tree node, with normalized white space and limited length.
* Get a trimmed string for a tree node, with normalized white space and limited length.
*/
*/
String
trim
(
JCTree
t
,
int
len
)
{
String
trim
(
Tree
tree
,
int
len
)
{
JCTree
t
=
(
JCTree
)
tree
;
String
s
=
t
.
toString
().
replaceAll
(
"[\r\n]+"
,
" "
).
replaceAll
(
" +"
,
" "
);
String
s
=
t
.
toString
().
replaceAll
(
"[\r\n]+"
,
" "
).
replaceAll
(
" +"
,
" "
);
return
(
s
.
length
()
<
len
)
?
s
:
s
.
substring
(
0
,
len
);
return
(
s
.
length
()
<
len
)
?
s
:
s
.
substring
(
0
,
len
);
}
}
/** Number of files that have been analyzed. */
/** Number of files that have been analyzed. */
int
fileCount
;
int
fileCount
;
/** Number of trees that have been successfully compared. */
int
treeCount
;
/** Number of errors reported. */
/** Number of errors reported. */
int
errors
;
int
errors
;
/** Flag: don't report irrelevant files. */
/** Flag: don't report irrelevant files. */
...
@@ -243,78 +212,6 @@ public class TreeScannerTest {
...
@@ -243,78 +212,6 @@ public class TreeScannerTest {
/** Flag: report files as they are processed. */
/** Flag: report files as they are processed. */
boolean
verbose
;
boolean
verbose
;
/**
* Main class for testing operation of tree scanner.
* The set of nodes found by the scanner are compared
* against the set of nodes found by reflection.
*/
private
class
ScanTester
extends
TreeScanner
{
/** Main entry method for the class. */
void
test
(
JCCompilationUnit
tree
)
{
sourcefile
=
tree
.
sourcefile
;
found
=
new
HashSet
<
JCTree
>();
scan
(
tree
);
expect
=
new
HashSet
<
JCTree
>();
reflectiveScan
(
tree
);
if
(
found
.
equals
(
expect
))
return
;
error
(
"Differences found for "
+
tree
.
sourcefile
.
getName
());
if
(
found
.
size
()
!=
expect
.
size
())
error
(
"Size mismatch; found: "
+
found
.
size
()
+
", expected: "
+
expect
.
size
());
Set
<
JCTree
>
missing
=
new
HashSet
<
JCTree
>();
missing
.
addAll
(
expect
);
missing
.
removeAll
(
found
);
for
(
JCTree
t:
missing
)
error
(
tree
.
sourcefile
,
t
,
"missing"
);
Set
<
JCTree
>
excess
=
new
HashSet
<
JCTree
>();
excess
.
addAll
(
found
);
excess
.
removeAll
(
expect
);
for
(
JCTree
t:
excess
)
error
(
tree
.
sourcefile
,
t
,
"unexpected"
);
}
/** Record all tree nodes found by scanner. */
@Override
public
void
scan
(
JCTree
tree
)
{
if
(
tree
==
null
)
return
;
System
.
err
.
println
(
"FOUND: "
+
tree
.
getTag
()
+
" "
+
trim
(
tree
,
64
));
found
.
add
(
tree
);
super
.
scan
(
tree
);
}
/** record all tree nodes found by reflection. */
public
void
reflectiveScan
(
Object
o
)
{
if
(
o
==
null
)
return
;
if
(
o
instanceof
JCTree
)
{
JCTree
tree
=
(
JCTree
)
o
;
System
.
err
.
println
(
"EXPECT: "
+
tree
.
getTag
()
+
" "
+
trim
(
tree
,
64
));
expect
.
add
(
tree
);
for
(
Field
f:
getFields
(
tree
))
{
try
{
//System.err.println("FIELD: " + f.getName());
reflectiveScan
(
f
.
get
(
tree
));
}
catch
(
IllegalAccessException
e
)
{
error
(
e
.
toString
());
}
}
}
else
if
(
o
instanceof
List
)
{
List
<?>
list
=
(
List
<?>)
o
;
for
(
Object
item:
list
)
reflectiveScan
(
item
);
}
else
error
(
"unexpected item: "
+
o
);
}
JavaFileObject
sourcefile
;
Set
<
JCTree
>
found
;
Set
<
JCTree
>
expect
;
}
/**
/**
* Thrown when errors are found parsing a java file.
* Thrown when errors are found parsing a java file.
...
...
test/tools/javac/tree/JavacTreeScannerTest.java
0 → 100644
浏览文件 @
6eeac523
/*
* 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.
*/
/**
* Utility and test program to check javac's internal TreeScanner class.
* The program can be run standalone, or as a jtreg test. For info on
* command line args, run program with no args.
*
* <p>
* jtreg: Note that by using the -r switch in the test description below, this test
* will process all java files in the langtools/test directory, thus implicitly
* covering any new language features that may be tested in this test suite.
*/
/*
* @test
* @bug 6923080
* @summary TreeScanner.visitNewClass should scan tree.typeargs
* @build AbstractTreeScannerTest JavacTreeScannerTest
* @run main JavacTreeScannerTest -q -r .
*/
import
java.io.*
;
import
java.lang.reflect.*
;
import
java.util.*
;
import
javax.tools.*
;
import
com.sun.tools.javac.tree.JCTree
;
import
com.sun.tools.javac.tree.JCTree.JCCompilationUnit
;
import
com.sun.tools.javac.tree.TreeScanner
;
import
com.sun.tools.javac.util.List
;
public
class
JavacTreeScannerTest
extends
AbstractTreeScannerTest
{
/**
* Main entry point.
* If test.src is set, program runs in jtreg mode, and will throw an Error
* if any errors arise, otherwise System.exit will be used. In jtreg mode,
* the default base directory for file args is the value of ${test.src}.
* In jtreg mode, the -r option can be given to change the default base
* directory to the root test directory.
*/
public
static
void
main
(
String
...
args
)
{
String
testSrc
=
System
.
getProperty
(
"test.src"
);
File
baseDir
=
(
testSrc
==
null
)
?
null
:
new
File
(
testSrc
);
boolean
ok
=
new
JavacTreeScannerTest
().
run
(
baseDir
,
args
);
if
(!
ok
)
{
if
(
testSrc
!=
null
)
// jtreg mode
throw
new
Error
(
"failed"
);
else
System
.
exit
(
1
);
}
}
int
test
(
JCCompilationUnit
tree
)
{
return
new
ScanTester
().
test
(
tree
);
}
/**
* Main class for testing operation of tree scanner.
* The set of nodes found by the scanner are compared
* against the set of nodes found by reflection.
*/
private
class
ScanTester
extends
TreeScanner
{
/** Main entry method for the class. */
int
test
(
JCCompilationUnit
tree
)
{
sourcefile
=
tree
.
sourcefile
;
found
=
new
HashSet
<
JCTree
>();
scan
(
tree
);
expect
=
new
HashSet
<
JCTree
>();
reflectiveScan
(
tree
);
if
(
found
.
equals
(
expect
))
{
System
.
err
.
println
(
found
.
size
()
+
" trees compared OK"
);
return
found
.
size
();
}
error
(
"Differences found for "
+
tree
.
sourcefile
.
getName
());
if
(
found
.
size
()
!=
expect
.
size
())
error
(
"Size mismatch; found: "
+
found
.
size
()
+
", expected: "
+
expect
.
size
());
Set
<
JCTree
>
missing
=
new
HashSet
<
JCTree
>();
missing
.
addAll
(
expect
);
missing
.
removeAll
(
found
);
for
(
JCTree
t:
missing
)
error
(
tree
.
sourcefile
,
t
,
"missing"
);
Set
<
JCTree
>
excess
=
new
HashSet
<
JCTree
>();
excess
.
addAll
(
found
);
excess
.
removeAll
(
expect
);
for
(
JCTree
t:
excess
)
error
(
tree
.
sourcefile
,
t
,
"unexpected"
);
return
0
;
}
/** Record all tree nodes found by scanner. */
@Override
public
void
scan
(
JCTree
tree
)
{
if
(
tree
==
null
)
return
;
System
.
err
.
println
(
"FOUND: "
+
tree
.
getTag
()
+
" "
+
trim
(
tree
,
64
));
found
.
add
(
tree
);
super
.
scan
(
tree
);
}
/** record all tree nodes found by reflection. */
public
void
reflectiveScan
(
Object
o
)
{
if
(
o
==
null
)
return
;
if
(
o
instanceof
JCTree
)
{
JCTree
tree
=
(
JCTree
)
o
;
System
.
err
.
println
(
"EXPECT: "
+
tree
.
getTag
()
+
" "
+
trim
(
tree
,
64
));
expect
.
add
(
tree
);
for
(
Field
f:
getFields
(
tree
))
{
try
{
//System.err.println("FIELD: " + f.getName());
reflectiveScan
(
f
.
get
(
tree
));
}
catch
(
IllegalAccessException
e
)
{
error
(
e
.
toString
());
}
}
}
else
if
(
o
instanceof
List
)
{
List
<?>
list
=
(
List
<?>)
o
;
for
(
Object
item:
list
)
reflectiveScan
(
item
);
}
else
error
(
"unexpected item: "
+
o
);
}
JavaFileObject
sourcefile
;
Set
<
JCTree
>
found
;
Set
<
JCTree
>
expect
;
}
}
test/tools/javac/tree/SourceTreeScannerTest.java
0 → 100644
浏览文件 @
6eeac523
/*
* 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.
*/
/**
* Utility and test program to check javac's internal TreeScanner class.
* The program can be run standalone, or as a jtreg test. For info on
* command line args, run program with no args.
*
* <p>
* jtreg: Note that by using the -r switch in the test description below, this test
* will process all java files in the langtools/test directory, thus implicitly
* covering any new language features that may be tested in this test suite.
*/
/*
* @test
* @bug 6923080
* @summary TreeScanner.visitNewClass should scan tree.typeargs
* @build AbstractTreeScannerTest SourceTreeScannerTest
* @run main SourceTreeScannerTest -q -r .
*/
import
java.io.*
;
import
java.lang.reflect.*
;
import
java.util.*
;
import
javax.tools.*
;
import
com.sun.source.tree.Tree
;
import
com.sun.source.util.TreeScanner
;
import
com.sun.tools.javac.tree.JCTree
;
import
com.sun.tools.javac.tree.JCTree.JCCompilationUnit
;
import
com.sun.tools.javac.tree.JCTree.TypeBoundKind
;
import
com.sun.tools.javac.util.List
;
public
class
SourceTreeScannerTest
extends
AbstractTreeScannerTest
{
/**
* Main entry point.
* If test.src is set, program runs in jtreg mode, and will throw an Error
* if any errors arise, otherwise System.exit will be used. In jtreg mode,
* the default base directory for file args is the value of ${test.src}.
* In jtreg mode, the -r option can be given to change the default base
* directory to the root test directory.
*/
public
static
void
main
(
String
...
args
)
{
String
testSrc
=
System
.
getProperty
(
"test.src"
);
File
baseDir
=
(
testSrc
==
null
)
?
null
:
new
File
(
testSrc
);
boolean
ok
=
new
SourceTreeScannerTest
().
run
(
baseDir
,
args
);
if
(!
ok
)
{
if
(
testSrc
!=
null
)
// jtreg mode
throw
new
Error
(
"failed"
);
else
System
.
exit
(
1
);
}
}
int
test
(
JCCompilationUnit
tree
)
{
return
new
ScanTester
().
test
(
tree
);
}
/**
* Main class for testing operation of tree scanner.
* The set of nodes found by the scanner are compared
* against the set of nodes found by reflection.
*/
private
class
ScanTester
extends
TreeScanner
<
Void
,
Void
>
{
/** Main entry method for the class. */
int
test
(
JCCompilationUnit
tree
)
{
sourcefile
=
tree
.
sourcefile
;
found
=
new
HashSet
<
Tree
>();
scan
(
tree
,
null
);
expect
=
new
HashSet
<
Tree
>();
reflectiveScan
(
tree
);
if
(
found
.
equals
(
expect
))
{
System
.
err
.
println
(
found
.
size
()
+
" trees compared OK"
);
return
found
.
size
();
}
error
(
"Differences found for "
+
tree
.
sourcefile
.
getName
());
if
(
found
.
size
()
!=
expect
.
size
())
error
(
"Size mismatch; found: "
+
found
.
size
()
+
", expected: "
+
expect
.
size
());
Set
<
Tree
>
missing
=
new
HashSet
<
Tree
>();
missing
.
addAll
(
expect
);
missing
.
removeAll
(
found
);
for
(
Tree
t:
missing
)
error
(
tree
.
sourcefile
,
t
,
"missing"
);
Set
<
Tree
>
excess
=
new
HashSet
<
Tree
>();
excess
.
addAll
(
found
);
excess
.
removeAll
(
expect
);
for
(
Tree
t:
excess
)
error
(
tree
.
sourcefile
,
t
,
"unexpected"
);
return
0
;
}
/** Record all tree nodes found by scanner. */
@Override
public
Void
scan
(
Tree
tree
,
Void
ignore
)
{
if
(
tree
==
null
)
return
null
;
System
.
err
.
println
(
"FOUND: "
+
tree
.
getKind
()
+
" "
+
trim
(
tree
,
64
));
found
.
add
(
tree
);
return
super
.
scan
(
tree
,
ignore
);
}
/** record all tree nodes found by reflection. */
public
void
reflectiveScan
(
Object
o
)
{
if
(
o
==
null
)
return
;
if
(
o
instanceof
JCTree
)
{
JCTree
tree
=
(
JCTree
)
o
;
System
.
err
.
println
(
"EXPECT: "
+
tree
.
getKind
()
+
" "
+
trim
(
tree
,
64
));
expect
.
add
(
tree
);
for
(
Field
f:
getFields
(
tree
))
{
if
(
TypeBoundKind
.
class
.
isAssignableFrom
(
f
.
getType
()))
{
// not part of public API
continue
;
}
if
(
JCTree
.
JCNewArray
.
class
.
isAssignableFrom
(
tree
.
getClass
())
&&
(
f
.
getName
().
equals
(
"annotations"
)
||
f
.
getName
().
equals
(
"dimAnnotations"
)))
{
// these fields are incorrectly missing from the public API
// (CR 6983297)
continue
;
}
try
{
//System.err.println("FIELD: " + f.getName());
reflectiveScan
(
f
.
get
(
tree
));
}
catch
(
IllegalAccessException
e
)
{
error
(
e
.
toString
());
}
}
}
else
if
(
o
instanceof
List
)
{
List
<?>
list
=
(
List
<?>)
o
;
for
(
Object
item:
list
)
reflectiveScan
(
item
);
}
else
error
(
"unexpected item: "
+
o
);
}
JavaFileObject
sourcefile
;
Set
<
Tree
>
found
;
Set
<
Tree
>
expect
;
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录