1 19 20 package org.netbeans.modules.java.codegen; 21 22 import org.openide.src.*; 23 import org.openide.text.*; 24 25 import org.netbeans.modules.java.bridge.Binding; 26 27 32 class Initializer extends ElementBinding implements Binding.Initializer { 33 35 private String preexistingBody; 36 37 public Initializer(InitializerElement el, SourceText s) { 38 super(el, s); 39 } 40 41 public void create(PositionBounds b) throws SourceException { 42 super.create(b); 43 preexistingBody = null; 44 } 45 46 private InitializerElement getInitializer() { 47 return (InitializerElement)getElement(); 48 } 49 50 private InitializerElement cloneInitializer() { 51 return (InitializerElement)cloneElement(); 52 } 53 54 protected int classifyProperty(String name) { 55 if (name == PROP_BODY) 56 return CLASS_BODY; 57 else 58 return CLASS_HEADER; 59 } 60 61 protected Element cloneElement() { 62 InitializerElement initEl = new InitializerElement(); 63 try { 64 initEl.setStatic(getInitializer().isStatic()); 65 } catch (SourceException ex) { 66 } 67 return initEl; 68 } 69 70 73 public void changeStatic(boolean enable) throws SourceException { 74 if (!source.isGeneratorEnabled()) 75 return; 76 77 InitializerElement iel = cloneInitializer(); 78 iel.setStatic(enable); 79 regenerateHeader(iel); 80 } 81 82 85 public void updateFrom(Binding other) { 86 } 87 88 public String getBodyContent() throws SourceException { 89 if (preexistingBody != null) 90 return preexistingBody; 91 return CodeGenerator.readTextBounds(bodyBounds); 92 } 93 94 public void changeBody(String bodyString) throws SourceException { 95 if (!source.isGeneratorEnabled()) 96 return; 97 98 InitializerElement ie = cloneInitializer(); 99 ie.setBody(bodyString); 100 source.runAtomic(getElement(), new PartialGenerator(source.getDocument(), 101 ie, bodyBounds, ElementPrinter.BODY_BEGIN, ElementPrinter.BODY_END)); 102 } 103 104 public void copyBody(String bodyString) { 105 this.preexistingBody = bodyString; 106 } 107 } 108 | Popular Tags |