KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > aspectj > internal > lang > reflect > InterTypeConstructorDeclarationImpl


1 /* *******************************************************************
2  * Copyright (c) 2005 Contributors.
3  * All rights reserved.
4  * This program and the accompanying materials are made available
5  * under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution and is available at
7  * http://eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  * Adrian Colyer Initial implementation
11  * ******************************************************************/

12 package org.aspectj.internal.lang.reflect;
13
14 import java.lang.reflect.Method JavaDoc;
15 import java.lang.reflect.Type JavaDoc;
16
17 import org.aspectj.lang.reflect.AjType;
18 import org.aspectj.lang.reflect.AjTypeSystem;
19 import org.aspectj.lang.reflect.InterTypeConstructorDeclaration;
20
21 /**
22  * @author colyer
23  *
24  */

25 public class InterTypeConstructorDeclarationImpl extends
26         InterTypeDeclarationImpl implements InterTypeConstructorDeclaration {
27
28     private Method JavaDoc baseMethod;
29     
30     /**
31      * @param decType
32      * @param target
33      * @param mods
34      */

35     public InterTypeConstructorDeclarationImpl(AjType<?> decType,
36             String JavaDoc target, int mods, Method JavaDoc baseMethod) {
37         super(decType, target, mods);
38         this.baseMethod = baseMethod;
39     }
40
41     /* (non-Javadoc)
42      * @see org.aspectj.lang.reflect.InterTypeConstructorDeclaration#getParameters()
43      */

44     public AjType<?>[] getParameterTypes() {
45         Class JavaDoc<?>[] baseTypes = baseMethod.getParameterTypes();
46         AjType<?>[] ret = new AjType<?>[baseTypes.length-1];
47         for (int i = 1; i < baseTypes.length; i++) {
48             ret[i-1] = AjTypeSystem.getAjType(baseTypes[i]);
49         }
50         return ret;
51     }
52
53     /* (non-Javadoc)
54      * @see org.aspectj.lang.reflect.InterTypeConstructorDeclaration#getGenericParameters()
55      */

56     public Type JavaDoc[] getGenericParameterTypes() {
57         Type JavaDoc[] baseTypes = baseMethod.getGenericParameterTypes();
58         Type JavaDoc[] ret = new AjType<?>[baseTypes.length-1];
59         for (int i = 1; i < baseTypes.length; i++) {
60             if (baseTypes[i] instanceof Class JavaDoc) {
61                 ret[i-1] = AjTypeSystem.getAjType((Class JavaDoc<?>)baseTypes[i]);
62             } else {
63                 ret[i-1] = baseTypes[i];
64             }
65         }
66         return ret;
67     }
68
69     /* (non-Javadoc)
70      * @see org.aspectj.lang.reflect.InterTypeConstructorDeclaration#getDeclaredExceptionTypes()
71      */

72     public AjType<?>[] getExceptionTypes() {
73         Class JavaDoc<?>[] baseTypes = baseMethod.getExceptionTypes();
74         AjType<?>[] ret = new AjType<?>[baseTypes.length];
75         for (int i = 0; i < baseTypes.length; i++) {
76             ret[i] = AjTypeSystem.getAjType(baseTypes[i]);
77         }
78         return ret;
79     }
80     
81     public String JavaDoc toString() {
82         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
83         sb.append(java.lang.reflect.Modifier.toString(getModifiers()));
84         sb.append(" ");
85         sb.append(this.targetTypeName);
86         sb.append(".new");
87         sb.append("(");
88         AjType<?>[] pTypes = getParameterTypes();
89         for(int i = 0; i < (pTypes.length - 1); i++) {
90             sb.append(pTypes[i].toString());
91             sb.append(", ");
92         }
93         if (pTypes.length > 0) {
94             sb.append(pTypes[pTypes.length -1].toString());
95         }
96         sb.append(")");
97         return sb.toString();
98     }
99
100 }
101
Popular Tags