@@ -37,7 +37,7 @@ public void actionPerformed(AnActionEvent e) {
3737 Module module = ProjectRootManager .getInstance (p ).getFileIndex ().getModuleForFile (javaFile .getVirtualFile ());
3838
3939 // Compile the javaFile's module
40- CompilerCallback compilerCallback = new CompilerCallback (javaFile );
40+ CompilerCallback compilerCallback = new CompilerCallback (module , javaFile );
4141 CompilerManager .getInstance (p ).compile (module , compilerCallback );
4242 }
4343
@@ -69,52 +69,52 @@ private static VirtualFile getSourceRootFile(PsiFile file) {
6969 */
7070 private static class CompilerCallback implements CompileStatusNotification {
7171
72+ private final Module module ;
7273 private final PsiJavaFile javaFile ;
7374
74- public CompilerCallback (PsiJavaFile file ) {
75+ public CompilerCallback (Module module , PsiJavaFile file ) {
76+ this .module = module ;
7577 this .javaFile = file ;
7678 }
7779
7880 public void finished (boolean b , int i , int i2 , CompileContext compileContext ) {
79- VirtualFile [] outputDirectories = compileContext .getAllOutputDirectories ();
80- if (outputDirectories != null && outputDirectories .length > 0 ) {
81- String compileDirPath = outputDirectories [0 ].getPath ();
82- String compiledFilePath = getCompiledClassFilePath (compileDirPath );
83-
84- String dexFile = compiledFilePath + DEX_EXTENSION ;
85- // CLASS -> DEX
86- try {
87- Class2DexHelper .dexClassFile (compiledFilePath , dexFile );
88- } catch (IOException e ) {
89- e .printStackTrace ();
90- return ;
91- }
92-
93- // DEX -> SMALI
94- String outputDir = getSourceRootFile (javaFile ).getPath ();
95- try {
96- Dex2SmaliHelper .disassembleDexFile (dexFile , outputDir );
97- } catch (IOException e ) {
98- e .printStackTrace ();
99- return ;
100- }
101-
102- // we've created the smali file in our source file's directory
103- // refresh directory synchronously to let IDEA detect the file
104- javaFile .getVirtualFile ().getParent ().refresh (false , false );
105-
106- // get a VirtualFile by the IO path
107- String smaliPath = javaFile .getVirtualFile ().getPath ().replace (JAVA_EXTENSION , SMALI_EXTENSION );
108- VirtualFile virtualDexFile = LocalFileSystem .getInstance ().findFileByIoFile (new File (smaliPath ));
109- if (virtualDexFile == null ) {
110- // create smali file failed
111- return ;
112- }
113-
114- // use the VirtualFile to show the smali file in IDEA editor
115- OpenFileDescriptor openFileDescriptor = new OpenFileDescriptor (javaFile .getProject (), virtualDexFile );
116- openFileDescriptor .navigate (true );
81+ VirtualFile outputDirectory = compileContext .getModuleOutputDirectory (module );
82+ String compileDirPath = outputDirectory .getPath ();
83+ String compiledFilePath = getCompiledClassFilePath (compileDirPath );
84+
85+ String dexFile = compiledFilePath + DEX_EXTENSION ;
86+ // CLASS -> DEX
87+ try {
88+ Class2DexHelper .dexClassFile (compiledFilePath , dexFile );
89+ } catch (IOException e ) {
90+ e .printStackTrace ();
91+ return ;
11792 }
93+
94+ // DEX -> SMALI
95+ String outputDir = getSourceRootFile (javaFile ).getPath ();
96+ try {
97+ Dex2SmaliHelper .disassembleDexFile (dexFile , outputDir );
98+ } catch (IOException e ) {
99+ e .printStackTrace ();
100+ return ;
101+ }
102+
103+ // we've created the smali file in our source file's directory
104+ // refresh directory synchronously to let IDEA detect the file
105+ javaFile .getVirtualFile ().getParent ().refresh (false , false );
106+
107+ // get a VirtualFile by the IO path
108+ String smaliPath = javaFile .getVirtualFile ().getPath ().replace (JAVA_EXTENSION , SMALI_EXTENSION );
109+ VirtualFile virtualDexFile = LocalFileSystem .getInstance ().findFileByIoFile (new File (smaliPath ));
110+ if (virtualDexFile == null ) {
111+ // create smali file failed
112+ return ;
113+ }
114+
115+ // use the VirtualFile to show the smali file in IDEA editor
116+ OpenFileDescriptor openFileDescriptor = new OpenFileDescriptor (javaFile .getProject (), virtualDexFile );
117+ openFileDescriptor .navigate (true );
118118 }
119119
120120 private String getCompiledClassFilePath (String dirPath ) {
0 commit comments