Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_langtools
提交
eb69fe1e
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看板
提交
eb69fe1e
编写于
3月 15, 2011
作者:
J
jjg
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
6993311: annotations on packages are not validated
Reviewed-by: mcimadamore
上级
ffbb2f04
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
121 addition
and
10 deletion
+121
-10
src/share/classes/com/sun/tools/javac/comp/Attr.java
src/share/classes/com/sun/tools/javac/comp/Attr.java
+24
-0
src/share/classes/com/sun/tools/javac/main/JavaCompiler.java
src/share/classes/com/sun/tools/javac/main/JavaCompiler.java
+1
-1
test/tools/javac/annotations/TestAnnotationPackageInfo.java
test/tools/javac/annotations/TestAnnotationPackageInfo.java
+87
-0
test/tools/javac/annotations/pos/package-info.java
test/tools/javac/annotations/pos/package-info.java
+3
-3
test/tools/javac/processing/filer/TestPackageInfo.java
test/tools/javac/processing/filer/TestPackageInfo.java
+4
-4
test/tools/javac/processing/filer/foo/bar/package-info.java
test/tools/javac/processing/filer/foo/bar/package-info.java
+2
-2
未找到文件。
src/share/classes/com/sun/tools/javac/comp/Attr.java
浏览文件 @
eb69fe1e
...
...
@@ -3004,6 +3004,30 @@ public class Attr extends JCTree.Visitor {
throw
new
AssertionError
();
}
/**
* Attribute an env for either a top level tree or class declaration.
*/
public
void
attrib
(
Env
<
AttrContext
>
env
)
{
if
(
env
.
tree
.
getTag
()
==
JCTree
.
TOPLEVEL
)
attribTopLevel
(
env
);
else
attribClass
(
env
.
tree
.
pos
(),
env
.
enclClass
.
sym
);
}
/**
* Attribute a top level tree. These trees are encountered when the
* package declaration has annotations.
*/
public
void
attribTopLevel
(
Env
<
AttrContext
>
env
)
{
JCCompilationUnit
toplevel
=
env
.
toplevel
;
try
{
annotate
.
flush
();
chk
.
validateAnnotations
(
toplevel
.
packageAnnotations
,
toplevel
.
packge
);
}
catch
(
CompletionFailure
ex
)
{
chk
.
completionError
(
toplevel
.
pos
(),
ex
);
}
}
/** Main method: attribute class definition associated with given class symbol.
* reporting completion failures at the given position.
* @param pos The source position at which completion errors are to be
...
...
src/share/classes/com/sun/tools/javac/main/JavaCompiler.java
浏览文件 @
eb69fe1e
...
...
@@ -1166,7 +1166,7 @@ public class JavaCompiler implements ClassReader.SourceCompleter {
env
.
enclClass
.
sym
.
sourcefile
:
env
.
toplevel
.
sourcefile
);
try
{
attr
.
attrib
Class
(
env
.
tree
.
pos
(),
env
.
enclClass
.
sym
);
attr
.
attrib
(
env
);
if
(
errorCount
()
>
0
&&
!
shouldStop
(
CompileState
.
ATTR
))
{
//if in fail-over mode, ensure that AST expression nodes
//are correctly initialized (e.g. they have a type/symbol)
...
...
test/tools/javac/annotations/TestAnnotationPackageInfo.java
0 → 100644
浏览文件 @
eb69fe1e
/*
* 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 6993311
* @summary annotations on packages are not validated
*/
import
java.io.*
;
import
java.net.*
;
import
java.util.*
;
import
javax.tools.*
;
import
com.sun.source.util.*
;
public
class
TestAnnotationPackageInfo
{
public
static
void
main
(
String
...
args
)
throws
Exception
{
new
TestAnnotationPackageInfo
().
run
();
}
static
class
MyFileObject
extends
SimpleJavaFileObject
{
private
String
text
;
public
MyFileObject
(
String
fileName
,
String
text
)
{
super
(
URI
.
create
(
"myfo:/"
+
fileName
),
JavaFileObject
.
Kind
.
SOURCE
);
this
.
text
=
text
;
}
@Override
public
CharSequence
getCharContent
(
boolean
ignoreEncodingErrors
)
{
return
text
;
}
}
public
void
run
()
throws
Exception
{
final
String
bootPath
=
System
.
getProperty
(
"sun.boot.class.path"
);
final
JavaCompiler
tool
=
ToolProvider
.
getSystemJavaCompiler
();
assert
tool
!=
null
;
JavaFileObject
test_java
=
new
MyFileObject
(
"test/Test.java"
,
"package test; public @interface Test {\n"
+
" public int mandatory();\n"
+
"}\n"
);
JavaFileObject
package_info_java
=
new
MyFileObject
(
"test/package-info.java"
,
"@Test package test;"
);
DiagnosticCollector
<
JavaFileObject
>
coll
=
new
DiagnosticCollector
<
JavaFileObject
>();
List
<
String
>
options
=
Arrays
.
asList
(
"-bootclasspath"
,
bootPath
);
List
<?
extends
JavaFileObject
>
files
=
Arrays
.
asList
(
test_java
,
package_info_java
);
JavacTask
ct
=
(
JavacTask
)
tool
.
getTask
(
null
,
null
,
coll
,
options
,
null
,
files
);
ct
.
analyze
();
String
expectedCode
=
"compiler.err.annotation.missing.default.value"
;
List
<
Diagnostic
<?
extends
JavaFileObject
>>
diags
=
coll
.
getDiagnostics
();
switch
(
diags
.
size
())
{
case
0
:
throw
new
Exception
(
"no diagnostics reported"
);
case
1
:
String
code
=
diags
.
get
(
0
).
getCode
();
if
(
code
.
equals
(
expectedCode
))
return
;
throw
new
Exception
(
"unexpected diag: "
+
diags
.
get
(
0
));
default
:
throw
new
Exception
(
"unexpected diags reported: "
+
diags
);
}
}
}
test/tools/javac/annotations/pos/package-info.java
浏览文件 @
eb69fe1e
/*
* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003,
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
...
...
@@ -23,12 +23,12 @@
/*
* @test
* @bug 4901290
* @bug 4901290
6993311
* @summary Package annotations
* @author gafter
*
* @compile package-info.java
*/
@
java
.
lang
.
annotation
.
Documen
ted
@
Depreca
ted
package
foo.bar
;
test/tools/javac/processing/filer/TestPackageInfo.java
浏览文件 @
eb69fe1e
/*
* Copyright (c) 2006, 201
0
, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2006, 201
1
, 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
...
...
@@ -23,7 +23,7 @@
/*
* @test
* @bug 6380018 6392177
* @bug 6380018 6392177
6993311
* @summary Test the ability to create and process package-info.java files
* @author Joseph D. Darcy
* @library ../../lib
...
...
@@ -60,7 +60,7 @@ public class TestPackageInfo extends JavacTestingAbstractProcessor {
// Verify annotations are as expected
Set
<
TypeElement
>
expectedAnnotations
=
new
HashSet
<
TypeElement
>();
expectedAnnotations
.
add
(
eltUtils
.
getTypeElement
(
"java.lang.
SuppressWarnings
"
));
expectedAnnotations
.
add
(
eltUtils
.
getTypeElement
(
"java.lang.
Deprecated
"
));
if
(!
roundEnv
.
processingOver
())
{
System
.
out
.
println
(
"\nRound "
+
round
);
...
...
@@ -90,7 +90,7 @@ public class TestPackageInfo extends JavacTestingAbstractProcessor {
}
catch
(
FilerException
fe
)
{}
PrintWriter
pw
=
new
PrintWriter
(
filer
.
createSourceFile
(
"foo.package-info"
).
openWriter
());
pw
.
println
(
"@
SuppressWarnings(\"\")
"
);
pw
.
println
(
"@
Deprecated
"
);
pw
.
println
(
"package foo;"
);
pw
.
close
();
...
...
test/tools/javac/processing/filer/foo/bar/package-info.java
浏览文件 @
eb69fe1e
/*
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2006,
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
...
...
@@ -24,5 +24,5 @@
/**
* Javadoc for the foo.bar package!
*/
@
SuppressWarnings
(
"deprecation"
)
@
Deprecated
package
foo.bar
;
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录