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

The following examples show how to use org.eclipse.xtext.xbase.lib.IterableExtensions#sortBy() . 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
protected List<XClosure> findClosures(final CharSequence expression) {
  try {
    final String expressionAsString = expression.toString().replace("ClosureTypeResolutionTestData", "org.eclipse.xtext.xbase.tests.typesystem.ClosureTypeResolutionTestData").replace("$$", "org::eclipse::xtext::xbase::lib::");
    final XExpression xExpression = this.expression(expressionAsString, false);
    final List<XClosure> Closures = IteratorExtensions.<XClosure>toList(Iterators.<XClosure>filter(EcoreUtil2.eAll(xExpression), XClosure.class));
    final Function1<XClosure, Integer> _function = (XClosure it) -> {
      return Integer.valueOf(NodeModelUtils.findActualNodeFor(it).getOffset());
    };
    return IterableExtensions.<XClosure, Integer>sortBy(Closures, _function);
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 2
protected List<XAbstractFeatureCall> findFeatureCalls(final CharSequence expression) {
  try {
    final XExpression xExpression = this.expression(expression, false);
    final List<XAbstractFeatureCall> featureCalls = IteratorExtensions.<XAbstractFeatureCall>toList(Iterators.<XAbstractFeatureCall>filter(EcoreUtil2.eAll(xExpression), XAbstractFeatureCall.class));
    final Function1<XAbstractFeatureCall, Integer> _function = (XAbstractFeatureCall it) -> {
      return Integer.valueOf(IterableExtensions.<INode>head(NodeModelUtils.findNodesForFeature(it, XbasePackage.Literals.XABSTRACT_FEATURE_CALL__FEATURE)).getOffset());
    };
    return IterableExtensions.<XAbstractFeatureCall, Integer>sortBy(featureCalls, _function);
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 3
protected List<XClosure> findClosures(final CharSequence expression) {
  try {
    final String expressionAsString = expression.toString().replace("ClosureTypeResolutionTestData", "org.eclipse.xtext.xbase.tests.typesystem.ClosureTypeResolutionTestData").replace("$$", "org::eclipse::xtext::xbase::lib::");
    final XExpression xExpression = this.expression(expressionAsString, false);
    final List<XClosure> Closures = IteratorExtensions.<XClosure>toList(Iterators.<XClosure>filter(EcoreUtil2.eAll(xExpression), XClosure.class));
    final Function1<XClosure, Integer> _function = (XClosure it) -> {
      return Integer.valueOf(NodeModelUtils.findActualNodeFor(it).getOffset());
    };
    return IterableExtensions.<XClosure, Integer>sortBy(Closures, _function);
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 4
protected List<XConstructorCall> findConstructorCalls(final CharSequence expression) {
  try {
    final XExpression xExpression = this.expression(expression, false);
    Assert.assertTrue(xExpression.eResource().getErrors().isEmpty());
    final List<XConstructorCall> closures = IteratorExtensions.<XConstructorCall>toList(Iterators.<XConstructorCall>filter(EcoreUtil2.eAll(xExpression), XConstructorCall.class));
    final Function1<XConstructorCall, Integer> _function = (XConstructorCall it) -> {
      return Integer.valueOf(IterableExtensions.<INode>head(NodeModelUtils.findNodesForFeature(it, XbasePackage.Literals.XCONSTRUCTOR_CALL__CONSTRUCTOR)).getOffset());
    };
    return IterableExtensions.<XConstructorCall, Integer>sortBy(closures, _function);
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 5
protected List<XStringLiteral> findLiterals(final CharSequence expression) {
  try {
    final XExpression xExpression = this.expression(expression, false);
    final List<XStringLiteral> featureCalls = IteratorExtensions.<XStringLiteral>toList(Iterators.<XStringLiteral>filter(EcoreUtil2.eAll(xExpression), XStringLiteral.class));
    final Function1<XStringLiteral, Integer> _function = (XStringLiteral it) -> {
      return Integer.valueOf(NodeModelUtils.findActualNodeFor(it).getOffset());
    };
    return IterableExtensions.<XStringLiteral, Integer>sortBy(featureCalls, _function);
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 6
@Test public void testSortBy() throws Exception {
	List<? extends CharSequence> list = newArrayList("foo","bar","baz");
	List<? extends CharSequence> sorted = IterableExtensions.sortBy(list, new Functions.Function1<CharSequence, String>() {
		@Override
		public String apply(CharSequence p) {
			return p.toString();
		}
	});
	assertNotSame(list, sorted);
	assertEquals(sorted, newArrayList("bar","baz","foo"));
}
 
Example 7
protected String applyEdits(String oldDocument, Collection<TextReplacement> edits) {
	int lastOffset = 0;
	StringBuilder newDocument = new StringBuilder();
	for (TextReplacement edit : IterableExtensions.sortBy(edits, TextReplacement::getOffset)) {
		newDocument.append(oldDocument.substring(lastOffset, edit.getOffset()));
		newDocument.append(edit.getText());
		lastOffset = edit.getOffset() + edit.getLength();
	}
	newDocument.append(oldDocument.substring(lastOffset, oldDocument.length()));
	return newDocument.toString();
}
 
Example 8
protected String applyDebugEdits(String oldDocument, Collection<TextReplacement> edits) {
	int lastOffset = 0;
	StringBuilder debugTrace = new StringBuilder();
	for (TextReplacement edit : IterableExtensions.sortBy(edits, TextReplacement::getOffset)) {
		debugTrace.append(oldDocument.substring(lastOffset, edit.getOffset()));
		debugTrace.append(
				"[" + oldDocument.substring(edit.getOffset(), edit.getOffset() + edit.getLength()) + "|" + edit.getText() + "]");
		lastOffset = edit.getOffset() + edit.getLength();
	}
	debugTrace.append(oldDocument.substring(lastOffset, oldDocument.length()));
	return debugTrace.toString();
}
 
Example 9
public ResponseError toResponseError() {
	Severity maxSeverity = getMaximumSeverity();
	ResponseError responseError = new ResponseError();
	responseError.setMessage(getMessageBySeverity(maxSeverity));
	responseError.setCode(getCodeBySeverity(maxSeverity));
	List<Issue> bySeverity = IterableExtensions.sortBy(issues, (i) -> i.severity);
	List<String> messages = ListExtensions.map(ListExtensions.reverse(bySeverity), (i) -> i.message);
	responseError.setData(IterableExtensions.join(messages, "\n"));
	return responseError;
}