Package groovy.lang

Examples of groovy.lang.MetaClass


        replaceCallSite(callSite, site);
        return site;
    }

    private static CallSite createCallConstructorSite(CallSite callSite, Class receiver, Object[] args) {
       MetaClass metaClass = InvokerHelper.getMetaClass(receiver);

       CallSite site;
       if (metaClass instanceof MetaClassImpl) {
           site = ((MetaClassImpl)metaClass).createConstructorSite(callSite, args);
       }
View Full Code Here


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

    // for MetaClassImpl we try to pick meta method,
    // otherwise or if method doesn't exist we make call via POJO meta class
    private static CallSite createPojoSite(CallSite callSite, Object receiver, Object[] args) {
        final Class klazz = receiver.getClass();
        MetaClass metaClass = InvokerHelper.getMetaClass(receiver);
        if (!GroovyCategorySupport.hasCategoryInCurrentThread() && metaClass instanceof MetaClassImpl) {
            final MetaClassImpl mci = (MetaClassImpl) metaClass;
            final ClassInfo info = mci.getTheCachedClass().classInfo;
            if (info.hasPerInstanceMetaClasses()) {
                return new PerInstancePojoMetaClassSite(callSite, info);
View Full Code Here

    private static CallSite createPogoSite(CallSite callSite, Object receiver, Object[] args) {
        if (receiver instanceof GroovyInterceptable)
          return new PogoInterceptableSite(callSite);

        MetaClass metaClass = ((GroovyObject)receiver).getMetaClass();

        if (metaClass instanceof MetaClassImpl) {
            return ((MetaClassImpl)metaClass).createPogoCallSite(callSite, args);
        }
View Full Code Here

            excludeParam = file;
        } else if (excludeNameFilter != null) {
            excludeFilterToUse = excludeNameFilter;
            excludeParam = file.getName();
        }
        final MetaClass filterMC = filterToUse == null ? null : InvokerHelper.getMetaClass(filterToUse);
        final MetaClass excludeMC = excludeFilterToUse == null ? null : InvokerHelper.getMetaClass(excludeFilterToUse);
        boolean included = filterToUse == null || DefaultTypeTransformation.castToBoolean(filterMC.invokeMethod(filterToUse, "isCase", filterParam));
        boolean excluded = excludeFilterToUse != null && DefaultTypeTransformation.castToBoolean(excludeMC.invokeMethod(excludeFilterToUse, "isCase", excludeParam));
        return included && !excluded;
    }
View Full Code Here

            this.parent().children().add(child);
        }
    }

    protected static void setMetaClass(final MetaClass metaClass, Class nodeClass) {
        final MetaClass newMetaClass = new DelegatingMetaClass(metaClass) {
            @Override
            public Object getAttribute(final Object object, final String attribute) {
                Node n = (Node) object;
                return n.get("@" + attribute);
            }
View Full Code Here

        final String typeName = field.getClass().getName();
        throw new RuntimeException(createErrorMessage(className, fieldName, typeName, "constructing"));
    }

    public static void checkPropNames(Object instance, Map<String, Object> args) {
        final MetaClass metaClass = InvokerHelper.getMetaClass(instance);
        for (String k : args.keySet()) {
            if (metaClass.hasProperty(instance, k) == null)
                throw new MissingPropertyException(k, instance.getClass());
        }
    }
View Full Code Here

     * @param object - the object to check
     * @param methodName - the name of the method
     * @return true if the object responds to the named method
     */
    public static boolean respondsTo(Object object, String methodName) {
        MetaClass metaClass = DefaultGroovyMethods.getMetaClass(object);
        if (!metaClass.respondsTo(object, methodName).isEmpty()) {
            return true;
        }
        Map properties = DefaultGroovyMethods.getProperties(object);
        return properties.containsKey(methodName);
    }
View Full Code Here

    }
    else if (args.length > 1 && args[args.length -1] instanceof Closure) {
      return invokeBeanDefiningMethod(name, args);
    }
        WebApplicationContext ctx = springConfig.getUnrefreshedApplicationContext();
        MetaClass mc = DefaultGroovyMethods.getMetaClass(ctx);
        if(!mc.respondsTo(ctx, name, args).isEmpty()){
            return mc.invokeMethod(ctx,name, args);
        }
        return this;
  }
View Full Code Here

  public boolean canCreate(IMockConfiguration configuration) {
    return configuration.getImplementation() == MockImplementation.GROOVY;
  }

  public Object create(IMockConfiguration configuration, Specification specification) throws CannotCreateMockException {
    final MetaClass oldMetaClass = GroovyRuntimeUtil.getMetaClass(configuration.getType());
    GroovyMockMetaClass newMetaClass = new GroovyMockMetaClass(configuration, specification, oldMetaClass);
    final Class<?> type = configuration.getType();

    if (configuration.isGlobal()) {
      if (type.isInterface()) {
View Full Code Here

TOP

Related Classes of groovy.lang.MetaClass

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.