KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > javacore > jmiimpl > javamodel > GotoStatementImpl


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.modules.javacore.jmiimpl.javamodel;
20
21 import java.util.ArrayList JavaDoc;
22 import java.util.Collection JavaDoc;
23 import java.util.Collections JavaDoc;
24 import java.util.List JavaDoc;
25 import org.netbeans.jmi.javamodel.GotoStatement;
26 import org.netbeans.lib.java.parser.ASTree;
27 import org.netbeans.mdr.storagemodel.StorableObject;
28 import org.netbeans.modules.javacore.parser.ASTProvider;
29 import org.netbeans.modules.javacore.parser.ASTUtil;
30
31 /**
32  * Ancenstor of <code>break</code> and <code>continue</code> statements.
33  *
34  * @author Martin Matula
35  */

36 public abstract class GotoStatementImpl extends StatementImpl implements GotoStatement {
37     private String JavaDoc label = null;
38     
39     /** Creates a new instance of GotoStatementImpl */
40     public GotoStatementImpl(StorableObject o) {
41         super(o);
42     }
43     
44     public void setLabel(String JavaDoc label) {
45         objectChanged(CHANGED_LABEL);
46         this.label = label;
47     }
48     
49     public String JavaDoc getLabel() {
50         if (isChanged(CHANGED_LABEL)) {
51             return label;
52         } else {
53             return ASTUtil.getIdentifier(getASTree().getSubTrees()[0]);
54         }
55     }
56     
57     protected abstract String JavaDoc getStatementName();
58     
59     String JavaDoc getRawText() {
60         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
61         buf.append(getStatementName());
62         String JavaDoc label = getLabel();
63         if (label != null) {
64             buf.append(' ');
65             buf.append(label);
66         }
67         buf.append(';');
68         return buf.toString();
69     }
70
71     public void getDiff(List JavaDoc diff) {
72         ASTProvider parser = getParser();
73         ASTree tree = getASTree();
74         ASTree[] children = tree.getSubTrees();
75         
76         if (isChanged(CHANGED_LABEL)) {
77             replaceNode(diff, parser, children[0], getLabel(), parser.getToken(tree.getFirstToken()).getEndOffset(), " "); // NOI18N
78
}
79     }
80
81     void setData(String JavaDoc label) {
82         this.label = label;
83     }
84 }
85
Popular Tags