Java 类groovy.lang.MetaMethod 实例源码

项目:Reer    文件:BeanDynamicObject.java   
@Nullable
private MetaMethod findPropertyMissingMethod(MetaClass metaClass) {
    if (metaClass instanceof MetaClassImpl) {
        // Reach into meta class to avoid lookup
        try {
            return (MetaMethod) MISSING_PROPERTY_GET_METHOD.get(metaClass);
        } catch (IllegalAccessException e) {
            throw UncheckedException.throwAsUncheckedException(e);
        }
    }

    // Query the declared methods of the meta class
    for (MetaMethod method : metaClass.getMethods()) {
        if (method.getName().equals("propertyMissing") && method.getParameterTypes().length == 1) {
            return method;
        }
    }
    return null;
}
项目:ADRApp    文件:ScriptPR.java   
/**
 * Check whether the script declares a method with the given name that takes a
 * corpus parameter, and if so, call it passing the corpus from the given
 * controller. If the controller is not a CorpusController, do nothing.
 *
 * @throws ExecutionException
 *           if the script method throws an ExecutionException we re-throw it
 */
protected void callControllerAwareMethod(String methodName, Controller c)
        throws ExecutionException {
  if(!(c instanceof CorpusController)) { return; }
  List<MetaMethod> metaMethods =
          groovyScript.getMetaClass().respondsTo(groovyScript, methodName,
                  new Class[]{gate.Corpus.class});
  if(!metaMethods.isEmpty()) {
    try {
      metaMethods.get(0).invoke(groovyScript,
              new Corpus[]{((CorpusController)c).getCorpus()});
    } catch(InvokerInvocationException iie) {
      if(iie.getCause() instanceof ExecutionException) {
        throw (ExecutionException)iie.getCause();
      } else if(iie.getCause() instanceof RuntimeException) {
        throw (RuntimeException)iie.getCause();
      } else if(iie.getCause() instanceof Error) {
        throw (Error)iie.getCause();
      } else {
        throw iie;
      }
    }
  }
}
项目:groovy    文件:NumberMathModificationInfo.java   
public void checkIfStdMethod(MetaMethod method) {
    if (method.getClass() != NewInstanceMetaMethod.class) {
        String name = method.getName();

        if (method.getParameterTypes().length != 1)
            return;

        if (!method.getParameterTypes()[0].isNumber && method.getParameterTypes()[0].getTheClass() != Object.class)
            return;

        if (!NAMES.contains(name))
            return;

        checkNumberOps(name, method.getDeclaringClass().getTheClass());
    }
}
项目:Reer    文件:BeanDynamicObject.java   
@Nullable
@Override
protected MetaMethod lookupMethod(MetaClass metaClass, String name, Class[] arguments) {
    MetaMethod metaMethod = super.lookupMethod(metaClass, name, arguments);
    if (metaMethod != null) {
        return metaMethod;
    }
    metaMethod = classMetaData.getMetaMethod(name, arguments);
    if (metaMethod != null && Modifier.isStatic(metaMethod.getModifiers())) {
        return metaMethod;
    }
    return null;
}
项目:sponge    文件:GroovyKnowledgeBaseInterpreter.java   
protected Object doInvokeFunction(String name, boolean optional, Object[] args) {
    Object result = null;
    boolean invoked = false;

    for (Script script : scripts) {
        MetaMethod method = script.getMetaClass().getMetaMethod(name, args != null ? args : new Object[0]);
        if (method != null) {
            if (invoked) {
                // Invoke only the last function of the same name. This is required for compatibility with other supported
                // scripting languages.
                break;
            }
            result = script.invokeMethod(name, args);
            invoked = true;
        }
    }

    if (!invoked) {
        if (optional) {
            return null;
        } else {
            throw new SpongeException("Missing function '" + name + "'");
        }
    }

    return result;
}
项目:ipf-flow-manager    文件:ExtensionModuleFactory.java   
@Override
public ExtensionModule newModule(Properties properties, ClassLoader classLoader) {
    LOG.info("Registering new extension module {} defined in class {}",
            properties.getProperty(MODULE_NAME_KEY),
            properties.getProperty(MetaInfExtensionModule.MODULE_INSTANCE_CLASSES_KEY));
    ExtensionModule module = createExtensionModule(properties, classLoader);
    if (LOG.isDebugEnabled()) {
        for(MetaMethod method : module.getMetaMethods()) {
            LOG.debug("registered method: {}", method);
        }
    }
    return module;
}
项目:yajsw    文件:SimpleExtensionModule.java   
private static void createMetaMethods(final Class extensionClass, final List<MetaMethod> metaMethods, final boolean isStatic) {
    CachedClass cachedClass = ReflectionCache.getCachedClass(extensionClass);
    CachedMethod[] methods = cachedClass.getMethods();
    for (CachedMethod method : methods) {
        if (method.isStatic() && method.isPublic() && method.getParamsCount() > 0) {
            // an extension method is found
            metaMethods.add(isStatic?new NewStaticMetaMethod(method) : new NewInstanceMetaMethod(method));
        }
    }
}
项目:jasperreports    文件:GroovyEvaluator.java   
protected void addFunctionClosureMethods(MethodClosure methodClosure, String functionName)
{
    // calling registerInstanceMethod(String, Closure) would register all methods, but we only want public methods
    List<MetaMethod> closureMethods = ClosureMetaMethod.createMethodList(functionName, getClass(), methodClosure);
    for (MetaMethod metaMethod : closureMethods)
    {
        if (!(metaMethod instanceof ClosureMetaMethod))
        {
            // should not happen
            log.warn("Got unexpected closure method " + metaMethod + " of type " + metaMethod.getClass().getName());
            continue;
        }

        ClosureMetaMethod closureMethod = (ClosureMetaMethod) metaMethod;
        if (!closureMethod.getDoCall().isPublic())
        {
            if (log.isDebugEnabled())
            {
                log.debug("method " + closureMethod.getDoCall() + " is not public, not registering");
            }
            continue;
        }

        if (log.isDebugEnabled())
        {
            log.debug("creating closure method for " + closureMethod.getDoCall());
        }

        functionMethods.add(closureMethod);
    }
}
项目:intellij-ce-playground    文件:CustomMembersGenerator.java   
@SuppressWarnings("UnusedDeclaration")
@Nullable
public Object methodMissing(String name, Object args) {
  final Object[] newArgs = constructNewArgs((Object[])args);

  // Get other DSL methods from extensions
  for (GdslMembersProvider provider : PROVIDERS) {
    final List<MetaMethod> variants = DefaultGroovyMethods.getMetaClass(provider).respondsTo(provider, name, newArgs);
    if (variants.size() == 1) {
      return InvokerHelper.invokeMethod(provider, name, newArgs);
    }
  }
  return null;
}
项目:groovy    文件:ClosureMetaMethod.java   
private static MetaMethod adjustParamTypesForStdMethods(MetaMethod metaMethod, String methodName) {
    Class[] nativeParamTypes = metaMethod.getNativeParameterTypes();
    nativeParamTypes = (nativeParamTypes != null) ? nativeParamTypes : EMPTY_CLASS_ARRAY;
    // for methodMissing, first parameter should be String type - to allow overriding of this method without
    // type String explicitly specified for first parameter (missing method name) - GROOVY-2951
    if("methodMissing".equals(methodName) && nativeParamTypes.length == 2 && nativeParamTypes[0] != String.class) {
        nativeParamTypes[0] = String.class;
    }
    return metaMethod;
}
项目:groovy    文件:CachedClass.java   
private void updateSetNewMopMethods(List<MetaMethod> arr) {
    if (arr != null) {
        final MetaMethod[] metaMethods = arr.toArray(new MetaMethod[arr.size()]);
        classInfo.dgmMetaMethods = metaMethods;
        classInfo.newMetaMethods = metaMethods;
    }
    else
        classInfo.newMetaMethods = classInfo.dgmMetaMethods;
}
项目:groovy    文件:MetaMethodIndex.java   
private static boolean isNonRealMethod(MetaMethod method) {
    return method instanceof NewInstanceMetaMethod ||
            method instanceof NewStaticMetaMethod ||
            method instanceof ClosureMetaMethod ||
            method instanceof GeneratedMetaMethod ||
            method instanceof ClosureStaticMetaMethod ||
            method instanceof MixinInstanceMetaMethod ||
            method instanceof ClosureMetaMethod.AnonymousMetaMethod;
}
项目:groovy    文件:CachedClass.java   
private void updateAddNewMopMethods(List<MetaMethod> arr) {
    List<MetaMethod> res = new ArrayList<MetaMethod>();
    res.addAll(Arrays.asList(classInfo.newMetaMethods));
    res.addAll(arr);
    classInfo.newMetaMethods = res.toArray(new MetaMethod[res.size()]);
    Class theClass = classInfo.getCachedClass().getTheClass();
    if (theClass==Closure.class || theClass==Class.class) {
        ClosureMetaClass.resetCachedMetaClasses();
    }
}
项目:groovy    文件:GeneratedMetaMethod.java   
private void createProxy() {
    try {
        Class<?> aClass = getClass().getClassLoader().loadClass(className.replace('/', '.'));
        Constructor<?> constructor = aClass.getConstructor(String.class, CachedClass.class, Class.class, Class[].class);
        proxy = (MetaMethod) constructor.newInstance(getName(), getDeclaringClass(), getReturnType(), getNativeParameterTypes());
    } catch (Throwable t) {
        t.printStackTrace();
        throw new GroovyRuntimeException("Failed to create DGM method proxy : " + t, t);
    }
}
项目:groovy    文件:ClassLoaderForClassArtifacts.java   
public Constructor defineClassAndGetConstructor(final String name, final byte[] bytes) {
    final Class cls = AccessController.doPrivileged( new PrivilegedAction<Class>(){
        public Class run() {
            return define(name, bytes);
        }
    });

    if (cls != null) {
        try {
            return cls.getConstructor(CallSite.class, MetaClassImpl.class, MetaMethod.class, Class[].class, Constructor.class);
        } catch (NoSuchMethodException e) { //
        }
    }
    return null;
}
项目:groovy    文件:PojoMetaMethodSite.java   
public static CallSite createPojoMetaMethodSite(CallSite site, MetaClassImpl metaClass, MetaMethod metaMethod, Class[] params, Object receiver, Object[] args) {
    if (metaMethod instanceof CallSiteAwareMetaMethod) {
        return ((CallSiteAwareMetaMethod)metaMethod).createPojoCallSite(site, metaClass, metaMethod, params, receiver, args);
    }

    if (metaMethod.getClass() == CachedMethod.class)
      return createCachedMethodSite (site, metaClass, (CachedMethod) metaMethod, params, args);

    return createNonAwareCallSite(site, metaClass, metaMethod, params, args);
}
项目:groovy    文件:PogoMetaMethodSite.java   
private static CallSite createNonAwareCallSite(CallSite site, MetaClassImpl metaClass, MetaMethod metaMethod, Class[] params, Object[] args) {
    if (metaMethod.correctArguments(args) == args) {
        if (noWrappers(args)) {
            if (noCoerce(metaMethod,args))
                return new PogoMetaMethodSiteNoUnwrap(site, metaClass, metaMethod, params);
            else {
                return new PogoMetaMethodSiteNoUnwrapNoCoerce(site, metaClass, metaMethod, params);
            }
        }
    }
    return new PogoMetaMethodSite(site, metaClass, metaMethod, params);
}
项目:groovy    文件:MethodClosure.java   
private Class[] makeParameterTypes(Object owner, MetaMethod m) {
    Class[] newParameterTypes;

    if (owner instanceof Class && !m.isStatic()) {
        Class[] nativeParameterTypes = m.getNativeParameterTypes();
        newParameterTypes = new Class[nativeParameterTypes.length + 1];

        System.arraycopy(nativeParameterTypes, 0, newParameterTypes, 1, nativeParameterTypes.length);
        newParameterTypes[0] = (Class) owner;
    } else {
        newParameterTypes = m.getNativeParameterTypes();
    }

    return newParameterTypes;
}
项目:groovy    文件:MetaClassHelper.java   
public static GroovyRuntimeException createExceptionText(String init, MetaMethod method, Object object, Object[] args, Throwable reason, boolean setReason) {
    return new GroovyRuntimeException(
            init
                    + method
                    + " on: "
                    + object
                    + " with arguments: "
                    + InvokerHelper.toString(args)
                    + " reason: "
                    + reason,
            setReason ? reason : null);
}
项目:groovy    文件:Inspector.java   
/**
 * Get info about instance and class Methods that are dynamically added through Groovy.
 *
 * @return Array of StringArrays that can be indexed with the MEMBER_xxx_IDX constants
 */
