Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_langtools
提交
0ee79307
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看板
提交
0ee79307
编写于
10月 11, 2013
作者:
J
jlahoda
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
6278240: Exception from AnnotationValue.getValue() should list the found type not the required type
Reviewed-by: darcy, jfranck, jjg
上级
3d98e5c6
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
152 addition
and
11 deletion
+152
-11
src/share/classes/com/sun/tools/javac/code/Type.java
src/share/classes/com/sun/tools/javac/code/Type.java
+6
-0
src/share/classes/com/sun/tools/javac/comp/Annotate.java
src/share/classes/com/sun/tools/javac/comp/Annotate.java
+11
-10
src/share/classes/com/sun/tools/javac/comp/MemberEnter.java
src/share/classes/com/sun/tools/javac/comp/MemberEnter.java
+1
-1
test/tools/javac/processing/errors/EnsureAnnotationTypeMismatchException/Processor.java
...rors/EnsureAnnotationTypeMismatchException/Processor.java
+102
-0
test/tools/javac/processing/errors/EnsureAnnotationTypeMismatchException/Source.java
.../errors/EnsureAnnotationTypeMismatchException/Source.java
+25
-0
test/tools/javac/processing/errors/EnsureAnnotationTypeMismatchException/Source.out
...g/errors/EnsureAnnotationTypeMismatchException/Source.out
+7
-0
未找到文件。
src/share/classes/com/sun/tools/javac/code/Type.java
浏览文件 @
0ee79307
...
@@ -165,6 +165,12 @@ public abstract class Type extends AnnoConstruct implements TypeMirror {
...
@@ -165,6 +165,12 @@ public abstract class Type extends AnnoConstruct implements TypeMirror {
return
lb
.
toList
();
return
lb
.
toList
();
}
}
/**For ErrorType, returns the original type, otherwise returns the type itself.
*/
public
Type
getOriginalType
()
{
return
this
;
}
public
<
R
,
S
>
R
accept
(
Type
.
Visitor
<
R
,
S
>
v
,
S
s
)
{
return
v
.
visitType
(
this
,
s
);
}
public
<
R
,
S
>
R
accept
(
Type
.
Visitor
<
R
,
S
>
v
,
S
s
)
{
return
v
.
visitType
(
this
,
s
);
}
/** Define a type given its tag and type symbol
/** Define a type given its tag and type symbol
...
...
src/share/classes/com/sun/tools/javac/comp/Annotate.java
浏览文件 @
0ee79307
...
@@ -37,6 +37,7 @@ import com.sun.tools.javac.tree.JCTree.*;
...
@@ -37,6 +37,7 @@ import com.sun.tools.javac.tree.JCTree.*;
import
static
com
.
sun
.
tools
.
javac
.
code
.
TypeTag
.
ARRAY
;
import
static
com
.
sun
.
tools
.
javac
.
code
.
TypeTag
.
ARRAY
;
import
static
com
.
sun
.
tools
.
javac
.
code
.
TypeTag
.
CLASS
;
import
static
com
.
sun
.
tools
.
javac
.
code
.
TypeTag
.
CLASS
;
import
static
com
.
sun
.
tools
.
javac
.
tree
.
JCTree
.
Tag
.*;
import
static
com
.
sun
.
tools
.
javac
.
tree
.
JCTree
.
Tag
.*;
import
javax.lang.model.type.ErrorType
;
/** Enter annotations on symbols. Annotations accumulate in a queue,
/** Enter annotations on symbols. Annotations accumulate in a queue,
* which is processed at the top level of any set of recursive calls
* which is processed at the top level of any set of recursive calls
...
@@ -310,7 +311,6 @@ public class Annotate {
...
@@ -310,7 +311,6 @@ public class Annotate {
Attribute
enterAttributeValue
(
Type
expected
,
Attribute
enterAttributeValue
(
Type
expected
,
JCExpression
tree
,
JCExpression
tree
,
Env
<
AttrContext
>
env
)
{
Env
<
AttrContext
>
env
)
{
Type
original
=
expected
;
//first, try completing the attribution value sym - if a completion
//first, try completing the attribution value sym - if a completion
//error is thrown, we should recover gracefully, and display an
//error is thrown, we should recover gracefully, and display an
//ordinary resolution diagnostic.
//ordinary resolution diagnostic.
...
@@ -351,7 +351,7 @@ public class Annotate {
...
@@ -351,7 +351,7 @@ public class Annotate {
l
.
head
,
l
.
head
,
env
);
env
);
}
}
return
new
Attribute
.
Error
(
original
);
return
new
Attribute
.
Error
(
syms
.
errType
);
}
}
if
((
expected
.
tsym
.
flags
()
&
Flags
.
ANNOTATION
)
!=
0
)
{
if
((
expected
.
tsym
.
flags
()
&
Flags
.
ANNOTATION
)
!=
0
)
{
if
(
tree
.
hasTag
(
ANNOTATION
))
{
if
(
tree
.
hasTag
(
ANNOTATION
))
{
...
@@ -365,12 +365,12 @@ public class Annotate {
...
@@ -365,12 +365,12 @@ public class Annotate {
if
(!
expected
.
isErroneous
())
if
(!
expected
.
isErroneous
())
log
.
error
(
tree
.
pos
(),
"annotation.not.valid.for.type"
,
expected
);
log
.
error
(
tree
.
pos
(),
"annotation.not.valid.for.type"
,
expected
);
enterAnnotation
((
JCAnnotation
)
tree
,
syms
.
errType
,
env
);
enterAnnotation
((
JCAnnotation
)
tree
,
syms
.
errType
,
env
);
return
new
Attribute
.
Error
(
original
);
return
new
Attribute
.
Error
(
((
JCAnnotation
)
tree
).
annotationType
.
type
);
}
}
if
(
expected
.
isPrimitive
()
||
types
.
isSameType
(
expected
,
syms
.
stringType
))
{
if
(
expected
.
isPrimitive
()
||
types
.
isSameType
(
expected
,
syms
.
stringType
))
{
Type
result
=
attr
.
attribExpr
(
tree
,
env
,
expected
);
Type
result
=
attr
.
attribExpr
(
tree
,
env
,
expected
);
if
(
result
.
isErroneous
())
if
(
result
.
isErroneous
())
return
new
Attribute
.
Error
(
expected
);
return
new
Attribute
.
Error
(
result
.
getOriginalType
()
);
if
(
result
.
constValue
()
==
null
)
{
if
(
result
.
constValue
()
==
null
)
{
log
.
error
(
tree
.
pos
(),
"attribute.value.must.be.constant"
);
log
.
error
(
tree
.
pos
(),
"attribute.value.must.be.constant"
);
return
new
Attribute
.
Error
(
expected
);
return
new
Attribute
.
Error
(
expected
);
...
@@ -381,14 +381,15 @@ public class Annotate {
...
@@ -381,14 +381,15 @@ public class Annotate {
if
(
expected
.
tsym
==
syms
.
classType
.
tsym
)
{
if
(
expected
.
tsym
==
syms
.
classType
.
tsym
)
{
Type
result
=
attr
.
attribExpr
(
tree
,
env
,
expected
);
Type
result
=
attr
.
attribExpr
(
tree
,
env
,
expected
);
if
(
result
.
isErroneous
())
{
if
(
result
.
isErroneous
())
{
// Does it look like a class literal?
// Does it look like an unresolved class literal?
if
(
TreeInfo
.
name
(
tree
)
==
names
.
_class
)
{
if
(
TreeInfo
.
name
(
tree
)
==
names
.
_class
&&
((
JCFieldAccess
)
tree
).
selected
.
type
.
isErroneous
())
{
Name
n
=
(((
JCFieldAccess
)
tree
).
selected
).
type
.
tsym
.
flatName
();
Name
n
=
(((
JCFieldAccess
)
tree
).
selected
).
type
.
tsym
.
flatName
();
return
new
Attribute
.
UnresolvedClass
(
expected
,
return
new
Attribute
.
UnresolvedClass
(
expected
,
types
.
createErrorType
(
n
,
types
.
createErrorType
(
n
,
syms
.
unknownSymbol
,
syms
.
classType
));
syms
.
unknownSymbol
,
syms
.
classType
));
}
else
{
}
else
{
return
new
Attribute
.
Error
(
expected
);
return
new
Attribute
.
Error
(
result
.
getOriginalType
()
);
}
}
}
}
...
@@ -396,21 +397,21 @@ public class Annotate {
...
@@ -396,21 +397,21 @@ public class Annotate {
// at the tree level
// at the tree level
if
(
TreeInfo
.
name
(
tree
)
!=
names
.
_class
)
{
if
(
TreeInfo
.
name
(
tree
)
!=
names
.
_class
)
{
log
.
error
(
tree
.
pos
(),
"annotation.value.must.be.class.literal"
);
log
.
error
(
tree
.
pos
(),
"annotation.value.must.be.class.literal"
);
return
new
Attribute
.
Error
(
expected
);
return
new
Attribute
.
Error
(
syms
.
errType
);
}
}
return
new
Attribute
.
Class
(
types
,
return
new
Attribute
.
Class
(
types
,
(((
JCFieldAccess
)
tree
).
selected
).
type
);
(((
JCFieldAccess
)
tree
).
selected
).
type
);
}
}
if
(
expected
.
hasTag
(
CLASS
)
&&
if
(
expected
.
hasTag
(
CLASS
)
&&
(
expected
.
tsym
.
flags
()
&
Flags
.
ENUM
)
!=
0
)
{
(
expected
.
tsym
.
flags
()
&
Flags
.
ENUM
)
!=
0
)
{
attr
.
attribExpr
(
tree
,
env
,
expected
);
Type
result
=
attr
.
attribExpr
(
tree
,
env
,
expected
);
Symbol
sym
=
TreeInfo
.
symbol
(
tree
);
Symbol
sym
=
TreeInfo
.
symbol
(
tree
);
if
(
sym
==
null
||
if
(
sym
==
null
||
TreeInfo
.
nonstaticSelect
(
tree
)
||
TreeInfo
.
nonstaticSelect
(
tree
)
||
sym
.
kind
!=
Kinds
.
VAR
||
sym
.
kind
!=
Kinds
.
VAR
||
(
sym
.
flags
()
&
Flags
.
ENUM
)
==
0
)
{
(
sym
.
flags
()
&
Flags
.
ENUM
)
==
0
)
{
log
.
error
(
tree
.
pos
(),
"enum.annotation.must.be.enum.constant"
);
log
.
error
(
tree
.
pos
(),
"enum.annotation.must.be.enum.constant"
);
return
new
Attribute
.
Error
(
expected
);
return
new
Attribute
.
Error
(
result
.
getOriginalType
()
);
}
}
VarSymbol
enumerator
=
(
VarSymbol
)
sym
;
VarSymbol
enumerator
=
(
VarSymbol
)
sym
;
return
new
Attribute
.
Enum
(
expected
,
enumerator
);
return
new
Attribute
.
Enum
(
expected
,
enumerator
);
...
...
src/share/classes/com/sun/tools/javac/comp/MemberEnter.java
浏览文件 @
0ee79307
...
@@ -1379,7 +1379,7 @@ public class MemberEnter extends JCTree.Visitor implements Completer {
...
@@ -1379,7 +1379,7 @@ public class MemberEnter extends JCTree.Visitor implements Completer {
if
(!
t
.
hasTag
(
ERROR
))
if
(!
t
.
hasTag
(
ERROR
))
return
t
;
return
t
;
return
new
ErrorType
(
((
ErrorType
)
t
)
.
getOriginalType
(),
t
.
tsym
)
{
return
new
ErrorType
(
t
.
getOriginalType
(),
t
.
tsym
)
{
private
Type
modelType
;
private
Type
modelType
;
@Override
@Override
...
...
test/tools/javac/processing/errors/EnsureAnnotationTypeMismatchException/Processor.java
0 → 100644
浏览文件 @
0ee79307
/*
* Copyright (c) 2013, 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.
*/
import
java.io.IOException
;
import
java.io.Writer
;
import
java.lang.annotation.*
;
import
java.util.Set
;
import
javax.annotation.processing.*
;
import
javax.lang.model.element.*
;
import
javax.lang.model.util.ElementFilter
;
import
javax.tools.*
;
import
com.sun.tools.javac.util.Assert
;
public
class
Processor
extends
JavacTestingAbstractProcessor
{
private
boolean
seenGenerated
;
@Override
public
boolean
process
(
Set
<?
extends
TypeElement
>
annotations
,
RoundEnvironment
roundEnv
)
{
for
(
Element
e
:
roundEnv
.
getElementsAnnotatedWith
(
Gen
.
class
))
{
Gen
gen
=
e
.
getAnnotation
(
Gen
.
class
);
try
{
JavaFileObject
source
=
processingEnv
.
getFiler
().
createSourceFile
(
gen
.
fileName
());
try
(
Writer
out
=
source
.
openWriter
())
{
out
.
write
(
gen
.
content
());
}
}
catch
(
IOException
ex
)
{
throw
new
IllegalStateException
(
ex
);
}
}
TypeElement
generated
=
processingEnv
.
getElementUtils
().
getTypeElement
(
"Generated"
);
if
(
generated
!=
null
)
{
Check
check
=
ElementFilter
.
methodsIn
(
generated
.
getEnclosedElements
()).
get
(
0
).
getAnnotation
(
Check
.
class
);
checkCorrectException
(
check:
:
classValue
,
"java.lang.Class<java.lang.String>"
);
checkCorrectException
(
check:
:
intConstValue
,
"boolean"
);
checkCorrectException
(
check:
:
enumValue
,
"java.lang.String"
);
checkCorrectException
(
check:
:
incorrectAnnotationValue
,
"java.lang.Deprecated"
);
checkCorrectException
(
check:
:
incorrectArrayValue
,
"<any>"
);
checkCorrectException
(
check:
:
incorrectClassValue
,
"<any>"
);
seenGenerated
=
true
;
}
if
(
roundEnv
.
processingOver
()
&&
!
seenGenerated
)
{
Assert
.
error
(
"Did not see the generated class!"
);
}
return
true
;
}
private
static
void
checkCorrectException
(
Runnable
runCheck
,
String
expectedType
)
{
try
{
runCheck
.
run
();
Assert
.
check
(
false
);
//Should not reach here
}
catch
(
AnnotationTypeMismatchException
ex
)
{
Assert
.
check
(
expectedType
.
equals
(
ex
.
foundType
()),
ex
.
foundType
());
}
}
}
@interface
Gen
{
String
fileName
();
String
content
();
}
@interface
Check
{
Class
<?
extends
Number
>
classValue
();
int
intConstValue
();
E
enumValue
();
int
incorrectAnnotationValue
();
int
incorrectArrayValue
();
Class
<?>
incorrectClassValue
();
}
enum
E
{
A
;
}
test/tools/javac/processing/errors/EnsureAnnotationTypeMismatchException/Source.java
0 → 100644
浏览文件 @
0ee79307
/*
* @test /nodynamiccopyright/
* @bug 6278240
* @summary Ensure AnnotationTypeMismatchException is thrown when appropriate
* with reasonable foundType filled.
* @library /tools/javac/lib
* @build JavacTestingAbstractProcessor Processor
* @compile/fail/ref=Source.out -XDrawDiagnostics -processor Processor Source.java
*/
@Gen
(
fileName
=
"Generated"
,
content
=
"class Generated {\n"
+
" @Check(classValue=String.class,\n"
+
" intConstValue=false,\n"
+
" enumValue=\"a\",\n"
+
" incorrectAnnotationValue=@Deprecated,\n"
+
" incorrectArrayValue={1, \"a\"},\n"
+
" incorrectClassValue=get())\n"
+
" public static Class<?> get() {\n"
+
" return null;\n"
+
" }\n"
+
"}\n"
)
class
Source
{
}
test/tools/javac/processing/errors/EnsureAnnotationTypeMismatchException/Source.out
0 → 100644
浏览文件 @
0ee79307
Generated.java:2:29: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: java.lang.Class<java.lang.String>, java.lang.Class<? extends java.lang.Number>)
Generated.java:3:26: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: boolean, int)
Generated.java:4:22: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: java.lang.String, E)
Generated.java:5:37: compiler.err.annotation.not.valid.for.type: int
Generated.java:6:32: compiler.err.annotation.value.not.allowable.type
Generated.java:7:35: compiler.err.annotation.value.must.be.class.literal
6 errors
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录