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.asm.Opcodes;
036: import net.sf.retrotranslator.runtime.impl.*;
037:
038: /**
039: * @author Taras Puchko
040: */
041: public class _Constructor {
042:
043: public static Annotation getAnnotation(Constructor constructor,
044: Class annotationType) {
045: return MethodDescriptor.getInstance(constructor).getAnnotation(
046: annotationType);
047: }
048:
049: public static Annotation[] getAnnotations(Constructor constructor) {
050: return MethodDescriptor.getInstance(constructor)
051: .getAnnotations();
052: }
053:
054: public static Annotation[] getDeclaredAnnotations(
055: Constructor constructor) {
056: return MethodDescriptor.getInstance(constructor)
057: .getDeclaredAnnotations();
058: }
059:
060: public static Type[] getGenericExceptionTypes(
061: Constructor constructor) {
062: return RuntimeTools.getTypes(constructor.getExceptionTypes(),
063: MethodDescriptor.getInstance(constructor)
064: .getGenericExceptionTypes());
065: }
066:
067: public static Type[] getGenericParameterTypes(
068: Constructor constructor) {
069: return RuntimeTools.getTypes(constructor.getParameterTypes(),
070: MethodDescriptor.getInstance(constructor)
071: .getGenericParameterTypes());
072: }
073:
074: public static Annotation[][] getParameterAnnotations(
075: Constructor constructor) {
076: return MethodDescriptor.getInstance(constructor)
077: .getParameterAnnotations();
078: }
079:
080: public static TypeVariable[] getTypeParameters(
081: Constructor constructor) {
082: return MethodDescriptor.getInstance(constructor)
083: .getTypeParameters();
084: }
085:
086: public static boolean isAnnotationPresent(Constructor constructor,
087: Class annotationType) {
088: return MethodDescriptor.getInstance(constructor)
089: .isAnnotationPresent(annotationType);
090: }
091:
092: public static boolean isSynthetic(Constructor constructor) {
093: return MethodDescriptor.getInstance(constructor).isAccess(
094: Opcodes.ACC_SYNTHETIC);
095: }
096:
097: public static boolean isVarArgs(Constructor constructor) {
098: return MethodDescriptor.getInstance(constructor).isAccess(
099: Opcodes.ACC_VARARGS);
100: }
101:
102: public static String toGenericString(Constructor constructor) {
103: StringBuilder builder = new StringBuilder();
104: if (constructor.getModifiers() != 0) {
105: builder.append(
106: Modifier.toString(constructor.getModifiers()))
107: .append(' ');
108: }
109: TypeVariable[] typeParameters = getTypeParameters(constructor);
110: if (typeParameters.length > 0) {
111: RuntimeTools.append(builder.append('<'), typeParameters)
112: .append("> ");
113: }
114: builder.append(RuntimeTools.getString(constructor
115: .getDeclaringClass()));
116: RuntimeTools.append(builder.append('('),
117: getGenericParameterTypes(constructor)).append(')');
118: Type[] exceptionTypes = getGenericExceptionTypes(constructor);
119: if (exceptionTypes.length > 0) {
120: RuntimeTools.append(builder.append(" throws "),
121: exceptionTypes);
122: }
123: return builder.toString();
124: }
125:
126: }
|