Java Code Examples for org.eclipse.xtend2.lib.StringConcatenation#toString()

The following examples show how to use org.eclipse.xtend2.lib.StringConcatenation#toString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OverriddenValueInspectorTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testBug280011_02() throws Exception {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("grammar org.foo with org.eclipse.xtext.common.Terminals");
  _builder.newLine();
  _builder.append("generate metamodel \'foo.sample\'");
  _builder.newLine();
  _builder.append("Q : \'x\' a = ID \'y\' b = ID ;");
  _builder.newLine();
  String grammarAsString = _builder.toString();
  final Grammar grammar = this.getGrammar(grammarAsString);
  AbstractRule _findRuleForName = GrammarUtil.findRuleForName(grammar, "Q");
  final ParserRule rule = ((ParserRule) _findRuleForName);
  this.validateRule(rule);
  Assert.assertTrue(this.warnings.toString(), this.warnings.isEmpty());
}
 
Example 2
Source File: OverriddenValueInspectorTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testUnassignedRule_01() throws Exception {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("grammar org.foo with org.eclipse.xtext.common.Terminals");
  _builder.newLine();
  _builder.append("generate metamodel \'foo.sample\'");
  _builder.newLine();
  _builder.append("First : Second name+=ID;");
  _builder.newLine();
  _builder.append("Second: name+=ID;");
  _builder.newLine();
  String grammarAsString = _builder.toString();
  final Grammar grammar = this.getGrammar(grammarAsString);
  AbstractRule _findRuleForName = GrammarUtil.findRuleForName(grammar, "First");
  final ParserRule rule = ((ParserRule) _findRuleForName);
  this.validateRule(rule);
  Assert.assertTrue(this.warnings.toString(), this.warnings.isEmpty());
}
 
Example 3
Source File: JavaConverterTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testCommentsCase_02() throws Exception {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("public class TestComment {");
  _builder.newLine();
  _builder.append("\t");
  _builder.append("String field = \"d\"; // last SL comment");
  _builder.newLine();
  _builder.append("}");
  String xtendCode = this.toXtendCode(_builder);
  StringConcatenation _builder_1 = new StringConcatenation();
  _builder_1.append("class TestComment {");
  _builder_1.newLine();
  _builder_1.append("\t");
  _builder_1.append("package String field=\"d\"// last SL comment");
  _builder_1.newLine();
  _builder_1.append("\t");
  _builder_1.newLine();
  _builder_1.append("}");
  final String expected = _builder_1.toString();
  Assert.assertEquals(expected, xtendCode);
}
 
