KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.netbeans.jmi.javamodel.Element;
23 import org.netbeans.jmi.javamodel.MultipartId;
24 import org.netbeans.jmi.javamodel.ThisExpression;
25 import org.netbeans.lib.java.parser.ASTree;
26 import org.netbeans.mdr.storagemodel.StorableObject;
27 import java.util.List JavaDoc;
28 import org.netbeans.jmi.javamodel.JavaModelPackage;
29
30 /**
31  *
32  * @author Martin Matula
33  */

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