Search in sources :

Example 1 with StringBasedTextRegionAccessDiffBuilder

use of org.eclipse.xtext.formatting2.regionaccess.internal.StringBasedTextRegionAccessDiffBuilder in project xtext-core by eclipse.

the class RecordingXtextResourceUpdater method beginRecording.

public ITextRegionDiffBuilder beginRecording(IChangeSerializer serializer, XtextResource resource) {
    this.serializer = serializer;
    this.snapshot = snapshotProvider.createResourceSnapshot(resource);
    this.document = new StringBasedTextRegionAccessDiffBuilder(this.snapshot.getRegions());
    EcoreUtil.resolveAll(resource);
    this.recorder = new ChangeRecorder(resource);
    return this.document;
}
Also used : ChangeRecorder(org.eclipse.emf.ecore.change.util.ChangeRecorder) StringBasedTextRegionAccessDiffBuilder(org.eclipse.xtext.formatting2.regionaccess.internal.StringBasedTextRegionAccessDiffBuilder)

Example 2 with StringBasedTextRegionAccessDiffBuilder

use of org.eclipse.xtext.formatting2.regionaccess.internal.StringBasedTextRegionAccessDiffBuilder in project xtext-core by eclipse.

the class RelatedXtextResourceUpdater method applyChange.

@Override
public void applyChange(Deltas deltas, IAcceptor<IEmfResourceChange> changeAcceptor) {
    XtextResource res = (XtextResource) lifecycleManager.openAndApplyReferences(getResourceSet(), getResource());
    if (!referenceUpdater.isAffected(deltas, getResource())) {
        return;
    }
    ITextRegionAccess base = textRegionBuilderProvider.get().forNodeModel(res).create();
    ITextRegionDiffBuilder rewriter = new StringBasedTextRegionAccessDiffBuilder(base);
    ReferenceUpdaterContext context = new ReferenceUpdaterContext(deltas, rewriter, getResource());
    referenceUpdater.update(context);
    if (!context.getModifications().isEmpty()) {
        ChangeRecorder rec = new ChangeRecorder(res);
        for (Runnable run : context.getModifications()) {
            run.run();
        }
        ChangeDescription recording = rec.endRecording();
        ResourceSet rs = res.getResourceSet();
        ResourceSetRecording tree = changeTreeProvider.createChangeTree(rs, Collections.emptyList(), recording);
        ResourceRecording recordedResource = tree.getRecordedResource(res);
        if (recordedResource != null) {
            serializer.serializeChanges(recordedResource, rewriter);
        }
    }
    for (IUpdatableReference upd : context.getUpdatableReferences()) {
        referenceUpdater.updateReference(rewriter, upd);
    }
    ITextRegionAccessDiff rewritten = rewriter.create();
    List<ITextReplacement> rep = formatter.format(rewritten);
    TextDocumentChange change = new TextDocumentChange(rewritten, getResource().getUri(), rep);
    changeAcceptor.accept(change);
}
Also used : ResourceRecording(org.eclipse.xtext.ide.serializer.impl.ChangeTreeProvider.ResourceRecording) ITextRegionAccessDiff(org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccessDiff) ITextRegionAccess(org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess) StringBasedTextRegionAccessDiffBuilder(org.eclipse.xtext.formatting2.regionaccess.internal.StringBasedTextRegionAccessDiffBuilder) IUpdatableReference(org.eclipse.xtext.ide.serializer.hooks.IUpdatableReference) ITextReplacement(org.eclipse.xtext.formatting2.regionaccess.ITextReplacement) ResourceSetRecording(org.eclipse.xtext.ide.serializer.impl.ChangeTreeProvider.ResourceSetRecording) XtextResource(org.eclipse.xtext.resource.XtextResource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) ChangeRecorder(org.eclipse.emf.ecore.change.util.ChangeRecorder) ChangeDescription(org.eclipse.emf.ecore.change.ChangeDescription) ITextRegionDiffBuilder(org.eclipse.xtext.formatting2.regionaccess.ITextRegionDiffBuilder)

Example 3 with StringBasedTextRegionAccessDiffBuilder

use of org.eclipse.xtext.formatting2.regionaccess.internal.StringBasedTextRegionAccessDiffBuilder in project xtext-core by eclipse.

the class RegionAccessTestHelper method modify.

public ITextRegionAccess modify(final ITextRegionAccess base, final Procedure1<? super ITextRegionDiffBuilder> modify) {
    final StringBasedTextRegionAccessDiffBuilder fac = new StringBasedTextRegionAccessDiffBuilder(base);
    modify.apply(fac);
    final StringBasedTextRegionAccessDiff modified = fac.create();
    return modified;
}
Also used : StringBasedTextRegionAccessDiffBuilder(org.eclipse.xtext.formatting2.regionaccess.internal.StringBasedTextRegionAccessDiffBuilder) StringBasedTextRegionAccessDiff(org.eclipse.xtext.formatting2.regionaccess.internal.StringBasedTextRegionAccessDiff)

Aggregations

StringBasedTextRegionAccessDiffBuilder (org.eclipse.xtext.formatting2.regionaccess.internal.StringBasedTextRegionAccessDiffBuilder)3 ChangeRecorder (org.eclipse.emf.ecore.change.util.ChangeRecorder)2 ChangeDescription (org.eclipse.emf.ecore.change.ChangeDescription)1 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)1 ITextRegionAccess (org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess)1 ITextRegionAccessDiff (org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccessDiff)1 ITextRegionDiffBuilder (org.eclipse.xtext.formatting2.regionaccess.ITextRegionDiffBuilder)1 ITextReplacement (org.eclipse.xtext.formatting2.regionaccess.ITextReplacement)1 StringBasedTextRegionAccessDiff (org.eclipse.xtext.formatting2.regionaccess.internal.StringBasedTextRegionAccessDiff)1 IUpdatableReference (org.eclipse.xtext.ide.serializer.hooks.IUpdatableReference)1 ResourceRecording (org.eclipse.xtext.ide.serializer.impl.ChangeTreeProvider.ResourceRecording)1 ResourceSetRecording (org.eclipse.xtext.ide.serializer.impl.ChangeTreeProvider.ResourceSetRecording)1 XtextResource (org.eclipse.xtext.resource.XtextResource)1