mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-03-22 15:19:59 +07:00
Java: make "Generate toString" dumb aware (IDEA-342761)
GitOrigin-RevId: 1f7cd75dbbb63bc6d305a7aa9655dab72c93dde6
This commit is contained in:
committed by
intellij-monorepo-bot
parent
55c8e18dc9
commit
5d3e2a6424
@@ -16,12 +16,13 @@
|
||||
package org.jetbrains.java.generate;
|
||||
|
||||
import com.intellij.codeInsight.generation.actions.BaseGenerateAction;
|
||||
import com.intellij.openapi.project.DumbAware;
|
||||
|
||||
/**
|
||||
* This action handles the generation of a {@code toString()} method that dumps the fields
|
||||
* of the class.
|
||||
*/
|
||||
public class GenerateToStringAction extends BaseGenerateAction {
|
||||
public class GenerateToStringAction extends BaseGenerateAction implements DumbAware {
|
||||
|
||||
public GenerateToStringAction() {
|
||||
super(new GenerateToStringActionHandlerImpl());
|
||||
|
||||
@@ -31,6 +31,7 @@ import com.intellij.openapi.options.Configurable;
|
||||
import com.intellij.openapi.options.ConfigurationException;
|
||||
import com.intellij.openapi.options.ShowSettingsUtil;
|
||||
import com.intellij.openapi.options.TabbedConfigurable;
|
||||
import com.intellij.openapi.project.DumbService;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.ComboBox;
|
||||
import com.intellij.openapi.ui.ComponentValidator;
|
||||
@@ -236,13 +237,16 @@ public class GenerateToStringActionHandlerImpl implements GenerateToStringAction
|
||||
|
||||
comboBox = new ComboBox<>(templates.toArray(new TemplateResource[0]));
|
||||
comboBox.addActionListener(e -> updateErrorMessage());
|
||||
final JavaPsiFacade instance = JavaPsiFacade.getInstance(clazz.getProject());
|
||||
Project project = clazz.getProject();
|
||||
final JavaPsiFacade instance = JavaPsiFacade.getInstance(project);
|
||||
final GlobalSearchScope resolveScope = clazz.getResolveScope();
|
||||
DumbService dumbService = DumbService.getInstance(project);
|
||||
ReadAction.nonBlocking(() -> {
|
||||
final Set<TemplateResource> invalid = new HashSet<>();
|
||||
for (TemplateResource template : templates) {
|
||||
String className = template.getClassName();
|
||||
if (className != null && instance.findClass(className, resolveScope) == null) {
|
||||
if (className != null &&
|
||||
dumbService.computeWithAlternativeResolveEnabled(() -> instance.findClass(className, resolveScope)) == null) {
|
||||
invalid.add(template);
|
||||
}
|
||||
}
|
||||
@@ -263,13 +267,13 @@ public class GenerateToStringActionHandlerImpl implements GenerateToStringAction
|
||||
settingsButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
final TemplatesPanel ui = new TemplatesPanel(clazz.getProject());
|
||||
final TemplatesPanel ui = new TemplatesPanel(project);
|
||||
Configurable composite = new TabbedConfigurable() {
|
||||
@Override
|
||||
@NotNull
|
||||
protected List<Configurable> createConfigurables() {
|
||||
List<Configurable> res = new ArrayList<>();
|
||||
res.add(new GenerateToStringConfigurable(clazz.getProject()));
|
||||
res.add(new GenerateToStringConfigurable(project));
|
||||
res.add(ui);
|
||||
return res;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user