diff org.eclipse.jface.text/src/org/eclipse/jface/text/reconciler/DirtyRegion.d @ 12:bc29606a740c

Added dwt-addons in original directory structure of eclipse.org
author Frank Benoit <benoit@tionex.de>
date Sat, 14 Mar 2009 18:23:29 +0100
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/reconciler/DirtyRegion.d	Sat Mar 14 18:23:29 2009 +0100
@@ -0,0 +1,131 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2005 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
+ * Port to the D programming language:
+ *     Frank Benoit <benoit@tionex.de>
+ *******************************************************************************/
+module org.eclipse.jface.text.reconciler.DirtyRegion;
+
+import org.eclipse.jface.text.reconciler.IReconciler; // packageimport
+import org.eclipse.jface.text.reconciler.DirtyRegionQueue; // packageimport
+import org.eclipse.jface.text.reconciler.IReconcilingStrategy; // packageimport
+import org.eclipse.jface.text.reconciler.AbstractReconcileStep; // packageimport
+import org.eclipse.jface.text.reconciler.IReconcilingStrategyExtension; // packageimport
+import org.eclipse.jface.text.reconciler.MonoReconciler; // packageimport
+import org.eclipse.jface.text.reconciler.IReconcileStep; // packageimport
+import org.eclipse.jface.text.reconciler.AbstractReconciler; // packageimport
+import org.eclipse.jface.text.reconciler.Reconciler; // packageimport
+import org.eclipse.jface.text.reconciler.IReconcilableModel; // packageimport
+import org.eclipse.jface.text.reconciler.IReconcileResult; // packageimport
+import org.eclipse.jface.text.reconciler.IReconcilerExtension; // packageimport
+
+
+import java.lang.all;
+import java.util.Set;
+
+import org.eclipse.jface.text.ITypedRegion;
+
+
+/**
+ * A dirty region describes a document range which has been changed.
+ */
+public class DirtyRegion : ITypedRegion {
+
+    /**
+     * Identifies an insert operation.
+     */
+    final static public String INSERT= "__insert"; //$NON-NLS-1$
+    /**
+     * Identifies a remove operation.
+     */
+    final static public String REMOVE= "__remove"; //$NON-NLS-1$
+
+    /** The region's offset. */
+    private int fOffset;
+    /** The region's length. */
+    private int fLength;
+    /** Indicates the type of the applied change. */
+    private String fType;
+    /** The text which has been inserted. */
+    private String fText;
+
+    /**
+     * Creates a new dirty region.
+     *
+     * @param offset the offset within the document where the change occurred
+     * @param length the length of the text within the document that changed
+     * @param type the type of change that this region represents: {@link #INSERT} {@link #REMOVE}
+     * @param text the substitution text
+     */
+    public this(int offset, int length, String type, String text) {
+        fOffset= offset;
+        fLength= length;
+        fType= normalizeTypeValue(type);
+        fText= text;
+    }
+
+    /**
+     * Computes the normalized type value to ensure that the implementation can use object identity rather
+     * than equality.
+     *
+     * @param type the type value
+     * @return the normalized type value or <code>null</code>
+     * @since 3.1
+     */
+    private String normalizeTypeValue(String type) {
+        if (INSERT.equals(type))
+            return INSERT;
+        if (REMOVE.equals(type))
+            return REMOVE;
+        return null;
+    }
+
+    /*
+     * @see ITypedRegion#getOffset()
+     */
+    public int getOffset() {
+        return fOffset;
+    }
+
+    /*
+     * @see ITypedRegion#getLength()
+     */
+    public int getLength() {
+        return fLength;
+    }
+
+    /*
+     * @see ITypedRegion#getType
+     */
+    public String getType() {
+        return fType;
+    }
+
+    /**
+     * Returns the text that changed as part of the region change.
+     *
+     * @return the changed text
+     */
+    public String getText() {
+        return fText;
+    }
+
+    /**
+     * Modify the receiver so that it encompasses the region specified by the dirty region.
+     *
+     * @param dr the dirty region with which to merge
+     */
+    void mergeWith(DirtyRegion dr) {
+        int start= Math.min(fOffset, dr.fOffset);
+        int end= Math.max(fOffset + fLength, dr.fOffset + dr.fLength);
+        fOffset= start;
+        fLength= end - start;
+        fText= (dr.fText is null ? fText : (fText is null) ? dr.fText : fText ~ dr.fText);
+    }
+}