Search in sources :

Example 6 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 7 with IntegerRange

use of org.eclipse.xtext.xbase.lib.IntegerRange in project xtext-xtend by eclipse.

the class ActualTypeArgumentMergeTest method mappedBy.

public Map<JvmTypeParameter, List<LightweightBoundTypeArgument>> mappedBy(final String typeParameters, final String... alternatingTypeReferences) {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("def ");
        {
            boolean _isNullOrEmpty = StringExtensions.isNullOrEmpty(typeParameters);
            boolean _not = (!_isNullOrEmpty);
            if (_not) {
                _builder.append("<");
                _builder.append(typeParameters);
                _builder.append(">");
            }
        }
        _builder.append(" void method(");
        final Function1<String, CharSequence> _function = (String it) -> {
            return it;
        };
        String _join = IterableExtensions.<String>join(((Iterable<String>) Conversions.doWrapArray(alternatingTypeReferences)), null, " p, ", " p", _function);
        _builder.append(_join);
        _builder.append(") {}");
        final String signature = _builder.toString();
        final XtendFunction function = this.function(signature.toString());
        final JvmOperation operation = this._iXtendJvmAssociations.getDirectlyInferredOperation(function);
        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();
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) IntegerRange(org.eclipse.xtext.xbase.lib.IntegerRange) JvmTypeParameter(org.eclipse.xtext.common.types.JvmTypeParameter) ITypeReferenceOwner(org.eclipse.xtext.xbase.typesystem.references.ITypeReferenceOwner) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) EList(org.eclipse.emf.common.util.EList) List(java.util.List) ActualTypeArgumentCollector(org.eclipse.xtext.xbase.typesystem.util.ActualTypeArgumentCollector)

Example 8 with IntegerRange

use of org.eclipse.xtext.xbase.lib.IntegerRange in project xtext-xtend by eclipse.

the class XtendUIValidationTests method testPerformance.

public void testPerformance() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("import org.eclipse.xtend.core.tests.restricted.RestrictedClass");
        _builder.newLine();
        _builder.append("import org.eclipse.xtend.core.tests.internal.InternalClass");
        _builder.newLine();
        _builder.newLine();
        _builder.append("class Foo {");
        _builder.newLine();
        {
            IntegerRange _upTo = new IntegerRange(0, 200);
            for (final Integer i : _upTo) {
                _builder.append("RestrictedClass x");
                _builder.append(i);
                _builder.append(" = new RestrictedClass");
                _builder.newLineIfNotEmpty();
                _builder.append("InternalClass y");
                _builder.append(i);
                _builder.append(" = new InternalClass");
                _builder.newLineIfNotEmpty();
                _builder.append("def bar(InternalClass p1");
                _builder.append(i);
                _builder.append(", RestrictedClass p2");
                _builder.append(i);
                _builder.append("){}");
                _builder.newLineIfNotEmpty();
            }
        }
        _builder.append("}");
        _builder.newLine();
        final XtendFile xtendFile = this.testHelper.xtendFile("Clazz.xtend", _builder.toString());
        this.helper.validate(xtendFile);
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) IntegerRange(org.eclipse.xtext.xbase.lib.IntegerRange) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation)

Example 9 with IntegerRange

use of org.eclipse.xtext.xbase.lib.IntegerRange in project xtext-xtend by eclipse.

the class UIResourceChangeRegistryTest method testConcurrentDiscard.

