Making compiler exit codes type safe. Fixes the problem with wrong command-line argument usage being missed by the IDE

This commit is contained in:
Andrey Breslav
2012-03-16 20:19:27 +04:00
parent fda2bc25dc
commit 9c58e5b45c
4 changed files with 41 additions and 21 deletions
@@ -274,8 +274,10 @@ public class JetCompiler implements TranslatingCompiler {
context.addMessage(INFORMATION, "Invoking in-process compiler " + compilerClassName + " with arguments " + Arrays.asList(arguments), "", -1, -1);
Object rc = exec.invoke(kompiler.newInstance(), out, arguments);
if (rc instanceof Integer) {
return ((Integer) rc).intValue();
// exec() returns a KotlinCompiler.ExitCode object, that class is not accessible here,
// so we take it's contents through reflection
if ("org.jetbrains.jet.cli.KotlinCompiler.ExitCode".equals(rc.getClass().getCanonicalName())) {
return (Integer) rc.getClass().getMethod("getCode").invoke(rc);
}
else {
throw new IllegalStateException("Unexpected return: " + rc);
@@ -150,8 +150,8 @@ public class LibrariesTest extends PlatformTestCase {
protected void setUp() throws Exception {
super.setUp();
String libraryDir = FileUtil.getTempDirectory();
int compilerExec = new KotlinCompiler().exec("-src", TEST_DATA_PATH + "/library", "-output", libraryDir);
assertEquals(0, compilerExec);
KotlinCompiler.ExitCode compilerExec = new KotlinCompiler().exec("-src", TEST_DATA_PATH + "/library", "-output", libraryDir);
assertEquals(KotlinCompiler.ExitCode.OK, compilerExec);
myLibraryDir = LocalFileSystem.getInstance().findFileByPath(libraryDir);
assertNotNull(myLibraryDir);
@@ -168,4 +168,4 @@ public class LibrariesTest extends PlatformTestCase {
}
});
}
}
}