mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-03-22 06:50:54 +07:00
(no message)
This commit is contained in:
@@ -7,10 +7,13 @@ import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.psi.xml.XmlFile;
|
||||
import com.intellij.psi.PsiFile;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
@@ -24,17 +27,24 @@ public abstract class LightQuickFixTestCase extends LightDaemonAnalyzerTestCase
|
||||
String contents = StringUtil.convertLineSeparators(new String(FileUtil.loadFileText(ioFile)), "\n");
|
||||
configureFromFileText(ioFile.getName(), contents);
|
||||
|
||||
String comment = getFile() instanceof XmlFile ? "<!--" : "//";
|
||||
// "quick fix action text to perform" "should be available"
|
||||
Pattern pattern = Pattern.compile("^"+comment+" \"([^\"]*)\" \"(\\S*)\".*", Pattern.DOTALL);
|
||||
Matcher matcher = pattern.matcher(contents);
|
||||
assertTrue(matcher.matches());
|
||||
final String text = matcher.group(1);
|
||||
final boolean actionShouldBeAvailable = Boolean.valueOf(matcher.group(2)).booleanValue();
|
||||
final Pair<String, Boolean> pair = parseActionHint(getFile());
|
||||
final String text = pair.getFirst();
|
||||
final boolean actionShouldBeAvailable = pair.getSecond().booleanValue();
|
||||
|
||||
doAction(text, actionShouldBeAvailable, testFullPath, testName);
|
||||
}
|
||||
|
||||
public static Pair<String, Boolean> parseActionHint(final PsiFile file) throws IOException {
|
||||
String comment = file instanceof XmlFile ? "<!--" : "//";
|
||||
// "quick fix action text to perform" "should be available"
|
||||
Pattern pattern = Pattern.compile("^" + comment + " \"([^\"]*)\" \"(\\S*)\".*", Pattern.DOTALL);
|
||||
Matcher matcher = pattern.matcher(new String(file.getVirtualFile().contentsToCharArray()));
|
||||
assertTrue(matcher.matches());
|
||||
final String text = matcher.group(1);
|
||||
final Boolean actionShouldBeAvailable = Boolean.valueOf(matcher.group(2));
|
||||
return Pair.create(text, actionShouldBeAvailable);
|
||||
}
|
||||
|
||||
protected void doAction(final String text, final boolean actionShouldBeAvailable, final String testFullPath, final String testName)
|
||||
throws Exception {
|
||||
IntentionAction action = findActionWithText(text);
|
||||
@@ -59,6 +69,10 @@ public abstract class LightQuickFixTestCase extends LightDaemonAnalyzerTestCase
|
||||
|
||||
protected IntentionAction findActionWithText(final String text) {
|
||||
final List<IntentionAction> actions = getAvailableActions();
|
||||
return findActionWithText(actions, text);
|
||||
}
|
||||
|
||||
public static IntentionAction findActionWithText(final List<IntentionAction> actions, final String text) {
|
||||
for (int j = 0; j < actions.size(); j++) {
|
||||
IntentionAction action = actions.get(j);
|
||||
if (text.equals(action.getText())) {
|
||||
@@ -86,7 +100,11 @@ public abstract class LightQuickFixTestCase extends LightDaemonAnalyzerTestCase
|
||||
|
||||
private List<IntentionAction> getAvailableActions() {
|
||||
final HighlightInfo[] infos = doHighlighting();
|
||||
final int offset = getEditor().getCaretModel().getOffset();
|
||||
return getAvailableActions(infos, getEditor(), getFile());
|
||||
}
|
||||
|
||||
public static List<IntentionAction> getAvailableActions(final HighlightInfo[] infos, final Editor editor, final PsiFile file) {
|
||||
final int offset = editor.getCaretModel().getOffset();
|
||||
final List<IntentionAction> availableActions = new ArrayList<IntentionAction>();
|
||||
for (int i = 0; infos != null && i < infos.length; i++) {
|
||||
HighlightInfo info = infos[i];
|
||||
@@ -100,7 +118,7 @@ public abstract class LightQuickFixTestCase extends LightDaemonAnalyzerTestCase
|
||||
IntentionAction action = pair.first;
|
||||
TextRange range = pair.second;
|
||||
if (range.getStartOffset() <= offset && offset <= range.getEndOffset() &&
|
||||
action.isAvailable(getProject(), getEditor(), getFile())) {
|
||||
action.isAvailable(getProject(), editor, file)) {
|
||||
availableActions.add(action);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user