Search in sources :

Example 6 with StringConcatenationClient

use of org.eclipse.xtend2.lib.StringConcatenationClient in project xtext-core by eclipse.

the class GeneratorNodeTest method testTemplateProcessing.

@Test
public void testTemplateProcessing() {
    final LocationData root = this.loc(0);
    CompositeGeneratorNode _trace = this.exts.trace(root);
    StringConcatenationClient _client = new StringConcatenationClient() {

        @Override
        protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
            StringConcatenationClient _someCodeGen = GeneratorNodeTest.this.someCodeGen(2);
            _builder.append(_someCodeGen);
            _builder.newLineIfNotEmpty();
        }
    };
    final CompositeGeneratorNode node = this.exts.appendTemplate(_trace, _client);
    final GeneratorNodeProcessor processor = new GeneratorNodeProcessor();
    final GeneratorNodeProcessor.Result result = processor.process(node);
    this.assertEquals(this.someCodeGen_noTrace(2).toString(), result.toString());
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("CompletableTraceRegion [myOffset=0, myLength=80, useForDebugging=false] associations={");
    _builder.newLine();
    _builder.append("  ");
    _builder.append("LocationData [TextRegionWithLineInformation [0:100][lineNumber=0, endLineNumber=0]][path=foo/mymodel.dsl]");
    _builder.newLine();
    _builder.append("} nestedRegions={");
    _builder.newLine();
    _builder.append("  ");
    _builder.append("CompletableTraceRegion [myOffset=7, myLength=5, useForDebugging=false] associations={");
    _builder.newLine();
    _builder.append("    ");
    _builder.append("LocationData [TextRegionWithLineInformation [10:90][lineNumber=0, endLineNumber=0]][path=foo/mymodel.dsl]");
    _builder.newLine();
    _builder.append("  ");
    _builder.append("}");
    _builder.newLine();
    _builder.append("  ");
    _builder.append("CompletableTraceRegion [myOffset=28, myLength=5, useForDebugging=false] associations={");
    _builder.newLine();
    _builder.append("    ");
    _builder.append("LocationData [TextRegionWithLineInformation [10:90][lineNumber=0, endLineNumber=0]][path=foo/mymodel.dsl]");
    _builder.newLine();
    _builder.append("  ");
    _builder.append("}");
    _builder.newLine();
    _builder.append("  ");
    _builder.append("CompletableTraceRegion [myOffset=47, myLength=5, useForDebugging=false] associations={");
    _builder.newLine();
    _builder.append("    ");
    _builder.append("LocationData [TextRegionWithLineInformation [11:89][lineNumber=0, endLineNumber=0]][path=foo/mymodel.dsl]");
    _builder.newLine();
    _builder.append("  ");
    _builder.append("}");
    _builder.newLine();
    _builder.append("  ");
    _builder.append("CompletableTraceRegion [myOffset=68, myLength=5, useForDebugging=false] associations={");
    _builder.newLine();
    _builder.append("    ");
    _builder.append("LocationData [TextRegionWithLineInformation [10:90][lineNumber=0, endLineNumber=0]][path=foo/mymodel.dsl]");
    _builder.newLine();
    _builder.append("  ");
    _builder.append("}");
    _builder.newLine();
    _builder.append("}");
    this.assertEquals(_builder.toString(), result.getTraceRegion().toString());
}
Also used : GeneratorNodeProcessor(org.eclipse.xtext.generator.trace.node.GeneratorNodeProcessor) LocationData(org.eclipse.xtext.generator.trace.LocationData) StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) CompositeGeneratorNode(org.eclipse.xtext.generator.trace.node.CompositeGeneratorNode) Test(org.junit.Test)

Example 7 with StringConcatenationClient

use of org.eclipse.xtend2.lib.StringConcatenationClient in project xtext-core by eclipse.

the class GeneratorNodeTest method testAppendVariants.

@Test
public void testAppendVariants() {
    final CompositeGeneratorNode node = new CompositeGeneratorNode();
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("* a simple string");
    final String string = _builder.toString();
    this.exts.append(node, string);
    this.exts.appendNewLine(node);
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("* a multi-line string concatenation embedding");
    _builder_1.newLine();
    _builder_1.append("  \t");
    _builder_1.append(string, "  \t");
    _builder_1.newLineIfNotEmpty();
    final StringConcatenation stringConcat1 = _builder_1;
    this.exts.append(node, stringConcat1);
    StringConcatenationClient _client = new StringConcatenationClient() {

        @Override
        protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
            _builder.append("* a string concatentation client embedding");
            _builder.newLine();
            _builder.append("  \t");
            _builder.append(stringConcat1, "  \t");
            _builder.newLineIfNotEmpty();
        }
    };
    final StringConcatenationClient client = _client;
    this.exts.append(node, client);
    final CompositeGeneratorNode nestedNode = new CompositeGeneratorNode();
    StringConcatenation _builder_2 = new StringConcatenation();
    _builder_2.append("* I can even embed");
    _builder_2.newLine();
    _builder_2.append("  \t");
    _builder_2.append(client, "  \t");
    _builder_2.newLineIfNotEmpty();
    _builder_2.append("  ");
    _builder_2.append("in a string concatenation");
    _builder_2.newLine();
    final StringConcatenation stringConcat2 = _builder_2;
    this.exts.append(nestedNode, stringConcat2);
    this.exts.append(node, nestedNode);
    final GeneratorNodeProcessor processor = new GeneratorNodeProcessor();
    StringConcatenation _builder_3 = new StringConcatenation();
    _builder_3.append("* a simple string");
    _builder_3.newLine();
    _builder_3.append("* a multi-line string concatenation embedding");
    _builder_3.newLine();
    _builder_3.append("  \t");
    _builder_3.append("* a simple string");
    _builder_3.newLine();
    _builder_3.append("* a string concatentation client embedding");
    _builder_3.newLine();
    _builder_3.append("  \t");
    _builder_3.append("* a multi-line string concatenation embedding");
    _builder_3.newLine();
    _builder_3.append("  \t  \t");
    _builder_3.append("* a simple string");
    _builder_3.newLine();
    _builder_3.append("* I can even embed");
    _builder_3.newLine();
    _builder_3.append("  \t");
    _builder_3.append("* a string concatentation client embedding");
    _builder_3.newLine();
    _builder_3.append("  \t  \t");
    _builder_3.append("* a multi-line string concatenation embedding");
    _builder_3.newLine();
    _builder_3.append("  \t  \t  \t");
    _builder_3.append("* a simple string");
    _builder_3.newLine();
    _builder_3.append("  ");
    _builder_3.append("in a string concatenation");
    _builder_3.newLine();
    this.assertEquals(_builder_3.toString(), processor.process(node).toString());
}
Also used : GeneratorNodeProcessor(org.eclipse.xtext.generator.trace.node.GeneratorNodeProcessor) StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) CompositeGeneratorNode(org.eclipse.xtext.generator.trace.node.CompositeGeneratorNode) Test(org.junit.Test)

Example 8 with StringConcatenationClient

use of org.eclipse.xtend2.lib.StringConcatenationClient in project xtext-core by eclipse.

the class TemplateNodeTest method testNull.

@Test
public void testNull() {
    final Object x = null;
    StringConcatenationClient _client = new StringConcatenationClient() {

        @Override
        protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
            _builder.append("fooo ");
            _builder.append(x);
            _builder.append("bar");
            _builder.newLineIfNotEmpty();
        }
    };
    this.assertEquals(_client);
}
Also used : StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) Test(org.junit.Test)

Example 9 with StringConcatenationClient

use of org.eclipse.xtend2.lib.StringConcatenationClient in project xtext-core by eclipse.

the class TemplateNodeTest method testSimpleTemplate_01.

@Test
public void testSimpleTemplate_01() {
    StringConcatenationClient _client = new StringConcatenationClient() {

        @Override
        protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
            String _multiLineString = TemplateNodeTest.this.multiLineString();
            _builder.append(_multiLineString);
            _builder.append(" ");
            String _multiLineString_1 = TemplateNodeTest.this.multiLineString();
            _builder.append(_multiLineString_1);
            _builder.newLineIfNotEmpty();
        }
    };
    this.assertEquals(_client);
}
Also used : StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) Test(org.junit.Test)

Example 10 with StringConcatenationClient

use of org.eclipse.xtend2.lib.StringConcatenationClient in project xtext-core by eclipse.

the class TemplateNodeTest method testNull_02.

@Test
public void testNull_02() {
    final Object x = null;
    StringConcatenationClient _client = new StringConcatenationClient() {

        @Override
        protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
            _builder.append("fooo");
            _builder.newLine();
            _builder.append("\t");
            _builder.append(x, "\t");
            _builder.newLineIfNotEmpty();
            _builder.append(" ");
            _builder.append("bar");
            _builder.newLine();
        }
    };
    this.assertEquals(_client);
}
Also used : StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) Test(org.junit.Test)

Aggregations

StringConcatenationClient (org.eclipse.xtend2.lib.StringConcatenationClient)194 TypeReference (org.eclipse.xtext.xtext.generator.model.TypeReference)119 GeneratedJavaFileAccess (org.eclipse.xtext.xtext.generator.model.GeneratedJavaFileAccess)24 GuiceModuleAccess (org.eclipse.xtext.xtext.generator.model.GuiceModuleAccess)24 Grammar (org.eclipse.xtext.Grammar)23 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)19 List (java.util.List)18 Test (org.junit.Test)18 Set (java.util.Set)14 JavaFileAccess (org.eclipse.xtext.xtext.generator.model.JavaFileAccess)12 ManifestAccess (org.eclipse.xtext.xtext.generator.model.ManifestAccess)12 EClass (org.eclipse.emf.ecore.EClass)11 EList (org.eclipse.emf.common.util.EList)10 AbstractRule (org.eclipse.xtext.AbstractRule)10 IGeneratorNode (org.eclipse.xtext.generator.trace.node.IGeneratorNode)10 EObject (org.eclipse.emf.ecore.EObject)9 IClassAnnotation (org.eclipse.xtext.xtext.generator.model.annotations.IClassAnnotation)9 Function1 (org.eclipse.xtext.xbase.lib.Functions.Function1)8 SuppressWarningsAnnotation (org.eclipse.xtext.xtext.generator.model.annotations.SuppressWarningsAnnotation)8 ArrayList (java.util.ArrayList)7