diff options
author | Vladimir Piskarev | 2014-09-08 13:31:28 +0000 |
---|---|---|
committer | Vladimir Piskarev | 2014-09-09 07:55:51 +0000 |
commit | 121a5211a2ab873fe557a736e1c5dbb2d1492709 (patch) | |
tree | 9bc5711e35cbe7218f33a41c82fba0f7d4c72e74 | |
parent | 497612055eacbb625fa3dc79d8e26828b9bed2e6 (diff) | |
download | org.eclipse.handly-121a5211a2ab873fe557a736e1c5dbb2d1492709.tar.gz org.eclipse.handly-121a5211a2ab873fe557a736e1c5dbb2d1492709.tar.xz org.eclipse.handly-121a5211a2ab873fe557a736e1c5dbb2d1492709.zip |
Bug 438380 - Adapt changes in Xtext
Adapted relevant changes from Xtext 2.7
3 files changed, 84 insertions, 49 deletions
diff --git a/org.eclipse.handly.xtext.ui/src/org/eclipse/handly/xtext/ui/editor/HandlyDirtyStateEditorSupport.java b/org.eclipse.handly.xtext.ui/src/org/eclipse/handly/xtext/ui/editor/HandlyDirtyStateEditorSupport.java index d3939962..cf0eb61e 100644 --- a/org.eclipse.handly.xtext.ui/src/org/eclipse/handly/xtext/ui/editor/HandlyDirtyStateEditorSupport.java +++ b/org.eclipse.handly.xtext.ui/src/org/eclipse/handly/xtext/ui/editor/HandlyDirtyStateEditorSupport.java @@ -21,7 +21,6 @@ import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.jobs.ISchedulingRule; -import org.eclipse.core.runtime.jobs.Job; import org.eclipse.emf.common.util.URI; import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.emf.ecore.resource.ResourceSet; @@ -32,6 +31,7 @@ import org.eclipse.xtext.resource.impl.ResourceDescriptionChangeEvent; import org.eclipse.xtext.ui.editor.DirtyStateEditorSupport; import org.eclipse.xtext.ui.editor.Messages; import org.eclipse.xtext.ui.editor.SchedulingRuleFactory; +import org.eclipse.xtext.ui.editor.model.IXtextDocument; import org.eclipse.xtext.util.Pair; import org.eclipse.xtext.util.Tuples; import org.eclipse.xtext.util.concurrent.IUnitOfWork; @@ -48,20 +48,24 @@ public class HandlyDirtyStateEditorSupport /** * Constant identifying the job family identifier * for the dirty state reconciler job. + * @deprecated Use <code>org.eclipse.xtext.ui.refactoring.ui.SyncUtil</code> + * to wait for XtextEditor dirty state reconciler. */ public static final Object FAMILY_DIRTY_STATE_RECONCILER = new Object(); - protected static final ISchedulingRule RECONCILER_RULE = + protected static final ISchedulingRule SCHEDULING_RULE = SchedulingRuleFactory.INSTANCE.newSequence(); private volatile IDirtyStateEditorSupportClient currentClient; // unfortunately had to duplicate - private DirtyStateReconciler dirtyStateReconciler; @Override public void initializeDirtyStateSupport( IDirtyStateEditorSupportClient client) { super.initializeDirtyStateSupport(client); + IXtextDocument document = client.getDocument(); + if (document instanceof HandlyXtextDocument) + ((HandlyXtextDocument)document).setDirtyStateEditorSupport(this); this.currentClient = client; } @@ -69,71 +73,52 @@ public class HandlyDirtyStateEditorSupport public void removeDirtyStateSupport(IDirtyStateEditorSupportClient client) { super.removeDirtyStateSupport(client); + IXtextDocument document = client.getDocument(); + if (document instanceof HandlyXtextDocument) + ((HandlyXtextDocument)document).setDirtyStateEditorSupport(null); this.currentClient = null; } @Override - public void descriptionsChanged(final IResourceDescription.Event event) - { - if (!getDirtyResource().isInitialized()) - return; - for (IResourceDescription.Delta delta : event.getDeltas()) - { - if (delta.getOld() == getDirtyResource().getDescription() - || delta.getNew() == getDirtyResource().getDescription()) - return; - } - scheduleReconciler(event); - } - - protected final IDirtyStateEditorSupportClient getCurrentClient() - { - return currentClient; - } - - protected DirtyStateReconciler createReconciler() + protected UpdateEditorStateJob createUpdateEditorJob() { // default is sequential execution to ensure a minimum number of // spawned worker threads - return new DirtyStateReconciler(RECONCILER_RULE); + return new UpdateEditorStateJob(SCHEDULING_RULE); } - protected final void scheduleReconciler(IResourceDescription.Event event) + protected final IDirtyStateEditorSupportClient getCurrentClient() { - synchronized (this) - { - if (dirtyStateReconciler == null) - { - dirtyStateReconciler = createReconciler(); - } - } - dirtyStateReconciler.scheduleFor(event); + return currentClient; } /** - * Initially copied from <code>DirtyStateEditorSupport.UpdateEditorStateJob</code>. - * Unfortunately had to fork, could not subclass. + * Initially copied from <code>DirtyStateEditorSupport.UpdateEditorStateJob</code>. + * <p> + * Although effectively a fork, it extends <code>DirtyStateEditorSupport.UpdateEditorStateJob</code> + * in order to retain assignment compatibility. + * </p> */ - protected class DirtyStateReconciler - extends Job + protected class UpdateEditorStateJob + extends DirtyStateEditorSupport.UpdateEditorStateJob { protected final AtomicInteger coarseGrainedChanges; protected final Queue<IResourceDescription.Delta> pendingChanges; - public DirtyStateReconciler(ISchedulingRule rule) + public UpdateEditorStateJob(ISchedulingRule rule) { this(rule, Messages.DirtyStateEditorSupport_JobName); } - public DirtyStateReconciler(ISchedulingRule rule, String name) + public UpdateEditorStateJob(ISchedulingRule rule, String name) { - super(name); - setRule(rule); + super(rule, name); coarseGrainedChanges = new AtomicInteger(); pendingChanges = new ConcurrentLinkedQueue<IResourceDescription.Delta>(); } + @Override public void scheduleFor(IResourceDescription.Event event) { cancel(); @@ -156,12 +141,14 @@ public class HandlyDirtyStateEditorSupport try { IDirtyStateEditorSupportClient myClient = currentClient; - if (myClient == null || monitor.isCanceled()) + if (myClient == null) return Status.OK_STATUS; final HandlyXtextDocument document = (HandlyXtextDocument)myClient.getDocument(); if (document == null) return Status.OK_STATUS; + if (monitor.isCanceled()) + return Status.CANCEL_STATUS; int coarseGrainedChangesSeen = coarseGrainedChanges.get(); final boolean[] isReparseRequired = new boolean[] { coarseGrainedChangesSeen > 0 }; @@ -194,7 +181,7 @@ public class HandlyDirtyStateEditorSupport } }); if (monitor.isCanceled()) - return Status.OK_STATUS; + return Status.CANCEL_STATUS; unloadAffectedResourcesAndReparseDocument(document, affectedResources, isReparseRequired[0]); for (int i = 0; i < event.getSecond(); i++) @@ -211,6 +198,7 @@ public class HandlyDirtyStateEditorSupport return Status.OK_STATUS; } + @Override protected Pair<IResourceDescription.Event, Integer> mergePendingDeltas() { Map<URI, IResourceDescription.Delta> uriToDelta = @@ -236,11 +224,6 @@ public class HandlyDirtyStateEditorSupport return Tuples.create(event, size); } - protected int getDelay() - { - return 500; - } - private void unloadAffectedResourcesAndReparseDocument( final HandlyXtextDocument document, final Collection<Resource> affectedResources, diff --git a/org.eclipse.handly.xtext.ui/src/org/eclipse/handly/xtext/ui/editor/HandlyXtextDocument.java b/org.eclipse.handly.xtext.ui/src/org/eclipse/handly/xtext/ui/editor/HandlyXtextDocument.java index e19f6165..8f793131 100644 --- a/org.eclipse.handly.xtext.ui/src/org/eclipse/handly/xtext/ui/editor/HandlyXtextDocument.java +++ b/org.eclipse.handly.xtext.ui/src/org/eclipse/handly/xtext/ui/editor/HandlyXtextDocument.java @@ -16,8 +16,10 @@ import java.util.ArrayList; import java.util.List; import org.eclipse.core.runtime.Assert; +import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.ISafeRunnable; import org.eclipse.core.runtime.ListenerList; +import org.eclipse.core.runtime.OperationCanceledException; import org.eclipse.core.runtime.SafeRunner; import org.eclipse.core.runtime.jobs.Job; import org.eclipse.emf.common.util.WrappedException; @@ -35,6 +37,8 @@ import org.eclipse.jface.text.DocumentEvent; import org.eclipse.jface.text.IDocumentListener; import org.eclipse.text.edits.TextEdit; import org.eclipse.xtext.EcoreUtil2; +import org.eclipse.xtext.resource.DerivedStateAwareResource; +import org.eclipse.xtext.resource.IBatchLinkableResource; import org.eclipse.xtext.resource.XtextResource; import org.eclipse.xtext.ui.editor.DirtyStateEditorSupport; import org.eclipse.xtext.ui.editor.model.DocumentTokenSource; @@ -42,6 +46,7 @@ import org.eclipse.xtext.ui.editor.model.IXtextDocumentContentObserver.Processor import org.eclipse.xtext.ui.editor.model.IXtextModelListener; import org.eclipse.xtext.ui.editor.model.XtextDocument; import org.eclipse.xtext.ui.editor.model.edit.ITextEditComposer; +import org.eclipse.xtext.ui.editor.reconciler.CancelIndicatorBasedProgressMonitor; import org.eclipse.xtext.ui.editor.reconciler.ReplaceRegion; import org.eclipse.xtext.util.CancelIndicator; import org.eclipse.xtext.util.concurrent.IUnitOfWork; @@ -70,6 +75,7 @@ public class HandlyXtextDocument private final DocumentListener selfListener = new DocumentListener(); private PendingChange pendingChange; private final Object pendingChangeLock = new Object(); + private DirtyStateEditorSupport dirtyStateEditorSupport; @Inject public HandlyXtextDocument(DocumentTokenSource tokenSource, @@ -234,6 +240,12 @@ public class HandlyXtextDocument } } + void setDirtyStateEditorSupport( + DirtyStateEditorSupport dirtyStateEditorSupport) + { + this.dirtyStateEditorSupport = dirtyStateEditorSupport; + } + private PendingChange getAndResetPendingChange() { final PendingChange result; @@ -276,6 +288,8 @@ public class HandlyXtextDocument private void reconciled(final XtextResource resource, final NonExpiringSnapshot snapshot, final boolean forced) { + postProcess(resource, new CancelIndicatorBasedProgressMonitor( + getOutdatedStateCancelIndicator(resource))); Object[] listeners = reconcilingListeners.getListeners(); for (final Object listener : listeners) { @@ -297,6 +311,39 @@ public class HandlyXtextDocument reconciledSnapshot = snapshot; } + // initially copied from XtextDocumentReconcileStrategy#postParse + private void postProcess(XtextResource resource, + final IProgressMonitor monitor) + { + if (dirtyStateEditorSupport != null) + dirtyStateEditorSupport.announceDirtyState(resource); + CancelIndicator cancelIndicator = new CancelIndicator() + { + public boolean isCanceled() + { + return monitor.isCanceled(); + } + }; + try + { + if (resource instanceof DerivedStateAwareResource) + ((DerivedStateAwareResource)resource).installDerivedState(false); + if (resource instanceof IBatchLinkableResource) + { + ((IBatchLinkableResource)resource).linkBatched(cancelIndicator); + } + } + catch (OperationCanceledException e) + { + resource.getCache().clear(resource); + } + catch (RuntimeException e) + { + Activator.log(Activator.createErrorStatus( + "Error post-processing resource", e)); //$NON-NLS-1$ + } + } + private void internalReconcile(XtextResource resource, boolean force) throws Exception { @@ -442,7 +489,8 @@ public class HandlyXtextDocument if (force) // reconciling is forced { NonExpiringSnapshot snapshot = reconciledSnapshot; - resource.reparse(snapshot.getContents()); + // no need to reparse -- just update internal state + resource.update(0, 0, ""); //$NON-NLS-1$ reconciled(resource, snapshot, true); } return false; diff --git a/org.eclipse.handly.xtext.ui/src/org/eclipse/handly/xtext/ui/editor/HandlyXtextReconciler.java b/org.eclipse.handly.xtext.ui/src/org/eclipse/handly/xtext/ui/editor/HandlyXtextReconciler.java index 53aed0e2..7803f7da 100644 --- a/org.eclipse.handly.xtext.ui/src/org/eclipse/handly/xtext/ui/editor/HandlyXtextReconciler.java +++ b/org.eclipse.handly.xtext.ui/src/org/eclipse/handly/xtext/ui/editor/HandlyXtextReconciler.java @@ -42,6 +42,8 @@ public class HandlyXtextReconciler { /** * Constant identifying the job family identifier for the reconciler job. + * @deprecated Use <code>org.eclipse.xtext.ui.refactoring.ui.SyncUtil</code> + * to wait for XtextEditor reconciler. */ public static final Object FAMILY_RECONCILER = XtextReconciler.class.getName(); @@ -135,7 +137,9 @@ public class HandlyXtextReconciler IDocument document = viewer.getDocument(); if (document instanceof HandlyXtextDocument) { - ((HandlyXtextDocument)document).reconcile(false); + HandlyXtextDocument doc = (HandlyXtextDocument)document; + if (doc.needsReconciling()) + doc.reconcile(false); } return Status.OK_STATUS; } |