@Test
public void testConcurrentDiscard() throws Exception {
    try {
        final Consumer<Integer> _function = (Integer it) -> {
            this.resourceChangeRegistry.registerCreateOrModify("/foo", this.uri.appendSegment(it.toString()));
        };
        new IntegerRange(1, 10000).forEach(_function);
        final Runnable _function_1 = () -> {
            final SecureRandom random = new SecureRandom(new byte[] { ((byte) 1) });
            final Consumer<Integer> _function_2 = (Integer it) -> {
                final URI removedURI = this.uri.appendSegment(Integer.valueOf(random.nextInt(10000)).toString());
                this.resourceChangeRegistry.discardCreateOrModifyInformation(removedURI);
            };
            new IntegerRange(1, 1000).forEach(_function_2);
        };
        final Runnable r = _function_1;
        final ExecutorService executorService = Executors.newCachedThreadPool();
        try {
            final Future<?> future1 = executorService.submit(r);
            final Future<?> future2 = executorService.submit(r);
            final Future<?> future3 = executorService.submit(r);
            final Future<?> future4 = executorService.submit(r);
            future1.get();
            future2.get();
            future3.get();
            future4.get();
        } catch (final Throwable _t) {
            if (_t instanceof ExecutionException) {
                final ExecutionException e = (ExecutionException) _t;
                throw e.getCause();
            } else {
                throw Exceptions.sneakyThrow(_t);
            }
        } finally {
            executorService.shutdown();
        }
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : IntegerRange(org.eclipse.xtext.xbase.lib.IntegerRange) Consumer(java.util.function.Consumer) ExecutorService(java.util.concurrent.ExecutorService) SecureRandom(java.security.SecureRandom) ExecutionException(java.util.concurrent.ExecutionException) URI(org.eclipse.emf.common.util.URI) Test(org.junit.Test)

Example 10 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() {
    try {
        XtextResourceSet _createEmptyResourceSet = this.createEmptyResourceSet();
        final SynchronizedXtextResourceSet resourceSet = ((SynchronizedXtextResourceSet) _createEmptyResourceSet);
        final Resource.Factory _function = (URI uri) -> {
            NullResource _xblockexpression = null;
            {
                final NullResource result = new NullResource();
                result.setURI(uri);
                _xblockexpression = result;
            }
            return _xblockexpression;
        };
        final Resource.Factory nullFactory = _function;
        resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("xmi", nullFactory);
        final ArrayList<Thread> threads = CollectionLiterals.<Thread>newArrayList();
        final Consumer<Integer> _function_1 = (Integer i) -> {
            final Runnable _function_2 = () -> {
                final ArrayList<Resource> resources = CollectionLiterals.<Resource>newArrayList();
                for (int j = 0; (j < 5000); j++) {
                    {
                        String _plus = (i + " ");
                        String _plus_1 = (_plus + Integer.valueOf(j));
                        String _plus_2 = (_plus_1 + ".xmi");
                        final Resource resource = resourceSet.createResource(URI.createURI(_plus_2));
                        Assert.assertNotNull(resource);
                        resources.add(resource);
                        URI _uRI = resource.getURI();
                        String _plus_3 = (_uRI + "b");
                        resource.setURI(URI.createURI(_plus_3));
                    }
                }
            };
            Thread _thread = new Thread(_function_2);
            threads.add(_thread);
        };
        new IntegerRange(1, 10).forEach(_function_1);
        for (final Thread thread : threads) {
            thread.start();
        }
        for (final Thread thread_1 : threads) {
            thread_1.join();
        }
        Assert.assertEquals(50000, resourceSet.getResources().size());
        Assert.assertEquals(IterableExtensions.<Resource>toSet(resourceSet.getResources()).size(), IterableExtensions.<Resource>toSet(resourceSet.getURIResourceMap().values()).size());
        final Function1<Resource, List<URI>> _function_2 = (Resource it) -> {
            URI _uRI = it.getURI();
            URI _normalize = resourceSet.getURIConverter().normalize(it.getURI());
            return Collections.<URI>unmodifiableList(CollectionLiterals.<URI>newArrayList(_uRI, _normalize));
        };
        Assert.assertEquals(IterableExtensions.<URI>toSet(Iterables.<URI>concat(ListExtensions.<Resource, List<URI>>map(resourceSet.getResources(), _function_2))), resourceSet.getURIResourceMap().keySet());
        final Function1<Resource, String> _function_3 = (Resource it) -> {
            return it.getURI().toString();
        };
        final Function1<URI, String> _function_4 = (URI it) -> {
            return it.toString();
        };
        Assert.assertEquals(IterableExtensions.join(IterableExtensions.<String>sort(IterableExtensions.<String>toList(ListExtensions.<Resource, String>map(resourceSet.getResources(), _function_3))), "\n"), IterableExtensions.join(IterableExtensions.<String>sort(IterableExtensions.<String>toList(IterableExtensions.<URI, String>map(resourceSet.getNormalizationMap().keySet(), _function_4))), "\n"));
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : IntegerRange(org.eclipse.xtext.xbase.lib.IntegerRange) NullResource(org.eclipse.xtext.resource.NullResource) Resource(org.eclipse.emf.ecore.resource.Resource) SynchronizedXtextResourceSet(org.eclipse.xtext.resource.SynchronizedXtextResourceSet) URI(org.eclipse.emf.common.util.URI) NullResource(org.eclipse.xtext.resource.NullResource) SynchronizedXtextResourceSet(org.eclipse.xtext.resource.SynchronizedXtextResourceSet) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test) AbstractXtextResourceSetTest(org.eclipse.xtext.resource.AbstractXtextResourceSetTest)

Aggregations

IntegerRange (org.eclipse.xtext.xbase.lib.IntegerRange)15 Test (org.junit.Test)5 List (java.util.List)4 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)4 ArrayList (java.util.ArrayList)2 EList (org.eclipse.emf.common.util.EList)2 URI (org.eclipse.emf.common.util.URI)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 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 SecureRandom (java.security.SecureRandom)1 ExecutionException (java.util.concurrent.ExecutionException)1 ExecutorService (java.util.concurrent.ExecutorService)1