nitind | 93023a1 | 2006-09-19 18:24:13 +0000 | [diff] [blame] | 1 | /******************************************************************************* |
nsandonato | ff577b4 | 2010-03-29 14:55:55 +0000 | [diff] [blame] | 2 | * Copyright (c) 2006, 2010 IBM Corporation and others. |
nitind | 93023a1 | 2006-09-19 18:24:13 +0000 | [diff] [blame] | 3 | * All rights reserved. This program and the accompanying materials |
| 4 | * are made available under the terms of the Eclipse Public License v1.0 |
| 5 | * which accompanies this distribution, and is available at |
| 6 | * http://www.eclipse.org/legal/epl-v10.html |
| 7 | * |
| 8 | * Contributors: |
| 9 | * IBM Corporation - initial API and implementation |
nsandonato | ff577b4 | 2010-03-29 14:55:55 +0000 | [diff] [blame] | 10 | * David Carver (Intalio) - bug 307323 - remove extraneous call to spell check strategy |
nitind | 93023a1 | 2006-09-19 18:24:13 +0000 | [diff] [blame] | 11 | *******************************************************************************/ |
pavery | dc8b306 | 2005-10-24 20:43:42 +0000 | [diff] [blame] | 12 | package org.eclipse.wst.sse.ui.internal.reconcile; |
| 13 | |
pavery | dc8b306 | 2005-10-24 20:43:42 +0000 | [diff] [blame] | 14 | import java.io.IOException; |
nitind | c77f963 | 2008-03-19 21:26:39 +0000 | [diff] [blame] | 15 | import java.io.StringReader; |
nitind | 93023a1 | 2006-09-19 18:24:13 +0000 | [diff] [blame] | 16 | import java.util.ArrayList; |
nsandonato | 8efc758 | 2009-12-02 23:52:57 +0000 | [diff] [blame] | 17 | import java.util.Arrays; |
| 18 | import java.util.HashSet; |
nitind | 93023a1 | 2006-09-19 18:24:13 +0000 | [diff] [blame] | 19 | import java.util.List; |
nsandonato | 8efc758 | 2009-12-02 23:52:57 +0000 | [diff] [blame] | 20 | import java.util.Set; |
pavery | dc8b306 | 2005-10-24 20:43:42 +0000 | [diff] [blame] | 21 | |
nsandonato | 8efc758 | 2009-12-02 23:52:57 +0000 | [diff] [blame] | 22 | import org.eclipse.core.runtime.NullProgressMonitor; |
pavery | dc8b306 | 2005-10-24 20:43:42 +0000 | [diff] [blame] | 23 | import org.eclipse.core.runtime.Platform; |
| 24 | import org.eclipse.core.runtime.content.IContentDescription; |
| 25 | import org.eclipse.core.runtime.content.IContentType; |
nitind | bb9106d | 2008-10-11 00:52:30 +0000 | [diff] [blame] | 26 | import org.eclipse.core.runtime.content.IContentTypeManager; |
pavery | dc8b306 | 2005-10-24 20:43:42 +0000 | [diff] [blame] | 27 | import org.eclipse.jface.text.IDocument; |
nsandonato | 9592423 | 2009-08-26 20:50:40 +0000 | [diff] [blame] | 28 | import org.eclipse.jface.text.ITextViewer; |
pavery | dc8b306 | 2005-10-24 20:43:42 +0000 | [diff] [blame] | 29 | import org.eclipse.jface.text.ITypedRegion; |
nitind | f3f1087 | 2007-09-03 06:36:56 +0000 | [diff] [blame] | 30 | import org.eclipse.jface.text.Region; |
pavery | dc8b306 | 2005-10-24 20:43:42 +0000 | [diff] [blame] | 31 | import org.eclipse.jface.text.reconciler.DirtyRegion; |
| 32 | import org.eclipse.jface.text.reconciler.IReconcilingStrategy; |
nsandonato | 8efc758 | 2009-12-02 23:52:57 +0000 | [diff] [blame] | 33 | import org.eclipse.jface.text.source.IAnnotationModel; |
pavery | dc8b306 | 2005-10-24 20:43:42 +0000 | [diff] [blame] | 34 | import org.eclipse.jface.text.source.ISourceViewer; |
nitind | b8d8891 | 2010-04-05 13:49:32 +0000 | [diff] [blame] | 35 | import org.eclipse.jface.text.source.projection.ProjectionViewer; |
nsandonato | 9592423 | 2009-08-26 20:50:40 +0000 | [diff] [blame] | 36 | import org.eclipse.wst.sse.ui.internal.ExtendedConfigurationBuilder; |
pavery | dc8b306 | 2005-10-24 20:43:42 +0000 | [diff] [blame] | 37 | import org.eclipse.wst.sse.ui.internal.IReleasable; |
nitind | 93023a1 | 2006-09-19 18:24:13 +0000 | [diff] [blame] | 38 | import org.eclipse.wst.sse.ui.internal.Logger; |
nsandonato | 9592423 | 2009-08-26 20:50:40 +0000 | [diff] [blame] | 39 | import org.eclipse.wst.sse.ui.internal.SSEUIPlugin; |
nsandonato | 9592423 | 2009-08-26 20:50:40 +0000 | [diff] [blame] | 40 | import org.eclipse.wst.sse.ui.internal.projection.AbstractStructuredFoldingStrategy; |
| 41 | import org.eclipse.wst.sse.ui.internal.provisional.preferences.CommonEditorPreferenceNames; |
pavery | dc8b306 | 2005-10-24 20:43:42 +0000 | [diff] [blame] | 42 | import org.eclipse.wst.sse.ui.internal.reconcile.validator.ValidatorBuilder; |
| 43 | import org.eclipse.wst.sse.ui.internal.reconcile.validator.ValidatorMetaData; |
| 44 | import org.eclipse.wst.sse.ui.internal.reconcile.validator.ValidatorStrategy; |
nitind | b044597 | 2006-02-16 22:19:20 +0000 | [diff] [blame] | 45 | import org.eclipse.wst.sse.ui.internal.spelling.SpellcheckStrategy; |
nsandonato | 7a2c57a | 2010-01-19 20:01:07 +0000 | [diff] [blame] | 46 | import org.eclipse.wst.sse.ui.reconcile.ISourceReconcilingListener; |
pavery | dc8b306 | 2005-10-24 20:43:42 +0000 | [diff] [blame] | 47 | |
| 48 | /** |
nitind | b044597 | 2006-02-16 22:19:20 +0000 | [diff] [blame] | 49 | * Adds to DirtyRegionProcessor Job: - IDocumentListener - ValidatorStrategy - |
| 50 | * Text viewer(dispose, input changed) listeners. - default, spelling, and |
| 51 | * validator strategies - DirtyRegion processing logic. |
pavery | dc8b306 | 2005-10-24 20:43:42 +0000 | [diff] [blame] | 52 | */ |
nitind | b044597 | 2006-02-16 22:19:20 +0000 | [diff] [blame] | 53 | public class DocumentRegionProcessor extends DirtyRegionProcessor { |
nitind | c77f963 | 2008-03-19 21:26:39 +0000 | [diff] [blame] | 54 | private static final boolean DEBUG_VALIDATORS = Boolean.TRUE.toString().equalsIgnoreCase(Platform.getDebugOption("org.eclipse.wst.sse.ui/debug/reconcilerValidators")); //$NON-NLS-1$ |
nitind | 93023a1 | 2006-09-19 18:24:13 +0000 | [diff] [blame] | 55 | |
pavery | dc8b306 | 2005-10-24 20:43:42 +0000 | [diff] [blame] | 56 | /** |
nitind | b044597 | 2006-02-16 22:19:20 +0000 | [diff] [blame] | 57 | * A strategy to use the defined default Spelling service. |
pavery | dc8b306 | 2005-10-24 20:43:42 +0000 | [diff] [blame] | 58 | */ |
nitind | c77f963 | 2008-03-19 21:26:39 +0000 | [diff] [blame] | 59 | private IReconcilingStrategy fSpellcheckStrategy; |
pavery | dc8b306 | 2005-10-24 20:43:42 +0000 | [diff] [blame] | 60 | |
pavery | dc8b306 | 2005-10-24 20:43:42 +0000 | [diff] [blame] | 61 | /** |
| 62 | * The strategy that runs validators contributed via |
| 63 | * <code>org.eclipse.wst.sse.ui.extensions.sourcevalidation</code> |
| 64 | * extension point |
| 65 | */ |
| 66 | private ValidatorStrategy fValidatorStrategy; |
nitind | b044597 | 2006-02-16 22:19:20 +0000 | [diff] [blame] | 67 | |
nsandonato | 8efc758 | 2009-12-02 23:52:57 +0000 | [diff] [blame] | 68 | private ISourceReconcilingListener[] fReconcileListeners = new ISourceReconcilingListener[0]; |
| 69 | |
nsandonato | 8c64252 | 2009-01-26 22:45:19 +0000 | [diff] [blame] | 70 | private IReconcilingStrategy fSemanticHighlightingStrategy; |
| 71 | |
nsandonato | 9592423 | 2009-08-26 20:50:40 +0000 | [diff] [blame] | 72 | /** |
| 73 | * The folding strategy for this processor |
| 74 | */ |
| 75 | private AbstractStructuredFoldingStrategy fFoldingStrategy; |
| 76 | |
nitind | a5804e8 | 2006-03-14 00:54:11 +0000 | [diff] [blame] | 77 | private final String SSE_UI_ID = "org.eclipse.wst.sse.ui"; //$NON-NLS-1$ |
pavery | dc8b306 | 2005-10-24 20:43:42 +0000 | [diff] [blame] | 78 | |
nsandonato | 9592423 | 2009-08-26 20:50:40 +0000 | [diff] [blame] | 79 | /** |
| 80 | * true if as you type validation is enabled, |
| 81 | * false otherwise |
| 82 | */ |
| 83 | private boolean fValidationEnabled; |
nsandonato | 8efc758 | 2009-12-02 23:52:57 +0000 | [diff] [blame] | 84 | |
| 85 | public void addReconcilingListener(ISourceReconcilingListener listener) { |
| 86 | Set listeners = new HashSet(Arrays.asList(fReconcileListeners)); |
| 87 | listeners.add(listener); |
| 88 | fReconcileListeners = (ISourceReconcilingListener[]) listeners.toArray(new ISourceReconcilingListener[listeners.size()]); |
| 89 | } |
| 90 | |
nitind | b044597 | 2006-02-16 22:19:20 +0000 | [diff] [blame] | 91 | protected void beginProcessing() { |
| 92 | super.beginProcessing(); |
nitind | a5804e8 | 2006-03-14 00:54:11 +0000 | [diff] [blame] | 93 | ValidatorStrategy validatorStrategy = getValidatorStrategy(); |
| 94 | if (validatorStrategy != null) { |
| 95 | validatorStrategy.beginProcessing(); |
| 96 | } |
nsandonato | 8efc758 | 2009-12-02 23:52:57 +0000 | [diff] [blame] | 97 | if ((getTextViewer() instanceof ISourceViewer)) { |
| 98 | for (int i = 0; i < fReconcileListeners.length; i++) { |
| 99 | fReconcileListeners[i].aboutToBeReconciled(); |
| 100 | } |
| 101 | } |
pavery | dc8b306 | 2005-10-24 20:43:42 +0000 | [diff] [blame] | 102 | } |
pavery | dc8b306 | 2005-10-24 20:43:42 +0000 | [diff] [blame] | 103 | |
nitind | b044597 | 2006-02-16 22:19:20 +0000 | [diff] [blame] | 104 | protected void endProcessing() { |
| 105 | super.endProcessing(); |
nitind | a5804e8 | 2006-03-14 00:54:11 +0000 | [diff] [blame] | 106 | ValidatorStrategy validatorStrategy = getValidatorStrategy(); |
| 107 | if (validatorStrategy != null) { |
| 108 | validatorStrategy.endProcessing(); |
| 109 | } |
nitind | 5893a85 | 2008-08-09 19:19:10 +0000 | [diff] [blame] | 110 | /* single spell-check for everything to ensure that SpellingProblem offsets are correct */ |
nitind | bb9106d | 2008-10-11 00:52:30 +0000 | [diff] [blame] | 111 | IReconcilingStrategy spellingStrategy = getSpellcheckStrategy(); |
nitind | fefa770 | 2008-10-11 01:12:21 +0000 | [diff] [blame] | 112 | IDocument document = getDocument(); |
| 113 | if (spellingStrategy != null && document != null) { |
nsandonato | ff577b4 | 2010-03-29 14:55:55 +0000 | [diff] [blame] | 114 | spellingStrategy.reconcile(new Region(0, document.getLength())); |
nitind | 5893a85 | 2008-08-09 19:19:10 +0000 | [diff] [blame] | 115 | } |
nsandonato | 8c64252 | 2009-01-26 22:45:19 +0000 | [diff] [blame] | 116 | |
| 117 | IReconcilingStrategy semanticHighlightingStrategy = getSemanticHighlightingStrategy(); |
| 118 | if (semanticHighlightingStrategy != null && document != null) { |
| 119 | semanticHighlightingStrategy.reconcile(new Region(0, document.getLength())); |
| 120 | } |
nsandonato | 8efc758 | 2009-12-02 23:52:57 +0000 | [diff] [blame] | 121 | |
| 122 | if ((getTextViewer() instanceof ISourceViewer)) { |
| 123 | ISourceViewer sourceViewer = (ISourceViewer) getTextViewer(); |
| 124 | IAnnotationModel annotationModel = sourceViewer.getAnnotationModel(); |
| 125 | for (int i = 0; i < fReconcileListeners.length; i++) { |
| 126 | fReconcileListeners[i].reconciled(document, annotationModel, false, new NullProgressMonitor()); |
| 127 | } |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | public void forceReconciling() { |
| 132 | super.forceReconciling(); |
nitind | b044597 | 2006-02-16 22:19:20 +0000 | [diff] [blame] | 133 | } |
pavery | dc8b306 | 2005-10-24 20:43:42 +0000 | [diff] [blame] | 134 | |
nitind | b044597 | 2006-02-16 22:19:20 +0000 | [diff] [blame] | 135 | protected String getContentType(IDocument doc) { |
| 136 | if (doc == null) |
| 137 | return null; |
pavery | dc8b306 | 2005-10-24 20:43:42 +0000 | [diff] [blame] | 138 | |
nitind | b044597 | 2006-02-16 22:19:20 +0000 | [diff] [blame] | 139 | String contentTypeId = null; |
pavery | dc8b306 | 2005-10-24 20:43:42 +0000 | [diff] [blame] | 140 | |
nitind | b044597 | 2006-02-16 22:19:20 +0000 | [diff] [blame] | 141 | IContentType ct = null; |
| 142 | try { |
nitind | c77f963 | 2008-03-19 21:26:39 +0000 | [diff] [blame] | 143 | IContentDescription desc = Platform.getContentTypeManager().getDescriptionFor(new StringReader(doc.get()), null, IContentDescription.ALL); |
nitind | b044597 | 2006-02-16 22:19:20 +0000 | [diff] [blame] | 144 | if (desc != null) { |
| 145 | ct = desc.getContentType(); |
| 146 | if (ct != null) |
| 147 | contentTypeId = ct.getId(); |
pavery | dc8b306 | 2005-10-24 20:43:42 +0000 | [diff] [blame] | 148 | } |
| 149 | } |
nitind | b044597 | 2006-02-16 22:19:20 +0000 | [diff] [blame] | 150 | catch (IOException e) { |
| 151 | // just bail |
pavery | dc8b306 | 2005-10-24 20:43:42 +0000 | [diff] [blame] | 152 | } |
nitind | b044597 | 2006-02-16 22:19:20 +0000 | [diff] [blame] | 153 | return contentTypeId; |
pavery | dc8b306 | 2005-10-24 20:43:42 +0000 | [diff] [blame] | 154 | } |
pavery | dc8b306 | 2005-10-24 20:43:42 +0000 | [diff] [blame] | 155 | |
nitind | c77f963 | 2008-03-19 21:26:39 +0000 | [diff] [blame] | 156 | protected IReconcilingStrategy getSpellcheckStrategy() { |
nitind | bb9106d | 2008-10-11 00:52:30 +0000 | [diff] [blame] | 157 | if (fSpellcheckStrategy == null && getDocument() != null) { |
nitind | b044597 | 2006-02-16 22:19:20 +0000 | [diff] [blame] | 158 | String contentTypeId = getContentType(getDocument()); |
nitind | bb9106d | 2008-10-11 00:52:30 +0000 | [diff] [blame] | 159 | if (contentTypeId == null) { |
| 160 | contentTypeId = IContentTypeManager.CT_TEXT; |
| 161 | } |
| 162 | if (getTextViewer() instanceof ISourceViewer) { |
| 163 | ISourceViewer viewer = (ISourceViewer) getTextViewer(); |
| 164 | fSpellcheckStrategy = new SpellcheckStrategy(viewer, contentTypeId); |
| 165 | fSpellcheckStrategy.setDocument(getDocument()); |
pavery | dc8b306 | 2005-10-24 20:43:42 +0000 | [diff] [blame] | 166 | } |
pavery | dc8b306 | 2005-10-24 20:43:42 +0000 | [diff] [blame] | 167 | } |
nitind | b044597 | 2006-02-16 22:19:20 +0000 | [diff] [blame] | 168 | return fSpellcheckStrategy; |
pavery | dc8b306 | 2005-10-24 20:43:42 +0000 | [diff] [blame] | 169 | } |
nsandonato | 9592423 | 2009-08-26 20:50:40 +0000 | [diff] [blame] | 170 | |
| 171 | /** |
| 172 | * <p>Get the folding strategy for this processor. Retrieved from the |
| 173 | * extended configuration builder. The processor chosen is set by the plugin.</p> |
| 174 | * |
| 175 | * <p>EX:<br /> |
| 176 | * <code><extension point="org.eclipse.wst.sse.ui.editorConfiguration"><br /> |
| 177 | * <provisionalConfiguration<br /> |
| 178 | * type="foldingstrategy"<br /> |
| 179 | * class="org.eclipse.wst.xml.ui.internal.projection.XMLFoldingStrategy"<br /> |
| 180 | * target="org.eclipse.core.runtime.xml, org.eclipse.wst.xml.core.xmlsource" /><br /> |
| 181 | * </extension></code></p> |
| 182 | * |
| 183 | * <p>The type must be equal to <code>AbstractFoldingStrategy.ID</code> (AKA: foldingstrategy) |
| 184 | * and the class must extend <code>org.eclipse.wst.sse.ui.internal.projection.AbstractFoldingStrategy</code> |
| 185 | * and the target must be a structured editor content type ID</p> |
| 186 | * |
| 187 | * @return the requested folding strategy or null if none can be found |
| 188 | */ |
| 189 | protected IReconcilingStrategy getFoldingStrategy() { |
| 190 | if(fFoldingStrategy == null && getDocument() != null) { |
| 191 | String contentTypeId = getContentType(getDocument()); |
| 192 | if (contentTypeId == null) { |
| 193 | contentTypeId = IContentTypeManager.CT_TEXT; |
| 194 | } |
| 195 | |
| 196 | ITextViewer viewer = getTextViewer(); |
nitind | b8d8891 | 2010-04-05 13:49:32 +0000 | [diff] [blame] | 197 | if(viewer instanceof ProjectionViewer) { |
nsandonato | 9592423 | 2009-08-26 20:50:40 +0000 | [diff] [blame] | 198 | ExtendedConfigurationBuilder builder = ExtendedConfigurationBuilder.getInstance(); |
| 199 | |
| 200 | IContentType type = Platform.getContentTypeManager().getContentType(contentTypeId); |
| 201 | while(fFoldingStrategy == null && type != null) { |
| 202 | fFoldingStrategy =(AbstractStructuredFoldingStrategy) builder.getConfiguration( |
| 203 | AbstractStructuredFoldingStrategy.ID, type.getId()); |
| 204 | |
| 205 | type = type.getBaseType(); |
| 206 | } |
| 207 | |
| 208 | if(fFoldingStrategy != null) { |
nitind | b8d8891 | 2010-04-05 13:49:32 +0000 | [diff] [blame] | 209 | fFoldingStrategy.setViewer((ProjectionViewer)viewer); |
nsandonato | 9592423 | 2009-08-26 20:50:40 +0000 | [diff] [blame] | 210 | fFoldingStrategy.setDocument(getDocument()); |
| 211 | } |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | return fFoldingStrategy; |
| 216 | } |
| 217 | |
| 218 | /** |
| 219 | * Enable or disable as you type validation. Typically set by a user preference |
| 220 | * |
| 221 | * @param enable true to enable as you type validation, false to disable |
| 222 | */ |
| 223 | public void setValidatorStrategyEnabled(boolean enable) { |
| 224 | fValidationEnabled = enable; |
| 225 | } |
nitind | b044597 | 2006-02-16 22:19:20 +0000 | [diff] [blame] | 226 | |
pavery | dc8b306 | 2005-10-24 20:43:42 +0000 | [diff] [blame] | 227 | /** |
nitind | b044597 | 2006-02-16 22:19:20 +0000 | [diff] [blame] | 228 | * @return Returns the ValidatorStrategy. |
pavery | dc8b306 | 2005-10-24 20:43:42 +0000 | [diff] [blame] | 229 | */ |
nitind | b044597 | 2006-02-16 22:19:20 +0000 | [diff] [blame] | 230 | protected ValidatorStrategy getValidatorStrategy() { |
nsandonato | 9592423 | 2009-08-26 20:50:40 +0000 | [diff] [blame] | 231 | ValidatorStrategy validatorStrategy = null; |
| 232 | if (fValidatorStrategy == null && fValidationEnabled) { |
pavery | dc8b306 | 2005-10-24 20:43:42 +0000 | [diff] [blame] | 233 | if (getTextViewer() instanceof ISourceViewer) { |
nitind | b044597 | 2006-02-16 22:19:20 +0000 | [diff] [blame] | 234 | ISourceViewer viewer = (ISourceViewer) getTextViewer(); |
pavery | dc8b306 | 2005-10-24 20:43:42 +0000 | [diff] [blame] | 235 | String contentTypeId = null; |
nitind | b044597 | 2006-02-16 22:19:20 +0000 | [diff] [blame] | 236 | |
pavery | dc8b306 | 2005-10-24 20:43:42 +0000 | [diff] [blame] | 237 | IDocument doc = viewer.getDocument(); |
| 238 | contentTypeId = getContentType(doc); |
nitind | b044597 | 2006-02-16 22:19:20 +0000 | [diff] [blame] | 239 | |
pavery | dc8b306 | 2005-10-24 20:43:42 +0000 | [diff] [blame] | 240 | if (contentTypeId != null) { |
pavery | dc8b306 | 2005-10-24 20:43:42 +0000 | [diff] [blame] | 241 | validatorStrategy = new ValidatorStrategy(viewer, contentTypeId); |
| 242 | ValidatorBuilder vBuilder = new ValidatorBuilder(); |
nitind | a5804e8 | 2006-03-14 00:54:11 +0000 | [diff] [blame] | 243 | ValidatorMetaData[] vmds = vBuilder.getValidatorMetaData(SSE_UI_ID); |
nitind | 93023a1 | 2006-09-19 18:24:13 +0000 | [diff] [blame] | 244 | List enabledValidators = new ArrayList(1); |
| 245 | /* if any "must" handle this content type, just add them */ |
| 246 | boolean foundSpecificContentTypeValidators = false; |
pavery | dc8b306 | 2005-10-24 20:43:42 +0000 | [diff] [blame] | 247 | for (int i = 0; i < vmds.length; i++) { |
nitind | 93023a1 | 2006-09-19 18:24:13 +0000 | [diff] [blame] | 248 | if (vmds[i].mustHandleContentType(contentTypeId)) { |
| 249 | if (DEBUG_VALIDATORS) |
| 250 | Logger.log(Logger.INFO, contentTypeId + " using specific validator " + vmds[i].getValidatorId()); //$NON-NLS-1$ |
| 251 | foundSpecificContentTypeValidators = true; |
| 252 | enabledValidators.add(vmds[i]); |
| 253 | } |
| 254 | } |
| 255 | if (!foundSpecificContentTypeValidators) { |
| 256 | for (int i = 0; i < vmds.length; i++) { |
| 257 | if (vmds[i].canHandleContentType(contentTypeId)) { |
| 258 | if (DEBUG_VALIDATORS) |
| 259 | Logger.log(Logger.INFO, contentTypeId + " using inherited(?) validator " + vmds[i].getValidatorId()); //$NON-NLS-1$ |
| 260 | enabledValidators.add(vmds[i]); |
| 261 | } |
| 262 | } |
| 263 | } |
| 264 | for (int i = 0; i < enabledValidators.size(); i++) { |
| 265 | validatorStrategy.addValidatorMetaData((ValidatorMetaData) enabledValidators.get(i)); |
pavery | dc8b306 | 2005-10-24 20:43:42 +0000 | [diff] [blame] | 266 | } |
| 267 | } |
| 268 | } |
| 269 | fValidatorStrategy = validatorStrategy; |
nsandonato | 9592423 | 2009-08-26 20:50:40 +0000 | [diff] [blame] | 270 | } else if(fValidatorStrategy != null && fValidationEnabled) { |
| 271 | validatorStrategy = fValidatorStrategy; |
pavery | dc8b306 | 2005-10-24 20:43:42 +0000 | [diff] [blame] | 272 | } |
nsandonato | 9592423 | 2009-08-26 20:50:40 +0000 | [diff] [blame] | 273 | return validatorStrategy; |
pavery | dc8b306 | 2005-10-24 20:43:42 +0000 | [diff] [blame] | 274 | } |
nsandonato | 8c64252 | 2009-01-26 22:45:19 +0000 | [diff] [blame] | 275 | |
| 276 | public void setSemanticHighlightingStrategy(IReconcilingStrategy semanticHighlightingStrategy) { |
| 277 | fSemanticHighlightingStrategy = semanticHighlightingStrategy; |
| 278 | fSemanticHighlightingStrategy.setDocument(getDocument()); |
| 279 | } |
| 280 | |
| 281 | protected IReconcilingStrategy getSemanticHighlightingStrategy() { |
| 282 | return fSemanticHighlightingStrategy; |
| 283 | } |
nsandonato | 9592423 | 2009-08-26 20:50:40 +0000 | [diff] [blame] | 284 | |
pavery | dc8b306 | 2005-10-24 20:43:42 +0000 | [diff] [blame] | 285 | /** |
nitind | b044597 | 2006-02-16 22:19:20 +0000 | [diff] [blame] | 286 | * @param dirtyRegion |
pavery | dc8b306 | 2005-10-24 20:43:42 +0000 | [diff] [blame] | 287 | */ |
nitind | b044597 | 2006-02-16 22:19:20 +0000 | [diff] [blame] | 288 | protected void process(DirtyRegion dirtyRegion) { |
nsandonato | 0e6030b | 2009-12-15 15:51:37 +0000 | [diff] [blame] | 289 | if (!isInstalled() || isInRewriteSession() || dirtyRegion == null || getDocument() == null) |
nitind | b044597 | 2006-02-16 22:19:20 +0000 | [diff] [blame] | 290 | return; |
| 291 | |
| 292 | super.process(dirtyRegion); |
nsandonato | f165d2f | 2009-09-28 14:54:44 +0000 | [diff] [blame] | 293 | |
nitind | b044597 | 2006-02-16 22:19:20 +0000 | [diff] [blame] | 294 | ITypedRegion[] partitions = computePartitioning(dirtyRegion); |
nsandonato | f165d2f | 2009-09-28 14:54:44 +0000 | [diff] [blame] | 295 | |
| 296 | // call the validator strategy once for each effected partition |
nitind | b044597 | 2006-02-16 22:19:20 +0000 | [diff] [blame] | 297 | DirtyRegion dirty = null; |
| 298 | for (int i = 0; i < partitions.length; i++) { |
nsandonato | 9592423 | 2009-08-26 20:50:40 +0000 | [diff] [blame] | 299 | dirty = createDirtyRegion(partitions[i], DirtyRegion.INSERT); |
| 300 | |
nitind | b044597 | 2006-02-16 22:19:20 +0000 | [diff] [blame] | 301 | // [source]validator (extension) for this partition |
david_williams | 5ce6d6c | 2006-05-28 23:58:12 +0000 | [diff] [blame] | 302 | if (getValidatorStrategy() != null) { |
nitind | b044597 | 2006-02-16 22:19:20 +0000 | [diff] [blame] | 303 | getValidatorStrategy().reconcile(partitions[i], dirty); |
david_williams | 5ce6d6c | 2006-05-28 23:58:12 +0000 | [diff] [blame] | 304 | } |
nsandonato | f165d2f | 2009-09-28 14:54:44 +0000 | [diff] [blame] | 305 | } |
| 306 | |
| 307 | /* if there is a folding strategy then reconcile it for the |
| 308 | * entire dirty region. |
| 309 | * NOTE: the folding strategy does not care about the sub regions. |
| 310 | */ |
| 311 | if(getFoldingStrategy() != null) { |
| 312 | getFoldingStrategy().reconcile(dirtyRegion, null); |
pavery | 1f1588d | 2006-02-15 20:44:54 +0000 | [diff] [blame] | 313 | } |
pavery | dc8b306 | 2005-10-24 20:43:42 +0000 | [diff] [blame] | 314 | } |
nsandonato | 8efc758 | 2009-12-02 23:52:57 +0000 | [diff] [blame] | 315 | |
| 316 | public void removeReconcilingListener(ISourceReconcilingListener listener) { |
| 317 | Set listeners = new HashSet(Arrays.asList(fReconcileListeners)); |
| 318 | listeners.remove(listener); |
| 319 | fReconcileListeners = (ISourceReconcilingListener[]) listeners.toArray(new ISourceReconcilingListener[listeners.size()]); |
| 320 | } |
| 321 | |
pavery | dc8b306 | 2005-10-24 20:43:42 +0000 | [diff] [blame] | 322 | |
nitind | b044597 | 2006-02-16 22:19:20 +0000 | [diff] [blame] | 323 | public void setDocument(IDocument doc) { |
| 324 | super.setDocument(doc); |
nsandonato | 9592423 | 2009-08-26 20:50:40 +0000 | [diff] [blame] | 325 | |
nitind | b044597 | 2006-02-16 22:19:20 +0000 | [diff] [blame] | 326 | IReconcilingStrategy validatorStrategy = getValidatorStrategy(); |
| 327 | if (validatorStrategy != null) { |
| 328 | validatorStrategy.setDocument(doc); |
pavery | dc8b306 | 2005-10-24 20:43:42 +0000 | [diff] [blame] | 329 | } |
nsandonato | 033201e | 2010-08-10 20:42:56 +0000 | [diff] [blame] | 330 | if (fSemanticHighlightingStrategy != null) { |
| 331 | fSemanticHighlightingStrategy.setDocument(doc); |
| 332 | } |
nitind | bb9106d | 2008-10-11 00:52:30 +0000 | [diff] [blame] | 333 | |
| 334 | fSpellcheckStrategy = null; |
nsandonato | 9592423 | 2009-08-26 20:50:40 +0000 | [diff] [blame] | 335 | if(fFoldingStrategy != null) { |
| 336 | fFoldingStrategy.uninstall(); |
| 337 | } |
| 338 | fFoldingStrategy = null; |
pavery | dc8b306 | 2005-10-24 20:43:42 +0000 | [diff] [blame] | 339 | } |
nitind | c77f963 | 2008-03-19 21:26:39 +0000 | [diff] [blame] | 340 | |
nitind | f3f1087 | 2007-09-03 06:36:56 +0000 | [diff] [blame] | 341 | protected void setEntireDocumentDirty(IDocument document) { |
| 342 | super.setEntireDocumentDirty(document); |
nitind | b044597 | 2006-02-16 22:19:20 +0000 | [diff] [blame] | 343 | |
nitind | f3f1087 | 2007-09-03 06:36:56 +0000 | [diff] [blame] | 344 | // make the entire document dirty |
| 345 | // this also happens on a "save as" |
| 346 | if (document != null && isInstalled() && fLastPartitions != null && document.getLength() == 0) { |
| 347 | /** |
| 348 | * https://bugs.eclipse.org/bugs/show_bug.cgi?id=199053 |
| 349 | * |
| 350 | * Process the strategies for the last known-good partitions. |
| 351 | */ |
| 352 | for (int i = 0; i < fLastPartitions.length; i++) { |
nitind | 69bc47f | 2008-04-07 22:45:51 +0000 | [diff] [blame] | 353 | ValidatorStrategy validatorStrategy = getValidatorStrategy(); |
| 354 | if (validatorStrategy != null) { |
| 355 | validatorStrategy.reconcile(fLastPartitions[i], createDirtyRegion(fLastPartitions[i], DirtyRegion.REMOVE)); |
| 356 | } |
nitind | f3f1087 | 2007-09-03 06:36:56 +0000 | [diff] [blame] | 357 | } |
nitind | bb9106d | 2008-10-11 00:52:30 +0000 | [diff] [blame] | 358 | IReconcilingStrategy spellingStrategy = getSpellcheckStrategy(); |
| 359 | if (spellingStrategy != null) { |
| 360 | spellingStrategy.reconcile(new Region(0, document.getLength())); |
nitind | f3f1087 | 2007-09-03 06:36:56 +0000 | [diff] [blame] | 361 | } |
nsandonato | 9592423 | 2009-08-26 20:50:40 +0000 | [diff] [blame] | 362 | |
| 363 | //if there is a folding strategy then reconcile it |
| 364 | if(getFoldingStrategy() != null) { |
| 365 | getFoldingStrategy().reconcile(new Region(0, document.getLength())); |
| 366 | } |
nitind | f3f1087 | 2007-09-03 06:36:56 +0000 | [diff] [blame] | 367 | } |
| 368 | } |
nitind | c77f963 | 2008-03-19 21:26:39 +0000 | [diff] [blame] | 369 | |
nitind | b044597 | 2006-02-16 22:19:20 +0000 | [diff] [blame] | 370 | /** |
nsandonato | 9592423 | 2009-08-26 20:50:40 +0000 | [diff] [blame] | 371 | * @see org.eclipse.wst.sse.ui.internal.reconcile.DirtyRegionProcessor#install(org.eclipse.jface.text.ITextViewer) |
| 372 | */ |
| 373 | public void install(ITextViewer textViewer) { |
| 374 | super.install(textViewer); |
nsandonato | 8efc758 | 2009-12-02 23:52:57 +0000 | [diff] [blame] | 375 | |
nsandonato | 9592423 | 2009-08-26 20:50:40 +0000 | [diff] [blame] | 376 | //determine if validation is enabled |
| 377 | this.fValidationEnabled = SSEUIPlugin.getInstance().getPreferenceStore().getBoolean( |
| 378 | CommonEditorPreferenceNames.EVALUATE_TEMPORARY_PROBLEMS); |
| 379 | } |
| 380 | |
| 381 | /** |
nitind | b044597 | 2006-02-16 22:19:20 +0000 | [diff] [blame] | 382 | * @see org.eclipse.wst.sse.ui.internal.reconcile.DirtyRegionProcessor#uninstall() |
| 383 | */ |
| 384 | public void uninstall() { |
| 385 | if (isInstalled()) { |
| 386 | |
| 387 | cancel(); |
| 388 | |
nitind | b044597 | 2006-02-16 22:19:20 +0000 | [diff] [blame] | 389 | IReconcilingStrategy validatorStrategy = getValidatorStrategy(); |
| 390 | |
| 391 | if (validatorStrategy != null) { |
| 392 | if (validatorStrategy instanceof IReleasable) |
| 393 | ((IReleasable) validatorStrategy).release(); |
| 394 | } |
nitind | bb9106d | 2008-10-11 00:52:30 +0000 | [diff] [blame] | 395 | |
nsandonato | a8c6909 | 2009-03-12 02:07:17 +0000 | [diff] [blame] | 396 | if (fSpellcheckStrategy != null) { |
| 397 | fSpellcheckStrategy.setDocument(null); |
| 398 | fSpellcheckStrategy = null; |
| 399 | } |
nsandonato | 8efc758 | 2009-12-02 23:52:57 +0000 | [diff] [blame] | 400 | |
| 401 | fReconcileListeners = new ISourceReconcilingListener[0]; |
nitind | b044597 | 2006-02-16 22:19:20 +0000 | [diff] [blame] | 402 | } |
| 403 | super.uninstall(); |
| 404 | } |
pavery | dc8b306 | 2005-10-24 20:43:42 +0000 | [diff] [blame] | 405 | } |