1 19 package org.netbeans.modules.javacore.jmiimpl.javamodel; 20 21 import java.util.List ; 22 import org.netbeans.jmi.javamodel.Element; 23 import org.netbeans.jmi.javamodel.Expression; 24 import org.netbeans.jmi.javamodel.AssertStatement; 25 import org.netbeans.jmi.javamodel.AssertStatementClass; 26 import org.netbeans.jmi.javamodel.JavaModelPackage; 27 import org.netbeans.lib.java.parser.ASTree; 28 import org.netbeans.mdr.storagemodel.StorableObject; 29 import org.netbeans.modules.javacore.parser.ASTProvider; 30 31 35 public abstract class AssertStatementImpl extends ConditionImpl implements AssertStatement { 36 private Expression detail = null; 37 38 39 public AssertStatementImpl(StorableObject o) { 40 super(o); 41 } 42 43 public void setDetail(Expression detail) { 44 objectChanged(CHANGED_DETAIL); 45 changeChild(getDetail(), detail); 46 this.detail = detail; 47 } 48 49 public List getChildren() { 50 List list = super.getChildren(); 51 addIfNotNull(list, getDetail()); 52 return list; 53 } 54 55 protected void initChildren() { 56 childrenInited = false; 57 ASTree tree = getASTree(); 58 if (tree != null) { 59 ASTree[] parts = tree.getSubTrees(); 60 expression = (Expression) initOrCreate(expression, parts[0]); 61 detail = (Expression) initOrCreate(detail, parts[1]); 62 } 63 childrenInited = true; 64 } 65 66 public Expression getDetail() { 67 if (!childrenInited) { 68 initChildren(); 69 } 70 return detail; 71 } 72 73 public String getSourceText() { 74 String origElem; 75 if ((origElem = checkChange()) != null) 76 return origElem; 77 StringBuffer buf = new StringBuffer (); 78 TransientElement cond = (TransientElement)getExpression(); 79 TransientElement detail = (TransientElement)getDetail(); 80 buf.append('\n'); 81 formatElementPart(ASSERT_KEYWORD, buf); 82 buf.append(cond.getSourceText()); 83 if (detail != null) { 84 buf.append(" : "); buf.append(detail.getSourceText()); 86 } 87 buf.append(';'); 88 return buf.toString(); 89 } 90 91 public void getDiff(List diff) { 92 ASTProvider parser = getParser(); 93 ASTree tree = getASTree(); 94 ASTree[] children = tree.getSubTrees(); 95 96 getChildDiff(diff, parser, children[0], (TransientElement) getExpression(), CHANGED_EXPRESSION); 97 TransientElement detail = (TransientElement) getDetail(); 98 getChildDiff(diff, parser, children[1], detail, CHANGED_DETAIL, parser.getToken(children[0].getLastToken()).getEndOffset(), " : "); } 100 101 void setData(Expression expression, Expression detail) { 102 changeChild(null, expression); 103 changeChild(null, detail); 104 this.expression = expression; 105 this.detail = detail; 106 } 107 108 protected void _delete() { 109 if (childrenInited) { 111 deleteChild(detail); 112 } 113 super._delete(); 117 } 118 119 public void replaceChild(Element oldElement,Element newElement) { 120 if (childrenInited) { 121 if (oldElement.equals(detail)) { 122 setDetail((Expression)newElement); 123 } else 124 super.replaceChild(oldElement,newElement); 125 } 126 } 127 128 public Element duplicate(JavaModelPackage targetExtent) { 129 return targetExtent.getAssertStatement().createAssertStatement( 130 (Expression) duplicateElement(getExpression(), targetExtent), 131 (Expression) duplicateElement(getDetail(), targetExtent)); 132 } 133 } 134 | Popular Tags |