Search in sources :

Example 1 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)

Example 2 with MethodEntity

use of php.runtime.reflection.MethodEntity in project jphp by jphp-compiler.

the class RootObject method __isset.

@Reflection.Signature({ @Reflection.Arg("name") })
public Memory __isset(Environment env, Memory... args) {
    String name = args[0].toString();
    MethodEntity methodEntity = __class__.findMethod("__get" + name.toLowerCase());
    return methodEntity == null ? Memory.FALSE : Memory.TRUE;
}
Also used : MethodEntity(php.runtime.reflection.MethodEntity)

Example 3 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()));
    entity.setStatic(statement.isStatic());
    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.setClosureEntity(entity);
    classStmtCompiler.setSystem(true);
    classStmtCompiler.setInterfaceCheck(false);
    classStmtCompiler.setClassContext(statement.getOwnerClass());
    classStmtCompiler.setFunctionName(null);
    ClassEntity clazzEntity = classStmtCompiler.compile();
    clazzEntity.setType(ClassEntity.Type.CLOSURE);
    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 4 with MethodEntity

use of php.runtime.reflection.MethodEntity in project jphp by jphp-compiler.

the class MethodDumperTest method testBasic.

@Test
public void testBasic() throws IOException {
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    MethodEntity entity = new MethodEntity(context);
    entity.setName("foobar");
    entity.setAbstract(true);
    entity.setFinal(true);
    entity.setModifier(Modifier.PROTECTED);
    entity.setAbstractable(true);
    entity.setImmutable(true);
    entity.setReturnReference(true);
    dumper.save(entity, output);
    MethodEntity copyEntity = dumper.load(new ByteArrayInputStream(output.toByteArray()));
    Assert.assertEquals("foobar", copyEntity.getName());
    Assert.assertEquals(Modifier.PROTECTED, copyEntity.getModifier());
    Assert.assertTrue(copyEntity.isAbstract());
    Assert.assertTrue(copyEntity.isFinal());
    Assert.assertTrue(copyEntity.isAbstractable());
    Assert.assertTrue(copyEntity.isImmutable());
    Assert.assertTrue(copyEntity.isReturnReference());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) MethodEntity(php.runtime.reflection.MethodEntity) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 5 with MethodEntity

use of php.runtime.reflection.MethodEntity in project jphp by jphp-compiler.

the class DynamicMethodInvoker method valueOf.

public static DynamicMethodInvoker valueOf(Environment env, TraceInfo trace, IObject object, String methodName) {
    String methodNameL = methodName.toLowerCase();
    int pos;
    MethodEntity methodEntity;
    if ((pos = methodName.indexOf("::")) > -1) {
        String className = methodNameL.substring(0, pos);
        methodNameL = methodNameL.substring(pos + 2);
        ClassEntity classEntity = object.getReflection();
        ClassEntity clazz = env.fetchClass(methodName.substring(0, pos), className, false);
        if (!classEntity.isInstanceOf(clazz)) {
            return null;
        }
        methodEntity = clazz.findMethod(methodNameL);
    } else
        methodEntity = object.getReflection().findMethod(methodNameL);
    if (methodEntity == null) {
        if (object.getReflection().methodMagicCall != null) {
            return new MagicDynamicMethodInvoker(env, trace, object, object.getReflection().methodMagicCall, methodName);
        }
        if (trace == null) {
            return null;
        }
        env.error(trace, Messages.ERR_CALL_TO_UNDEFINED_METHOD.fetch(object.getReflection().getName() + "::" + methodName));
    }
    return new DynamicMethodInvoker(env, trace, object, methodEntity);
}
Also used : ClassEntity(php.runtime.reflection.ClassEntity) MethodEntity(php.runtime.reflection.MethodEntity)

Aggregations

MethodEntity (php.runtime.reflection.MethodEntity)17 ClassEntity (php.runtime.reflection.ClassEntity)10 ObjectMemory (php.runtime.memory.ObjectMemory)6 Memory (php.runtime.Memory)5 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 ParameterEntity (php.runtime.reflection.ParameterEntity)3 CriticalException (php.runtime.exceptions.CriticalException)2 IObject (php.runtime.lang.IObject)2 ReferenceMemory (php.runtime.memory.ReferenceMemory)2 ClassExprToken (org.develnext.jphp.core.tokenizer.token.expr.ClassExprToken)1 ValueExprToken (org.develnext.jphp.core.tokenizer.token.expr.ValueExprToken)1 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 CallStack (php.runtime.env.CallStack)1 Closure (php.runtime.lang.Closure)1