import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory;
public class Compiler {
+ private static final boolean DEBUG = false;
// Static Entry Point /////////////////////////////////////////////////////
private ClassLoader loader = ClassLoader.getSystemClassLoader();
private Map loaded = new HashMap();
private PrintWriter out = new PrintWriter(System.out);
- private Preprocessor preprocessor = new Preprocessor(null, null, Collections.EMPTY_LIST);
+ private Preprocessor preprocessor;
private Source[] sources;
private File builddir = new File(".");
- private File sourcedir = new File(".");
+ private String sourcedir = null;
+
+ public Compiler() {
+ List defs = Collections.EMPTY_LIST;
+
+ String define = System.getProperty("org.ibex.tool.preprocessor.define");
+ if (define != null) {
+ defs = new ArrayList();
+ StringTokenizer st = new StringTokenizer(define.toUpperCase(), ",");
+ while (st.hasMoreTokens()) defs.add(st.nextToken().trim());
+ }
+
+ preprocessor = new Preprocessor(null, null, defs);
+ }
- public Compiler() { }
public void setBuildDir(String dir) { builddir = new File(dir == null ? "." : dir); }
- public void setSourceDir(String dir) { sourcedir = new File(dir == null ? "." : dir); }
+ public void setSourceDir(String dir) { sourcedir = dir; }
/** Pass CompilerOptions.VERSION_1_*. A String of form "1.1", ".2", etc. */
public void setSource(String v) { settings.put(CompilerOptions.OPTION_Source, v); }
public void compile() {
List s = new ArrayList();
- filterSources(s, sourcedir, new char[0][]);
- System.out.println("working with "+s.size() +" sources");
+ filterSources(s, new File(sourcedir), new char[0][]);
+ if (DEBUG) System.out.println("working with "+s.size() +" sources");
sources = new Source[s.size()]; s.toArray(sources);
ICompilationUnit[] units = new ICompilationUnit[s.size()];
for (int i=0; i < sources.length; i++) units[i] = sources[i].unit;
- System.out.println("compiling");
org.eclipse.jdt.internal.compiler.Compiler jdt =
new org.eclipse.jdt.internal.compiler.Compiler(
env, policy, settings, results, problems);
private Source(File o, char[] n, char[][] p) {
orig = o; this.n = n; this.p = p;
- try { fileName = orig.getCanonicalPath().toCharArray(); } // FIXME: dont use full path
- catch (IOException e) { fileName = orig.getName().toCharArray(); }
+ String file = sourcedir;
+ file += File.separatorChar + str(p, File.separatorChar);
+ file += File.separatorChar + new String(n) + ".java";
+ fileName = file.toCharArray();
}
}
for (int i=0; i < ex.length; i++) ex[i] = name(exs[i]);
desc = descriptor(m.getParameterTypes(), m.getReturnType());
- /*if (new String(desc).indexOf("[") > -1)
- System.out.println("method: "+m+", desc="+new String(desc));*/ // DEBUG
}
public int getModifiers() { return m.getModifiers(); }
public char[] getSelector() { return m.getName().toCharArray(); }
for (int i=0; i < nested.length; i++)
nested[i] = new LoadedNestedType(classes[i]);
- Constructor[] constructors = c.getConstructors();
+ Constructor[] constructors = c.getDeclaredConstructors();
Method[] methods = c.getDeclaredMethods();
if (methods.length + constructors.length > 0) {
meth = new IBinaryMethod[methods.length + constructors.length];
final INameEnvironment env = new INameEnvironment() {
public NameEnvironmentAnswer findType(char[][] c) { return findType(name(c), pack(c)); }
public NameEnvironmentAnswer findType(char[] n, char[][] p) {
- boolean DEBUG = false;
if (DEBUG) System.out.println("requesting: "+ str(p, '.') + "."+new String(n));
try {
/** Used by compiler for processing compiled classes and their errors. */
private final ICompilerRequestor results = new ICompilerRequestor() {
public void acceptResult(CompilationResult result) {
- System.out.println("got result: "+result);
+ if (DEBUG) System.out.println("got result: "+result);
if (result.hasProblems()) {
boolean hasErrors = false;
IProblem[] p = result.getProblems();
for (int i=0; i < p.length; i++) {
- if (p[i].isError()) hasErrors = true;
out.print(p[i].getOriginatingFileName());
out.print(':');
out.print(p[i].getSourceLineNumber());
out.print(':');
+ if (p[i].isError()) { out.print(" error: "); hasErrors = true; }
+ else out.print(" warning: ");
out.println(p[i].getMessage());
}
out.flush();
File path = builddir;
char[][] name = c[i].getCompoundName();
path = new File(builddir, str(pack(name), '/'));
- System.out.println("DEBUG: creating path "+path+", out of builddir="+builddir);
+ if (DEBUG) System.out.println("DEBUG: creating path "+path+", out of builddir="+builddir);
if (!path.exists()) path.mkdirs();
// write new class file
path = new File(path, new String(name(name)) + ".class");
- System.out.println("DEBUG: writing file "+path);
+ if (DEBUG) System.out.println("DEBUG: writing file "+path);
OutputStream o = new BufferedOutputStream(
new FileOutputStream(path));
o.write(c[i].getBytes());