1 19 package org.netbeans.modules.javacore.jmiimpl.javamodel; 20 21 import java.util.*; 22 import org.netbeans.jmi.javamodel.Element; 23 import org.netbeans.jmi.javamodel.ExpressionStatement; 24 import org.netbeans.jmi.javamodel.Expression; 25 import org.netbeans.jmi.javamodel.JavaModelPackage; 26 import org.netbeans.lib.java.parser.ASTree; 27 import org.netbeans.mdr.storagemodel.StorableObject; 28 import org.netbeans.modules.javacore.parser.ASTProvider; 29 30 34 public abstract class ExpressionStatementImpl extends StatementImpl implements ExpressionStatement { 35 private Expression expression = null; 36 37 38 public ExpressionStatementImpl(StorableObject o) { 39 super(o); 40 } 41 42 protected String getIndentation() { 43 return ((MetadataElement) refImmediateComposite()).getIndentation().concat(INDENTATION); 44 } 45 46 public void setExpression(Expression expression) { 47 objectChanged(CHANGED_EXPRESSION); 48 changeChild(getExpression(), expression); 49 this.expression = expression; 50 } 51 52 public Expression getExpression() { 53 if (!childrenInited) { 54 initChildren(); 55 } 56 return expression; 57 } 58 59 public List getChildren() { 60 List list = new ArrayList(1); 61 addIfNotNull(list, getExpression()); 62 return list; 63 } 64 65 protected void initChildren() { 66 childrenInited = false; 67 ASTree tree = getASTree(); 68 if (tree != null) { 69 expression = (Expression) initOrCreate(expression, tree.getSubTrees()[0]); 70 } 71 childrenInited = true; 72 } 73 74 String getRawText() { 75 StringBuffer buf = new StringBuffer (); 76 StatementImpl expr = (StatementImpl) getExpression(); 77 buf.append(expr.getSourceText()); 78 buf.append(";"); return buf.toString(); 80 } 81 82 public void getDiff(List diff) { 83 ASTProvider parser = getParser(); 84 ASTree tree = getASTree(); 85 ASTree[] children = tree.getSubTrees(); 86 87 getChildDiff(diff, parser, children[0], (MetadataElement) getExpression(), CHANGED_EXPRESSION); 88 } 89 90 void setData(Expression expression) { 91 changeChild(null, expression); 92 this.expression = expression; 93 } 94 95 protected void _delete() { 96 if (childrenInited) { 98 deleteChild(expression); 99 } 100 super._delete(); 104 } 105 106 public void replaceChild(Element oldElement,Element newElement) { 107 if (childrenInited) { 108 if (oldElement.equals(expression)) { 109 setExpression((Expression)newElement); 110 } 111 } 112 } 113 114 public Element duplicate(JavaModelPackage targetExtent) { 115 return targetExtent.getExpressionStatement().createExpressionStatement( 116 (Expression) duplicateElement(getExpression(), targetExtent)); 117 } 118 } 119 | Popular Tags |