Skip to content

Commit

Permalink
retrieve compile directory via the module
Browse files Browse the repository at this point in the history
  • Loading branch information
ollide committed Mar 15, 2015
1 parent 434644b commit 41c8bf7
Showing 1 changed file with 40 additions and 40 deletions.
80 changes: 40 additions & 40 deletions src/org/ollide/java2smali/GenerateAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void actionPerformed(AnActionEvent e) {
Module module = ProjectRootManager.getInstance(p).getFileIndex().getModuleForFile(javaFile.getVirtualFile());

// Compile the javaFile's module
CompilerCallback compilerCallback = new CompilerCallback(javaFile);
CompilerCallback compilerCallback = new CompilerCallback(module, javaFile);
CompilerManager.getInstance(p).compile(module, compilerCallback);
}

Expand Down Expand Up @@ -69,52 +69,52 @@ private static VirtualFile getSourceRootFile(PsiFile file) {
*/
private static class CompilerCallback implements CompileStatusNotification {

private final Module module;
private final PsiJavaFile javaFile;

public CompilerCallback(PsiJavaFile file) {
public CompilerCallback(Module module, PsiJavaFile file) {
this.module = module;
this.javaFile = file;
}

public void finished(boolean b, int i, int i2, CompileContext compileContext) {
VirtualFile[] outputDirectories = compileContext.getAllOutputDirectories();
if (outputDirectories != null && outputDirectories.length > 0) {
String compileDirPath = outputDirectories[0].getPath();
String compiledFilePath = getCompiledClassFilePath(compileDirPath);

String dexFile = compiledFilePath + DEX_EXTENSION;
// CLASS -> DEX
try {
Class2DexHelper.dexClassFile(compiledFilePath, dexFile);
} catch (IOException e) {
e.printStackTrace();
return;
}

// DEX -> SMALI
String outputDir = getSourceRootFile(javaFile).getPath();
try {
Dex2SmaliHelper.disassembleDexFile(dexFile, outputDir);
} catch (IOException e) {
e.printStackTrace();
return;
}

// we've created the smali file in our source file's directory
// refresh directory synchronously to let IDEA detect the file
javaFile.getVirtualFile().getParent().refresh(false, false);

// get a VirtualFile by the IO path
String smaliPath = javaFile.getVirtualFile().getPath().replace(JAVA_EXTENSION, SMALI_EXTENSION);
VirtualFile virtualDexFile = LocalFileSystem.getInstance().findFileByIoFile(new File(smaliPath));
if (virtualDexFile == null) {
// create smali file failed
return;
}

// use the VirtualFile to show the smali file in IDEA editor
OpenFileDescriptor openFileDescriptor = new OpenFileDescriptor(javaFile.getProject(), virtualDexFile);
openFileDescriptor.navigate(true);
VirtualFile outputDirectory = compileContext.getModuleOutputDirectory(module);
String compileDirPath = outputDirectory.getPath();
String compiledFilePath = getCompiledClassFilePath(compileDirPath);

String dexFile = compiledFilePath + DEX_EXTENSION;
// CLASS -> DEX
try {
Class2DexHelper.dexClassFile(compiledFilePath, dexFile);
} catch (IOException e) {
e.printStackTrace();
return;
}

// DEX -> SMALI
String outputDir = getSourceRootFile(javaFile).getPath();
try {
Dex2SmaliHelper.disassembleDexFile(dexFile, outputDir);
} catch (IOException e) {
e.printStackTrace();
return;
}

// we've created the smali file in our source file's directory
// refresh directory synchronously to let IDEA detect the file
javaFile.getVirtualFile().getParent().refresh(false, false);

// get a VirtualFile by the IO path
String smaliPath = javaFile.getVirtualFile().getPath().replace(JAVA_EXTENSION, SMALI_EXTENSION);
VirtualFile virtualDexFile = LocalFileSystem.getInstance().findFileByIoFile(new File(smaliPath));
if (virtualDexFile == null) {
// create smali file failed
return;
}

// use the VirtualFile to show the smali file in IDEA editor
OpenFileDescriptor openFileDescriptor = new OpenFileDescriptor(javaFile.getProject(), virtualDexFile);
openFileDescriptor.navigate(true);
}

private String getCompiledClassFilePath(String dirPath) {
Expand Down

0 comments on commit 41c8bf7

Please sign in to comment.