Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add regex-method and tidy up the code
  • Loading branch information
Christian Bender committed Jul 4, 2018
commit 6aeaec5328ff8f3e005dc45996fd25a7398c495b
16 changes: 2 additions & 14 deletions java/src/processing/mode/java/Compiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ static public boolean compile(JavaBuild build) throws SketchException {
SketchException exception = null;
boolean success = false;

// System.out.printf("DEBUG: class Compiler -- BEGIN compile(...)\n"); //DEBUG

String baseCommand[] = new String[] {
"-g",
"-Xemacs",
Expand Down Expand Up @@ -112,9 +110,6 @@ public void close() { }
// so that it can grab the compiler JAR files from it.
ClassLoader loader = build.mode.getClassLoader();

// System.out.printf("DEBUG: class Compiler -- line 114 -- compile(...) exception=%s\n",exception); // DEBUG
// System.err.println(errorBuffer.toString()); //DEBUG

try {
Class<?> batchClass =
Class.forName("org.eclipse.jdt.core.compiler.batch.BatchCompiler", false, loader);
Expand All @@ -125,33 +120,26 @@ public void close() { }
Method compileMethod = batchClass.getMethod("compile", compileArgs);
success = (Boolean)
compileMethod.invoke(null, new Object[] { command, outWriter, writer, null });
// System.err.println(errorBuffer.toString()); //DEBUG

} catch (Exception e) {
e.printStackTrace();
throw new SketchException("Unknown error inside the compiler.");
}

// System.err.println(errorBuffer.toString()); //DEBUG

// Close out the stream for good measure
writer.flush();
writer.close();

BufferedReader reader =
new BufferedReader(new StringReader(errorBuffer.toString()));
// System.err.println(errorBuffer.toString()); //DEBUG

String line = null;
while ((line = reader.readLine()) != null) {
// System.out.println("got line " + line); // debug

// get first line, which contains file name, line number,
// and at least the first line of the error message
String errorFormat = "([\\w\\d_]+.java):(\\d+):\\s*(.*):\\s*(.*)\\s*";
String[] pieces = PApplet.match(line, errorFormat);
// PApplet.println(pieces);
// System.out.println(pieces[4]); //DEBUG

// if it's something unexpected, die and print the mess to the console
if (pieces == null) {
Expand All @@ -173,7 +161,8 @@ public void close() { }
String errorMessage = pieces[4];

// extended error message or certain error message
if (errorMessage.length() <= 3) {

if (!errorMessage.matches("(a-zA-Z| )+")) {
switch (errorMessage) {
case "23)": // cast error: int -> boolean
errorMessage = "int constant cannot be casted into boolean";
Expand All @@ -191,7 +180,6 @@ public void close() { }


if (exception == null) {
// System.err.println(errorMessage); //DEBUG
exception = new SketchException(errorMessage);
}

Expand Down