use of php.runtime.lang.IObject in project jphp by jphp-compiler.
the class ClassEntity method cloneObject.
public <T extends IObject> T cloneObject(T value, Environment env, TraceInfo trace) throws Throwable {
IObject copy = this.newObjectWithoutConstruct(env);
ForeachIterator iterator = value.getProperties().foreachIterator(false, false);
ArrayMemory props = copy.getProperties();
while (iterator.next()) {
Object key = iterator.getKey();
if (key instanceof String) {
String name = (String) key;
if (name.indexOf('\0') > -1)
name = name.substring(name.lastIndexOf('\0') + 1);
PropertyEntity entity = properties.get(name);
if (entity != null) {
if (props.getByScalar(entity.getSpecificName()) == null)
props.put(entity.getSpecificName(), iterator.getValue().toImmutable());
} else
props.put(key, iterator.getValue().toImmutable());
} else
props.put(key, iterator.getValue().toImmutable());
}
if (methodMagicClone != null) {
ObjectInvokeHelper.invokeMethod(copy, methodMagicClone, env, trace, null, true);
}
return (T) copy;
}
use of php.runtime.lang.IObject in project jphp by jphp-compiler.
the class ClassEntity method newObject.
public <T extends IObject> T newObject(Environment env, TraceInfo trace, boolean doConstruct, Memory... args) throws Throwable {
if (isAbstract) {
env.error(trace, "Cannot instantiate abstract class %s", name);
} else if (type == Type.INTERFACE) {
env.error(trace, "Cannot instantiate interface %s", name);
} else if (type == Type.TRAIT) {
env.error(trace, "Cannot instantiate trait %s", name);
}
IObject object;
try {
if (nativeConstructor == null) {
env.error(trace, ErrorType.E_CORE_ERROR, "Cannot find a java constructor %s(Environment, ClassEntity)", getName());
}
object = (IObject) nativeConstructor.newInstance(env, this);
} catch (InvocationTargetException e) {
env.__throwException(e);
return null;
}
ArrayMemory props = object.getProperties();
for (PropertyEntity property : getProperties()) {
if (id == property.clazz.getId() && property.getGetter() == null) {
props.putAsKeyString(property.getSpecificName(), property.getDefaultValue(env).toImmutable());
}
}
ClassEntity tmp = parent;
while (tmp != null) {
long otherId = tmp.getId();
for (PropertyEntity property : tmp.getProperties()) {
if (property.getClazz().getId() == otherId && property.getGetter() == null) {
if (property.modifier != Modifier.PROTECTED || props.getByScalar(property.getName()) == null)
props.getByScalarOrCreate(property.getSpecificName(), property.getDefaultValue(env).toImmutable());
}
}
tmp = tmp.parent;
}
if (doConstruct && methodConstruct != null) {
ObjectInvokeHelper.invokeMethod(object, methodConstruct, env, trace, args, true);
}
return (T) object;
}
use of php.runtime.lang.IObject in project jphp by jphp-compiler.
the class ClassEntity method newMock.
public <T extends IObject> T newMock(Environment env) throws Throwable {
if (nativeConstructor == null) {
env.error(env.trace(), ErrorType.E_CORE_ERROR, "Cannot find a java constructor %s(Environment, ClassEntity)", getName());
}
try {
IObject object = (IObject) nativeConstructor.newInstance(env, this);
object.setAsMock();
return (T) object;
} catch (InstantiationException e) {
return null;
}
}
Aggregations