Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_langtools
提交
f6d9426c
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看板
提交
f6d9426c
编写于
6月 24, 2011
作者:
D
darcy
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
6575445: Update annotation processor to only use java.util.ServiceLoader
Reviewed-by: jjg
上级
d1eaa177
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
19 addition
and
65 deletion
+19
-65
src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java
...un/tools/javac/processing/JavacProcessingEnvironment.java
+18
-59
src/share/classes/com/sun/tools/javac/resources/compiler.properties
...classes/com/sun/tools/javac/resources/compiler.properties
+1
-5
test/tools/javac/diags/examples.not-yet.txt
test/tools/javac/diags/examples.not-yet.txt
+0
-1
未找到文件。
src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java
浏览文件 @
f6d9426c
...
...
@@ -295,59 +295,24 @@ public class JavacProcessingEnvironment implements ProcessingEnvironment, Closea
/**
* Use a service loader appropriate for the platform to provide an
* iterator over annotations processors. If
* java.util.ServiceLoader is present use it, otherwise, use
* sun.misc.Service, otherwise fail if a loader is needed.
* iterator over annotations processors; fails if a loader is
* needed but unavailable.
*/
private
class
ServiceIterator
implements
Iterator
<
Processor
>
{
// The to-be-wrapped iterator.
private
Iterator
<?>
iterator
;
private
Iterator
<
Processor
>
iterator
;
private
Log
log
;
private
Class
<?>
loaderClass
;
private
boolean
jusl
;
private
Object
loader
;
private
ServiceLoader
<
Processor
>
loader
;
ServiceIterator
(
ClassLoader
classLoader
,
Log
log
)
{
String
loadMethodName
;
this
.
log
=
log
;
try
{
try
{
loaderClass
=
Class
.
forName
(
"java.util.ServiceLoader"
);
loadMethodName
=
"load"
;
jusl
=
true
;
}
catch
(
ClassNotFoundException
cnfe
)
{
try
{
loaderClass
=
Class
.
forName
(
"sun.misc.Service"
);
loadMethodName
=
"providers"
;
jusl
=
false
;
}
catch
(
ClassNotFoundException
cnfe2
)
{
// Fail softly if a loader is not actually needed.
this
.
iterator
=
handleServiceLoaderUnavailability
(
"proc.no.service"
,
null
);
return
;
}
}
// java.util.ServiceLoader.load or sun.misc.Service.providers
Method
loadMethod
=
loaderClass
.
getMethod
(
loadMethodName
,
Class
.
class
,
ClassLoader
.
class
);
Object
result
=
loadMethod
.
invoke
(
null
,
Processor
.
class
,
classLoader
);
// For java.util.ServiceLoader, we have to call another
// method to get the iterator.
if
(
jusl
)
{
loader
=
result
;
// Store ServiceLoader to call reload later
Method
m
=
loaderClass
.
getMethod
(
"iterator"
);
result
=
m
.
invoke
(
result
);
// serviceLoader.iterator();
loader
=
ServiceLoader
.
load
(
Processor
.
class
,
classLoader
);
this
.
iterator
=
loader
.
iterator
();
}
catch
(
Exception
e
)
{
// Fail softly if a loader is not actually needed.
this
.
iterator
=
handleServiceLoaderUnavailability
(
"proc.no.service"
,
null
);
}
// The result should now be an iterator.
this
.
iterator
=
(
Iterator
<?>)
result
;
}
catch
(
Throwable
t
)
{
log
.
error
(
"proc.service.problem"
);
throw
new
Abort
(
t
);
...
...
@@ -357,25 +322,21 @@ public class JavacProcessingEnvironment implements ProcessingEnvironment, Closea
public
boolean
hasNext
()
{
try
{
return
iterator
.
hasNext
();
}
catch
(
ServiceConfigurationError
sce
)
{
log
.
error
(
"proc.bad.config.file"
,
sce
.
getLocalizedMessage
());
throw
new
Abort
(
sce
);
}
catch
(
Throwable
t
)
{
if
(
"ServiceConfigurationError"
.
equals
(
t
.
getClass
().
getSimpleName
()))
{
log
.
error
(
"proc.bad.config.file"
,
t
.
getLocalizedMessage
());
}
throw
new
Abort
(
t
);
}
}
public
Processor
next
()
{
try
{
return
(
Processor
)(
iterator
.
next
());
return
iterator
.
next
();
}
catch
(
ServiceConfigurationError
sce
)
{
log
.
error
(
"proc.bad.config.file"
,
sce
.
getLocalizedMessage
());
throw
new
Abort
(
sce
);
}
catch
(
Throwable
t
)
{
if
(
"ServiceConfigurationError"
.
equals
(
t
.
getClass
().
getSimpleName
()))
{
log
.
error
(
"proc.bad.config.file"
,
t
.
getLocalizedMessage
());
}
else
{
log
.
error
(
"proc.processor.constructor.error"
,
t
.
getLocalizedMessage
());
}
throw
new
Abort
(
t
);
}
}
...
...
@@ -385,11 +346,9 @@ public class JavacProcessingEnvironment implements ProcessingEnvironment, Closea
}
public
void
close
()
{
if
(
jus
l
)
{
if
(
loader
!=
nul
l
)
{
try
{
// Call java.util.ServiceLoader.reload
Method
reloadMethod
=
loaderClass
.
getMethod
(
"reload"
);
reloadMethod
.
invoke
(
loader
);
loader
.
reload
();
}
catch
(
Exception
e
)
{
;
// Ignore problems during a call to reload.
}
...
...
src/share/classes/com/sun/tools/javac/resources/compiler.properties
浏览文件 @
f6d9426c
...
...
@@ -637,8 +637,7 @@ compiler.err.proc.no.explicit.annotation.processing.requested=\
Class names, ''{0}'', are only accepted if annotation processing is explicitly requested
compiler.err.proc.no.service
=
\
A service loader class could not be found.
\n\
Either java.util.ServiceLoader or sun.misc.Service must be available.
A ServiceLoader was not usable and is required for annotation processing.
compiler.err.proc.processor.bad.option.name
=
\
Bad option name ''{0}'' provided by processor ''{1}''
...
...
@@ -647,9 +646,6 @@ compiler.err.proc.processor.bad.option.name=\
compiler.err.proc.processor.cant.instantiate
=
\
Could not instantiate an instance of processor ''{0}''
compiler.err.proc.processor.constructor.error
=
\
Exception thrown while constructing Processor object: {0}
# 0: string
compiler.err.proc.processor.not.found
=
\
Annotation processor ''{0}'' not found
...
...
test/tools/javac/diags/examples.not-yet.txt
浏览文件 @
f6d9426c
...
...
@@ -31,7 +31,6 @@ compiler.err.proc.cant.access.1 # completion failure, no
compiler.err.proc.cant.create.loader # security exception from service loader
compiler.err.proc.no.service # JavacProcessingEnvironment: no service loader available
compiler.err.proc.processor.bad.option.name # cannot happen? masked by javac.err.invalid.A.key
compiler.err.proc.processor.constructor.error
compiler.err.proc.service.problem # JavacProcessingEnvironment: catch Throwable from service loader
compiler.err.signature.doesnt.match.intf # UNUSED
compiler.err.signature.doesnt.match.supertype # UNUSED
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录