jdk/src/share/classes/java/lang/annotation/InvalidContainerAnnotationError.java
author darcy
Thu, 31 Jan 2013 12:13:21 -0800
changeset 15514 81f4aa2dd9e3
parent 14676 985410ec95e3
permissions -rw-r--r--
8005832: Remove java.lang.annotation.{ContainedBy, ContainerFor} annotation types Reviewed-by: mduigou
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14676
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
     1
/*
15514
81f4aa2dd9e3 8005832: Remove java.lang.annotation.{ContainedBy, ContainerFor} annotation types
darcy
parents: 14676
diff changeset
     2
 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
14676
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
     4
 *
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
    10
 *
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
    15
 * accompanied this code).
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
    16
 *
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
    20
 *
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
    23
 * questions.
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
    24
 */
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
    25
package java.lang.annotation;
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
    26
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
    27
import java.util.Objects;
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
    28
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
    29
/**
15514
81f4aa2dd9e3 8005832: Remove java.lang.annotation.{ContainedBy, ContainerFor} annotation types
darcy
parents: 14676
diff changeset
    30
 * Thrown to indicate that an annotation type expected to act as a
81f4aa2dd9e3 8005832: Remove java.lang.annotation.{ContainedBy, ContainerFor} annotation types
darcy
parents: 14676
diff changeset
    31
 * container for another annotation type by virture of an @Repeatable
81f4aa2dd9e3 8005832: Remove java.lang.annotation.{ContainedBy, ContainerFor} annotation types
darcy
parents: 14676
diff changeset
    32
 * annotation, does not act as a container.
14676
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
    33
 *
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
    34
 * @see   java.lang.reflect.AnnotatedElement
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
    35
 * @since 1.8
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
    36
 * @jls   9.6 Annotation Types
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
    37
 * @jls   9.7 Annotations
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
    38
 */
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
    39
public class InvalidContainerAnnotationError extends AnnotationFormatError {
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
    40
    private static final long serialVersionUID = 5023L;
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
    41
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
    42
    /**
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
    43
     * The instance of the erroneous container.
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
    44
     */
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
    45
    private transient Annotation container;
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
    46
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
    47
    /**
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
    48
     * The type of the annotation that should be contained in the
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
    49
     * container.
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
    50
     */
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
    51
    private transient Class<? extends Annotation> annotationType;
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
    52
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
    53
    /**
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
    54
     * Constructs a new InvalidContainerAnnotationError with the
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
    55
     * specified detail message.
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
    56
     *
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
    57
     * @param  message the detail message.
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
    58
     */
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
    59
    public InvalidContainerAnnotationError(String message) {
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
    60
        super(message);
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
    61
    }
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
    62
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
    63
    /**
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
    64
     * Constructs a new InvalidContainerAnnotationError with the specified
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
    65
     * detail message and cause.  Note that the detail message associated
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
    66
     * with {@code cause} is <i>not</i> automatically incorporated in
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
    67
     * this error's detail message.
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
    68
     *
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
    69
     * @param message the detail message
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
    70
     * @param cause the cause, may be {@code null}
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
    71
     */
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
    72
    public InvalidContainerAnnotationError(String message, Throwable cause) {
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
    73
        super(message, cause);
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
    74
    }
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
    75
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
    76
    /**
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
    77
     * Constructs a new InvalidContainerAnnotationError with the
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
    78
     * specified cause and a detail message of {@code (cause == null ?
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
    79
     * null : cause.toString())} (which typically contains the class
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
    80
     * and detail message of {@code cause}).
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
    81
     *
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
    82
     * @param cause the cause, may be {@code null}
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
    83
     */
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
    84
    public InvalidContainerAnnotationError(Throwable cause) {
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
    85
        super(cause);
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
    86
    }
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
    87
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
    88
    /**
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
    89
     * Constructs InvalidContainerAnnotationError for the specified
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
    90
     * container instance and contained annotation type.
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
    91
     *
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
    92
     * @param  message the detail message
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
    93
     * @param  cause the cause, may be {@code null}
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
    94
     * @param container the erroneous container instance, may be
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
    95
     *        {@code null}
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
    96
     * @param annotationType the annotation type intended to be
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
    97
     *        contained, may be {@code null}
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
    98
     */
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
    99
    public InvalidContainerAnnotationError(String message,
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
   100
                                           Throwable cause,
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
   101
                                           Annotation container,
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
   102
                                           Class<? extends Annotation> annotationType) {
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
   103
        super(message, cause);
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
   104
        this.container = container;
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
   105
        this.annotationType = annotationType;
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
   106
    }
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
   107
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
   108
    /**
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
   109
     * Returns the erroneous container.
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
   110
     *
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
   111
     * @return the erroneous container, may return {@code null}
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
   112
     */
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
   113
    public Annotation getContainer() {
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
   114
        return container;
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
   115
    }
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
   116
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
   117
    /**
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
   118
     * Returns the annotation type intended to be contained. Returns
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
   119
     * {@code null} if the annotation type intended to be contained
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
   120
     * could not be determined.
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
   121
     *
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
   122
     * @return the annotation type intended to be contained, or {@code
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
   123
     * null} if unknown
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
   124
     */
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
   125
    public Class<? extends Annotation> getAnnotationType() {
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
   126
        return annotationType;
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
   127
    }
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
diff changeset
   128
}