Search in sources :

Example 1 with Memory

use of php.runtime.Memory in project jphp by jphp-compiler.

the class UICombobox method onCellRender.

@Signature(@Arg(value = "handler", optional = @Optional("null")))
public Memory onCellRender(final Environment env, Memory... args) {
    if (args[0].isNull())
        component.setRenderer(defaultRenderer);
    else {
        final Invoker invoker = Invoker.valueOf(env, null, args[0]);
        final ObjectMemory self = new ObjectMemory(this);
        component.setRenderer(new ListCellRenderer() {

            @Override
            public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
                JLabel template = (JLabel) defaultRenderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
                Memory _value = MemoryUtils.valueOf(value);
                Memory _index = LongMemory.valueOf(index);
                Memory _isSelected = TrueMemory.valueOf(isSelected);
                Memory _cellHasFocus = TrueMemory.valueOf(cellHasFocus);
                Memory r = invoker.callNoThrow(self, new ObjectMemory(new UILabel(env, template)), _value, _index, _isSelected, _cellHasFocus);
                if (r.isObject() && r.instanceOf(UIElement.class)) {
                    return r.toObject(UIElement.class).getComponent();
                }
                return template;
            }
        });
    }
    return Memory.NULL;
}
Also used : Invoker(php.runtime.invoke.Invoker) Memory(php.runtime.Memory)

Example 2 with Memory

use of php.runtime.Memory in project jphp by jphp-compiler.

the class UIFileChooser method __setSelectedFiles.

@Signature(@Arg(value = "value", type = HintType.ARRAY))
protected Memory __setSelectedFiles(Environment env, Memory... args) {
    ArrayMemory value = args[0].toValue(ArrayMemory.class);
    File[] files = new File[value.size()];
    ForeachIterator iterator = value.foreachIterator(false, false);
    int i = 0;
    while (iterator.next()) {
        Memory el = iterator.getValue();
        if (el.instanceOf(FileObject.class)) {
            files[i] = el.toObject(FileObject.class).getFile();
        } else {
            files[i] = new File(el.toString());
        }
        i++;
    }
    component.setSelectedFiles(files);
    return Memory.NULL;
}
Also used : ForeachIterator(php.runtime.lang.ForeachIterator) Memory(php.runtime.Memory) File(java.io.File)

Example 3 with Memory

use of php.runtime.Memory in project jphp by jphp-compiler.

the class VarVarValueCompiler method write.

@Override
public void write(GetVarExprToken getVar, boolean returnValue) {
    if (!methodStatement.isDynamicLocal())
        throw new ExpressionStmtCompiler.UnsupportedTokenException(getVar);
    Memory result = expr.writeExpression(getVar.getName(), true, true, false);
    if (result != null && result.isString()) {
        String name = result.toString();
        LocalVariable variable = method.getLocalVariable(name);
        if (variable != null) {
            if (returnValue)
                expr.writeVarLoad(variable);
            return;
        }
    }
    expr.writePushLocal();
    expr.writeExpression(getVar.getName(), true, false);
    expr.writePopBoxing();
    expr.writeSysDynamicCall(Memory.class, "refOfIndex", Memory.class, Memory.class);
    if (!returnValue)
        expr.writePopAll(1);
}
Also used : Memory(php.runtime.Memory) LocalVariable(org.develnext.jphp.core.compiler.jvm.misc.LocalVariable) ExpressionStmtCompiler(org.develnext.jphp.core.compiler.jvm.statement.ExpressionStmtCompiler)

Example 4 with Memory

use of php.runtime.Memory in project jphp by jphp-compiler.

the class ArraysTest method testComplex.

@Test
public void testComplex() {
    Memory memory = includeResource("arrays/complex.php");
    Assert.assertEquals("success", memory.toString());
}
Also used : Memory(php.runtime.Memory) ArrayMemory(php.runtime.memory.ArrayMemory) Test(org.junit.Test)

Example 5 with Memory

use of php.runtime.Memory in project jphp by jphp-compiler.

the class ArraysTest method testArrayReference.

@Test
public void testArrayReference() {
    Memory memory = includeResource("arrays/array_reference.php");
    Assert.assertEquals(100, memory.toLong());
}
Also used : Memory(php.runtime.Memory) ArrayMemory(php.runtime.memory.ArrayMemory) Test(org.junit.Test)

Aggregations

Memory (php.runtime.Memory)402 ArrayMemory (php.runtime.memory.ArrayMemory)151 Test (org.junit.Test)127 ObjectMemory (php.runtime.memory.ObjectMemory)84 StringMemory (php.runtime.memory.StringMemory)68 LongMemory (php.runtime.memory.LongMemory)60 ForeachIterator (php.runtime.lang.ForeachIterator)54 ReferenceMemory (php.runtime.memory.ReferenceMemory)45 Signature (php.runtime.annotation.Reflection.Signature)27 Invoker (php.runtime.invoke.Invoker)27 KeyValueMemory (php.runtime.memory.KeyValueMemory)26 IObject (php.runtime.lang.IObject)24 ArrayKeyMemory (php.runtime.memory.helper.ArrayKeyMemory)23 ArrayValueMemory (php.runtime.memory.helper.ArrayValueMemory)23 ShortcutMemory (php.runtime.memory.helper.ShortcutMemory)23 Environment (php.runtime.env.Environment)21 ClassEntity (php.runtime.reflection.ClassEntity)18 UndefinedMemory (php.runtime.memory.helper.UndefinedMemory)16 TraceInfo (php.runtime.env.TraceInfo)12 CriticalException (php.runtime.exceptions.CriticalException)10