KickJava   Java API By Example, From Geeks To Geeks.

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


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

35 public abstract class AssertStatementImpl extends ConditionImpl implements AssertStatement {
36     private Expression detail = null;
37     
38     /** Creates a new instance of AssertStatementImpl */
39     public AssertStatementImpl(StorableObject o) {
40         super(o);
41     }
42     
43     public void setDetail(Expression detail) {
44         objectChanged(CHANGED_DETAIL);
45         changeChild(getDetail(), detail);
46         this.detail = detail;
47     }
48
49     public List JavaDoc getChildren() {
50         List JavaDoc list = super.getChildren();
51         addIfNotNull(list, getDetail());
52         return list;
53     }
54     
55     protected void initChildren() {
56         childrenInited = false;
57         ASTree tree = getASTree();
58         if (tree != null) {
59             ASTree[] parts = tree.getSubTrees();
60             expression = (Expression) initOrCreate(expression, parts[0]);
61             detail = (Expression) initOrCreate(detail, parts[1]);
62         }
63         childrenInited = true;
64     }
65     
66     public Expression getDetail() {
67         if (!childrenInited) {
68             initChildren();
69         }
70         return detail;
71     }
72     
73     public String JavaDoc getSourceText() {
74         String JavaDoc origElem;
75         if ((origElem = checkChange()) != null)
76             return origElem;
77         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
78         TransientElement cond = (TransientElement)getExpression();
79         TransientElement detail = (TransientElement)getDetail();
80         buf.append('\n');
81         formatElementPart(ASSERT_KEYWORD, buf);
82         buf.append(cond.getSourceText());
83         if (detail != null) {
84             buf.append(" : "); // NOI18N
85
buf.append(detail.getSourceText());
86         }
87         buf.append(';');
88         return buf.toString();
89     }
90     
91     public void getDiff(List JavaDoc diff) {
92         ASTProvider parser = getParser();
93         ASTree tree = getASTree();
94         ASTree[] children = tree.getSubTrees();
95         
96         getChildDiff(diff, parser, children[0], (TransientElement) getExpression(), CHANGED_EXPRESSION);
97         TransientElement detail = (TransientElement) getDetail();
98         getChildDiff(diff, parser, children[1], detail, CHANGED_DETAIL, parser.getToken(children[0].getLastToken()).getEndOffset(), " : "); // NOI18N
99
}
100     
101     void setData(Expression expression, Expression detail) {
102         changeChild(null, expression);
103         changeChild(null, detail);
104         this.expression = expression;
105         this.detail = detail;
106     }
107
108     protected void _delete() {
109         // --- delete components -------------------------------------------
110
if (childrenInited) {
111             deleteChild(detail);
112         }
113         // --- delete links -----------------------------------------------
114
// no links to delete
115
// --- call super ---------------------------------------
116
super._delete();
117     }
118     
119     public void replaceChild(Element oldElement,Element newElement) {
120         if (childrenInited) {
121             if (oldElement.equals(detail)) {
122                 setDetail((Expression)newElement);
123             } else
124                 super.replaceChild(oldElement,newElement);
125         }
126     }
127     
128     public Element duplicate(JavaModelPackage targetExtent) {
129         return targetExtent.getAssertStatement().createAssertStatement(
130                 (Expression) duplicateElement(getExpression(), targetExtent),
131                 (Expression) duplicateElement(getDetail(), targetExtent));
132     }
133 }
134
Popular Tags