Skip to content

Commit

Permalink
misc: remove unused variables and cleanup file
Browse files Browse the repository at this point in the history
  • Loading branch information
PranavPurwar committed Apr 21, 2022
1 parent 6374f97 commit d44ac64
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 23 deletions.
6 changes: 0 additions & 6 deletions app/src/main/java/com/pranav/java/ide/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,7 @@ public final class MainActivity extends AppCompatActivity {

public CodeEditor editor;

private long d8Time = 0;
private long ecjTime = 0;

private boolean errorsArePresent = false;

private AlertDialog loadingDialog;
public File file;
public JavaBuilder builder;
private Thread runThread;

Expand Down
34 changes: 17 additions & 17 deletions app/src/main/java/com/pranav/java/ide/compiler/CompileTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class CompileTask extends Thread {

private boolean errorsArePresent = false;

private Context context;
private MainActivity activity;

private CompilerListeners listener;

Expand All @@ -33,7 +33,7 @@ public class CompileTask extends Thread {
public static String STAGE_LOADING_DEX;

public CompileTask(Context context, CompilerListeners listener) {
this.context = (MainActivity) context;
this.activity = (MainActivity) context;
this.listener = listener;

STAGE_CLEAN = context.getString(R.string.stage_clean);
Expand All @@ -50,17 +50,17 @@ public void run() {
// Delete previous build files
listener.OnCurrentBuildStageChanged(STAGE_CLEAN);
FileUtil.deleteFile(FileUtil.getBinDir());
((MainActivity) context).file(FileUtil.getBinDir()).mkdirs();
final File mainFile = ((MainActivity) context).file(
activity.file(FileUtil.getBinDir()).mkdirs();
final File mainFile = activity.file(
FileUtil.getJavaDir() + "Main.java");
Files.createParentDirs(mainFile);
// a simple workaround to prevent calls to system.exit
Files.write(((MainActivity) context).editor.getText().toString()
Files.write(activity.editor.getText().toString()
.replace("System.exit(",
"System.err.print(\"Exit code \" + ")
.getBytes(), mainFile);
} catch (final IOException e) {
((MainActivity) context).dialog("Cannot save program", e.getMessage(), true);
activity.dialog("Cannot save program", e.getMessage(), true);
listener.OnFailed();
}

Expand All @@ -69,14 +69,14 @@ public void run() {
errorsArePresent = true;
try {
listener.OnCurrentBuildStageChanged(STAGE_ECJ);
CompileJavaTask javaTask = new CompileJavaTask(((MainActivity) context).builder);
CompileJavaTask javaTask = new CompileJavaTask(activity.builder);
javaTask.doFullTask();
errorsArePresent = false;
} catch (CompilationFailedException e) {
((MainActivity) context).showErr(e.getMessage());
activity.showErr(e.getMessage());
listener.OnFailed();
} catch (Throwable e) {
((MainActivity) context).showErr(e.getMessage());
activity.showErr(e.getMessage());
listener.OnFailed();
}
if (errorsArePresent) {
Expand All @@ -92,32 +92,32 @@ public void run() {
new D8Task().doFullTask();
} catch (Exception e) {
errorsArePresent = true;
((MainActivity) context).showErr(e.getMessage());
activity.showErr(e.getMessage());
listener.OnFailed();
return;
}
d8Time = System.currentTimeMillis() - time;
// code that loads the final dex
try {
listener.OnCurrentBuildStageChanged(STAGE_LOADING_DEX);
final String[] classes = ((MainActivity) context).getClassesFromDex();
final String[] classes = activity.getClassesFromDex();
if (classes == null) {
return;
}
listener.OnSuccess();
((MainActivity) context).listDialog("Select a class to execute", classes, (dialog, item) -> {
ExecuteJavaTask task = new ExecuteJavaTask(((MainActivity) context).builder, classes[item]);
activity.listDialog("Select a class to execute", classes, (dialog, item) -> {
ExecuteJavaTask task = new ExecuteJavaTask(activity.builder, classes[item]);
try {
task.doFullTask();
} catch (InvocationTargetException e) {
((MainActivity) context).dialog("Failed...",
activity.dialog("Failed...",
"Runtime error: " +
e.getMessage() +
"\n\n" +
e.getMessage(),
true);
} catch (Exception e) {
((MainActivity) context).dialog("Failed..",
activity.dialog("Failed..",
"Couldn't execute the dex: "
+ e.toString()
+ "\n\nSystem logs:\n"
Expand All @@ -133,11 +133,11 @@ public void run() {
s.append(String.valueOf(d8Time));
s.append("ms");

((MainActivity) context).dialog(s.toString(), task.getLogs(), true);
activity.dialog(s.toString(), task.getLogs(), true);
});
} catch (Throwable e) {
listener.OnFailed();
((MainActivity) context).showErr(e.getMessage());
activity.showErr(e.getMessage());
}
}

Expand Down

0 comments on commit d44ac64

Please sign in to comment.