1 21 22 package org.armedbear.j; 23 24 public final class CompilationError 25 { 26 private final Line errorLine; 27 private final String fileName; 28 private final int lineNumber; 29 private final int offset; 30 private final String message; 31 32 private CompilationError(Line errorLine, String fileName, int lineNumber, 33 int offset, String message) 34 { 35 this.errorLine = errorLine; 36 this.fileName = fileName; 37 this.lineNumber = lineNumber; 38 this.offset = offset; 39 this.message = message; 40 } 41 42 public Line getErrorLine() 43 { 44 return errorLine; 45 } 46 47 public String getFileName() 48 { 49 return fileName; 50 } 51 52 public int getLineNumber() 53 { 54 return lineNumber; 55 } 56 57 public int getOffset() 58 { 59 return offset; 60 } 61 62 public String getMessage() 63 { 64 return message; 65 } 66 67 public static CompilationError parseLineAsErrorMessage(final Line line) 68 { 69 String text = line.trim(); 70 if (text.startsWith("[javac]")) { 71 text = text.substring(7).trim(); 73 } 74 String lookFor = ") : error "; 75 int index = text.indexOf(lookFor); 76 if (index < 0) { 77 lookFor = ") : warning "; 78 index = text.indexOf(lookFor); 79 } 80 if (index >= 0) { 81 int end = text.indexOf('('); 83 if (end >= 0) { 84 String fileName = text.substring(0, end); 85 String s = text.substring(end + 1, index); 86 int lineNumber = 0; 87 try { 88 lineNumber = Integer.parseInt(s); 89 } 90 catch (NumberFormatException e) { 91 return null; 92 } 93 if (lineNumber > 0) { 94 String remainder = text.substring(index + lookFor.length()); 96 String message; 97 if ((index = remainder.indexOf(": ")) >= 0) 98 message = remainder.substring(index + 2).trim(); 99 else 100 message = remainder.trim(); 101 if (message.length() == 0) 102 message = null; 103 return new CompilationError(line, fileName, lineNumber, -1, 104 message); 105 } 106 } 107 return null; 108 } 109 index = text.indexOf(':'); 110 if (Platform.isPlatformWindows() && index == 1) { 111 index = text.indexOf(':', 2); 114 } 115 if (index >= 0) { 116 String fileName = text.substring(0, index).trim(); 117 String remainder = text.substring(index + 1); 118 index = remainder.indexOf(':'); 119 if (index >= 0) { 120 String s = remainder.substring(0, index); 121 int lineNumber = 0; 122 try { 123 lineNumber = Integer.parseInt(s); 124 } 125 catch (NumberFormatException e) { 126 return null; 127 } 128 if (lineNumber > 0) { 129 int offset = -1; 131 remainder = remainder.substring(index + 1); 132 index = remainder.indexOf(':'); 133 if (index >= 0) { 134 s = remainder.substring(0, index); 136 try { 137 offset = Integer.parseInt(s) - 1; 138 } 139 catch (NumberFormatException e) { 140 } 142 } 143 String message; 145 if ((index = remainder.indexOf(": ")) >= 0) 146 message = remainder.substring(index + 2).trim(); 147 else 148 message = remainder.trim(); 149 if (message.length() == 0) 150 message = null; 151 return new CompilationError(line, fileName, lineNumber, 152 offset, message); 153 } 154 } 155 } 156 return null; 157 } 158 } 159 | Popular Tags |