Search in sources :

Example 6 with MethodEntity

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();
}
Also used : ArrayMemory(php.runtime.memory.ArrayMemory) ClassEntity(php.runtime.reflection.ClassEntity) ObjectMemory(php.runtime.memory.ObjectMemory) MethodEntity(php.runtime.reflection.MethodEntity)

Example 7 with MethodEntity

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);
}
Also used : ObjectMemory(php.runtime.memory.ObjectMemory) MethodEntity(php.runtime.reflection.MethodEntity)

Example 8 with MethodEntity

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;
}
Also used : ClassEntity(php.runtime.reflection.ClassEntity) ClosureEntity(php.runtime.reflection.helper.ClosureEntity) MethodEntity(php.runtime.reflection.MethodEntity) ClassStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.ClassStmtToken) MethodStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.MethodStmtToken)

Example 9 with MethodEntity

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;
}
Also used : DumpInputStream(php.runtime.loader.dump.io.DumpInputStream) DocumentComment(php.runtime.reflection.DocumentComment) ParameterEntity(php.runtime.reflection.ParameterEntity) MethodEntity(php.runtime.reflection.MethodEntity) DumpException(php.runtime.loader.dump.io.DumpException)

Example 10 with MethodEntity

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;
}
Also used : MethodEntity(php.runtime.reflection.MethodEntity) Memory(php.runtime.Memory) WrapScopeValue(org.develnext.jphp.swing.classes.WrapScopeValue)

Aggregations

MethodEntity (php.runtime.reflection.MethodEntity)16 ClassEntity (php.runtime.reflection.ClassEntity)9 ObjectMemory (php.runtime.memory.ObjectMemory)6 Memory (php.runtime.Memory)4 ArrayMemory (php.runtime.memory.ArrayMemory)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 Test (org.junit.Test)3 StringMemory (php.runtime.memory.StringMemory)3 CriticalException (php.runtime.exceptions.CriticalException)2 IObject (php.runtime.lang.IObject)2 ReferenceMemory (php.runtime.memory.ReferenceMemory)2 ParameterEntity (php.runtime.reflection.ParameterEntity)2 ClassStmtToken (org.develnext.jphp.core.tokenizer.token.stmt.ClassStmtToken)1 MethodStmtToken (org.develnext.jphp.core.tokenizer.token.stmt.MethodStmtToken)1 WrapScopeValue (org.develnext.jphp.swing.classes.WrapScopeValue)1 Closure (php.runtime.lang.Closure)1 DumpException (php.runtime.loader.dump.io.DumpException)1 DumpInputStream (php.runtime.loader.dump.io.DumpInputStream)1 LongMemory (php.runtime.memory.LongMemory)1