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);
}
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);
}
Aggregations