Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_langtools
提交
64840665
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看板
提交
64840665
编写于
8月 31, 2011
作者:
J
jjg
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
7074416: Regression: JSR199: javac doesn't unwrap clientcodewrapper objects
Reviewed-by: mcimadamore
上级
0e0b65f4
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
94 addition
and
13 deletion
+94
-13
src/share/classes/com/sun/tools/javac/api/ClientCodeWrapper.java
...re/classes/com/sun/tools/javac/api/ClientCodeWrapper.java
+59
-3
src/share/classes/javax/tools/JavaCompiler.java
src/share/classes/javax/tools/JavaCompiler.java
+0
-2
test/tools/javac/TryWithResources/UnusedResourcesTest.java
test/tools/javac/TryWithResources/UnusedResourcesTest.java
+10
-1
test/tools/javac/diags/Example.java
test/tools/javac/diags/Example.java
+14
-5
test/tools/javac/processing/errors/TestSuppression.java
test/tools/javac/processing/errors/TestSuppression.java
+11
-2
未找到文件。
src/share/classes/com/sun/tools/javac/api/ClientCodeWrapper.java
浏览文件 @
64840665
...
...
@@ -37,6 +37,7 @@ import java.util.Collections;
import
java.util.HashMap
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.Locale
;
import
java.util.Map
;
import
java.util.Set
;
...
...
@@ -51,6 +52,7 @@ import com.sun.source.util.TaskEvent;
import
com.sun.source.util.TaskListener
;
import
com.sun.tools.javac.util.ClientCodeException
;
import
com.sun.tools.javac.util.Context
;
import
com.sun.tools.javac.util.JCDiagnostic
;
import
java.lang.annotation.ElementType
;
import
java.lang.annotation.Retention
;
import
java.lang.annotation.RetentionPolicy
;
...
...
@@ -146,7 +148,7 @@ public class ClientCodeWrapper {
return
fo
;
}
<
T
>
DiagnosticListener
<
T
>
wrap
(
DiagnosticListener
<
T
>
dl
)
{
<
T
/*super JavaFileOject*/
>
DiagnosticListener
<
T
>
wrap
(
DiagnosticListener
<
T
>
dl
)
{
if
(
isTrusted
(
dl
))
return
dl
;
return
new
WrappedDiagnosticListener
<
T
>(
dl
);
...
...
@@ -158,6 +160,16 @@ public class ClientCodeWrapper {
return
new
WrappedTaskListener
(
tl
);
}
@SuppressWarnings
(
"unchecked"
)
private
<
T
>
Diagnostic
<
T
>
unwrap
(
final
Diagnostic
<
T
>
diagnostic
)
{
if
(
diagnostic
instanceof
JCDiagnostic
)
{
JCDiagnostic
d
=
(
JCDiagnostic
)
diagnostic
;
return
(
Diagnostic
<
T
>)
new
DiagnosticSourceUnwrapper
(
d
);
}
else
{
return
diagnostic
;
}
}
protected
boolean
isTrusted
(
Object
o
)
{
Class
<?>
c
=
o
.
getClass
();
Boolean
trusted
=
trustedClasses
.
get
(
c
);
...
...
@@ -534,7 +546,7 @@ public class ClientCodeWrapper {
}
}
protected
class
WrappedDiagnosticListener
<
T
>
implements
DiagnosticListener
<
T
>
{
protected
class
WrappedDiagnosticListener
<
T
/*super JavaFileObject*/
>
implements
DiagnosticListener
<
T
>
{
protected
DiagnosticListener
<
T
>
clientDiagnosticListener
;
WrappedDiagnosticListener
(
DiagnosticListener
<
T
>
clientDiagnosticListener
)
{
clientDiagnosticListener
.
getClass
();
// null check
...
...
@@ -544,7 +556,7 @@ public class ClientCodeWrapper {
@Override
public
void
report
(
Diagnostic
<?
extends
T
>
diagnostic
)
{
try
{
clientDiagnosticListener
.
report
(
diagnostic
);
clientDiagnosticListener
.
report
(
unwrap
(
diagnostic
)
);
}
catch
(
ClientCodeException
e
)
{
throw
e
;
}
catch
(
RuntimeException
e
)
{
...
...
@@ -555,6 +567,50 @@ public class ClientCodeWrapper {
}
}
public
class
DiagnosticSourceUnwrapper
implements
Diagnostic
<
JavaFileObject
>
{
public
final
JCDiagnostic
d
;
DiagnosticSourceUnwrapper
(
JCDiagnostic
d
)
{
this
.
d
=
d
;
}
public
Diagnostic
.
Kind
getKind
()
{
return
d
.
getKind
();
}
public
JavaFileObject
getSource
()
{
return
unwrap
(
d
.
getSource
());
}
public
long
getPosition
()
{
return
d
.
getPosition
();
}
public
long
getStartPosition
()
{
return
d
.
getStartPosition
();
}
public
long
getEndPosition
()
{
return
d
.
getEndPosition
();
}
public
long
getLineNumber
()
{
return
d
.
getLineNumber
();
}
public
long
getColumnNumber
()
{
return
d
.
getColumnNumber
();
}
public
String
getCode
()
{
return
d
.
getCode
();
}
public
String
getMessage
(
Locale
locale
)
{
return
d
.
getMessage
(
locale
);
}
}
protected
class
WrappedTaskListener
implements
TaskListener
{
protected
TaskListener
clientTaskListener
;
WrappedTaskListener
(
TaskListener
clientTaskListener
)
{
...
...
src/share/classes/javax/tools/JavaCompiler.java
浏览文件 @
64840665
...
...
@@ -26,10 +26,8 @@
package
javax.tools
;
import
java.io.File
;
import
java.io.InputStream
;
import
java.io.Writer
;
import
java.nio.charset.Charset
;
import
java.util.List
;
import
java.util.Locale
;
import
java.util.concurrent.Callable
;
import
javax.annotation.processing.Processor
;
...
...
test/tools/javac/TryWithResources/UnusedResourcesTest.java
浏览文件 @
64840665
...
...
@@ -28,6 +28,7 @@
*/
import
com.sun.source.util.JavacTask
;
import
com.sun.tools.javac.api.ClientCodeWrapper
;
import
com.sun.tools.javac.api.JavacTool
;
import
com.sun.tools.javac.util.JCDiagnostic
;
import
java.net.URI
;
...
...
@@ -236,7 +237,7 @@ public class UnusedResourcesTest {
public
void
report
(
Diagnostic
<?
extends
JavaFileObject
>
diagnostic
)
{
if
(
diagnostic
.
getKind
()
==
Diagnostic
.
Kind
.
WARNING
&&
diagnostic
.
getCode
().
contains
(
"try.resource.not.referenced"
))
{
String
varName
=
((
JCDiagnostic
)
diagnostic
).
getArgs
()[
0
].
toString
();
String
varName
=
unwrap
(
diagnostic
).
getArgs
()[
0
].
toString
();
if
(
varName
.
equals
(
TwrStmt
.
TWR1
.
resourceName
))
{
unused_r1
=
true
;
}
else
if
(
varName
.
equals
(
TwrStmt
.
TWR2
.
resourceName
))
{
...
...
@@ -246,5 +247,13 @@ public class UnusedResourcesTest {
}
}
}
private
JCDiagnostic
unwrap
(
Diagnostic
<?
extends
JavaFileObject
>
diagnostic
)
{
if
(
diagnostic
instanceof
JCDiagnostic
)
return
(
JCDiagnostic
)
diagnostic
;
if
(
diagnostic
instanceof
ClientCodeWrapper
.
DiagnosticSourceUnwrapper
)
return
((
ClientCodeWrapper
.
DiagnosticSourceUnwrapper
)
diagnostic
).
d
;
throw
new
IllegalArgumentException
();
}
}
}
test/tools/javac/diags/Example.java
浏览文件 @
64840665
...
...
@@ -21,10 +21,12 @@
* questions.
*/
import
com.sun.tools.javac.file.JavacFileManager
;
import
java.io.*
;
import
java.net.URL
;
import
java.net.URLClassLoader
;
import
java.util.*
;
import
java.util.regex.*
;
import
javax.annotation.processing.Processor
;
import
javax.tools.Diagnostic
;
import
javax.tools.DiagnosticCollector
;
import
javax.tools.JavaCompiler
;
...
...
@@ -37,12 +39,11 @@ import javax.tools.ToolProvider;
// import com.sun.tools.javac.Main
// import com.sun.tools.javac.main.Main
import
com.sun.tools.javac.api.ClientCodeWrapper
;
import
com.sun.tools.javac.file.JavacFileManager
;
import
com.sun.tools.javac.util.Context
;
import
com.sun.tools.javac.util.JavacMessages
;
import
com.sun.tools.javac.util.JCDiagnostic
;
import
java.net.URL
;
import
java.net.URLClassLoader
;
import
javax.annotation.processing.Processor
;
/**
* Class to handle example code designed to illustrate javac diagnostic messages.
...
...
@@ -397,7 +398,7 @@ class Example implements Comparable<Example> {
if
(
keys
!=
null
)
{
for
(
Diagnostic
<?
extends
JavaFileObject
>
d:
dc
.
getDiagnostics
())
{
scanForKeys
(
(
JCDiagnostic
)
d
,
keys
);
scanForKeys
(
unwrap
(
d
)
,
keys
);
}
}
...
...
@@ -418,6 +419,14 @@ class Example implements Comparable<Example> {
for
(
JCDiagnostic
sd:
d
.
getSubdiagnostics
())
scanForKeys
(
sd
,
keys
);
}
private
JCDiagnostic
unwrap
(
Diagnostic
<?
extends
JavaFileObject
>
diagnostic
)
{
if
(
diagnostic
instanceof
JCDiagnostic
)
return
(
JCDiagnostic
)
diagnostic
;
if
(
diagnostic
instanceof
ClientCodeWrapper
.
DiagnosticSourceUnwrapper
)
return
((
ClientCodeWrapper
.
DiagnosticSourceUnwrapper
)
diagnostic
).
d
;
throw
new
IllegalArgumentException
();
}
}
/**
...
...
test/tools/javac/processing/errors/TestSuppression.java
浏览文件 @
64840665
/*
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010,
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
...
...
@@ -35,6 +35,7 @@ import javax.lang.model.element.TypeElement;
import
javax.tools.*
;
import
com.sun.source.util.JavacTask
;
import
com.sun.tools.javac.api.ClientCodeWrapper
;
import
com.sun.tools.javac.api.JavacTool
;
import
com.sun.tools.javac.util.JCDiagnostic
;
...
...
@@ -171,7 +172,7 @@ public class TestSuppression {
public
void
report
(
Diagnostic
<?
extends
JavaFileObject
>
diagnostic
)
{
System
.
err
.
println
((++
total
)
+
": "
+
"resolveError:"
+
isResolveError
(
(
JCDiagnostic
)
diagnostic
)
+
"\n"
+
"resolveError:"
+
isResolveError
(
unwrap
(
diagnostic
)
)
+
"\n"
+
diagnostic
);
Diagnostic
.
Kind
dk
=
diagnostic
.
getKind
();
Integer
c
=
counts
.
get
(
dk
);
...
...
@@ -181,6 +182,14 @@ public class TestSuppression {
private
static
boolean
isResolveError
(
JCDiagnostic
d
)
{
return
d
.
isFlagSet
(
RESOLVE_ERROR
);
}
private
JCDiagnostic
unwrap
(
Diagnostic
<?
extends
JavaFileObject
>
diagnostic
)
{
if
(
diagnostic
instanceof
JCDiagnostic
)
return
(
JCDiagnostic
)
diagnostic
;
if
(
diagnostic
instanceof
ClientCodeWrapper
.
DiagnosticSourceUnwrapper
)
return
((
ClientCodeWrapper
.
DiagnosticSourceUnwrapper
)
diagnostic
).
d
;
throw
new
IllegalArgumentException
();
}
}
@SupportedAnnotationTypes
(
"*"
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录