1 28 29 package com.caucho.java; 30 31 import com.caucho.util.CharBuffer; 32 import com.caucho.vfs.ByteToChar; 33 34 import java.io.IOException ; 35 import java.io.InputStream ; 36 37 40 class JikesErrorParser extends ErrorParser { 41 private ByteToChar token = ByteToChar.create(); 42 private ByteToChar buf = ByteToChar.create(); 43 private String filename = "filename"; 44 45 50 String parseErrors(InputStream is, LineMap lineMap) 51 throws IOException 52 { 53 CharBuffer errors = new CharBuffer(); 54 55 scanError(is, lineMap, errors); 56 57 return errors.toString(); 58 } 59 60 65 private void scanError(InputStream is, LineMap lineMap, CharBuffer errors) 66 throws IOException 67 { 68 int ch = is.read(); 69 ByteToChar sourceLine = ByteToChar.create(); 70 sourceLine.setEncoding(System.getProperty("file.encoding")); 71 filename = "filename"; 72 73 buf.clear(); 74 while (ch >= 0) { 75 int colOffset = 0; 76 for (; ch >= 0 && (ch == ' ' || ch == '\t'); ch = is.read()) 77 colOffset++; 78 79 int line = 0; 80 for (; ch >= 0 && ch >= '0' && ch <= '9'; ch = is.read()) { 81 line = 10 * line + ch - '0'; 82 colOffset++; 83 } 84 85 if (ch < 0) 86 return; 87 else if (colOffset == 0 && ! Character.isWhitespace((char) ch)) { 88 ch = scanUnknownLine(is, ch, errors); 89 } 90 else if (ch != '.') { 91 ch = skipToNewline(is, ch); 92 continue; 93 } 94 95 sourceLine.clear(); 96 for (ch = is.read(); ch >= 0 && ch != '\n'; ch = is.read()) 97 sourceLine.addByte(ch); 98 sourceLine.addChar('\n'); 99 100 int column = 0; 101 for (ch = is.read(); ch >= 0 && ch != '\n'; ch = is.read()) { 102 if (ch == '^') 103 break; 104 else if (ch == ' ') 105 column++; 106 else if (ch == '\t') 107 column = ((column + 8) / 8) * 8; 108 } 109 for (int i = colOffset + 1; i < column; i++) 110 sourceLine.addChar(' '); 111 sourceLine.addChar('^'); 112 sourceLine.addChar('\n'); 113 114 ch = skipToNewline(is, ch); 115 if (ch != '*') 116 continue; 117 118 buf.clear(); 119 for (; ch >= 0 && ch != ':' && ch != '\n'; ch = is.read()) { 120 } 121 122 if (ch != ':') { 123 ch = skipToNewline(is, ch); 124 continue; 125 } 126 127 for (ch = is.read(); 128 ch >= 0 && (ch == ' ' || ch == ' '); 129 ch = is.read()) { 130 } 131 132 for (; ch >= 0 && ch != '\n'; ch = is.read()) 133 buf.addByte(ch); 134 135 String message = buf.getConvertedString(); 136 137 if (lineMap != null) 138 errors.append(lineMap.convertError(filename, line, 0, message)); 139 else 140 errors.append(filename + ":" + line + ": " + message); 141 errors.append('\n'); 142 errors.append(sourceLine.getConvertedString()); 143 } 144 } 145 146 private int scanUnknownLine(InputStream is, int ch, CharBuffer errors) 147 throws IOException 148 { 149 token.clear(); 150 token.addByte(ch); 151 for (ch = is.read(); 152 ch > 0 && ! Character.isWhitespace((char) ch); 153 ch = is.read()) { 154 } 155 156 if (token.equals("Found")) { 157 return scanFilename(is, ch); 158 } 159 else if (token.equals("***")) { 160 for (; ch == ' ' || ch == '\t'; ch = is.read()) { 161 } 162 token.clear(); 163 for (; ch > 0 && ch != '\n' && ch != ':'; ch = is.read()) { 164 token.addByte(ch); 165 } 166 167 if (token.equals("Warning")) 168 return skipToNewline(is, ch); 169 170 token.clear(); 171 for (ch = is.read(); ch > 0 && ch != '\n'; ch = is.read()) 172 token.addByte(ch); 173 token.addChar('\n'); 174 175 errors.append(token.getConvertedString()); 176 177 return is.read(); 178 } 179 else 180 return skipToNewline(is, ch); 181 } 182 183 private int scanFilename(InputStream is, int ch) 184 throws IOException 185 { 186 for (; ch >= 0 && ch != '\n' && ch != '"'; ch = is.read()) { 187 } 188 189 if (ch != '"') 190 return skipToNewline(is, ch); 191 192 token.clear(); 193 for (ch = is.read(); 194 ch >= 0 && ch != '"' && ch != '\n'; 195 ch = is.read()) { 196 token.addByte(ch); 197 } 198 199 if (ch != '"') 200 return skipToNewline(is, ch); 201 202 filename = token.getConvertedString(); 203 204 return skipToNewline(is, ch); 205 } 206 207 private int skipToNewline(InputStream is, int ch) 208 throws IOException 209 { 210 for (; ch >= 0 && ch != '\n'; ch = is.read()) { 211 } 212 213 return is.read(); 214 } 215 } 216 | Popular Tags |