Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_langtools
提交
8c89a549
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看板
提交
8c89a549
编写于
12月 07, 2011
作者:
K
ksrini
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
7086015: fix test/tools/javac/parser/netbeans/JavacParserTest.java
Reviewed-by: ksrini, jjg Contributed-by: matherey.nunez@oracle.com
上级
8c3bcb45
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
186 addition
and
23 deletion
+186
-23
test/tools/javac/parser/netbeans/JavacParserTest.java
test/tools/javac/parser/netbeans/JavacParserTest.java
+186
-23
未找到文件。
test/tools/javac/parser/netbeans/JavacParserTest.java
浏览文件 @
8c89a549
...
...
@@ -32,6 +32,7 @@ import com.sun.source.tree.BinaryTree;
import
com.sun.source.tree.BlockTree
;
import
com.sun.source.tree.ClassTree
;
import
com.sun.source.tree.CompilationUnitTree
;
import
com.sun.source.tree.ErroneousTree
;
import
com.sun.source.tree.ExpressionStatementTree
;
import
com.sun.source.tree.ExpressionTree
;
import
com.sun.source.tree.MethodInvocationTree
;
...
...
@@ -49,6 +50,7 @@ import com.sun.tools.javac.api.JavacTaskImpl;
import
com.sun.tools.javac.tree.JCTree
;
import
java.io.IOException
;
import
java.net.URI
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.LinkedList
;
import
java.util.List
;
...
...
@@ -82,6 +84,30 @@ public class JavacParserTest extends TestCase {
}
}
public
CompilationUnitTree
getCompilationUnitTree
(
String
code
)
throws
IOException
{
JavacTaskImpl
ct
=
(
JavacTaskImpl
)
tool
.
getTask
(
null
,
null
,
null
,
null
,
null
,
Arrays
.
asList
(
new
MyFileObject
(
code
)));
CompilationUnitTree
cut
=
ct
.
parse
().
iterator
().
next
();
return
cut
;
}
public
List
<
String
>
getErroneousTreeValues
(
ErroneousTree
node
)
{
List
<
String
>
values
=
new
ArrayList
<>();
if
(
node
.
getErrorTrees
()
!=
null
)
{
for
(
Tree
t
:
node
.
getErrorTrees
())
{
values
.
add
(
t
.
toString
());
}
}
else
{
throw
new
RuntimeException
(
"ERROR: No Erroneous tree "
+
"has been created."
);
}
return
values
;
}
public
void
testPositionForSuperConstructorCalls
()
throws
IOException
{
assert
tool
!=
null
;
...
...
@@ -97,22 +123,28 @@ public class JavacParserTest extends TestCase {
ExpressionStatementTree
es
=
(
ExpressionStatementTree
)
method
.
getBody
().
getStatements
().
get
(
0
);
final
int
esStartPos
=
code
.
indexOf
(
es
.
toString
());
final
int
esEndPos
=
esStartPos
+
es
.
toString
().
length
();
assertEquals
(
"testPositionForSuperConstructorCalls"
,
72
-
24
,
pos
.
getStartPosition
(
cut
,
es
));
esStartPos
,
pos
.
getStartPosition
(
cut
,
es
));
assertEquals
(
"testPositionForSuperConstructorCalls"
,
80
-
24
,
pos
.
getEndPosition
(
cut
,
es
));
esEndPos
,
pos
.
getEndPosition
(
cut
,
es
));
MethodInvocationTree
mit
=
(
MethodInvocationTree
)
es
.
getExpression
();
final
int
mitStartPos
=
code
.
indexOf
(
mit
.
toString
());
final
int
mitEndPos
=
mitStartPos
+
mit
.
toString
().
length
();
assertEquals
(
"testPositionForSuperConstructorCalls"
,
72
-
24
,
pos
.
getStartPosition
(
cut
,
mit
));
mitStartPos
,
pos
.
getStartPosition
(
cut
,
mit
));
assertEquals
(
"testPositionForSuperConstructorCalls"
,
79
-
24
,
pos
.
getEndPosition
(
cut
,
mit
));
mitEndPos
,
pos
.
getEndPosition
(
cut
,
mit
));
final
int
methodStartPos
=
mitStartPos
;
final
int
methodEndPos
=
methodStartPos
+
mit
.
getMethodSelect
().
toString
().
length
();
assertEquals
(
"testPositionForSuperConstructorCalls"
,
72
-
24
,
pos
.
getStartPosition
(
cut
,
mit
.
getMethodSelect
()));
methodStartPos
,
pos
.
getStartPosition
(
cut
,
mit
.
getMethodSelect
()));
assertEquals
(
"testPositionForSuperConstructorCalls"
,
77
-
24
,
pos
.
getEndPosition
(
cut
,
mit
.
getMethodSelect
()));
methodEndPos
,
pos
.
getEndPosition
(
cut
,
mit
.
getMethodSelect
()));
}
...
...
@@ -158,24 +190,21 @@ public class JavacParserTest extends TestCase {
public
void
testPreferredPositionForBinaryOp
()
throws
IOException
{
String
code
=
"package test; public class Test {"
+
"private void test() {"
+
"Object o = null; boolean b = o != null && o instanceof String;"
+
"} private Test() {}}"
;
JavacTaskImpl
ct
=
(
JavacTaskImpl
)
tool
.
getTask
(
null
,
null
,
null
,
null
,
null
,
Arrays
.
asList
(
new
MyFileObject
(
code
)));
CompilationUnitTree
cut
=
ct
.
parse
().
iterator
().
next
();
String
code
=
"package test; public class Test {"
+
"private void test() {"
+
"Object o = null; boolean b = o != null && o instanceof String;"
+
"} private Test() {}}"
;
CompilationUnitTree
cut
=
getCompilationUnitTree
(
code
);
ClassTree
clazz
=
(
ClassTree
)
cut
.
getTypeDecls
().
get
(
0
);
MethodTree
method
=
(
MethodTree
)
clazz
.
getMembers
().
get
(
0
);
VariableTree
condSt
=
(
VariableTree
)
method
.
getBody
().
getStatements
().
get
(
1
);
BinaryTree
cond
=
(
BinaryTree
)
condSt
.
getInitializer
();
JCTree
condJC
=
(
JCTree
)
cond
;
assertEquals
(
"test
NewClassWithEnclosing
"
,
117
-
24
,
condJC
.
pos
);
int
condStartPos
=
code
.
indexOf
(
"&&"
);
assertEquals
(
"test
PreferredPositionForBinaryOp
"
,
condStartPos
,
condJC
.
pos
);
}
public
void
testPositionBrokenSource126732a
()
throws
IOException
{
...
...
@@ -599,9 +628,7 @@ public class JavacParserTest extends TestCase {
final
String
code
=
"package t; class Test { "
+
"{ try (java.io.InputStream in = null) { } } }"
;
JavacTaskImpl
ct
=
(
JavacTaskImpl
)
tool
.
getTask
(
null
,
null
,
null
,
null
,
null
,
Arrays
.
asList
(
new
MyFileObject
(
code
)));
CompilationUnitTree
cut
=
ct
.
parse
().
iterator
().
next
();
CompilationUnitTree
cut
=
getCompilationUnitTree
(
code
);
new
TreeScanner
<
Void
,
Void
>()
{
@Override
...
...
@@ -622,9 +649,7 @@ public class JavacParserTest extends TestCase {
final
String
code
=
"package t; class Test { "
+
"{ java.io.InputStream in = null; } }"
;
JavacTaskImpl
ct
=
(
JavacTaskImpl
)
tool
.
getTask
(
null
,
null
,
null
,
null
,
null
,
Arrays
.
asList
(
new
MyFileObject
(
code
)));
CompilationUnitTree
cut
=
ct
.
parse
().
iterator
().
next
();
CompilationUnitTree
cut
=
getCompilationUnitTree
(
code
);
new
TreeScanner
<
Void
,
Void
>()
{
...
...
@@ -640,6 +665,138 @@ public class JavacParserTest extends TestCase {
}.
scan
(
cut
,
null
);
}
// expected erroneous tree: int x = y;(ERROR);
public
void
testOperatorMissingError
()
throws
IOException
{
String
code
=
"package test; public class ErrorTest { "
+
"void method() { int x = y z } }"
;
CompilationUnitTree
cut
=
getCompilationUnitTree
(
code
);
final
List
<
String
>
values
=
new
ArrayList
<>();
final
List
<
String
>
expectedValues
=
new
ArrayList
<>(
Arrays
.
asList
(
"[z]"
));
new
TreeScanner
<
Void
,
Void
>()
{
@Override
public
Void
visitErroneous
(
ErroneousTree
node
,
Void
p
)
{
values
.
add
(
getErroneousTreeValues
(
node
).
toString
());
return
null
;
}
}.
scan
(
cut
,
null
);
assertEquals
(
"testSwitchError: The Erroneous tree "
+
"error values: "
+
values
+
" do not match expected error values: "
+
expectedValues
,
values
,
expectedValues
);
}
//expected erroneous tree: String s = (ERROR);
public
void
testMissingParenthesisError
()
throws
IOException
{
String
code
=
"package test; public class ErrorTest { "
+
"void f() {String s = new String; } }"
;
CompilationUnitTree
cut
=
getCompilationUnitTree
(
code
);
final
List
<
String
>
values
=
new
ArrayList
<>();
final
List
<
String
>
expectedValues
=
new
ArrayList
<>(
Arrays
.
asList
(
"[new String()]"
));
new
TreeScanner
<
Void
,
Void
>()
{
@Override
public
Void
visitErroneous
(
ErroneousTree
node
,
Void
p
)
{
values
.
add
(
getErroneousTreeValues
(
node
).
toString
());
return
null
;
}
}.
scan
(
cut
,
null
);
assertEquals
(
"testSwitchError: The Erroneous tree "
+
"error values: "
+
values
+
" do not match expected error values: "
+
expectedValues
,
values
,
expectedValues
);
}
//expected erroneous tree: package test; (ERROR)(ERROR)
public
void
testMissingClassError
()
throws
IOException
{
String
code
=
"package Test; clas ErrorTest { "
+
"void f() {String s = new String(); } }"
;
CompilationUnitTree
cut
=
getCompilationUnitTree
(
code
);
final
List
<
String
>
values
=
new
ArrayList
<>();
final
List
<
String
>
expectedValues
=
new
ArrayList
<>(
Arrays
.
asList
(
"[, clas]"
,
"[]"
));
new
TreeScanner
<
Void
,
Void
>()
{
@Override
public
Void
visitErroneous
(
ErroneousTree
node
,
Void
p
)
{
values
.
add
(
getErroneousTreeValues
(
node
).
toString
());
return
null
;
}
}.
scan
(
cut
,
null
);
assertEquals
(
"testSwitchError: The Erroneous tree "
+
"error values: "
+
values
+
" do not match expected error values: "
+
expectedValues
,
values
,
expectedValues
);
}
//expected erroneous tree: void m1(int i) {(ERROR);{(ERROR);}
public
void
testSwitchError
()
throws
IOException
{
String
code
=
"package test; public class ErrorTest { "
+
"int numDays; void m1(int i) { switchh {i} { case 1: "
+
"numDays = 31; break; } } }"
;
CompilationUnitTree
cut
=
getCompilationUnitTree
(
code
);
final
List
<
String
>
values
=
new
ArrayList
<>();
final
List
<
String
>
expectedValues
=
new
ArrayList
<>(
Arrays
.
asList
(
"[switchh]"
,
"[i]"
));
new
TreeScanner
<
Void
,
Void
>()
{
@Override
public
Void
visitErroneous
(
ErroneousTree
node
,
Void
p
)
{
values
.
add
(
getErroneousTreeValues
(
node
).
toString
());
return
null
;
}
}.
scan
(
cut
,
null
);
assertEquals
(
"testSwitchError: The Erroneous tree "
+
"error values: "
+
values
+
" do not match expected error values: "
+
expectedValues
,
values
,
expectedValues
);
}
//expected erroneous tree: class ErrorTest {(ERROR)
public
void
testMethodError
()
throws
IOException
{
String
code
=
"package Test; class ErrorTest { "
+
"static final void f) {String s = new String(); } }"
;
CompilationUnitTree
cut
=
getCompilationUnitTree
(
code
);
final
List
<
String
>
values
=
new
ArrayList
<>();
final
List
<
String
>
expectedValues
=
new
ArrayList
<>(
Arrays
.
asList
(
"[\nstatic final void f();]"
));
new
TreeScanner
<
Void
,
Void
>()
{
@Override
public
Void
visitErroneous
(
ErroneousTree
node
,
Void
p
)
{
values
.
add
(
getErroneousTreeValues
(
node
).
toString
());
return
null
;
}
}.
scan
(
cut
,
null
);
assertEquals
(
"testMethodError: The Erroneous tree "
+
"error value: "
+
values
+
" does not match expected error values: "
+
expectedValues
,
values
,
expectedValues
);
}
void
testsNotWorking
()
throws
IOException
{
// Fails with nb-javac, needs further investigation
...
...
@@ -661,7 +818,13 @@ public class JavacParserTest extends TestCase {
testStartPositionForMethodWithoutModifiers
();
testVarPos
();
testVariableInIfThen3
();
testMissingExponent
();
testTryResourcePos
();
testOperatorMissingError
();
testMissingParenthesisError
();
testMissingClassError
();
testSwitchError
();
testMethodError
();
}
public
static
void
main
(
String
...
args
)
throws
IOException
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录