• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java MetaClass类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中groovy.lang.MetaClass的典型用法代码示例。如果您正苦于以下问题:Java MetaClass类的具体用法?Java MetaClass怎么用?Java MetaClass使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



MetaClass类属于groovy.lang包,在下文中一共展示了MetaClass类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: findPropertyMissingMethod

import groovy.lang.MetaClass; //导入依赖的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;
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:20,代码来源:BeanDynamicObject.java


示例2: addListeners

import groovy.lang.MetaClass; //导入依赖的package包/类
/**
 * Add listeners to a specific object.  Updates the bould flags and update set
 *
 * @param listener This listener to attach.
 * @param newObject The object we should read our property off of.
 * @param updateSet The list of objects we have added listeners to
 */
public void addListeners(PropertyChangeListener listener, Object newObject, Set updateSet) {
    removeListeners();
    if (newObject != null) {
        // check for local synthetics
        TriggerBinding syntheticTrigger = getSyntheticTriggerBinding(newObject);
        MetaClass mc = InvokerHelper.getMetaClass(newObject);
        if (syntheticTrigger != null) {
            PropertyBinding psb = new PropertyBinding(newObject, propertyName);
            PropertyChangeProxyTargetBinding proxytb = new PropertyChangeProxyTargetBinding(newObject, propertyName, listener);

            syntheticFullBinding = syntheticTrigger.createBinding(psb, proxytb);
            syntheticFullBinding.bind();
            updateSet.add(newObject);
        } else if (!mc.respondsTo(newObject, "addPropertyChangeListener", NAME_PARAMS).isEmpty()) {
            InvokerHelper.invokeMethod(newObject, "addPropertyChangeListener", new Object[] {propertyName, listener});
            localListener = listener;
            updateSet.add(newObject);
        } else if (!mc.respondsTo(newObject, "addPropertyChangeListener", GLOBAL_PARAMS).isEmpty()) {
            InvokerHelper.invokeMethod(newObject, "addPropertyChangeListener", listener);
            globalListener = listener;
            updateSet.add(newObject);
        }
    }
    currentObject = newObject;
}
 
开发者ID:apache,项目名称:groovy,代码行数:33,代码来源:BindPath.java


示例3: staticMethod

