Search in sources :

Example 1 with UpdatePsiFileCopyright

use of com.maddyhome.idea.copyright.psi.UpdatePsiFileCopyright in project intellij-community by JetBrains.

the class UpdateCopyrightProcessor method preprocessFile.

protected Runnable preprocessFile(final PsiFile file, final boolean allowReplacement) throws IncorrectOperationException {
    VirtualFile vfile = file.getVirtualFile();
    if (vfile == null)
        return EmptyRunnable.getInstance();
    final ProgressIndicator progressIndicator = ProgressManager.getInstance().getProgressIndicator();
    if (progressIndicator != null) {
        progressIndicator.setText2(vfile.getPresentableUrl());
    }
    Module mod = module;
    if (module == null) {
        mod = ProjectRootManager.getInstance(project).getFileIndex().getModuleForFile(vfile);
    }
    if (mod == null)
        return EmptyRunnable.getInstance();
    CopyrightProfile opts = CopyrightManager.getInstance(project).getCopyrightOptions(file);
    if (opts != null && FileTypeUtil.isSupportedFile(file)) {
        logger.debug("process " + file);
        final UpdateCopyright update = UpdateCopyrightFactory.createUpdateCopyright(project, mod, file, opts);
        if (update == null)
            return EmptyRunnable.getInstance();
        update.prepare();
        if (update instanceof UpdatePsiFileCopyright && !((UpdatePsiFileCopyright) update).hasUpdates())
            return EmptyRunnable.getInstance();
        return () -> {
            try {
                if (update instanceof UpdatePsiFileCopyright) {
                    ((UpdatePsiFileCopyright) update).complete(allowReplacement);
                } else {
                    update.complete();
                }
            } catch (Exception e) {
                logger.error(e);
            }
        };
    } else {
        return EmptyRunnable.getInstance();
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) CopyrightProfile(com.maddyhome.idea.copyright.CopyrightProfile) Module(com.intellij.openapi.module.Module) UpdateCopyright(com.maddyhome.idea.copyright.psi.UpdateCopyright) UpdatePsiFileCopyright(com.maddyhome.idea.copyright.psi.UpdatePsiFileCopyright) IncorrectOperationException(com.intellij.util.IncorrectOperationException)

Aggregations

Module (com.intellij.openapi.module.Module)1 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 IncorrectOperationException (com.intellij.util.IncorrectOperationException)1 CopyrightProfile (com.maddyhome.idea.copyright.CopyrightProfile)1 UpdateCopyright (com.maddyhome.idea.copyright.psi.UpdateCopyright)1 UpdatePsiFileCopyright (com.maddyhome.idea.copyright.psi.UpdatePsiFileCopyright)1