KickJava   Java API By Example, From Geeks To Geeks.

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


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