Search in sources :

Example 1 with IAcceptor

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);
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) CompilationTestHelper(org.eclipse.xtext.xbase.testing.CompilationTestHelper) IAcceptor(org.eclipse.xtext.util.IAcceptor) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType)

Example 2 with IAcceptor

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;
}
Also used : EObject(org.eclipse.emf.ecore.EObject) IAcceptor(org.eclipse.xtext.util.IAcceptor) URI(org.eclipse.emf.common.util.URI) IReferenceDescription(org.eclipse.xtext.resource.IReferenceDescription) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Example 3 with IAcceptor

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());
}
Also used : Wrapper(org.eclipse.xtext.util.Wrapper) GenericFormatterTestRequest(org.eclipse.xtext.formatting2.internal.GenericFormatterTestRequest) IHiddenRegionFormatter(org.eclipse.xtext.formatting2.IHiddenRegionFormatter) IFormattableDocument(org.eclipse.xtext.formatting2.IFormattableDocument) IDList(org.eclipse.xtext.formatting2.internal.formattertestlanguage.IDList) ITextRegionExtensions(org.eclipse.xtext.formatting2.regionaccess.ITextRegionExtensions) ConflictingRegionsException(org.eclipse.xtext.formatting2.internal.ConflictingRegionsException) ConflictingRegionsException(org.eclipse.xtext.formatting2.internal.ConflictingRegionsException) GenericFormatter(org.eclipse.xtext.formatting2.internal.GenericFormatter) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) IAcceptor(org.eclipse.xtext.util.IAcceptor) FormatterRequest(org.eclipse.xtext.formatting2.FormatterRequest) Test(org.junit.Test)

Example 4 with IAcceptor

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());
}
Also used : Wrapper(org.eclipse.xtext.util.Wrapper) GenericFormatterTestRequest(org.eclipse.xtext.formatting2.internal.GenericFormatterTestRequest) IHiddenRegionFormatter(org.eclipse.xtext.formatting2.IHiddenRegionFormatter) IFormattableDocument(org.eclipse.xtext.formatting2.IFormattableDocument) IDList(org.eclipse.xtext.formatting2.internal.formattertestlanguage.IDList) ITextRegionExtensions(org.eclipse.xtext.formatting2.regionaccess.ITextRegionExtensions) ConflictingRegionsException(org.eclipse.xtext.formatting2.internal.ConflictingRegionsException) ConflictingRegionsException(org.eclipse.xtext.formatting2.internal.ConflictingRegionsException) GenericFormatter(org.eclipse.xtext.formatting2.internal.GenericFormatter) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) IAcceptor(org.eclipse.xtext.util.IAcceptor) FormatterRequest(org.eclipse.xtext.formatting2.FormatterRequest) Test(org.junit.Test)

Example 5 with IAcceptor

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;
}
Also used : JvmOperation(org.eclipse.xtext.common.types.JvmOperation) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) IAcceptor(org.eclipse.xtext.util.IAcceptor) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) DispatchHelper(org.eclipse.xtend.core.jvmmodel.DispatchHelper) IProject(org.eclipse.core.resources.IProject)

Aggregations

IAcceptor (org.eclipse.xtext.util.IAcceptor)6 EObject (org.eclipse.emf.ecore.EObject)2 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)2 FormatterRequest (org.eclipse.xtext.formatting2.FormatterRequest)2 IFormattableDocument (org.eclipse.xtext.formatting2.IFormattableDocument)2 IHiddenRegionFormatter (org.eclipse.xtext.formatting2.IHiddenRegionFormatter)2 ConflictingRegionsException (org.eclipse.xtext.formatting2.internal.ConflictingRegionsException)2 GenericFormatter (org.eclipse.xtext.formatting2.internal.GenericFormatter)2 GenericFormatterTestRequest (org.eclipse.xtext.formatting2.internal.GenericFormatterTestRequest)2 IDList (org.eclipse.xtext.formatting2.internal.formattertestlanguage.IDList)2 ITextRegionExtensions (org.eclipse.xtext.formatting2.regionaccess.ITextRegionExtensions)2 IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)2 Wrapper (org.eclipse.xtext.util.Wrapper)2 Procedure1 (org.eclipse.xtext.xbase.lib.Procedures.Procedure1)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 IProject (org.eclipse.core.resources.IProject)1 URI (org.eclipse.emf.common.util.URI)1 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)1 DispatchHelper (org.eclipse.xtend.core.jvmmodel.DispatchHelper)1