head	1.3;
access;
symbols;
locks; strict;
comment	@# @;


1.3
date	2001.08.28.23.02.05;	author leonardr;	state Exp;
branches;
next	1.2;

1.2
date	2001.08.17.22.57.33;	author dlr;	state Exp;
branches;
next	1.1;

1.1
date	2001.08.17.19.07.04;	author leonardr;	state Exp;
branches;
next	;


desc
@@


1.3
log
@The tool events now know that business objects don't always correspond naively to peers, and that it's okay to call a method using a subclass of the formal argument as the actual argument.
@
text
@/* ================================================================
 * Copyright (c) 2001 CollabNet.  All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 *
 * 1. Redistributions of source code must retain the above copyright
 * notice, this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 *
 * 3. The end-user documentation included with the redistribution, if
 * any, must include the following acknowlegement: "This product includes
 * software developed by CollabNet (http://www.collab.net/)."
 * Alternately, this acknowlegement may appear in the software itself, if
 * and wherever such third-party acknowlegements normally appear.
 *
 * 4. The hosted project names must not be used to endorse or promote
 * products derived from this software without prior written
 * permission. For written permission, please contact info@@collab.net.
 *
 * 5. Products derived from this software may not use the "Tigris" name
 * nor may "Tigris" appear in their names without prior written
 * permission of CollabNet.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL COLLABNET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * ====================================================================
 *
 * This software consists of voluntary contributions made by many
 * individuals on behalf of CollabNet.
 */
package org.tigris.helm.util;

import java.lang.*;
import java.lang.reflect.*;

/**
 * Class representing the signature of a method.
 *
 * @@author <a href="mailto:leonardr@@collab.net">Leonard Richardson</a>
 * @@version $Id: MethodSignature.java,v 1.2 2001/08/17 22:57:33 dlr Exp $
 */
public class MethodSignature
{
    String name;
    Class[] parameters;
    
    /**
     * Creates a MethodSignature object from a Method.
     */
    public MethodSignature(Method m)
    {
        name = m.getName();
        parameters = m.getParameterTypes();
    }

    /**
     * Creates a MethodSignature object from a name and some parameters
     */
    public MethodSignature(String name, Class[] parameters)
    {
        this.name = name;
        this.parameters = parameters;
    }

    public String toString()
    {
        StringBuffer s = new StringBuffer(name);
        s.append('(');
        for (int m = 0; m < parameters.length; m++)
        {
            s.append(parameters[m].getName());
            if (m < (parameters.length - 1))
            {
                s.append(", ");
            }
        }
        s.append(')');
        return s.toString();
    }

    public int hashCode()
    {
        return name.hashCode();
    }

    public boolean equals(Object o)
    {
        boolean equal = false;
        if (o instanceof MethodSignature)
        {
            MethodSignature s = (MethodSignature)o;
            if (name.equals(s.name) &&
                parameters.length == s.parameters.length)
            {
                equal = true;
                for (int i = 0; i < parameters.length; i++)
                {
                    if (!parameters[i].equals(s.parameters[i]))
                    {
                        equal = false;
                        break;
                    }
                }
            }
        }
        return equal;
    }

    /**
     * Returns true iff this method has the same name as the given
     * method and takes subclasses of the given method's arguments
     * (or the same classes) as its arguments.
     */
    public boolean subclasses(MethodSignature s)
    {
        boolean compatible = false;
        if (name.equals(s.name) &&
            parameters.length == s.parameters.length)
        {
            compatible = true;
            for (int i = 0; i < parameters.length; i++)
            {
                if (!s.parameters[i].isAssignableFrom(parameters[i]))
                {
                    compatible = false;
                    break;
                }
            }
        }
        return compatible;
    }
}
@


1.2
log
@Minor optimization.
@
text
@d55 1
a55 1
 * @@version $Id: MethodSignature.java,v 1.1 2001/08/17 19:07:04 leonardr Exp $
d124 23
@


1.1
log
@Convenience class for representing a method's signature.
@
text
@d55 1
a55 1
 * @@version $Id: MethodSignature.java,v 1.31 2001/05/14 12:40:12 edk Exp $
d83 1
a83 1
        s.append("(");
d92 1
a92 1
        s.append(")");
@

