1 33 34 package net.percederberg.grammatica.code.csharp; 35 36 import java.io.PrintWriter ; 37 import net.percederberg.grammatica.code.CodeElement; 38 import net.percederberg.grammatica.code.CodeStyle; 39 40 46 public class CSharpEnumeration extends CSharpType { 47 48 51 public static final int PUBLIC = CSharpModifier.PUBLIC; 52 53 57 public static final int PROTECTED_INTERNAL = 58 CSharpModifier.PROTECTED_INTERNAL; 59 60 64 public static final int PROTECTED = CSharpModifier.PROTECTED; 65 66 69 public static final int INTERNAL = CSharpModifier.INTERNAL; 70 71 75 public static final int PRIVATE = CSharpModifier.PRIVATE; 76 77 81 public static final int NEW = CSharpModifier.NEW; 82 83 86 private Constant last = null; 87 88 93 public CSharpEnumeration(String name) { 94 this(PUBLIC, name); 95 } 96 97 104 public CSharpEnumeration(int modifiers, String name) { 105 super(modifiers, name, ""); 106 } 107 108 116 public int category() { 117 return 3; 118 } 119 120 125 public void addConstant(String name) { 126 addConstant(name, null); 127 } 128 129 135 public void addConstant(String name, String value) { 136 addConstant(name, value, null); 137 } 138 139 146 public void addConstant(String name, 147 String value, 148 CSharpComment comment) { 149 150 Constant c = new Constant(name, value); 151 152 if (comment != null) { 153 c.setComment(comment); 154 } 155 addElement(c); 156 last = c; 157 } 158 159 166 public void print(PrintWriter out, CodeStyle style, int indent) { 167 print(out, style, indent, "enum"); 168 } 169 170 180 protected void printSeparator(PrintWriter out, 181 CodeStyle style, 182 CodeElement prev, 183 CodeElement next) { 184 } 186 187 190 private class Constant extends CodeElement { 191 192 195 private String name; 196 197 200 private String value; 201 202 205 private CSharpComment comment; 206 207 213 public Constant(String name, String value) { 214 this.name = name; 215 this.value = value; 216 this.comment = null; 217 } 218 219 227 public int category() { 228 return 0; 229 } 230 231 237 public void setComment(CSharpComment comment) { 238 this.comment = comment; 239 } 240 241 248 public void print(PrintWriter out, CodeStyle style, int indent) { 249 if (comment != null) { 250 out.println(); 251 comment.print(out, style, indent); 252 } 253 out.print(style.getIndent(indent)); 254 out.print(name); 255 if (value != null) { 256 out.print(" = "); 257 out.print(value); 258 } 259 if (this != last) { 260 out.print(","); 261 } 262 out.println(); 263 } 264 } 265 } 266 | Popular Tags |