use of org.eclipse.xtext.util.IAcceptor in project xtext-xtend by eclipse.
the class AbstractXtendCompilerTest method doAssertCompilesTo.
protected XtendFile doAssertCompilesTo(final CharSequence input, final CharSequence expected, final GeneratorConfig config, final boolean serializeAllTypes) {
try {
final XtendFile file = this.file(input.toString(), true);
final ArrayList<CharSequence> results = CollectionLiterals.<CharSequence>newArrayList();
Iterable<JvmDeclaredType> _filter = Iterables.<JvmDeclaredType>filter(file.eResource().getContents(), JvmDeclaredType.class);
for (final JvmDeclaredType inferredType : _filter) {
{
Assert.assertFalse(DisableCodeGenerationAdapter.isDisabled(inferredType));
CharSequence javaCode = this.generator.generateType(inferredType, config);
javaCode = this.postProcessor.postProcess(null, javaCode);
results.add(javaCode);
if (this.useJavaCompiler) {
final IAcceptor<CompilationTestHelper.Result> _function = (CompilationTestHelper.Result it) -> {
it.getCompiledClass();
};
this.compilationTestHelper.compile(input, _function);
}
}
}
if (serializeAllTypes) {
Assert.assertEquals(expected.toString(), IterableExtensions.join(results, "\n"));
} else {
Assert.assertEquals(expected.toString(), IterableExtensions.<CharSequence>head(results).toString());
}
return file;
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtext.util.IAcceptor in project xtext-core by eclipse.
the class DefaultResourceDescription method computeReferenceDescriptions.
protected List<IReferenceDescription> computeReferenceDescriptions() {
final List<IReferenceDescription> referenceDescriptions = Lists.newArrayList();
IAcceptor<IReferenceDescription> acceptor = new IAcceptor<IReferenceDescription>() {
@Override
public void accept(IReferenceDescription referenceDescription) {
referenceDescriptions.add(referenceDescription);
}
};
EcoreUtil2.resolveLazyCrossReferences(resource, CancelIndicator.NullImpl);
Map<EObject, IEObjectDescription> eObject2exportedEObjects = createEObject2ExportedEObjectsMap(getExportedObjects());
TreeIterator<EObject> contents = EcoreUtil.getAllProperContents(this.resource, true);
while (contents.hasNext()) {
EObject eObject = contents.next();
URI exportedContainerURI = findExportedContainerURI(eObject, eObject2exportedEObjects);
if (!strategy.createReferenceDescriptions(eObject, exportedContainerURI, acceptor))
contents.prune();
}
return referenceDescriptions;
}
use of org.eclipse.xtext.util.IAcceptor in project xtext-core by eclipse.
the class FormattingConflictTest method enableDebugTracingFalse.
@Test
public void enableDebugTracingFalse() {
final Wrapper<Throwable> wrapper = new Wrapper<Throwable>();
final Wrapper<Integer> execution = new Wrapper<Integer>(Integer.valueOf(0));
final Procedure1<GenericFormatterTestRequest> _function = (GenericFormatterTestRequest it) -> {
StringConcatenation _builder = new StringConcatenation();
_builder.append("idlist a");
_builder.newLine();
it.setToBeFormatted(_builder);
final GenericFormatter<IDList> _function_1 = new GenericFormatter<IDList>() {
@Override
protected void format(final IDList model, @Extension final ITextRegionExtensions regions, @Extension final IFormattableDocument document) {
Integer _get = execution.get();
int _plus = ((_get).intValue() + 1);
execution.set(Integer.valueOf(_plus));
final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it_1) -> {
it_1.setSpace(" ");
};
document.append(regions.regionFor(model).keyword("idlist"), _function);
final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it_1) -> {
it_1.setSpace("\t");
};
document.append(regions.regionFor(model).keyword("idlist"), _function_1);
}
};
it.setFormatter(_function_1);
FormatterRequest _request = it.getRequest();
_request.setEnableDebugTracing(false);
FormatterRequest _request_1 = it.getRequest();
final IAcceptor<Exception> _function_2 = (Exception e) -> {
wrapper.set(e);
};
_request_1.setExceptionHandler(_function_2);
};
this._genericFormatterTester.assertFormatted(_function);
Throwable _get = wrapper.get();
final ConflictingRegionsException exception = ((ConflictingRegionsException) _get);
Assert.assertEquals(2, (execution.get()).intValue());
Assert.assertEquals(2, exception.getTraces().size());
}
use of org.eclipse.xtext.util.IAcceptor in project xtext-core by eclipse.
the class FormattingConflictTest method enableDebugTracingTrue.
@Test
public void enableDebugTracingTrue() {
final Wrapper<Throwable> wrapper = new Wrapper<Throwable>();
final Wrapper<Integer> execution = new Wrapper<Integer>(Integer.valueOf(0));
final Procedure1<GenericFormatterTestRequest> _function = (GenericFormatterTestRequest it) -> {
StringConcatenation _builder = new StringConcatenation();
_builder.append("idlist a");
_builder.newLine();
it.setToBeFormatted(_builder);
final GenericFormatter<IDList> _function_1 = new GenericFormatter<IDList>() {
@Override
protected void format(final IDList model, @Extension final ITextRegionExtensions regions, @Extension final IFormattableDocument document) {
Integer _get = execution.get();
int _plus = ((_get).intValue() + 1);
execution.set(Integer.valueOf(_plus));
final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it_1) -> {
it_1.setSpace(" ");
};
document.append(regions.regionFor(model).keyword("idlist"), _function);
final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it_1) -> {
it_1.setSpace("\t");
};
document.append(regions.regionFor(model).keyword("idlist"), _function_1);
}
};
it.setFormatter(_function_1);
FormatterRequest _request = it.getRequest();
_request.setEnableDebugTracing(true);
FormatterRequest _request_1 = it.getRequest();
final IAcceptor<Exception> _function_2 = (Exception e) -> {
wrapper.set(e);
};
_request_1.setExceptionHandler(_function_2);
};
this._genericFormatterTester.assertFormatted(_function);
Throwable _get = wrapper.get();
final ConflictingRegionsException exception = ((ConflictingRegionsException) _get);
Assert.assertEquals(1, (execution.get()).intValue());
Assert.assertEquals(2, exception.getTraces().size());
}
use of org.eclipse.xtext.util.IAcceptor in project xtext-xtend by eclipse.
the class DispatchRenameSupport method getAllDispatchOperations.
/**
* Returns all operations of the declaring type that have to be renamed with the given Xtend function. I.e. all
* dispatch functions with the same name of all sub- and super types as well as the artificial dispatchers.
*
* The method will likely load all subtypes into the resource set of the dispatch function, so you might want to
* hand in a reloaded instance instead.
*/
public Iterable<JvmOperation> getAllDispatchOperations(XtendFunction dispatchFunction) {
Assert.isLegal(dispatchFunction.isDispatch());
IProject project = projectUtil.getProject(dispatchFunction.eResource().getURI());
final ResourceSet tempResourceSet = resourceSetProvider.get(project);
JvmOperation localDispatcher = associations.getDispatchOperation(dispatchFunction);
XtendClass xtendClass = (XtendClass) dispatchFunction.eContainer();
final Set<JvmOperation> dispatchCases = newLinkedHashSet();
IAcceptor<JvmOperation> operationAcceptor = new IAcceptor<JvmOperation>() {
@Override
public void accept(JvmOperation operation) {
dispatchCases.add(operation);
}
};
final Set<JvmGenericType> processedTypes = newHashSet();
addDispatcher(associations.getInferredType(xtendClass), new DispatchHelper.DispatchSignature(localDispatcher.getSimpleName(), localDispatcher.getParameters().size()), operationAcceptor, processedTypes, tempResourceSet);
return dispatchCases;
}
Aggregations