use of lucee.commons.lang.types.RefIntegerImpl in project Lucee by lucee.
the class Reflector method getConstructorInstance.
public static ConstructorInstance getConstructorInstance(Class clazz, Object[] args, ConstructorInstance defaultValue) {
args = cleanArgs(args);
// getConstructors(clazz);
Constructor[] constructors = cStorage.getConstructors(clazz, args.length);
if (constructors != null) {
Class[] clazzArgs = getClasses(args);
// exact comparsion
outer: for (int i = 0; i < constructors.length; i++) {
if (constructors[i] != null) {
Class[] parameterTypes = constructors[i].getParameterTypes();
for (int y = 0; y < parameterTypes.length; y++) {
if (toReferenceClass(parameterTypes[y]) != clazzArgs[y])
continue outer;
}
return new ConstructorInstance(constructors[i], args);
}
}
// like comparsion
outer: for (int i = 0; i < constructors.length; i++) {
if (constructors[i] != null) {
Class[] parameterTypes = constructors[i].getParameterTypes();
for (int y = 0; y < parameterTypes.length; y++) {
if (!like(clazzArgs[y], toReferenceClass(parameterTypes[y])))
continue outer;
}
return new ConstructorInstance(constructors[i], args);
}
}
// convert comparsion
ConstructorInstance ci = null;
int _rating = 0;
outer: for (int i = 0; i < constructors.length; i++) {
if (constructors[i] != null) {
RefInteger rating = (constructors.length > 1) ? new RefIntegerImpl(0) : null;
Class[] parameterTypes = constructors[i].getParameterTypes();
Object[] newArgs = new Object[args.length];
for (int y = 0; y < parameterTypes.length; y++) {
try {
newArgs[y] = convert(args[y], toReferenceClass(parameterTypes[y]), rating);
} catch (PageException e) {
continue outer;
}
}
if (ci == null || rating.toInt() > _rating) {
if (rating != null)
_rating = rating.toInt();
ci = new ConstructorInstance(constructors[i], newArgs);
}
// return new ConstructorInstance(constructors[i],newArgs);
}
}
return ci;
}
return defaultValue;
// throw new NoSuchMethodException("No matching Constructor for "+clazz.getName()+"("+getDspMethods(getClasses(args))+") found");
}
use of lucee.commons.lang.types.RefIntegerImpl in project Lucee by lucee.
the class MacAddressWrap method getCallerClass.
/**
* @return the class calling me and the first class not in bootdelegation if the the is in bootdelegation
*/
public static Caller getCallerClass() {
final Ref ref = new Ref();
new SecurityManager() {
{
ref.context = getClassContext();
}
};
Caller rtn = new Caller();
// element at position 2 is the caller
Class<?> caller = ref.context[2];
RefInteger index = new RefIntegerImpl(3);
Class<?> clazz = _getCallerClass(ref.context, caller, index, true, true);
// analyze the first result
if (clazz == null)
return rtn;
if (isFromBundle(clazz)) {
rtn.fromBundle = clazz;
return rtn;
}
if (!OSGiUtil.isClassInBootelegation(clazz.getName())) {
rtn.fromSystem = clazz;
} else {
rtn.fromBootDelegation = clazz;
}
clazz = null;
if (rtn.fromBootDelegation != null) {
index = new RefIntegerImpl(3);
clazz = _getCallerClass(ref.context, caller, index, false, true);
if (clazz == null)
return rtn;
if (isFromBundle(clazz)) {
rtn.fromBundle = clazz;
return rtn;
} else
rtn.fromSystem = clazz;
}
clazz = _getCallerClass(ref.context, caller, index, false, false);
if (clazz == null)
return rtn;
rtn.fromBundle = clazz;
return rtn;
}
use of lucee.commons.lang.types.RefIntegerImpl in project Lucee by lucee.
the class Reflector method getMethodInstanceEL.
/**
* gets the MethodInstance matching given Parameter
* @param objMaybeNull maybe null
* @param clazz Class Of the Method to get
* @param methodName Name of the Method to get
* @param args Arguments of the Method to get
* @return return Matching Method
* @throws
*/
public static MethodInstance getMethodInstanceEL(Object objMaybeNull, Class clazz, Collection.Key methodName, Object[] args) {
checkAccessibility(objMaybeNull, clazz, methodName);
args = cleanArgs(args);
// getDeclaredMethods(clazz);
Method[] methods = mStorage.getMethods(clazz, methodName, args.length);
if (methods != null) {
Class[] clazzArgs = getClasses(args);
// print.e("exact:"+methodName);
outer: for (int i = 0; i < methods.length; i++) {
if (methods[i] != null) {
Class[] parameterTypes = methods[i].getParameterTypes();
for (int y = 0; y < parameterTypes.length; y++) {
if (toReferenceClass(parameterTypes[y]) != clazzArgs[y])
continue outer;
}
return new MethodInstance(methods[i], args);
}
}
// print.e("like:"+methodName);
outer: for (int i = 0; i < methods.length; i++) {
if (methods[i] != null) {
Class[] parameterTypes = methods[i].getParameterTypes();
for (int y = 0; y < parameterTypes.length; y++) {
if (!like(clazzArgs[y], toReferenceClass(parameterTypes[y])))
continue outer;
}
return new MethodInstance(methods[i], args);
}
}
// convert comparsion
// print.e("convert:"+methodName);
MethodInstance mi = null;
int _rating = 0;
outer: for (int i = 0; i < methods.length; i++) {
if (methods[i] != null) {
RefInteger rating = (methods.length > 1) ? new RefIntegerImpl(0) : null;
Class[] parameterTypes = methods[i].getParameterTypes();
Object[] newArgs = new Object[args.length];
for (int y = 0; y < parameterTypes.length; y++) {
try {
newArgs[y] = convert(args[y], toReferenceClass(parameterTypes[y]), rating);
} catch (PageException e) {
continue outer;
}
}
if (mi == null || rating.toInt() > _rating) {
if (rating != null)
_rating = rating.toInt();
mi = new MethodInstance(methods[i], newArgs);
}
// return new MethodInstance(methods[i],newArgs);
}
}
return mi;
}
return null;
}
use of lucee.commons.lang.types.RefIntegerImpl in project Lucee by lucee.
the class VT method _writeOutCallerUtil.
private Type _writeOutCallerUtil(BytecodeContext bc, int mode) throws TransformerException {
GeneratorAdapter adapter = bc.getAdapter();
final int count = countFM + countDM;
// count 0
if (count == 0)
return _writeOutEmpty(bc);
// pc
adapter.loadArg(0);
// collection
RefInteger startIndex = new RefIntegerImpl();
_writeOutFirst(bc, (members.get(0)), mode, count == 1, true, defaultValue, startIndex);
// keys
Iterator<Member> it = members.iterator();
ArrayVisitor av = new ArrayVisitor();
av.visitBegin(adapter, Types.COLLECTION_KEY, countDM - startIndex.toInt());
int index = 0, i = 0;
while (it.hasNext()) {
DataMember member = (DataMember) it.next();
if (i++ < startIndex.toInt())
continue;
av.visitBeginItem(adapter, index++);
getFactory().registerKey(bc, member.getName(), false);
av.visitEndItem(bc.getAdapter());
}
av.visitEnd();
// defaultValue
defaultValue.writeOut(bc, MODE_REF);
bc.getAdapter().invokeStatic(Types.CALLER_UTIL, CALLER_UTIL_GET);
return Types.OBJECT;
}
Aggregations