1 19 20 package org.netbeans.modules.javacore.jmiimpl.javamodel; 21 22 import java.util.ArrayList ; 23 import java.util.List ; 24 import org.netbeans.jmi.javamodel.*; 25 import org.netbeans.lib.java.parser.ASTree; 26 import org.netbeans.lib.java.parser.ParserTokens; 27 import org.netbeans.mdr.storagemodel.StorableObject; 28 import org.netbeans.modules.javacore.parser.ASTProvider; 29 30 33 public abstract class WildCardImpl extends TransientElement implements WildCard { 34 private boolean isLower; 35 private TypeReference boundName; 36 private Type bound; 37 38 public WildCardImpl(StorableObject o) { 39 super(o); 40 } 41 42 public boolean isLower() { 43 if (isChanged(CHANGED_IS_LOWER)) { 44 return isLower; 45 } else { 46 ASTree lower = getASTree().getSubTrees()[0]; 47 return lower == null || lower.getType() == ParserTokens.EXTENDS; 48 } 49 } 50 51 public void setLower(boolean newValue) { 52 objectChanged(CHANGED_IS_LOWER); 53 isLower = newValue; 54 } 55 56 public TypeReference getBoundName() { 57 if (!childrenInited) { 58 initChildren(); 59 } 60 return boundName; 61 } 62 63 public void setBoundName(TypeReference newValue) { 64 objectChanged(CHANGED_BOUND); 65 changeChild(getBoundName(), newValue); 66 this.boundName = newValue; 67 this.bound = null; 68 } 69 70 public Type getBound() { 71 if (bound == null || !isChanged(CHANGED_BOUND)) { 72 return (Type) getBoundName().getElement(); 73 } else { 74 return bound; 75 } 76 } 77 78 public void setBound(Type newValue) { 79 bound = newValue; 80 MultipartIdClass proxy = ((JavaModelPackage) refImmediatePackage()).getMultipartId(); 81 setBoundName(proxy.createMultipartId(newValue.getName(), null, null)); 82 } 83 84 public List getChildren() { 85 List list = new ArrayList (1); 86 addIfNotNull(list, getBoundName()); 87 return list; 88 } 89 90 protected void initChildren() { 91 childrenInited = false; 92 ASTree tree = getASTree(); 93 ASTree[] children = getASTree().getSubTrees(); 94 if (tree != null) { 95 boundName = (TypeReference) initOrCreate(boundName, children[1]); 96 } 97 childrenInited = true; 98 } 99 100 public String getSourceText() { 101 String origElem; 102 if ((origElem = checkChange()) != null) 103 return origElem; 104 StringBuffer buf = new StringBuffer (); 105 buf.append('?'); 106 TypeReferenceImpl boundName = (TypeReferenceImpl) getBoundName(); 107 if (boundName != null) { 108 buf.append(isLower() ? " extends " : " super "); buf.append(boundName.getSourceText()); 110 } 111 return buf.toString(); 112 } 113 114 public void getDiff(List diff) { 115 ASTProvider parser = getParser(); 116 ASTree tree = getASTree(); 117 118 if (isChanged(CHANGED_IS_LOWER) || isChanged(CHANGED_BOUND)) { 119 replaceNode(diff, parser, tree, getSourceText(), 0, null); 120 } else if (isChanged(CHANGED_CHILDREN)) { 121 ((MetadataElement) getBoundName()).getDiff(diff); 122 } 123 } 124 125 void setData(boolean isLower, TypeReference boundName) { 126 this.isLower = isLower; 127 changeChild(null, boundName); 128 this.boundName = boundName; 129 } 130 131 protected void _delete() { 132 if (childrenInited) { 134 deleteChild(boundName); 135 } 136 super._delete(); 140 } 141 142 public void replaceChild(Element oldElement,Element newElement){ 143 if (childrenInited) { 144 if (oldElement.equals(boundName)) { 145 setBoundName((TypeReference) newElement); 146 } 147 } 148 } 149 150 public Element duplicate(JavaModelPackage targetExtent) { 151 return targetExtent.getWildCard().createWildCard( 152 isLower(), (TypeReference) duplicateElement(getBoundName(), targetExtent)); 153 } 154 } 155 | Popular Tags |