1 19 package org.netbeans.modules.javacore.jmiimpl.javamodel; 20 21 import org.netbeans.jmi.javamodel.Initializer; 22 import org.netbeans.jmi.javamodel.StatementBlock; 23 import org.netbeans.lib.java.parser.ASTree; 24 import org.netbeans.mdr.storagemodel.StorableObject; 25 import org.netbeans.modules.javacore.parser.ASTProvider; 26 import org.netbeans.modules.javacore.parser.ElementInfo; 27 import org.netbeans.modules.javacore.parser.FeatureInfo; 28 import java.lang.reflect.Modifier ; 29 import java.util.Collection ; 30 import java.util.Collections ; 31 import java.util.List ; 32 import org.netbeans.jmi.javamodel.Element; 33 import org.netbeans.jmi.javamodel.JavaDoc; 34 import org.netbeans.jmi.javamodel.JavaModelPackage; 35 import org.netbeans.modules.javacore.JMManager; 36 37 42 public abstract class InitializerImpl extends BehavioralFeatureImpl implements Initializer { 43 private static final ElementInfo DEFAULT_INFO = new FeatureInfo(null, FeatureInfo.STATIC_INITIALIZER_TYPE, null, 0, null); 44 45 46 public InitializerImpl(StorableObject s) { 47 super(s); 48 } 49 50 protected ElementInfo getDefaultInfo() { 51 return DEFAULT_INFO; 52 } 53 54 protected void matchName(ElementInfo info) { 55 } 57 58 public String getName() { 59 return null; 60 } 61 62 public void setName(String name) { 63 throw new UnsupportedOperationException (); 65 } 66 67 protected ASTree getBodyAST() { 68 return getASTree().getSubTrees()[1]; 69 } 70 71 public Collection getReferences() { 72 return Collections.EMPTY_LIST; 73 } 74 75 protected void initChildren() { 76 childrenInited = true; 77 StatementBlock body = retrieveBody(); 78 if (bodyInited) { 79 JMManager.getTransactionMutex().addBFeatureToInitQueue(this); 80 } 81 } 82 83 public String getSourceText() { 84 String origElem; 85 if ((origElem = checkChange()) != null) 86 return origElem; 87 StringBuffer buf = new StringBuffer (); 92 String indent = getIndentation(); 93 buf.append('\n'); 94 buf.append(indent); 95 int modifiers = getSourceModifiers(); 96 if ((modifiers & ~Modifier.STATIC) != modifiers) { 97 buf.append(Modifier.toString(modifiers)); 98 } 99 generateBody(buf); 100 return buf.toString(); 101 } 102 103 public void getDiff(List diffList) { 104 ASTProvider parser = getParser(); 105 ASTree tree = getASTree(); 106 107 if (isChanged(CHANGED_MODIFIERS)) { 109 boolean isStatic = (getSourceModifiers() & Modifier.STATIC) == Modifier.STATIC ? true : false; 110 int startOffset = parser.getToken(tree.getFirstToken()).getStartOffset(); 111 if (isStatic) { 112 String mods = Modifier.toString(getSourceModifiers()); 114 mods += ' '; 115 diffList.add(new DiffElement(startOffset, startOffset, mods)); 116 } 117 else { 118 int endOffset = parser.getToken(tree.getFirstToken()+1).getStartOffset(); 120 diffList.add(new DiffElement(startOffset, endOffset, "")); 121 } 122 } 123 createBodyDiffs(diffList); 125 } 126 127 public Element duplicate(JavaModelPackage targetExtent) { 128 StatementBlock body; 129 String bodyText; 130 131 if (isChanged(CHANGED_BODY) && this.bodyText != null) { 132 body = null; 133 bodyText = this.bodyText; 134 } else { 135 body = (StatementBlock) duplicateElement(getBody(), targetExtent); 136 bodyText = null; 137 } 138 139 return targetExtent.getInitializer().createInitializer( 140 null, 141 duplicateList(getAnnotations(), targetExtent), 142 getModifiers(), 143 null, 144 (JavaDoc) duplicateElement(getJavadoc(), targetExtent), 145 body, 146 bodyText 147 ); 148 } 149 } 150 | Popular Tags |