public Object[] getMetaMethods() {
    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;
}
项目:groovy    文件:MultipleSetterProperty.java   
@Override
public Object getProperty(Object object) {
    MetaMethod getter = getGetter();
    if (getter == null) {
        if (field != null) return field.getProperty(object);
        throw new GroovyRuntimeException("Cannot read write-only property: " + name);
    }
    return getter.invoke(object, MetaClassHelper.EMPTY_ARRAY);
}
项目:groovy    文件:ClosureMetaClass.java   
@Override
public MetaMethod pickMethod(String name, Class[] argTypes) {
    if (argTypes == null) argTypes = MetaClassHelper.EMPTY_CLASS_ARRAY;
    if (name.equals(CLOSURE_CALL_METHOD) || name.equals(CLOSURE_DO_CALL_METHOD)) {
        return pickClosureMethod(argTypes);
    }
    return CLOSURE_METACLASS.getMetaMethod(name, argTypes);
}
项目:groovy    文件:MixinInstanceMetaProperty.java   
private static MetaMethod createSetter(final MetaProperty property, final MixinInMetaClass mixinInMetaClass) {
  return new MetaMethod() {
      final String name = getSetterName(property.getName());
      {
          setParametersTypes (new CachedClass [] {ReflectionCache.getCachedClass(property.getType())} );
      }

      public int getModifiers() {
          return Modifier.PUBLIC;
      }

      public String getName() {
          return name;
      }

      public Class getReturnType() {
          return property.getType();
      }

      public CachedClass getDeclaringClass() {
          return mixinInMetaClass.getInstanceClass();
      }

      public Object invoke(Object object, Object[] arguments) {
          property.setProperty(mixinInMetaClass.getMixinInstance(object), arguments[0]);
          return null;
      }
  };
}
项目:Reer    文件:BeanDynamicObject.java   
@Nullable
protected MetaMethod lookupMethod(MetaClass metaClass, String name, Class[] arguments) {
    return metaClass.getMetaMethod(name, arguments);
}
项目:groovy    文件:MetaClassConstant.java   
public MetaMethod getMethod(String name, Class[] parameters) {
    return impl.pickMethod(name, parameters);
}
项目:groovy    文件:MetaClass.java   
public MetaMethod getMethod(String name, Class[] parameters) {
    return implRef.getPayload().getMethod(name, parameters);
}
项目:groovy    文件:NumberNumberMetaMethod.java   
public NumberNumberCallSite(CallSite site, MetaClassImpl metaClass, MetaMethod metaMethod, Class[] params, Number receiver, Number arg) {
    super(site, metaClass, metaMethod, params);
    math = NumberMath.getMath(receiver,arg);
}
项目:groovy    文件:NumberNumberDiv.java   
public FloatDouble(CallSite site, MetaClassImpl metaClass, MetaMethod metaMethod, Class[] params, Object receiver, Object[] args) {
    super(site, metaClass, metaMethod, params, (Number) receiver, (Number) args[0]);
}
项目:groovy    文件:StaticMethodCallExpression.java   
public void setMetaMethod(MetaMethod metaMethod) {
    this.metaMethod = metaMethod;
}
项目:groovy    文件:StaticMethodCallExpression.java   
public MetaMethod getMetaMethod() {
    return metaMethod;
}
项目:groovy    文件:NumberNumberMultiply.java   
public IntegerDouble(CallSite site, MetaClassImpl metaClass, MetaMethod metaMethod, Class[] params, Object receiver, Object[] args) {
    super(site, metaClass, metaMethod, params, (Number) receiver, (Number) args[0]);
}
项目:groovy    文件:ConstructorMetaMethodSite.java   
public ConstructorMetaMethodSite(CallSite site, MetaClassImpl metaClass, MetaMethod method, Class [] params) {
    super(site, metaClass, method, params);
    this.version = metaClass.getVersion();
}
项目:groovy    文件:StaticMetaMethodSite.java   
public StaticMetaMethodSite(CallSite site, MetaClassImpl metaClass, MetaMethod metaMethod, Class params[]) {
    super(site, metaClass, metaMethod, params);
    version = metaClass.getVersion ();
}
项目:groovy    文件:MetaClassRegistryImpl.java   
private static void refreshMopMethods(final Map<CachedClass, List<MetaMethod>> map) {
    for (Map.Entry<CachedClass, List<MetaMethod>> e : map.entrySet()) {
        CachedClass cls = e.getKey();
        cls.setNewMopMethods(e.getValue());
    }
}
项目:groovy    文件:ClosureMetaClass.java   
@Override
public List<MetaMethod> getMethods() {
    List<MetaMethod> answer = CLOSURE_METACLASS.getMetaMethods();
    answer.addAll(closureMethods.toList());
    return answer;
}
项目:groovy    文件:StaticMetaMethodSite.java   
public StaticMetaMethodSiteNoUnwrapNoCoerce(CallSite site, MetaClassImpl metaClass, MetaMethod metaMethod, Class params[]) {
    super(site, metaClass, metaMethod, params);
}
项目:groovy    文件:OwnedMetaClass.java   
public List<MetaMethod> getMetaMethods() {
    final Object owner = getOwner();
    final MetaClass ownerMetaClass = getOwnerMetaClass(owner);
    return ownerMetaClass.getMetaMethods();
}
项目:groovy    文件:MethodMetaProperty.java   
public MethodMetaProperty(String name, MetaMethod method) {
    super(name, Object.class);
    this.method = method;
}
项目:groovy    文件:PojoMetaMethodSite.java   
public PojoCachedMethodSite(CallSite site, MetaClassImpl metaClass, MetaMethod metaMethod, Class[] params) {
    super(site, metaClass, metaMethod, params);
    reflect = ((CachedMethod)metaMethod).setAccessible();
}
项目:groovy    文件:OwnedMetaClass.java   
public MetaMethod getMetaMethod(String name, Class[] argTypes) {
    final Object owner = getOwner();
    final MetaClass ownerMetaClass = getOwnerMetaClass(owner);
    return ownerMetaClass.getMetaMethod(name, argTypes);
}