Search in sources :

Example 11 with BaseNode

use of com.dexels.navajo.document.base.BaseNode in project navajo by Dexels.

the class NavascriptTag method formatNS3.

@Override
public void formatNS3(int indent, OutputStream w) throws Exception {
    StringBuffer sb = new StringBuffer();
    sb.append("/*\n");
    if (id != null)
        sb.append("   id      : " + id + "\n");
    if (author != null)
        sb.append("   author  : " + author + "\n");
    if (notes != null)
        sb.append("   notes   : " + notes + "\n");
    sb.append("   Copyright(c) 2021 Dexels BV\n");
    sb.append("*/\n\n");
    w.write(sb.toString().getBytes());
    for (BaseNode c : getChildren()) {
        if (c instanceof NS3Compatible) {
            ((NS3Compatible) c).formatNS3(indent, w);
        }
    }
}
Also used : BaseNode(com.dexels.navajo.document.base.BaseNode)

Example 12 with BaseNode

use of com.dexels.navajo.document.base.BaseNode in project navajo by Dexels.

the class MethodsTag method formatNS3.

@Override
public void formatNS3(int indent, OutputStream w) throws Exception {
    String r = NS3Utils.generateIndent(indent) + NS3Keywords.METHODS + " {\n";
    w.write(r.getBytes());
    for (BaseNode c : getChildren()) {
        if (c instanceof MethodTag) {
            ((MethodTag) c).formatNS3(indent + 1, w);
        }
        w.write("\n".getBytes());
    }
    w.write("}\n\n".getBytes());
}
Also used : BaseNode(com.dexels.navajo.document.base.BaseNode)

Example 13 with BaseNode

use of com.dexels.navajo.document.base.BaseNode in project navajo by Dexels.

the class ParamTag method formatNS3.

@Override
public void formatNS3(int indent, OutputStream w) throws Exception {
    Map<String, String> map = getAttributes();
    boolean isArrayElement = (getType() != null && getType().equals(Message.MSG_TYPE_ARRAY_ELEMENT));
    boolean hasArrayElements = (getChildren().size() > 0 && getChildren().get(0) instanceof ParamTag && Message.MSG_TYPE_ARRAY_ELEMENT.equals(((ParamTag) getChildren().get(0)).getType()));
    boolean hasSubParam = (getChildren().size() > 0 && getChildren().get(0) instanceof ParamTag && !Message.MSG_TYPE_ARRAY_ELEMENT.equals(((ParamTag) getChildren().get(0)).getType()));
    StringBuffer sb = new StringBuffer();
    int origIndent = indent;
    sb.append(NS3Utils.generateIndent(indent));
    sb.append(NS3Utils.formatConditional(map.get("condition")));
    if (!isArrayElement) {
        sb.append(NS3Keywords.VAR + " " + getName());
    }
    // Check for attributes
    if (!isArrayElement) {
        AttributeAssignments aa = new AttributeAssignments();
        aa.addMap(getAttributes(), "name", "condition", (hasArrayElements || "simple".equals(getType()) ? "type" : ""));
        sb.append(" ");
        sb.append(aa.format(true));
    }
    // It has a param array element
    boolean hasParam = hasParamChildren();
    // It has a mapped ref.
    MapTag ref = (MapTag) getMap();
    if (NS3Utils.hasExpressionWithConstant(this)) {
        sb.append(" = ");
    } else if (!hasParam && ref == null) {
        sb.append(" = ");
    }
    if (ref != null) {
        sb.append(" {\n");
        // write current buffer.
        w.write(sb.toString().getBytes());
        ref.formatNS3(indent + 1, w);
        w.write((NS3Utils.generateIndent(indent) + "}\n").getBytes());
    } else if (hasArrayElements) {
        sb.append(" [\n");
        // write current buffer.
        w.write(sb.toString().getBytes());
        int size = getChildren().size();
        int count = 0;
        for (BaseNode p : getChildren()) {
            ((NS3Compatible) p).formatNS3(indent + 1, w);
            if (hasArrayElements && count < size - 1) {
                w.write(",".getBytes());
            }
            count++;
        }
        w.write(("\n" + NS3Utils.generateIndent(indent) + "]\n").getBytes());
    } else if (isArrayElement || hasSubParam) {
        if (isArrayElement) {
            sb.append("\n" + NS3Utils.generateIndent(indent) + "{\n");
        } else {
            sb.append(" {\n");
        }
        // write current buffer.
        w.write(sb.toString().getBytes());
        for (BaseNode p : getChildren()) {
            ((NS3Compatible) p).formatNS3(indent + 1, w);
        }
        w.write((NS3Utils.generateIndent(indent) + "}").getBytes());
        if (hasSubParam && !isArrayElement) {
            w.write("\n".getBytes());
        }
    } else {
        // write current buffer.
        w.write(sb.toString().getBytes());
        NS3Utils.writeConditionalExpressions(origIndent, w, getChildren());
        w.write((NS3Constants.EOL_DELIMITER + "\n\n").getBytes());
    }
}
Also used : BaseNode(com.dexels.navajo.document.base.BaseNode)

