Skip to main content

This CGIT instance is deprecated, and repositories have been moved to Gitlab or Github. See the repository descriptions for specific locations.

summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornitind2007-08-01 22:53:07 +0000
committernitind2007-08-01 22:53:07 +0000
commit464be561fdab5e59698689fd3fbc792e2d949a9a (patch)
treeed562323d88694e53f2a994431cb955cf23947d8 /bundles
parent86913fbd764c920ff4511c5a79d2bce859861763 (diff)
downloadwebtools.sourceediting-464be561fdab5e59698689fd3fbc792e2d949a9a.tar.gz
webtools.sourceediting-464be561fdab5e59698689fd3fbc792e2d949a9a.tar.xz
webtools.sourceediting-464be561fdab5e59698689fd3fbc792e2d949a9a.zip
194276 - Backport 192530 to 1.5.5 [XML Editor burns and leaks memory like crazy with spelling enabled]
Diffstat (limited to 'bundles')
-rw-r--r--bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/text/GenericPositionManager.java10
-rw-r--r--bundles/org.eclipse.wst.sse.ui/META-INF/MANIFEST.MF2
-rw-r--r--bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/spelling/SpellcheckStrategy.java112
3 files changed, 93 insertions, 31 deletions
diff --git a/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/text/GenericPositionManager.java b/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/text/GenericPositionManager.java
index 5083724f05..2af50b0ee6 100644
--- a/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/text/GenericPositionManager.java
+++ b/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/text/GenericPositionManager.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2001, 2004 IBM Corporation and others.
+ * Copyright (c) 2001, 2007 IBM Corporation 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
@@ -74,7 +74,7 @@ public class GenericPositionManager {
* @see org.eclipse.jface.text.IDocument#addPosition(java.lang.String,
* org.eclipse.jface.text.Position)
*/
- public void addPosition(String category, Position position) throws BadLocationException, BadPositionCategoryException {
+ public synchronized void addPosition(String category, Position position) throws BadLocationException, BadPositionCategoryException {
if ((0 > position.offset) || (0 > position.length) || (position.offset + position.length > getDocumentLength()))
throw new BadLocationException();
@@ -153,7 +153,7 @@ public class GenericPositionManager {
*
* @see IDocument#computeIndexInCategory(String, int)
*/
- protected int computeIndexInPositionList(List positions, int offset) {
+ protected synchronized int computeIndexInPositionList(List positions, int offset) {
if (positions.size() == 0)
return 0;
@@ -255,6 +255,8 @@ public class GenericPositionManager {
/**
* Returns all positions managed by the document grouped by category.
*
+ * @deprecated - exposes volatile internals
+ *
* @return the document's positions
*/
protected Map getDocumentManagedPositions() {
@@ -329,7 +331,7 @@ public class GenericPositionManager {
* @see org.eclipse.jface.text.IDocument#removePosition(java.lang.String,
* org.eclipse.jface.text.Position)
*/
- public void removePosition(String category, Position position) throws BadPositionCategoryException {
+ public synchronized void removePosition(String category, Position position) throws BadPositionCategoryException {
if (position == null)
return;
diff --git a/bundles/org.eclipse.wst.sse.ui/META-INF/MANIFEST.MF b/bundles/org.eclipse.wst.sse.ui/META-INF/MANIFEST.MF
index cd1aa77027..c8bbdd06bf 100644
--- a/bundles/org.eclipse.wst.sse.ui/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.wst.sse.ui/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.wst.sse.ui; singleton:=true
-Bundle-Version: 1.0.202.qualifier
+Bundle-Version: 1.0.203.qualifier
Bundle-Activator: org.eclipse.wst.sse.ui.internal.SSEUIPlugin
Bundle-Vendor: %providerName
Bundle-Localization: plugin
diff --git a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/spelling/SpellcheckStrategy.java b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/spelling/SpellcheckStrategy.java
index 4e01c14ad1..692779a5f0 100644
--- a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/spelling/SpellcheckStrategy.java
+++ b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/spelling/SpellcheckStrategy.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006 IBM Corporation and others.
+ * Copyright (c) 2006, 2007 IBM Corporation 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
@@ -44,6 +44,10 @@ import org.eclipse.ui.texteditor.spelling.SpellingContext;
import org.eclipse.ui.texteditor.spelling.SpellingEngineDescriptor;
import org.eclipse.ui.texteditor.spelling.SpellingProblem;
import org.eclipse.ui.texteditor.spelling.SpellingService;
+import org.eclipse.wst.sse.core.internal.parser.ForeignRegion;
+import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument;
+import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
+import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion;
import org.eclipse.wst.sse.core.utils.StringUtils;
import org.eclipse.wst.sse.ui.internal.ExtendedConfigurationBuilder;
import org.eclipse.wst.sse.ui.internal.Logger;
@@ -80,6 +84,9 @@ public class SpellcheckStrategy extends StructuredTextReconcilingStrategy {
List annotations = new ArrayList();
public void accept(SpellingProblem problem) {
+ if (!isInterestingProblem(problem))
+ return;
+
TemporaryAnnotation annotation = new TemporaryAnnotation(new Position(problem.getOffset(), problem.getLength()), TemporaryAnnotation.ANNOT_WARNING, problem.getMessage(), fReconcileAnnotationKey);
/*
* TODO: create and use an IQuickFixProcessor that uses
@@ -103,6 +110,36 @@ public class SpellcheckStrategy extends StructuredTextReconcilingStrategy {
public void endCollecting() {
}
+ /**
+ * Judge whether a spelling problem is "interesting". Accept any
+ * regions that are explictly allowed, and since valid prose areas are
+ * rarely in a complicated document region, accept any document region
+ * with more than one text region and reject any document regions
+ * containing foreign text regions.
+ *
+ * @param problem
+ * a SpellingProblem
+ * @return whether the collector should accept the given
+ * SpellingProblem
+ */
+ boolean isInterestingProblem(SpellingProblem problem) {
+ if (getDocument() instanceof IStructuredDocument) {
+ IStructuredDocumentRegion documentRegion = ((IStructuredDocument) getDocument()).getRegionAtCharacterOffset(problem.getOffset());
+ if (documentRegion != null) {
+ ITextRegion textRegion = documentRegion.getRegionAtCharacterOffset(problem.getOffset());
+ if (textRegion != null) {
+ return true;
+ }
+ if (documentRegion.getFirstRegion() instanceof ForeignRegion)
+ return false;
+ if (documentRegion.getRegions().size() == 1)
+ return true;
+ return false;
+ }
+ }
+ return true;
+ }
+
IReconcileResult[] getResults() {
return (IReconcileResult[]) annotations.toArray(new IReconcileResult[annotations.size()]);
}
@@ -282,45 +319,68 @@ public class SpellcheckStrategy extends StructuredTextReconcilingStrategy {
if (isCanceled())
return;
- TemporaryAnnotation[] annotationsToRemove = null;
- IReconcileResult[] annotationsToAdd = null;
- StructuredReconcileStep structuredStep = (StructuredReconcileStep) fSpellingStep;
IAnnotationModel annotationModel = getAnnotationModel();
IDocument document = getDocument();
if (document != null) {
try {
- ITypedRegion[] partitions = TextUtilities.computePartitioning(document, getDocumentPartitioning(), dirtyRegion.getOffset(), dirtyRegion.getLength(), true);
- for (int i = 0; i < partitions.length; i++) {
- if (isSupportedPartitionType(partitions[i].getType())) {
- annotationsToRemove = getSpellingAnnotationsToRemove(partitions[i]);
- annotationsToAdd = structuredStep.reconcile(dirtyRegion, partitions[i]);
-
- if (annotationModel instanceof IAnnotationModelExtension) {
- IAnnotationModelExtension modelExtension = (IAnnotationModelExtension) annotationModel;
- Map annotationsToAddMap = new HashMap();
- for (int j = 0; j < annotationsToAdd.length; j++) {
- annotationsToAddMap.put(annotationsToAdd[j], ((TemporaryAnnotation) annotationsToAdd[j]).getPosition());
- }
- modelExtension.replaceAnnotations(annotationsToRemove, annotationsToAddMap);
- }
-
- else {
- for (int j = 0; j < annotationsToAdd.length; j++) {
- annotationModel.addAnnotation((TemporaryAnnotation) annotationsToAdd[j], ((TemporaryAnnotation) annotationsToAdd[j]).getPosition());
- }
- for (int j = 0; j < annotationsToRemove.length; j++) {
- annotationModel.removeAnnotation(annotationsToRemove[j]);
- }
+ /**
+ * Apparently the default spelling engine has noticeable
+ * overhead for each call made to it, as well as the
+ * IAnnotatioModel updates we would perform for each. It's
+ * faster to check the entire dirty region at once if we know
+ * that we're not differentiating by partition.
+ *
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=192530
+ */
+ if (checkByPartitions()) {
+ ITypedRegion[] partitions = TextUtilities.computePartitioning(document, getDocumentPartitioning(), dirtyRegion.getOffset(), dirtyRegion.getLength(), true);
+ for (int i = 0; i < partitions.length; i++) {
+ if (isSupportedPartitionType(partitions[i].getType())) {
+ spellCheck(dirtyRegion, partitions[i], annotationModel);
}
}
}
+ else {
+ spellCheck(dirtyRegion, dirtyRegion, annotationModel);
+ }
}
catch (BadLocationException e) {
}
}
}
+ boolean checkByPartitions() {
+ return (fSupportedPartitionTypes != null && fSupportedPartitionTypes.length > 0);
+ }
+
+ private void spellCheck(DirtyRegion dirtyRegion, IRegion regionToBeChecked, IAnnotationModel annotationModel) {
+ StructuredReconcileStep structuredStep = (StructuredReconcileStep) fSpellingStep;
+
+ TemporaryAnnotation[] annotationsToRemove;
+ IReconcileResult[] annotationsToAdd;
+ annotationsToRemove = getSpellingAnnotationsToRemove(regionToBeChecked);
+ annotationsToAdd = structuredStep.reconcile(dirtyRegion, regionToBeChecked);
+
+ if (annotationModel instanceof IAnnotationModelExtension) {
+ IAnnotationModelExtension modelExtension = (IAnnotationModelExtension) annotationModel;
+ Map annotationsToAddMap = new HashMap();
+ for (int i = 0; i < annotationsToAdd.length; i++) {
+ annotationsToAddMap.put(annotationsToAdd[i], ((TemporaryAnnotation) annotationsToAdd[i]).getPosition());
+ }
+ modelExtension.replaceAnnotations(annotationsToRemove, annotationsToAddMap);
+ }
+
+ else {
+ for (int j = 0; j < annotationsToAdd.length; j++) {
+ annotationModel.addAnnotation((TemporaryAnnotation) annotationsToAdd[j], ((TemporaryAnnotation) annotationsToAdd[j]).getPosition());
+ }
+ for (int j = 0; j < annotationsToRemove.length; j++) {
+ annotationModel.removeAnnotation(annotationsToRemove[j]);
+ }
+ }
+ }
+
/**
* @param partition
* @see org.eclipse.jface.text.reconciler.IReconcilingStrategy#reconcile(org.eclipse.jface.text.IRegion)

Back to the top