Search in sources :

Example 26 with IChangeSerializer

use of org.eclipse.xtext.ide.serializer.IChangeSerializer in project xtext-eclipse by eclipse.

the class BatchModification method applyInWorkspace.

protected void applyInWorkspace(Iterable<IBatchableModification> modifications, IProgressMonitor monitor) throws CoreException {
    IProject proj = getResolvedProject();
    if (proj == null) {
        LOG.error("No project configured.");
        return;
    }
    SubMonitor progress = SubMonitor.convert(monitor, 100);
    ResourceSet resourceSet = resourceSetProvider.get(proj);
    liveScopeResourceSetInitializer.initialize(resourceSet);
    List<ResolvedModification> resolved = Lists.newArrayList();
    for (IBatchableModification modification : modifications) {
        EObject obj = resourceSet.getEObject(modification.getEObjectURI(), true);
        if (obj == null || obj.eIsProxy()) {
            LOG.error("Invalid EObject URI " + modification.getEObjectURI());
            continue;
        }
        resolved.add(new ResolvedModification(obj, modification));
    }
    progress.split(5);
    IChangeSerializer serializer = serializerProvider.get();
    SubMonitor subProgress = SubMonitor.convert(progress.split(80), resolved.size());
    for (ResolvedModification mod : resolved) {
        serializer.setProgressMonitor(subProgress.split(1));
        mod.modification.apply(mod.object, serializer);
        subProgress.split(1);
    }
    boolean first = true;
    for (ResolvedModification mod : resolved) {
        if (first) {
            serializer.setUpdateCrossReferences(mod.modification.isUpdateCrossReferences());
            serializer.setUpdateRelatedFiles(mod.modification.isUpdateRelatedFiles());
        } else {
            if (serializer.isUpdateCrossReferences() != mod.modification.isUpdateCrossReferences()) {
                LOG.error("two modifications can't be batched.");
                return;
            }
            if (serializer.isUpdateRelatedFiles() != mod.modification.isUpdateRelatedFiles()) {
                LOG.error("two modifications can't be batched.");
                return;
            }
        }
    }
    // 15 ticks yet available
    progress.split(1);
    ChangeConverter converter = changeConverterFactory.create("Resolving Issues", null, issueAcceptor);
    serializer.applyModifications(converter);
    progress.split(1);
    Change change = converter.getChange();
    if (change != null) {
        change.initializeValidationData(progress.split(3));
        new PerformChangeOperation(change).run(progress.split(10));
    }
    progress.done();
}
Also used : PerformChangeOperation(org.eclipse.ltk.core.refactoring.PerformChangeOperation) IChangeSerializer(org.eclipse.xtext.ide.serializer.IChangeSerializer) EObject(org.eclipse.emf.ecore.EObject) SubMonitor(org.eclipse.core.runtime.SubMonitor) ChangeConverter(org.eclipse.xtext.ui.refactoring2.ChangeConverter) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) Change(org.eclipse.ltk.core.refactoring.Change) IProject(org.eclipse.core.resources.IProject)

Aggregations

IChangeSerializer (org.eclipse.xtext.ide.serializer.IChangeSerializer)26 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)23 Resource (org.eclipse.emf.ecore.resource.Resource)19 IEmfResourceChange (org.eclipse.xtext.ide.serializer.IEmfResourceChange)19 Test (org.junit.Test)19 InMemoryURIHandler (org.eclipse.xtext.testing.util.InMemoryURIHandler)18 Node (org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.Node)11 MandatoryValue (org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.MandatoryValue)5 EObject (org.eclipse.emf.ecore.EObject)4 TwoChildLists (org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.TwoChildLists)4 SubMonitor (org.eclipse.core.runtime.SubMonitor)3 RenameChange (org.eclipse.xtext.ide.refactoring.RenameChange)3 RenameContext (org.eclipse.xtext.ide.refactoring.RenameContext)3 IProject (org.eclipse.core.resources.IProject)2 URI (org.eclipse.emf.common.util.URI)2 WorkspaceEdit (org.eclipse.lsp4j.WorkspaceEdit)2 IRenameStrategy2 (org.eclipse.xtext.ide.refactoring.IRenameStrategy2)2 ResourceRelocationContext (org.eclipse.xtext.ide.refactoring.ResourceRelocationContext)2 IResourceServiceProvider (org.eclipse.xtext.resource.IResourceServiceProvider)2 XtextResource (org.eclipse.xtext.resource.XtextResource)2