1 33 34 package net.percederberg.grammatica.code.csharp; 35 36 import java.io.PrintWriter ; 37 38 import net.percederberg.grammatica.code.CodeElement; 39 import net.percederberg.grammatica.code.CodeElementContainer; 40 import net.percederberg.grammatica.code.CodeStyle; 41 42 48 abstract class CSharpType extends CodeElementContainer { 49 50 53 private int modifiers; 54 55 58 private String name; 59 60 63 private String [] extendTypes; 64 65 68 private CSharpComment comment = null; 69 70 80 protected CSharpType(int modifiers, String name, String extendType) { 81 this.modifiers = modifiers; 82 this.name = name; 83 if (extendType == null || extendType.equals("")) { 84 this.extendTypes = new String [0]; 85 } else { 86 this.extendTypes = new String [1]; 87 this.extendTypes[0] = extendType; 88 } 89 } 90 91 99 protected CSharpType(int modifiers, String name, String [] extendTypes) { 100 this.modifiers = modifiers; 101 this.name = name; 102 this.extendTypes = extendTypes; 103 } 104 105 110 public String toString() { 111 return name; 112 } 113 114 120 public void addComment(CSharpComment comment) { 121 this.comment = comment; 122 } 123 124 132 protected void print(PrintWriter out, 133 CodeStyle style, 134 int indent, 135 String type) { 136 137 StringBuffer buf = new StringBuffer (); 138 String indentStr = style.getIndent(indent); 139 140 if (comment != null) { 142 comment.print(out, style, indent); 143 } 144 145 buf.append(indentStr); 147 buf.append(CSharpModifier.createModifierDecl(modifiers)); 148 buf.append(type); 149 buf.append(" "); 150 buf.append(name); 151 for (int i = 0; i < extendTypes.length; i++) { 152 if (i == 0) { 153 buf.append(" : "); 154 } else { 155 buf.append(", "); 156 } 157 buf.append(extendTypes[i]); 158 } 159 buf.append(" {"); 160 out.println(buf.toString()); 161 162 printContents(out, style, indent + 1); 164 165 out.println(indentStr + "}"); 167 } 168 169 177 protected void printSeparator(PrintWriter out, 178 CodeStyle style, 179 CodeElement prev, 180 CodeElement next) { 181 182 if (prev == null || next == null) { 183 } else { 185 out.println(); 186 } 187 } 188 } 189 | Popular Tags |