Example 14 with BaseNode

use of com.dexels.navajo.document.base.BaseNode in project navajo by Dexels.

the class BlockTag method formatNS3.

@Override
public void formatNS3(int indent, OutputStream w) throws Exception {
    StringBuffer sb = new StringBuffer();
    sb.append(NS3Utils.generateIndent(indent));
    sb.append(NS3Utils.formatConditional(getCondition()));
    sb.append(NS3Constants.OPEN_BLOCK);
    sb.append("\n");
    w.write(sb.toString().getBytes());
    // Loop over children
    for (BaseNode n : getChildren()) {
        if (n instanceof NS3Compatible) {
            ((NS3Compatible) n).formatNS3(indent + 1, w);
        }
    }
    w.write((NS3Utils.generateIndent(indent) + NS3Constants.CLOSE_BLOCK + "\n").getBytes());
}
Also used : BaseNode(com.dexels.navajo.document.base.BaseNode)

Example 15 with BaseNode

use of com.dexels.navajo.document.base.BaseNode in project navajo by Dexels.

the class MessageTag method formatNS3.

@Override
public void formatNS3(int indent, OutputStream w) throws Exception {
    int size = getChildren().size();
    boolean isArrayElement = (getType() != null && getType().equals(Message.MSG_TYPE_ARRAY_ELEMENT));
    boolean hasArrayElements = (getChildren().size() > 0 && getChildren().get(0) instanceof MessageTag && Message.MSG_TYPE_ARRAY_ELEMENT.equals(((MessageTag) getChildren().get(0)).getType()));
    String msgName = getName();
    Map<String, String> map = getAttributes();
    w.write(NS3Utils.generateIndent(indent).getBytes());
    w.write(NS3Utils.formatConditional(map.get("condition")).getBytes());
    if (!isArrayElement) {
        String start = (isAntiMessage() ? "anti" : "") + "message \"" + msgName + "\" ";
        w.write(start.getBytes());
        AttributeAssignments aa = new AttributeAssignments();
        aa.addMap(getAttributes(), "name", "condition", (hasArrayElements || "simple".equals(getType()) ? "type" : ""));
        w.write(aa.format(true).getBytes());
    }
    if (size > 0) {
        String openBlock = null;
        if (isArrayElement) {
            openBlock = "\n" + NS3Utils.generateIndent(indent) + " {\n";
        } else if (hasArrayElements) {
            openBlock = " [\n";
        } else {
            openBlock = " {\n";
        }
        w.write(openBlock.getBytes());
    } else {
        w.write((NS3Constants.EOL_DELIMITER + "\n").getBytes());
    }
    // Loop over children
    int count = 0;
    for (BaseNode n : getChildren()) {
        if (n instanceof NS3Compatible) {
            ((NS3Compatible) n).formatNS3(indent + 1, w);
        }
        if (hasArrayElements && count < getChildren().size() - 1) {
            w.write(",".getBytes());
        }
        count++;
    }
    if (size > 0) {
        String end = null;
        if (isArrayElement) {
            end = NS3Utils.generateIndent(indent) + "}";
        } else if (hasArrayElements) {
            end = "\n" + NS3Utils.generateIndent(indent) + "]\n\n";
        } else {
            end = NS3Utils.generateIndent(indent) + "}\n\n";
        }
        w.write(end.getBytes());
    }
}
Also used : BaseNode(com.dexels.navajo.document.base.BaseNode)

Aggregations

BaseNode (com.dexels.navajo.document.base.BaseNode)15 DefineTag (com.dexels.navajo.document.navascript.tags.DefineTag)2 FieldTag (com.dexels.navajo.document.navascript.tags.FieldTag)2 MapTag (com.dexels.navajo.document.navascript.tags.MapTag)2 MessageTag (com.dexels.navajo.document.navascript.tags.MessageTag)2 ValueTag (com.dexels.navajo.document.navascript.tags.ValueTag)2 IOException (java.io.IOException)2 BaseCheckTagImpl (com.dexels.navajo.document.base.BaseCheckTagImpl)1 BaseExpressionTagImpl (com.dexels.navajo.document.base.BaseExpressionTagImpl)1 BaseFieldTagImpl (com.dexels.navajo.document.base.BaseFieldTagImpl)1 BlockTag (com.dexels.navajo.document.navascript.tags.BlockTag)1 BreakTag (com.dexels.navajo.document.navascript.tags.BreakTag)1 CheckTag (com.dexels.navajo.document.navascript.tags.CheckTag)1 DebugTag (com.dexels.navajo.document.navascript.tags.DebugTag)1 DefinesTag (com.dexels.navajo.document.navascript.tags.DefinesTag)1 ExpressionTag (com.dexels.navajo.document.navascript.tags.ExpressionTag)1 FinallyTag (com.dexels.navajo.document.navascript.tags.FinallyTag)1 IncludeTag (com.dexels.navajo.document.navascript.tags.IncludeTag)1 LogTag (com.dexels.navajo.document.navascript.tags.LogTag)1 MethodTag (com.dexels.navajo.document.navascript.tags.MethodTag)1