1 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 ; 29 import java.util.List ; 30 import org.netbeans.jmi.javamodel.JavaModelPackage; 31 32 36 public abstract class ClassExpressionImpl extends ExpressionImpl implements ClassExpression { 37 private TypeReference className; 38 private Type type; 39 40 41 public ClassExpressionImpl(StorableObject o) { 42 super(o); 43 type = ((JavaModelPackage) refImmediatePackage()).getType().resolve("java.lang.Class"); } 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."); } 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 getChildren() { 77 List result = new ArrayList (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 getSourceText() { 92 String origElem; 93 if ((origElem = checkChange()) != null) 94 return origElem; 95 return ((MetadataElement) getClassName()).getSourceText() + ".class"; } 97 98 public void getDiff(List diff) { 99 getChildDiff(diff, getParser(), getASTree().getSubTrees()[0], (MetadataElement) getClassName(), CHANGED_CLASS_NAME); 100 } 101 102 protected void _delete() { 103 if (childrenInited) { 105 deleteChild(className); 106 } 107 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 |