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 VisualBasicComment extends CodeElement { 50 51 56 public static final int DOCUMENTATION = 0; 57 58 63 public static final int SINGLELINE = 1; 64 65 68 private int type; 69 70 73 private String comment; 74 75 80 public VisualBasicComment(String comment) { 81 this(DOCUMENTATION, comment); 82 } 83 84 93 public VisualBasicComment(int type, String comment) { 94 if (DOCUMENTATION <= type && type <= SINGLELINE) { 95 this.type = type; 96 } else { 97 this.type = DOCUMENTATION; 98 } 99 this.comment = comment; 100 } 101 102 110 public int category() { 111 return 0; 112 } 113 114 121 public void print(PrintWriter out, CodeStyle style, int indent) { 122 String indentStr = style.getIndent(indent); 123 String firstLine; 124 String restLines; 125 int pos; 126 127 restLines = comment; 128 while ((pos = restLines.indexOf('\n')) >= 0) { 129 firstLine = restLines.substring(0, pos); 130 restLines = restLines.substring(pos + 1); 131 printLine(out, indentStr, firstLine); 132 } 133 printLine(out, indentStr, restLines); 134 } 135 136 143 private void printLine(PrintWriter out, String indent, String line) { 144 if (type == DOCUMENTATION) { 145 out.println(indent + "'''" + line); 146 } else if (line.equals("")) { 147 out.println(indent + "'"); 148 } else { 149 out.println(indent + "' " + line); 150 } 151 } 152 } 153 | Popular Tags |