001: /***
002: * Retrotranslator: a Java bytecode transformer that translates Java classes
003: * compiled with JDK 5.0 into classes that can be run on JVM 1.4.
004: *
005: * Copyright (c) 2005 - 2008 Taras Puchko
006: * All rights reserved.
007: *
008: * Redistribution and use in source and binary forms, with or without
009: * modification, are permitted provided that the following conditions
010: * are met:
011: * 1. Redistributions of source code must retain the above copyright
012: * notice, this list of conditions and the following disclaimer.
013: * 2. Redistributions in binary form must reproduce the above copyright
014: * notice, this list of conditions and the following disclaimer in the
015: * documentation and/or other materials provided with the distribution.
016: * 3. Neither the name of the copyright holders nor the names of its
017: * contributors may be used to endorse or promote products derived from
018: * this software without specific prior written permission.
019: *
020: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
021: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
022: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
023: * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
024: * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
025: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
026: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
027: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
028: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
029: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
030: * THE POSSIBILITY OF SUCH DAMAGE.
031: */package net.sf.retrotranslator.runtime.java.lang.reflect;
032:
033: import java.lang.annotation.Annotation;
034: import java.lang.reflect.*;
035:
036: /**
037: * @author Taras Puchko
038: */
039: public class _AccessibleObject {
040:
041: public static Annotation getAnnotation(
042: AccessibleObject accessibleObject, Class annotationType) {
043: if (accessibleObject instanceof Constructor) {
044: return _Constructor.getAnnotation(
045: (Constructor) accessibleObject, annotationType);
046: }
047: if (accessibleObject instanceof Field) {
048: return _Field.getAnnotation((Field) accessibleObject,
049: annotationType);
050: }
051: if (accessibleObject instanceof Method) {
052: return _Method.getAnnotation((Method) accessibleObject,
053: annotationType);
054: }
055: return null;
056: }
057:
058: public static Annotation[] getAnnotations(
059: AccessibleObject accessibleObject) {
060: if (accessibleObject instanceof Constructor) {
061: return _Constructor
062: .getAnnotations((Constructor) accessibleObject);
063: }
064: if (accessibleObject instanceof Field) {
065: return _Field.getAnnotations((Field) accessibleObject);
066: }
067: if (accessibleObject instanceof Method) {
068: return _Method.getAnnotations((Method) accessibleObject);
069: }
070: return new Annotation[0];
071: }
072:
073: public static Annotation[] getDeclaredAnnotations(
074: AccessibleObject accessibleObject) {
075: if (accessibleObject instanceof Constructor) {
076: return _Constructor
077: .getDeclaredAnnotations((Constructor) accessibleObject);
078: }
079: if (accessibleObject instanceof Field) {
080: return _Field
081: .getDeclaredAnnotations((Field) accessibleObject);
082: }
083: if (accessibleObject instanceof Method) {
084: return _Method
085: .getDeclaredAnnotations((Method) accessibleObject);
086: }
087: return new Annotation[0];
088: }
089:
090: public static boolean isAnnotationPresent(
091: AccessibleObject accessibleObject, Class annotationType) {
092: if (accessibleObject instanceof Constructor) {
093: return _Constructor.isAnnotationPresent(
094: (Constructor) accessibleObject, annotationType);
095: }
096: if (accessibleObject instanceof Field) {
097: return _Field.isAnnotationPresent((Field) accessibleObject,
098: annotationType);
099: }
100: if (accessibleObject instanceof Method) {
101: return _Method.isAnnotationPresent(
102: (Method) accessibleObject, annotationType);
103: }
104: return false;
105: }
106:
107: }
|