use of com.intellij.lang.ImportOptimizer in project intellij-community by JetBrains.
the class OptimizeImportsQuickFix method optimizeImports.
private void optimizeImports(final Project project, final PsiFile file) {
ImportOptimizer optimizer = new PyImportOptimizer();
final Runnable runnable = optimizer.processFile(file);
new WriteCommandAction.Simple(project, getFamilyName(), file) {
@Override
protected void run() throws Throwable {
runnable.run();
}
}.execute();
}
use of com.intellij.lang.ImportOptimizer in project intellij-community by JetBrains.
the class OptimizeImportsProcessor method prepareTask.
@Override
@NotNull
protected FutureTask<Boolean> prepareTask(@NotNull PsiFile file, boolean processChangedTextOnly) {
if (DumbService.isDumb(file.getProject())) {
return new FutureTask<>(EmptyRunnable.INSTANCE, true);
}
final Set<ImportOptimizer> optimizers = LanguageImportStatements.INSTANCE.forFile(file);
final List<Runnable> runnables = new ArrayList<>();
List<PsiFile> files = file.getViewProvider().getAllFiles();
for (ImportOptimizer optimizer : optimizers) {
for (PsiFile psiFile : files) {
if (optimizer.supports(psiFile)) {
runnables.add(optimizer.processFile(psiFile));
}
}
}
Runnable runnable = !runnables.isEmpty() ? () -> {
CodeStyleManagerImpl.setSequentialProcessingAllowed(false);
try {
for (Runnable runnable1 : runnables) {
runnable1.run();
retrieveAndStoreNotificationInfo(runnable1);
}
putNotificationInfoIntoCollector();
} finally {
CodeStyleManagerImpl.setSequentialProcessingAllowed(true);
}
} : EmptyRunnable.getInstance();
return new FutureTask<>(runnable, true);
}
use of com.intellij.lang.ImportOptimizer in project intellij-plugins by JetBrains.
the class ActionScriptUnusedImportsPassFactory method createOptimizeImportsIntention.
private static IntentionAction createOptimizeImportsIntention() {
return new IntentionAction() {
@NotNull
public String getText() {
return JSBundle.message("javascript.fix.optimize.imports");
}
@NotNull
public String getFamilyName() {
return getText();
}
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
return true;
}
public void invoke(@NotNull final Project project, Editor editor, PsiFile file) {
ImportOptimizer optimizer = new ECMAScriptImportOptimizer();
final Runnable runnable = optimizer.processFile(file);
ApplicationManager.getApplication().runWriteAction(new Runnable() {
public void run() {
CommandProcessor.getInstance().executeCommand(project, runnable, getFamilyName(), this);
}
});
}
public boolean startInWriteAction() {
return true;
}
};
}
Aggregations