KickJava   Java API By Example, From Geeks To Geeks.

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


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 javax.jmi.reflect.ConstraintViolationException;
22 import org.netbeans.jmi.javamodel.ClassExpression;
23 import org.netbeans.jmi.javamodel.Element;
24 import org.netbeans.jmi.javamodel.Type;
25 import org.netbeans.jmi.javamodel.TypeReference;
26 import org.netbeans.lib.java.parser.ASTree;
27 import org.netbeans.mdr.storagemodel.StorableObject;
28 import java.util.ArrayList JavaDoc;
29 import java.util.List JavaDoc;
30 import org.netbeans.jmi.javamodel.JavaModelPackage;
31
32 /**
33  *
34  * @author Martin Matula
35  */

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