Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 /*
  * Copyright 2003-2007 the original author or authors.
  *
  * 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.codehaus.groovy.runtime.metaclass;
This exception is thrown if the runtime is unable to select a method. This class builds the exception text when calling getMessage.
Note: This exception as for internal use only!

Author(s):
Jochen Theodorou
Since:
Groovy 1.1
    private String methodName;
    private FastArray methods;
    private Class[] arguments;
    
    
Creates a new MethodSelectionException.

Parameters:
methodName name of the method
methods a FastArray of methods
arguments the method call argument classes
    public MethodSelectionException(String methodNameFastArray methodsClass[] arguments) {
        super(methodName);
        this. = methodName;
        this. = arguments;
        this. = methods;
    }
    public String getMessage() {
        StringBuffer buffer = new StringBuffer();
        buffer.append("Could not find which method ").append();
        appendClassNames(buffer,);
        buffer.append(" to invoke from this list:");
        appendMethods(buffer);
        return buffer.toString();
    }
    
    
    private void appendClassNames(StringBuffer argBufClass[] classes) {
        argBuf.append("(");
        for (int i = 0; i < classes.lengthi++) {
            if (i > 0) {
                argBuf.append(", ");
            }
            Class clazz = classes[i];
            String name = clazz==null"null"clazz.getName();
            argBuf.append(name);
        }
        argBuf.append(")");
    }
    
    private void appendMethods(StringBuffer buffer) {
        for (int i = 0; i < .i++) {
            buffer.append("\n  ");
            Object methodOrConstructor = .get(i);
            if (methodOrConstructor instanceof MetaMethod) {
                MetaMethod method = (MetaMethodmethodOrConstructor;
                buffer.append(Modifier.toString(method.getModifiers()));
                buffer.append(" ").append(method.getReturnType().getName());
                buffer.append(" ").append(method.getDeclaringClass().getName());
                buffer.append("#");
                buffer.append(method.getName());
                appendClassNames(buffer,method.getNativeParameterTypes());
            }
            else {
                CachedConstructor method = (CachedConstructormethodOrConstructor;
                buffer.append(Modifier.toString(method.cachedConstructor.getModifiers()));
                buffer.append(" ").append(method.cachedConstructor.getDeclaringClass().getName());
                buffer.append("#<init>");
                appendClassNames(buffer,method.getNativeParameterTypes());
            }
        }
    }
New to GrepCode? Check out our FAQ X