Search in sources :

Example 11 with FastArray

use of org.codehaus.groovy.util.FastArray in project groovy by apache.

the class MetaMethodIndex method copyNonPrivateMethodsFromSuper.

private void copyNonPrivateMethodsFromSuper(Entry e) {
    Object oldListOrMethod = e.methodsForSuper;
    if (oldListOrMethod == null)
        return;
    if (oldListOrMethod instanceof FastArray) {
        FastArray oldList = (FastArray) oldListOrMethod;
        int len1 = oldList.size();
        Object[] list = oldList.getArray();
        for (int j = 0; j != len1; ++j) {
            MetaMethod method = (MetaMethod) list[j];
            if (method.isPrivate())
                continue;
            e.methods = addMethodToList(e.methods, method);
        }
    } else {
        MetaMethod method = (MetaMethod) oldListOrMethod;
        if (!method.isPrivate()) {
            e.methods = addMethodToList(e.methods, method);
        }
    }
}
Also used : MetaMethod(groovy.lang.MetaMethod) GeneratedMetaMethod(org.codehaus.groovy.reflection.GeneratedMetaMethod) FastArray(org.codehaus.groovy.util.FastArray)

Example 12 with FastArray

use of org.codehaus.groovy.util.FastArray in project groovy by apache.

the class MetaMethodIndex method copyAllMethods.

private void copyAllMethods(Entry from, Header to) {
    Object oldListOrMethod = from.methods;
    if (oldListOrMethod instanceof FastArray) {
        FastArray oldList = (FastArray) oldListOrMethod;
        Entry e = null;
        int len1 = oldList.size();
        Object[] list = oldList.getArray();
        for (int j = 0; j != len1; ++j) {
            MetaMethod method = (MetaMethod) list[j];
            if (e == null)
                e = getOrPutMethods(from.name, to);
            e.methods = addMethodToList(e.methods, method);
        }
    } else {
        MetaMethod method = (MetaMethod) oldListOrMethod;
        if (!method.isPrivate()) {
            Entry e = getOrPutMethods(from.name, to);
            e.methods = addMethodToList(e.methods, method);
        }
    }
}
Also used : MetaMethod(groovy.lang.MetaMethod) GeneratedMetaMethod(org.codehaus.groovy.reflection.GeneratedMetaMethod) FastArray(org.codehaus.groovy.util.FastArray)

Example 13 with FastArray

use of org.codehaus.groovy.util.FastArray in project groovy by apache.

the class MetaMethodIndex method copyNonPrivateMethods.

private void copyNonPrivateMethods(Entry from, Header to) {
    Object oldListOrMethod = from.methods;
    if (oldListOrMethod instanceof FastArray) {
        FastArray oldList = (FastArray) oldListOrMethod;
        Entry e = null;
        int len1 = oldList.size();
        Object[] list = oldList.getArray();
        for (int j = 0; j != len1; ++j) {
            MetaMethod method = (MetaMethod) list[j];
            if (method.isPrivate())
                continue;
            if (e == null)
                e = getOrPutMethods(from.name, to);
            e.methods = addMethodToList(e.methods, method);
        }
    } else {
        MetaMethod method = (MetaMethod) oldListOrMethod;
        if (!method.isPrivate()) {
            Entry e = getOrPutMethods(from.name, to);
            e.methods = addMethodToList(e.methods, method);
        }
    }
}
Also used : MetaMethod(groovy.lang.MetaMethod) GeneratedMetaMethod(org.codehaus.groovy.reflection.GeneratedMetaMethod) FastArray(org.codehaus.groovy.util.FastArray)

Example 14 with FastArray

use of org.codehaus.groovy.util.FastArray in project groovy by apache.

the class MetaMethodIndex method copyNonPrivateNonNewMetaMethods.

private void copyNonPrivateNonNewMetaMethods(Entry from, Header to) {
    Object oldListOrMethod = from.methods;
    if (oldListOrMethod == null)
        return;
    if (oldListOrMethod instanceof FastArray) {
        FastArray oldList = (FastArray) oldListOrMethod;
        Entry e = null;
        int len1 = oldList.size();
        Object[] list = oldList.getArray();
        for (int j = 0; j != len1; ++j) {
            MetaMethod method = (MetaMethod) list[j];
            if (method instanceof NewMetaMethod || method.isPrivate())
                continue;
            if (e == null)
                e = getOrPutMethods(from.name, to);
            e.methods = addMethodToList(e.methods, method);
        }
    } else {
        MetaMethod method = (MetaMethod) oldListOrMethod;
        if (method instanceof NewMetaMethod || method.isPrivate())
            return;
        Entry e = getOrPutMethods(from.name, to);
        e.methods = addMethodToList(e.methods, method);
    }
}
Also used : MetaMethod(groovy.lang.MetaMethod) GeneratedMetaMethod(org.codehaus.groovy.reflection.GeneratedMetaMethod) FastArray(org.codehaus.groovy.util.FastArray)

