Package groovy.lang

Examples of groovy.lang.MetaMethod


      argTypes[i++] = arg == null ? null : arg.getClass();
    }

    MetaClass metaClass = target instanceof Class ? InvokerHelper.getMetaClass((Class) target) : InvokerHelper.getMetaClass(target);

    MetaMethod metaMethod = metaClass.pickMethod(method, argTypes);
    if (metaMethod == null) {
      return false;
    }

    Class returnType = metaMethod.getReturnType();
    return returnType == void.class || returnType == Void.class;
  }
View Full Code Here


*
*/
public class StandardInterceptor<B extends StandardBuilder, S extends StandardStack> implements GroovyBuilderInterceptor<B, S> {

  public Object handleInvokedMethod(InterceptorContext<B, S> ctx) {
    MetaMethod method = ctx.getMetaMethod();
    B builder = ctx.getBuilder();
    S stack = ctx.getStack();
    Object[] args = ctx.getArgs();
    String name = ctx.getMethodName();
   
    if (method != null) return method.invoke(builder, args);
   
    Object value = null;
    Map<Object, Object> parameters = null;
    Closure closure = null;
   
View Full Code Here

   * call. These arguments should match standard optional parameters (Closure, Object, Map).
   * If there are it will then try to call the method on the current node (if any). Otherwise it will attempt to find a class in
   * via {@link ObjectFactoryInstantiator#instantiateNode(ObjectFactoryInterceptor, String, Object)}.
   */
  public Object handleInvokedMethod(InterceptorContext<T, S> ctx) {
    MetaMethod method = ctx.getMetaMethod();
    T builder = ctx.getBuilder();
    S stack = ctx.getStack();
    Object[] args = ctx.getArgs();
    String name = ctx.getMethodName();
   
    // If we should attempt method calls on the builder first
    // we will do so, only catching MME's, other exceptions mean
    // the method was probably called and should be propagated.
    if (method != null && !callProxyFirst) try {
      return method.invoke(builder, args);
    } catch (MissingMethodException mme) {}

   
    Closure closure = null;
    Object nodeInstance = stack.getCurrent();
    Map attributes = null;
   
    // If this is not the first node we want to try
    // to invoke a method corresponding to the node object.
    if (nodeInstance != null) {
      try {
        return InvokerHelper.invokeMethod(nodeInstance, name, args);
      } catch (MissingMethodException e) {
        if (attemptBinding)
          try { return builder.getBinding().invokeMethod(name, args); }
          catch (MissingMethodException ee) {}
          catch (MissingPropertyException ee) {}
      }
      nodeInstance = null;
    }
   
    // If this is a three argument or less having unique arguments being one of
    // Object, Map or Closure then this can be considered a valid node invocation
    // from the builder source.
    if (args.length <= 3) {
      try {
        Map<Class, Object> ps = ParameterUtil.scan(args, Closure.class, Map.class, Object.class);
       
        closure = (Closure) ps.get(Closure.class);
        attributes = (Map) ps.get(Map.class);
        if (ps.containsKey(Object.class)) {
          if (attributes == null) attributes = new HashMap();
          attributes.put("value", ps.get(Object.class));
        }
       
        nodeInstance = this.instantiator.instantiateNode(builder, this, name, stack.getCurrent());
      } catch (InvalidParameterException e) {}
    }
   
    // If a node object was created then we want to push it onto the stack, call
    // the closure if one was passed and then pop it off the stack.
    if (nodeInstance != null) {
      return this.handleNode(builder, stack, name, nodeInstance, attributes, closure);
    }

    // If no node instance could be created then we will
    // do a last attempt (if not already attempted above)
    // to call the method on the builder
    if (method != null && callProxyFirst) return method.invoke(builder, args);
   
    // If we get here we have attempted all methods for valid invocation
    // thus we must throw a MME
    throw new MissingMethodException(name, builder.getClass(), args);
   
View Full Code Here

        MetaClass metaClass = InvokerHelper.getMetaClass(objectUnderInspection);
        List metaMethods = metaClass.getMetaMethods();
        Object[] result = new Object[metaMethods.size()];
        int i=0;
        for (Iterator iter = metaMethods.iterator(); iter.hasNext(); i++) {
            MetaMethod metaMethod = (MetaMethod) iter.next();
            result[i] = methodInfo(metaMethod);
        }
        return result;
    }
View Full Code Here

            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);
            }
        }
    }
View Full Code Here

            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.methodsForSuper = addMethodToList(e.methodsForSuper, method);
            }
        } else {
            MetaMethod method = (MetaMethod) oldListOrMethod;
            Entry e = getOrPutMethods(from.name, to);
            e.methodsForSuper = addMethodToList(e.methodsForSuper, method);
        }
    }
View Full Code Here

        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);
            }
        }
    }
View Full Code Here

            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);
        }
    }
View Full Code Here

        if (o == null) {
            return method;
        }

        if (o instanceof MetaMethod) {
            MetaMethod match = (MetaMethod) o;
            if (!isMatchingMethod(match, method)) {
                FastArray list = new FastArray(2);
                list.add(match);
                list.add(method);
                return list;
            } else {
                if (match.isPrivate()
                        || (!isNonRealMethod(match) && match.getDeclaringClass().isInterface() && !method.getDeclaringClass().isInterface())) {
                    // do not overwrite interface methods with instance methods
                    // do not overwrite private methods
                    // Note: private methods from parent classes are not shown here,
                    // but when doing the multimethod connection step, we overwrite
                    // methods of the parent class with methods of a subclass and
                    // in that case we want to keep the private methods
                } else {
                    CachedClass methodC = method.getDeclaringClass();
                    CachedClass matchC = match.getDeclaringClass();
                    if (methodC == matchC) {
                        if (isNonRealMethod(method)) {
                            return method;
                        }
                    } else if (!methodC.isAssignableFrom(matchC.getTheClass())) {
                        return method;
                    }
                }
            }
            return o;
        }

        if (o instanceof FastArray) {
            FastArray list = (FastArray) o;
            int found = findMatchingMethod(list, method);

            if (found == -1) {
                list.add(method);
            } else {
                MetaMethod match = (MetaMethod) list.get(found);
                if (match==method) return o;
                if (match.isPrivate()
                        || (!isNonRealMethod(match) && match.getDeclaringClass().isInterface() && !method.getDeclaringClass().isInterface())) {
                    // do not overwrite interface methods with instance methods
                    // do not overwrite private methods
                    // Note: private methods from parent classes are not shown here,
                    // but when doing the multimethod connection step, we overwrite
                    // methods of the parent class with methods of a subclass and
                    // in that case we want to keep the private methods
                } else {
                    CachedClass  methodC = method.getDeclaringClass();
                    CachedClass matchC = match.getDeclaringClass();
                    if (methodC == matchC) {
                        if (isNonRealMethod(method)) {
                            list.set(found, method);
                        }
                    } else if (!methodC.isAssignableFrom(matchC.getTheClass())) {
View Full Code Here

    private int findMatchingMethod(FastArray list, MetaMethod method) {
        int len = list.size();
        Object data[] = list.getArray();
        for (int j = 0; j != len; ++j) {
            MetaMethod aMethod = (MetaMethod) data[j];
            if (isMatchingMethod(aMethod, method))
                return j;
        }
        return -1;
    }
View Full Code Here

TOP

Related Classes of groovy.lang.MetaMethod

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.