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: import net.sf.retrotranslator.runtime.java.lang.*;
036:
037: /**
038: * @author Taras Puchko
039: */
040: public class _AnnotatedElement {
041:
042: public static boolean executeInstanceOfInstruction(Object object) {
043: return object instanceof Class || object instanceof Constructor
044: || object instanceof Field || object instanceof Method
045: || object instanceof Package
046: || object instanceof AnnotatedElement_;
047: }
048:
049: public static Object executeCheckCastInstruction(Object object) {
050: if (object instanceof Class) {
051: return (Class) object;
052: }
053: if (object instanceof Constructor) {
054: return (Constructor) object;
055: }
056: if (object instanceof Field) {
057: return (Field) object;
058: }
059: if (object instanceof Method) {
060: return (Method) object;
061: }
062: if (object instanceof Package) {
063: return (Package) object;
064: }
065: return (AnnotatedElement_) object;
066: }
067:
068: public static Annotation getAnnotation(AnnotatedElement object,
069: Class<? extends Annotation> annotationType) {
070: if (object instanceof Class) {
071: return _Class.getAnnotation((Class) object, annotationType);
072: }
073: if (object instanceof Constructor) {
074: return _Constructor.getAnnotation((Constructor) object,
075: annotationType);
076: }
077: if (object instanceof Field) {
078: return _Field.getAnnotation((Field) object, annotationType);
079: }
080: if (object instanceof Method) {
081: return _Method.getAnnotation((Method) object,
082: annotationType);
083: }
084: if (object instanceof Package) {
085: return _Package.getAnnotation((Package) object,
086: annotationType);
087: }
088: return ((AnnotatedElement_) object)
089: .getAnnotation(annotationType);
090: }
091:
092: public static Annotation[] getAnnotations(AnnotatedElement object) {
093: if (object instanceof Class) {
094: return _Class.getAnnotations((Class) object);
095: }
096: if (object instanceof Constructor) {
097: return _Constructor.getAnnotations((Constructor) object);
098: }
099: if (object instanceof Field) {
100: return _Field.getAnnotations((Field) object);
101: }
102: if (object instanceof Method) {
103: return _Method.getAnnotations((Method) object);
104: }
105: if (object instanceof Package) {
106: return _Package.getAnnotations((Package) object);
107: }
108: return ((AnnotatedElement_) object).getAnnotations();
109: }
110:
111: public static Annotation[] getDeclaredAnnotations(
112: AnnotatedElement object) {
113: if (object instanceof Class) {
114: return _Class.getDeclaredAnnotations((Class) object);
115: }
116: if (object instanceof Constructor) {
117: return _Constructor
118: .getDeclaredAnnotations((Constructor) object);
119: }
120: if (object instanceof Field) {
121: return _Field.getDeclaredAnnotations((Field) object);
122: }
123: if (object instanceof Method) {
124: return _Method.getDeclaredAnnotations((Method) object);
125: }
126: if (object instanceof Package) {
127: return _Package.getDeclaredAnnotations((Package) object);
128: }
129: return ((AnnotatedElement_) object).getDeclaredAnnotations();
130: }
131:
132: public static boolean isAnnotationPresent(AnnotatedElement object,
133: Class<? extends Annotation> annotationType) {
134: if (object instanceof Class) {
135: return _Class.isAnnotationPresent((Class) object,
136: annotationType);
137: }
138: if (object instanceof Constructor) {
139: return _Constructor.isAnnotationPresent(
140: (Constructor) object, annotationType);
141: }
142: if (object instanceof Field) {
143: return _Field.isAnnotationPresent((Field) object,
144: annotationType);
145: }
146: if (object instanceof Method) {
147: return _Method.isAnnotationPresent((Method) object,
148: annotationType);
149: }
150: if (object instanceof Package) {
151: return _Package.isAnnotationPresent((Package) object,
152: annotationType);
153: }
154: return ((AnnotatedElement_) object)
155: .isAnnotationPresent(annotationType);
156: }
157:
158: }
|