Package org.rythmengine.utils

Examples of org.rythmengine.utils.TextBuilder


     */
    public void removeSpaceToLastLineBreak(IContext ctx) {
        boolean shouldRemoveSpace = true;
        List<Token> bl = builders();
        for (int i = bl.size() - 1; i >= 0; --i) {
            TextBuilder tb = bl.get(i);
            if (tb == Token.EMPTY_TOKEN || tb instanceof IDirective) {
                continue;
            }
            if (tb.getClass().equals(Token.StringToken.class)) {
                String s = tb.toString();
                if (s.matches("[ \\t\\x0B\\f]+")) {
                    continue;
                } else if (s.matches("(\\n\\r|\\r\\n|[\\r\\n])")) {
                } else {
                    shouldRemoveSpace = false;
                }
            }
            break;
        }
        if (shouldRemoveSpace) {
            for (int i = bl.size() - 1; i >= 0; --i) {
                TextBuilder tb = bl.get(i);
                if (tb == Token.EMPTY_TOKEN || tb instanceof IDirective) {
                    continue;
                }
                if (tb.getClass().equals(Token.StringToken.class)) {
                    String s = tb.toString();
                    if (s.matches("[ \\t\\x0B\\f]+")) {
                        bl.remove(i);
                        continue;
                    } else if (s.matches("(\\n\\r|\\r\\n|[\\r\\n])")) {
                        bl.remove(i);
View Full Code Here


            }
            break;
        }
        if (shouldRemoveSpace) {
            for (int i = bl.size() - 1; i >= 0; --i) {
                TextBuilder tb = bl.get(i);
                if (tb == Token.EMPTY_TOKEN || tb instanceof IDirective) {
                    continue;
                }
                if (tb.getClass().equals(Token.StringToken.class)) {
                    String s = tb.toString();
                    if (s.matches("[ \\t\\x0B\\f]+")) {
                        bl.remove(i);
                        continue;
                    }
                }
View Full Code Here

    public String javaSourceInfo() {
        if (null != javaSourceInfo) return javaSourceInfo;
        String javaSource = getJavaSource();
        if (S.isEmpty(javaSource)) return "No java source available";
        TextBuilder tb = new TextBuilder();
        tb.p("Relevant Java source lines:\n-------------------------------------------------\n");
        String[] lines = javaSource.split("(\\n\\r|\\r\\n|\\r|\\n)");
        int start = 0, end = lines.length;
        int javaLineNumber = this.javaLineNumber;
        if (javaLineNumber > -1 && javaLineNumber < lines.length) {
            start = Math.max(0, javaLineNumber - 6);
            end = Math.min(end, javaLineNumber + 6);
        }
        for (int line = start; line < end; ++line) {
            if ((line + 1) == javaLineNumber) tb.p(">> ");
            else tb.p("   ");
            tb.p(line + 1).p(": ").p(lines[line]).p("\n");
        }
        javaSourceInfo = tb.toString();
        return javaSourceInfo;
    }
View Full Code Here

    public String templateSourceInfo() {
        if (null != templateSourceInfo) return templateSourceInfo;
        String tmplSource = getTemplateSource();
        if (S.isEmpty(tmplSource)) return "No template source available";
        TextBuilder tb = new TextBuilder();
        tb.p("Relevant template source lines:\n-------------------------------------------------\n");
        String[] lines = tmplSource.split("(\\n\\r|\\r\\n|\\r|\\n)");
        int start = 0, end = lines.length;
        if (templateLineNumber > -1 && templateLineNumber < lines.length) {
            start = Math.max(0, templateLineNumber - 6);
            end = Math.min(end, templateLineNumber + 6);
        }
        for (int line = start; line < end; ++line) {
            if ((line + 1) == templateLineNumber) tb.p(">> ");
            else tb.p("   ");
            tb.p(line + 1).p(": ").p(lines[line]).p("\n");
        }
        templateSourceInfo = tb.toString();
        return templateSourceInfo;
    }
View Full Code Here

        String javaSourceInfo = null;
        templateLineNumber = resolveTemplateLineNumber(javaLineNumber, templateLineNumber, javaSource, templateClass);
        if (!logJava && !logTmpl) {
            return new F.T4(message, templateLineNumber, tmplSourceInfo, javaSourceInfo);
        }
        TextBuilder tb = new TextBuilder();
        tb.pn(message);
        tb.p("\nTemplate: ").p(templateClass.getKey()).p("\n");
        if (logTmpl && !S.isEmpty(tmplSource)) {
            TextBuilder tbTmpl = new TextBuilder();
            tbTmpl.p("\nRelevant template source lines:\n-------------------------------------------------\n");
            String[] lines = tmplSource.split("(\\n\\r|\\r\\n|\\r|\\n)");
            int start = 0, end = lines.length;
            if (templateLineNumber > -1) {
                start = Math.max(0, templateLineNumber - 6);
                end = Math.min(end, templateLineNumber + 6);
            }
            for (int line = start; line < end; ++line) {
                if ((line + 1) == templateLineNumber) tbTmpl.p(">> ");
                else tbTmpl.p("   ");
                tbTmpl.p(line + 1).p(": ").p(lines[line]).p("\n");
            }
            tmplSourceInfo = tbTmpl.toString();
        }
        // log java source anyway if template line number is not resolved
        if ((logJava || templateLineNumber < 0) && !S.isEmpty(javaSource)) {
            TextBuilder tbJava = new TextBuilder();
            tbJava.p("\nRelevant Java source lines:\n-------------------------------------------------\n");
            String[] lines = javaSource.split("(\\n\\r|\\r\\n|\\r|\\n)");
            int start = 0, end = lines.length;
            if (javaLineNumber > -1) {
                start = Math.max(0, javaLineNumber - 6);
                end = Math.min(end, javaLineNumber + 6);
            }
            for (int line = start; line < end; ++line) {
                if ((line + 1) == javaLineNumber) tbJava.p(">> ");
                else tbJava.p("   ");
                tbJava.p(line + 1).p(": ").p(lines[line]).p("\n");
            }
            javaSourceInfo = tbJava.toString();
        }
        tb.pn(tmplSourceInfo);
        tb.pn(javaSourceInfo);
        return new F.T4(tb.toString(), templateLineNumber, tmplSourceInfo, javaSourceInfo);
    }
View Full Code Here

                        if (blank.length() > 0) {
                            ctx.getCodeBuilder().addBuilder(new Token.StringToken(blank, ctx));
                        }
                    }
                }
                String s = new TextBuilder().p("__logger.debug").p(r.stringMatched(2)).p(";").toString();
                return new CodeToken(s, ctx());
            }
        };
    }
View Full Code Here

            os.write(hash.getBytes("utf-8"));

            // --- cache java source
            os.write(0);
            if (null != tc.javaSource) {
                TextBuilder tb = new TextBuilder();
                tb.p(tc.javaSource);
                tb.p("__INCLUDED_TAG_TYPES__").p(tc.serializeIncludeTagTypes());
                tb.p("__INCULDED_TEMPLATE_CLASS_NAME_LIST__").p(tc.refreshIncludeTemplateClassNames())
                        .p("__IMPORT_PATH_LIST__");
                if (tc.importPaths == null) {
                    tc.importPaths = new HashSet<String>(0);
                }
                if (tc.importPaths.isEmpty()) {
                    tc.importPaths.add("java.lang");
                }
                boolean first = true;
                for (String s : tc.importPaths) {
                    if (!first) {
                        tb.p(";");
                    } else {
                        first = false;
                    }
                    tb.p(s);
                }
                os.write(tb.toString().getBytes("utf-8"));
            } // else the tc is an inner class thus we don't have javaSource at all

            // --- cache byte code
            os.write(0);
            //if (null != tc.enhancedByteCode) {
View Full Code Here

TOP

Related Classes of org.rythmengine.utils.TextBuilder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.