1 /***************************************************************************************
2 * Copyright (c) Jonas Bonér, Alexandre Vasseur. All rights reserved. *
3 * http://aspectwerkz.codehaus.org *
4 * ---------------------------------------------------------------------------------- *
5 * The software in this package is published under the terms of the LGPL license *
6 * a copy of which has been included with this distribution in the license.txt file. *
7 **************************************************************************************/
8 package org.codehaus.aspectwerkz.reflect.impl.javassist;
9
10 import org.codehaus.aspectwerkz.annotation.instrumentation.AttributeExtractor;
11 import org.codehaus.aspectwerkz.reflect.ClassInfo;
12 import javassist.CtBehavior;
13 import javassist.CtClass;
14 import javassist.NotFoundException;
15
16 /***
17 * Base class for the code members (method and constructor) for javassist.
18 *
19 * @author <a href="mailto:jboner@codehaus.org">Jonas Bonér </a>
20 */
21 abstract class JavassistCodeInfo extends JavassistMemberInfo {
22 /***
23 * A list with the parameter types.
24 */
25 protected ClassInfo[] m_parameterTypes = null;
26
27 /***
28 * A list with the exception types.
29 */
30 protected ClassInfo[] m_exceptionTypes = null;
31
32 /***
33 * Creates a new method meta data instance.
34 *
35 * @param method
36 * @param declaringType
37 * @param loader
38 * @param attributeExtractor
39 */
40 JavassistCodeInfo(final CtBehavior method,
41 final JavassistClassInfo declaringType,
42 final ClassLoader loader,
43 final AttributeExtractor attributeExtractor) {
44 super(method, declaringType, loader, attributeExtractor);
45 }
46
47 /***
48 * Returns the parameter types.
49 *
50 * @return the parameter types
51 */
52 public ClassInfo[] getParameterTypes() {
53 if (m_parameterTypes == null) {
54 try {
55 CtClass[] parameterTypes = ((CtBehavior) m_member).getParameterTypes();
56 m_parameterTypes = new ClassInfo[parameterTypes.length];
57 for (int i = 0; i < parameterTypes.length; i++) {
58 CtClass parameterType = parameterTypes[i];
59 ClassInfo metaData;
60 if (m_classInfoRepository.hasClassInfo(parameterType.getName())) {
61 metaData = m_classInfoRepository.getClassInfo(parameterType.getName());
62 } else {
63 metaData = JavassistClassInfo.getClassInfo(parameterType, (ClassLoader) m_loaderRef.get());
64 m_classInfoRepository.addClassInfo(metaData);
65 }
66 m_parameterTypes[i] = metaData;
67 }
68 } catch (NotFoundException e) {
69
70 }
71 }
72 return m_parameterTypes;
73 }
74
75 /***
76 * Returns the exception types.
77 *
78 * @return the exception types
79 */
80 public ClassInfo[] getExceptionTypes() {
81 if (m_exceptionTypes == null) {
82 try {
83 CtClass[] exceptionTypes = ((CtBehavior) m_member).getExceptionTypes();
84 m_exceptionTypes = new ClassInfo[exceptionTypes.length];
85 for (int i = 0; i < exceptionTypes.length; i++) {
86 CtClass exceptionType = exceptionTypes[i];
87 ClassInfo metaData;
88 if (m_classInfoRepository.hasClassInfo(exceptionType.getName())) {
89 metaData = m_classInfoRepository.getClassInfo(exceptionType.getName());
90 } else {
91 metaData = JavassistClassInfo.getClassInfo(exceptionType, (ClassLoader) m_loaderRef.get());
92 m_classInfoRepository.addClassInfo(metaData);
93 }
94 m_exceptionTypes[i] = metaData;
95 }
96 } catch (NotFoundException e) {
97
98 }
99 }
100 return m_exceptionTypes;
101 }
102 }