import groovy.lang.MetaClass; //导入依赖的package包/类
private static void staticMethod(final MetaClass self, List<MetaMethod> arr, final CachedMethod method) {
    CachedClass[] paramTypes = method.getParameterTypes();

    if (paramTypes.length == 0)
        return;

    NewInstanceMetaMethod metaMethod;
    if (paramTypes[0].isAssignableFrom(self.getTheClass())) {
        if (paramTypes[0].getTheClass() == self.getTheClass())
            metaMethod = new NewInstanceMetaMethod(method);
        else
            metaMethod = new NewInstanceMetaMethod(method) {
                public CachedClass getDeclaringClass() {
                    return ReflectionCache.getCachedClass(self.getTheClass());
                }
            };
        arr.add(metaMethod);
    } else {
        if (self.getTheClass().isAssignableFrom(paramTypes[0].getTheClass())) {
            metaMethod = new NewInstanceMetaMethod(method);
            arr.add(metaMethod);
        }
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:25,代码来源:MixinInMetaClass.java


示例4: setNewMopMethods

import groovy.lang.MetaClass; //导入依赖的package包/类
public void setNewMopMethods(List<MetaMethod> arr) {
    final MetaClass metaClass = classInfo.getStrongMetaClass();
    if (metaClass != null) {
      if (metaClass.getClass() == MetaClassImpl.class) {
          classInfo.setStrongMetaClass(null);
          updateSetNewMopMethods(arr);
          classInfo.setStrongMetaClass(new MetaClassImpl(metaClass.getTheClass()));
          return;
      }

      if (metaClass.getClass() == ExpandoMetaClass.class) {
          classInfo.setStrongMetaClass(null);
          updateSetNewMopMethods(arr);
          ExpandoMetaClass newEmc = new ExpandoMetaClass(metaClass.getTheClass());
          newEmc.initialize();
          classInfo.setStrongMetaClass(newEmc);
          return;
      }

      throw new GroovyRuntimeException("Can't add methods to class " + getTheClass().getName() + ". Strong custom meta class already set.");
    }

    classInfo.setWeakMetaClass(null);
    updateSetNewMopMethods(arr);
}
 
开发者ID:apache,项目名称:groovy,代码行数:26,代码来源:CachedClass.java


示例5: getMetaClassUnderLock

import groovy.lang.MetaClass; //导入依赖的package包/类
private MetaClass getMetaClassUnderLock() {
    MetaClass answer = getStrongMetaClass();
    if (answer!=null) return answer;
    
    answer = getWeakMetaClass();
    final MetaClassRegistry metaClassRegistry = GroovySystem.getMetaClassRegistry();
    MetaClassRegistry.MetaClassCreationHandle mccHandle = metaClassRegistry.getMetaClassCreationHandler();
    
    if (isValidWeakMetaClass(answer, mccHandle)) {
        return answer;
    }

    answer = mccHandle.create(classRef.get(), metaClassRegistry);
    answer.initialize();

    if (GroovySystem.isKeepJavaMetaClasses()) {
        setStrongMetaClass(answer);
    } else {
        setWeakMetaClass(answer);
    }
    return answer;
}
 
开发者ID:apache,项目名称:groovy,代码行数:23,代码来源:ClassInfo.java


示例6: createPojoMetaClassGetPropertySite

import groovy.lang.MetaClass; //导入依赖的package包/类
private CallSite createPojoMetaClassGetPropertySite(Object receiver) {
    final MetaClass metaClass = InvokerHelper.getMetaClass(receiver);

    CallSite site;
    if (metaClass.getClass() != MetaClassImpl.class || GroovyCategorySupport.hasCategoryInCurrentThread()) {
        site = new PojoMetaClassGetPropertySite(this);
    } else {
        final MetaProperty effective = ((MetaClassImpl) metaClass).getEffectiveGetMetaProperty(receiver.getClass(), receiver, name, false);
        if (effective != null) {
            if (effective instanceof CachedField)
                site = new GetEffectivePojoFieldSite(this, (MetaClassImpl) metaClass, (CachedField) effective);
            else
                site = new GetEffectivePojoPropertySite(this, (MetaClassImpl) metaClass, effective);
        } else {
            site = new PojoMetaClassGetPropertySite(this);
        }
    }

    array.array[index] = site;
    return site;
}
 
开发者ID:apache,项目名称:groovy,代码行数:22,代码来源:AbstractCallSite.java


示例7: createPogoMetaClassGetPropertySite

import groovy.lang.MetaClass; //导入依赖的package包/类
private CallSite createPogoMetaClassGetPropertySite(GroovyObject receiver) {
    MetaClass metaClass = receiver.getMetaClass();

    CallSite site;
    if (metaClass.getClass() != MetaClassImpl.class || GroovyCategorySupport.hasCategoryInCurrentThread()) {
        site = new PogoMetaClassGetPropertySite(this, metaClass);
    } else {
        final MetaProperty effective = ((MetaClassImpl) metaClass).getEffectiveGetMetaProperty(this.array.owner, receiver, name, false);
        if (effective != null) {
            if (effective instanceof CachedField)
                site = new GetEffectivePogoFieldSite(this, metaClass, (CachedField) effective);
            else
                site = new GetEffectivePogoPropertySite(this, metaClass, effective);
        } else {
            site = new PogoMetaClassGetPropertySite(this, metaClass);
        }
    }

    array.array[index] = site;
    return site;
}
 
开发者ID:apache,项目名称:groovy,代码行数:22,代码来源:AbstractCallSite.java


示例8: createCallStaticSite

import groovy.lang.MetaClass; //导入依赖的package包/类
private static CallSite createCallStaticSite(CallSite callSite, final Class receiver, Object[] args) {
    CallSite site;
    AccessController.doPrivileged(new PrivilegedAction<Void>() {
        public Void run() {
            try {
                Class.forName(receiver.getName(), true, receiver.getClassLoader());
            } catch (Exception e) {
                // force <clinit>
            }
            return null;
        }
    });
    MetaClass metaClass = InvokerHelper.getMetaClass(receiver);
    if (metaClass instanceof MetaClassImpl) {
        site = ((MetaClassImpl)metaClass).createStaticSite(callSite, args);
    }
    else
      site = new StaticMetaClassSite(callSite, metaClass);

    replaceCallSite(callSite, site);
    return site;
}
 
开发者ID:apache,项目名称:groovy,代码行数:23,代码来源:CallSiteArray.java


示例9: createCallCurrentSite

import groovy.lang.MetaClass; //导入依赖的package包/类
private static CallSite createCallCurrentSite(CallSite callSite, GroovyObject receiver, Object[] args, Class sender) {
    CallSite site;
    if (receiver instanceof GroovyInterceptable)
      site = new PogoInterceptableSite(callSite);
    else {
        MetaClass metaClass = receiver.getMetaClass();
        if (receiver.getClass() != metaClass.getTheClass() && !metaClass.getTheClass().isInterface()) {
            site = new PogoInterceptableSite(callSite);
        }
        else
            if (metaClass instanceof MetaClassImpl) {
                site = ((MetaClassImpl)metaClass).createPogoCallCurrentSite(callSite, sender, args);
            }
            else
              site = new PogoMetaClassSite(callSite, metaClass);
    }

    replaceCallSite(callSite, site);
    return site;
}
 
开发者ID:apache,项目名称:groovy,代码行数:21,代码来源:CallSiteArray.java


示例10: setMetaClass

import groovy.lang.MetaClass; //导入依赖的package包/类
/**
 * Sets the metaclass for a given class.
 *
 * @param self the class whose metaclass we wish to set
 * @param metaClass the new MetaClass
 * @since 1.6.0
 */
public static void setMetaClass(Class self, MetaClass metaClass) {
    final MetaClassRegistry metaClassRegistry = GroovySystem.getMetaClassRegistry();
    if (metaClass == null)
        metaClassRegistry.removeMetaClass(self);
    else {
        if (metaClass instanceof HandleMetaClass) {
            metaClassRegistry.setMetaClass(self, ((HandleMetaClass)metaClass).getAdaptee());
        } else {
            metaClassRegistry.setMetaClass(self, metaClass);
        }
        if (self==NullObject.class) {
            NullObject.getNullObject().setMetaClass(metaClass);
        }
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:23,代码来源:DefaultGroovyMethods.java


示例11: hasPerInstanceMetaClass

import groovy.lang.MetaClass; //导入依赖的package包/类
private static MetaClass hasPerInstanceMetaClass(Object object) {
    if (object instanceof GroovyObject) {
        MetaClass mc = ((GroovyObject)object).getMetaClass();
        if (mc == GroovySystem.getMetaClassRegistry().getMetaClass(object.getClass()) || mc.getClass() == MetaClassImpl.class)
            return null;
        else
            return mc;
    }
    else {
        ClassInfo info = ClassInfo.getClassInfo(object.getClass());
        info.lock();
        try {
            return info.getPerInstanceMetaClass(object);
        }
        finally {
            info.unlock();
        }
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:20,代码来源:DefaultGroovyMethods.java


示例12: build

import groovy.lang.MetaClass; //导入依赖的package包/类
public Object build(Script script) {
    // this used to be synchronized, but we also used to remove the
    // metaclass.  Since adding the metaclass is now a side effect, we
    // don't need to ensure the meta-class won't be observed and don't
    // need to hide the side effect.
    MetaClass scriptMetaClass = script.getMetaClass();
    script.setMetaClass(new FactoryInterceptorMetaClass(scriptMetaClass, this));
    script.setBinding(this);
    Object oldScriptName = getProxyBuilder().getVariables().get(SCRIPT_CLASS_NAME);
    try {
        getProxyBuilder().setVariable(SCRIPT_CLASS_NAME, script.getClass().getName());
        return script.run();
    } finally {
        if(oldScriptName != null) {
            getProxyBuilder().setVariable(SCRIPT_CLASS_NAME, oldScriptName);
        } else {
            getProxyBuilder().getVariables().remove(SCRIPT_CLASS_NAME);
        }
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:21,代码来源:FactoryBuilderSupport.java


示例13: setProperty

import groovy.lang.MetaClass; //导入依赖的package包/类
public void setProperty(String property, Object newValue) {
    if ("metaClass".equals(property)) {
        setMetaClass((MetaClass) newValue);
    } else if ("scriptTarget".equals(property)) {
        setScriptTarget(newValue);
    } else {
        getDynamicTarget().setProperty(property, newValue);
    }
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:10,代码来源:BasicScript.java


示例14: getMetaClass

import groovy.lang.MetaClass; //导入依赖的package包/类
private MetaClass getMetaClass() {
    if (bean instanceof GroovyObject) {
        return ((GroovyObject) bean).getMetaClass();
    } else {
        return GroovySystem.getMetaClassRegistry().getMetaClass(bean.getClass());
    }
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:8,代码来源:BeanDynamicObject.java


示例15: lookupProperty

import groovy.lang.MetaClass; //导入依赖的package包/类
@Nullable
protected MetaProperty lookupProperty(MetaClass metaClass, String name) {
    if (metaClass instanceof MetaClassImpl) {
        // MetaClass.getMetaProperty(name) is very expensive when the property is not known. Instead, reach into the meta class to call a much more efficient lookup method
        try {
            return (MetaProperty) META_PROP_METHOD.invoke(metaClass, name, false);
        } catch (Throwable e) {
            throw UncheckedException.throwAsUncheckedException(e);
        }
    }

    // Some other meta-class implementation - fall back to the public API
    return metaClass.getMetaProperty(name);
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:15,代码来源:BeanDynamicObject.java


示例16: lookupMethod

import groovy.lang.MetaClass; //导入依赖的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;
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:14,代码来源:BeanDynamicObject.java


示例17: updateConstantMetaClass

import groovy.lang.MetaClass; //导入依赖的package包/类
public void updateConstantMetaClass(final MetaClassRegistryChangeEvent cmcu) {
	log.info("!! updateConstantMetaClass: {}", cmcu);
    if (!cleaning) {
        MetaClass oldMetaClass = cmcu.getOldMetaClass();
        Class classToUpdate = cmcu.getClassToUpdate();
        Object instanceToUpdate = cmcu.getInstance();
        if (instanceToUpdate == null && (cmcu.getNewMetaClass() instanceof ExpandoMetaClass)) {
            updateMetaClassOfClass(oldMetaClass, classToUpdate);
        } else if (instanceToUpdate != null) {
            updateMetaClassOfInstance(oldMetaClass, instanceToUpdate);
        }
    }
}
 
开发者ID:nickman,项目名称:HeliosStreams,代码行数:14,代码来源:MetaClassRegistryCleaner.java


示例18: updateMetaClassOfInstance

import groovy.lang.MetaClass; //导入依赖的package包/类
private void updateMetaClassOfInstance(MetaClass oldMetaClass, Object instanceToUpdate) {
    IdentityWeakReference key = new IdentityWeakReference(instanceToUpdate);
    if (oldMetaClass != null) {
        Object current = alteredInstances.get(key);
        if (current == null || current == NO_CUSTOM_METACLASS) {
            alteredInstances.put(key, oldMetaClass);
        }
    } else {
        alteredInstances.put(key, NO_CUSTOM_METACLASS);
    }
}
 
开发者ID:nickman,项目名称:HeliosStreams,代码行数:12,代码来源:MetaClassRegistryCleaner.java


示例19: updateMetaClassOfClass

import groovy.lang.MetaClass; //导入依赖的package包/类
private void updateMetaClassOfClass(MetaClass oldMetaClass, Class classToUpdate) {
    if (oldMetaClass != null && !(oldMetaClass instanceof MockProxyMetaClass)) {
        Object current = alteredClasses.get(classToUpdate);
        if (current == null ) {
            alteredClasses.put(classToUpdate, oldMetaClass);
        }
    }
    else {
        alteredClasses.put(classToUpdate, NO_CUSTOM_METACLASS);
    }
}
 
开发者ID:nickman,项目名称:HeliosStreams,代码行数:12,代码来源:MetaClassRegistryCleaner.java


示例20: cleanMetaClassOfInstance

import groovy.lang.MetaClass; //导入依赖的package包/类
private void cleanMetaClassOfInstance(MetaClassRegistryImpl registry) {
    List<IdentityWeakReference> keys = new ArrayList<IdentityWeakReference>(alteredInstances.keySet());
    for (IdentityWeakReference key : keys) {
        Object instance = key.get();
        if (instance != null) {
            Object alteredMetaClass = alteredInstances.get(key);
            if (alteredMetaClass == NO_CUSTOM_METACLASS) {
                alteredMetaClass = null;
            }
            registry.setMetaClass(instance, (MetaClass) alteredMetaClass);
        }
    }
    alteredInstances.clear();
}
 
开发者ID:nickman,项目名称:HeliosStreams,代码行数:15,代码来源:MetaClassRegistryCleaner.java



注:本文中的groovy.lang.MetaClass类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java HttpCallerInfo类代码示例发布时间:2022-05-21
下一篇:
Java FakeRequest类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap