1 34 35 package net.percederberg.grammatica.code.visualbasic; 36 37 import java.io.PrintWriter ; 38 import net.percederberg.grammatica.code.CodeElement; 39 import net.percederberg.grammatica.code.CodeStyle; 40 41 49 public class VisualBasicEnumeration extends VisualBasicType { 50 51 54 public static final int PUBLIC = VisualBasicModifier.PUBLIC; 55 56 60 public static final int PROTECTED_FRIEND = 61 VisualBasicModifier.PROTECTED_FRIEND; 62 63 67 public static final int PROTECTED = VisualBasicModifier.PROTECTED; 68 69 72 public static final int FRIEND = VisualBasicModifier.FRIEND; 73 74 78 public static final int PRIVATE = VisualBasicModifier.PRIVATE; 79 80 84 public static final int SHADOWS = VisualBasicModifier.SHADOWS; 85 86 89 private Constant last = null; 90 91 96 public VisualBasicEnumeration(String name) { 97 this(PUBLIC, name); 98 } 99 100 107 public VisualBasicEnumeration(int modifiers, String name) { 108 super(modifiers, name, ""); 109 } 110 111 119 public int category() { 120 return 3; 121 } 122 123 128 public void addConstant(String name) { 129 addConstant(name, null); 130 } 131 132 138 public void addConstant(String name, String value) { 139 addConstant(name, value, null); 140 } 141 142 149 public void addConstant(String name, 150 String value, 151 VisualBasicComment comment) { 152 153 Constant c = new Constant(name, value); 154 155 if (comment != null) { 156 c.setComment(comment); 157 } 158 addElement(c); 159 last = c; 160 } 161 162 169 public void print(PrintWriter out, CodeStyle style, int indent) { 170 print(out, style, indent, "Enum"); 171 } 172 173 183 protected void printSeparator(PrintWriter out, 184 CodeStyle style, 185 CodeElement prev, 186 CodeElement next) { 187 } 189 190 191 195 private class Constant extends CodeElement { 196 197 200 private String name; 201 202 205 private String value; 206 207 210 private VisualBasicComment comment; 211 212 218 public Constant(String name, String value) { 219 this.name = name; 220 this.value = value; 221 this.comment = null; 222 } 223 224 232 public int category() { 233 return 0; 234 } 235 236 242 public void setComment(VisualBasicComment comment) { 243 this.comment = comment; 244 } 245 246 253 public void print(PrintWriter out, CodeStyle style, int indent) { 254 if (comment != null) { 255 out.println(); 256 comment.print(out, style, indent); 257 } 258 out.print(style.getIndent(indent)); 259 out.print("[" + name + "]"); 260 if (value != null) { 261 out.print(" = "); 262 out.print(value); 263 } 264 out.println(); 265 } 266 } 267 } 268 | Popular Tags |