1 19 package org.netbeans.modules.javacore.jmiimpl.javamodel; 20 21 import java.util.ArrayList ; 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 ; 28 import org.netbeans.jmi.javamodel.JavaModelPackage; 29 30 34 public abstract class ThisExpressionImpl extends ExpressionImpl implements ThisExpression { 35 private MultipartId className; 36 37 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 getChildren() { 56 List result = new ArrayList (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 getSourceText() { 75 String origElem; 76 if ((origElem = checkChange()) != null) 77 return origElem; 78 StringBuffer buf = new StringBuffer (); 79 MetadataElement parentClass = (MetadataElement) getClassName(); 80 if (parentClass != null) { 81 buf.append(parentClass.getSourceText()); 82 buf.append("."); } 84 buf.append("this"); return buf.toString(); 86 } 87 88 public void getDiff(List 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 if (childrenInited) { 100 deleteChild(className); 101 } 102 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 |