All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.rahulsom.svg.GroovyContext.groovy Maven / Gradle / Ivy

The newest version!
package com.github.rahulsom.svg

import groovy.transform.CompileStatic
import groovy.transform.Memoized

import javax.xml.bind.JAXBElement

@CompileStatic
class GroovyContext {
    List things = new ArrayList<>();

    boolean leftShift(Object object) {

        if (object instanceof JAXBElement) {
            things.add(object)
        } else {

            def factory = new ObjectFactory()
            def metaClass = factory.metaClass
            def objectClass = object.class
            MetaMethod method = getMethod(metaClass, objectClass)

            things.add(method.invoke(factory, [object] as Object[]) as JAXBElement)
        }

    }

    @Memoized
    private static MetaMethod getMethod(MetaClass metaClass, Class objectClass) {
        metaClass.methods.find {
            it.returnType == JAXBElement &&
                    it.parameterTypes.length == 1 &&
                    it.parameterTypes[0].isAssignableFrom(objectClass) &&
                    it.parameterTypes[0].name != 'java.lang.Object'
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy