Java Code Examples for org.eclipse.xtext.xbase.lib.IterableExtensions#sort()

The following examples show how to use org.eclipse.xtext.xbase.lib.IterableExtensions#sort() . 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: JFlexGeneratorFragmentTemplate.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
public String tokens(final Grammar it) {
  ArrayList<String> allKeywords = CollectionLiterals.<String>newArrayList();
  List<ParserRule> _allParserRules = GrammarUtil.allParserRules(it);
  for (final ParserRule r : _allParserRules) {
    this.collectTokens(r, allKeywords);
  }
  List<EnumRule> _allEnumRules = GrammarUtil.allEnumRules(it);
  for (final EnumRule r_1 : _allEnumRules) {
    this.collectTokens(r_1, allKeywords);
  }
  StringConcatenation _builder = new StringConcatenation();
  {
    List<String> _sort = IterableExtensions.<String>sort(allKeywords);
    for(final String k : _sort) {
      CharSequence _state = this.state(k);
      _builder.append(_state);
      _builder.newLineIfNotEmpty();
    }
  }
  return _builder.toString();
}
 
Example 2
Source File: LspExtensionTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testExtension_readIndex() {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("type C {");
    _builder.newLine();
    _builder.append("  ");
    _builder.append("op baz() { }");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    _builder.append("type A {");
    _builder.newLine();
    _builder.append("  ");
    _builder.append("op foo() { }");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    _builder.append("type B {");
    _builder.newLine();
    _builder.append("  ");
    _builder.append("op bar() { }");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    this.writeFile("model.testlang", _builder);
    this.initialize();
    final TestLangLSPExtension ext = ServiceEndpoints.<TestLangLSPExtension>toServiceObject(this.languageServer, TestLangLSPExtension.class);
    final List<String> actual = IterableExtensions.<String>sort(IterableExtensions.<String>toList(ext.getAllOpNames().get()));
    Assert.assertEquals(Collections.<String>unmodifiableList(CollectionLiterals.<String>newArrayList("bar", "baz", "foo")), actual);
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 3
Source File: JavaFileAccess.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public CharSequence getContent() {
  StringConcatenation _builder = new StringConcatenation();
  String _fileHeader = this.codeConfig.getFileHeader();
  _builder.append(_fileHeader);
  _builder.newLineIfNotEmpty();
  _builder.append("package ");
  String _packageName = this.javaType.getPackageName();
  _builder.append(_packageName);
  {
    boolean _appendSemicolons = this.appendSemicolons();
    if (_appendSemicolons) {
      _builder.append(";");
    }
  }
  _builder.newLineIfNotEmpty();
  _builder.newLine();
  {
    List<String> _sort = IterableExtensions.<String>sort(IterableExtensions.<String>toSet(this.imports.values()));
    for(final String importName : _sort) {
      _builder.append("import ");
      _builder.append(importName);
      {
        boolean _appendSemicolons_1 = this.appendSemicolons();
        if (_appendSemicolons_1) {
          _builder.append(";");
        }
      }
      _builder.newLineIfNotEmpty();
    }
  }
  _builder.newLine();
  CharSequence _internalContent = this.getInternalContent();
  _builder.append(_internalContent);
  _builder.newLineIfNotEmpty();
  return _builder;
}
 
Example 4
Source File: SerializerFragment2.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
private StringConcatenationClient genCondition(final List<ISerializationContext> contexts, final IGrammarConstraintProvider.IConstraint constraint, final Multimap<EObject, IGrammarConstraintProvider.IConstraint> ctx2ctr) {
  StringConcatenationClient _xblockexpression = null;
  {
    final List<ISerializationContext> sorted = IterableExtensions.<ISerializationContext>sort(contexts);
    final LinkedHashMultimap<EObject, ISerializationContext> index = LinkedHashMultimap.<EObject, ISerializationContext>create();
    final Consumer<ISerializationContext> _function = (ISerializationContext it) -> {
      index.put(this.getContextObject(it), it);
    };
    sorted.forEach(_function);
    StringConcatenationClient _client = new StringConcatenationClient() {
      @Override
      protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
        {
          Set<EObject> _keySet = index.keySet();
          boolean _hasElements = false;
          for(final EObject obj : _keySet) {
            if (!_hasElements) {
              _hasElements = true;
            } else {
              _builder.appendImmediate("\n\t\t|| ", "");
            }
            StringConcatenationClient _genObjectSelector = SerializerFragment2.this.genObjectSelector(obj);
            _builder.append(_genObjectSelector);
            {
              int _size = ctx2ctr.get(obj).size();
              boolean _greaterThan = (_size > 1);
              if (_greaterThan) {
                StringConcatenationClient _genParameterSelector = SerializerFragment2.this.genParameterSelector(obj, index.get(obj), constraint);
                _builder.append(_genParameterSelector);
              }
            }
          }
        }
      }
    };
    _xblockexpression = _client;
  }
  return _xblockexpression;
}
 
Example 5
Source File: IEditorHighlightingConfigurationProvider.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
public Iterable<String> getKeywords() {
	Set<String> result = new HashSet<>();
	for (Keyword k : GrammarUtil.containedKeywords(grammarAccess.getGrammar())) {
		if (Character.isLetter(k.getValue().charAt(0))) {
			result.add(k.getValue());
		}
	}
	return IterableExtensions.sort(result);
}