Search in sources :

Example 1 with MetaClassConstructorSite

use of org.codehaus.groovy.runtime.callsite.MetaClassConstructorSite in project groovy by apache.

the class MetaClassImpl method createConstructorSite.

/**
     * Create a CallSite
     */
public CallSite createConstructorSite(CallSite site, Object[] args) {
    if (!(this instanceof AdaptingMetaClass)) {
        Class[] params = MetaClassHelper.convertToTypeArray(args);
        CachedConstructor constructor = (CachedConstructor) chooseMethod("<init>", constructors, params);
        if (constructor != null) {
            return ConstructorSite.createConstructorSite(site, this, constructor, params, args);
        } else {
            if (args.length == 1 && args[0] instanceof Map) {
                constructor = (CachedConstructor) chooseMethod("<init>", constructors, MetaClassHelper.EMPTY_TYPE_ARRAY);
                if (constructor != null) {
                    return new ConstructorSite.NoParamSite(site, this, constructor, params);
                }
            } else if (args.length == 2 && theClass.getEnclosingClass() != null && args[1] instanceof Map) {
                Class enclosingClass = theClass.getEnclosingClass();
                String enclosingInstanceParamType = args[0] != null ? args[0].getClass().getName() : "";
                if (enclosingClass.getName().equals(enclosingInstanceParamType)) {
                    constructor = (CachedConstructor) chooseMethod("<init>", constructors, new Class[] { enclosingClass });
                    if (constructor != null) {
                        return new ConstructorSite.NoParamSiteInnerClass(site, this, constructor, params);
                    }
                }
            }
        }
    }
    return new MetaClassConstructorSite(site, this);
}
Also used : MetaClassConstructorSite(org.codehaus.groovy.runtime.callsite.MetaClassConstructorSite) CachedConstructor(org.codehaus.groovy.reflection.CachedConstructor) CachedClass(org.codehaus.groovy.reflection.CachedClass) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) SingleKeyHashMap(org.codehaus.groovy.util.SingleKeyHashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) ComplexKeyHashMap(org.codehaus.groovy.util.ComplexKeyHashMap) ConstructorSite(org.codehaus.groovy.runtime.callsite.ConstructorSite) MetaClassConstructorSite(org.codehaus.groovy.runtime.callsite.MetaClassConstructorSite)

Example 2 with MetaClassConstructorSite

use of org.codehaus.groovy.runtime.callsite.MetaClassConstructorSite in project groovy-core by groovy.

the class MetaClassImpl method createConstructorSite.

/**
     * Create a CallSite
     */
public CallSite createConstructorSite(CallSite site, Object[] args) {
    if (!(this instanceof AdaptingMetaClass)) {
        Class[] params = MetaClassHelper.convertToTypeArray(args);
        CachedConstructor constructor = (CachedConstructor) chooseMethod("<init>", constructors, params);
        if (constructor != null) {
            return ConstructorSite.createConstructorSite(site, this, constructor, params, args);
        } else {
            if (args.length == 1 && args[0] instanceof Map) {
                constructor = (CachedConstructor) chooseMethod("<init>", constructors, MetaClassHelper.EMPTY_TYPE_ARRAY);
                if (constructor != null) {
                    return new ConstructorSite.NoParamSite(site, this, constructor, params);
                }
            } else if (args.length == 2 && theClass.getEnclosingClass() != null && args[1] instanceof Map) {
                Class enclosingClass = theClass.getEnclosingClass();
                String enclosingInstanceParamType = args[0] != null ? args[0].getClass().getName() : "";
                if (enclosingClass.getName().equals(enclosingInstanceParamType)) {
                    constructor = (CachedConstructor) chooseMethod("<init>", constructors, new Class[] { enclosingClass });
                    if (constructor != null) {
                        return new ConstructorSite.NoParamSiteInnerClass(site, this, constructor, params);
                    }
                }
            }
        }
    }
    return new MetaClassConstructorSite(site, this);
}
Also used : MetaClassConstructorSite(org.codehaus.groovy.runtime.callsite.MetaClassConstructorSite) CachedConstructor(org.codehaus.groovy.reflection.CachedConstructor) CachedClass(org.codehaus.groovy.reflection.CachedClass) SingleKeyHashMap(org.codehaus.groovy.util.SingleKeyHashMap) ComplexKeyHashMap(org.codehaus.groovy.util.ComplexKeyHashMap) ConstructorSite(org.codehaus.groovy.runtime.callsite.ConstructorSite) MetaClassConstructorSite(org.codehaus.groovy.runtime.callsite.MetaClassConstructorSite)

Aggregations

CachedClass (org.codehaus.groovy.reflection.CachedClass)2 CachedConstructor (org.codehaus.groovy.reflection.CachedConstructor)2 ConstructorSite (org.codehaus.groovy.runtime.callsite.ConstructorSite)2 MetaClassConstructorSite (org.codehaus.groovy.runtime.callsite.MetaClassConstructorSite)2 ComplexKeyHashMap (org.codehaus.groovy.util.ComplexKeyHashMap)2 SingleKeyHashMap (org.codehaus.groovy.util.SingleKeyHashMap)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1