Search in sources :

Example 51 with ArrayMemory

use of php.runtime.memory.ArrayMemory in project jphp by jphp-compiler.

the class WrapThread method __debugInfo.

@Signature
public Memory __debugInfo(Environment env, Memory... args) {
    ArrayMemory r = new ArrayMemory();
    r.refOfIndex("*id").assign(thread.getId());
    r.refOfIndex("*name").assign(thread.getName());
    if (thread.getThreadGroup() != null)
        r.refOfIndex("*group").assign(thread.getThreadGroup().getName());
    else
        r.refOfIndex("*group");
    r.refOfIndex("*priority").assign(thread.getPriority());
    return r.toConstant();
}
Also used : ArrayMemory(php.runtime.memory.ArrayMemory)

Example 52 with ArrayMemory

use of php.runtime.memory.ArrayMemory in project jphp by jphp-compiler.

the class WrapDomDocument method createElement.

@Signature
public Element createElement(String tagName, @Nullable ArrayMemory _model) {
    Element element = getWrappedObject().createElement(tagName);
    ForeachIterator model = _model.foreachIterator(false, false);
    while (model != null && model.next()) {
        String key = model.getKey().toString();
        Memory value = model.getValue();
        if (key.startsWith("@")) {
            element.setAttribute(key.substring(1), value.toString());
        } else {
            Element subElement = getWrappedObject().createElement(key);
            if (value.isArray()) {
                for (Memory el : value.toValue(ArrayMemory.class)) {
                    Element sub = getWrappedObject().createElement("item");
                    if (el.isArray()) {
                        sub = createElement("item", el.toValue(ArrayMemory.class));
                    } else {
                        sub.setTextContent(el.toString());
                    }
                    subElement.appendChild(sub);
                }
            } else {
                subElement.setTextContent(value.toString());
            }
            element.appendChild(subElement);
        }
    }
    return element;
}
Also used : ForeachIterator(php.runtime.lang.ForeachIterator) Memory(php.runtime.Memory) ArrayMemory(php.runtime.memory.ArrayMemory) Element(org.w3c.dom.Element)

Example 53 with ArrayMemory

use of php.runtime.memory.ArrayMemory in project jphp by jphp-compiler.

the class WrapDomNode method toModel.

protected static Memory toModel(Node node) {
    if (node.getNodeType() == Node.TEXT_NODE) {
        return StringMemory.valueOf(node.getTextContent());
    }
    ArrayMemory result = new ArrayMemory(true);
    NamedNodeMap attrs = node.getAttributes();
    for (int i = 0; i < attrs.getLength(); i++) {
        Node attr = attrs.item(i);
        result.refOfIndex("@" + attr.getNodeName()).assign(attr.getNodeValue());
    }
    NodeList children = node.getChildNodes();
    for (int i = 0; i < children.getLength(); i++) {
        Node el = children.item(i);
        if (el.getNodeType() == Node.TEXT_NODE) {
            continue;
        }
        if (el.hasAttributes() || el.hasChildNodes()) {
            if (el.getChildNodes().getLength() == 1 && el.getFirstChild().getNodeType() == Node.TEXT_NODE) {
                ReferenceMemory one = result.getByScalar(el.getNodeName());
                if (one != null) {
                    if (!one.isArray()) {
                        ArrayMemory tmp = new ArrayMemory();
                        tmp.refOfPush().assign(one.toValue());
                        one.assign(tmp);
                    }
                    one.refOfPush().assign(el.getFirstChild().getTextContent());
                    result.refOfIndex(el.getNodeName()).assignRef(one.toValue());
                } else {
                    result.refOfIndex(el.getNodeName()).assign(el.getFirstChild().getTextContent());
                }
            } else {
                result.refOfIndex(el.getNodeName()).assign(toModel(el).toImmutable());
            }
        } else {
            result.refOfIndex(el.getNodeName()).assign(el.getTextContent());
        }
    }
    if (result.size() == 1) {
        Memory tmp = result.getByScalar("item");
        if (tmp != null) {
            if (tmp.isArray()) {
                return tmp.toValue(ArrayMemory.class).toConstant();
            } else {
                ArrayMemory m = new ArrayMemory();
                m.add(tmp.toValue());
                return m.toConstant();
            }
        }
    }
    return result.toConstant();
}
Also used : ArrayMemory(php.runtime.memory.ArrayMemory) ReferenceMemory(php.runtime.memory.ReferenceMemory) NamedNodeMap(org.w3c.dom.NamedNodeMap) Memory(php.runtime.Memory) ArrayMemory(php.runtime.memory.ArrayMemory) ReferenceMemory(php.runtime.memory.ReferenceMemory) StringMemory(php.runtime.memory.StringMemory) Node(org.w3c.dom.Node) NodeList(org.w3c.dom.NodeList)

Example 54 with ArrayMemory

use of php.runtime.memory.ArrayMemory in project jphp by jphp-compiler.

the class UISlider method __getLabelTable.

@Signature
protected Memory __getLabelTable(Environment env, Memory... args) {
    Dictionary dictionary = component.getLabelTable();
    ArrayMemory result = new ArrayMemory();
    for (Object key : Collections.list(dictionary.keys())) {
        JLabel label = (JLabel) dictionary.get(key);
        result.refOfIndex((Integer) key).assign(label.getText());
    }
    return result.toConstant();
}
Also used : ArrayMemory(php.runtime.memory.ArrayMemory) Dictionary(java.util.Dictionary)

Example 55 with ArrayMemory

use of php.runtime.memory.ArrayMemory in project jphp by jphp-compiler.

the class UIElement method __debugInfo.

@Signature
public Memory __debugInfo(Environment env, Memory... args) {
    ArrayMemory result = new ArrayMemory();
    result.refOfIndex("uid").assign(getComponent().getName());
    result.refOfIndex("position").assign(ArrayMemory.ofIntegers(getComponent().getX(), getComponent().getY()));
    result.refOfIndex("size").assign(ArrayMemory.ofIntegers(getComponent().getWidth(), getComponent().getHeight()));
    ComponentProperties properties = SwingExtension.getProperties(getComponent());
    if (properties.getOriginGroups() != null)
        result.refOfIndex("group").assign(properties.getOriginGroups());
    return result.toConstant();
}
Also used : ArrayMemory(php.runtime.memory.ArrayMemory) ComponentProperties(org.develnext.jphp.swing.ComponentProperties)

Aggregations

ArrayMemory (php.runtime.memory.ArrayMemory)148 Memory (php.runtime.Memory)60 ForeachIterator (php.runtime.lang.ForeachIterator)41 ObjectMemory (php.runtime.memory.ObjectMemory)35 LongMemory (php.runtime.memory.LongMemory)31 StringMemory (php.runtime.memory.StringMemory)29 ReferenceMemory (php.runtime.memory.ReferenceMemory)25 KeyValueMemory (php.runtime.memory.KeyValueMemory)17 Invoker (php.runtime.invoke.Invoker)9 ClassEntity (php.runtime.reflection.ClassEntity)9 Signature (php.runtime.annotation.Reflection.Signature)6 IObject (php.runtime.lang.IObject)6 Map (java.util.Map)4 Test (org.junit.Test)4 DoubleMemory (php.runtime.memory.DoubleMemory)4 ConcurrentEnvironment (php.runtime.env.ConcurrentEnvironment)3 TraceInfo (php.runtime.env.TraceInfo)3 ModuleEntity (php.runtime.reflection.ModuleEntity)3 ParameterEntity (php.runtime.reflection.ParameterEntity)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2