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-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);
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations