KickJava   Java API By Example, From Geeks To Geeks.

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


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 import java.lang.reflect.TypeVariable JavaDoc;
17
18 import org.aspectj.lang.reflect.AjType;
19 import org.aspectj.lang.reflect.AjTypeSystem;
20 import org.aspectj.lang.reflect.InterTypeMethodDeclaration;
21
22 /**
23  * @author colyer
24  *
25  */

26 public class InterTypeMethodDeclarationImpl extends InterTypeDeclarationImpl
27         implements InterTypeMethodDeclaration {
28
29     private String JavaDoc name;
30     private Method JavaDoc baseMethod;
31     private int parameterAdjustmentFactor = 1; // no of fake params at start of baseMethod
32
private AjType<?>[] parameterTypes;
33     private Type JavaDoc[] genericParameterTypes;
34     private AjType<?> returnType;
35     private Type JavaDoc genericReturnType;
36     private AjType<?>[] exceptionTypes;
37     
38     /**
39      * @param decType
40      * @param target
41      * @param mods
42      */

43     public InterTypeMethodDeclarationImpl(AjType<?> decType, String JavaDoc target,
44             int mods, String JavaDoc name, Method JavaDoc itdInterMethod) {
45         super(decType, target, mods);
46         this.name = name;
47         this.baseMethod = itdInterMethod;
48     }
49
50     public InterTypeMethodDeclarationImpl(AjType<?> decType, AjType<?> targetType, Method JavaDoc base, int modifiers) {
51         super(decType,targetType,modifiers);
52         this.parameterAdjustmentFactor = 0;
53         this.name = base.getName();
54         this.baseMethod = base;
55     }
56     
57     /* (non-Javadoc)
58      * @see org.aspectj.lang.reflect.InterTypeMethodDeclaration#getName()
59      */

60     public String JavaDoc getName() {
61         return this.name;
62     }
63
64     /* (non-Javadoc)
65      * @see org.aspectj.lang.reflect.InterTypeMethodDeclaration#getReturnType()
66      */

67     public AjType<?> getReturnType() {
68         return AjTypeSystem.getAjType(baseMethod.getReturnType());
69     }
70
71     /* (non-Javadoc)
72      * @see org.aspectj.lang.reflect.InterTypeMethodDeclaration#getGenericReturnType()
73      */

74     public Type JavaDoc getGenericReturnType() {
75         Type JavaDoc gRet = baseMethod.getGenericReturnType();
76         if (gRet instanceof Class JavaDoc) {
77             return AjTypeSystem.getAjType((Class JavaDoc<?>)gRet);
78         }
79         return gRet;
80     }
81
82     /* (non-Javadoc)
83      * @see org.aspectj.lang.reflect.InterTypeMethodDeclaration#getParameters()
84      */

85     public AjType<?>[] getParameterTypes() {
86         Class JavaDoc<?>[] baseTypes = baseMethod.getParameterTypes();
87         AjType<?>[] ret = new AjType<?>[baseTypes.length -parameterAdjustmentFactor];
88         for (int i = parameterAdjustmentFactor; i < baseTypes.length; i++) {
89             ret[i-parameterAdjustmentFactor] = AjTypeSystem.getAjType(baseTypes[i]);
90         }
91         return ret;
92     }
93
94     /* (non-Javadoc)
95      * @see org.aspectj.lang.reflect.InterTypeMethodDeclaration#getGenericParameters()
96      */

97     public Type JavaDoc[] getGenericParameterTypes() {
98         Type JavaDoc[] baseTypes = baseMethod.getGenericParameterTypes();
99         Type JavaDoc[] ret = new AjType<?>[baseTypes.length-parameterAdjustmentFactor];
100         for (int i = parameterAdjustmentFactor; i < baseTypes.length; i++) {
101             if (baseTypes[i] instanceof Class JavaDoc) {
102                 ret[i-parameterAdjustmentFactor] = AjTypeSystem.getAjType((Class JavaDoc<?>)baseTypes[i]);
103             } else {
104                 ret[i-parameterAdjustmentFactor] = baseTypes[i];
105             }
106         }
107         return ret;
108     }
109
110     /* (non-Javadoc)
111      * @see org.aspectj.lang.reflect.InterTypeMethodDeclaration#getTypeParameters()
112      */

113     public TypeVariable JavaDoc<Method JavaDoc>[] getTypeParameters() {
114         return baseMethod.getTypeParameters();
115     }
116
117     public AjType<?>[] getExceptionTypes() {
118         Class JavaDoc<?>[] baseTypes = baseMethod.getExceptionTypes();
119         AjType<?>[] ret = new AjType<?>[baseTypes.length];
120         for (int i = 0; i < baseTypes.length; i++) {
121             ret[i] = AjTypeSystem.getAjType(baseTypes[i]);
122         }
123         return ret;
124     }
125     
126     public String JavaDoc toString() {
127         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
128         sb.append(java.lang.reflect.Modifier.toString(getModifiers()));
129         sb.append(" ");
130         sb.append(getReturnType().toString());
131         sb.append(" ");
132         sb.append(this.targetTypeName);
133         sb.append(".");
134         sb.append(getName());
135         sb.append("(");
136         AjType<?>[] pTypes = getParameterTypes();
137         for(int i = 0; i < (pTypes.length - 1); i++) {
138             sb.append(pTypes[i].toString());
139             sb.append(", ");
140         }
141         if (pTypes.length > 0) {
142             sb.append(pTypes[pTypes.length -1].toString());
143         }
144         sb.append(")");
145         return sb.toString();
146     }
147
148 }
149
Popular Tags