8043984: Confusing (incorrect) error message on repeatable annotations
Adjusted error mesage for repeating annotations Reviewed-by: jfranck, dlsmith
This commit is contained in:
parent
e17a42c26a
commit
868bdb35b2
langtools
src/jdk.compiler/share/classes/com/sun/tools/javac
test/tools/javac
annotations/repeatingAnnotations
diags/examples
@ -31,6 +31,7 @@ import com.sun.tools.javac.code.Attribute.TypeCompound;
|
|||||||
import com.sun.tools.javac.code.Scope.WriteableScope;
|
import com.sun.tools.javac.code.Scope.WriteableScope;
|
||||||
import com.sun.tools.javac.code.Symbol.*;
|
import com.sun.tools.javac.code.Symbol.*;
|
||||||
import com.sun.tools.javac.code.TypeMetadata.Entry.Kind;
|
import com.sun.tools.javac.code.TypeMetadata.Entry.Kind;
|
||||||
|
import com.sun.tools.javac.resources.CompilerProperties.Errors;
|
||||||
import com.sun.tools.javac.tree.JCTree;
|
import com.sun.tools.javac.tree.JCTree;
|
||||||
import com.sun.tools.javac.tree.JCTree.*;
|
import com.sun.tools.javac.tree.JCTree.*;
|
||||||
import com.sun.tools.javac.tree.TreeInfo;
|
import com.sun.tools.javac.tree.TreeInfo;
|
||||||
@ -778,9 +779,10 @@ public class Annotate {
|
|||||||
Attribute.Compound c = new Attribute.Compound(targetContainerType, List.of(p));
|
Attribute.Compound c = new Attribute.Compound(targetContainerType, List.of(p));
|
||||||
JCAnnotation annoTree = m.Annotation(c);
|
JCAnnotation annoTree = m.Annotation(c);
|
||||||
|
|
||||||
if (!chk.annotationApplicable(annoTree, on))
|
if (!chk.annotationApplicable(annoTree, on)) {
|
||||||
log.error(annoTree.pos(), "invalid.repeatable.annotation.incompatible.target",
|
log.error(annoTree.pos(),
|
||||||
targetContainerType, origAnnoType);
|
Errors.InvalidRepeatableAnnotationNotApplicable(targetContainerType, on));
|
||||||
|
}
|
||||||
|
|
||||||
if (!chk.validateAnnotationDeferErrors(annoTree))
|
if (!chk.validateAnnotationDeferErrors(annoTree))
|
||||||
log.error(annoTree.pos(), "duplicate.annotation.invalid.repeated", origAnnoType);
|
log.error(annoTree.pos(), "duplicate.annotation.invalid.repeated", origAnnoType);
|
||||||
|
@ -410,6 +410,10 @@ compiler.err.invalid.repeatable.annotation.incompatible.target=\
|
|||||||
compiler.err.invalid.repeatable.annotation.repeated.and.container.present=\
|
compiler.err.invalid.repeatable.annotation.repeated.and.container.present=\
|
||||||
container {0} must not be present at the same time as the element it contains
|
container {0} must not be present at the same time as the element it contains
|
||||||
|
|
||||||
|
# 0: type, 1: symbol
|
||||||
|
compiler.err.invalid.repeatable.annotation.not.applicable=\
|
||||||
|
container {0} is not applicable to element {1}
|
||||||
|
|
||||||
# 0: name
|
# 0: name
|
||||||
compiler.err.duplicate.class=\
|
compiler.err.duplicate.class=\
|
||||||
duplicate class: {0}
|
duplicate class: {0}
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
RepeatingTargetNotAllowed.java:43:5: compiler.err.invalid.repeatable.annotation.incompatible.target: Foos, Foo
|
RepeatingTargetNotAllowed.java:43:5: compiler.err.invalid.repeatable.annotation.not.applicable: Foos, f
|
||||||
1 error
|
1 error
|
||||||
|
@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015, 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// key: compiler.err.invalid.repeatable.annotation.not.applicable
|
||||||
|
|
||||||
|
import java.lang.annotation.*;
|
||||||
|
|
||||||
|
@Repeatable(Foos.class)
|
||||||
|
@interface Foo {}
|
||||||
|
|
||||||
|
@Target(ElementType.ANNOTATION_TYPE)
|
||||||
|
@interface Foos {
|
||||||
|
Foo[] value();
|
||||||
|
}
|
||||||
|
|
||||||
|
public class NonApplicableRepeatingAnno {
|
||||||
|
@Foo @Foo int f = 0;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user