use of org.eclipse.xtext.xbase.lib.IntegerRange in project xtext-xtend by eclipse.
the class ActualTypeArgumentCollectorTest method mappedBy.
public Map<JvmTypeParameter, List<LightweightBoundTypeArgument>> mappedBy(final String typeParameters, final String... alternatingTypeReferences) {
final JvmOperation operation = this.operation(typeParameters, alternatingTypeReferences);
EList<JvmTypeParameter> _typeParameters = operation.getTypeParameters();
ITypeReferenceOwner _owner = this.getOwner();
final ActualTypeArgumentCollector collector = new ActualTypeArgumentCollector(_typeParameters, BoundTypeArgumentSource.INFERRED, _owner);
int _size = ((List<String>) Conversions.doWrapArray(alternatingTypeReferences)).size();
int _minus = (_size - 1);
IntegerRange _withStep = new IntegerRange(0, _minus).withStep(2);
for (final Integer i : _withStep) {
collector.populateTypeParameterMapping(this.toLightweightTypeReference(operation.getParameters().get((i).intValue()).getParameterType()), this.toLightweightTypeReference(operation.getParameters().get(((i).intValue() + 1)).getParameterType()));
}
return collector.getTypeParameterMapping();
}
use of org.eclipse.xtext.xbase.lib.IntegerRange in project xtext-core by eclipse.
the class SynchronizedXtextResourceSetTest method testSynchronization.
@Test
public void testSynchronization() throws Exception {
SynchronizedXtextResourceSet resourceSet = (SynchronizedXtextResourceSet) createEmptyResourceSet();
Resource.Factory nullFactory = (URI uri) -> {
NullResource result = new NullResource();
result.setURI(uri);
return result;
};
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("xmi", nullFactory);
List<Thread> threads = new ArrayList<>();
new IntegerRange(1, 10).forEach((Integer i) -> {
threads.add(new Thread(() -> {
List<Resource> resources = new ArrayList<>();
for (int j = 0; j < 5000; j++) {
Resource resource = resourceSet.createResource(URI.createURI(i + " " + j + ".xmi"));
Assert.assertNotNull(resource);
resources.add(resource);
resource.setURI(URI.createURI(resource.getURI() + "b"));
}
}));
});
for (Thread thread : threads) {
thread.start();
}
for (Thread thread : threads) {
thread.join();
}
Assert.assertEquals(50000, resourceSet.getResources().size());
Assert.assertEquals(Sets.newLinkedHashSet(resourceSet.getResources()).size(), Sets.newLinkedHashSet(resourceSet.getURIResourceMap().values()).size());
Assert.assertEquals(Sets.newLinkedHashSet(Iterables.concat(Lists.transform(resourceSet.getResources(), (Resource it) -> {
return Lists.<URI>newArrayList(it.getURI(), resourceSet.getURIConverter().normalize(it.getURI()));
}))), resourceSet.getURIResourceMap().keySet());
Assert.assertEquals(Joiner.on("\n").join(IterableExtensions.sort(IterableExtensions.toList(Lists.<Resource, String>transform(resourceSet.getResources(), it -> it.getURI().toString())))), Joiner.on("\n").join(IterableExtensions.sort(IterableExtensions.toList(Iterables.transform(resourceSet.getNormalizationMap().keySet(), URI::toString)))));
}
use of org.eclipse.xtext.xbase.lib.IntegerRange in project xtext-core by eclipse.
the class DefaultTaskParserTest method testLongInputManyTasks.
@Test
public void testLongInputManyTasks() {
final int expectation = 100000;
StringConcatenation _builder = new StringConcatenation();
_builder.append("/*");
_builder.newLine();
{
IntegerRange _upTo = new IntegerRange(1, expectation);
for (final Integer i : _upTo) {
_builder.append(" ");
_builder.append("* FIXME this cannot work");
_builder.newLine();
}
}
_builder.append(" ");
_builder.append("*/");
_builder.newLine();
final String source = _builder.toString();
final List<Task> parsed = this.parser.parseTasks(LineDelimiters.toUnix(source), this.definitions);
Assert.assertEquals(expectation, parsed.size());
ExclusiveRange _doubleDotLessThan = new ExclusiveRange(0, expectation, true);
for (final Integer i_1 : _doubleDotLessThan) {
Assert.assertEquals(((i_1).intValue() + 2), parsed.get((i_1).intValue()).getLineNumber());
}
}
use of org.eclipse.xtext.xbase.lib.IntegerRange in project xtext-lib by eclipse.
the class IntegerRangeTest method testIterator.
@Test
public void testIterator() {
ListIterator<Integer> iterator = new IntegerRange(-2, 2, 2).iterator();
assertFalse(iterator.hasPrevious());
assertTrue(iterator.hasNext());
assertEquals(0, iterator.nextIndex());
assertEquals(-1, iterator.previousIndex());
try {
iterator.previous();
fail("Expected NoSuchElementException");
} catch (NoSuchElementException e) {
// expected exception;
}
assertEquals(-2, iterator.next().intValue());
assertTrue(iterator.hasPrevious());
assertTrue(iterator.hasNext());
assertEquals(1, iterator.nextIndex());
assertEquals(0, iterator.previousIndex());
assertEquals(0, iterator.next().intValue());
assertTrue(iterator.hasPrevious());
assertTrue(iterator.hasNext());
assertEquals(2, iterator.nextIndex());
assertEquals(1, iterator.previousIndex());
assertEquals(2, iterator.next().intValue());
assertTrue(iterator.hasPrevious());
assertFalse(iterator.hasNext());
assertEquals(3, iterator.nextIndex());
assertEquals(2, iterator.previousIndex());
try {
iterator.next();
fail("Expected NoSuchElementException");
} catch (NoSuchElementException e) {
// expected exception;
}
assertEquals(2, iterator.previous().intValue());
assertTrue(iterator.hasPrevious());
assertTrue(iterator.hasNext());
assertEquals(2, iterator.nextIndex());
assertEquals(1, iterator.previousIndex());
assertEquals(0, iterator.previous().intValue());
assertTrue(iterator.hasPrevious());
assertTrue(iterator.hasNext());
assertEquals(1, iterator.nextIndex());
assertEquals(0, iterator.previousIndex());
assertEquals(-2, iterator.previous().intValue());
assertFalse(iterator.hasPrevious());
assertTrue(iterator.hasNext());
assertEquals(0, iterator.nextIndex());
assertEquals(-1, iterator.previousIndex());
try {
iterator.previous();
fail("Expected NoSuchElementException");
} catch (NoSuchElementException e) {
// expected exception;
}
}
use of org.eclipse.xtext.xbase.lib.IntegerRange in project xtext-lib by eclipse.
the class IntegerRangeTest method testSize.
@Test
public void testSize() {
final IntegerRange myRange = new IntegerRange(-1, 1);
assertEquals(3, myRange.getSize());
assertEquals(2, myRange.withStep(2).getSize());
assertEquals(1, myRange.withStep(3).getSize());
final IntegerRange myRange2 = new IntegerRange(1, -1);
assertEquals(3, myRange2.getSize());
assertEquals(2, myRange2.withStep(-2).getSize());
assertEquals(1, myRange2.withStep(-3).getSize());
}
Aggregations