| author | hbehrens | 2008-11-21 06:07:43 (EST) |
|---|---|---|
| committer | sefftinge | 2008-11-21 06:07:43 (EST) |
| commit | 6eab5a87202ca5ec8e59286e56c388c22840df77 (patch) (side-by-side diff) | |
| tree | 113ad13f76b6699d915eac695c5314438f0688c3 | |
| parent | 0dff25ab190411cc40613ab87bb28b6291db0916 (diff) | |
| download | org.eclipse.xtext-6eab5a87202ca5ec8e59286e56c388c22840df77.zip org.eclipse.xtext-6eab5a87202ca5ec8e59286e56c388c22840df77.tar.gz org.eclipse.xtext-6eab5a87202ca5ec8e59286e56c388c22840df77.tar.bz2 | |
* Performance und minor refactorings (two patches from Sebastian)
4 files changed, 66 insertions, 52 deletions
diff --git a/plugins/org.eclipse.xtext.ui.core/src/org/eclipse/xtext/ui/core/editor/reconciler/XtextDocumentReconcileStrategy.java b/plugins/org.eclipse.xtext.ui.core/src/org/eclipse/xtext/ui/core/editor/reconciler/XtextDocumentReconcileStrategy.java index 778af10..e04a8eb 100644 --- a/plugins/org.eclipse.xtext.ui.core/src/org/eclipse/xtext/ui/core/editor/reconciler/XtextDocumentReconcileStrategy.java +++ b/plugins/org.eclipse.xtext.ui.core/src/org/eclipse/xtext/ui/core/editor/reconciler/XtextDocumentReconcileStrategy.java @@ -24,7 +24,7 @@ public class XtextDocumentReconcileStrategy implements IReconcilingStrategy { private XtextDocument document; public void reconcile(final IRegion region) { - document.modify(XtextReconcilerHelper.createReconcileJob(region, document)); + document.modify(new XtextReconcilerUnitOfWork(region, document)); } public void reconcile(DirtyRegion dirtyRegion, IRegion subRegion) { diff --git a/plugins/org.eclipse.xtext.ui.core/src/org/eclipse/xtext/ui/core/editor/reconciler/XtextReconciler.java b/plugins/org.eclipse.xtext.ui.core/src/org/eclipse/xtext/ui/core/editor/reconciler/XtextReconciler.java index c25860b..fa79050 100644 --- a/plugins/org.eclipse.xtext.ui.core/src/org/eclipse/xtext/ui/core/editor/reconciler/XtextReconciler.java +++ b/plugins/org.eclipse.xtext.ui.core/src/org/eclipse/xtext/ui/core/editor/reconciler/XtextReconciler.java @@ -66,7 +66,7 @@ public class XtextReconciler extends Job implements IReconciler { if (document != null) { final ReplaceRegion replaceRegionToBeProcessed = getAndResetReplaceRegion(); if (replaceRegionToBeProcessed != null) { - processor.process(XtextReconcilerHelper.createReconcileJob(replaceRegionToBeProcessed, document)); + processor.process(new XtextReconcilerUnitOfWork(replaceRegionToBeProcessed, document)); } } } diff --git a/plugins/org.eclipse.xtext.ui.core/src/org/eclipse/xtext/ui/core/editor/reconciler/XtextReconcilerHelper.java b/plugins/org.eclipse.xtext.ui.core/src/org/eclipse/xtext/ui/core/editor/reconciler/XtextReconcilerHelper.java deleted file mode 100644 index c8cddf6..0000000 --- a/plugins/org.eclipse.xtext.ui.core/src/org/eclipse/xtext/ui/core/editor/reconciler/XtextReconcilerHelper.java +++ b/dev/null @@ -1,50 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 itemis AG (http://www.itemis.eu) and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - *******************************************************************************/ -package org.eclipse.xtext.ui.core.editor.reconciler; - -import org.apache.log4j.Logger; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.IRegion; -import org.eclipse.xtext.resource.XtextResource; -import org.eclipse.xtext.ui.core.editor.model.UnitOfWork; - -/** - * @author Sebastian Zarnekow - Initial contribution and API - */ -public class XtextReconcilerHelper { - - private static final Logger log = Logger.getLogger(XtextReconcilerHelper.class); - - public static UnitOfWork<Object> createReconcileJob(final IRegion region, final IDocument document) { - - return new UnitOfWork<Object>() { - public Object exec(XtextResource resource) throws Exception { - if (log.isDebugEnabled()) - log.debug("Preparing reconciliation."); - try { - if (!(region instanceof ReplaceRegion)) { - throw new IllegalArgumentException("Region to be reconciled must be a ReplaceRegion"); - } - ReplaceRegion replaceRegionToBeProcessed = (ReplaceRegion) region; - - if(log.isTraceEnabled()) - log.trace("Parsing replace region '" + replaceRegionToBeProcessed.getText() + "'."); - - resource.update(replaceRegionToBeProcessed.getOffset(), replaceRegionToBeProcessed.getLength(), - replaceRegionToBeProcessed.getText()); - } - catch (Throwable t) { - if (log.isDebugEnabled()) - log.debug("Partial parsing failed. Performing full reparse", t); - resource.reparse(document.get()); - } - return null; - } - }; - } -} diff --git a/plugins/org.eclipse.xtext.ui.core/src/org/eclipse/xtext/ui/core/editor/reconciler/XtextReconcilerUnitOfWork.java b/plugins/org.eclipse.xtext.ui.core/src/org/eclipse/xtext/ui/core/editor/reconciler/XtextReconcilerUnitOfWork.java new file mode 100644 index 0000000..9714ee4 --- a/dev/null +++ b/plugins/org.eclipse.xtext.ui.core/src/org/eclipse/xtext/ui/core/editor/reconciler/XtextReconcilerUnitOfWork.java @@ -0,0 +1,64 @@ +/******************************************************************************* + * Copyright (c) 2008 itemis AG (http://www.itemis.eu) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + *******************************************************************************/ +package org.eclipse.xtext.ui.core.editor.reconciler; + +import org.apache.log4j.Logger; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.IRegion; +import org.eclipse.xtext.resource.XtextResource; +import org.eclipse.xtext.ui.core.editor.model.UnitOfWork; + +/** + * @author Sebastian Zarnekow - Initial contribution and API + */ +class XtextReconcilerUnitOfWork implements UnitOfWork<Void> { + + private static final Logger log = Logger.getLogger(XtextReconcilerUnitOfWork.class); + + private IRegion region; + + private IDocument document; + + /** + * @param region + * @param document + */ + public XtextReconcilerUnitOfWork(IRegion region, IDocument document) { + super(); + this.document = document; + this.region = region; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.xtext.ui.core.editor.model.UnitOfWork#exec(org.eclipse.xtext.resource.XtextResource) + */ + public Void exec(XtextResource resource) throws Exception { + if (log.isDebugEnabled()) + log.debug("Preparing reconciliation."); + try { + if (!(region instanceof ReplaceRegion)) { + throw new IllegalArgumentException("Region to be reconciled must be a ReplaceRegion"); + } + ReplaceRegion replaceRegionToBeProcessed = (ReplaceRegion) region; + + if (log.isTraceEnabled()) + log.trace("Parsing replace region '" + replaceRegionToBeProcessed.getText() + "'."); + + resource.update(replaceRegionToBeProcessed.getOffset(), replaceRegionToBeProcessed.getLength(), + replaceRegionToBeProcessed.getText()); + } + catch (Throwable t) { + if (log.isDebugEnabled()) + log.debug("Partial parsing failed. Performing full reparse", t); + resource.reparse(document.get()); + } + return null; + } +} |

