1 20 package org.objectweb.modfact.jmi.generator; 21 22 29 public abstract class BracketGenerator extends PrintGenerator { 30 31 35 protected void output(String outputString) { 36 int index = outputString.indexOf("\n"); 37 if (index != -1 && index != outputString.length() - 1) { 38 java.util.StringTokenizer token = new java.util.StringTokenizer (outputString, "\n"); 40 while (token.hasMoreTokens()) { 41 String next = token.nextToken(); 42 if (!token.hasMoreTokens()) { 43 if (outputString.endsWith("\n")) 44 outputln(next); 45 else 46 output(next); 47 } else { 48 outputln(next); 49 } 50 } 51 } else { 52 if (outputString.trim().startsWith("}")) 53 level--; 54 if (newLine) { 55 for (int j = 0; j < level; j++) 56 out.print(TABULATION); 57 } 58 if (outputString.trim().startsWith("}")) { 59 out.print(outputString); 60 if (outputString.trim().endsWith("{")) 61 level++; 62 } else { 63 out.print(outputString); 64 for (int i = 0; i < outputString.length(); i++) { 65 String current = String.valueOf(outputString.charAt(i)); 66 if (current.equals("{")) 67 level++; 68 else if (current.equals("}")) 69 level--; 70 } 71 } 72 if (outputString.trim().endsWith("\n")) 73 newLine = true; 74 else 75 newLine = false; 76 } 77 } 78 79 } 80 | Popular Tags |