1 28 29 package com.caucho.java; 30 31 import com.caucho.util.CharBuffer; 32 import com.caucho.util.CharCursor; 33 import com.caucho.util.StringCharCursor; 34 import com.caucho.vfs.ByteToChar; 35 36 import java.io.IOException ; 37 import java.io.InputStream ; 38 import java.io.UnsupportedEncodingException ; 39 40 43 class JavacErrorParser extends ErrorParser { 44 private CharBuffer _token = new CharBuffer(); 45 private CharBuffer _buf = new CharBuffer(); 46 private ByteToChar _lineBuf = ByteToChar.create(); 47 48 public JavacErrorParser() 49 throws UnsupportedEncodingException 50 { 51 this(null); 52 } 53 54 public JavacErrorParser(String encoding) 55 throws UnsupportedEncodingException 56 { 57 if (encoding == null) 58 encoding = System.getProperty("file.encoding"); 59 60 _lineBuf.setEncoding(encoding); 61 } 62 63 String parseErrors(InputStream is, LineMap lineMap) 64 throws IOException 65 { 66 CharBuffer result = new CharBuffer(); 67 68 int ch = is.read(); 69 for (; ch >= 0; ch = is.read()) { 70 _lineBuf.clear(); 71 72 for (; ch > 0 && ch != '\n'; ch = is.read()) 73 _lineBuf.addByte((byte) ch); 74 _lineBuf.addChar('\n'); 75 76 String lineString = _lineBuf.getConvertedString(); 77 78 StringCharCursor cursor = new StringCharCursor(lineString); 79 80 String line = parseLine(cursor, lineMap); 81 if (line == null) 82 result.append(lineString); 83 else 84 result.append(line); 85 86 } 87 88 return result.toString(); 89 } 90 91 96 String parseLine(CharCursor is, LineMap lineMap) 97 throws IOException 98 { 99 int ch = is.read(); 100 101 _buf.clear(); 102 103 String filename = null; 104 int line = 0; 105 106 _token.clear(); 108 109 line: 110 for (; ch != is.DONE; ch = is.read()) { 111 while (ch == ':') { 112 line = 0; 113 for (ch = is.read(); ch >= '0' && ch <= '9'; ch = is.read()) 114 line = 10 * line + ch - '0'; 115 if (ch == ':' && line > 0) { 116 filename = _token.toString(); 117 break line; 118 } 119 else { 120 _token.append(':'); 121 if (line > 0) 122 _token.append(line); 123 } 124 } 125 126 if (ch != is.DONE) 127 _token.append((char) ch); 128 } 129 130 if (filename == null) 131 return null; 132 133 int column = 0; 134 135 for (; ch != is.DONE && ch != ' '; ch = is.read()) { 137 } 138 139 for (; ch == ' '; ch = is.read()) { 140 } 141 142 _buf.clear(); 144 for (; ch != is.DONE; ch = is.read()) 145 _buf.append((char) ch); 146 147 String message = _buf.toString(); 148 149 if (lineMap != null) 150 return lineMap.convertError(filename, line, 0, message); 151 else 152 return filename + ":" + line + ": " + message; 153 } 154 } 155 | Popular Tags |