Package groovy.lang

Examples of groovy.lang.MetaClass


  public static void main(final String[] args) throws InstantiationException, Exception {
    Binding binding = new Binding();
    binding.setVariable("foo", new Integer(2));
    GroovyShell shell = new GroovyShell(binding);
    Script script = shell.parse("service.with{sru()} ;x = 123; return foo * 10;");
    MetaClass metaClass = script.getMetaClass();
    Binding binding2 = script.getBinding();
    // Object property = script.getProperty("service");
    script.setProperty("service", new CustomerService() {

      @Override
View Full Code Here


    Binding binding = new Binding();
    binding.setVariable("foo", new Integer(2));
    GroovyShell shell = new GroovyShell(binding);
    long start = System.currentTimeMillis();
    Script script = shell.parse("x = 123; return foo * 10");
    MetaClass metaClass = script.getMetaClass();
    Binding binding2 = script.getBinding();
    for (int i = 0; i < 1000; i++) {
      script.run();
    }
    long end = System.currentTimeMillis() - start;
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

            Stream.of(scriptClass.getMethods()).forEach(m -> {
                final String name = m.getName();
                globalClosures.put(name, new MethodClosure(scriptObject, name));
            });

            final MetaClass oldMetaClass = scriptObject.getMetaClass();
            scriptObject.setMetaClass(new DelegatingMetaClass(oldMetaClass) {
                @Override
                public Object invokeMethod(Object object, String name, Object args) {
                    if (args == null) {
                        return invokeMethod(object, name, MetaClassHelper.EMPTY_ARRAY);
View Full Code Here

   * @see #invokeMethod(Class, Object, String, Object[], boolean, boolean)
   */
  public BuilderClosureMetaClass(Closure closure, Object out) {
    super(closure.getMetaClass());
    this.out = out;
    MetaClass mc = InvokerHelper.getMetaClass(out);
    print = mc.getMetaMethod("print", new Class[] { Object.class });
    println = mc.getMetaMethod("println", new Class[] { Object.class });
  }
View Full Code Here

  public Class getExpectedType () {
    if (expectedType != null) return expectedType;
    if (parent == null) return expectedType = Object.class;
    Object p = this.parent.get();
    if (p == null) return Object.class;
    MetaClass mc = InvokerHelper.getMetaClass(p);
    MetaProperty mp = mc.getMetaProperty(name);
    return expectedType = (mp == null ? Object.class : mp.getType());
//    try {
//      return expectedType = p.getClass().getField(name).getType();
//    } catch (NoSuchFieldException e) {
//      try {
View Full Code Here

  public void alias (String name, Class type) {
    this.aliases.put(name, type);
  }

  public T instantiateNode (B builder, ObjectFactoryInterceptor ofi, String nodeName, T parent) {
    MetaClass mc = ofi.getMetaClassForNode(nodeName);
   
    if (mc == null) {
      if (this.aliases.containsKey(nodeName)) {
        ofi.setMetaClassForNode(nodeName, InvokerHelper.getMetaClass(this.aliases.get(nodeName)));
      } else {
        String newNodeName = nodeName.substring(0, 1).toUpperCase() + nodeName.substring(1);
        for (String pkg : this.pkgs) {
          try {
            Class clazz = Class.forName(pkg + "." + newNodeName, false, Thread.currentThread().getContextClassLoader());
            ofi.setMetaClassForNode(nodeName, mc = InvokerHelper.getMetaClass(clazz));
            break;
          } catch (ClassNotFoundException e) {}
        }
        if (mc == null) ofi.setMetaClassForNode(nodeName, null);
      }
    }
   
    return (T) (mc == null ? null : mc.invokeConstructor(parent == null || !ofi.isPassParentToConstructor() ? EMPTY_ARRAY : new Object[] { parent }));
  }
View Full Code Here

  public Object invokeGraceletDSLMethod(Object instance, String methodName, Object[] arguments, MissingMethodException me) {
    if (manager == null) manager = GroovyDSLContext.getManager();
    if (manager == null) throw me;
   
    GroovyDSLMethod method = null;
    MetaClass mc = this;
    while (true) {
      method = manager.findMethod(mc, instance, methodName, arguments);
      if (method != null) break;
      else if (mc.getTheClass() != Object.class) mc = GroovySystem.getMetaClassRegistry().getMetaClass(mc.getTheClass().getSuperclass());
      else break;
    }
    if (method == null) {
      try {
        Binding dsl = GroovyDSLBinding.getInstance();
View Full Code Here

    } catch (MissingPropertyException e) {
      if (manager == null) manager = GroovyDSLContext.getManager();
      if (manager == null) throw e;

      GroovyDSLProperty property = null;
      MetaClass mc = this;
      while (true) {
        property = manager.findProperty(mc, instance, propertyName);
        if (property != null) break;
        else if (mc.getTheClass() != Object.class) mc = GroovySystem.getMetaClassRegistry().getMetaClass(mc.getTheClass().getSuperclass());
        else break;
      }
     
      if (property == null) {
        try {
View Full Code Here

   *
   * @see ObjectFactoryInterceptor#isPassParentToConstructor()
   */
  public void associate(GroovyBuilder builder, ObjectFactoryInterceptor ofi, Object child, Object parent) {
    if (parent != null) {
      MetaClass pmc = InvokerHelper.getMetaClass(child.getClass());
      pmc.invokeMethod(parent, "addChild", new Object[] { parent });
    }
   
    MetaClass cmc = InvokerHelper.getMetaClass(child.getClass());
    cmc.invokeMethod(child, "setParent", new Object[] { parent });
  }
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.