Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  // Copyright 2006, 2007, 2010 The Apache Software Foundation
  //
  // 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 or implied.
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
 package org.apache.tapestry5.services;
 
 
A representation of a method signature, which consists of its name, modifiers (primarily, visibility), return type, parameter types, and declared exception types.

Types are stored as class names (or primitive names) because the signature is used with ClassTransformation (which operates on as-yet unloaded classes).

 
 {
     private int hashCode = -1;
 
     private final int modifiers;
 
     private final String returnTypemethodName;
 
     private final String[] parameterTypesexceptionTypes;

    
Convenience for adding a public void method with no parameters or exception types.
 
 
     public TransformMethodSignature(String name)
     {
     }
 
     public TransformMethodSignature(int modifiersString typeString nameString[] parameterTypes,
             String[] exceptionTypes)
     {
         assert InternalUtils.isNonBlank(name);
         assert InternalUtils.isNonBlank(type);
 
         this. = modifiers;
 
          = type;
          = name;
 
         // TODO: Checks that no element within the two arrays
         // is null or blank.
 
         this. = typeNamesOrEmpty(parameterTypes);
         this. = typeNamesOrEmpty(exceptionTypes);
     }
 
     private String[] typeNamesOrEmpty(String[] types)
     {
         return types == null ? . : types;
     }

    
Returns a non-null array of the names of each declared exception type thrown by the method. Calling code should not modify the array.
 
     public String[] getExceptionTypes()
     {
         return ;
     }

    
Returns the name of the method.
 
     public String getMethodName()
     {
         return ;
     }

    
Returns the set of modifier flags for this method.

 
     public int getModifiers()
     {
         return ;
     }

    
Returns an array of the type name for each parameter. Calling code should not modify the array.
    public String[] getParameterTypes()
    {
        return ;
    }

    
Return the type name of the return type of the method.
    public String getReturnType()
    {
        return ;
    }
    @Override
    public int hashCode()
    {
        if ( == -1)
        {
             = 17 * ;
             += 31 * .hashCode();
             += 31 * .hashCode();
            for (String parameterType : )
            {
                 += 31 * parameterType.hashCode();
            }
            for (String exceptionType : )
            {
                 += 31 * exceptionType.hashCode();
            }
        }
        return ;
    }
    @Override
    public boolean equals(Object other)
    {
        if (other == null || !(other instanceof TransformMethodSignature))
            return false;
        TransformMethodSignature ms = (TransformMethodSignatureother;
        return  == ms.modifiers && .equals(ms.returnType) && .equals(ms.methodName)
                && matches(ms.parameterTypes) && matches(ms.exceptionTypes);
    }
    private boolean matches(String[] valuesString[] otherValues)
    {
        if (values.length != otherValues.length)
            return false;
        for (int i = 0; i < values.lengthi++)
        {
            if (!values[i].equals(otherValues[i]))
                return false;
        }
        return true;
    }

    
Returns the long form description of the signature. This includes modifiers, return type, method name, parameters and thrown exceptions, formatted approximately as it would appear in Java source (except that parameter names, which are not known, do no appear).
    @Override
    public String toString()
    {
        StringBuilder builder = new StringBuilder();
        // Package private is simply omitted.
        if ( != 0)
        {
            builder.append(Modifier.toString());
            builder.append(' ');
        }
        builder.append();
        builder.append(' ');
        addMethodNameAndParameters(builder);
        for (int i = 0; i < .i++)
        {
            if (i == 0)
                builder.append(" throws ");
            else
                builder.append(", ");
            builder.append([i]);
        }
        return builder.toString();
    }
    private void addMethodNameAndParameters(StringBuilder builder)
    {
        builder.append();
        builder.append('(');
        for (int i = 0; i < .i++)
        {
            if (i > 0)
                builder.append(", ");
            builder.append([i]);
        }
        builder.append(')');
    }

    
Sorting is primarily via method name. For methods with the same name, the second level of sorting is by parameter count (descending).
    public int compareTo(TransformMethodSignature o)
    {
        int result = .compareTo(o.methodName);
        // Sort descending
        if (result == 0)
            result = o.parameterTypes.length - .;
        return result;
    }

    
Returns a shortened form of the string representation of the method. It lists just the name of the method and the types of any parameters, omitting return type, exceptions and modifiers.

Returns:
    public String getMediumDescription()
    {
        StringBuilder builder = new StringBuilder();
        addMethodNameAndParameters(builder);
        return builder.toString();
    }
New to GrepCode? Check out our FAQ X