KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > form > codestructure > AbstractCodeStatement


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
20 package org.netbeans.modules.form.codestructure;
21
22 import java.util.Iterator JavaDoc;
23
24 /**
25  * Abstract class providing common implementation of UsingCodeObject
26  * interface for further CodeStatement implementations. No other
27  * UsingCodeObject implementation for statement should be introduced.
28  *
29  * @author Tomas Pavek
30  */

31
32 abstract class AbstractCodeStatement implements CodeStatement {
33
34     protected CodeExpression parentExpression;
35
36     protected AbstractCodeStatement(CodeExpression parentExpression) {
37         this.parentExpression = parentExpression;
38     }
39
40     public CodeExpression getParentExpression() {
41         return parentExpression;
42     }
43
44     // --------
45
// UsingCodeObject implementation
46

47     // notifying about registering this object in used object
48
public void usageRegistered(UsedCodeObject usedObject) {
49     }
50
51     // notifying about removing the used object from structure
52
public boolean usedObjectRemoved(UsedCodeObject usedObject) {
53         return false;
54     }
55
56     public UsedCodeObject getDefiningObject() {
57         return getParentExpression();
58     }
59
60     public Iterator JavaDoc getUsedObjectsIterator() {
61         return new UsedObjectsIterator();
62     }
63
64     // --------
65

66     private class UsedObjectsIterator implements Iterator JavaDoc {
67         int index;
68         CodeExpression[] parameters;
69
70         UsedObjectsIterator() {
71             index = getParentExpression() != null ? -1 : 0;
72             parameters = getStatementParameters();
73             if (parameters == null)
74                 parameters = CodeStructure.EMPTY_PARAMS;
75         }
76
77         public boolean hasNext() {
78             return index < parameters.length;
79         }
80
81         public Object JavaDoc next() {
82             if (!hasNext())
83                 throw new java.util.NoSuchElementException JavaDoc();
84
85             Object JavaDoc obj = index > -1 ? parameters[index] : getParentExpression();
86             index++;
87             return obj;
88         }
89
90         public void remove() {
91             throw new UnsupportedOperationException JavaDoc();
92         }
93     }
94 }
95
Popular Tags