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.joinpoint.impl;
9
10 import org.codehaus.aspectwerkz.annotation.Annotation;
11 import org.codehaus.aspectwerkz.annotation.Annotations;
12 import org.codehaus.aspectwerkz.joinpoint.MethodSignature;
13
14 import java.lang.reflect.Method;
15 import java.util.List;
16
17 /***
18 * Implementation for the method signature.
19 *
20 * @author <a href="mailto:jboner@codehaus.org">Jonas BonŽr </a>
21 */
22 public class MethodSignatureImpl implements MethodSignature {
23 private final Class m_declaringType;
24
25 private final Method m_method;
26
27 /***
28 * @param declaringType
29 * @param method
30 */
31 public MethodSignatureImpl(final Class declaringType, final Method method) {
32 m_declaringType = declaringType;
33 m_method = method;
34 }
35
36 /***
37 * Returns the method.
38 *
39 * @return the method
40 */
41 public Method getMethod() {
42 return m_method;
43 }
44
45 /***
46 * Returns the declaring class.
47 *
48 * @return the declaring class
49 */
50 public Class getDeclaringType() {
51 return m_declaringType;
52 }
53
54 /***
55 * Returns the modifiers for the signature. <p/>Could be used like this:
56 * <p/>
57 * <pre>
58 * boolean isPublic = java.lang.reflect.Modifier.isPublic(signature.getModifiers());
59 * </pre>
60 *
61 * @return the mofifiers
62 */
63 public int getModifiers() {
64 return m_method.getModifiers();
65 }
66
67 /***
68 * Returns the name (f.e. name of method of field).
69 *
70 * @return
71 */
72 public String getName() {
73 return m_method.getName();
74 }
75
76 /***
77 * Returns the exception types declared by the code block.
78 *
79 * @return the exception types
80 */
81 public Class[] getExceptionTypes() {
82 return m_method.getExceptionTypes();
83 }
84
85 /***
86 * Returns the parameter types.
87 *
88 * @return the parameter types
89 */
90 public Class[] getParameterTypes() {
91 return m_method.getParameterTypes();
92 }
93
94 /***
95 * Returns the return type.
96 *
97 * @return the return type
98 */
99 public Class getReturnType() {
100 return m_method.getReturnType();
101 }
102
103 /***
104 * Return the annotation with a specific name.
105 *
106 * @param annotationName the annotation name
107 * @return the annotation or null
108 */
109 public Annotation getAnnotation(final String annotationName) {
110 return Annotations.getAnnotation(annotationName, m_method);
111 }
112
113 /***
114 * Return a list with the annotations with a specific name.
115 *
116 * @param annotationName the annotation name
117 * @return the annotations in a list (can be empty)
118 */
119 public List getAnnotations(final String annotationName) {
120 return Annotations.getAnnotations(annotationName, m_method);
121 }
122
123 /***
124 * Return all the annotations <p/>Each annotation is wrapped in
125 * {@link org.codehaus.aspectwerkz.annotation.AnnotationInfo}instance.
126 *
127 * @return a list with the annotations
128 */
129 public List getAnnotationInfos() {
130 return Annotations.getAnnotationInfos(m_method);
131 }
132
133 /***
134 * Returns a string representation of the signature.
135 *
136 * @return a string representation
137 */
138 public String toString() {
139 return m_method.toString();
140 }
141 }