本文整理汇总了Java中groovy.lang.MetaMethod类的典型用法代码示例。如果您正苦于以下问题:Java MetaMethod类的具体用法?Java MetaMethod怎么用?Java MetaMethod使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MetaMethod类属于groovy.lang包,在下文中一共展示了MetaMethod类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findPropertyMissingMethod
import groovy.lang.MetaMethod; //导入依赖的package包/类
@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;
}
示例2: callControllerAwareMethod
import groovy.lang.MetaMethod; //导入依赖的package包/类
/**
* 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;
}
}
}
}
示例3: checkIfStdMethod
import groovy.lang.MetaMethod; //导入依赖的package包/类
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());
}
}
示例4: lookupMethod
import groovy.lang.MetaMethod; //导入依赖的package包/类
@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;
}
示例5: doInvokeFunction
import groovy.lang.MetaMethod; //导入依赖的package包/类
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;
}
示例6: newModule
import groovy.lang.MetaMethod; //导入依赖的package包/类
@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;
}
示例7: createMetaMethods
import groovy.lang.MetaMethod; //导入依赖的package包/类
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));
}
}
}
示例8: addFunctionClosureMethods
import groovy.lang.MetaMethod; //导入依赖的package包/类
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);
}
}
示例9: methodMissing
import groovy.lang.MetaMethod; //导入依赖的package包/类
@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;
}
示例10: adjustParamTypesForStdMethods
import groovy.lang.MetaMethod; //导入依赖的package包/类
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;
}
示例11: updateSetNewMopMethods
import groovy.lang.MetaMethod; //导入依赖的package包/类
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;
}
示例12: isNonRealMethod
import groovy.lang.MetaMethod; //导入依赖的package包/类
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;
}
示例13: updateAddNewMopMethods
import groovy.lang.MetaMethod; //导入依赖的package包/类
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();
}
}
示例14: createProxy
import groovy.lang.MetaMethod; //导入依赖的package包/类
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);
}
}
示例15: defineClassAndGetConstructor
import groovy.lang.MetaMethod; //导入依赖的package包/类
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;
}