1 19 package org.netbeans.modules.javacore.jmiimpl.javamodel; 20 21 import org.netbeans.jmi.javamodel.ArrayReference; 22 import org.netbeans.jmi.javamodel.MultipartId; 23 import org.netbeans.jmi.javamodel.NamedElement; 24 import org.netbeans.lib.java.parser.ASTree; 25 import org.netbeans.mdr.storagemodel.StorableObject; 26 27 import java.util.List ; 28 import org.netbeans.jmi.javamodel.Element; 29 import org.netbeans.jmi.javamodel.JavaModelPackage; 30 31 35 public abstract class ArrayReferenceImpl extends TypeReferenceImpl implements ArrayReference { 36 private int dimCount; 37 38 39 public ArrayReferenceImpl(StorableObject o) { 40 super(o); 41 } 42 43 protected ASTree getNameAST() { 44 return getASTree(); 45 } 46 47 public String getName() { 48 StringBuffer buf = new StringBuffer (); 49 buf.append(getParent().getName()); 50 appendDims(buf); 51 return buf.toString(); 52 } 53 54 void setData(String name, MultipartId parent, int dimCount) { 55 super.setData(name, parent); 56 this.dimCount = dimCount; 57 } 58 59 public String getSourceText() { 60 String origElem; 61 if ((origElem = checkChange()) != null) 62 return origElem; 63 StringBuffer buf = new StringBuffer (); 64 buf.append(((MetadataElement) getParent()).getSourceText()); 65 appendDims(buf); 66 return buf.toString(); 67 } 68 69 public void setDimCount(int dimCount) { 70 objectChanged(CHANGED_DIM_COUNT); 71 this.dimCount = dimCount; 72 } 73 74 public int getDimCount() { 75 if (isChanged(CHANGED_DIM_COUNT)) { 76 return dimCount; 77 } else { 78 ASTree dimsTree = getASTree().getSubTrees()[1]; 79 return (dimsTree.getLastToken() - dimsTree.getFirstToken() + 1) / 2; 80 } 81 } 82 83 private StringBuffer appendDims(StringBuffer buf) { 84 for (int i = 0; i < getDimCount(); i++) { 85 formatElementPart(ARRAY_OPEN_BRACKET, buf); 86 formatElementPart(ARRAY_CLOSE_BRACKET, buf); 87 } 88 return buf; 89 } 90 91 public void getDiff(List diff) { 92 ASTree tree = getASTree(); 93 getChildDiff(diff, getParser(), tree.getSubTrees()[0], (MetadataElement) getParent(), CHANGED_PARENT); 94 if (isChanged(CHANGED_DIM_COUNT)) { 95 replaceNode(diff, getParser(), tree.getSubTrees()[1], appendDims(new StringBuffer ()).toString(), 0, null); 96 } 97 } 98 99 public NamedElement getElement() { 100 return (NamedElement) getParser().getSemanticInfo(getASTree(), this); 101 } 102 103 106 public Element duplicate(JavaModelPackage targetExtent) { 107 return targetExtent.getArrayReference().createArrayReference( 108 getName(), 109 (MultipartId) duplicateElement(getParent(), targetExtent), 110 getDimCount() 111 ); 112 } 113 } 114 | Popular Tags |