Guest User

cmplr

a guest
Nov 18th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.56 KB | None | 0 0
  1. import com.intellij.openapi.actionSystem.AnAction;
  2. import com.intellij.openapi.actionSystem.AnActionEvent;
  3. import com.intellij.openapi.actionSystem.CommonDataKeys;
  4. import com.intellij.openapi.compiler.CompilerManager;
  5. import com.intellij.openapi.module.Module;
  6. import com.intellij.openapi.module.ModuleManager;
  7. import com.intellij.openapi.project.Project;
  8. import com.intellij.openapi.roots.ProjectRootManager;
  9. import com.intellij.openapi.vfs.VirtualFile;
  10. import com.intellij.psi.PsiDocumentManager;
  11. import com.intellij.psi.PsiFile;
  12.  
  13. public class CompileAction extends AnAction {
  14.  
  15.     @Override
  16.     public void update(AnActionEvent e) {
  17.         Project project = e.getProject();
  18.         e.getPresentation().setEnabledAndVisible(project != null);
  19.     }
  20.  
  21.     @Override
  22.     public void actionPerformed(AnActionEvent e) {
  23.         Project project = e.getProject();
  24.  
  25.         CompilerManager compilerManager = CompilerManager.getInstance(e.getProject());
  26.  
  27.         PsiDocumentManager psiDocumentManager = PsiDocumentManager.getInstance(project);
  28.         PsiFile psiFile = psiDocumentManager.getPsiFile(e.getData(CommonDataKeys.EDITOR).getDocument());
  29.         VirtualFile virtualFile = psiFile.getVirtualFile();
  30.         Module module = ProjectRootManager.getInstance(project).getFileIndex().getModuleForFile(virtualFile);
  31.  
  32.         compilerManager.compile(module, null);
  33.  
  34.         // Get the Base Dir and refresh with the following parameters
  35.         // 'asynchronous' set to false and 'recursive' set to true
  36.         project.getBaseDir().refresh(false,true);
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment