use of com.maddyhome.idea.copyright.psi.UpdateCopyright 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();
}
}
Aggregations