Save This Page
Home » cglib-src-2.2 » net.sf.cglib.core » [javadoc | source]
    1   /*
    2    * Copyright 2003 The Apache Software Foundation
    3    *
    4    *  Licensed under the Apache License, Version 2.0 (the "License");
    5    * you may not use this file except in compliance with the License.
    6    * You may obtain a copy of the License at
    7    *
    8    *      http://www.apache.org/licenses/LICENSE-2.0
    9    *
   10    *  Unless required by applicable law or agreed to in writing, software
   11    * distributed under the License is distributed on an "AS IS" BASIS,
   12    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   13    * See the License for the specific language governing permissions and
   14    * limitations under the License.
   15    */
   16   package net.sf.cglib.core;
   17   
   18   import org.objectweb.asm.Type;
   19   
   20   /**
   21    * A representation of a method signature, containing the method name,
   22    * return type, and parameter types.
   23    */
   24   public class Signature {
   25       private String name;
   26       private String desc;
   27   
   28       public Signature(String name, String desc) {
   29           // TODO: better error checking
   30           if (name.indexOf('(') >= 0) {
   31               throw new IllegalArgumentException("Name '" + name + "' is invalid");
   32           }
   33           this.name = name;
   34           this.desc = desc;
   35       }
   36   
   37       public Signature(String name, Type returnType, Type[] argumentTypes) {
   38           this(name, Type.getMethodDescriptor(returnType, argumentTypes));
   39       }
   40   
   41       public String getName() {
   42           return name;
   43       }
   44   
   45       public String getDescriptor() {
   46           return desc;
   47       }
   48   
   49       public Type getReturnType() {
   50           return Type.getReturnType(desc);
   51       }
   52   
   53       public Type[] getArgumentTypes() {
   54           return Type.getArgumentTypes(desc);
   55       }
   56   
   57       public String toString() {
   58           return name + desc;
   59       }
   60   
   61       public boolean equals(Object o) {
   62           if (o == null)
   63               return false;
   64           if (!(o instanceof Signature))
   65               return false;
   66           Signature other = (Signature)o;
   67           return name.equals(other.name) && desc.equals(other.desc);
   68       }
   69   
   70       public int hashCode() {
   71           return name.hashCode() ^ desc.hashCode();
   72       }
   73   }

Save This Page
Home » cglib-src-2.2 » net.sf.cglib.core » [javadoc | source]