Java Code Examples for org.eclipse.xtext.xbase.lib.ListExtensions#sortInplaceBy()
The following examples show how to use
org.eclipse.xtext.xbase.lib.ListExtensions#sortInplaceBy() .
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: AbstractCompletionTest.java From n4js with Eclipse Public License 1.0 | 5 votes |
@Override protected void performTest(Project project, String moduleName, TestCompletionConfiguration tcc) throws InterruptedException, ExecutionException { CompletionParams completionParams = new CompletionParams(); Position pos = new Position(tcc.getLine(), tcc.getColumn()); completionParams.setPosition(pos); FileURI uri = getFileURIFromModuleName(tcc.getFilePath()); TextDocumentIdentifier textDocument = new TextDocumentIdentifier(); textDocument.setUri(uri.toString()); completionParams.setTextDocument(textDocument); CompletableFuture<Either<List<CompletionItem>, CompletionList>> future = languageServer .completion(completionParams); Either<List<CompletionItem>, CompletionList> result = future.get(); List<CompletionItem> items = result.isLeft() ? result.getLeft() : result.getRight().getItems(); // assert already sorted List<CompletionItem> sortedItems = ListExtensions.sortInplaceBy(items, CompletionItem::getSortText); Assert.assertEquals(items, sortedItems); if (tcc.getAssertCompletionList() != null) { tcc.getAssertCompletionList().apply(result.getRight()); } else { String resultStr = Strings.join("\n", getStringLSP4J()::toString, items); assertEquals(tcc.getExpectedCompletionItems().trim(), resultStr.trim()); } }
Example 2
Source File: MutableTokenDefProvider.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
public void writeTokenFile(PrintWriter out) throws IOException { List<Map.Entry<Integer, String>> entries = Lists.newArrayList(getTokenDefMap().entrySet()); ListExtensions.sortInplaceBy(entries, new Functions.Function1<Map.Entry<Integer, String>, String>() { @Override public String apply(Map.Entry<Integer, String> p) { return p.getValue(); } }); for(Map.Entry<Integer, String> entry: entries) { out.print(entry.getValue()); out.print('='); out.println(entry.getKey()); } out.close(); }
Example 3
Source File: AbstractPortableURIsTest.java From xtext-extras with Eclipse Public License 2.0 | 4 votes |
protected void doTestResource(String platformPath, String... packageNames) { Resource resource = resourceSet.getResource(URI.createPlatformPluginURI(platformPath, false), true); assertNotNull(resource); assertEquals(1, resource.getContents().size()); EObject obj = resource.getContents().get(0); if (obj instanceof EPackage) { assertEquals(packageNames[0], ((EPackage) obj).getName()); } else if (obj instanceof GenModel) { GenModel model = (GenModel) obj; List<GenPackage> packages = Lists.newArrayList(model.getGenPackages()); assertEquals(packageNames.length, packages.size()); ListExtensions.sortInplaceBy(packages, new Functions.Function1<GenPackage, String>() { @Override public String apply(GenPackage p) { return p.getEcorePackage().getName(); } }); List<String> packageNamesList = Arrays.asList(packageNames); Collections.sort(packageNamesList); for(int i = 0; i < packageNamesList.size(); i++) { assertEquals(packageNamesList.get(i), packages.get(i).getEcorePackage().getName()); } IStatus status = model.validate(); assertTrue(printLeafs(status), status.isOK()); EObject orig = EcoreUtil.copy(obj); ((GenModel) obj).reconcile(); if (!EcoreUtil.equals(orig, obj)) { Predicate<EStructuralFeature> ignoreContainer = new Predicate<EStructuralFeature>() { @Override public boolean apply(EStructuralFeature f) { if (f instanceof EReference) { EReference casted = (EReference) f; return !casted.isContainment(); } return false; } }; String origAsString = EmfFormatter.objToStr(orig, ignoreContainer); String newAsString = EmfFormatter.objToStr(obj, ignoreContainer); throw new ComparisonFailure("Reconcile changed model", origAsString, newAsString); } } else { fail("Unexpected root element type: " + obj.eClass().getName()); } }
Example 4
Source File: AbstractPortableURIsTest.java From xtext-extras with Eclipse Public License 2.0 | 4 votes |
protected void doTestResource(String platformPath, String... packageNames) { Resource resource = resourceSet.getResource(URI.createPlatformPluginURI(platformPath, false), true); assertNotNull(resource); assertEquals(1, resource.getContents().size()); EObject obj = resource.getContents().get(0); if (obj instanceof EPackage) { assertEquals(packageNames[0], ((EPackage) obj).getName()); } else if (obj instanceof GenModel) { GenModel model = (GenModel) obj; List<GenPackage> packages = Lists.newArrayList(model.getGenPackages()); assertEquals(packageNames.length, packages.size()); ListExtensions.sortInplaceBy(packages, new Functions.Function1<GenPackage, String>() { @Override public String apply(GenPackage p) { return p.getEcorePackage().getName(); } }); List<String> packageNamesList = Arrays.asList(packageNames); Collections.sort(packageNamesList); for(int i = 0; i < packageNamesList.size(); i++) { assertEquals(packageNamesList.get(i), packages.get(i).getEcorePackage().getName()); } IStatus status = model.validate(); assertTrue(printLeafs(status), status.isOK()); EObject orig = EcoreUtil.copy(obj); ((GenModel) obj).reconcile(); if (!EcoreUtil.equals(orig, obj)) { Predicate<EStructuralFeature> ignoreContainer = new Predicate<EStructuralFeature>() { @Override public boolean apply(EStructuralFeature f) { if (f instanceof EReference) { EReference casted = (EReference) f; return !casted.isContainment(); } return false; } }; String origAsString = EmfFormatter.objToStr(orig, ignoreContainer); String newAsString = EmfFormatter.objToStr(obj, ignoreContainer); throw new ComparisonFailure("Reconcile changed model", origAsString, newAsString); } } else { fail("Unexpected root element type: " + obj.eClass().getName()); } }
Example 5
Source File: AbstractPortableURIsTest.java From xtext-eclipse with Eclipse Public License 2.0 | 4 votes |
protected void doTestResource(String platformPath, String... packageNames) { Resource resource = resourceSet.getResource(URI.createPlatformPluginURI(platformPath, false), true); assertNotNull(resource); assertEquals(1, resource.getContents().size()); EObject obj = resource.getContents().get(0); if (obj instanceof EPackage) { assertEquals(packageNames[0], ((EPackage) obj).getName()); } else if (obj instanceof GenModel) { GenModel model = (GenModel) obj; List<GenPackage> packages = Lists.newArrayList(model.getGenPackages()); assertEquals(packageNames.length, packages.size()); ListExtensions.sortInplaceBy(packages, new Functions.Function1<GenPackage, String>() { @Override public String apply(GenPackage p) { return p.getEcorePackage().getName(); } }); List<String> packageNamesList = Arrays.asList(packageNames); Collections.sort(packageNamesList); for(int i = 0; i < packageNamesList.size(); i++) { assertEquals(packageNamesList.get(i), packages.get(i).getEcorePackage().getName()); } IStatus status = model.validate(); assertTrue(printLeafs(status), status.isOK()); EObject orig = EcoreUtil.copy(obj); ((GenModel) obj).reconcile(); if (!EcoreUtil.equals(orig, obj)) { Predicate<EStructuralFeature> ignoreContainer = new Predicate<EStructuralFeature>() { @Override public boolean apply(EStructuralFeature f) { if (f instanceof EReference) { EReference casted = (EReference) f; return !casted.isContainment(); } return false; } }; String origAsString = EmfFormatter.objToStr(orig, ignoreContainer); String newAsString = EmfFormatter.objToStr(obj, ignoreContainer); throw new ComparisonFailure("Reconcile changed model", origAsString, newAsString); } } else { fail("Unexpected root element type: " + obj.eClass().getName()); } }
Example 6
Source File: URIsInEcoreFilesXtendTest.java From xtext-xtend with Eclipse Public License 2.0 | 4 votes |
protected void doTestResource(String platformPath, String... packageNames) { Resource resource = resourceSet.getResource(URI.createPlatformPluginURI(platformPath, false), true); assertNotNull(resource); assertEquals(1, resource.getContents().size()); EObject obj = resource.getContents().get(0); if (obj instanceof EPackage) { assertEquals(packageNames[0], ((EPackage) obj).getName()); } else if (obj instanceof GenModel) { GenModel model = (GenModel) obj; List<GenPackage> packages = Lists.newArrayList(model.getGenPackages()); assertEquals(packageNames.length, packages.size()); ListExtensions.sortInplaceBy(packages, new Functions.Function1<GenPackage, String>() { @Override public String apply(GenPackage p) { return p.getEcorePackage().getName(); } }); List<String> packageNamesList = Arrays.asList(packageNames); Collections.sort(packageNamesList); for(int i = 0; i < packageNamesList.size(); i++) { assertEquals(packageNamesList.get(i), packages.get(i).getEcorePackage().getName()); } IStatus status = model.validate(); assertTrue(printLeafs(status), status.isOK()); EObject orig = EcoreUtil.copy(obj); ((GenModel) obj).reconcile(); if (!EcoreUtil.equals(orig, obj)) { Predicate<EStructuralFeature> ignoreContainer = new Predicate<EStructuralFeature>() { @Override public boolean apply(EStructuralFeature f) { if (f instanceof EReference) { EReference casted = (EReference) f; return !casted.isContainment(); } return false; } }; String origAsString = EmfFormatter.objToStr(orig, ignoreContainer); String newAsString = EmfFormatter.objToStr(obj, ignoreContainer); throw new ComparisonFailure("Reconcile changed model", origAsString, newAsString); } } else { fail("Unexpected root element type: " + obj.eClass().getName()); } }
Example 7
Source File: AbstractPortableURIsTest.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
protected void doTestResource(String platformPath, String... packageNames) { Resource resource = resourceSet.getResource(URI.createPlatformPluginURI(platformPath, false), true); assertNotNull(resource); assertEquals(1, resource.getContents().size()); EObject obj = resource.getContents().get(0); if (obj instanceof EPackage) { assertEquals(packageNames[0], ((EPackage) obj).getName()); } else if (obj instanceof GenModel) { GenModel model = (GenModel) obj; List<GenPackage> packages = Lists.newArrayList(model.getGenPackages()); assertEquals(packageNames.length, packages.size()); ListExtensions.sortInplaceBy(packages, new Functions.Function1<GenPackage, String>() { @Override public String apply(GenPackage p) { return p.getEcorePackage().getName(); } }); List<String> packageNamesList = Arrays.asList(packageNames); Collections.sort(packageNamesList); for(int i = 0; i < packageNamesList.size(); i++) { assertEquals(packageNamesList.get(i), packages.get(i).getEcorePackage().getName()); } IStatus status = model.validate(); assertTrue(printLeafs(status), status.isOK()); EObject orig = EcoreUtil.copy(obj); ((GenModel) obj).reconcile(); if (!EcoreUtil.equals(orig, obj)) { Predicate<EStructuralFeature> ignoreContainer = new Predicate<EStructuralFeature>() { @Override public boolean apply(EStructuralFeature f) { if (f instanceof EReference) { EReference casted = (EReference) f; return !casted.isContainment(); } return false; } }; String origAsString = EmfFormatter.objToStr(orig, ignoreContainer); String newAsString = EmfFormatter.objToStr(obj, ignoreContainer); throw new ComparisonFailure("Reconcile changed model", origAsString, newAsString); } } else { fail("Unexpected root element type: " + obj.eClass().getName()); } }