use of com.intellij.codeInsight.daemon.impl.actions.AddImportAction in project intellij-community by JetBrains.
the class OrderEntryFix method importClass.
public static void importClass(@NotNull Module currentModule, @Nullable Editor editor, @Nullable PsiReference reference, @Nullable String className) {
Project project = currentModule.getProject();
if (editor != null && reference != null && className != null) {
DumbService.getInstance(project).withAlternativeResolveEnabled(() -> {
GlobalSearchScope scope = GlobalSearchScope.moduleWithLibrariesScope(currentModule);
PsiClass aClass = JavaPsiFacade.getInstance(project).findClass(className, scope);
if (aClass != null) {
new AddImportAction(project, reference, editor, aClass).execute();
}
});
}
}
use of com.intellij.codeInsight.daemon.impl.actions.AddImportAction in project intellij-community by JetBrains.
the class ImportClassFixBase method invoke.
@Override
public void invoke(@NotNull final Project project, final Editor editor, final PsiFile file) {
if (!FileModificationService.getInstance().prepareFileForWrite(file))
return;
ApplicationManager.getApplication().runWriteAction(() -> {
List<PsiClass> classesToImport = getClassesToImport(true);
PsiClass[] classes = classesToImport.toArray(new PsiClass[classesToImport.size()]);
if (classes.length == 0)
return;
AddImportAction action = createAddImportAction(classes, project, editor);
action.execute();
});
}
use of com.intellij.codeInsight.daemon.impl.actions.AddImportAction in project intellij-community by JetBrains.
the class AddModuleDependencyFix method addDependencyOnModule.
private void addDependencyOnModule(Project project, Editor editor, @Nullable Module module) {
if (module == null)
return;
Couple<Module> circularModules = ModuleCompilerUtil.addingDependencyFormsCircularity(myCurrentModule, module);
if (circularModules == null || showCircularWarning(project, circularModules, module)) {
WriteAction.run(() -> {
boolean test = ModuleRootManager.getInstance(myCurrentModule).getFileIndex().isInTestSourceContent(myRefVFile);
DependencyScope scope = test ? DependencyScope.TEST : DependencyScope.COMPILE;
JavaProjectModelModificationService.getInstance(project).addDependency(myCurrentModule, module, scope);
if (editor != null && !myClasses.isEmpty()) {
PsiClass[] targetClasses = myClasses.stream().filter(c -> ModuleUtilCore.findModuleForPsiElement(c) == module).toArray(PsiClass[]::new);
if (targetClasses.length > 0 && !DumbService.isDumb(project)) {
new AddImportAction(project, myReference, editor, targetClasses).execute();
}
}
});
}
}
use of com.intellij.codeInsight.daemon.impl.actions.AddImportAction in project intellij-community by JetBrains.
the class MoveClassToModuleFix method moveClass.
private void moveClass(Project project, Editor editor, PsiFile file, PsiClass aClass) {
RefactoringActionHandler moveHandler = RefactoringActionHandlerFactory.getInstance().createMoveHandler();
DataManager dataManager = DataManager.getInstance();
DataContext dataContext = dataManager.getDataContext();
final String fqName = aClass.getQualifiedName();
LOG.assertTrue(fqName != null);
PsiDirectory directory = PackageUtil.findOrCreateDirectoryForPackage(myCurrentModule, StringUtil.getPackageName(fqName), mySourceRoot, true);
DataContext context = SimpleDataContext.getSimpleContext(LangDataKeys.TARGET_PSI_ELEMENT.getName(), directory, dataContext);
moveHandler.invoke(project, new PsiElement[] { aClass }, context);
PsiReference reference = file.findReferenceAt(editor.getCaretModel().getOffset());
PsiClass newClass = JavaPsiFacade.getInstance(project).findClass(fqName, GlobalSearchScope.moduleScope(myCurrentModule));
if (reference != null && newClass != null) {
final QuestionAction action = new AddImportAction(project, reference, editor, newClass);
action.execute();
}
}
Aggregations