fix #774 infinite loop in net.sourceforge.phpeclipse.builder.IdentifierIndexManager...
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / ui / text / TypingRun.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2003 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  *
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11 package net.sourceforge.phpdt.internal.ui.text;
12
13 /**
14  * Describes a run of similar typing changes.
15  * <p>
16  * XXX to be extended with further information, e.g. offset, length, and content
17  * of the run.
18  * </p>
19  * 
20  * @since 3.0
21  */
22 public final class TypingRun {
23         /**
24          * A change of type <code>DELETE</code> deletes one single character
25          * (through delete or backspace or empty paste).
26          */
27         public static final ChangeType DELETE = new ChangeType(true, "DELETE"); //$NON-NLS-1$
28
29         /**
30          * A change of type <code>INSERT</code> inserts one single character
31          * (normal typing).
32          */
33         public static final ChangeType INSERT = new ChangeType(true, "INSERT"); //$NON-NLS-1$
34
35         /**
36          * A change of type <code>NO_CHANGE</code> does not change anything.
37          */
38         public static final ChangeType NO_CHANGE = new ChangeType(false,
39                         "NO_CHANGE"); //$NON-NLS-1$
40
41         /**
42          * A change of type <code>OVERTYPE</code> replaces one single character
43          * (overwrite mode, pasting a single character).
44          */
45         public static final ChangeType OVERTYPE = new ChangeType(true, "OVERTYPE"); //$NON-NLS-1$
46
47         /**
48          * A change of type <code>SELECTION</code> does not change text, but
49          * changes the focus, or selection. Such a change ends all typing runs.
50          */
51         public static final ChangeType SELECTION = new ChangeType(false,
52                         "SELECTION"); //$NON-NLS-1$
53
54         /**
55          * A change of type <code>UNKNOWN</code> modifies text in an unspecified
56          * way. An example is pasting more than one character, or deleting an entire
57          * selection, or reverting a file. Such a change ends all typing runs and
58          * cannot form a typing run with any other change, including a change of
59          * type <code>UNKNOWN</code>.
60          */
61         public static final ChangeType UNKNOWN = new ChangeType(true, "UNKNOWN"); //$NON-NLS-1$
62
63         /**
64          * Enumeration of change types.
65          * 
66          * @since 3.0
67          */
68         public static final class ChangeType {
69                 private final boolean fIsModification;
70
71                 private final String fName;
72
73                 /** Private ctor for type safe enumeration. */
74                 private ChangeType(boolean isRunPart, String name) {
75                         fIsModification = isRunPart;
76                         fName = name;
77                 }
78
79                 /**
80                  * Returns <code>true</code> if changes of this type modify text.
81                  * 
82                  * @return <code>true</code> if changes of this type modify text,
83                  *         <code>false</code> otherwise
84                  */
85                 boolean isModification() {
86                         return fIsModification;
87                 }
88
89                 /*
90                  * @see java.lang.Object#toString()
91                  */
92                 public String toString() {
93                         return fName;
94                 }
95         }
96
97         /**
98          * Creates a new run.
99          * 
100          * @param type
101          *            the type of the run
102          */
103         TypingRun(ChangeType type) {
104                 this.type = type;
105         }
106
107         /** The change type of this run. */
108         public final ChangeType type;
109 }