KickJava   Java API By Example, From Geeks To Geeks.

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


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.*;
22 import org.netbeans.jmi.javamodel.Element;
23 import org.netbeans.jmi.javamodel.ExpressionStatement;
24 import org.netbeans.jmi.javamodel.Expression;
25 import org.netbeans.jmi.javamodel.JavaModelPackage;
26 import org.netbeans.lib.java.parser.ASTree;
27 import org.netbeans.mdr.storagemodel.StorableObject;
28 import org.netbeans.modules.javacore.parser.ASTProvider;
29
30 /**
31  *
32  * @author Martin Matula
33  */

34 public abstract class ExpressionStatementImpl extends StatementImpl implements ExpressionStatement {
35     private Expression expression = null;
36     
37     /** Creates a new instance of ExpressionStatementImpl */
38     public ExpressionStatementImpl(StorableObject o) {
39         super(o);
40     }
41
42     protected String JavaDoc getIndentation() {
43         return ((MetadataElement) refImmediateComposite()).getIndentation().concat(INDENTATION);
44     }
45
46     public void setExpression(Expression expression) {
47         objectChanged(CHANGED_EXPRESSION);
48         changeChild(getExpression(), expression);
49         this.expression = expression;
50     }
51     
52     public Expression getExpression() {
53         if (!childrenInited) {
54             initChildren();
55         }
56         return expression;
57     }
58     
59     public List getChildren() {
60         List list = new ArrayList(1);
61         addIfNotNull(list, getExpression());
62         return list;
63     }
64
65     protected void initChildren() {
66         childrenInited = false;
67         ASTree tree = getASTree();
68         if (tree != null) {
69             expression = (Expression) initOrCreate(expression, tree.getSubTrees()[0]);
70         }
71         childrenInited = true;
72     }
73     
74     String JavaDoc getRawText() {
75         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
76         StatementImpl expr = (StatementImpl) getExpression();
77         buf.append(expr.getSourceText());
78         buf.append(";"); // NOI18N
79
return buf.toString();
80     }
81     
82     public void getDiff(List diff) {
83         ASTProvider parser = getParser();
84         ASTree tree = getASTree();
85         ASTree[] children = tree.getSubTrees();
86
87         getChildDiff(diff, parser, children[0], (MetadataElement) getExpression(), CHANGED_EXPRESSION);
88     }
89     
90     void setData(Expression expression) {
91         changeChild(null, expression);
92         this.expression = expression;
93     }
94
95     protected void _delete() {
96         // --- delete components -------------------------------------------
97
if (childrenInited) {
98             deleteChild(expression);
99         }
100         // --- delete links -----------------------------------------------
101
// no links to delete
102
// --- call super ---------------------------------------
103
super._delete();
104     }
105     
106     public void replaceChild(Element oldElement,Element newElement) {
107         if (childrenInited) {
108             if (oldElement.equals(expression)) {
109                 setExpression((Expression)newElement);
110             }
111         }
112     }
113     
114     public Element duplicate(JavaModelPackage targetExtent) {
115         return targetExtent.getExpressionStatement().createExpressionStatement(
116                 (Expression) duplicateElement(getExpression(), targetExtent));
117     }
118 }
119
Popular Tags