Search in sources :

Example 11 with StringConcatenationClient

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

the class TemplateNodeTest method testIndentedIf.

@Test
public void testIndentedIf() {
    final boolean condition = true;
    final String string = "foo";
    StringConcatenationClient _client = new StringConcatenationClient() {

        @Override
        protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
            _builder.append("Very wise:");
            _builder.newLine();
            {
                if (condition) {
                    _builder.append("\t");
                    _builder.append("who ");
                    _builder.append(string, "\t");
                    _builder.append(" do");
                    _builder.newLineIfNotEmpty();
                }
            }
        }
    };
    this.assertEquals(_client);
}
Also used : StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) Test(org.junit.Test)

Example 12 with StringConcatenationClient

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

the class TemplateNodeTest method testSeparatorLoop.

@Test
public void testSeparatorLoop() {
    final List<String> strings = Collections.<String>unmodifiableList(CollectionLiterals.<String>newArrayList("a", "b", "c"));
    StringConcatenationClient _client = new StringConcatenationClient() {

        @Override
        protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
            {
                boolean _hasElements = false;
                for (final String s : strings) {
                    if (!_hasElements) {
                        _hasElements = true;
                    } else {
                        _builder.appendImmediate(", ", "");
                    }
                    _builder.append("\"");
                    _builder.append(s);
                    _builder.append("\"");
                }
            }
            _builder.newLineIfNotEmpty();
        }
    };
    this.assertEquals(_client);
}
Also used : StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) Test(org.junit.Test)

Example 13 with StringConcatenationClient

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

the class TemplateNodeTest method testSeparatorLoopWithWhitespace3.

@Test
public void testSeparatorLoopWithWhitespace3() {
    final List<String> strings = Collections.<String>unmodifiableList(CollectionLiterals.<String>newArrayList("a", "b", "c"));
    StringConcatenationClient _client = new StringConcatenationClient() {

        @Override
        protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
            {
                boolean _hasElements = false;
                for (final String s : strings) {
                    if (!_hasElements) {
                        _hasElements = true;
                    } else {
                        _builder.appendImmediate(",", "");
                    }
                    _builder.newLine();
                    _builder.append(s);
                    _builder.append(" ");
                    _builder.newLineIfNotEmpty();
                    _builder.newLine();
                }
            }
        }
    };
    this.assertEquals(_client);
}
Also used : StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) Test(org.junit.Test)

Example 14 with StringConcatenationClient

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

the class TracingSugarTest method testCodeGenerationWithDebug.

