Search in sources :

Example 16 with IntegerRange

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();
}
Also used : JvmOperation(org.eclipse.xtext.common.types.JvmOperation) IntegerRange(org.eclipse.xtext.xbase.lib.IntegerRange) JvmTypeParameter(org.eclipse.xtext.common.types.JvmTypeParameter) EList(org.eclipse.emf.common.util.EList) List(java.util.List) ITypeReferenceOwner(org.eclipse.xtext.xbase.typesystem.references.ITypeReferenceOwner) ActualTypeArgumentCollector(org.eclipse.xtext.xbase.typesystem.util.ActualTypeArgumentCollector)

Example 17 with IntegerRange

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)))));
}
Also used : IntegerRange(org.eclipse.xtext.xbase.lib.IntegerRange) Resource(org.eclipse.emf.ecore.resource.Resource) ArrayList(java.util.ArrayList) URI(org.eclipse.emf.common.util.URI) List(java.util.List) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 18 with IntegerRange

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());
    }
}
Also used : Task(org.eclipse.xtext.tasks.Task) IntegerRange(org.eclipse.xtext.xbase.lib.IntegerRange) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) ExclusiveRange(org.eclipse.xtext.xbase.lib.ExclusiveRange) Test(org.junit.Test)

Example 19 with IntegerRange

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;
    }
}
Also used : IntegerRange(org.eclipse.xtext.xbase.lib.IntegerRange) NoSuchElementException(java.util.NoSuchElementException) Test(org.junit.Test)

Example 20 with IntegerRange

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());
}
Also used : IntegerRange(org.eclipse.xtext.xbase.lib.IntegerRange) Test(org.junit.Test)

Aggregations

IntegerRange (org.eclipse.xtext.xbase.lib.IntegerRange)36 Test (org.junit.Test)12 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)9 List (java.util.List)6 Consumer (java.util.function.Consumer)3 URI (org.eclipse.emf.common.util.URI)3 ArrayList (java.util.ArrayList)2 EList (org.eclipse.emf.common.util.EList)2 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)2 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)2 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)2 JvmTypeConstraint (org.eclipse.xtext.common.types.JvmTypeConstraint)2 JvmTypeParameter (org.eclipse.xtext.common.types.JvmTypeParameter)2 IHiddenRegionFormatter (org.eclipse.xtext.formatting2.IHiddenRegionFormatter)2 ISemanticRegion (org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion)2 Function1 (org.eclipse.xtext.xbase.lib.Functions.Function1)2 Function2 (org.eclipse.xtext.xbase.lib.Functions.Function2)2 Procedure1 (org.eclipse.xtext.xbase.lib.Procedures.Procedure1)2 ITypeReferenceOwner (org.eclipse.xtext.xbase.typesystem.references.ITypeReferenceOwner)2 ActualTypeArgumentCollector (org.eclipse.xtext.xbase.typesystem.util.ActualTypeArgumentCollector)2