diff options
Diffstat (limited to 'bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/reconcile')
21 files changed, 0 insertions, 3706 deletions
diff --git a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/reconcile/AbstractStructuredTextReconcilingStrategy.java b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/reconcile/AbstractStructuredTextReconcilingStrategy.java deleted file mode 100644 index 7ae04ff5ad..0000000000 --- a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/reconcile/AbstractStructuredTextReconcilingStrategy.java +++ /dev/null @@ -1,527 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 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 - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.sse.ui.internal.reconcile; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import org.eclipse.core.resources.IMarker; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.Platform; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.IRegion; -import org.eclipse.jface.text.reconciler.DirtyRegion; -import org.eclipse.jface.text.reconciler.IReconcileResult; -import org.eclipse.jface.text.reconciler.IReconcileStep; -import org.eclipse.jface.text.reconciler.IReconcilingStrategy; -import org.eclipse.jface.text.reconciler.IReconcilingStrategyExtension; -import org.eclipse.jface.text.source.IAnnotationModel; -import org.eclipse.jface.text.source.IAnnotationModelExtension; -import org.eclipse.jface.text.source.ISourceViewer; -import org.eclipse.wst.sse.ui.internal.IReleasable; -import org.eclipse.wst.sse.ui.internal.ITemporaryAnnotation; -import org.eclipse.wst.sse.ui.internal.Logger; -import org.eclipse.wst.sse.ui.internal.StructuredMarkerAnnotation; - - -/** - * A base ReconcilingStrategy. Subclasses must implement - * createReconcileSteps(). This class should not know about - * IStructuredDocument, only IDocument. - * - * @author pavery - */ -public abstract class AbstractStructuredTextReconcilingStrategy implements IReconcilingStrategy, IReconcilingStrategyExtension, IReleasable { - - /** debug flag */ - protected static final boolean DEBUG; - static { - String value = Platform.getDebugOption("org.eclipse.wst.sse.ui/debug/reconcilerjob"); //$NON-NLS-1$ - DEBUG = value != null && value.equalsIgnoreCase("true"); //$NON-NLS-1$ - } - - // these limits are safetys for "runaway" validation cases - // should be used to safeguard potentially dangerous loops or potentially - // long annotations - // (since the painter seems to affect performance when painting long - // annotations) - public static final int ANNOTATION_LENGTH_LIMIT = 25; - public static final int ELEMENT_ERROR_LIMIT = 25; - - private IDocument fDocument = null; - // private IReconcileStep fFirstStep = null; - private IProgressMonitor fProgressMonitor = null; - private ISourceViewer fSourceViewer = null; -// private Comparator fComparator; - - // list of "validator" annotations - // for gray/un-gray capability - private HashSet fMarkerAnnotations = null; - - /** - * Creates a new strategy. The editor parameter is for access to the - * annotation model. - * - * @param editor - */ - public AbstractStructuredTextReconcilingStrategy(ISourceViewer sourceViewer) { - fSourceViewer = sourceViewer; - init(); - } - - /** - * This is where we add results to the annotationModel, doing any special - * "extra" processing. - */ - protected void addResultToAnnotationModel(IReconcileResult result) { - if (!(result instanceof TemporaryAnnotation)) - return; - // can be null when closing the editor - if (getAnnotationModel() != null) { - TemporaryAnnotation tempAnnotation = (TemporaryAnnotation) result; - - StructuredMarkerAnnotation sma = getCorrespondingMarkerAnnotation(tempAnnotation); - if (sma != null) { - // un-gray out the marker annotation - sma.setGrayed(false); - } - - getAnnotationModel().addAnnotation(tempAnnotation, tempAnnotation.getPosition()); - } - } - - /** - * @param object - * @return if this strategy is responisble for adding this type of key - */ - protected boolean canHandlePartition(String partition) { - // String[] haystack = getPartitionTypes(); - // for (int i = 0; i < haystack.length; i++) { - // if (haystack[i].equals(partition)) - // return true; - // } - // return false; - return false; - } - - // /** - // * @param step - // * @return - // */ - // protected boolean containsStep(IReconcileStep step) { - // if (fFirstStep instanceof StructuredReconcileStep) - // return ((StructuredReconcileStep) fFirstStep).isSiblingStep(step); - // return false; - // } - - /** - * This is where you should create the steps for this strategy - */ - abstract public void createReconcileSteps(); - - /** - * Remove ALL temporary annotations that this strategy can handle. - */ - protected TemporaryAnnotation[] getAllAnnotationsToRemove() { - List removals = new ArrayList(); - IAnnotationModel annotationModel = getAnnotationModel(); - if (annotationModel != null) { - Iterator i = annotationModel.getAnnotationIterator(); - while (i.hasNext()) { - Object obj = i.next(); - if (!(obj instanceof ITemporaryAnnotation)) - continue; - - ITemporaryAnnotation annotation = (ITemporaryAnnotation) obj; - ReconcileAnnotationKey key = (ReconcileAnnotationKey) annotation.getKey(); - // then if this strategy knows how to add/remove this - // partition type - if (canHandlePartition(key.getPartitionType()) /* - * && - * containsStep(key.getStep()) - */) - removals.add(annotation); - } - } - return (TemporaryAnnotation[]) removals.toArray(new TemporaryAnnotation[removals.size()]); - } - - protected IAnnotationModel getAnnotationModel() { - IAnnotationModel model = null; - if (fSourceViewer != null) { - model = fSourceViewer.getAnnotationModel(); - } - return model; - } - - protected TemporaryAnnotation[] getAnnotationsToRemove(DirtyRegion dr, List stepsRun) { - - List remove = new ArrayList(); - IAnnotationModel annotationModel = getAnnotationModel(); - // can be null when closing the editor - if (getAnnotationModel() != null) { - - // clear validator annotations - getMarkerAnnotations().clear(); - - Iterator i = annotationModel.getAnnotationIterator(); - while (i.hasNext()) { - - Object obj = i.next(); - - // check if it's a validator marker annotation - // if it is save it for comparision later (to "gray" icons) - if (obj instanceof StructuredMarkerAnnotation) { - StructuredMarkerAnnotation sma = (StructuredMarkerAnnotation) obj; - - if (sma.getAnnotationType() == TemporaryAnnotation.ANNOT_ERROR || sma.getAnnotationType() == TemporaryAnnotation.ANNOT_WARNING) - fMarkerAnnotations.add(sma); - } - - if (!(obj instanceof TemporaryAnnotation)) - continue; - - TemporaryAnnotation annotation = (TemporaryAnnotation) obj; - ReconcileAnnotationKey key = (ReconcileAnnotationKey) annotation.getKey(); - - // then if this strategy knows how to add/remove this - // partition type - if (canHandlePartition(key.getPartitionType()) && stepsRun.contains(key.getStep())) { - if (key.getScope() == ReconcileAnnotationKey.PARTIAL && annotation.getPosition().overlapsWith(dr.getOffset(), dr.getLength())) { - remove.add(annotation); - } - else if (key.getScope() == ReconcileAnnotationKey.TOTAL) { - remove.add(annotation); - } - } - } - } - return (TemporaryAnnotation[]) remove.toArray(new TemporaryAnnotation[remove.size()]); - } - - - protected abstract boolean containsStep(IReconcileStep step); - - /** - * Gets partition types from all steps in this strategy. - * - * @return parition types from all steps - */ - // public String[] getPartitionTypes() { - // if (fFirstStep instanceof StructuredReconcileStep) - // return ((StructuredReconcileStep) fFirstStep).getPartitionTypes(); - // return new String[0]; - // } - public void init() { - createReconcileSteps(); - } - - /** - * @see org.eclipse.jface.text.reconciler.IReconcilingStrategyExtension#initialReconcile() - */ - public void initialReconcile() { - // do nothing - } - - /** - * @return - */ - protected boolean isCanceled() { - if (DEBUG && (fProgressMonitor != null && fProgressMonitor.isCanceled())) - System.out.println("** STRATEGY CANCELED **:" + this.getClass().getName()); //$NON-NLS-1$ - return fProgressMonitor != null && fProgressMonitor.isCanceled(); - } - - /** - * Process the results from the reconcile steps in this strategy. - * - * @param results - */ - private void process(final IReconcileResult[] results) { - if (DEBUG) - System.out.println("[trace reconciler] > STARTING PROCESS METHOD with (" + results.length + ") results"); //$NON-NLS-1$ //$NON-NLS-2$ - - if (results == null) - return; - - for (int i = 0; i < results.length && i < ELEMENT_ERROR_LIMIT && !isCanceled(); i++) { - - if (isCanceled()) { - if (DEBUG) - System.out.println("[trace reconciler] >** PROCESS (adding) WAS CANCELLED **"); //$NON-NLS-1$ - return; - } - addResultToAnnotationModel(results[i]); - } - - if (DEBUG) { - StringBuffer traceString = new StringBuffer(); - for (int j = 0; j < results.length; j++) - traceString.append("\n (+) :" + results[j] + ":\n"); //$NON-NLS-1$ //$NON-NLS-2$ - System.out.println("[trace reconciler] > PROCESSING (" + results.length + ") results in AbstractStructuredTextReconcilingStrategy " + traceString); //$NON-NLS-1$ //$NON-NLS-2$ - } - } - - /** - * @see org.eclipse.jface.text.reconciler.IReconcilingStrategy#reconcile(org.eclipse.jface.text.reconciler.DirtyRegion, - * org.eclipse.jface.text.IRegion) - */ - public void reconcile(DirtyRegion dirtyRegion, IRegion subRegion) { - // not used - // we only have validator strategy now - - // // external files may be null - // if (isCanceled() || fFirstStep == null) - // return; - // - // TemporaryAnnotation[] annotationsToRemove = new - // TemporaryAnnotation[0]; - // IReconcileResult[] annotationsToAdd = new IReconcileResult[0]; - // StructuredReconcileStep structuredStep = (StructuredReconcileStep) - // fFirstStep; - // - // annotationsToRemove = getAnnotationsToRemove(dirtyRegion); - // annotationsToAdd = structuredStep.reconcile(dirtyRegion, - // subRegion); - // - // smartProcess(annotationsToRemove, annotationsToAdd); - } - - /** - * @param partition - * @see org.eclipse.jface.text.reconciler.IReconcilingStrategy#reconcile(org.eclipse.jface.text.IRegion) - */ - public void reconcile(IRegion partition) { - // not used, we use: - // reconcile(DirtyRegion dirtyRegion, IRegion subRegion) - } - - /** - * Calls release() on all the steps in this strategy. Currently done in - * StructuredRegionProcessor.SourceWidgetDisposeListener#widgetDisposed(...) - */ - public void release() { - // release steps (each step calls release on the next) - // if (fFirstStep != null && fFirstStep instanceof IReleasable) - // ((IReleasable) fFirstStep).release(); - // we don't to null out the steps, in case - // it's reconfigured later - } - - private void removeAnnotations(TemporaryAnnotation[] annotationsToRemove) { - - IAnnotationModel annotationModel = getAnnotationModel(); - // can be null when closing the editor - if (annotationModel != null) { - for (int i = 0; i < annotationsToRemove.length; i++) { - if (isCanceled()) { - if (DEBUG) - System.out.println("[trace reconciler] >** REMOVAL WAS CANCELLED **"); //$NON-NLS-1$ - return; - } - StructuredMarkerAnnotation sma = getCorrespondingMarkerAnnotation(annotationsToRemove[i]); - if (sma != null) { - // gray out the marker annotation - sma.setGrayed(true); - } - // remove the temp one - annotationModel.removeAnnotation(annotationsToRemove[i]); - - } - } - - if (DEBUG) { - StringBuffer traceString = new StringBuffer(); - for (int i = 0; i < annotationsToRemove.length; i++) - traceString.append("\n (-) :" + annotationsToRemove[i] + ":\n"); //$NON-NLS-1$ //$NON-NLS-2$ - System.out.println("[trace reconciler] > REMOVED (" + annotationsToRemove.length + ") annotations in AbstractStructuredTextReconcilingStrategy :" + traceString); //$NON-NLS-1$ //$NON-NLS-2$ - } - } - - private StructuredMarkerAnnotation getCorrespondingMarkerAnnotation(TemporaryAnnotation tempAnnotation) { - - Iterator it = getMarkerAnnotations().iterator(); - while (it.hasNext()) { - StructuredMarkerAnnotation markerAnnotation = (StructuredMarkerAnnotation) it.next(); - String message = ""; //$NON-NLS-1$ - try { - message = (String) markerAnnotation.getMarker().getAttribute(IMarker.MESSAGE); - } - catch (CoreException e) { - if (DEBUG) - Logger.logException(e); - } - // it would be nice to check line number here... - if (message != null && message.equals(tempAnnotation.getText())) - return markerAnnotation; - } - return null; - } - - private void removeAllAnnotations() { - removeAnnotations(getAllAnnotationsToRemove()); - } - - /** - * Set the document for this strategy. - * - * @param document - * @see org.eclipse.jface.text.reconciler.IReconcilingStrategy#setDocument(org.eclipse.jface.text.IDocument) - */ - public void setDocument(IDocument document) { - - // remove all old annotations since it's a new document - removeAllAnnotations(); - - if (document == null) - release(); - - // if (getFirstStep() != null) - // getFirstStep().setInputModel(new DocumentAdapter(document)); - - fDocument = document; - } - - public IDocument getDocument() { - return fDocument; - } - - /** - * @param monitor - * @see org.eclipse.jface.text.reconciler.IReconcilingStrategyExtension#setProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) - */ - public void setProgressMonitor(IProgressMonitor monitor) { - // fProgressMonitor = monitor; - // if (fFirstStep != null) - // fFirstStep.setProgressMonitor(fProgressMonitor); - } - - /** - * Check if the annotation is already there, if it is, no need to remove - * or add again. This will avoid a lot of "flickering" behavior. - * - * @param annotationsToRemove - * @param annotationsToAdd - */ - protected void smartProcess(TemporaryAnnotation[] annotationsToRemove, IReconcileResult[] annotationsToAdd) { -// Comparator comp = getTemporaryAnnotationComparator(); -// List sortedRemovals = Arrays.asList(annotationsToRemove); -// Collections.sort(sortedRemovals, comp); -// -// List sortedAdditions = Arrays.asList(annotationsToAdd); -// Collections.sort(sortedAdditions, comp); -// -// List filteredRemovals = new ArrayList(sortedRemovals); -// List filteredAdditions = new ArrayList(sortedAdditions); -// -// boolean ignore = false; -// int lastFoundAdded = 0; -// for (int i = 0; i < sortedRemovals.size(); i++) { -// TemporaryAnnotation removal = (TemporaryAnnotation) sortedRemovals.get(i); -// for (int j = lastFoundAdded; j < sortedAdditions.size(); j++) { -// TemporaryAnnotation addition = (TemporaryAnnotation) sortedAdditions.get(j); -// // quick position check here -// if (removal.getPosition().equals(addition.getPosition())) { -// lastFoundAdded = j; -// // remove performs TemporaryAnnotation.equals() -// // which checks text as well -// filteredAdditions.remove(addition); -// ignore = true; -// if (DEBUG) -// System.out.println(" ~ smart process ignoring: " + removal.getPosition().getOffset()); //$NON-NLS-1$ -// break; -// } -// } -// if (ignore) { -// filteredRemovals.remove(removal); -// } -// ignore = false; -// } - if (getAnnotationModel() instanceof IAnnotationModelExtension) { -// TemporaryAnnotation[] filteredRemovalArray = (TemporaryAnnotation[]) filteredRemovals.toArray(new TemporaryAnnotation[filteredRemovals.size()]); -// // apply "grey"-ness -// for (int i = 0; i < filteredRemovalArray.length; i++) { -// if (isCanceled()) { -// if (DEBUG) -// System.out.println("[trace reconciler] >** replacing WAS CANCELLED **"); //$NON-NLS-1$ -// return; -// } -// StructuredMarkerAnnotation sma = getCorrespondingMarkerAnnotation(filteredRemovalArray[i]); -// if (sma != null) { -// // gray out the marker annotation -// sma.setGrayed(true); -// } -// } -// Map annotationsToAddMap = new HashMap(); -// for (int i = 0; i < filteredAdditions.size(); i++) { -// TemporaryAnnotation temporaryAnnotation = (TemporaryAnnotation) filteredAdditions.get(i); -// annotationsToAddMap.put(temporaryAnnotation, temporaryAnnotation.getPosition()); -// } -// if (isCanceled()) { -// if (DEBUG) -// System.out.println("[trace reconciler] >** PROCESS (replacing) WAS CANCELLED **"); //$NON-NLS-1$ -// return; -// } -// /* -// * Using the extension means we can't enforce the -// * ELEMENT_ERROR_LIMIT limit. -// */ -// ((IAnnotationModelExtension) getAnnotationModel()).replaceAnnotations(filteredRemovalArray, annotationsToAddMap); - - Map annotationsToAddMap = new HashMap(); - for (int i = 0; i < annotationsToAdd.length; i++) { - TemporaryAnnotation temporaryAnnotation = (TemporaryAnnotation) annotationsToAdd[i]; - annotationsToAddMap.put(temporaryAnnotation, temporaryAnnotation.getPosition()); - } - if (isCanceled()) { - if (DEBUG) - System.out.println("[trace reconciler] >** PROCESS (replacing) WAS CANCELLED **"); //$NON-NLS-1$ - return; - } - ((IAnnotationModelExtension) getAnnotationModel()).replaceAnnotations(annotationsToRemove, annotationsToAddMap); - } - else { -// removeAnnotations((TemporaryAnnotation[]) filteredRemovals.toArray(new TemporaryAnnotation[filteredRemovals.size()])); -// process((IReconcileResult[]) filteredAdditions.toArray(new IReconcileResult[filteredAdditions.size()])); - removeAnnotations(annotationsToRemove); - process(annotationsToAdd); - } - } - -// private Comparator getTemporaryAnnotationComparator() { -// if (fComparator == null) { -// fComparator = new Comparator() { -// public int compare(Object arg0, Object arg1) { -// TemporaryAnnotation ta1 = (TemporaryAnnotation) arg0; -// TemporaryAnnotation ta2 = (TemporaryAnnotation) arg1; -// int result = ta1.getPosition().getOffset() - ta2.getPosition().getOffset(); -// if(result != 0) -// return result; -// return Collator.getInstance().compare(ta1.getText(), ta2.getText()); -// } -// }; -// } -// return fComparator; -// } - - public HashSet getMarkerAnnotations() { - if (fMarkerAnnotations == null) - fMarkerAnnotations = new HashSet(); - return fMarkerAnnotations; - } -} diff --git a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/reconcile/DirtyRegionProcessor.java b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/reconcile/DirtyRegionProcessor.java deleted file mode 100644 index 4bdfe29874..0000000000 --- a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/reconcile/DirtyRegionProcessor.java +++ /dev/null @@ -1,644 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 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 - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.sse.ui.internal.reconcile; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.OperationCanceledException; -import org.eclipse.core.runtime.Platform; -import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.jobs.Job; -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.DocumentEvent; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.IDocumentExtension3; -import org.eclipse.jface.text.IDocumentListener; -import org.eclipse.jface.text.ITextInputListener; -import org.eclipse.jface.text.ITextViewer; -import org.eclipse.jface.text.ITypedRegion; -import org.eclipse.jface.text.TextUtilities; -import org.eclipse.jface.text.reconciler.DirtyRegion; -import org.eclipse.jface.text.reconciler.IReconciler; -import org.eclipse.jface.text.reconciler.IReconcilerExtension; -import org.eclipse.jface.text.reconciler.IReconcilingStrategy; -import org.eclipse.wst.sse.ui.internal.Logger; -import org.eclipse.wst.sse.ui.internal.SSEUIMessages; - -/** - * This Job holds a queue of updates from the editor (DirtyRegions) to - * process. When a new request comes in, the current run is canceled, the new - * request is added to the queue, then the job is re-scheduled. - * - * @author pavery - */ -public class DirtyRegionProcessor extends Job implements IReconciler, IReconcilerExtension, IConfigurableReconciler { - class DocumentListener implements IDocumentListener { - public void documentAboutToBeChanged(DocumentEvent event) { - // save partition type (to see if it changes in documentChanged()) - fLastPartitions = getPartitions(event.getOffset(), event.getLength()); - } - - public void documentChanged(DocumentEvent event) { - if (partitionsChanged(event)) { - // pa_TODO - // this is a simple way to ensure old - // annotations are removed when partition changes - - // it might be a performance hit though - setEntireDocumentDirty(getDocument()); - } - else { - /* - * Note that creating DirtyRegions *now* means that the wrong - * text may be included - */ - DirtyRegion dr = null; - if (event.getLength() == 0) { - /* - * It's an insert-- we use text length though so that the - * new region gets validated... - */ - dr = createDirtyRegion(event.getOffset(), 0, DirtyRegion.INSERT); - } - else { - if ("".equals(event.getText())) { //$NON-NLS-1$ - // it's a delete - dr = createDirtyRegion(event.getOffset(), event.getLength(), DirtyRegion.REMOVE); - } - else { - // it's a replace - dr = createDirtyRegion(event.getOffset(), event.getLength(), DirtyRegion.INSERT); - } - } - processDirtyRegion(dr); - } - } - - /** - * Checks previous partitions from the span of the event w/ the new - * partitions from the span of the event. If partitions changed, - * return true, else return false - * - * @param event - * @return - */ - private boolean partitionsChanged(DocumentEvent event) { - boolean changed = false; - int length = event.getLength(); - - if (event.getLength() == 0 && event.getText().length() > 0) { - // it's an insert, we want partitions of the new text - length = event.getText().length(); - } - - String[] newPartitions = getPartitions(event.getOffset(), length); - if (fLastPartitions != null) { - if (fLastPartitions.length != newPartitions.length) { - changed = true; - } - else { - for (int i = 0; i < fLastPartitions.length; i++) { - if (!fLastPartitions[i].equals(newPartitions[i])) { - changed = true; - break; - } - } - } - } - return changed; - } - - - } - - /** - * Reconciles the entire document when the document in the viewer is - * changed. This happens when the document is initially opened, as well as - * after a save-as. - * - * Also see processPostModelEvent(...) for similar behavior when document - * for the model is changed. - */ - class TextInputListener implements ITextInputListener { - public void inputDocumentAboutToBeChanged(IDocument oldInput, IDocument newInput) { - // do nothing - } - - public void inputDocumentChanged(IDocument oldInput, IDocument newInput) { - handleInputDocumentChanged(oldInput, newInput); - } - } - - /** debug flag */ - protected static final boolean DEBUG; - private static final long UPDATE_DELAY = 750; - - static { - String value = Platform.getDebugOption("org.eclipse.wst.sse.ui/debug/reconcilerjob"); //$NON-NLS-1$ - DEBUG = value != null && value.equalsIgnoreCase("true"); //$NON-NLS-1$ - } - - private long fDelay; - - - /** local queue of dirty regions (created here) to be reconciled */ - private List fDirtyRegionQueue = Collections.synchronizedList(new ArrayList()); - - /** document that this reconciler works on */ - private IDocument fDocument = null; - - private IDocumentListener fDocumentListener = new DocumentListener(); - /** - * set true after first install to prevent duplicate work done in the - * install method (since install gets called multiple times) - */ - private boolean fIsInstalled = false; - - /** - * so we can tell if a partition changed after the last edit - */ - String[] fLastPartitions; - - List fNonIncrementalStrategiesAlreadyProcessed = new ArrayList(1); - - /** - * The partitioning this reconciler uses. - */ - private String fPartitioning; - - Map fReconcilingStrategies = null; - - /** for initial reconcile when document is opened */ - private TextInputListener fTextInputListener = null; - /** the text viewer */ - private ITextViewer fViewer; - - /** - * Creates a new StructuredRegionProcessor - */ - public DirtyRegionProcessor() { - // init job stuff - super(SSEUIMessages.proc_dirty_regions_0); //$NON-NLS-1$ - setPriority(Job.LONG); - setSystem(true); - - // init reconciler stuff - setDelay(UPDATE_DELAY); - fReconcilingStrategies = new HashMap(); - } - - /** - * Adds the given resource to the set of resources that need refreshing. - * Synchronized in order to protect the collection during add. - * - * @param resource - */ - private synchronized void addRequest(DirtyRegion newDirtyRegion) { - // NOTE: This method is called a lot so make sure it's fast - List dirtyRegionQueue = getDirtyRegionQueue(); - for (Iterator it = dirtyRegionQueue.iterator(); it.hasNext();) { - // go through list of existing dirty regions and check if any - // dirty regions need to be discarded - DirtyRegion currentExisting = (DirtyRegion) it.next(); - DirtyRegion outer = getOuterRegion(currentExisting, newDirtyRegion); - // if we already have a request which contains the new request, - // discard the new request - if (outer == currentExisting) - return; - // if new request contains any existing requests, - // remove those - if (outer == newDirtyRegion) - it.remove(); - } - dirtyRegionQueue.add(newDirtyRegion); - } - - /** - * Notifies subclasses that processing of multiple dirty regions has begun - */ - protected void beginProcessing() { - // do nothing by default - } - - /** - * @param dirtyRegion - * @return - */ - protected ITypedRegion[] computePartitioning(DirtyRegion dirtyRegion) { - int drOffset = dirtyRegion.getOffset(); - int drLength = dirtyRegion.getLength(); - - return computePartitioning(drOffset, drLength); - } - - protected ITypedRegion[] computePartitioning(int drOffset, int drLength) { - IDocument doc = getDocument(); - int docLength = doc.getLength(); - - ITypedRegion[] tr = new ITypedRegion[0]; - - if (drOffset > docLength) { - drOffset = docLength; - drLength = 0; - } - else if (drOffset + drLength > docLength) { - drLength = docLength - drOffset; - } - - try { - // dirty region may span multiple partitions - tr = TextUtilities.computePartitioning(doc, getDocumentPartitioning(), drOffset, drLength, true); - } - catch (BadLocationException e) { - String info = "dr: [" + drOffset + ":" + drLength + "] doc: [" + docLength + "] "; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ - Logger.logException(info, e); - tr = new ITypedRegion[0]; - } - return tr; - } - - /** - * Used to determine if one dirty region contains the other and if so, - * which is the one that contains it. - * - * @param root - * @param possible - * @return the outer dirty region if it contains the other dirty region, - * null otherwise - */ - protected DirtyRegion getOuterRegion(DirtyRegion root, DirtyRegion possible) { - DirtyRegion outer = null; - if (isContained(root, possible)) - outer = root; - else if (isContained(possible, root)) - outer = possible; - return outer; - } - - /** - * Used to determine of a "possible" dirty region can be discarded in - * favor of using just the "root" dirty region. - * - * @return if the root dirty region contains possible, return true, - * otherwise return false - */ - private boolean isContained(DirtyRegion root, DirtyRegion possible) { - int rootStart = root.getOffset(); - int rootEnd = rootStart + root.getLength(); - int possStart = possible.getOffset(); - int possEnd = possStart + possible.getLength(); - if (rootStart <= possStart && rootEnd >= possEnd) - return true; - return false; - } - - protected DirtyRegion createDirtyRegion(int offset, int length, String type) { - DirtyRegion durty = null; - IDocument doc = getDocument(); - - if (doc != null) { - // safety for BLE - int docLen = doc.getLength(); - if (offset > docLen) { - offset = docLen; - length = 0; - } - else if (offset + length >= docLen) - length = docLen - offset; - try { - durty = new DirtyRegion(offset, length, type, doc.get(offset, length)); - } - catch (BadLocationException e) { - String info = "dr: [" + offset + ":" + length + "] doc: [" + docLen + "] "; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ - Logger.logException(info, e); - } - } - return durty; - } - - protected DirtyRegion createDirtyRegion(ITypedRegion tr, String type) { - return createDirtyRegion(tr.getOffset(), tr.getLength(), type); - } - - protected void flushDirtyRegionQueue() { - fDirtyRegionQueue.clear(); - } - - /** - * Notifies subclasses that processing of multiple dirty regions has - * ended, for now - */ - protected void endProcessing() { - // do nothing by default - } - - /** - * Delay between processing of DirtyRegions. - * - * @return - */ - long getDelay() { - return fDelay; - } - - List getDirtyRegionQueue() { - return fDirtyRegionQueue; - } - - /** - * The IDocument on which this reconciler operates - * - * @return - */ - protected IDocument getDocument() { - return fDocument; - } - - public String getDocumentPartitioning() { - if (fPartitioning == null) - return IDocumentExtension3.DEFAULT_PARTITIONING; - return fPartitioning; - } - - protected String[] getPartitions(int drOffset, int drLength) { - - ITypedRegion[] regions = new ITypedRegion[0]; - int docLength = getDocument().getLength(); - - if (drOffset > docLength) { - drOffset = docLength; - drLength = 0; - } - else if (drOffset + drLength > docLength) { - drLength = docLength - drOffset; - } - - try { - regions = TextUtilities.computePartitioning(getDocument(), getDocumentPartitioning(), drOffset, drLength, true); - } - catch (BadLocationException e) { - Logger.logException(e); - regions = new ITypedRegion[0]; - } - String[] partitions = new String[regions.length]; - for (int i = 0; i < regions.length; i++) - partitions[i] = regions[i].getType(); - return partitions; - } - - /** - * Returns the reconciling strategy registered with the reconciler for the - * specified partition type. - * - * @param partitionType - * the partition type for which to determine the reconciling - * strategy - * - * @return the reconciling strategy registered for the given partition - * type, or <code>null</code> if there is no such strategy - * - * @see org.eclipse.jface.text.reconciler.IReconciler#getReconcilingStrategy(java.lang.String) - */ - public IReconcilingStrategy getReconcilingStrategy(String partitionType) { - if (partitionType == null) - return null; - return (IReconcilingStrategy) fReconcilingStrategies.get(partitionType); - } - - /** - * This method also synchronized because it accesses the fRequests queue - * - * @return an array of the currently requested Nodes to refresh - */ - private synchronized DirtyRegion[] getRequests() { - DirtyRegion[] toRefresh = (DirtyRegion[]) fDirtyRegionQueue.toArray(new DirtyRegion[fDirtyRegionQueue.size()]); - fDirtyRegionQueue.clear(); - return toRefresh; - } - - /** - * Returns the text viewer this reconciler is installed on. - * - * @return the text viewer this reconciler is installed on - */ - protected ITextViewer getTextViewer() { - return fViewer; - } - - /** - * - * @param oldInput - * @param newInput - */ - void handleInputDocumentChanged(IDocument oldInput, IDocument newInput) { - // don't bother if reconciler not installed - if (isInstalled()) { - - reconcilerDocumentChanged(newInput); - setDocument(newInput); - setEntireDocumentDirty(newInput); - } - } - - /** - * @see org.eclipse.jface.text.reconciler.IReconciler#install(ITextViewer) - */ - public void install(ITextViewer textViewer) { - // we might be called multiple times with the same viewe.r, - // maybe after being uninstalled as well, so track separately - if (!isInstalled()) { - fViewer = textViewer; - fTextInputListener = new TextInputListener(); - textViewer.addTextInputListener(fTextInputListener); - setInstalled(true); - } - } - - /** - * The viewer has been set on this Reconciler. - * - * @return true if the viewer has been set on this Reconciler, false - * otherwise. - */ - public boolean isInstalled() { - return fIsInstalled; - } - - /** - * Subclasses should implement for specific handling of dirty regions. The - * method is invoked for each dirty region in the Job's queue. - * - * @param dirtyRegion - */ - protected void process(DirtyRegion dirtyRegion) { - /* - * Break the dirty region into a sequence of partitions and find the - * corresponding strategy to reconcile those partitions. If a strategy - * implements INonIncrementalReconcilingStrategy, only call it once - * regardless of the number and types of partitions. - */ - ITypedRegion[] partitions = computePartitioning(dirtyRegion); - for (int i = 0; i < partitions.length; i++) { - IReconcilingStrategy strategy = getReconcilingStrategy(partitions[i].getType()); - if (strategy != null) { - strategy.reconcile(partitions[i]); - } - } - } - - /** - * Invoke dirty region processing. - * - * @param node - */ - public final void processDirtyRegion(DirtyRegion dr) { - if (dr == null) - return; - - cancel(); - addRequest(dr); - schedule(getDelay()); - - if (DEBUG) { - System.out.println("added request for: [" + dr.getText() + "]"); //$NON-NLS-1$ //$NON-NLS-2$ - System.out.println("queue size is now: " + getDirtyRegionQueue().size()); //$NON-NLS-1$ - } - } - - /** - * Reinitializes listeners and sets new document onall strategies. - * - * @see org.eclipse.jface.text.reconciler.AbstractReconciler#reconcilerDocumentChanged(IDocument) - */ - void reconcilerDocumentChanged(IDocument newDocument) { - IDocument currentDoc = getDocument(); - - // unhook old document listener - if (currentDoc != null) - currentDoc.removeDocumentListener(fDocumentListener); - // hook up new document listener - if (newDocument != null) - newDocument.addDocumentListener(fDocumentListener); - - // sets document on all strategies - setDocument(newDocument); - } - - protected IStatus run(IProgressMonitor monitor) { - IStatus status = Status.OK_STATUS; - try { - beginProcessing(); - - DirtyRegion[] toRefresh = getRequests(); - for (int i = 0; i < toRefresh.length; i++) { - if (monitor.isCanceled()) - throw new OperationCanceledException(); - process(toRefresh[i]); - } - } - catch (Exception e) { - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=103676 - // stop errors from popping up a dialog - // from the job manager - - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=106052 - // don't log OperationCanceledException - if (!(e instanceof OperationCanceledException)) - Logger.logException("problem with reconciling", e); //$NON-NLS-1$ - } - finally { - endProcessing(); - - monitor.done(); - } - return status; - } - - public void setDelay(long delay) { - fDelay = delay; - } - - public void setDocument(IDocument doc) { - fDocument = doc; - } - - /** - * Sets the document partitioning for this reconciler. - * - * @param partitioning - * the document partitioning for this reconciler - */ - public void setDocumentPartitioning(String partitioning) { - fPartitioning = partitioning; - } - - /** - * Basically means process the entire document. - * - * @param document - */ - protected void setEntireDocumentDirty(IDocument document) { - - // make the entire document dirty - // this also happens on a "save as" - if (document != null && isInstalled()) { - - // since we're marking the entire doc dirty - getDirtyRegionQueue().clear(); - DirtyRegion entireDocument = createDirtyRegion(0, document.getLength(), DirtyRegion.INSERT); - processDirtyRegion(entireDocument); - } - } - - /** - * @param isInstalled - * The isInstalled to set. - */ - void setInstalled(boolean isInstalled) { - fIsInstalled = isInstalled; - } - - public void setReconcilingStrategy(String partitionType, IReconcilingStrategy strategy) { - if (partitionType == null) { - throw new IllegalArgumentException(); - } - - if (strategy == null) { - fReconcilingStrategies.remove(partitionType); - } - else { - fReconcilingStrategies.put(partitionType, strategy); - } - } - - /** - * @see org.eclipse.jface.text.reconciler.IReconciler#uninstall() - */ - public void uninstall() { - if (isInstalled()) { - // removes widget listener - getTextViewer().removeTextInputListener(fTextInputListener); - setInstalled(false); - // removes document listeners - reconcilerDocumentChanged(null); - } - setDocument(null); - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/reconcile/DocumentAdapter.java b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/reconcile/DocumentAdapter.java deleted file mode 100644 index 4a09d274a6..0000000000 --- a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/reconcile/DocumentAdapter.java +++ /dev/null @@ -1,43 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 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 - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.sse.ui.internal.reconcile; - -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.reconciler.IReconcilableModel; - -/** - * Adapts an <code>IDocument</code> to a <code>IReconcilableModel</code>. - * - */ -public class DocumentAdapter implements IReconcilableModel { - - private IDocument fDocument; - - /** - * Creates a text model adapter for the given document. - * - * @param document - */ - public DocumentAdapter(IDocument document) { - fDocument = document; - } - - /** - * Returns this model's document. - * - * @return the model's input document - */ - public IDocument getDocument() { - return fDocument; - } -} diff --git a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/reconcile/DocumentRegionProcessor.java b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/reconcile/DocumentRegionProcessor.java deleted file mode 100644 index 39c56f8cf7..0000000000 --- a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/reconcile/DocumentRegionProcessor.java +++ /dev/null @@ -1,187 +0,0 @@ -package org.eclipse.wst.sse.ui.internal.reconcile; - -import java.io.ByteArrayInputStream; -import java.io.IOException; - -import org.eclipse.core.runtime.Platform; -import org.eclipse.core.runtime.content.IContentDescription; -import org.eclipse.core.runtime.content.IContentType; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.ITypedRegion; -import org.eclipse.jface.text.reconciler.DirtyRegion; -import org.eclipse.jface.text.reconciler.IReconcilingStrategy; -import org.eclipse.jface.text.source.ISourceViewer; -import org.eclipse.wst.sse.ui.internal.IReleasable; -import org.eclipse.wst.sse.ui.internal.reconcile.validator.ValidatorBuilder; -import org.eclipse.wst.sse.ui.internal.reconcile.validator.ValidatorMetaData; -import org.eclipse.wst.sse.ui.internal.reconcile.validator.ValidatorStrategy; -import org.eclipse.wst.sse.ui.internal.spelling.SpellcheckStrategy; - -/** - * Adds to DirtyRegionProcessor Job: - IDocumentListener - ValidatorStrategy - - * Text viewer(dispose, input changed) listeners. - default, spelling, and - * validator strategies - DirtyRegion processing logic. - */ -public class DocumentRegionProcessor extends DirtyRegionProcessor { - - /** - * A strategy to use the defined default Spelling service. - */ - private SpellcheckStrategy fSpellcheckStrategy; - - /** - * The strategy that runs validators contributed via - * <code>org.eclipse.wst.sse.ui.extensions.sourcevalidation</code> - * extension point - */ - private ValidatorStrategy fValidatorStrategy; - - private final String SSE_UI_ID = "org.eclipse.wst.sse.ui"; //$NON-NLS-1$ - - protected void beginProcessing() { - super.beginProcessing(); - ValidatorStrategy validatorStrategy = getValidatorStrategy(); - if (validatorStrategy != null) { - validatorStrategy.beginProcessing(); - } - } - - protected void endProcessing() { - super.endProcessing(); - ValidatorStrategy validatorStrategy = getValidatorStrategy(); - if (validatorStrategy != null) { - validatorStrategy.endProcessing(); - } - } - - protected String getContentType(IDocument doc) { - if (doc == null) - return null; - - String contentTypeId = null; - - // pa_TODO it would be nice to be able to get filename from - // IDocument... - // because it seems that getting content type from input stream - // isn't all that accurate (eg. w/ a javascript file) - - // IContentType ct = - // Platform.getContentTypeManager().findContentTypeFor("test.js"); - IContentType ct = null; - try { - IContentDescription desc = Platform.getContentTypeManager().getDescriptionFor(new ByteArrayInputStream(doc.get().getBytes()), null, IContentDescription.ALL); - if (desc != null) { - ct = desc.getContentType(); - if (ct != null) - contentTypeId = ct.getId(); - } - } - catch (IOException e) { - // just bail - } - return contentTypeId; - } - - protected final StructuredTextReconcilingStrategy getSpellcheckStrategy() { - if (fSpellcheckStrategy == null) { - String contentTypeId = getContentType(getDocument()); - if (contentTypeId != null) { - if (getTextViewer() instanceof ISourceViewer) { - ISourceViewer viewer = (ISourceViewer) getTextViewer(); - fSpellcheckStrategy = new SpellcheckStrategy(viewer, contentTypeId); - fSpellcheckStrategy.setDocument(getDocument()); - fSpellcheckStrategy.setDocumentPartitioning(getDocumentPartitioning()); - } - } - } - return fSpellcheckStrategy; - } - - /** - * @return Returns the ValidatorStrategy. - */ - protected ValidatorStrategy getValidatorStrategy() { - if (fValidatorStrategy == null) { - ValidatorStrategy validatorStrategy = null; - - if (getTextViewer() instanceof ISourceViewer) { - ISourceViewer viewer = (ISourceViewer) getTextViewer(); - String contentTypeId = null; - - IDocument doc = viewer.getDocument(); - contentTypeId = getContentType(doc); - - if (contentTypeId != null) { - validatorStrategy = new ValidatorStrategy(viewer, contentTypeId); - ValidatorBuilder vBuilder = new ValidatorBuilder(); - ValidatorMetaData[] vmds = vBuilder.getValidatorMetaData(SSE_UI_ID); - for (int i = 0; i < vmds.length; i++) { - if (vmds[i].canHandleContentType(contentTypeId)) - validatorStrategy.addValidatorMetaData(vmds[i]); - } - } - } - fValidatorStrategy = validatorStrategy; - } - return fValidatorStrategy; - } - - /** - * @param dirtyRegion - */ - protected void process(DirtyRegion dirtyRegion) { - if (!isInstalled()) - return; - - super.process(dirtyRegion); - - // Also call the validation and spell-check strategies - ITypedRegion[] partitions = computePartitioning(dirtyRegion); - - DirtyRegion dirty = null; - for (int i = 0; i < partitions.length; i++) { - // [source]validator (extension) for this partition - if (getValidatorStrategy() != null) { - dirty = createDirtyRegion(partitions[i], DirtyRegion.INSERT); - getValidatorStrategy().reconcile(partitions[i], dirty); - } - } - - // single spell-check for everything - if (getSpellcheckStrategy() != null) { - getSpellcheckStrategy().reconcile(dirtyRegion, dirtyRegion); - } - } - - public void setDocument(IDocument doc) { - super.setDocument(doc); - IReconcilingStrategy validatorStrategy = getValidatorStrategy(); - if (validatorStrategy != null) { - validatorStrategy.setDocument(doc); - } - if (fSpellcheckStrategy != null) { - fSpellcheckStrategy.setDocument(doc); - } - } - - /** - * @see org.eclipse.wst.sse.ui.internal.reconcile.DirtyRegionProcessor#uninstall() - */ - public void uninstall() { - if (isInstalled()) { - - cancel(); - - IReconcilingStrategy validatorStrategy = getValidatorStrategy(); - - if (validatorStrategy != null) { - if (validatorStrategy instanceof IReleasable) - ((IReleasable) validatorStrategy).release(); - } - if (fSpellcheckStrategy != null) { - fSpellcheckStrategy.setDocument(null); - } - } - super.uninstall(); - } -} diff --git a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/reconcile/IConfigurableReconciler.java b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/reconcile/IConfigurableReconciler.java deleted file mode 100644 index 6f8b28f06d..0000000000 --- a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/reconcile/IConfigurableReconciler.java +++ /dev/null @@ -1,35 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 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 - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * - *******************************************************************************/ -package org.eclipse.wst.sse.ui.internal.reconcile; - -import org.eclipse.jface.text.reconciler.IReconcilingStrategy; - -/** - * A reconciler that allows IReconcilingStrategies to be assigned to partition - * types. The reconciler will call the registered IReconcilingStrategy when - * dirty regions which contain partitions of a specific type need to be - * reconciled. - * - * @since 1.1 - */ -public interface IConfigurableReconciler { - /** - * Sets the reconciling strategy for the reconciler to use for the - * specified content type. - * - * @param partitionType - * the partition type - * @param strategy - * the reconciling strategy - */ - void setReconcilingStrategy(String partitionType, IReconcilingStrategy strategy); -} diff --git a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/reconcile/IReconcileAnnotationKey.java b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/reconcile/IReconcileAnnotationKey.java deleted file mode 100644 index 052df0a46b..0000000000 --- a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/reconcile/IReconcileAnnotationKey.java +++ /dev/null @@ -1,35 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 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 - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.sse.ui.internal.reconcile; - -import org.eclipse.jface.text.reconciler.IReconcileStep; - -/** - * Defines an annotation key that the - * <code>AbstractStructuredTextReconcilingStrategy</code> knows how to - * remove appropriately. - * - * @deprecated not API, this will probably just become an abstract class - * - * @author pavery - */ -public interface IReconcileAnnotationKey { - static final int PARTIAL = 1; - static final int TOTAL = 0; - - String getPartitionType(); - - //int getScope(); - - IReconcileStep getStep(); -} diff --git a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/reconcile/IStructuredReconcileStep.java b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/reconcile/IStructuredReconcileStep.java deleted file mode 100644 index 3abb5f99e0..0000000000 --- a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/reconcile/IStructuredReconcileStep.java +++ /dev/null @@ -1,66 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 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 - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.sse.ui.internal.reconcile; - -import org.eclipse.jface.text.IRegion; -import org.eclipse.jface.text.reconciler.DirtyRegion; -import org.eclipse.jface.text.reconciler.IReconcileResult; -import org.eclipse.jface.text.reconciler.IReconcileStep; - -/** - * @author pavery - * @deprecated still working out API (or if anything here should be API) - * - * Interface for a step in StructuredRegionProcessor framework. - */ -public interface IStructuredReconcileStep extends IReconcileStep { - /** - * Partitions for which this step can add/remove annotions - * - * @return an array of the partitions for which this step can add/remove - * annotions - */ - String[] getPartitionTypes(); - - /** - * Returns the scope for which this step adds annotations. - * - * @return the scope for which this step adds annotations - */ - //int getScope(); - - /** - * Tells you if the step is equal to this step or any of the sibling - * steps. - * - * @return - */ - boolean isSiblingStep(IReconcileStep step); - - /** - * Adds awareness that the Reconciler is reconciling the entire document - * this call. - * - * @param dirtyRegion - * @param subRegion - * @param refreshAll - * @return - */ - IReconcileResult[] reconcile(DirtyRegion dirtyRegion, IRegion subRegion, boolean refreshAll); - - /** - * Used to reset the state of the Strategy. For example: any flags that - * need to be reset after a long running operation like processAll(). - */ - void reset(); -} diff --git a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/reconcile/IStructuredReconcilingStrategy.java b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/reconcile/IStructuredReconcilingStrategy.java deleted file mode 100644 index 8b441519e8..0000000000 --- a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/reconcile/IStructuredReconcilingStrategy.java +++ /dev/null @@ -1,43 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 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 - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.sse.ui.internal.reconcile; - -import org.eclipse.jface.text.IRegion; -import org.eclipse.jface.text.reconciler.DirtyRegion; -import org.eclipse.jface.text.reconciler.IReconcilingStrategy; - - -/** - * Interface for structured reconciling strategies. - * - * @deprecated doesn't need to be API and might go away - * - * @author pavery - */ -public interface IStructuredReconcilingStrategy extends IReconcilingStrategy { - /** - * Adds awareness that the reconciler is processing the entire document - * via refreshAll flag. - * - * @param dirtyRegion - * @param subRegion - * @param refreshAll - */ - public void reconcile(DirtyRegion dirtyRegion, IRegion subRegion, boolean refreshAll); - - /** - * Used to reset the state of the Strategy. For example: any flags that - * need to be reset after a long running operation like processAll(). - */ - public void reset(); -} diff --git a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/reconcile/ReconcileAnnotationKey.java b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/reconcile/ReconcileAnnotationKey.java deleted file mode 100644 index fa89e2d4ba..0000000000 --- a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/reconcile/ReconcileAnnotationKey.java +++ /dev/null @@ -1,56 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 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 - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.sse.ui.internal.reconcile; - -import org.eclipse.jface.text.reconciler.IReconcileStep; - - -/** - * Implementation of <code>IReconcileAnnotationKey</code> note: clients - * should use the method StructuredReconcileStep#createKey(String - * partitionType, int scope) - * - * @author pavery - */ -public class ReconcileAnnotationKey { - - public static final int PARTIAL = 1; - public static final int TOTAL = 0; - - private String fPartitionType = null; - - private IReconcileStep fReconcileStep = null; - private int fScope; - - public ReconcileAnnotationKey(IReconcileStep step, String partitionType, int scope) { - fReconcileStep = step; - fPartitionType = partitionType; - fScope = scope; - } - - public String getPartitionType() { - return fPartitionType; - } - - public int getScope() { - return fScope; - } - - public IReconcileStep getStep() { - return fReconcileStep; - } - - public String toString() { - return this.getClass() + "\r\nid: " + fPartitionType; //$NON-NLS-1$ - } -} diff --git a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/reconcile/StructuredReconcileStep.java b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/reconcile/StructuredReconcileStep.java deleted file mode 100644 index e6a88754b0..0000000000 --- a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/reconcile/StructuredReconcileStep.java +++ /dev/null @@ -1,193 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 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 - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.sse.ui.internal.reconcile; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashSet; -import java.util.List; - -import org.eclipse.core.runtime.Platform; -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.IRegion; -import org.eclipse.jface.text.ITypedRegion; -import org.eclipse.jface.text.TextUtilities; -import org.eclipse.jface.text.reconciler.AbstractReconcileStep; -import org.eclipse.jface.text.reconciler.DirtyRegion; -import org.eclipse.jface.text.reconciler.IReconcilableModel; -import org.eclipse.jface.text.reconciler.IReconcileResult; -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.IStructuredPartitioning; -import org.eclipse.wst.sse.core.text.IStructuredPartitions; -import org.eclipse.wst.sse.ui.internal.IReleasable; -import org.eclipse.wst.sse.ui.internal.Logger; - - -/** - * ReconcileStep that knows about the annotation that it adds to the - * AnnotationModel. It knows how to create an annotation key (for smart - * removal later) It knows the partition types on which it can operate. It - * knows the scope on which it operates (for short circuiting) It knows if the - * Reconciler is reconciling the entire document. - * - * Clients must subclass this class. - * - * @author pavery - */ -public abstract class StructuredReconcileStep extends AbstractReconcileStep implements IReleasable { - - /** debug flag */ - protected static final boolean DEBUG; - static { - String value = Platform.getDebugOption("org.eclipse.wst.sse.ui/debug/reconcilerjob"); //$NON-NLS-1$ - DEBUG = value != null && value.equalsIgnoreCase("true"); //$NON-NLS-1$ - } - - protected final IReconcileResult[] EMPTY_RECONCILE_RESULT_SET = new IReconcileResult[0]; - - /** - * It's possible for a partial step to get called on the same area twice - * (as w/ a full document reconcile) this list keeps track of area already - * covered. Should be reset() after the "batch" of reconciling is - * finished. - */ - private HashSet fPartitionTypes = null; - - public StructuredReconcileStep() { - super(); - fPartitionTypes = new HashSet(); - } - - public ReconcileAnnotationKey createKey(IStructuredDocumentRegion sdRegion, int scope) { - - ITypedRegion tr = getPartition(sdRegion); - String partitionType = (tr != null) ? tr.getType() : IStructuredPartitions.UNKNOWN_PARTITION; - return createKey(partitionType, scope); - } - - /** - * @param sdRegion - * @return - */ - protected ITypedRegion getPartition(IStructuredDocumentRegion sdRegion) { - ITypedRegion tr = null; - if (!sdRegion.isDeleted()) - tr = getPartition(sdRegion.getParentDocument(), sdRegion.getStartOffset()); - return tr; - } - - private ITypedRegion getPartition(IDocument doc, int offset) { - ITypedRegion tr = null; - // not sure why document would ever be null, but put in this - // guard for - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=86069 - if (doc != null) { - try { - tr = TextUtilities.getPartition(doc, IStructuredPartitioning.DEFAULT_STRUCTURED_PARTITIONING, offset, false); - } catch (BadLocationException e) { - if (DEBUG) - Logger.logException("problem getting partition at: " + offset, e); //$NON-NLS-1$ - } - } - return tr; - } - - /** - * Clients should use this method to create annotation keys as it - * registers the key for removal later. - * - * @param partitionType - * @param scope - * @return - */ - public ReconcileAnnotationKey createKey(String partitionType, int scope) { - fPartitionTypes.add(partitionType); - return new ReconcileAnnotationKey(this, partitionType, scope); - } - - protected IDocument getDocument() { - IDocument doc = null; - IReconcilableModel rModel = getModel(); - if (rModel instanceof DocumentAdapter) { - doc = ((DocumentAdapter) rModel).getDocument(); - } - return doc; - } - - public IReconcilableModel getModel() { - return getInputModel(); - } - - public String getPartitionType(IDocument doc, int offset) { - ITypedRegion tr = getPartition(doc, offset); - return (tr != null) ? tr.getType() : IStructuredPartitions.UNKNOWN_PARTITION; - } - - public String[] getPartitionTypes() { - // using hash set to automatically get rid of dupes - HashSet tempResults = new HashSet(); - // add these partition types - tempResults.addAll(fPartitionTypes); - return (String[]) tempResults.toArray(new String[tempResults.size()]); - } - - protected IStructuredDocument getStructuredDocument() { - IStructuredDocument sDoc = null; - IDocument doc = getDocument(); - if (doc instanceof IStructuredDocument) - sDoc = (IStructuredDocument) getDocument(); - return sDoc; - } - - /** - * Removes duplicates. - * - * @param results1 - * @param results2 - * @return - */ - protected IReconcileResult[] merge(IReconcileResult[] results1, IReconcileResult[] results2) { - if (results1 == null) - return results2; - if (results2 == null) - return results1; - - List results = new ArrayList(); - results.addAll(Arrays.asList(results1)); - for (int i = 0; i < results2.length; i++) { - results.add(results2[i]); - } - return (IReconcileResult[]) results.toArray(new IReconcileResult[results.size()]); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.text.reconciler.AbstractReconcileStep#reconcileModel(org.eclipse.jface.text.reconciler.DirtyRegion, - * org.eclipse.jface.text.IRegion) - */ - protected IReconcileResult[] reconcileModel(DirtyRegion dirtyRegion, IRegion subRegion) { - return EMPTY_RECONCILE_RESULT_SET; - } - - /** - * Release resources used by the step here as needed. Be sure to call - * super.release() when you override this method as to propagate the - * release through all steps. - */ - public void release() { - // - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/reconcile/StructuredRegionProcessor.java b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/reconcile/StructuredRegionProcessor.java deleted file mode 100644 index 270f3978ed..0000000000 --- a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/reconcile/StructuredRegionProcessor.java +++ /dev/null @@ -1,305 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2006 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 - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.sse.ui.internal.reconcile; - -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.reconciler.DirtyRegion; -import org.eclipse.wst.sse.core.StructuredModelManager; -import org.eclipse.wst.sse.core.internal.model.ModelLifecycleEvent; -import org.eclipse.wst.sse.core.internal.provisional.IModelLifecycleListener; -import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; -import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion; -import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument; - -/** - * An IStructuredModel aware Region Processor. Adds ModelLifecycle listener. - * ModelLifecycle listener notifies us that some reinitialization needs to - * take place. - * - * Model aware "process()" Implements a IndexedRegion-based "contains()" - * method using IStructuredModel. - * - */ -public class StructuredRegionProcessor extends DocumentRegionProcessor { - - class ModelLifecycleListener implements IModelLifecycleListener { - /** - * @see org.eclipse.wst.sse.core.internal.provisional.IModelLifecycleListener#processPostModelEvent(org.eclipse.wst.sse.core.internal.model.ModelLifecycleEvent) - */ - public void processPostModelEvent(ModelLifecycleEvent event) { - - // if underlying StructuredDocument changed, need to reconnect it - // here... - // ex. file is modified outside the workbench - if (event.getType() == ModelLifecycleEvent.MODEL_DOCUMENT_CHANGED) { - - // check that it's this model that changed - IStructuredModel thisModel = getStructuredModelForRead(getDocument()); - try { - if (thisModel != null && event.getModel().equals(thisModel)) { - - IStructuredDocument sDoc = event.getModel().getStructuredDocument(); - - if (DEBUG) { - System.out.println("======================================================"); //$NON-NLS-1$ - System.out.println("StructuredRegionProcessor: DOCUMENT MODEL CHANGED TO: "); //$NON-NLS-1$ - System.out.println(sDoc.get()); - System.out.println("======================================================"); //$NON-NLS-1$ - } - setDocument(sDoc); - // propagate document change - // setDocumentOnAllStrategies(sDoc); - // ensure that the document is re-reconciled - setEntireDocumentDirty(sDoc); - } - } - finally { - if (thisModel != null) - thisModel.releaseFromRead(); - } - } - } - - /** - * @see org.eclipse.wst.sse.core.internal.provisional.IModelLifecycleListener#processPreModelEvent(org.eclipse.wst.sse.core.internal.model.ModelLifecycleEvent) - */ - public void processPreModelEvent(ModelLifecycleEvent event) { - - if (event.getType() == ModelLifecycleEvent.MODEL_DOCUMENT_CHANGED) { - - flushDirtyRegionQueue(); - // note: old annotations are removed via the strategies on - // AbstractStructuredTextReconcilingStrategy#setDocument(...) - } - } - } - - private IModelLifecycleListener fLifeCycleListener = new ModelLifecycleListener(); - - /* - * (non-Javadoc) - * - * @see org.eclipse.wst.sse.ui.internal.reconcile.DirtyRegionProcessor#getOuterRegion(org.eclipse.jface.text.reconciler.DirtyRegion, - * org.eclipse.jface.text.reconciler.DirtyRegion) - */ - protected DirtyRegion getOuterRegion(DirtyRegion root, DirtyRegion possible) { - // first try simple region check if one region contains the other - DirtyRegion outer = super.getOuterRegion(root, possible); - if (outer == null) { - // now compare nodes - IStructuredModel sModel = getStructuredModelForRead(getDocument()); - try { - if (sModel != null) { - IndexedRegion rootRegion = sModel.getIndexedRegion(root.getOffset()); - IndexedRegion possRegion = sModel.getIndexedRegion(possible.getOffset()); - if (rootRegion != null && possRegion != null) { - int rootStart = rootRegion.getStartOffset(); - int possStart = possRegion.getStartOffset(); - // first just check if rootregion starts before - // possregion - if (rootStart <= possStart) { - // check if possregion is inside rootregion - outer = _getOuterRegion(root, possible, sModel, rootStart, possStart); - } - else { - // otherwise if rootregion is inside possregion - outer = _getOuterRegion(possible, root, sModel, possStart, rootStart); - } - } - } - } - finally { - if (sModel != null) - sModel.releaseFromRead(); - } - } - return outer; - } - - /** - * Assumes that when this method is called, region1's node start offset >= - * region2's node start offset. Determines if region1 contains region2 or - * vice versa. Returns region1 if: - * <ul> - * <li>region1's node region == region2's node region</li> - * <li>region1's node region contains region2's node region</li> - * </ul> - * Returns region2 if: - * <ul> - * <li>region1's node region and region2's node region starts at same - * offset but region2's node region is longer</li> - * </ul> - * Returns null otherwise. - * - * @param region1 - * @param region2 - * @param sModel - * @param region1NodeStart - * @param region2NodeStart - * @return outer dirty region or null if none exists. - */ - private DirtyRegion _getOuterRegion(DirtyRegion region1, DirtyRegion region2, IStructuredModel sModel, int region1NodeStart, int region2NodeStart) { - DirtyRegion outer = null; - int region1NodeEnd = -1; - int region2NodeEnd = -1; - // then check if region1's end appears after - // region2's end - IndexedRegion region1EndNode = sModel.getIndexedRegion(region1.getOffset() + region1.getLength()); - if (region1EndNode == null) { - // if no end, just assume region spans all the - // way to the end so it includes other region - outer = region1; - } - else { - region1NodeEnd = region1EndNode.getEndOffset(); - IndexedRegion region2EndNode = sModel.getIndexedRegion(region2.getOffset() + region2.getLength()); - region2NodeEnd = region2EndNode != null ? region2EndNode.getEndOffset() : getDocument().getLength(); - if (region1NodeEnd >= region2NodeEnd) { - // root contains or is equal to possible - outer = region1; - } - else if (region1NodeStart == region2NodeStart && region2NodeEnd >= region1NodeEnd) { - // possible contains root because they - // both start at same place but possible - // is longer - outer = region2; - } - } - if (DEBUG) { - if (outer != null) - System.out.println("checking if [" + region1NodeStart + ":" + region1NodeEnd + "] contains [" + region2NodeStart + ":" + region2NodeEnd + "] ... " + outer.toString()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ - else - System.out.println("checking if [" + region1NodeStart + ":" + region1NodeEnd + "] contains [" + region2NodeStart + ":" + region2NodeEnd + "] ... NO CONTAIN"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ - } - return outer; - } - - /** - * We already know content type from when we created the model, so just - * use that. - */ - protected String getContentType(IDocument doc) { - - String contentTypeId = null; - IStructuredModel sModel = null; - try { - sModel = StructuredModelManager.getModelManager().getExistingModelForRead(doc); - if (sModel != null) { - contentTypeId = sModel.getContentTypeIdentifier(); - } - } - finally { - if (sModel != null) - sModel.releaseFromRead(); - } - return contentTypeId; - } - - - /** - * Remember to release model after use!! - * - * @return - */ - private IStructuredModel getStructuredModelForRead(IDocument doc) { - IStructuredModel sModel = null; - if (doc != null) - sModel = StructuredModelManager.getModelManager().getExistingModelForRead(doc); - return sModel; - } - - /** - * @param document - */ - private void hookUpModelLifecycleListener(IDocument document) { - IStructuredModel sModel = getStructuredModelForRead(document); - try { - if (sModel != null) { - sModel.addModelLifecycleListener(fLifeCycleListener); - } - } - finally { - if (sModel != null) - sModel.releaseFromRead(); - } - } - - protected void process(DirtyRegion dirtyRegion) { - if (getDocument() == null) - return; - - // use structured model to determine area to process - IStructuredModel sModel = StructuredModelManager.getModelManager().getExistingModelForRead(getDocument()); - try { - if (sModel != null) { - int start = dirtyRegion.getOffset(); - int end = start + dirtyRegion.getLength(); - IndexedRegion irStart = sModel.getIndexedRegion(start); - IndexedRegion irEnd = sModel.getIndexedRegion(end); - - if (irStart != null) { - start = Math.min(start, irStart.getStartOffset()); - } - if (irEnd != null) { - end = Math.max(end, irEnd.getEndOffset()); - } - super.process(createDirtyRegion(start, end - start, DirtyRegion.INSERT)); - } - } - finally { - if (sModel != null) - sModel.releaseFromRead(); - } - } - - /** - * Reinitializes listeners and sets new document onall strategies. - * - * @see org.eclipse.jface.text.reconciler.AbstractReconciler#reconcilerDocumentChanged(IDocument) - */ - protected void reconcilerDocumentChanged(IDocument newDocument) { - - IDocument currentDoc = getDocument(); - - // unhook old lifecycle listner - unhookModelLifecycleListener(currentDoc); - // add new lifecycle listener - if (newDocument != null) - hookUpModelLifecycleListener(newDocument); - - super.reconcilerDocumentChanged(newDocument); - } - - /** - * @param document - */ - private void unhookModelLifecycleListener(IDocument document) { - IStructuredModel sModel = getStructuredModelForRead(document); - try { - if (sModel != null) - sModel.removeModelLifecycleListener(fLifeCycleListener); - - } - finally { - if (sModel != null) - sModel.releaseFromRead(); - } - } - - public void uninstall() { - - // removes model listeners - unhookModelLifecycleListener(getDocument()); - super.uninstall(); - } -} diff --git a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/reconcile/StructuredTextReconcilingStrategy.java b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/reconcile/StructuredTextReconcilingStrategy.java deleted file mode 100644 index bceefd4652..0000000000 --- a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/reconcile/StructuredTextReconcilingStrategy.java +++ /dev/null @@ -1,65 +0,0 @@ -package org.eclipse.wst.sse.ui.internal.reconcile; - -import org.eclipse.jface.text.Position; -import org.eclipse.jface.text.source.ISourceViewer; -import org.eclipse.wst.sse.core.StructuredModelManager; -import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; -import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion; -import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion; - -/** - * Uses IStructuredModel nodes to check "overlaps()" when getting annotations to remove. - */ -public abstract class StructuredTextReconcilingStrategy extends AbstractStructuredTextReconcilingStrategy { - - - public StructuredTextReconcilingStrategy(ISourceViewer sourceViewer) { - super(sourceViewer); - } - - /** - * Checks if this position overlaps any of the StructuredDocument regions' - * correstponding IndexedRegion. - * - * @param pos - * @param dr - * @return true if the position overlaps any of the regions, otherwise - * false. - */ - protected boolean overlaps(Position pos, IStructuredDocumentRegion[] sdRegions) { - int start = -1; - int end = -1; - for (int i = 0; i < sdRegions.length; i++) { - if(!sdRegions[i].isDeleted()) { - IndexedRegion corresponding = getCorrespondingNode(sdRegions[i]); - if(corresponding != null) { - if (start == -1 || start > corresponding.getStartOffset()) - start = corresponding.getStartOffset(); - if (end == -1 || end < corresponding.getEndOffset()) - end = corresponding.getEndOffset(); - } - } - } - return pos.overlapsWith(start, end - start); - } - - /** - * Returns the corresponding node for the StructuredDocumentRegion. - * - * @param sdRegion - * @return the corresponding node for sdRegion - */ - protected IndexedRegion getCorrespondingNode(IStructuredDocumentRegion sdRegion) { - IStructuredModel sModel = StructuredModelManager.getModelManager().getExistingModelForRead(getDocument()); - IndexedRegion indexedRegion = null; - try { - if (sModel != null) - indexedRegion = sModel.getIndexedRegion(sdRegion.getStart()); - } finally { - if (sModel != null) - sModel.releaseFromRead(); - } - return indexedRegion; - } - -} diff --git a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/reconcile/TemporaryAnnotation.java b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/reconcile/TemporaryAnnotation.java deleted file mode 100644 index 21a05c8d65..0000000000 --- a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/reconcile/TemporaryAnnotation.java +++ /dev/null @@ -1,230 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 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 - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.sse.ui.internal.reconcile; - -import org.eclipse.jface.text.Position; -import org.eclipse.jface.text.reconciler.IReconcileResult; -import org.eclipse.jface.text.source.Annotation; -import org.eclipse.jface.text.source.IAnnotationAccessExtension; -import org.eclipse.jface.text.source.IAnnotationPresentation; -import org.eclipse.jface.text.source.ImageUtilities; -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.GC; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.graphics.Rectangle; -import org.eclipse.swt.widgets.Canvas; -import org.eclipse.ui.editors.text.EditorsUI; -import org.eclipse.ui.texteditor.AnnotationPreference; -import org.eclipse.ui.texteditor.AnnotationPreferenceLookup; -import org.eclipse.wst.sse.ui.internal.ITemporaryAnnotation; - - -/** - * An implementation of ITemporaryAnnotation @ - * @author pavery - */ -public class TemporaryAnnotation extends Annotation implements ITemporaryAnnotation, IReconcileResult, IAnnotationPresentation { - // remember to change these if it changes in the extension point - // may need a different home for them in the future, but they're here for - // now - public final static String ANNOT_ERROR = "org.eclipse.wst.sse.ui.temp.error"; //$NON-NLS-1$ - public final static String ANNOT_INFO = "org.eclipse.wst.sse.ui.temp.info"; //$NON-NLS-1$ - - // pa_TODO what should the ID be for this? - public final static String ANNOT_UNKNOWN = Annotation.TYPE_UNKNOWN; - public final static String ANNOT_WARNING = "org.eclipse.wst.sse.ui.temp.warning"; //$NON-NLS-1$ - - // copied from CompilationUnitDocumentProvider.ProblemAnnotation - //XXX: To be fully correct these constants should be non-static - - private static final int INFO_LAYER; - - private static final int WARNING_LAYER; - - private static final int ERROR_LAYER; - - static { - AnnotationPreferenceLookup lookup= EditorsUI.getAnnotationPreferenceLookup(); - INFO_LAYER= computeLayer("org.eclipse.wst.sse.ui.temp.info", lookup); //$NON-NLS-1$ - WARNING_LAYER= computeLayer("org.eclipse.wst.sse.ui.temp.warning", lookup); //$NON-NLS-1$ - ERROR_LAYER= computeLayer("org.eclipse.wst.sse.ui.temp.error", lookup); //$NON-NLS-1$ - } - - private static int computeLayer(String annotationType, AnnotationPreferenceLookup lookup) { - Annotation annotation= new Annotation(annotationType, false, null); - AnnotationPreference preference= lookup.getAnnotationPreference(annotation); - if (preference != null) - return preference.getPresentationLayer() + 1; - else - return IAnnotationAccessExtension.DEFAULT_LAYER + 1; - } - - - private Object fAdditionalFixInfo = null; - - private Object fKey = null; - private Position fPosition = null; - - private int fProblemID; - - private int fLayer = DEFAULT_LAYER; - - private Image fImage = null; - - public TemporaryAnnotation(Position p, String type, String message, ReconcileAnnotationKey key) { - super(); - fPosition = p; - setType(type); - fKey = key; - setText(message); - initLayer(); - initImage(); - } - - public TemporaryAnnotation(Position p, String type, String message, ReconcileAnnotationKey key, int problemId) { - super(); - fPosition = p; - fKey = key; - setType(type); - setText(message); - fProblemID = problemId; - initLayer(); - initImage(); - } - - private void initLayer() { - - String type = getType(); - if(type.equals(ANNOT_ERROR)) { - fLayer = ERROR_LAYER; - } - else if(type.equals(ANNOT_WARNING)) { - fLayer = WARNING_LAYER; - } - else if(type.equals(ANNOT_INFO)) { - fLayer = INFO_LAYER; - } - } - - private void initImage() { - // later we can add support for quick fix images. - String type = getType(); - if(type.equals(ANNOT_ERROR)) { - fImage = null; - } - else if(type.equals(ANNOT_WARNING)) { - fImage = null; - } - else if(type.equals(ANNOT_INFO)) { - fImage = null; - } - } - - /* - * (non-Javadoc) - * - * @see java.lang.Object#equals(java.lang.Object) - */ - public boolean equals(Object obj) { - // this check doesn't take into consideration that annotation - // positions that change from a text edit before it - // we should be checking if the annotation is still on the same line, - // and the distance from the start of the line is the same - if (obj instanceof TemporaryAnnotation) { - - TemporaryAnnotation ta = (TemporaryAnnotation) obj; - - boolean samePosition = ta.getPosition().equals(this.getPosition()); - boolean sameText = false; - - if(ta.getText() != null && this.getText() != null && ta.getText().equals(this.getText())) - sameText = true; - else if(ta.getText( )== null && this.getText() == null) - sameText = true; - - return sameText && samePosition; - } - return super.equals(obj); - } - - /** - * Additional info required to fix this problem. - * - * @return an Object that contains additional info on how to fix this - * problem, or null if there is none - */ - public Object getAdditionalFixInfo() { - return fAdditionalFixInfo; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.wst.sse.ui.ITemporaryAnnotation#getDescription() - */ - public String getDescription() { - return getText(); - } - - public Object getKey() { - return fKey; - } - - public Position getPosition() { - return fPosition; - } - - /** - * @return Returns the problemID. - */ - public int getProblemID() { - return fProblemID; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.text.source.Annotation#isPersistent() - */ - public boolean isPersistent() { - return false; - } - - /** - * Sets additional information useful to fixing this problem. - * - * @param an - * Object that contains additional info on how to fix this - * problem - */ - public void setAdditionalFixInfo(Object info) { - fAdditionalFixInfo = info; - } - - public int getLayer() { - return fLayer; - } - - /* - * @see Annotation#paint - */ - public void paint(GC gc, Canvas canvas, Rectangle r) { - //initializeImages(); - if (fImage != null) - ImageUtilities.drawImage(fImage, gc, canvas, r, SWT.CENTER, SWT.TOP); - } - - public String toString() { - return "" + fPosition.getOffset() + ':' + fPosition.getLength() + ": " + getText(); //$NON-NLS-1$ //$NON-NLS-2$ - } -} diff --git a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/reconcile/validator/AnnotationInfo.java b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/reconcile/validator/AnnotationInfo.java deleted file mode 100644 index 609420e136..0000000000 --- a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/reconcile/validator/AnnotationInfo.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.eclipse.wst.sse.ui.internal.reconcile.validator; - -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - -/** - * Holds info to create a TemporaryAnnotation. - * - * @since 1.0 - */ -public class AnnotationInfo { - - public static final int NO_PROBLEM_ID = -1; - private IMessage fMessage = null; - private Object fAdditionalFixInfo = null; - private int fProblemId = NO_PROBLEM_ID; - - public AnnotationInfo(IMessage message) { - fMessage = message; - - } - public AnnotationInfo(IMessage message, int problemId, Object additionalFixInfo) { - this(message); - fProblemId = problemId; - fAdditionalFixInfo = additionalFixInfo; - } - - public final IMessage getMessage() { - return fMessage; - } - - public final Object getAdditionalFixInfo() { - return fAdditionalFixInfo; - } - - public final int getProblemId() { - return fProblemId; - } -} diff --git a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/reconcile/validator/ISourceValidator.java b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/reconcile/validator/ISourceValidator.java deleted file mode 100644 index 1e09976ca9..0000000000 --- a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/reconcile/validator/ISourceValidator.java +++ /dev/null @@ -1,42 +0,0 @@ -package org.eclipse.wst.sse.ui.internal.reconcile.validator; - -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.IRegion; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; -import org.eclipse.wst.validation.internal.provisional.core.IValidationContext; - -/** - * Interface to allow for "partial document" as you type validation. - * - */ -public interface ISourceValidator { - - /** - * As you type validation is getting "hooked up" to this IDocument. - * This is the instance of IDocument that the validator should - * operate on for each validate call. - * - * @param document - */ - void connect(IDocument document); - - /** - * The same IDocument passed in from the connect() method. - * This indicates that as you type validation is "shutting down" - * for this IDocument. - * - * @param document - */ - void disconnect(IDocument document); - - /** - * Like IValidator#validate(IValidationContext helper, IReporter reporter) - * except passes the dirty region, so document validation can be better - * optimized. - * - * @param dirtyRegion - * @param helper - * @param reporter - */ - void validate(IRegion dirtyRegion, IValidationContext helper, IReporter reporter); -} diff --git a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/reconcile/validator/IncrementalHelper.java b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/reconcile/validator/IncrementalHelper.java deleted file mode 100644 index 7b3ce3402a..0000000000 --- a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/reconcile/validator/IncrementalHelper.java +++ /dev/null @@ -1,57 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 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 - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.sse.ui.internal.reconcile.validator; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.jface.text.IDocument; -import org.eclipse.wst.validation.internal.provisional.core.IValidationContext; - - - -public class IncrementalHelper implements IValidationContext { - private IProject fProject; - - private String fURI = null; - - public IncrementalHelper(IDocument sourceDocument, IProject project) { - super(); - fProject = project; - } - - public String getPortableName(IResource resource) { - return resource.getProjectRelativePath().toString(); - } - - public IProject getProject() { - return fProject; - } - - public Object loadModel(String symbolicName) { - return null; - } - - public Object loadModel(String symbolicName, Object[] parms) { - return null; - } - - void setURI(String uri) { - fURI = uri; - } - - public String[] getURIs() { - if(fURI != null) - return new String[]{fURI}; - return new String[0]; - } -} diff --git a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/reconcile/validator/IncrementalReporter.java b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/reconcile/validator/IncrementalReporter.java deleted file mode 100644 index f67dae7ae8..0000000000 --- a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/reconcile/validator/IncrementalReporter.java +++ /dev/null @@ -1,111 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 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 - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.sse.ui.internal.reconcile.validator; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; -import org.eclipse.wst.validation.internal.provisional.core.IValidator; - - -/** - * Right now we'll only use one reporter per validator. - */ -public class IncrementalReporter implements IReporter { - private IProgressMonitor fProgressMonitor; - private HashMap messages = new HashMap(); - - public IncrementalReporter(IProgressMonitor progressMonitor) { - super(); - fProgressMonitor = progressMonitor; - } - - public void addMessage(IValidator validator, IMessage message) { - AnnotationInfo info = new AnnotationInfo(message); - addAnnotationInfo(validator, info); - } - - public final void addAnnotationInfo(IValidator validator, AnnotationInfo info) { - Object existingValue = messages.get(validator); - if (existingValue != null) { - ((HashSet) existingValue).add(info); - } - else { - HashSet newValue = new HashSet(1); - newValue.add(info); - messages.put(validator, newValue); - } - } - - public void displaySubtask(IValidator validator, IMessage message) { - if ((message == null) || (message.equals(""))) { //$NON-NLS-1$ - return; - } - if (fProgressMonitor != null) { - fProgressMonitor.subTask(message.getText(validator.getClass().getClassLoader())); - } - } - - public List getMessages() { - List result = new ArrayList(); - // messages is a list of: - // validators => HashSet(AnnotationInfo1, AnnotationInfo2, ...) - // (one HashSet per validator...) - Object[] lists = messages.values().toArray(); - for (int i = 0; i < lists.length; i++) { - Iterator it = ((HashSet)lists[i]).iterator(); - while (it.hasNext()) { - AnnotationInfo info = (AnnotationInfo) it.next(); - result.add(info.getMessage()); - } - } - return result; - } - - public AnnotationInfo[] getAnnotationInfo() { - List result = new ArrayList(); - Object[] infos = messages.values().toArray(); - for (int i = 0; i < infos.length; i++) { - result.addAll((HashSet)infos[i]); - } - return (AnnotationInfo[])result.toArray(new AnnotationInfo[result.size()]); - } - - public boolean isCancelled() { - if (fProgressMonitor == null) - return false; - return fProgressMonitor.isCanceled(); - } - - public void removeAllMessages(IValidator validator) { - Object o = messages.get(validator); - if(o != null && o instanceof HashSet) { - ((HashSet)o).clear(); - } - } - - public void removeAllMessages(IValidator validator, Object object) { - removeAllMessages(validator); - } - - // group names are unsupported - public void removeMessageSubset(IValidator validator, Object obj, String groupName) { - removeAllMessages(validator); - } -} diff --git a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/reconcile/validator/ReconcileStepForValidator.java b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/reconcile/validator/ReconcileStepForValidator.java deleted file mode 100644 index 306d329b53..0000000000 --- a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/reconcile/validator/ReconcileStepForValidator.java +++ /dev/null @@ -1,345 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2006 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 - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.sse.ui.internal.reconcile.validator; - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.Platform; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.IRegion; -import org.eclipse.jface.text.Position; -import org.eclipse.jface.text.reconciler.DirtyRegion; -import org.eclipse.jface.text.reconciler.IReconcilableModel; -import org.eclipse.jface.text.reconciler.IReconcileResult; -import org.eclipse.wst.sse.core.StructuredModelManager; -import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; -import org.eclipse.wst.sse.ui.internal.Logger; -import org.eclipse.wst.sse.ui.internal.reconcile.DocumentAdapter; -import org.eclipse.wst.sse.ui.internal.reconcile.ReconcileAnnotationKey; -import org.eclipse.wst.sse.ui.internal.reconcile.StructuredReconcileStep; -import org.eclipse.wst.sse.ui.internal.reconcile.TemporaryAnnotation; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IValidator; - - -/** - * A reconcile step for an IValidator for reconcile. Used the reconcile - * framework to create TemporaryAnnotations from the validator messages. - * - * @author pavery - */ -public class ReconcileStepForValidator extends StructuredReconcileStep { - - /** debug flag */ - protected static final boolean DEBUG; - static { - String value = Platform.getDebugOption("org.eclipse.wst.sse.ui/debug/reconcilerjob"); //$NON-NLS-1$ - DEBUG = value != null && value.equalsIgnoreCase("true"); //$NON-NLS-1$ - } - - private final IReconcileResult[] EMPTY_RECONCILE_RESULT_SET = new IReconcileResult[0]; - private IncrementalHelper fHelper = null; - private IncrementalReporter fReporter = null; - private int fScope = -1; - private IValidator fValidator = null; - - - public ReconcileStepForValidator(IValidator v, int scope) { - super(); - - if (v == null) - throw new IllegalArgumentException("validator cannot be null"); //$NON-NLS-1$ - - fValidator = v; - fScope = scope; - } - - /** - * Converts a map of IValidatorForReconcile to List to annotations based - * on those messages - * - * @param messages - * @return - */ -// protected IReconcileResult[] createAnnotations(List messageList) { -// List annotations = new ArrayList(); -// for (int i = 0; i < messageList.size(); i++) { -// IMessage validationMessage = (IMessage) messageList.get(i); -// -// int offset = validationMessage.getOffset(); -// -// if (offset < 0) -// continue; -// -// String messageText = null; -// try { -// messageText = validationMessage.getText(validationMessage.getClass().getClassLoader()); -// } -// catch (Exception t) { -// Logger.logException("exception reporting message from validator", t); //$NON-NLS-1$ -// continue; -// } -// -// String type = getSeverity(validationMessage); -// // this position seems like it would be possibly be the wrong -// // length -// int length = validationMessage.getLength(); -// if (length >= 0) { -// Position p = new Position(offset, length); -// ReconcileAnnotationKey key = createKey(getPartitionType(getDocument(), offset), getScope()); -// annotations.add(new TemporaryAnnotation(p, type, messageText, key)); -// } -// } -// -// return (IReconcileResult[]) annotations.toArray(new IReconcileResult[annotations.size()]); -// } - - /** - * Converts a map of IValidatorForReconcile to List to annotations based - * on those messages - * - * @param messages - * @return - */ - protected IReconcileResult[] createAnnotations(AnnotationInfo[] infos) { - - - List annotations = new ArrayList(); - for (int i = 0; i < infos.length; i++) { - - AnnotationInfo info = infos[i]; - - IMessage validationMessage = info.getMessage(); - int offset = validationMessage.getOffset(); - if (offset < 0) - continue; - - String messageText = null; - try { - messageText = validationMessage.getText(validationMessage.getClass().getClassLoader()); - } - catch (Exception t) { - Logger.logException("exception reporting message from validator", t); //$NON-NLS-1$ - continue; - } - String type = getSeverity(validationMessage); - // this position seems like it would be possibly be the wrong - // length - int length = validationMessage.getLength(); - if (length >= 0) { - - Position p = new Position(offset, length); - ReconcileAnnotationKey key = createKey(getPartitionType(getDocument(), offset), getScope()); - - if(info.getProblemId() == AnnotationInfo.NO_PROBLEM_ID) { - // create an annotation w/ no fix info - annotations.add(new TemporaryAnnotation(p, type, messageText, key)); - } - else { - // create an annotation w/ problem ID and fix info - TemporaryAnnotation annotation = new TemporaryAnnotation(p, type, messageText, key, info.getProblemId()); - annotation.setAdditionalFixInfo(info.getAdditionalFixInfo()); - annotations.add(annotation); - } - } - } - return (IReconcileResult[]) annotations.toArray(new IReconcileResult[annotations.size()]); - } - - private String getSeverity(IMessage validationMessage) { - String type = TemporaryAnnotation.ANNOT_INFO; - switch (validationMessage.getSeverity()) { - case IMessage.HIGH_SEVERITY : - type = TemporaryAnnotation.ANNOT_ERROR; - break; - case IMessage.NORMAL_SEVERITY : - type = TemporaryAnnotation.ANNOT_WARNING; - break; - case IMessage.LOW_SEVERITY : - type = TemporaryAnnotation.ANNOT_WARNING; - break; - case IMessage.ERROR_AND_WARNING : - type = TemporaryAnnotation.ANNOT_WARNING; - break; - } - return type; - } - - private IFile getFile() { - IStructuredModel model = null; - IFile file = null; - try { - model = StructuredModelManager.getModelManager().getExistingModelForRead(getDocument()); - if (model != null) { - String baseLocation = model.getBaseLocation(); - // The baseLocation may be a path on disk or relative to the - // workspace root. Don't translate on-disk paths to - // in-workspace resources. - IPath basePath = new Path(baseLocation); - if (basePath.segmentCount() > 1 && !basePath.toFile().exists()) { - file = ResourcesPlugin.getWorkspace().getRoot().getFile(basePath); - } - } - } - finally { - if (model != null) { - model.releaseFromRead(); - } - } - return file; - } - - private IncrementalHelper getHelper(IProject project) { - if (fHelper == null) - fHelper = new IncrementalHelper(getDocument(), project); - return fHelper; - } - - private IncrementalReporter getReporter() { - if (fReporter == null) - fReporter = new IncrementalReporter(getProgressMonitor()); - return fReporter; - } - - /** - * If this validator is partial or total - * @return - */ - public int getScope() { - return fScope; - } - - public void initialReconcile() { - // do nothing - } - - protected IReconcileResult[] reconcileModel(DirtyRegion dirtyRegion, IRegion subRegion) { - if (DEBUG) - System.out.println("[trace reconciler] > reconciling model in VALIDATOR step w/ dirty region: [" + dirtyRegion.getText() + "]"); //$NON-NLS-1$ //$NON-NLS-2$ - - IReconcileResult[] results = EMPTY_RECONCILE_RESULT_SET; - if (dirtyRegion != null) { - try { - if(fValidator instanceof ISourceValidator) { - results = validate(dirtyRegion, subRegion); - } - else { - results = validate(); - } - } - catch (Exception ex) { - Logger.logException("EXEPTION IN RECONCILE STEP FOR VALIDATOR", ex); //$NON-NLS-1$ - } - } - - if (DEBUG) - System.out.println("[trace reconciler] > VALIDATOR step done"); //$NON-NLS-1$ - - return results; - } - - public String toString() { - StringBuffer debugString = new StringBuffer("ValidatorStep: "); //$NON-NLS-1$ - if (fValidator != null) - debugString.append(fValidator.getClass().toString()); - return debugString.toString(); - } - - protected IReconcileResult[] validate() { - IReconcileResult[] results = EMPTY_RECONCILE_RESULT_SET; - - IFile file = getFile(); - - try { - IncrementalHelper helper = getHelper(file != null ? file.getProject() : null); - IncrementalReporter reporter = getReporter(); - - if (file != null && file.exists()) { - helper.setURI(file.getFullPath().toString()); - } - - fValidator.validate(helper, reporter); - - // results = createAnnotations(reporter.getMessages()); - results = createAnnotations(reporter.getAnnotationInfo()); - reporter.removeAllMessages(fValidator); - - fValidator.cleanup(reporter); - } - catch (Exception e) { - Logger.logException(e); - } - return results; - } - - public void setInputModel(IReconcilableModel inputModel) { - if(inputModel instanceof DocumentAdapter) { - IDocument document = ((DocumentAdapter)inputModel).getDocument(); - if(document != null) { - if(fValidator instanceof ISourceValidator) { - // notify that document connecting - ((ISourceValidator)fValidator).connect(document); - } - } - } - super.setInputModel(inputModel); - } - - public void release() { - if(fValidator instanceof ISourceValidator) { - IDocument document = getDocument(); - if(document != null) { - // notify that document disconnecting - ((ISourceValidator)fValidator).disconnect(document); - } - fValidator.cleanup(getReporter()); - } - super.release(); - } - - protected IReconcileResult[] validate(DirtyRegion dirtyRegion, IRegion subRegion) { - IReconcileResult[] results = EMPTY_RECONCILE_RESULT_SET; - - IFile file = getFile(); - - try { - IncrementalHelper helper = getHelper(file != null ? file.getProject() : null); - /* - * Setting the URI isn't necessary for all source validators, we - * can still continue without it - */ - if (file != null && file.exists()) { - helper.setURI(file.getFullPath().toString()); - } - - if (fValidator instanceof ISourceValidator) { - IncrementalReporter reporter = getReporter(); - ((ISourceValidator) fValidator).validate(dirtyRegion, helper, reporter); - // call IValidator.cleanup() during release() - // results = createAnnotations(reporter.getMessages()); - results = createAnnotations(reporter.getAnnotationInfo()); - reporter.removeAllMessages(fValidator); - } - } - catch (Exception e) { - Logger.logException(e); - } - return results; - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/reconcile/validator/ValidatorBuilder.java b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/reconcile/validator/ValidatorBuilder.java deleted file mode 100644 index 411f084bd6..0000000000 --- a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/reconcile/validator/ValidatorBuilder.java +++ /dev/null @@ -1,139 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 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 - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.sse.ui.internal.reconcile.validator; - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.core.runtime.IExtensionRegistry; -import org.eclipse.core.runtime.Platform; -import org.eclipse.wst.sse.ui.internal.Logger; -import org.eclipse.wst.sse.ui.internal.extension.RegistryReader; - - -/** - * Based off of TransferBuilder. Reads the extension point for - * <code>org.eclipse.wst.sse.ui.extensions.sourcevalidation</code> - */ -public class ValidatorBuilder extends RegistryReader { - - public static final String ATT_CLASS = "class"; //$NON-NLS-1$ - public static final String ATT_ID = "id"; //$NON-NLS-1$ - public static final String ATT_SCOPE = "scope"; //$NON-NLS-1$ - - public static final ValidatorMetaData[] EMTPY_VMD_ARRAY = new ValidatorMetaData[0]; - - // extension point ID - public static final String PL_SOURCE_VALIDATION = "sourcevalidation"; //$NON-NLS-1$ - - public static final String PLUGIN_ID = "org.eclipse.wst.sse.ui"; //$NON-NLS-1$ - public static final String TAG_CONTENT_TYPE_IDENTIFIER = "contentTypeIdentifier"; //$NON-NLS-1$ - public static final String TAG_PARTITION_TYPE = "partitionType"; //$NON-NLS-1$ - - public static final String TAG_VALIDATOR = "validator"; //$NON-NLS-1$ - - public static final String TRACE_FILTER = "reconcile_validator"; //$NON-NLS-1$ - - public static final String TRUE = "true"; //$NON-NLS-1$ - private String fCurrentCTID; - private ValidatorMetaData fCurrentVMD = null; - private List fVmds = new ArrayList(); - protected String targetContributionTag; - protected String targetID; - - private final String UNKNOWN = "???"; //$NON-NLS-1$ - - /** - * Returns the name of the part ID attribute that is expected in the - * target extension. - * - * @param element - * @return String - */ - protected String getID(IConfigurationElement element) { - String value = element.getAttribute(ATT_ID); - return value != null ? value : UNKNOWN; //$NON-NLS-1$ - } - - protected String getValidatorClass(IConfigurationElement element) { - String value = element.getAttribute(ATT_CLASS); - return value != null ? value : UNKNOWN; //$NON-NLS-1$ - } - - /** - * @param editorId - * @return Transfer[] - */ - public ValidatorMetaData[] getValidatorMetaData(String editorId) { - readContributions(editorId, TAG_VALIDATOR, PL_SOURCE_VALIDATION); - return (ValidatorMetaData[]) fVmds.toArray(new ValidatorMetaData[fVmds.size()]); - } - - protected String getValidatorScope(IConfigurationElement element) { - String value = element.getAttribute(ATT_SCOPE); - return value != null ? value : UNKNOWN; //$NON-NLS-1$ - } - - /** - * Reads the contributions from the registry for the provided workbench - * part and the provided extension point ID. - * - * @param id - * @param tag - * @param extensionPoint - */ - protected void readContributions(String id, String tag, String extensionPoint) { - targetID = id; - targetContributionTag = tag; - IExtensionRegistry registry = Platform.getExtensionRegistry(); - readRegistry(registry, PLUGIN_ID, extensionPoint); - } - - protected boolean readElement(IConfigurationElement element) { - String tag = element.getName(); - //ie. targetContributionTag == validator - if (tag.equals(targetContributionTag)) { - String vId = getID(element); - String vClass = getValidatorClass(element); - String vScope = getValidatorScope(element); - - if (vId == null) { - // This is not of interest to us - don't go deeper - return true; - } - // start building a VMD - fCurrentVMD = new ValidatorMetaData(element, vId, vClass, vScope); - fVmds.add(fCurrentVMD); - - if (Logger.isTracing(ValidatorBuilder.TRACE_FILTER)) - System.out.println("added reconcile validator: " + vId + ":" + vClass + ":" + vScope); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - } else if (tag.equals(TAG_CONTENT_TYPE_IDENTIFIER)) { - // add to current VMD - fCurrentCTID = getID(element); - fCurrentVMD.addContentTypeId(fCurrentCTID); - } else if (tag.equals(TAG_PARTITION_TYPE)) { - // add to current VMD - String partitionType = getID(element); - fCurrentVMD.addParitionType(fCurrentCTID, partitionType); - - return true; - } else { - return false; - } - - readElementChildren(element); - return true; - } -} - diff --git a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/reconcile/validator/ValidatorMetaData.java b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/reconcile/validator/ValidatorMetaData.java deleted file mode 100644 index b5bc89bf57..0000000000 --- a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/reconcile/validator/ValidatorMetaData.java +++ /dev/null @@ -1,220 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 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 - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.sse.ui.internal.reconcile.validator; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.core.runtime.Platform; -import org.eclipse.core.runtime.content.IContentType; -import org.eclipse.core.runtime.content.IContentTypeManager; -import org.eclipse.swt.custom.BusyIndicator; -import org.eclipse.wst.sse.ui.internal.Logger; -import org.eclipse.wst.sse.ui.internal.reconcile.ReconcileAnnotationKey; -import org.eclipse.wst.validation.internal.provisional.core.IValidator; -import org.osgi.framework.Bundle; - - -/** - * Object that holds information relevant to the creation of a validator for - * the reconciling framework. - * - * @author pavery - */ -public class ValidatorMetaData { - private String fClass = null; - private IConfigurationElement fConfigurationElement = null; - private String fId = null; - private String fScope; - - // a hash map of content type Ids (String) that points to lists of - // partition types (List of Strings) - // contentTypeId -> List(paritionType, paritionType, partitionType, ...) - // contentTypeId2 -> List(partitionType, partitionType, ...) - // ... - private HashMap fMatrix = null; - - public ValidatorMetaData(IConfigurationElement element, String vId, String vClass, String vScope) { - fId = vId; - fClass = vClass; - fConfigurationElement = element; - fScope = vScope; - fMatrix = new HashMap(); - } - - /** - * TODO: This exact method is also in ValidatorStrategy. Should be in a common place. - * - * @param contentTypeId - * @return - */ - private String[] calculateParentContentTypeIds(String contentTypeId) { - - Set parentTypes = new HashSet(); - - IContentTypeManager ctManager = Platform.getContentTypeManager(); - IContentType ct = ctManager.getContentType(contentTypeId); - String id = contentTypeId; - - while(ct != null && id != null) { - - parentTypes.add(id); - ct = ctManager.getContentType(id); - if(ct != null) { - IContentType baseType = ct.getBaseType(); - id = (baseType != null) ? baseType.getId() : null; - } - } - return (String[])parentTypes.toArray(new String[parentTypes.size()]); - } - - public void addContentTypeId(String contentTypeId) { - if (!fMatrix.containsKey(contentTypeId)) - fMatrix.put(contentTypeId, new ArrayList()); - } - - public void addParitionType(String contentTypeId, String partitionType) { - if (!fMatrix.containsKey(contentTypeId)) - fMatrix.put(contentTypeId, new ArrayList()); - - List partitionList = (List) fMatrix.get(contentTypeId); - partitionList.add(partitionType); - } - - public boolean canHandleContentType(String contentType) { - // need to iterate hierarchy - String[] contentHierarchy = calculateParentContentTypeIds(contentType); - for (int i = 0; i < contentHierarchy.length; i++) { - if(fMatrix.containsKey(contentHierarchy[i])) - return true; - } - return false; - } - - public boolean canHandlePartitionType(String contentTypeIds[], String paritionType) { - for(int i=0; i<contentTypeIds.length; i++) { - if (fMatrix.containsKey(contentTypeIds[i])) { - List partitions = (List) fMatrix.get(contentTypeIds[i]); - for (int j = 0; j < partitions.size(); j++) { - if (paritionType.equals(partitions.get(j))) - return true; - } - } - } - return false; - } - - /** - * @param element - * @param classAttribute - * @return Object - * @throws CoreException - */ - Object createExecutableExtension(final IConfigurationElement element, final String classAttribute) throws CoreException { - Object obj = null; - obj = element.createExecutableExtension(classAttribute); - return obj; - } - - /** - * Creates an extension. If the extension plugin has not been loaded a - * busy cursor will be activated during the duration of the load. - * - * @param element - * @param classAttribute - * @return Object - * @throws CoreException - */ - public Object createExtension() { - // If plugin has been loaded create extension. - // Otherwise, show busy cursor then create extension. - final IConfigurationElement element = getConfigurationElement(); - final Object[] result = new Object[1]; - String pluginId = element.getDeclaringExtension().getNamespace(); - Bundle bundle = Platform.getBundle(pluginId); - if (bundle.getState() == Bundle.ACTIVE) { - try { - return createExecutableExtension(element, "class"); //$NON-NLS-1$ - } catch (CoreException e) { - handleCreateExecutableException(result, e); - } - } else { - BusyIndicator.showWhile(null, new Runnable() { - public void run() { - try { - result[0] = createExecutableExtension(element, "class"); //$NON-NLS-1$ - } catch (Exception e) { - handleCreateExecutableException(result, e); - } - } - }); - } - return result[0]; - } - - /** - * @return a validator instance based on this ValidatorMetaData instance - */ - public IValidator createValidator() { - Object obj = null; - obj = createExtension(); - if (obj == null) { - return null; - } - return (obj instanceof IValidator) ? (IValidator) obj : null; - } - - public IConfigurationElement getConfigurationElement() { - return fConfigurationElement; - } - - public String getValidatorClass() { - return fClass; - } - - public String getValidatorId() { - return fId; - } - - /** - * @param result - * @param e - */ - void handleCreateExecutableException(Object[] result, Throwable e) { - Logger.logException(e); - e.printStackTrace(); - result[0] = null; - } - /** - * ReconcileAnnotationKey.TOTAL or ReconcileAnnotationKey.PARTIAL - * @return - */ - public int getValidatorScope() { - return fScope.equalsIgnoreCase("total") ? ReconcileAnnotationKey.TOTAL : ReconcileAnnotationKey.PARTIAL; //$NON-NLS-1$ - } - - /** - * @see java.lang.Object#toString() - */ - public String toString() { - StringBuffer debugString = new StringBuffer("ValidatorMetaData:"); //$NON-NLS-1$ - if (fId != null) - debugString.append(" [id:" + fId + "]"); //$NON-NLS-1$ //$NON-NLS-2$ - return debugString.toString(); - } -} diff --git a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/reconcile/validator/ValidatorStrategy.java b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/reconcile/validator/ValidatorStrategy.java deleted file mode 100644 index 31fdfb8db0..0000000000 --- a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/reconcile/validator/ValidatorStrategy.java +++ /dev/null @@ -1,325 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 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 - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.sse.ui.internal.reconcile.validator; - -import java.lang.reflect.InvocationTargetException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Set; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.Platform; -import org.eclipse.core.runtime.content.IContentType; -import org.eclipse.core.runtime.content.IContentTypeManager; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.ITypedRegion; -import org.eclipse.jface.text.reconciler.DirtyRegion; -import org.eclipse.jface.text.reconciler.IReconcileResult; -import org.eclipse.jface.text.reconciler.IReconcileStep; -import org.eclipse.jface.text.source.ISourceViewer; -import org.eclipse.wst.sse.core.StructuredModelManager; -import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; -import org.eclipse.wst.sse.ui.internal.IReleasable; -import org.eclipse.wst.sse.ui.internal.Logger; -import org.eclipse.wst.sse.ui.internal.reconcile.DocumentAdapter; -import org.eclipse.wst.sse.ui.internal.reconcile.ReconcileAnnotationKey; -import org.eclipse.wst.sse.ui.internal.reconcile.StructuredTextReconcilingStrategy; -import org.eclipse.wst.sse.ui.internal.reconcile.TemporaryAnnotation; -import org.eclipse.wst.validation.internal.ConfigurationManager; -import org.eclipse.wst.validation.internal.ProjectConfiguration; -import org.eclipse.wst.validation.internal.ValidationRegistryReader; -import org.eclipse.wst.validation.internal.provisional.core.IValidator; - - -/** - * Special validator strategy. Runs validator steps contributed via the - * <code>org.eclipse.wst.sse.ui.extensions.sourcevalidation</code> extension - * point - * - * @author pavery - */ -public class ValidatorStrategy extends StructuredTextReconcilingStrategy { - - private String[] fContentTypeIds = null; - private List fMetaData = null; - /** validator id (as declared in ext point) -> ReconcileStepForValidator * */ - private HashMap fVidToVStepMap = null; - private ProjectConfiguration fProjectConfiguration = null; - - /* - * List of ValidatorMetaDatas of total scope validators that have been run - * since beginProcessing() was called. - */ - private List fTotalScopeValidatorsAlreadyRun; - - public ValidatorStrategy(ISourceViewer sourceViewer, String contentType) { - super(sourceViewer); - fMetaData = new ArrayList(); - fContentTypeIds = calculateParentContentTypeIds(contentType); - fVidToVStepMap = new HashMap(); - } - - public void addValidatorMetaData(ValidatorMetaData vmd) { - fMetaData.add(vmd); - } - - public void beginProcessing() { - if (fTotalScopeValidatorsAlreadyRun == null) - fTotalScopeValidatorsAlreadyRun = new ArrayList(); - } - - /** - * The content type passed in should be the most specific one. TODO: This - * exact method is also in ValidatorMetaData. Should be in a common place. - * - * @param contentType - * @return - */ - private String[] calculateParentContentTypeIds(String contentTypeId) { - - Set parentTypes = new HashSet(); - - IContentTypeManager ctManager = Platform.getContentTypeManager(); - IContentType ct = ctManager.getContentType(contentTypeId); - String id = contentTypeId; - - while (ct != null && id != null) { - - parentTypes.add(id); - ct = ctManager.getContentType(id); - if (ct != null) { - IContentType baseType = ct.getBaseType(); - id = (baseType != null) ? baseType.getId() : null; - } - } - return (String[]) parentTypes.toArray(new String[parentTypes.size()]); - } - - protected boolean canHandlePartition(String partitionType) { - ValidatorMetaData vmd = null; - for (int i = 0; i < fMetaData.size(); i++) { - vmd = (ValidatorMetaData) fMetaData.get(i); - if (vmd.canHandlePartitionType(getContentTypeIds(), partitionType)) - return true; - } - return false; - } - - protected boolean containsStep(IReconcileStep step) { - return fVidToVStepMap.containsValue(step); - } - - /** - * @see org.eclipse.wst.sse.ui.internal.provisional.reconcile.AbstractStructuredTextReconcilingStrategy#createReconcileSteps() - */ - public void createReconcileSteps() { - // do nothing, steps are created - } - - public void endProcessing() { - fTotalScopeValidatorsAlreadyRun.clear(); - } - - /** - * All content types on which this ValidatorStrategy can run - * - * @return - */ - public String[] getContentTypeIds() { - return fContentTypeIds; - } - - /** - * @param tr - * Partition of the region to reconcile. - * @param dr - * Dirty region representation of the typed region - */ - public void reconcile(ITypedRegion tr, DirtyRegion dr) { - - if (isCanceled()) - return; - - IDocument doc = getDocument(); - // for external files, this can be null - if (doc == null) - return; - - String partitionType = tr.getType(); - - ValidatorMetaData vmd = null; - List annotationsToAdd = new ArrayList(); - List stepsRanOnThisDirtyRegion = new ArrayList(1); - /* - * Loop through all of the relevant validator meta data to find - * supporting validators for this partition type. Don't check - * this.canHandlePartition() before-hand since it just loops through - * and calls vmd.canHandlePartitionType()...which we're already doing - * here anyway to find the right vmd. - */ - for (int i = 0; i < fMetaData.size() && !isCanceled(); i++) { - vmd = (ValidatorMetaData) fMetaData.get(i); - if (vmd.canHandlePartitionType(getContentTypeIds(), partitionType)) { - /* - * Check if validator is enabled according to validation - * preferences before attempting to create/use it - */ - if (isValidatorEnabled(vmd)) { - int validatorScope = vmd.getValidatorScope(); - ReconcileStepForValidator validatorStep = null; - // get step for partition type - Object o = fVidToVStepMap.get(vmd.getValidatorId()); - if (o != null) { - validatorStep = (ReconcileStepForValidator) o; - } - else { - // if doesn't exist, create one - IValidator validator = vmd.createValidator(); - - validatorStep = new ReconcileStepForValidator(validator, validatorScope); - validatorStep.setInputModel(new DocumentAdapter(doc)); - - fVidToVStepMap.put(vmd.getValidatorId(), validatorStep); - } - - if (!fTotalScopeValidatorsAlreadyRun.contains(vmd)) { - annotationsToAdd.addAll(Arrays.asList(validatorStep.reconcile(dr, dr))); - stepsRanOnThisDirtyRegion.add(validatorStep); - - if (validatorScope == ReconcileAnnotationKey.TOTAL) { - // mark this validator as "run" - fTotalScopeValidatorsAlreadyRun.add(vmd); - } - } - } - } - } - - TemporaryAnnotation[] annotationsToRemove = getAnnotationsToRemove(dr, stepsRanOnThisDirtyRegion); - if (annotationsToRemove.length + annotationsToAdd.size() > 0) - smartProcess(annotationsToRemove, (IReconcileResult[]) annotationsToAdd.toArray(new IReconcileResult[annotationsToAdd.size()])); - } - - public void release() { - super.release(); - Iterator it = fVidToVStepMap.values().iterator(); - IReconcileStep step = null; - while (it.hasNext()) { - step = (IReconcileStep) it.next(); - if (step instanceof IReleasable) - ((IReleasable) step).release(); - } - } - - /** - * @see org.eclipse.wst.sse.ui.internal.reconcile.AbstractStructuredTextReconcilingStrategy#setDocument(org.eclipse.jface.text.IDocument) - */ - public void setDocument(IDocument document) { - - super.setDocument(document); - - // validator steps are in "fVIdToVStepMap" (as opposed to fFirstStep > - // next step etc...) - Iterator it = fVidToVStepMap.values().iterator(); - IReconcileStep step = null; - while (it.hasNext()) { - step = (IReconcileStep) it.next(); - step.setInputModel(new DocumentAdapter(document)); - } - } - - /** - * Checks if validator is enabled according to Validation preferences - * - * @param vmd - * @return - */ - private boolean isValidatorEnabled(ValidatorMetaData vmd) { - boolean enabled = true; - ProjectConfiguration configuration = getProjectConfiguration(); - org.eclipse.wst.validation.internal.ValidatorMetaData metadata = ValidationRegistryReader.getReader().getValidatorMetaData(vmd.getValidatorClass()); - if (configuration != null && metadata != null) { - if (!configuration.isBuildEnabled(metadata) && !configuration.isManualEnabled(metadata)) - enabled = false; - } - return enabled; - } - - /** - * Gets current validation project configuration based on current project - * (which is based on current document) - * - * @return ProjectConfiguration - */ - private ProjectConfiguration getProjectConfiguration() { - if (fProjectConfiguration == null) { - IFile file = getFile(); - if (file != null) { - IProject project = file.getProject(); - if (project != null) { - try { - fProjectConfiguration = ConfigurationManager.getManager().getProjectConfiguration(project); - } - catch (InvocationTargetException e) { - Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e); - } - } - } - } - - return fProjectConfiguration; - } - - /** - * Gets IFile from current document - * - * @return IFile the IFile, null if no such file exists - */ - private IFile getFile() { - IStructuredModel model = null; - IFile file = null; - try { - model = StructuredModelManager.getModelManager().getExistingModelForRead(getDocument()); - if (model != null) { - String baseLocation = model.getBaseLocation(); - // The baseLocation may be a path on disk or relative to the - // workspace root. Don't translate on-disk paths to - // in-workspace resources. - IPath basePath = new Path(baseLocation); - if (basePath.segmentCount() > 1) { - file = ResourcesPlugin.getWorkspace().getRoot().getFile(basePath); - /* - * If the IFile doesn't exist, make sure it's not - * returned - */ - if (!file.exists()) - file = null; - } - } - } - finally { - if (model != null) { - model.releaseFromRead(); - } - } - return file; - } -} |