home | career | drupal | java | mac | mysql | perl | scala | uml | unix

Groovy example source code file (TestDgmConverter.java)

This example Groovy source code file (TestDgmConverter.java) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Groovy tags/keywords

classnotfoundexception, failed, failed, file, file, illegalaccessexception, instantiationexception, io, metaclassregistryimpl, metaclassregistryimpl, metamethod, object, string, string, testcase

The Groovy TestDgmConverter.java source code

package org.codehaus.groovy.tools;

import groovy.lang.MetaMethod;
import junit.framework.TestCase;
import org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl;

import java.io.File;

public class TestDgmConverter extends TestCase {

    public void testConverter () {
        final File[] files = new File("target/classes/org/codehaus/groovy/runtime").listFiles();
        for (int i = 0; i < files.length; i++) {
            File file = files[i];
            final String name = file.getName();
            if (name.startsWith("dgm$")) {
                System.out.println(name);

                final String className = "org.codehaus.groovy.runtime." + name.substring(0, name.length() - ".class".length());
                try {
                    Class cls = Class.forName(className);
                    final MetaMethod metaMethod = (MetaMethod) cls.newInstance();
                    System.out.println(metaMethod);
                } catch (ClassNotFoundException e) {
                    fail("Failed to load " + className);
                } catch (IllegalAccessException e) {
                    fail("Failed to instantiate " + className);
                } catch (InstantiationException e) {
                    fail("Failed to instantiate " + className);
                }
            }
        }
    }

    public void testRegistry () {
        final MetaClassRegistryImpl metaClassRegistry = new MetaClassRegistryImpl();
        final Object [] instanceMethods = metaClassRegistry.getInstanceMethods().getArray();
        for (int i = 0; i < instanceMethods.length; i++) {
            System.out.println(instanceMethods[i]);

        }
    }
}

Other Groovy examples (source code examples)

Here is a short list of links related to this Groovy TestDgmConverter.java source code file:

new blog posts

 

Copyright 1998-2014 Alvin Alexander, alvinalexander.com
All Rights Reserved.