com.intellij.lang.ImportOptimizer Java Examples

The following examples show how to use com.intellij.lang.ImportOptimizer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OptimizeImportsAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void updatePresentation(Presentation presentation, List<ImportOptimizer> importOptimizers) {
  Set<String> actionNames = new LinkedHashSet<>();
  Set<String> actionDescriptions = new LinkedHashSet<>();
  for (ImportOptimizer importOptimizer : importOptimizers) {
    actionNames.add(importOptimizer.getActionName());
    actionDescriptions.add(importOptimizer.getActionDescription());
  }

  if (!actionNames.isEmpty() && !actionDescriptions.isEmpty()) {
    presentation.setText(StringUtil.join(actionNames, " | "));
    presentation.setDescription(StringUtil.join(actionDescriptions, " | "));
  }
  else {
    presentation.setText(ActionsBundle.message("not.action.OptimizeImports.text"));
    presentation.setDescription(ActionsBundle.message("not.action.OptimizeImports.description"));
  }
}
 
Example #2
Source File: HaxeUnusedImportInspection.java    From intellij-haxe with Apache License 2.0 5 votes vote down vote up
public void invoke(@NotNull final Project project, PsiFile file) {
  ImportOptimizer optimizer = new HaxeImportOptimizer();
  final Runnable runnable = optimizer.processFile(file);
  ApplicationManager.getApplication().runWriteAction(new Runnable() {
    public void run() {
      CommandProcessor.getInstance().executeCommand(project, runnable, getFamilyName(), this);
    }
  });
}
 
Example #3
Source File: OptimizeImportsAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@RequiredUIAccess
private void updatePresentationForFiles(@Nonnull Presentation presentation, boolean enabled, @Nonnull List<PsiFile> files) {
  presentation.setEnabled(enabled);

  List<ImportOptimizer> importOptimizers = new ArrayList<>(files.size());
  for (PsiFile file : files) {
    importOptimizers.addAll(LanguageImportStatements.INSTANCE.forFile(file));
  }

  updatePresentation(presentation, importOptimizers);
}
 
Example #4
Source File: OptimizeImportsProcessor.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
@Nonnull
protected FutureTask<Boolean> prepareTask(@Nonnull 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);
}
 
Example #5
Source File: OptimizeImportsProcessor.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void retrieveAndStoreNotificationInfo(@Nonnull Runnable runnable) {
  if (runnable instanceof ImportOptimizer.CollectingInfoRunnable) {
    String optimizerMessage = ((ImportOptimizer.CollectingInfoRunnable)runnable).getUserNotificationInfo();
    myOptimizerNotifications.add(optimizerMessage != null ? new NotificationInfo(optimizerMessage) : NOTHING_CHANGED_NOTIFICATION);
  }
  else if (runnable == EmptyRunnable.getInstance()) {
    myOptimizerNotifications.add(NOTHING_CHANGED_NOTIFICATION);
  }
  else {
    myOptimizerNotifications.add(SOMETHING_CHANGED_WITHOUT_MESSAGE_NOTIFICATION);
  }
}
 
Example #6
Source File: OptimizeImportsAction.java    From consulo with Apache License 2.0 4 votes vote down vote up
public OptimizeImportsAction() {
  List<ImportOptimizer> extensions = LanguageImportStatements.INSTANCE.getExtensions();

  updatePresentation(getTemplatePresentation(), extensions);
}