Package greed.code

Examples of greed.code.CodeByLine


                        FileSystem.getResource(template.getTemplateFile()),
                        mergeModels(sharedModel, indivModel)
                );

                if (template.getTransformers() != null) {
                    CodeByLine codeLines = CodeByLine.fromString(output);
                    for (String transformerId: template.getTransformers()) {
                        if (codeTransformers.containsKey(transformerId)) {
                            codeLines = codeTransformers.get(transformerId).transform(codeLines);
                        }
                        else {
                            talkingWindow.indent();
                            talkingWindow.error("Unknown transformer \"" + transformerId + "\"");
                            talkingWindow.unindent();
                        }
                    }
                    output = codeLines.toString();
                }
            } catch (FileNotFoundException e) {
                // Fatal error, the existence has been checked before
                Log.e("Fatal error, cannot find resource " + template.getTemplateFile(), e);
                throw new IllegalStateException(e);
View Full Code Here


        if (!FileSystem.exists(filePath)) {
            talkingWindow.error("Source code file doesn't exist");
        }
        else {
            try {
                CodeByLine code = CodeByLine.fromInputStream(FileSystem.getResource(new ResourcePath(filePath, false)));

                if (LanguageManager.getInstance().getPostTransformer(currentLang) != null)
                    code = LanguageManager.getInstance().getPostTransformer(currentLang).transform(code);

                code = new CutBlockRemover(langConfig.getCutBegin(), langConfig.getCutEnd()).transform(code);
                code = new AppendingTransformer(getSignature()).transform(code);

                result = code.toString();
            } catch (IOException e) {
                talkingWindow.error("Cannot fetch source code, message says \"" + e.getMessage() + "\"");
                Log.e("Cannot fetch source code", e);
            }
        }
View Full Code Here

* Greed is good! Cheers!
*/
public class ContinuousBlankLineRemover implements ConfigurableCodeTransformer {
    @Override
    public CodeByLine transform(CodeByLine input) {
        CodeByLine res = new CodeByLine();
        int lastLen = 0;
        for (String line: input.getLines()) {
            if (line.trim().length() == 0 && lastLen == 0) {
                // skip this line
            }
            else res.getLines().add(line);
            lastLen = line.trim().length();
        }
        return res;
    }
View Full Code Here

        this.endTag = endTag;
    }

    @Override
    public CodeByLine transform(CodeByLine input) {
        CodeByLine res = new CodeByLine();

        boolean cutting = false;
        for (String line: input.getLines()) {
            if (line.trim().equals(startTag))
                cutting = true;
            else if (line.trim().equals(endTag))
                cutting = false;
            else if (!cutting)
                res.getLines().add(line);
        }

        return res;
    }
View Full Code Here

        this.text = text;
    }

    @Override
    public CodeByLine transform(CodeByLine input) {
        CodeByLine res = new CodeByLine(input);
        res.getLines().add(text);
        return res;
    }
View Full Code Here

    }


    @Override
    public CodeByLine transform(CodeByLine input) {
        CodeByLine res = new CodeByLine();

        ArrayList<String> buffer = new ArrayList<String>();
        int totalLen = 0;
        boolean inBlock = false;
        for (String line: input.getLines()) {
            if (line.trim().equals(startTag)) {
                inBlock = true;
                buffer.add(line);
            }
            else if (line.trim().equals(endTag)) {
                buffer.add(line);
                if (totalLen > 0)
                    res.getLines().addAll(buffer);
                inBlock = false;
                buffer.clear();
                totalLen = 0;
            }
            else {
                if (inBlock) {
                    buffer.add(line);
                    totalLen += line.trim().length();
                }
                else
                    res.getLines().add(line);
            }
        }

        return res;
    }
View Full Code Here

* Greed is good! Cheers!
*/
public class JavaPackageRemover implements CodeTransformer {
    @Override
    public CodeByLine transform(CodeByLine input) {
        CodeByLine code = new CodeByLine();

        // remove package declaration
        for (String line : input.getLines()) {
            if (line.trim().startsWith("package")) continue;
            code.getLines().add(line);
        }

        return code;
    }
View Full Code Here

TOP

Related Classes of greed.code.CodeByLine

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.