Example 4
Source File: LiveShadowedAllContainerStateTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testEmptyProject() {
  try {
    final IProject project = IResourcesSetupUtil.createProject("MyProject");
    IResourcesSetupUtil.addNature(project, XtextProjectHelper.NATURE_ID);
    final ResourceSet rs = this.liveScopeResourceSetProvider.get(project);
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("container MyProject isEmpty=true {");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    final String expected = _builder.toString();
    Assert.assertEquals(expected, this.formatContainers(rs));
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 5
Source File: FinalFieldsConstructorCompilerTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testParameterListValidation() {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("import org.eclipse.xtend.lib.annotations.FinalFieldsConstructor");
    _builder.newLine();
    _builder.append("class C {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("val int a");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("@FinalFieldsConstructor new(String a) {}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    final String source = _builder.toString();
    this._validationTestHelper.assertError(this.clazz(source), XtendPackage.Literals.XTEND_CONSTRUCTOR, "user.issue", "Parameter list must be empty");
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 6
Source File: GrammarPDAProviderTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testUnassignedTerminalRule() {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("Rule: val=ID Called;");
  _builder.newLine();
  _builder.append("terminal Called: \'kw1\';");
  _builder.newLine();
  final String actual = this.toPda(_builder);
  StringConcatenation _builder_1 = new StringConcatenation();
  _builder_1.append("Rule:");
  _builder_1.newLine();
  _builder_1.append("\t");
  _builder_1.append("start -> val=ID");
  _builder_1.newLine();
  _builder_1.append("\t");
  _builder_1.append("Called -> stop");
  _builder_1.newLine();
  _builder_1.append("\t");
  _builder_1.append("val=ID -> Called");
  _builder_1.newLine();
  final String expected = _builder_1.toString();
  Assert.assertEquals(expected, actual);
}
 
Example 7
Source File: GrammarUtilTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testFindCurrentType_03() throws Exception {
  this.with(XtextStandaloneSetup.class);
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("grammar myLang with org.eclipse.xtext.common.Terminals");
  _builder.newLine();
  _builder.append("generate g \'http://1\'");
  _builder.newLine();
  _builder.append("Rule:");
  _builder.newLine();
  _builder.append("\t");
  _builder.append("Fragment;");
  _builder.newLine();
  _builder.append("fragment Fragment: name=ID SecondFragment;");
  _builder.newLine();
  _builder.append("fragment SecondFragment: {SubRule.named=current} value=ID;");
  _builder.newLine();
  String model = _builder.toString();
  final XtextResource r = this.getResourceFromString(model);
  EObject _get = r.getContents().get(0);
  final Grammar grammar = ((Grammar) _get);
  final AbstractRule rule = IterableExtensions.<AbstractRule>head(grammar.getRules());
  final AbstractElement fragmentCall = rule.getAlternatives();
  final EClassifier currentType = GrammarUtil.findCurrentType(fragmentCall);
  Assert.assertEquals("SubRule", currentType.getName());
}
 
Example 8
Source File: NewDataCompilerTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testVariable() {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("import org.eclipse.xtend.lib.annotations.Data");
    _builder.newLine();
    _builder.append("@Data class Foo {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("var foo = 3");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    final String text = _builder.toString();
    this._validationTestHelper.assertError(this.clazz(text), XtendPackage.Literals.XTEND_FIELD, "user.issue", "\'var\'");
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 9
Source File: IndentationAwarePartialParsingErrorTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testResourceUpdate() {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("a");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("b // single tab");
    _builder.newLine();
    _builder.append("         ");
    _builder.append("// 8 spaces eq 1 tab");
    _builder.newLine();
    _builder.append("d");
    _builder.newLine();
    final String model = _builder.toString();
    final Tree tree = this.parseHelper.parse(model);
    Resource _eResource = tree.eResource();
    final XtextResource resource = ((XtextResource) _eResource);
    final int idx = model.indexOf(" // 8");
    resource.update(idx, 0, "c");
    EObject _head = IterableExtensions.<EObject>head(resource.getContents());
    final Tree reparsed = ((Tree) _head);
    Assert.assertNotSame(tree, reparsed);
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 10
Source File: IndentationAwarePartialParsingErrorTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testResourceUpdate_02() {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("a");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("x");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("b // two tabs");
    _builder.newLine();
    _builder.append("\t         ");
    _builder.append("// tab and 8 spaces (eq 2 tabs)");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("y");
    _builder.newLine();
    final String model = _builder.toString();
    final Tree tree = this.parseHelper.parse(model);
    Resource _eResource = tree.eResource();
    final XtextResource resource = ((XtextResource) _eResource);
    final int idx = model.indexOf(" // tab");
    resource.update(idx, 0, "c");
    EObject _head = IterableExtensions.<EObject>head(resource.getContents());
    final Tree reparsed = ((Tree) _head);
    Assert.assertNotSame(tree, reparsed);
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 11
Source File: AbstractLanguageServerTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected String _toExpectation(final Hover it) {
  StringConcatenation _builder = new StringConcatenation();
  String _expectation = this.toExpectation(it.getRange());
  _builder.append(_expectation);
  _builder.newLineIfNotEmpty();
  String _expectation_1 = this.toExpectation(it.getContents());
  _builder.append(_expectation_1);
  _builder.newLineIfNotEmpty();
  return _builder.toString();
}
 
Example 12
Source File: Xtext2EcoreTransformerTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testBug_272566_2() throws Exception {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("grammar test with org.eclipse.xtext.common.Terminals");
  _builder.newLine();
  _builder.append("generate test \'http://test\'");
  _builder.newLine();
  _builder.append("Model:");
  _builder.newLine();
  _builder.append("   ");
  _builder.append("test=Test");
  _builder.newLine();
  _builder.append(";");
  _builder.newLine();
  _builder.newLine();
  _builder.append("Test:");
  _builder.newLine();
  _builder.append("   ");
  _builder.append("\"keyword\" FooBar name=ID");
  _builder.newLine();
  _builder.append(";");
  _builder.newLine();
  _builder.append("FooBar:");
  _builder.newLine();
  _builder.append("\t");
  _builder.append("\'zonk\' WS WS INT WS;");
  _builder.newLine();
  String grammar = _builder.toString();
  final XtextResource resource = this.getResourceFromString(grammar);
  Assert.assertTrue(resource.getErrors().toString(), resource.getErrors().isEmpty());
}
 
Example 13
Source File: FormatterStubGenerator.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
public String getStubFileName() {
  StringConcatenation _builder = new StringConcatenation();
  String _asPath = this.service.naming.asPath(this.getStubQualifiedName());
  _builder.append(_asPath);
  _builder.append(".xtend");
  return _builder.toString();
}
 
Example 14
Source File: GrammarPDAProviderTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testTwoAssignedEObjectRuleCalls() {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("Rule: foo1=Sub foo2=Sub; Sub: id=\'id\';");
  _builder.newLine();
  final String actual = this.toPda(_builder);
  StringConcatenation _builder_1 = new StringConcatenation();
  _builder_1.append("Rule:");
  _builder_1.newLine();
  _builder_1.append("\t");
  _builder_1.append("start -> foo1=Sub");
  _builder_1.newLine();
  _builder_1.append("\t");
  _builder_1.append("foo1=Sub -> foo2=Sub");
  _builder_1.newLine();
  _builder_1.append("\t");
  _builder_1.append("foo2=Sub -> stop");
  _builder_1.newLine();
  _builder_1.append("Sub:");
  _builder_1.newLine();
  _builder_1.append("\t");
  _builder_1.append("start -> id=\'id\'");
  _builder_1.newLine();
  _builder_1.append("\t");
  _builder_1.append("id=\'id\' -> stop");
  _builder_1.newLine();
  final String expected = _builder_1.toString();
  Assert.assertEquals(expected, actual);
}
 
Example 15
Source File: AntlrGrammarComparatorTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void snippetMatch02() {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("((\t\'abstract\' ");
  _builder.newLine();
  _builder.append(" ");
  _builder.append("| \t\'annotation\' ");
  _builder.newLine();
  _builder.append(" ");
  _builder.append("| \t\'class\' ");
  _builder.newLine();
  _builder.append(" ");
  _builder.append("| \t\'(\' ");
  _builder.newLine();
  _builder.append(" ");
  _builder.append("|  RULE_ID | \tRULE_HEX )");
  _builder.newLine();
  final String expected = _builder.toString();
  StringConcatenation _builder_1 = new StringConcatenation();
  _builder_1.append("(");
  _builder_1.newLine();
  _builder_1.append("\t");
  _builder_1.append("(\'abstract\' | \'annotation\' | \'class\' | \'(\' | RULE_ID | RULE_HEX )");
  _builder_1.newLine();
  final String testee = _builder_1.toString();
  this._antlrGrammarComparatorTestHelper.compare(testee, expected);
}
 
Example 16
Source File: JavaDocContentAssistTest.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public String apply() {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("<|>");
  return _builder.toString();
}
 
Example 17
Source File: ResourceStorageTest.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
@Test
public void testWriteAndLoad() {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("package foo");
    _builder.newLine();
    _builder.newLine();
    _builder.append("class Bar {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("def dispatch myMethod(String s) {}");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("/**");
    _builder.newLine();
    _builder.append("\t ");
    _builder.append("* Hello myMethod ");
    _builder.newLine();
    _builder.append("\t ");
    _builder.append("*/");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("def dispatch myMethod(CharSequence cs) {}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    _builder.append("class Foo {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("def dispatch other(String it) {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("var x = \"\"");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("x = length.toString");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("println(x)");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    final String contents = _builder.toString();
    final XtendFile file = this.file(contents);
    final ByteArrayOutputStream bout = new ByteArrayOutputStream();
    ((ResourceStorageFacade) this.resourceStorageFacade).setStoreNodeModel(true);
    Resource _eResource = file.eResource();
    this.resourceStorageFacade.createResourceStorageWritable(bout).writeResource(((StorageAwareResource) _eResource));
    byte[] _byteArray = bout.toByteArray();
    ByteArrayInputStream _byteArrayInputStream = new ByteArrayInputStream(_byteArray);
    final ResourceStorageLoadable in = this.resourceStorageFacade.createResourceStorageLoadable(_byteArrayInputStream);
    Resource _createResource = file.eResource().getResourceSet().createResource(URI.createURI("synthetic:/test/MyClass.xtend"));
    final StorageAwareResource resource = ((StorageAwareResource) _createResource);
    final InMemoryURIConverter converter = new InMemoryURIConverter();
    converter.addModel(resource.getURI().toString(), contents);
    ResourceSet _resourceSet = resource.getResourceSet();
    _resourceSet.setURIConverter(converter);
    EList<Resource> _resources = file.eResource().getResourceSet().getResources();
    _resources.add(resource);
    resource.loadFromStorage(in);
    EObject _get = resource.getContents().get(1);
    final JvmGenericType jvmClass = ((JvmGenericType) _get);
    Assert.assertEquals("java.lang.CharSequence", IterableExtensions.<JvmFormalParameter>head((((JvmOperation[])Conversions.unwrapArray(jvmClass.getDeclaredOperations(), JvmOperation.class))[2]).getParameters()).getParameterType().getQualifiedName());
    Assert.assertEquals("java.lang.Object", (((JvmOperation[])Conversions.unwrapArray(jvmClass.getDeclaredOperations(), JvmOperation.class))[2]).getReturnType().getQualifiedName());
    Assert.assertEquals("Hello myMethod", IterableExtensions.<DocumentationAdapter>head(Iterables.<DocumentationAdapter>filter((((JvmOperation[])Conversions.unwrapArray(jvmClass.getDeclaredOperations(), JvmOperation.class))[1]).eAdapters(), DocumentationAdapter.class)).getDocumentation());
    Assert.assertEquals(resource.getURI(), resource.getResourceDescription().getURI());
    Assert.assertEquals(2, IterableExtensions.size(resource.getResourceDescription().getExportedObjects()));
    Assert.assertEquals("foo.Bar", IterableExtensions.<IEObjectDescription>head(resource.getResourceDescription().getExportedObjects()).getQualifiedName().toString());
    final BidiTreeIterator<INode> restoredNodes = NodeModelUtils.findActualNodeFor(IterableExtensions.<EObject>head(resource.getContents())).getAsTreeIterable().iterator();
    final BidiTreeIterator<INode> originalNodes = NodeModelUtils.findActualNodeFor(file).getAsTreeIterable().iterator();
    while (restoredNodes.hasNext()) {
      {
        final INode rest = restoredNodes.next();
        final INode orig = originalNodes.next();
        Assert.assertEquals(orig.getStartLine(), rest.getStartLine());
        Assert.assertEquals(orig.getEndLine(), rest.getEndLine());
        Assert.assertEquals(orig.getOffset(), rest.getOffset());
        Assert.assertEquals(orig.getEndOffset(), rest.getEndOffset());
        Assert.assertEquals(orig.getLength(), rest.getLength());
        Assert.assertEquals(orig.getTotalStartLine(), rest.getTotalStartLine());
        Assert.assertEquals(orig.getTotalEndLine(), rest.getTotalEndLine());
        Assert.assertEquals(orig.getTotalOffset(), rest.getTotalOffset());
        Assert.assertEquals(orig.getTotalEndOffset(), rest.getTotalEndOffset());
        Assert.assertEquals(orig.getTotalLength(), rest.getTotalLength());
        Assert.assertSame(orig.getGrammarElement(), rest.getGrammarElement());
        Assert.assertEquals(file.eResource().getURIFragment(orig.getSemanticElement()), resource.getURIFragment(rest.getSemanticElement()));
        Assert.assertEquals(orig.getText(), rest.getText());
      }
    }
    Assert.assertFalse(originalNodes.hasNext());
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 18
Source File: AntlrGrammarGenerator.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Override
protected String compileParserImports(final Grammar it, final AntlrOptions options) {
  StringConcatenation _builder = new StringConcatenation();
  _builder.newLine();
  _builder.append("import org.eclipse.xtext.*;");
  _builder.newLine();
  _builder.append("import org.eclipse.xtext.parser.*;");
  _builder.newLine();
  _builder.append("import org.eclipse.xtext.parser.impl.*;");
  _builder.newLine();
  _builder.append("import org.eclipse.emf.ecore.util.EcoreUtil;");
  _builder.newLine();
  _builder.append("import org.eclipse.emf.ecore.EObject;");
  _builder.newLine();
  {
    boolean _isEmpty = GrammarUtil.allEnumRules(it).isEmpty();
    boolean _not = (!_isEmpty);
    if (_not) {
      _builder.append("import org.eclipse.emf.common.util.Enumerator;");
      _builder.newLine();
    }
  }
  _builder.append("import ");
  String _name = this.getGrammarNaming().getInternalParserSuperClass(it).getName();
  _builder.append(_name);
  _builder.append(";");
  _builder.newLineIfNotEmpty();
  _builder.append("import org.eclipse.xtext.parser.antlr.XtextTokenStream;");
  _builder.newLine();
  _builder.append("import org.eclipse.xtext.parser.antlr.XtextTokenStream.HiddenTokens;");
  _builder.newLine();
  {
    if (((!IterableExtensions.isEmpty(Iterables.<UnorderedGroup>filter((Iterables.<EObject>concat(ListExtensions.<ParserRule, List<EObject>>map(GrammarUtil.allParserRules(it), ((Function1<ParserRule, List<EObject>>) (ParserRule it_1) -> {
      return EcoreUtil2.eAllContentsAsList(it_1);
    })))), UnorderedGroup.class))) && options.isBacktrack())) {
      _builder.append("import org.eclipse.xtext.parser.antlr.IUnorderedGroupHelper.UnorderedGroupState;");
      _builder.newLine();
    }
  }
  _builder.append("import org.eclipse.xtext.parser.antlr.AntlrDatatypeRuleToken;");
  _builder.newLine();
  _builder.append("import ");
  String _name_1 = this._grammarAccessExtensions.getGrammarAccess(it).getName();
  _builder.append(_name_1);
  _builder.append(";");
  _builder.newLineIfNotEmpty();
  _builder.newLine();
  return _builder.toString();
}
 
Example 19
Source File: RuleEngineContentAssistTest.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public String apply() {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("<|>");
  return _builder.toString();
}
 
Example 20
Source File: AbstractLanguageServerTest.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
protected String _toExpectation(final Integer it) {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append(it);
  return _builder.toString();
}