KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > core > SimpleDelta


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.core;
12
13 import org.eclipse.jdt.core.IJavaElementDelta;
14
15 /**
16  * A simple Java element delta that remembers the kind of changes only.
17  */

18 public class SimpleDelta {
19
20     /*
21      * @see IJavaElementDelta#getKind()
22      */

23     protected int kind = 0;
24     
25     /*
26      * @see IJavaElementDelta#getFlags()
27      */

28     protected int changeFlags = 0;
29     
30     /*
31      * Marks this delta as added
32      */

33     public void added() {
34         this.kind = IJavaElementDelta.ADDED;
35     }
36     
37     /*
38      * Marks this delta as changed with the given change flag
39      */

40     public void changed(int flags) {
41         this.kind = IJavaElementDelta.CHANGED;
42         this.changeFlags |= flags;
43     }
44     
45     /*
46      * @see IJavaElementDelta#getFlags()
47      */

48     public int getFlags() {
49         return this.changeFlags;
50     }
51     
52     /*
53      * @see IJavaElementDelta#getKind()
54      */

55     public int getKind() {
56         return this.kind;
57     }
58
59     /*
60      * Mark this delta has a having a modifiers change
61      */

62     public void modifiers() {
63         changed(IJavaElementDelta.F_MODIFIERS);
64     }
65
66     /*
67      * Marks this delta as removed
68      */

69     public void removed() {
70         this.kind = IJavaElementDelta.REMOVED;
71         this.changeFlags = 0;
72     }
73     
74     /*
75      * Mark this delta has a having a super type change
76      */

77     public void superTypes() {
78         changed(IJavaElementDelta.F_SUPER_TYPES);
79     }
80
81     protected void toDebugString(StringBuffer JavaDoc buffer) {
82         buffer.append("["); //$NON-NLS-1$
83
switch (getKind()) {
84             case IJavaElementDelta.ADDED :
85                 buffer.append('+');
86                 break;
87             case IJavaElementDelta.REMOVED :
88                 buffer.append('-');
89                 break;
90             case IJavaElementDelta.CHANGED :
91                 buffer.append('*');
92                 break;
93             default :
94                 buffer.append('?');
95                 break;
96         }
97         buffer.append("]: {"); //$NON-NLS-1$
98
toDebugString(buffer, getFlags());
99         buffer.append("}"); //$NON-NLS-1$
100
}
101
102     protected boolean toDebugString(StringBuffer JavaDoc buffer, int flags) {
103         boolean prev = false;
104         if ((flags & IJavaElementDelta.F_MODIFIERS) != 0) {
105             if (prev)
106                 buffer.append(" | "); //$NON-NLS-1$
107
buffer.append("MODIFIERS CHANGED"); //$NON-NLS-1$
108
prev = true;
109         }
110         if ((flags & IJavaElementDelta.F_SUPER_TYPES) != 0) {
111             if (prev)
112                 buffer.append(" | "); //$NON-NLS-1$
113
buffer.append("SUPER TYPES CHANGED"); //$NON-NLS-1$
114
prev = true;
115         }
116         return prev;
117     }
118
119     public String JavaDoc toString() {
120         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
121         toDebugString(buffer);
122         return buffer.toString();
123     }
124 }
125
Popular Tags