|
| 1 | +/* -*- mode: jde; c-basic-offset: 2; indent-tabs-mode: nil -*- */ |
| 2 | + |
| 3 | +/* |
| 4 | + PdeCompilerJavac - compiler interface to kjc.. someday this will go away |
| 5 | + Part of the Processing project - http://Proce55ing.net |
| 6 | +
|
| 7 | + Copyright (c) 2001-03 |
| 8 | + Ben Fry, Massachusetts Institute of Technology and |
| 9 | + Casey Reas, Interaction Design Institute Ivrea |
| 10 | +
|
| 11 | + This program is free software; you can redistribute it and/or modify |
| 12 | + it under the terms of the GNU General Public License as published by |
| 13 | + the Free Software Foundation; either version 2 of the License, or |
| 14 | + (at your option) any later version. |
| 15 | +
|
| 16 | + This program is distributed in the hope that it will be useful, |
| 17 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | + GNU General Public License for more details. |
| 20 | +
|
| 21 | + You should have received a copy of the GNU General Public License |
| 22 | + along with this program; if not, write to the Free Software Foundation, |
| 23 | + Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 24 | +*/ |
| 25 | + |
| 26 | +import java.io.*; |
| 27 | + |
| 28 | + |
| 29 | +public class PdeCompilerJavac extends PdeCompiler { |
| 30 | + |
| 31 | + public PdeCompilerJavac(String buildPath, |
| 32 | + String className, PdeEditor editor) { |
| 33 | + super(buildPath, className, editor); |
| 34 | + } |
| 35 | + |
| 36 | + public boolean compileJava(PrintStream leechErr) { |
| 37 | + |
| 38 | + // probably not needed with javac |
| 39 | + //System.setErr(leechErr); // redirect stderr to our leech filter |
| 40 | + |
| 41 | + String args[] = new String[3]; |
| 42 | + args[0] = "-d" + buildPath; |
| 43 | + args[1] = "-nowarn"; |
| 44 | + args[2] = buildPath + File.separator + className + ".java"; |
| 45 | + //System.out.println("args = " + args[0] + " " + args[1]); |
| 46 | + |
| 47 | +#ifdef JAVAC |
| 48 | + return new sun.tools.javac.Main(leechErr, "javac").compile(args); |
| 49 | +#else |
| 50 | + return false; |
| 51 | +#endif |
| 52 | + |
| 53 | + // probably not needed with javac |
| 54 | + //System.setErr(PdeEditorConsole.consoleErr); |
| 55 | + |
| 56 | + //System.err.println("success = " + success); |
| 57 | + //return success; |
| 58 | + } |
| 59 | + |
| 60 | + // part of the PdeMessageConsumer interface |
| 61 | + // |
| 62 | + public void message(String s) { |
| 63 | + System.out.println("javac msg: " + s); |
| 64 | + |
| 65 | + // as in: lib\build\Temporary_5476_6442.java:88: caution:Assignment of an expression to itself [KOPI] |
| 66 | + if (s.indexOf("caution") != -1) return; |
| 67 | + |
| 68 | + // |
| 69 | + //System.out.println("leech2: " + new String(b, offset, length)); |
| 70 | + //String s = new String(b, offset, length); |
| 71 | + //if (s.indexOf(tempFilename) == 0) { |
| 72 | + String fullTempFilename = buildPath + File.separator + className + ".java"; |
| 73 | + if (s.indexOf(fullTempFilename) == 0) { |
| 74 | + String s1 = s.substring(fullTempFilename.length() + 1); |
| 75 | + int colon = s1.indexOf(':'); |
| 76 | + int lineNumber = Integer.parseInt(s1.substring(0, colon)); |
| 77 | + //System.out.println("pde / line number: " + lineNumber); |
| 78 | + |
| 79 | + //String s2 = s1.substring(colon + 2); |
| 80 | + int err = s1.indexOf("error:"); |
| 81 | + if (err != -1) { |
| 82 | + //err += "error:".length(); |
| 83 | + String description = s1.substring(err + "error:".length()); |
| 84 | + description = description.trim(); |
| 85 | + |
| 86 | + // as in: ...error:Constructor setup must be named Temporary_5362_2548 [JL1 8.6] |
| 87 | + if(description.indexOf("Constructor setup must be named") != -1) { |
| 88 | + description = "Missing function return type, or constructor does not match class name"; |
| 89 | + } |
| 90 | + //exception = new PdeException(description, lineNumber-2); |
| 91 | + exception = new PdeException(description, lineNumber-1); |
| 92 | + editor.error(exception); |
| 93 | + |
| 94 | + } else { |
| 95 | + System.err.println("i suck: " + s); |
| 96 | + } |
| 97 | + |
| 98 | + } else { |
| 99 | + //System.err.println("don't understand: " + s); |
| 100 | + exception = new PdeException(SUPER_BADNESS); |
| 101 | + editor.error(exception); |
| 102 | + } |
| 103 | + } |
| 104 | +} |
0 commit comments