Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_langtools
提交
5c97fe66
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看板
提交
5c97fe66
编写于
9月 14, 2011
作者:
J
jjg
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
7090249: IllegalStateException from Trees.getScope when called from JSR 199
Reviewed-by: mcimadamore
上级
aabe9829
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
123 addition
and
8 deletion
+123
-8
src/share/classes/com/sun/tools/javac/api/JavacTaskImpl.java
src/share/classes/com/sun/tools/javac/api/JavacTaskImpl.java
+3
-0
src/share/classes/com/sun/tools/javac/api/JavacTrees.java
src/share/classes/com/sun/tools/javac/api/JavacTrees.java
+19
-8
test/tools/javac/api/TestGetScope.java
test/tools/javac/api/TestGetScope.java
+101
-0
未找到文件。
src/share/classes/com/sun/tools/javac/api/JavacTaskImpl.java
浏览文件 @
5c97fe66
...
...
@@ -274,6 +274,9 @@ public class JavacTaskImpl extends JavacTask {
public
Iterable
<?
extends
TypeElement
>
enter
(
Iterable
<?
extends
CompilationUnitTree
>
trees
)
throws
IOException
{
if
(
trees
==
null
&&
notYetEntered
!=
null
&&
notYetEntered
.
isEmpty
())
return
List
.
nil
();
prepareCompiler
();
ListBuffer
<
JCCompilationUnit
>
roots
=
null
;
...
...
src/share/classes/com/sun/tools/javac/api/JavacTrees.java
浏览文件 @
5c97fe66
...
...
@@ -65,6 +65,7 @@ import com.sun.tools.javac.tree.JCTree;
import
com.sun.tools.javac.tree.TreeCopier
;
import
com.sun.tools.javac.tree.TreeInfo
;
import
com.sun.tools.javac.tree.TreeMaker
;
import
com.sun.tools.javac.util.Assert
;
import
com.sun.tools.javac.util.Context
;
import
com.sun.tools.javac.util.JCDiagnostic
;
import
com.sun.tools.javac.util.List
;
...
...
@@ -263,9 +264,10 @@ public class JavacTrees extends Trees {
if
(!(
path
.
getLeaf
()
instanceof
JCTree
))
// implicit null-check
throw
new
IllegalArgumentException
();
// if we're being invoked via from a JSR199 client, we need to make sure
// all the classes have been entered; if we're being invoked from JSR269,
// then the classes will already have been entered.
// if we're being invoked from a Tree API client via parse/enter/analyze,
// we need to make sure all the classes have been entered;
// if we're being invoked from JSR 199 or JSR 269, then the classes
// will already have been entered.
if
(
javacTaskImpl
!=
null
)
{
try
{
javacTaskImpl
.
enter
(
null
);
...
...
@@ -313,10 +315,19 @@ public class JavacTrees extends Trees {
break
;
case
BLOCK:
{
// System.err.println("BLOCK: ");
if
(
method
!=
null
)
env
=
memberEnter
.
getMethodEnv
(
method
,
env
);
JCTree
body
=
copier
.
copy
((
JCTree
)
tree
,
(
JCTree
)
path
.
getLeaf
());
env
=
attribStatToTree
(
body
,
env
,
copier
.
leafCopy
);
if
(
method
!=
null
)
{
try
{
Assert
.
check
(
method
.
body
==
tree
);
method
.
body
=
copier
.
copy
((
JCBlock
)
tree
,
(
JCTree
)
path
.
getLeaf
());
env
=
memberEnter
.
getMethodEnv
(
method
,
env
);
env
=
attribStatToTree
(
method
.
body
,
env
,
copier
.
leafCopy
);
}
finally
{
method
.
body
=
(
JCBlock
)
tree
;
}
}
else
{
JCBlock
body
=
copier
.
copy
((
JCBlock
)
tree
,
(
JCTree
)
path
.
getLeaf
());
env
=
attribStatToTree
(
body
,
env
,
copier
.
leafCopy
);
}
return
env
;
}
default
:
...
...
@@ -329,7 +340,7 @@ public class JavacTrees extends Trees {
}
}
}
return
field
!=
null
?
memberEnter
.
getInitEnv
(
field
,
env
)
:
env
;
return
(
field
!=
null
)
?
memberEnter
.
getInitEnv
(
field
,
env
)
:
env
;
}
private
Env
<
AttrContext
>
attribStatToTree
(
JCTree
stat
,
Env
<
AttrContext
>
env
,
JCTree
tree
)
{
...
...
test/tools/javac/api/TestGetScope.java
0 → 100644
浏览文件 @
5c97fe66
/*
* Copyright (c) 2011, 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 7090249
* @summary IllegalStateException from Trees.getScope when called from JSR 199
*/
import
com.sun.source.tree.IdentifierTree
;
import
java.io.File
;
import
java.util.Arrays
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.Set
;
import
javax.annotation.processing.AbstractProcessor
;
import
javax.annotation.processing.RoundEnvironment
;
import
javax.lang.model.element.Element
;
import
javax.lang.model.element.TypeElement
;
import
javax.tools.JavaCompiler
;
import
javax.tools.JavaFileObject
;
import
javax.tools.StandardJavaFileManager
;
import
javax.tools.ToolProvider
;
import
com.sun.source.util.JavacTask
;
import
com.sun.source.util.TreePath
;
import
com.sun.source.util.TreePathScanner
;
import
com.sun.source.util.Trees
;
import
javax.annotation.processing.SupportedAnnotationTypes
;
import
javax.lang.model.SourceVersion
;
@SupportedAnnotationTypes
(
"*"
)
public
class
TestGetScope
extends
AbstractProcessor
{
public
static
void
main
(
String
...
args
)
{
new
TestGetScope
().
run
();
}
public
void
run
()
{
File
srcDir
=
new
File
(
System
.
getProperty
(
"test.src"
));
File
thisFile
=
new
File
(
srcDir
,
getClass
().
getName
()
+
".java"
);
JavaCompiler
c
=
ToolProvider
.
getSystemJavaCompiler
();
StandardJavaFileManager
fm
=
c
.
getStandardFileManager
(
null
,
null
,
null
);
List
<
String
>
opts
=
Arrays
.
asList
(
"-proc:only"
,
"-doe"
);
Iterable
<?
extends
JavaFileObject
>
files
=
fm
.
getJavaFileObjects
(
thisFile
);
JavacTask
t
=
(
JavacTask
)
c
.
getTask
(
null
,
fm
,
null
,
opts
,
null
,
files
);
t
.
setProcessors
(
Collections
.
singleton
(
this
));
boolean
ok
=
t
.
call
();
if
(!
ok
)
throw
new
Error
(
"compilation failed"
);
}
@Override
public
boolean
process
(
Set
<?
extends
TypeElement
>
annotations
,
RoundEnvironment
roundEnv
)
{
Trees
trees
=
Trees
.
instance
(
processingEnv
);
if
(
round
++
==
0
)
{
for
(
Element
e:
roundEnv
.
getRootElements
())
{
TreePath
p
=
trees
.
getPath
(
e
);
new
Scanner
().
scan
(
p
,
trees
);
}
}
return
false
;
}
@Override
public
SourceVersion
getSupportedSourceVersion
()
{
return
SourceVersion
.
latest
();
}
int
round
;
static
class
Scanner
extends
TreePathScanner
<
Void
,
Trees
>
{
@Override
public
Void
visitIdentifier
(
IdentifierTree
t
,
Trees
trees
)
{
System
.
err
.
println
(
"visitIdentifier: "
+
t
);
trees
.
getScope
(
getCurrentPath
());
return
null
;
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录