KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > core > dom > rewrite > NodeRewriteEvent


1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 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.dom.rewrite;
12
13
14
15 /**
16  *
17  */

18 public class NodeRewriteEvent extends RewriteEvent {
19     
20     private Object JavaDoc originalValue;
21     private Object JavaDoc newValue;
22         
23     public NodeRewriteEvent(Object JavaDoc originalValue, Object JavaDoc newValue) {
24         this.originalValue= originalValue;
25         this.newValue= newValue;
26     }
27             
28     /**
29      * @return Returns the new value.
30      */

31     public Object JavaDoc getNewValue() {
32         return this.newValue;
33     }
34     
35     /**
36      * @return Returns the original value.
37      */

38     public Object JavaDoc getOriginalValue() {
39         return this.originalValue;
40     }
41     
42     /* (non-Javadoc)
43      * @see org.eclipse.jdt.internal.corext.dom.RewriteEvent#getChangeKind()
44      */

45     public int getChangeKind() {
46         if (this.originalValue == this.newValue) {
47             return UNCHANGED;
48         }
49         if (this.originalValue == null) {
50             return INSERTED;
51         }
52         if (this.newValue == null) {
53             return REMOVED;
54         }
55         if (this.originalValue.equals(this.newValue)) {
56             return UNCHANGED;
57         }
58         return REPLACED;
59     }
60         
61
62     /* (non-Javadoc)
63      * @see org.eclipse.jdt.internal.corext.dom.RewriteEvent#isListRewrite()
64      */

65     public boolean isListRewrite() {
66         return false;
67     }
68
69     /*
70      * Sets a new value for the new node. Internal access only.
71      * @param newValue The new value to set.
72      */

73     public void setNewValue(Object JavaDoc newValue) {
74         this.newValue= newValue;
75     }
76
77     /* (non-Javadoc)
78      * @see org.eclipse.jdt.internal.corext.dom.RewriteEvent#getChildren()
79      */

80     public RewriteEvent[] getChildren() {
81         return null;
82     }
83     
84     /* (non-Javadoc)
85      * @see java.lang.Object#toString()
86      */

87     public String JavaDoc toString() {
88         StringBuffer JavaDoc buf= new StringBuffer JavaDoc();
89         switch (getChangeKind()) {
90         case INSERTED:
91             buf.append(" [inserted: "); //$NON-NLS-1$
92
buf.append(getNewValue());
93             buf.append(']');
94             break;
95         case REPLACED:
96             buf.append(" [replaced: "); //$NON-NLS-1$
97
buf.append(getOriginalValue());
98             buf.append(" -> "); //$NON-NLS-1$
99
buf.append(getNewValue());
100             buf.append(']');
101             break;
102         case REMOVED:
103             buf.append(" [removed: "); //$NON-NLS-1$
104
buf.append(getOriginalValue());
105             buf.append(']');
106             break;
107         default:
108             buf.append(" [unchanged]"); //$NON-NLS-1$
109
}
110         return buf.toString();
111     }
112     
113
114 }
115
Popular Tags