use of php.runtime.reflection.MethodEntity in project jphp by jphp-compiler.
the class ReflectionClass method getMethods.
@Signature(@Arg(value = "filter", optional = @Optional("NULL")))
public Memory getMethods(Environment env, Memory... args) {
int mod = args[0].isNull() ? -1 : args[0].toInteger();
ArrayMemory result = new ArrayMemory();
ClassEntity classEntity = env.fetchClass("ReflectionMethod");
for (MethodEntity e : entity.getMethods().values()) {
if (checkModifiers(e, mod)) {
ReflectionMethod method = new ReflectionMethod(env, classEntity);
method.setEntity(e);
result.add(new ObjectMemory(method));
}
}
return result.toConstant();
}
use of php.runtime.reflection.MethodEntity in project jphp by jphp-compiler.
the class ReflectionClass method getMethod.
@Signature(@Arg("name"))
public Memory getMethod(Environment env, Memory... args) {
MethodEntity m = entity.findMethod(args[0].toString().toLowerCase());
if (m == null) {
exception(env, Messages.ERR_METHOD_NOT_FOUND.fetch(entity.getName(), args[0]));
return Memory.NULL;
}
ReflectionMethod r = new ReflectionMethod(env, m);
return new ObjectMemory(r);
}
use of php.runtime.reflection.MethodEntity in project jphp by jphp-compiler.
the class ClosureStmtCompiler method compile.
@Override
public ClosureEntity compile() {
ClosureEntity entity = new ClosureEntity(getCompiler().getContext());
entity.setReturnReference(statement.getFunction().isReturnReference());
entity.setInternalName(compiler.getModule().getInternalName() + "_closure" + statement.getId());
entity.setId(statement.getId());
entity.setTrace(statement.toTraceInfo(compiler.getContext()));
ClassStmtToken classStmtToken = new ClassStmtToken(statement.getMeta());
classStmtToken.setNamespace(NamespaceStmtToken.getDefault());
classStmtToken.setName(NameToken.valueOf(entity.getInternalName()));
classStmtToken.setExtend(ExtendsStmtToken.valueOf(Closure.class.getSimpleName()));
MethodStmtToken methodToken = new MethodStmtToken(statement.getFunction());
methodToken.setClazz(classStmtToken);
methodToken.setReturnReference(entity.isReturnReference());
methodToken.setModifier(Modifier.PUBLIC);
methodToken.setName(NameToken.valueOf("__invoke"));
classStmtToken.setMethods(Arrays.asList(methodToken));
ClassStmtCompiler classStmtCompiler = new ClassStmtCompiler(this.compiler, classStmtToken);
classStmtCompiler.setSystem(true);
classStmtCompiler.setInterfaceCheck(false);
classStmtCompiler.setClassContext(statement.getOwnerClass());
classStmtCompiler.setFunctionName(null);
ClassEntity clazzEntity = classStmtCompiler.compile();
MethodEntity __invoke = clazzEntity.findMethod("__invoke");
entity.getMethods().putAll(clazzEntity.getMethods());
if (clazzEntity.getParent() != null)
entity.setParent(clazzEntity.getParent());
entity.setData(clazzEntity.getData());
entity.setParameters(__invoke.getParameters());
entity.doneDeclare();
entity.setGeneratorEntity(__invoke.getGeneratorEntity());
return entity;
}
use of php.runtime.reflection.MethodEntity in project jphp by jphp-compiler.
the class MethodDumper method load.
@Override
public MethodEntity load(InputStream input) throws IOException {
DumpInputStream data = new DumpInputStream(input);
MethodEntity entity = new MethodEntity(context);
String docComment = data.readUTF();
if (!docComment.isEmpty()) {
entity.setDocComment(new DocumentComment(docComment));
}
// static
entity.setStatic(data.readBoolean());
// final
entity.setFinal(data.readBoolean());
// abstract
entity.setAbstract(data.readBoolean());
entity.setAbstractable(data.readBoolean());
entity.setImmutable(data.readBoolean());
entity.setResult(data.readMemory());
entity.setEmpty(data.readBoolean());
// ref
entity.setReturnReference(data.readBoolean());
// uses stack trace
entity.setUsesStackTrace(data.readBoolean());
// modifier
entity.setModifier(data.readModifier());
// name
entity.setName(data.readName());
entity.setInternalName(data.readName());
// trace
entity.setTrace(data.readTrace(context));
int paramCount = data.readInt();
if (paramCount < 0)
throw new DumpException("Invalid param count");
entity.setParameters(new ParameterEntity[paramCount]);
for (int i = 0; i < paramCount; i++) {
ParameterEntity param = parameterDumper.load(input);
param.setTrace(entity.getTrace());
entity.getParameters()[i] = param;
}
data.readRawData();
return entity;
}
use of php.runtime.reflection.MethodEntity in project jphp by jphp-compiler.
the class RootObject method __set.
@Reflection.Signature({ @Reflection.Arg("name"), @Reflection.Arg("value") })
public Memory __set(Environment env, Memory... args) throws Throwable {
String name = args[0].toString();
MethodEntity methodEntity = __class__.findMethod("__set" + name.toLowerCase());
if (methodEntity != null) {
Memory value = args[1];
if (value.instanceOf(WrapScopeValue.class)) {
value.toObject(WrapScopeValue.class).bind(env, this, name);
value = value.toObject(WrapScopeValue.class).getValue(env);
}
ObjectInvokeHelper.invokeMethod(this, methodEntity, env, env.trace(), new Memory[] { value });
} else
env.exception(env.trace(), "setting: Unknown property - " + args[0].toString());
return Memory.NULL;
}
Aggregations