All Downloads are FREE. Search and download functionalities are using the official Maven repository.

patterntesting.runtime.util.reflect.MethodSignatureImpl Maven / Gradle / Ivy

Go to download

PatternTesting Runtime (patterntesting-rt) is the runtime component for the PatternTesting framework. It provides the annotations and base classes for the PatternTesting testing framework (e.g. patterntesting-check, patterntesting-concurrent or patterntesting-exception) but can be also used standalone for classpath monitoring or profiling. It uses AOP and AspectJ to perform this feat.

There is a newer version: 2.4.0
Show newest version
/*
 * $Id: MethodSignatureImpl.java,v 1.4 2011/07/09 21:43:22 oboehm Exp $
 *
 * Copyright (c) 2009 by Oliver Boehm
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express orimplied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * (c)reated 03.04.2009 by oliver ([email protected])
 */
package patterntesting.runtime.util.reflect;

import java.lang.reflect.Method;

import org.aspectj.lang.reflect.MethodSignature;
import org.slf4j.*;

import patterntesting.runtime.annotation.UnsupportedOperation;
import patterntesting.runtime.util.Converter;

/**
 * There is a class org.aspectj.runtime.reflect.MethodSignatureImpl in
 * aspectjrt.jar. But this class is not public so we must do it ourself.
 *
 * @see MethodSignature
 * @author oliver
 * @since 03.04.2009
 * @version $Revision: 1.4 $
 */
public class MethodSignatureImpl implements MethodSignature {

    private static final Logger log = LoggerFactory.getLogger(MethodSignatureImpl.class);
    private final Method method;

    /**
     * Instantiates a new method signature impl.
     *
     * @param method the method
     */
    public MethodSignatureImpl(final Method method) {
        this.method = method;
    }

    /**
     * Gets the method.
     *
     * @return the method
     *
     * @see org.aspectj.lang.reflect.MethodSignature#getMethod()
     */
    public Method getMethod() {
        return this.method;
    }

    /**
     * Gets the return type.
     *
     * @return the return type
     *
     * @see org.aspectj.lang.reflect.MethodSignature#getReturnType()
     */
    public Class getReturnType() {
        return this.method.getReturnType();
    }

    /**
     * Gets the exception types.
     *
     * @return the exception types
     *
     * @see org.aspectj.lang.reflect.CodeSignature#getExceptionTypes()
     */
    public Class[] getExceptionTypes() {
        return this.method.getExceptionTypes();
    }

    /**
     * Gets the parameter names.
     *
     * @return the parameter names
     *
     * @see org.aspectj.lang.reflect.CodeSignature#getParameterNames()
     */
    @UnsupportedOperation
    public String[] getParameterNames() {
        log.debug("this operation is not implemented");
        return null;
    }

    /**
     * Gets the parameter types.
     *
     * @return the parameter types
     *
     * @see org.aspectj.lang.reflect.CodeSignature#getParameterTypes()
     */
    public Class[] getParameterTypes() {
        return this.method.getParameterTypes();
    }

    /**
     * Gets the declaring type.
     *
     * @return the declaring type
     *
     * @see org.aspectj.lang.Signature#getDeclaringType()
     */
    public Class getDeclaringType() {
        return this.method.getDeclaringClass();
    }

    /**
     * Gets the declaring type name.
     *
     * @return the declaring type name
     *
     * @see org.aspectj.lang.Signature#getDeclaringTypeName()
     */
    public String getDeclaringTypeName() {
        return this.getDeclaringType().getName();
    }

    /**
     * Gets the modifiers.
     *
     * @return the modifiers
     *
     * @see org.aspectj.lang.Signature#getModifiers()
     */
    public int getModifiers() {
        return this.method.getModifiers();
    }

    /**
     * Gets the name.
     *
     * @return the name
     *
     * @see org.aspectj.lang.Signature#getName()
     */
    public String getName() {
        return this.method.getName();
    }

    /**
     * To long string.
     *
     * @return the string
     *
     * @see org.aspectj.lang.Signature#toLongString()
     */
    public String toLongString() {
        return this.method.toGenericString();
    }

    /**
     * To short string.
     *
     * @return the string
     *
     * @see org.aspectj.lang.Signature#toShortString()
     */
    public String toShortString() {
        return this.method.toString();
    }

    /**
     * To string.
     *
     * @return the string
     *
     * @see java.lang.Object#toString()
     */
    @Override
    public String toString() {
        return this.getReturnType() + " " + this.getDeclaringTypeName() + "."
                + this.getName() + "("
                + Converter.toShortString(this.getParameterTypes()) + ")";
    }



}

/**
 * $Log: MethodSignatureImpl.java,v $
 * Revision 1.4  2011/07/09 21:43:22  oboehm
 * switched from commons-logging to SLF4J
 *
 * Revision 1.3  2010/04/22 18:32:01  oboehm
 * compiler warnings fixed
 *
 * Revision 1.2  2010/04/22 18:27:19  oboehm
 * code cleanup of src/main/java
 *
 * Revision 1.1  2010/01/05 13:26:17  oboehm
 * begin with 1.0
 *
 * Revision 1.4  2009/12/19 22:34:09  oboehm
 * trailing spaces removed
 *
 * Revision 1.3  2009/09/25 14:49:43  oboehm
 * javadocs completed with the help of JAutodoc
 *
 * Revision 1.2  2009/04/09 18:30:47  oboehm
 * no longer double entries (bug 2745302 fixed)
 *
 * Revision 1.1  2009/04/03 21:30:09  oboehm
 * with (Abstract)ProfileAspect it is now possible
 * to find methods/constructors which are never called
 *
 * $Source: /cvsroot/patterntesting/PatternTesting10/patterntesting-rt/src/main/java/patterntesting/runtime/util/reflect/MethodSignatureImpl.java,v $
 */




© 2015 - 2024 Weber Informatics LLC | Privacy Policy