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 CSharpComment extends CodeElement { 47 48 51 public static final int DOCUMENTATION = 0; 52 53 58 public static final int DOCUMENTATION_SINGLE = 1; 59 60 63 public static final int BLOCK = 2; 64 65 70 public static final int SINGLELINE = 3; 71 72 75 private int type; 76 77 80 private String comment; 81 82 87 public CSharpComment(String comment) { 88 this(DOCUMENTATION, comment); 89 } 90 91 101 public CSharpComment(int type, String comment) { 102 if (DOCUMENTATION <= type && type <= SINGLELINE) { 103 this.type = type; 104 } else { 105 this.type = DOCUMENTATION; 106 } 107 this.comment = comment; 108 } 109 110 118 public int category() { 119 return 0; 120 } 121 122 129 public void print(PrintWriter out, CodeStyle style, int indent) { 130 131 String indentStr = style.getIndent(indent); 132 String firstLine; 133 String restLines; 134 int pos; 135 136 if (type == DOCUMENTATION) { 138 out.println(indentStr + "/**"); 139 } else if (type == BLOCK) { 140 out.println(indentStr + "/*"); 141 } 142 143 restLines = comment; 145 while ((pos = restLines.indexOf('\n')) >= 0) { 146 firstLine = restLines.substring(0, pos); 147 restLines = restLines.substring(pos + 1); 148 printLine(out, indentStr, firstLine); 149 } 150 printLine(out, indentStr, restLines); 151 152 if (type == DOCUMENTATION || type == BLOCK) { 154 out.println(indentStr + " */"); 155 } 156 } 157 158 165 private void printLine(PrintWriter out, String indent, String line) { 166 if (type == DOCUMENTATION || type == BLOCK) { 167 out.print(indent + " *"); 168 } else if (type == DOCUMENTATION_SINGLE) { 169 out.print(indent + "///"); 170 } else { 171 out.print(indent + "//"); 172 } 173 if (line.equals("")) { 174 out.println(); 175 } else { 176 out.println(" " + line); 177 } 178 } 179 } 180 | Popular Tags |