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.Expression; 24 import org.netbeans.jmi.javamodel.JavaModelPackage; 25 import org.netbeans.jmi.javamodel.ThrowStatement; 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 ThrowStatementImpl extends StatementImpl implements ThrowStatement { 35 private Expression expression = null; 36 37 38 public ThrowStatementImpl(StorableObject o) { 39 super(o); 40 } 41 42 public void setExpression(Expression expression) { 43 objectChanged(CHANGED_EXPRESSION); 44 changeChild(getExpression(), expression); 45 this.expression = expression; 46 } 47 48 public Expression getExpression() { 49 if (!childrenInited) { 50 initChildren(); 51 } 52 return expression; 53 } 54 55 public List getChildren() { 56 List list = new ArrayList(1); 57 addIfNotNull(list, getExpression()); 58 return list; 59 } 60 61 protected void initChildren() { 62 childrenInited = false; 63 ASTree tree = getASTree(); 64 if (tree != null) { 65 expression = (Expression) initOrCreate(expression, tree.getSubTrees()[0]); 66 } 67 childrenInited = true; 68 } 69 70 String getRawText() { 71 StringBuffer buf = new StringBuffer (); 72 StatementImpl expr = (StatementImpl) getExpression(); 73 formatElementPart(THROW_KEYWORD, buf); 74 buf.append(expr.getSourceText()); 75 buf.append(';'); 76 return buf.toString(); 77 } 78 79 public void getDiff(List diff) { 80 ASTProvider parser = getParser(); 81 ASTree tree = getASTree(); 82 ASTree[] children = tree.getSubTrees(); 83 84 getChildDiff(diff, parser, children[0], (MetadataElement) getExpression(), CHANGED_EXPRESSION); 85 } 86 87 void setData(Expression expression) { 88 changeChild(null, expression); 89 this.expression = expression; 90 } 91 92 protected void _delete() { 93 if (childrenInited) { 95 deleteChild(expression); 96 } 97 super._delete(); 101 } 102 103 public void replaceChild(Element oldElement,Element newElement) { 104 if (childrenInited) { 105 if (oldElement.equals(expression)) { 106 setExpression((Expression)newElement); 107 } 108 } 109 } 110 111 public Element duplicate(JavaModelPackage targetExtent) { 112 return targetExtent.getThrowStatement().createThrowStatement((Expression) duplicateElement(getExpression(), targetExtent)); 113 } 114 } 115 | Popular Tags |