Search in sources :

Example 1 with NativeObject

use of org.develnext.jphp.ext.pna.classes.NativeObject in project jphp by jphp-compiler.

the class NativeClassEntity method newObject.

@Override
public <T extends IObject> T newObject(Environment env, TraceInfo trace, boolean doConstruct, Memory... args) throws Throwable {
    Object instance = null;
    for (Constructor<?> construct : rawClass.getConstructors()) {
        Class<?>[] parameterTypes = construct.getParameterTypes();
        if ((args == null && parameterTypes.length == 0) || (parameterTypes.length == args.length)) {
            Object[] passed = new Object[args == null ? 0 : args.length];
            boolean next = false;
            for (int i = 0; i < passed.length; i++) {
                MemoryOperation op = MemoryOperation.get(parameterTypes[i], construct.getGenericParameterTypes()[i]);
                if (op == null) {
                    next = true;
                    break;
                }
                passed[i] = op.convert(env, trace, args[i]);
            }
            if (next)
                continue;
            try {
                instance = construct.newInstance(passed);
            } catch (InvocationTargetException e) {
                throw e.getCause();
            }
        }
    }
    NativeObject object = (NativeObject) super.newObject(env, trace, doConstruct, args);
    object.__setNativeObject(instance);
    return (T) object;
}
Also used : NativeObject(org.develnext.jphp.ext.pna.classes.NativeObject) NativeObject(org.develnext.jphp.ext.pna.classes.NativeObject) IObject(php.runtime.lang.IObject) MemoryOperation(php.runtime.memory.support.MemoryOperation)

Aggregations

NativeObject (org.develnext.jphp.ext.pna.classes.NativeObject)1 IObject (php.runtime.lang.IObject)1 MemoryOperation (php.runtime.memory.support.MemoryOperation)1