@Test
public void testCodeGenerationWithDebug() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("type String {}");
        _builder.newLine();
        _builder.append("type Foo {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("String name;");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final Model root = this.parseHelper.parse(LineDelimiters.toUnix(_builder.toString()));
        final InMemoryFileSystemAccess fsa = new InMemoryFileSystemAccess();
        StringConcatenationClient _client = new StringConcatenationClient() {

            @Override
            protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
                {
                    EList<Type> _types = root.getTypes();
                    for (final Type t : _types) {
                        IGeneratorNode __generateTypeWithDebugging = TracingSugarTest.this._generateTypeWithDebugging(t);
                        _builder.append(__generateTypeWithDebugging);
                        _builder.newLineIfNotEmpty();
                    }
                }
            }
        };
        this._myExtensions.generateTracedFile(fsa, "foo/bar.txt", root, _client);
        final CharSequence generated = fsa.getTextFiles().get((IFileSystemAccess.DEFAULT_OUTPUT + "foo/bar.txt"));
        StringConcatenation _builder_1 = new StringConcatenation();
        {
            EList<Type> _types = root.getTypes();
            for (final Type t : _types) {
                CharSequence _generateTypeWithDebugging = this.generateTypeWithDebugging(t);
                _builder_1.append(_generateTypeWithDebugging);
                _builder_1.newLineIfNotEmpty();
            }
        }
        Assert.assertEquals(LineDelimiters.toUnix(_builder_1.toString()), generated.toString());
        final AbstractTraceRegion trace = ((ITraceRegionProvider) generated).getTraceRegion();
        StringConcatenation _builder_2 = new StringConcatenation();
        _builder_2.append("CompletableTraceRegion [myOffset=0, myLength=55, useForDebugging=false] associations={");
        _builder_2.newLine();
        _builder_2.append("  ");
        _builder_2.append("LocationData [TextRegionWithLineInformation [0:41][lineNumber=0, endLineNumber=3]][path=__synthetic0.lazylinkingtestlanguage]");
        _builder_2.newLine();
        _builder_2.append("} nestedRegions={");
        _builder_2.newLine();
        _builder_2.append("  ");
        _builder_2.append("CompletableTraceRegion [myOffset=0, myLength=17, useForDebugging=true] associations={");
        _builder_2.newLine();
        _builder_2.append("    ");
        _builder_2.append("LocationData [TextRegionWithLineInformation [0:14][lineNumber=0, endLineNumber=0]][path=__synthetic0.lazylinkingtestlanguage]");
        _builder_2.newLine();
        _builder_2.append("  ");
        _builder_2.append("} nestedRegions={");
        _builder_2.newLine();
        _builder_2.append("    ");
        _builder_2.append("CompletableTraceRegion [myOffset=6, myLength=6, useForDebugging=false] associations={");
        _builder_2.newLine();
        _builder_2.append("      ");
        _builder_2.append("LocationData [TextRegionWithLineInformation [5:6][lineNumber=0, endLineNumber=0]][path=__synthetic0.lazylinkingtestlanguage]");
        _builder_2.newLine();
        _builder_2.append("    ");
        _builder_2.append("}");
        _builder_2.newLine();
        _builder_2.append("  ");
        _builder_2.append("}");
        _builder_2.newLine();
        _builder_2.append("  ");
        _builder_2.append("CompletableTraceRegion [myOffset=17, myLength=38, useForDebugging=true] associations={");
        _builder_2.newLine();
        _builder_2.append("    ");
        _builder_2.append("LocationData [TextRegionWithLineInformation [15:26][lineNumber=1, endLineNumber=3]][path=__synthetic0.lazylinkingtestlanguage]");
        _builder_2.newLine();
        _builder_2.append("  ");
        _builder_2.append("} nestedRegions={");
        _builder_2.newLine();
        _builder_2.append("    ");
        _builder_2.append("CompletableTraceRegion [myOffset=23, myLength=3, useForDebugging=false] associations={");
        _builder_2.newLine();
        _builder_2.append("      ");
        _builder_2.append("LocationData [TextRegionWithLineInformation [20:3][lineNumber=1, endLineNumber=1]][path=__synthetic0.lazylinkingtestlanguage]");
        _builder_2.newLine();
        _builder_2.append("    ");
        _builder_2.append("}");
        _builder_2.newLine();
        _builder_2.append("    ");
        _builder_2.append("CompletableTraceRegion [myOffset=30, myLength=24, useForDebugging=false] associations={");
        _builder_2.newLine();
        _builder_2.append("      ");
        _builder_2.append("LocationData [TextRegionWithLineInformation [27:12][lineNumber=2, endLineNumber=2]][path=__synthetic0.lazylinkingtestlanguage]");
        _builder_2.newLine();
        _builder_2.append("    ");
        _builder_2.append("} nestedRegions={");
        _builder_2.newLine();
        _builder_2.append("      ");
        _builder_2.append("CompletableTraceRegion [myOffset=39, myLength=4, useForDebugging=false] associations={");
        _builder_2.newLine();
        _builder_2.append("        ");
        _builder_2.append("LocationData [TextRegionWithLineInformation [34:4][lineNumber=2, endLineNumber=2]][path=__synthetic0.lazylinkingtestlanguage]");
        _builder_2.newLine();
        _builder_2.append("      ");
        _builder_2.append("}");
        _builder_2.newLine();
        _builder_2.append("      ");
        _builder_2.append("CompletableTraceRegion [myOffset=46, myLength=6, useForDebugging=false] associations={");
        _builder_2.newLine();
        _builder_2.append("        ");
        _builder_2.append("LocationData [TextRegionWithLineInformation [27:6][lineNumber=2, endLineNumber=2]][path=__synthetic0.lazylinkingtestlanguage]");
        _builder_2.newLine();
        _builder_2.append("      ");
        _builder_2.append("}");
        _builder_2.newLine();
        _builder_2.append("    ");
        _builder_2.append("}");
        _builder_2.newLine();
        _builder_2.append("  ");
        _builder_2.append("}");
        _builder_2.newLine();
        _builder_2.append("}");
        Assert.assertEquals(LineDelimiters.toUnix(_builder_2.toString()), trace.toString());
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : IGeneratorNode(org.eclipse.xtext.generator.trace.node.IGeneratorNode) Type(org.eclipse.xtext.linking.lazy.lazyLinking.Type) EList(org.eclipse.emf.common.util.EList) StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Model(org.eclipse.xtext.linking.lazy.lazyLinking.Model) AbstractTraceRegion(org.eclipse.xtext.generator.trace.AbstractTraceRegion) InMemoryFileSystemAccess(org.eclipse.xtext.generator.InMemoryFileSystemAccess) ITraceRegionProvider(org.eclipse.xtext.generator.trace.ITraceRegionProvider) Test(org.junit.Test)

