1 34 35 package net.percederberg.grammatica.code.visualbasic; 36 37 import java.io.PrintWriter ; 38 import java.util.LinkedList ; 39 40 import net.percederberg.grammatica.code.CodeElement; 41 import net.percederberg.grammatica.code.CodeStyle; 42 43 51 public class VisualBasicConstructor extends CodeElement { 52 53 56 public static final int PUBLIC = VisualBasicModifier.PUBLIC; 57 58 61 public static final int PROTECTED_FRIEND = 62 VisualBasicModifier.PROTECTED_FRIEND; 63 64 67 public static final int PROTECTED = VisualBasicModifier.PROTECTED; 68 69 72 public static final int FRIEND = VisualBasicModifier.FRIEND; 73 74 77 public static final int PRIVATE = VisualBasicModifier.PRIVATE; 78 79 82 public static final int SHARED = VisualBasicModifier.SHARED; 83 84 87 private int modifiers; 88 89 92 private VisualBasicClass cls; 93 94 97 private String args; 98 99 102 private LinkedList code; 103 104 107 private VisualBasicComment comment; 108 109 112 public VisualBasicConstructor() { 113 this(""); 114 } 115 116 121 public VisualBasicConstructor(String args) { 122 this(PUBLIC, args); 123 } 124 125 131 public VisualBasicConstructor(int modifiers, String args) { 132 this.modifiers = modifiers; 133 this.cls = null; 134 this.args = args; 135 this.code = new LinkedList (); 136 this.comment = null; 137 } 138 139 145 public VisualBasicClass getVisualBasicClass() { 146 return this.cls; 147 } 148 149 154 void setVisualBasicClass(VisualBasicClass cls) { 155 this.cls = cls; 156 } 157 158 163 public void addCode(String codeLines) { 164 int pos; 165 166 pos = codeLines.indexOf('\n'); 167 while (pos >= 0) { 168 this.code.add(codeLines.substring(0, pos)); 169 codeLines = codeLines.substring(pos + 1); 170 pos = codeLines.indexOf('\n'); 171 } 172 this.code.add(codeLines); 173 } 174 175 180 public void addComment(VisualBasicComment comment) { 181 this.comment = comment; 182 } 183 184 192 public int category() { 193 return 7; 194 } 195 196 203 public void print(PrintWriter out, CodeStyle style, int indent) { 204 String indentStr = style.getIndent(indent); 205 String codeIndentStr = style.getIndent(indent + 1); 206 StringBuffer res = new StringBuffer (); 207 208 if (comment != null) { 210 comment.print(out, style, indent); 211 } 212 213 res.append(indentStr); 215 res.append(VisualBasicModifier.createModifierDecl(modifiers)); 216 res.append("Sub New("); 217 res.append(args); 218 res.append(")"); 219 220 for (int i = 0; i < code.size(); i++) { 222 if (code.get(i).toString().length() > 0) { 223 res.append(codeIndentStr); 224 res.append(code.get(i).toString()); 225 res.append("\n"); 226 } else { 227 res.append("\n"); 228 } 229 } 230 res.append(indentStr); 231 res.append("End Sub"); 232 233 out.println(res.toString()); 235 } 236 } 237 | Popular Tags |