Example 15 with FastArray

use of org.codehaus.groovy.util.FastArray in project groovy-core by groovy.

the class MetaClassImpl method chooseMethodInternal.

private Object chooseMethodInternal(String methodName, Object methodOrList, Class[] arguments) {
    if (methodOrList instanceof MetaMethod) {
        if (((ParameterTypes) methodOrList).isValidMethod(arguments)) {
            return methodOrList;
        }
        return null;
    }
    FastArray methods = (FastArray) methodOrList;
    if (methods == null)
        return null;
    int methodCount = methods.size();
    if (methodCount <= 0) {
        return null;
    } else if (methodCount == 1) {
        Object method = methods.get(0);
        if (((ParameterTypes) method).isValidMethod(arguments)) {
            return method;
        }
        return null;
    }
    Object answer;
    if (arguments == null || arguments.length == 0) {
        answer = MetaClassHelper.chooseEmptyMethodParams(methods);
    } else {
        Object matchingMethods = null;
        final int len = methods.size;
        Object[] data = methods.getArray();
        for (int i = 0; i != len; ++i) {
            Object method = data[i];
            // making this false helps find matches
            if (((ParameterTypes) method).isValidMethod(arguments)) {
                if (matchingMethods == null)
                    matchingMethods = method;
                else if (matchingMethods instanceof ArrayList)
                    ((ArrayList) matchingMethods).add(method);
                else {
                    List arr = new ArrayList(4);
                    arr.add(matchingMethods);
                    arr.add(method);
                    matchingMethods = arr;
                }
            }
        }
        if (matchingMethods == null) {
            return null;
        } else if (!(matchingMethods instanceof ArrayList)) {
            return matchingMethods;
        }
        return chooseMostSpecificParams(methodName, (List) matchingMethods, arguments);
    }
    if (answer != null) {
        return answer;
    }
    throw new MethodSelectionException(methodName, methods, arguments);
}
Also used : NewInstanceMetaMethod(org.codehaus.groovy.runtime.metaclass.NewInstanceMetaMethod) NewMetaMethod(org.codehaus.groovy.runtime.metaclass.NewMetaMethod) MixinInstanceMetaMethod(org.codehaus.groovy.runtime.metaclass.MixinInstanceMetaMethod) NewStaticMetaMethod(org.codehaus.groovy.runtime.metaclass.NewStaticMetaMethod) GeneratedMetaMethod(org.codehaus.groovy.reflection.GeneratedMetaMethod) ClosureMetaMethod(org.codehaus.groovy.runtime.metaclass.ClosureMetaMethod) TransformMetaMethod(org.codehaus.groovy.runtime.metaclass.TransformMetaMethod) MethodSelectionException(org.codehaus.groovy.runtime.metaclass.MethodSelectionException) ParameterTypes(org.codehaus.groovy.reflection.ParameterTypes) FastArray(org.codehaus.groovy.util.FastArray)

Aggregations

FastArray (org.codehaus.groovy.util.FastArray)28 GeneratedMetaMethod (org.codehaus.groovy.reflection.GeneratedMetaMethod)26 ClosureMetaMethod (org.codehaus.groovy.runtime.metaclass.ClosureMetaMethod)16 MixinInstanceMetaMethod (org.codehaus.groovy.runtime.metaclass.MixinInstanceMetaMethod)16 NewInstanceMetaMethod (org.codehaus.groovy.runtime.metaclass.NewInstanceMetaMethod)14 NewMetaMethod (org.codehaus.groovy.runtime.metaclass.NewMetaMethod)14 NewStaticMetaMethod (org.codehaus.groovy.runtime.metaclass.NewStaticMetaMethod)14 TransformMetaMethod (org.codehaus.groovy.runtime.metaclass.TransformMetaMethod)14 MetaMethod (groovy.lang.MetaMethod)12 CachedClass (org.codehaus.groovy.reflection.CachedClass)10 MethodSelectionException (org.codehaus.groovy.runtime.metaclass.MethodSelectionException)4 ParameterTypes (org.codehaus.groovy.reflection.ParameterTypes)2 ClosureStaticMetaMethod (org.codehaus.groovy.runtime.metaclass.ClosureStaticMetaMethod)2 MetaMethodIndex (org.codehaus.groovy.runtime.metaclass.MetaMethodIndex)2