mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
start local fix without write action (IDEA-163184)
This commit is contained in:
+56
-54
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -31,7 +31,6 @@ import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.search.PsiNonJavaFileReferenceProcessor;
|
||||
import com.intellij.psi.search.PsiSearchHelper;
|
||||
import com.intellij.psi.util.PsiClassUtil;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
@@ -46,7 +45,6 @@ import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@@ -94,25 +92,23 @@ public class UndeclaredTestInspection extends BaseJavaLocalInspectionTool {
|
||||
final boolean isFullName = qName.equals(name);
|
||||
final boolean[] found = new boolean[]{false};
|
||||
PsiSearchHelper.SERVICE.getInstance(project)
|
||||
.processUsagesInNonJavaFiles(name, new PsiNonJavaFileReferenceProcessor() {
|
||||
public boolean process(final PsiFile file, final int startOffset, final int endOffset) {
|
||||
if (file.findReferenceAt(startOffset) != null) {
|
||||
if (!isFullName) { //special package tag required
|
||||
final XmlTag tag = PsiTreeUtil.getParentOfType(file.findElementAt(startOffset), XmlTag.class);
|
||||
if (tag == null || !tag.getName().equals("package")) {
|
||||
return true;
|
||||
}
|
||||
final XmlAttribute attribute = tag.getAttribute("name");
|
||||
if (attribute == null) return true;
|
||||
final String value = attribute.getValue();
|
||||
if (value == null) return true;
|
||||
if (!value.endsWith(".*") && !value.equals(packageQName)) return true;
|
||||
.processUsagesInNonJavaFiles(name, (file, startOffset, endOffset) -> {
|
||||
if (file.findReferenceAt(startOffset) != null) {
|
||||
if (!isFullName) { //special package tag required
|
||||
final XmlTag tag = PsiTreeUtil.getParentOfType(file.findElementAt(startOffset), XmlTag.class);
|
||||
if (tag == null || !tag.getName().equals("package")) {
|
||||
return true;
|
||||
}
|
||||
found[0] = true;
|
||||
return false;
|
||||
final XmlAttribute attribute = tag.getAttribute("name");
|
||||
if (attribute == null) return true;
|
||||
final String value = attribute.getValue();
|
||||
if (value == null) return true;
|
||||
if (!value.endsWith(".*") && !value.equals(packageQName)) return true;
|
||||
}
|
||||
return true;
|
||||
found[0] = true;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}, new TestNGSearchScope(project));
|
||||
if (found[0]) return null;
|
||||
}
|
||||
@@ -146,20 +142,23 @@ public class UndeclaredTestInspection extends BaseJavaLocalInspectionTool {
|
||||
public void applyFix(@NotNull final Project project, @NotNull ProblemDescriptor descriptor) {
|
||||
final PsiClass psiClass = PsiTreeUtil.getParentOfType(descriptor.getPsiElement(), PsiClass.class);
|
||||
LOG.assertTrue(psiClass != null);
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
final String testngXmlPath = new SuiteBrowser(project).showDialog();
|
||||
if (testngXmlPath == null) return;
|
||||
final VirtualFile virtualFile = LocalFileSystem.getInstance().findFileByPath(testngXmlPath);
|
||||
LOG.assertTrue(virtualFile != null);
|
||||
final PsiFile psiFile = PsiManager.getInstance(project).findFile(virtualFile);
|
||||
LOG.assertTrue(psiFile instanceof XmlFile);
|
||||
final XmlFile testngXML = (XmlFile)psiFile;
|
||||
new WriteCommandAction(project, getName(), testngXML) {
|
||||
protected void run(@NotNull final Result result) throws Throwable {
|
||||
patchTestngXml(testngXML, psiClass);
|
||||
}
|
||||
}.execute();
|
||||
});
|
||||
final String testngXmlPath = new SuiteBrowser(project).showDialog();
|
||||
if (testngXmlPath == null) return;
|
||||
final VirtualFile virtualFile = LocalFileSystem.getInstance().findFileByPath(testngXmlPath);
|
||||
LOG.assertTrue(virtualFile != null);
|
||||
final PsiFile psiFile = PsiManager.getInstance(project).findFile(virtualFile);
|
||||
LOG.assertTrue(psiFile instanceof XmlFile);
|
||||
final XmlFile testngXML = (XmlFile)psiFile;
|
||||
new WriteCommandAction(project, getName(), testngXML) {
|
||||
protected void run(@NotNull final Result result) throws Throwable {
|
||||
patchTestngXml(testngXML, psiClass);
|
||||
}
|
||||
}.execute();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean startInWriteAction() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -196,28 +195,31 @@ public class UndeclaredTestInspection extends BaseJavaLocalInspectionTool {
|
||||
|
||||
public void applyFix(@NotNull final Project project, @NotNull final ProblemDescriptor descriptor) {
|
||||
final PsiClass psiClass = PsiTreeUtil.getParentOfType(descriptor.getPsiElement(), PsiClass.class);
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
final VirtualFile file = FileChooser.chooseFile(FileChooserDescriptorFactory.createSingleFolderDescriptor(), project, null);
|
||||
if (file != null) {
|
||||
final PsiManager psiManager = PsiManager.getInstance(project);
|
||||
final PsiDirectory directory = psiManager.findDirectory(file);
|
||||
LOG.assertTrue(directory != null);
|
||||
new WriteCommandAction(project, getName(), null) {
|
||||
protected void run(@NotNull final Result result) throws Throwable {
|
||||
XmlFile testngXml = (XmlFile)PsiFileFactory.getInstance(psiManager.getProject())
|
||||
.createFileFromText("testng.xml", "<!DOCTYPE suite SYSTEM \"http://testng.org/testng-1.0.dtd\">\n<suite></suite>");
|
||||
try {
|
||||
testngXml = (XmlFile)directory.add(testngXml);
|
||||
}
|
||||
catch (IncorrectOperationException e) {
|
||||
//todo suggest new name
|
||||
return;
|
||||
}
|
||||
patchTestngXml(testngXml, psiClass);
|
||||
final VirtualFile file = FileChooser.chooseFile(FileChooserDescriptorFactory.createSingleFolderDescriptor(), project, null);
|
||||
if (file != null) {
|
||||
final PsiManager psiManager = PsiManager.getInstance(project);
|
||||
final PsiDirectory directory = psiManager.findDirectory(file);
|
||||
LOG.assertTrue(directory != null);
|
||||
new WriteCommandAction(project, getName(), null) {
|
||||
protected void run(@NotNull final Result result) throws Throwable {
|
||||
XmlFile testngXml = (XmlFile)PsiFileFactory.getInstance(psiManager.getProject())
|
||||
.createFileFromText("testng.xml", "<!DOCTYPE suite SYSTEM \"http://testng.org/testng-1.0.dtd\">\n<suite></suite>");
|
||||
try {
|
||||
testngXml = (XmlFile)directory.add(testngXml);
|
||||
}
|
||||
}.execute();
|
||||
}
|
||||
});
|
||||
catch (IncorrectOperationException e) {
|
||||
//todo suggest new name
|
||||
return;
|
||||
}
|
||||
patchTestngXml(testngXml, psiClass);
|
||||
}
|
||||
}.execute();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean startInWriteAction() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user