1 19 package org.netbeans.modules.javacore.jmiimpl.javamodel; 20 21 import java.util.*; 22 import org.netbeans.jmi.javamodel.*; 23 import org.netbeans.lib.java.parser.ASTree; 24 import org.netbeans.mdr.storagemodel.StorableObject; 25 import org.netbeans.modules.javacore.parser.*; 26 27 31 public abstract class CatchImpl extends TransientElement implements Catch { 32 private Parameter parameter; 33 private StatementBlock body; 34 35 36 public CatchImpl(StorableObject o) { 37 super(o); 38 } 39 40 public Parameter getParameter() { 41 if (!childrenInited) { 42 initChildren(); 43 } 44 return parameter; 45 } 46 47 public void setParameter(Parameter parameter) { 48 objectChanged(CHANGED_PARAMETER); 49 changeChild(getParameter(), parameter); 50 this.parameter = parameter; 51 } 52 53 public StatementBlock getBody() { 54 if (!childrenInited) { 55 initChildren(); 56 } 57 return body; 58 } 59 60 public void setBody(StatementBlock body) { 61 objectChanged(CHANGED_BODY); 62 changeChild(getBody(), body); 63 this.body = body; 64 } 65 66 public List getChildren() { 67 List list = new ArrayList(2); 68 addIfNotNull(list, getParameter()); 69 addIfNotNull(list, getBody()); 70 return list; 71 } 72 73 protected void initChildren() { 74 childrenInited = false; 75 ASTree tree = getASTree(); 76 if (tree != null) { 77 ASTree[] parts = tree.getSubTrees(); 78 79 ASTree parameterAST = parts[0]; 81 ParameterInfo paramInfo = (ParameterInfo)getParser().getSemanticInfo(parameterAST, this); 82 if (parameter == null) { 83 parameter = (Parameter)createElement(paramInfo); 84 changeChild(null, parameter); 85 } else { 86 ((SemiPersistentElement)parameter).updatePersistent(paramInfo); 87 ((SemiPersistentElement)parameter).setElementInfo(paramInfo); 88 } 89 body = (StatementBlock) initOrCreate(body, parts[1]); 91 } 92 childrenInited = true; 93 } 94 95 String getRawText() { 96 StringBuffer buf = new StringBuffer (); 97 StatementImpl body = (StatementImpl)getBody(); 98 ParameterImpl param = (ParameterImpl)getParameter(); 99 formatElementPart(CATCH_KEYWORD, buf); 100 formatElementPart(STMT_OPEN_BRACKET, buf); 101 buf.append(param.getSourceText()); 102 formatElementPart(STMT_CLOSE_BRACKET, buf); 103 buf.append(body.getSourceText()); 104 return buf.toString(); 105 } 106 107 protected String getIndentation() { 108 return ((MetadataElement) refImmediateComposite()).getIndentation(); 109 } 110 111 public void getDiff(List diff) { 112 ASTProvider parser = getParser(); 113 ASTree[] children = getASTree().getSubTrees(); 114 115 getChildDiff(diff, parser, children[0], (MetadataElement) getParameter(), CHANGED_PARAMETER); 116 getChildDiff(diff, parser, children[1], (MetadataElement) getBody(), CHANGED_BODY); 117 } 118 119 void setData(Parameter parameter, StatementBlock body) { 120 changeChild(null, parameter); 121 this.parameter = parameter; 122 changeChild(null, body); 123 this.body = body; 124 } 125 126 protected void _delete() { 127 if (childrenInited) { 129 deleteChild(parameter); 130 deleteChild(body); 131 } 132 super._delete(); 136 } 137 138 public void replaceChild(Element oldElement,Element newElement) { 139 if (childrenInited) { 140 if (oldElement.equals(parameter)) { 141 setParameter((Parameter)newElement); 142 } 143 if (oldElement.equals(body)) { 144 setBody((StatementBlock)newElement); 145 } 146 } 147 } 148 149 public Element duplicate(JavaModelPackage targetExtent) { 150 return targetExtent.getCatch().createCatch( 151 (Parameter) duplicateElement(getParameter(), targetExtent), (StatementBlock) duplicateElement(getBody(), targetExtent)); 152 } 153 } 154 | Popular Tags |