151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski/* 29599ec54b164da29db4e3386a9839aca73caf8eeIgor Murashkin * Copyright (C) 2016 The Android Open Source Project 320938c5ed2bc8f5de8047a47caddb146f730868fNeil Fuller * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. 451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * 651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * This code is free software; you can redistribute it and/or modify it 751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * under the terms of the GNU General Public License version 2 only, as 851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * published by the Free Software Foundation. Oracle designates this 951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * particular file as subject to the "Classpath" exception as provided 1051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * by Oracle in the LICENSE file that accompanied this code. 1151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * 1251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * This code is distributed in the hope that it will be useful, but WITHOUT 1351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * version 2 for more details (a copy is included in the LICENSE file that 1651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * accompanied this code). 1751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * 1851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * You should have received a copy of the GNU General Public License version 1951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * 2 along with this work; if not, write to the Free Software Foundation, 2051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * 2251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * or visit www.oracle.com if you need additional information or have any 2451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * questions. 2551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski */ 2651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski 2751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebskipackage java.lang.reflect; 2851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski 2951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebskiimport java.lang.annotation.Annotation; 3020938c5ed2bc8f5de8047a47caddb146f730868fNeil Fullerimport java.util.Objects; 31be1608980825868eb1c70fab6eb86fe06bd304ceYi Kongimport libcore.reflect.AnnotatedElements; 3251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski 337accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller// Android-changed: Removed some references to bytecode spec below that do not 347accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller// apply and added a note about annotation ordering. 3551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski/** 3651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * Represents an annotated element of the program currently running in this 3751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * VM. This interface allows annotations to be read reflectively. All 3851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * annotations returned by methods in this interface are immutable and 397accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * serializable. The arrays returned by methods of this interface may be modified 407accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * by callers without affecting the arrays returned to other callers. 417accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * 427accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * <p>Android note: methods that return multiple annotations of different types such as 437accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * {@link #getAnnotations()} and {@link #getDeclaredAnnotations()} can be affected 447accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * by the explicit character-code ordering of annotations types specified by the DEX format. 457accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * Annotations of different types on a single element are not guaranteed to be returned in the order 467accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * they are declared in source. 477accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * 487accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * <p>The {@link #getAnnotationsByType(Class)} and {@link 497accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * #getDeclaredAnnotationsByType(Class)} methods support multiple 507accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * annotations of the same type on an element. If the argument to 517accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * either method is a repeatable annotation type (JLS 9.6), then the 527accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * method will "look through" a container annotation (JLS 9.7), if 537accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * present, and return any annotations inside the container. Container 547accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * annotations may be generated at compile-time to wrap multiple 557accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * annotations of the argument type. 567accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * 577accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * <p>The terms <em>directly present</em>, <em>indirectly present</em>, 587accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * <em>present</em>, and <em>associated</em> are used throughout this 597accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * interface to describe precisely which annotations are returned by 607accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * methods: 617accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * 627accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * <ul> 637accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * 647accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * <li> An annotation <i>A</i> is <em>directly present</em> on an 657accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * element <i>E</i> if <i>E</i> is annotated by <i>A</i> in the original source. 667accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * 677accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * <li>An annotation <i>A</i> is <em>indirectly present</em> on an 687accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * element <i>E</i> if <i>E</i> is annotated by a container annotation 697accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * of <i>A</i>. 707accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * 717accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * <li>An annotation <i>A</i> is present on an element <i>E</i> if either: 727accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * 737accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * <ul> 747accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * 757accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * <li><i>A</i> is directly present on <i>E</i>; or 767accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * 777accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * <li>No annotation of <i>A</i> 's type is directly present on 787accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * <i>E</i>, and <i>E</i> is a class, and <i>A</i> 's type is 797accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * inheritable, and <i>A</i> is present on the superclass of <i>E</i>. 807accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * 817accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * </ul> 827accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * 837accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * <li>An annotation <i>A</i> is <em>associated</em> with an element <i>E</i> 847accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * if either: 857accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * 867accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * <ul> 877accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * 887accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * <li><i>A</i> is directly or indirectly present on <i>E</i>; or 897accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * 907accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * <li>No annotation of <i>A</i> 's type is directly or indirectly 917accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * present on <i>E</i>, and <i>E</i> is a class, and <i>A</i>'s type 927accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * is inheritable, and <i>A</i> is associated with the superclass of 937accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * <i>E</i>. 947accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * 957accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * </ul> 967accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * 977accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * </ul> 987accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * 997accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * <p>The table below summarizes which kind of annotation presence 1007accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * different methods in this interface examine. 1017accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * 1027accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * <table border> 1037accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * <caption>Overview of kind of presence detected by different AnnotatedElement methods</caption> 1047accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * <tr><th colspan=2></th><th colspan=4>Kind of Presence</th> 1057accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * <tr><th colspan=2>Method</th><th>Directly Present</th><th>Indirectly Present</th><th>Present</th><th>Associated</th> 1067accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * <tr><td align=right>{@code T}</td><td>{@link #getAnnotation(Class) getAnnotation(Class<T>)} 1077accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * <td></td><td></td><td>X</td><td></td> 1087accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * </tr> 1097accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * <tr><td align=right>{@code Annotation[]}</td><td>{@link #getAnnotations getAnnotations()} 1107accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * <td></td><td></td><td>X</td><td></td> 1117accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * </tr> 1127accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * <tr><td align=right>{@code T[]}</td><td>{@link #getAnnotationsByType(Class) getAnnotationsByType(Class<T>)} 1137accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * <td></td><td></td><td></td><td>X</td> 1147accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * </tr> 1157accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * <tr><td align=right>{@code T}</td><td>{@link #getDeclaredAnnotation(Class) getDeclaredAnnotation(Class<T>)} 1167accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * <td>X</td><td></td><td></td><td></td> 1177accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * </tr> 1187accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * <tr><td align=right>{@code Annotation[]}</td><td>{@link #getDeclaredAnnotations getDeclaredAnnotations()} 1197accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * <td>X</td><td></td><td></td><td></td> 1207accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * </tr> 1217accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * <tr><td align=right>{@code T[]}</td><td>{@link #getDeclaredAnnotationsByType(Class) getDeclaredAnnotationsByType(Class<T>)} 1227accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * <td>X</td><td>X</td><td></td><td></td> 1237accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * </tr> 1247accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * </table> 1257accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * 1267accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * <p>For an invocation of {@code get[Declared]AnnotationsByType( Class < 1277accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * T >)}, the order of annotations which are directly or indirectly 1287accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * present on an element <i>E</i> is computed as if indirectly present 1297accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * annotations on <i>E</i> are directly present on <i>E</i> in place 1307accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * of their container annotation, in the order in which they appear in 1317accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * the value element of the container annotation. 1327accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * 1337accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * <p>There are several compatibility concerns to keep in mind if an 1347accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * annotation type <i>T</i> is originally <em>not</em> repeatable and 1357accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * later modified to be repeatable. 1367accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * 1377accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * The containing annotation type for <i>T</i> is <i>TC</i>. 1387accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * 1397accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * <ul> 1407accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * 1417accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * <li>Modifying <i>T</i> to be repeatable is source and binary 1427accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * compatible with existing uses of <i>T</i> and with existing uses 1437accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * of <i>TC</i>. 1447accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * 1457accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * That is, for source compatibility, source code with annotations of 1467accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * type <i>T</i> or of type <i>TC</i> will still compile. For binary 1477accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * compatibility, class files with annotations of type <i>T</i> or of 1487accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * type <i>TC</i> (or with other kinds of uses of type <i>T</i> or of 1497accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * type <i>TC</i>) will link against the modified version of <i>T</i> 1507accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * if they linked against the earlier version. 1517accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * 1527accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * (An annotation type <i>TC</i> may informally serve as an acting 1537accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * containing annotation type before <i>T</i> is modified to be 1547accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * formally repeatable. Alternatively, when <i>T</i> is made 1557accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * repeatable, <i>TC</i> can be introduced as a new type.) 1567accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * 1577accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * <li>If an annotation type <i>TC</i> is present on an element, and 1587accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * <i>T</i> is modified to be repeatable with <i>TC</i> as its 1597accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * containing annotation type then: 1607accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * 1617accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * <ul> 1627accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * 1637accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * <li>The change to <i>T</i> is behaviorally compatible with respect 1647accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * to the {@code get[Declared]Annotation(Class<T>)} (called with an 1657accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * argument of <i>T</i> or <i>TC</i>) and {@code 1667accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * get[Declared]Annotations()} methods because the results of the 1677accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * methods will not change due to <i>TC</i> becoming the containing 1687accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * annotation type for <i>T</i>. 1697accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * 1707accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * <li>The change to <i>T</i> changes the results of the {@code 1717accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * get[Declared]AnnotationsByType(Class<T>)} methods called with an 1727accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * argument of <i>T</i>, because those methods will now recognize an 1737accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * annotation of type <i>TC</i> as a container annotation for <i>T</i> 1747accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * and will "look through" it to expose annotations of type <i>T</i>. 1757accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * 1767accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * </ul> 1777accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * 1787accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * <li>If an annotation of type <i>T</i> is present on an 1797accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * element and <i>T</i> is made repeatable and more annotations of 1807accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * type <i>T</i> are added to the element: 1817accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * 1827accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * <ul> 1837accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * 1847accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * <li> The addition of the annotations of type <i>T</i> is both 1857accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * source compatible and binary compatible. 1867accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * 1877accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * <li>The addition of the annotations of type <i>T</i> changes the results 1887accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * of the {@code get[Declared]Annotation(Class<T>)} methods and {@code 1897accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * get[Declared]Annotations()} methods, because those methods will now 1907accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * only see a container annotation on the element and not see an 1917accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * annotation of type <i>T</i>. 1927accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * 1937accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * <li>The addition of the annotations of type <i>T</i> changes the 1947accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * results of the {@code get[Declared]AnnotationsByType(Class<T>)} 1957accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * methods, because their results will expose the additional 1967accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * annotations of type <i>T</i> whereas previously they exposed only a 1977accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * single annotation of type <i>T</i>. 1987accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * 1997accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * </ul> 2007accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * 2017accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * </ul> 20251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * 20351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * <p>If an annotation returned by a method in this interface contains 20451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * (directly or indirectly) a {@link Class}-valued member referring to 20551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * a class that is not accessible in this VM, attempting to read the class 20651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * by calling the relevant Class-returning method on the returned annotation 20751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * will result in a {@link TypeNotPresentException}. 20851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * 20951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * <p>Similarly, attempting to read an enum-valued member will result in 21051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * a {@link EnumConstantNotPresentException} if the enum constant in the 21151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * annotation is no longer present in the enum type. 21251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * 2137accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * <p>If an annotation type <i>T</i> is (meta-)annotated with an 2147accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * {@code @Repeatable} annotation whose value element indicates a type 2157accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * <i>TC</i>, but <i>TC</i> does not declare a {@code value()} method 2167accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * with a return type of <i>T</i>{@code []}, then an exception of type 2177accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * {@link java.lang.annotation.AnnotationFormatError} is thrown. 2187accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * 2197accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * <p>Finally, attempting to read a member whose definition has evolved 22051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * incompatibly will result in a {@link 22151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * java.lang.annotation.AnnotationTypeMismatchException} or an 22251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * {@link java.lang.annotation.IncompleteAnnotationException}. 22351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * 22451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * @see java.lang.EnumConstantNotPresentException 22551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * @see java.lang.TypeNotPresentException 2267accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * @see AnnotationFormatError 22751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * @see java.lang.annotation.AnnotationTypeMismatchException 22851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * @see java.lang.annotation.IncompleteAnnotationException 22951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * @since 1.5 23051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * @author Josh Bloch 23151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski */ 23251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebskipublic interface AnnotatedElement { 23351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski /** 23451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * Returns true if an annotation for the specified type 2357accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * is <em>present</em> on this element, else false. This method 23651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * is designed primarily for convenient access to marker annotations. 23751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * 2387accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * <p>The truth value returned by this method is equivalent to: 2397accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * {@code getAnnotation(annotationClass) != null} 2407accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * 2417accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * <p>The body of the default method is specified to be the code 2427accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * above. 2437accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * 24451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * @param annotationClass the Class object corresponding to the 24551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * annotation type 24651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * @return true if an annotation for the specified annotation 24751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * type is present on this element, else false 24851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * @throws NullPointerException if the given annotation class is null 24951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * @since 1.5 25051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski */ 2517accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller default boolean isAnnotationPresent(Class<? extends Annotation> annotationClass) { 2527accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller return getAnnotation(annotationClass) != null; 2537accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller } 25451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski 25551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski /** 25651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * Returns this element's annotation for the specified type if 2577accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * such an annotation is <em>present</em>, else null. 25851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * 2597accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * @param <T> the type of the annotation to query for and return if present 26051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * @param annotationClass the Class object corresponding to the 26151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * annotation type 26251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * @return this element's annotation for the specified annotation type if 26351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * present on this element, else null 26451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * @throws NullPointerException if the given annotation class is null 26551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * @since 1.5 26651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski */ 26751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski <T extends Annotation> T getAnnotation(Class<T> annotationClass); 26851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski 26951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski /** 2707accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * Returns annotations that are <em>present</em> on this element. 2717accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * 2727accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * If there are no annotations <em>present</em> on this element, the return 2737accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * value is an array of length 0. 2747accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * 2757accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * The caller of this method is free to modify the returned array; it will 2767accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * have no effect on the arrays returned to other callers. 27751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * 2787accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * @return annotations present on this element 27951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * @since 1.5 28051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski */ 28151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski Annotation[] getAnnotations(); 28251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski 28351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski /** 2847accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * Returns annotations that are <em>associated</em> with this element. 28551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * 2867accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * If there are no annotations <em>associated</em> with this element, the return 2877accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * value is an array of length 0. 2887accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * 2897accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * The difference between this method and {@link #getAnnotation(Class)} 2907accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * is that this method detects if its argument is a <em>repeatable 2917accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * annotation type</em> (JLS 9.6), and if so, attempts to find one or 2927accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * more annotations of that type by "looking through" a container 2937accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * annotation. 2947accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * 2957accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * The caller of this method is free to modify the returned array; it will 2967accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * have no effect on the arrays returned to other callers. 2977accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * 2987accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * @implSpec The default implementation first calls {@link 2997accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * #getDeclaredAnnotationsByType(Class)} passing {@code 3007accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * annotationClass} as the argument. If the returned array has 3017accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * length greater than zero, the array is returned. If the returned 3027accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * array is zero-length and this {@code AnnotatedElement} is a 3037accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * class and the argument type is an inheritable annotation type, 3047accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * and the superclass of this {@code AnnotatedElement} is non-null, 3057accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * then the returned result is the result of calling {@link 3067accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * #getAnnotationsByType(Class)} on the superclass with {@code 3077accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * annotationClass} as the argument. Otherwise, a zero-length 3087accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * array is returned. 3097accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * 3107accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * @param <T> the type of the annotation to query for and return if present 3117accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * @param annotationClass the Class object corresponding to the 3127accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * annotation type 3137accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * @return all this element's annotations for the specified annotation type if 3147accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * associated with this element, else an array of length zero 3157accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * @throws NullPointerException if the given annotation class is null 31620938c5ed2bc8f5de8047a47caddb146f730868fNeil Fuller * @since 1.8 31751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski */ 31820938c5ed2bc8f5de8047a47caddb146f730868fNeil Fuller default <T extends Annotation> T[] getAnnotationsByType(Class<T> annotationClass) { 31920938c5ed2bc8f5de8047a47caddb146f730868fNeil Fuller // This method does not handle inherited annotations and is intended for use for 32020938c5ed2bc8f5de8047a47caddb146f730868fNeil Fuller // {@code Method}, {@code Field}, {@code Package}. The {@link Class#getAnnotationsByType} 32120938c5ed2bc8f5de8047a47caddb146f730868fNeil Fuller // is implemented explicitly. Therefore this implementation does not fulfill the documented 32220938c5ed2bc8f5de8047a47caddb146f730868fNeil Fuller // default implementation for {@link AnnotatedElement#getAnnotationsByType(Class)} but in an 32320938c5ed2bc8f5de8047a47caddb146f730868fNeil Fuller // undetectable way because Class is final. 32420938c5ed2bc8f5de8047a47caddb146f730868fNeil Fuller return AnnotatedElements.getDirectOrIndirectAnnotationsByType(this, annotationClass); 32520938c5ed2bc8f5de8047a47caddb146f730868fNeil Fuller } 3269599ec54b164da29db4e3386a9839aca73caf8eeIgor Murashkin 3279599ec54b164da29db4e3386a9839aca73caf8eeIgor Murashkin /** 3287accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * Returns this element's annotation for the specified type if 3297accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * such an annotation is <em>directly present</em>, else null. 3309599ec54b164da29db4e3386a9839aca73caf8eeIgor Murashkin * 3317accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * This method ignores inherited annotations. (Returns null if no 3327accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * annotations are directly present on this element.) 3337accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * 3347accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * @implSpec The default implementation first performs a null check 3357accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * and then loops over the results of {@link 3367accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * #getDeclaredAnnotations} returning the first annotation whose 3377accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * annotation type matches the argument type. 3387accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * 3397accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * @param <T> the type of the annotation to query for and return if directly present 3407accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * @param annotationClass the Class object corresponding to the 3417accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * annotation type 3427accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * @return this element's annotation for the specified annotation type if 3437accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * directly present on this element, else null 3447accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * @throws NullPointerException if the given annotation class is null 3459599ec54b164da29db4e3386a9839aca73caf8eeIgor Murashkin * @since 1.8 3469599ec54b164da29db4e3386a9839aca73caf8eeIgor Murashkin */ 3471be11783452103de134b37202e188eb1aba04c03Neil Fuller default <T extends Annotation> T getDeclaredAnnotation(Class<T> annotationClass) { 34820938c5ed2bc8f5de8047a47caddb146f730868fNeil Fuller Objects.requireNonNull(annotationClass); 34920938c5ed2bc8f5de8047a47caddb146f730868fNeil Fuller // Loop over all directly-present annotations looking for a matching one 35020938c5ed2bc8f5de8047a47caddb146f730868fNeil Fuller for (Annotation annotation : getDeclaredAnnotations()) { 35120938c5ed2bc8f5de8047a47caddb146f730868fNeil Fuller if (annotationClass.equals(annotation.annotationType())) { 35220938c5ed2bc8f5de8047a47caddb146f730868fNeil Fuller // More robust to do a dynamic cast at runtime instead 35320938c5ed2bc8f5de8047a47caddb146f730868fNeil Fuller // of compile-time only. 35420938c5ed2bc8f5de8047a47caddb146f730868fNeil Fuller return annotationClass.cast(annotation); 35520938c5ed2bc8f5de8047a47caddb146f730868fNeil Fuller } 35620938c5ed2bc8f5de8047a47caddb146f730868fNeil Fuller } 35720938c5ed2bc8f5de8047a47caddb146f730868fNeil Fuller return null; 358be1608980825868eb1c70fab6eb86fe06bd304ceYi Kong } 3599599ec54b164da29db4e3386a9839aca73caf8eeIgor Murashkin 3609599ec54b164da29db4e3386a9839aca73caf8eeIgor Murashkin /** 3617accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * Returns this element's annotation(s) for the specified type if 3627accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * such annotations are either <em>directly present</em> or 3637accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * <em>indirectly present</em>. This method ignores inherited 3647accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * annotations. 3657accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * 3667accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * If there are no specified annotations directly or indirectly 3677accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * present on this element, the return value is an array of length 3687accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * 0. 3697accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * 3707accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * The difference between this method and {@link 3717accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * #getDeclaredAnnotation(Class)} is that this method detects if its 3727accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * argument is a <em>repeatable annotation type</em> (JLS 9.6), and if so, 3737accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * attempts to find one or more annotations of that type by "looking 3747accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * through" a container annotation if one is present. 3757accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * 3767accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * The caller of this method is free to modify the returned array; it will 3777accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * have no effect on the arrays returned to other callers. 3789599ec54b164da29db4e3386a9839aca73caf8eeIgor Murashkin * 3797accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * @implSpec The default implementation may call {@link 3807accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * #getDeclaredAnnotation(Class)} one or more times to find a 3817accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * directly present annotation and, if the annotation type is 3827accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * repeatable, to find a container annotation. If annotations of 3837accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * the annotation type {@code annotationClass} are found to be both 3847accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * directly and indirectly present, then {@link 3857accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * #getDeclaredAnnotations()} will get called to determine the 3867accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * order of the elements in the returned array. 3877accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * 3887accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * <p>Alternatively, the default implementation may call {@link 3897accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * #getDeclaredAnnotations()} a single time and the returned array 3907accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * examined for both directly and indirectly present 3917accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * annotations. The results of calling {@link 3927accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * #getDeclaredAnnotations()} are assumed to be consistent with the 3937accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * results of calling {@link #getDeclaredAnnotation(Class)}. 3947accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * 3957accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * @param <T> the type of the annotation to query for and return 3967accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * if directly or indirectly present 3977accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * @param annotationClass the Class object corresponding to the 3987accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * annotation type 3997accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * @return all this element's annotations for the specified annotation type if 4007accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * directly or indirectly present on this element, else an array of length zero 4017accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * @throws NullPointerException if the given annotation class is null 4029599ec54b164da29db4e3386a9839aca73caf8eeIgor Murashkin * @since 1.8 4039599ec54b164da29db4e3386a9839aca73caf8eeIgor Murashkin */ 404be1608980825868eb1c70fab6eb86fe06bd304ceYi Kong default <T extends Annotation> T[] getDeclaredAnnotationsByType(Class<T> annotationClass) { 40520938c5ed2bc8f5de8047a47caddb146f730868fNeil Fuller return AnnotatedElements.getDirectOrIndirectAnnotationsByType(this, annotationClass); 406be1608980825868eb1c70fab6eb86fe06bd304ceYi Kong } 4079599ec54b164da29db4e3386a9839aca73caf8eeIgor Murashkin 4089599ec54b164da29db4e3386a9839aca73caf8eeIgor Murashkin /** 4097accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * Returns annotations that are <em>directly present</em> on this element. 4107accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * This method ignores inherited annotations. 4117accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * 4127accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * If there are no annotations <em>directly present</em> on this element, 4137accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * the return value is an array of length 0. 4147accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * 4157accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * The caller of this method is free to modify the returned array; it will 4167accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * have no effect on the arrays returned to other callers. 4177accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * 4187accc5fb09911a1dcc027f48089845f617f2912eNeil Fuller * @return annotations directly present on this element 41920938c5ed2bc8f5de8047a47caddb146f730868fNeil Fuller * @since 1.5 4209599ec54b164da29db4e3386a9839aca73caf8eeIgor Murashkin */ 42120938c5ed2bc8f5de8047a47caddb146f730868fNeil Fuller Annotation[] getDeclaredAnnotations(); 42251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski} 423