コード例 #1
0
  public static void removeDuplicatingClasses(
      final Module module,
      @NotNull final String packageName,
      @NotNull String className,
      @Nullable File classFile,
      String sourceRootPath) {
    if (sourceRootPath == null) {
      return;
    }
    VirtualFile sourceRoot = LocalFileSystem.getInstance().findFileByPath(sourceRootPath);
    if (sourceRoot == null) {
      return;
    }
    final Project project = module.getProject();
    final JavaPsiFacade facade = JavaPsiFacade.getInstance(project);
    final String interfaceQualifiedName = packageName + '.' + className;
    PsiClass[] classes =
        facade.findClasses(interfaceQualifiedName, GlobalSearchScope.moduleScope(module));
    final ProjectFileIndex projectFileIndex =
        ProjectRootManager.getInstance(project).getFileIndex();
    for (PsiClass c : classes) {
      PsiFile psiFile = c.getContainingFile();
      if (className.equals(FileUtil.getNameWithoutExtension(psiFile.getName()))) {
        VirtualFile virtualFile = psiFile.getVirtualFile();
        if (virtualFile != null
            && projectFileIndex.getSourceRootForFile(virtualFile) == sourceRoot) {
          final String path = virtualFile.getPath();
          File f = new File(path);

          try {
            f = f.getCanonicalFile();
            classFile = classFile != null ? classFile.getCanonicalFile() : null;
            if (f != null && !f.equals(classFile) && f.exists()) {
              if (f.delete()) {
                virtualFile.refresh(true, false);
              } else {
                ApplicationManager.getApplication()
                    .invokeLater(
                        new Runnable() {
                          public void run() {
                            Messages.showErrorDialog(
                                project, "Can't delete file " + path, CommonBundle.getErrorTitle());
                          }
                        },
                        project.getDisposed());
              }
            }
          } catch (IOException e) {
            LOG.info(e);
          }
        }
      }
    }
  }
コード例 #2
0
 public BackendCompilerWrapper(
     TranslatingCompiler translatingCompiler,
     Chunk<Module> chunk,
     @NotNull final Project project,
     @NotNull List<VirtualFile> filesToCompile,
     @NotNull CompileContextEx compileContext,
     @NotNull BackendCompiler compiler,
     TranslatingCompiler.OutputSink sink) {
   myTranslatingCompiler = translatingCompiler;
   myChunk = chunk;
   myProject = project;
   myCompiler = compiler;
   myCompileContext = compileContext;
   myFilesToCompile = filesToCompile;
   mySink = sink;
   myProjectFileIndex = ProjectRootManager.getInstance(myProject).getFileIndex();
   CompileStatistics stat = compileContext.getUserData(CompileStatistics.KEY);
   if (stat == null) {
     stat = new CompileStatistics();
     compileContext.putUserData(CompileStatistics.KEY, stat);
   }
   myStatistics = stat;
 }