Example 15 with StringConcatenationClient

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

the class TracingSugarTest method testCodeGeneration.

@Test
public void testCodeGeneration() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("type String {}");
        _builder.newLine();
        _builder.append("type Foo {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("String name;");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final Model root = this.parseHelper.parse(LineDelimiters.toUnix(_builder.toString()));
        final InMemoryFileSystemAccess fsa = new InMemoryFileSystemAccess();
        StringConcatenationClient _client = new StringConcatenationClient() {

            @Override
            protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
                {
                    EList<Type> _types = root.getTypes();
                    for (final Type t : _types) {
                        IGeneratorNode __generateType = TracingSugarTest.this._generateType(t);
                        _builder.append(__generateType);
                        _builder.newLineIfNotEmpty();
                    }
                }
            }
        };
        this._myExtensions.generateTracedFile(fsa, "foo/bar.txt", root, _client);
        final CharSequence generated = fsa.getTextFiles().get((IFileSystemAccess.DEFAULT_OUTPUT + "foo/bar.txt"));
        StringConcatenation _builder_1 = new StringConcatenation();
        {
            EList<Type> _types = root.getTypes();
            for (final Type t : _types) {
                CharSequence _generateType = this.generateType(t);
                _builder_1.append(_generateType);
                _builder_1.newLineIfNotEmpty();
            }
        }
        Assert.assertEquals(LineDelimiters.toUnix(_builder_1.toString()), generated.toString());
        final AbstractTraceRegion trace = ((ITraceRegionProvider) generated).getTraceRegion();
        StringConcatenation _builder_2 = new StringConcatenation();
        _builder_2.append("CompletableTraceRegion [myOffset=0, myLength=55, useForDebugging=false] associations={");
        _builder_2.newLine();
        _builder_2.append("  ");
        _builder_2.append("LocationData [TextRegionWithLineInformation [0:41][lineNumber=0, endLineNumber=3]][path=__synthetic0.lazylinkingtestlanguage]");
        _builder_2.newLine();
        _builder_2.append("} nestedRegions={");
        _builder_2.newLine();
        _builder_2.append("  ");
        _builder_2.append("CompletableTraceRegion [myOffset=0, myLength=17, useForDebugging=false] associations={");
        _builder_2.newLine();
        _builder_2.append("    ");
        _builder_2.append("LocationData [TextRegionWithLineInformation [0:14][lineNumber=0, endLineNumber=0]][path=__synthetic0.lazylinkingtestlanguage]");
        _builder_2.newLine();
        _builder_2.append("  ");
        _builder_2.append("} nestedRegions={");
        _builder_2.newLine();
        _builder_2.append("    ");
        _builder_2.append("CompletableTraceRegion [myOffset=6, myLength=6, useForDebugging=false] associations={");
        _builder_2.newLine();
        _builder_2.append("      ");
        _builder_2.append("LocationData [TextRegionWithLineInformation [5:6][lineNumber=0, endLineNumber=0]][path=__synthetic0.lazylinkingtestlanguage]");
        _builder_2.newLine();
        _builder_2.append("    ");
        _builder_2.append("}");
        _builder_2.newLine();
        _builder_2.append("  ");
        _builder_2.append("}");
        _builder_2.newLine();
        _builder_2.append("  ");
        _builder_2.append("CompletableTraceRegion [myOffset=17, myLength=38, useForDebugging=false] associations={");
        _builder_2.newLine();
        _builder_2.append("    ");
        _builder_2.append("LocationData [TextRegionWithLineInformation [15:26][lineNumber=1, endLineNumber=3]][path=__synthetic0.lazylinkingtestlanguage]");
        _builder_2.newLine();
        _builder_2.append("  ");
        _builder_2.append("} nestedRegions={");
        _builder_2.newLine();
        _builder_2.append("    ");
        _builder_2.append("CompletableTraceRegion [myOffset=23, myLength=3, useForDebugging=false] associations={");
        _builder_2.newLine();
        _builder_2.append("      ");
        _builder_2.append("LocationData [TextRegionWithLineInformation [20:3][lineNumber=1, endLineNumber=1]][path=__synthetic0.lazylinkingtestlanguage]");
        _builder_2.newLine();
        _builder_2.append("    ");
        _builder_2.append("}");
        _builder_2.newLine();
        _builder_2.append("    ");
        _builder_2.append("CompletableTraceRegion [myOffset=30, myLength=24, useForDebugging=false] associations={");
        _builder_2.newLine();
        _builder_2.append("      ");
        _builder_2.append("LocationData [TextRegionWithLineInformation [27:12][lineNumber=2, endLineNumber=2]][path=__synthetic0.lazylinkingtestlanguage]");
        _builder_2.newLine();
        _builder_2.append("    ");
        _builder_2.append("} nestedRegions={");
        _builder_2.newLine();
        _builder_2.append("      ");
        _builder_2.append("CompletableTraceRegion [myOffset=39, myLength=4, useForDebugging=false] associations={");
        _builder_2.newLine();
        _builder_2.append("        ");
        _builder_2.append("LocationData [TextRegionWithLineInformation [34:4][lineNumber=2, endLineNumber=2]][path=__synthetic0.lazylinkingtestlanguage]");
        _builder_2.newLine();
        _builder_2.append("      ");
        _builder_2.append("}");
        _builder_2.newLine();
        _builder_2.append("      ");
        _builder_2.append("CompletableTraceRegion [myOffset=46, myLength=6, useForDebugging=false] associations={");
        _builder_2.newLine();
        _builder_2.append("        ");
        _builder_2.append("LocationData [TextRegionWithLineInformation [27:6][lineNumber=2, endLineNumber=2]][path=__synthetic0.lazylinkingtestlanguage]");
        _builder_2.newLine();
        _builder_2.append("      ");
        _builder_2.append("}");
        _builder_2.newLine();
        _builder_2.append("    ");
        _builder_2.append("}");
        _builder_2.newLine();
        _builder_2.append("  ");
        _builder_2.append("}");
        _builder_2.newLine();
        _builder_2.append("}");
        Assert.assertEquals(LineDelimiters.toUnix(_builder_2.toString()), trace.toString());
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : IGeneratorNode(org.eclipse.xtext.generator.trace.node.IGeneratorNode) Type(org.eclipse.xtext.linking.lazy.lazyLinking.Type) EList(org.eclipse.emf.common.util.EList) StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Model(org.eclipse.xtext.linking.lazy.lazyLinking.Model) AbstractTraceRegion(org.eclipse.xtext.generator.trace.AbstractTraceRegion) InMemoryFileSystemAccess(org.eclipse.xtext.generator.InMemoryFileSystemAccess) ITraceRegionProvider(org.eclipse.xtext.generator.trace.ITraceRegionProvider) 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