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
Source File: AbstractClosureTypeTest2.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
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
Source File: AbstractFeatureCallTypeTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
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
Source File: AbstractClosureTypeTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
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
Source File: AbstractConstructorCallTypeTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
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
Source File: StringLiteralTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
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
Source File: IterableExtensionsTest.java    From xtext-lib with Eclipse Public License 2.0 5 votes vote down vote up
@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
Source File: FormatterTester.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
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
Source File: FormatterTester.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
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
Source File: ServerRefactoringIssueAcceptor.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
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;
}