001    /*
002     * $Id: MethodSignatureImpl.java,v 1.4 2011/07/09 21:43:22 oboehm Exp $
003     *
004     * Copyright (c) 2009 by Oliver Boehm
005     *
006     * Licensed under the Apache License, Version 2.0 (the "License");
007     * you may not use this file except in compliance with the License.
008     * You may obtain a copy of the License at
009     *
010     *   http://www.apache.org/licenses/LICENSE-2.0
011     *
012     * Unless required by applicable law or agreed to in writing, software
013     * distributed under the License is distributed on an "AS IS" BASIS,
014     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express orimplied.
015     * See the License for the specific language governing permissions and
016     * limitations under the License.
017     *
018     * (c)reated 03.04.2009 by oliver (ob@aosd.de)
019     */
020    package patterntesting.runtime.util.reflect;
021    
022    import java.lang.reflect.Method;
023    
024    import org.aspectj.lang.reflect.MethodSignature;
025    import org.slf4j.*;
026    
027    import patterntesting.runtime.annotation.UnsupportedOperation;
028    import patterntesting.runtime.util.Converter;
029    
030    /**
031     * There is a class org.aspectj.runtime.reflect.MethodSignatureImpl in
032     * aspectjrt.jar. But this class is not public so we must do it ourself.
033     *
034     * @see MethodSignature
035     * @author <a href="boehm@javatux.de">oliver</a>
036     * @since 03.04.2009
037     * @version $Revision: 1.4 $
038     */
039    public class MethodSignatureImpl implements MethodSignature {
040    
041        private static final Logger log = LoggerFactory.getLogger(MethodSignatureImpl.class);
042        private final Method method;
043    
044        /**
045         * Instantiates a new method signature impl.
046         *
047         * @param method the method
048         */
049        public MethodSignatureImpl(final Method method) {
050            this.method = method;
051        }
052    
053        /**
054         * Gets the method.
055         *
056         * @return the method
057         *
058         * @see org.aspectj.lang.reflect.MethodSignature#getMethod()
059         */
060        public Method getMethod() {
061            return this.method;
062        }
063    
064        /**
065         * Gets the return type.
066         *
067         * @return the return type
068         *
069         * @see org.aspectj.lang.reflect.MethodSignature#getReturnType()
070         */
071        public Class<?> getReturnType() {
072            return this.method.getReturnType();
073        }
074    
075        /**
076         * Gets the exception types.
077         *
078         * @return the exception types
079         *
080         * @see org.aspectj.lang.reflect.CodeSignature#getExceptionTypes()
081         */
082        public Class<?>[] getExceptionTypes() {
083            return this.method.getExceptionTypes();
084        }
085    
086        /**
087         * Gets the parameter names.
088         *
089         * @return the parameter names
090         *
091         * @see org.aspectj.lang.reflect.CodeSignature#getParameterNames()
092         */
093        @UnsupportedOperation
094        public String[] getParameterNames() {
095            log.debug("this operation is not implemented");
096            return null;
097        }
098    
099        /**
100         * Gets the parameter types.
101         *
102         * @return the parameter types
103         *
104         * @see org.aspectj.lang.reflect.CodeSignature#getParameterTypes()
105         */
106        public Class<?>[] getParameterTypes() {
107            return this.method.getParameterTypes();
108        }
109    
110        /**
111         * Gets the declaring type.
112         *
113         * @return the declaring type
114         *
115         * @see org.aspectj.lang.Signature#getDeclaringType()
116         */
117        public Class<?> getDeclaringType() {
118            return this.method.getDeclaringClass();
119        }
120    
121        /**
122         * Gets the declaring type name.
123         *
124         * @return the declaring type name
125         *
126         * @see org.aspectj.lang.Signature#getDeclaringTypeName()
127         */
128        public String getDeclaringTypeName() {
129            return this.getDeclaringType().getName();
130        }
131    
132        /**
133         * Gets the modifiers.
134         *
135         * @return the modifiers
136         *
137         * @see org.aspectj.lang.Signature#getModifiers()
138         */
139        public int getModifiers() {
140            return this.method.getModifiers();
141        }
142    
143        /**
144         * Gets the name.
145         *
146         * @return the name
147         *
148         * @see org.aspectj.lang.Signature#getName()
149         */
150        public String getName() {
151            return this.method.getName();
152        }
153    
154        /**
155         * To long string.
156         *
157         * @return the string
158         *
159         * @see org.aspectj.lang.Signature#toLongString()
160         */
161        public String toLongString() {
162            return this.method.toGenericString();
163        }
164    
165        /**
166         * To short string.
167         *
168         * @return the string
169         *
170         * @see org.aspectj.lang.Signature#toShortString()
171         */
172        public String toShortString() {
173            return this.method.toString();
174        }
175    
176        /**
177         * To string.
178         *
179         * @return the string
180         *
181         * @see java.lang.Object#toString()
182         */
183        @Override
184        public String toString() {
185            return this.getReturnType() + " " + this.getDeclaringTypeName() + "."
186                    + this.getName() + "("
187                    + Converter.toShortString(this.getParameterTypes()) + ")";
188        }
189    
190    
191    
192    }
193    
194    /**
195     * $Log: MethodSignatureImpl.java,v $
196     * Revision 1.4  2011/07/09 21:43:22  oboehm
197     * switched from commons-logging to SLF4J
198     *
199     * Revision 1.3  2010/04/22 18:32:01  oboehm
200     * compiler warnings fixed
201     *
202     * Revision 1.2  2010/04/22 18:27:19  oboehm
203     * code cleanup of src/main/java
204     *
205     * Revision 1.1  2010/01/05 13:26:17  oboehm
206     * begin with 1.0
207     *
208     * Revision 1.4  2009/12/19 22:34:09  oboehm
209     * trailing spaces removed
210     *
211     * Revision 1.3  2009/09/25 14:49:43  oboehm
212     * javadocs completed with the help of JAutodoc
213     *
214     * Revision 1.2  2009/04/09 18:30:47  oboehm
215     * no longer double entries (bug 2745302 fixed)
216     *
217     * Revision 1.1  2009/04/03 21:30:09  oboehm
218     * with (Abstract)ProfileAspect it is now possible
219     * to find methods/constructors which are never called
220     *
221     * $Source: /cvsroot/patterntesting/PatternTesting10/patterntesting-rt/src/main/java/patterntesting/runtime/util/reflect/MethodSignatureImpl.java,v $
222     */