mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
refactor QuickFixTestCase: encapsulate action hint in separate object; unify error reporting
This commit is contained in:
+4
-4
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2011 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.
|
||||
@@ -24,12 +24,12 @@ import org.jetbrains.annotations.NotNull;
|
||||
*/
|
||||
public class DelegateWithDefaultParamValueTest extends LightQuickFixParameterizedTestCase {
|
||||
@Override
|
||||
protected void doAction(@NotNull String text, boolean actionShouldBeAvailable, String testFullPath, String testName)
|
||||
protected void doAction(@NotNull ActionHint actionHint, String testFullPath, String testName)
|
||||
throws Exception {
|
||||
TemplateManagerImpl.setTemplateTesting(getProject(), getTestRootDisposable());
|
||||
super.doAction(text, actionShouldBeAvailable, testFullPath, testName);
|
||||
super.doAction(actionHint, testFullPath, testName);
|
||||
|
||||
if (actionShouldBeAvailable) {
|
||||
if (actionHint.shouldPresent()) {
|
||||
TemplateState state = TemplateManagerImpl.getTemplateState(getEditor());
|
||||
if (state != null) {
|
||||
state.gotoEnd(false);
|
||||
|
||||
+18
-6
@@ -1,3 +1,18 @@
|
||||
/*
|
||||
* 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.codeInsight.daemon.quickFix;
|
||||
|
||||
import com.intellij.codeInsight.CodeInsightSettings;
|
||||
@@ -17,17 +32,14 @@ public class EnableOptimizeImportsOnTheFlyTest extends LightQuickFixParameterize
|
||||
public void test() throws Exception { doAllTests(); }
|
||||
|
||||
@Override
|
||||
protected void doAction(@NotNull final String text, final boolean actionShouldBeAvailable, final String testFullPath, final String testName)
|
||||
protected void doAction(@NotNull final ActionHint actionHint, final String testFullPath, final String testName)
|
||||
throws Exception {
|
||||
boolean old = CodeInsightSettings.getInstance().OPTIMIZE_IMPORTS_ON_THE_FLY;
|
||||
|
||||
try {
|
||||
CodeInsightSettings.getInstance().OPTIMIZE_IMPORTS_ON_THE_FLY = false;
|
||||
IntentionAction action = findActionWithText(text);
|
||||
if (action == null && actionShouldBeAvailable) {
|
||||
fail("Action with text '" + text + "' is not available in test " + testFullPath);
|
||||
}
|
||||
if (action != null && actionShouldBeAvailable) {
|
||||
IntentionAction action = findActionAndCheck(actionHint, testFullPath);
|
||||
if (action != null) {
|
||||
action.invoke(getProject(), getEditor(), getFile());
|
||||
assertTrue(CodeInsightSettings.getInstance().OPTIMIZE_IMPORTS_ON_THE_FLY);
|
||||
}
|
||||
|
||||
+17
-6
@@ -1,6 +1,20 @@
|
||||
/*
|
||||
* 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.codeInsight.daemon.quickFix;
|
||||
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
@@ -9,11 +23,8 @@ import org.jetbrains.annotations.NotNull;
|
||||
*/
|
||||
public abstract class LightQuickFixAvailabilityTestCase extends LightQuickFixParameterizedTestCase {
|
||||
@Override
|
||||
protected void doAction(@NotNull final String text, final boolean actionShouldBeAvailable, final String testFullPath, final String testName)
|
||||
protected void doAction(@NotNull final ActionHint actionHint, final String testFullPath, final String testName)
|
||||
throws Exception {
|
||||
IntentionAction action = findActionWithText(text);
|
||||
assertTrue("Action with text '" + text + "' is " + (action == null ? "not " :"") +
|
||||
"available in test " + testFullPath,
|
||||
(action != null) == actionShouldBeAvailable);
|
||||
findActionAndCheck(actionHint, testFullPath);
|
||||
}
|
||||
}
|
||||
|
||||
+18
-23
@@ -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.
|
||||
@@ -28,7 +28,6 @@ import com.intellij.openapi.roots.ModifiableRootModel;
|
||||
import com.intellij.openapi.roots.ModuleRootManager;
|
||||
import com.intellij.openapi.roots.ModuleRootModificationUtil;
|
||||
import com.intellij.openapi.roots.OrderEntry;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.testFramework.PsiTestUtil;
|
||||
@@ -63,8 +62,12 @@ public class OrderEntryTest extends DaemonAnalyzerTestCase {
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
removeLibs();
|
||||
super.tearDown();
|
||||
try {
|
||||
removeLibs();
|
||||
}
|
||||
finally {
|
||||
super.tearDown();
|
||||
}
|
||||
}
|
||||
|
||||
private void doTest(String fileName) throws Exception {
|
||||
@@ -73,40 +76,32 @@ public class OrderEntryTest extends DaemonAnalyzerTestCase {
|
||||
VirtualFile root = ModuleRootManager.getInstance(myModule).getContentRoots()[0].getParent();
|
||||
VirtualFile virtualFile = root.findFileByRelativePath(fileName);
|
||||
configureByExistingFile(virtualFile);
|
||||
Pair<String, Boolean> pair = LightQuickFixTestCase.parseActionHint(getFile(), getFile().getText());
|
||||
final String text = pair.getFirst();
|
||||
final boolean actionShouldBeAvailable = pair.getSecond().booleanValue();
|
||||
ActionHint actionHint = ActionHint.parse(getFile(), getFile().getText());
|
||||
Collection<HighlightInfo> infosBefore = highlightErrors();
|
||||
final IntentionAction action = findActionWithText(text, infosBefore);
|
||||
final IntentionAction action = findActionAndCheck(actionHint, infosBefore);
|
||||
|
||||
if (action == null) {
|
||||
if (actionShouldBeAvailable) {
|
||||
fail("Action with text '" + text + "' is not available in test " + testFullPath + "." +
|
||||
"\nAvailable actions are: " + LightQuickFixTestCase.getAvailableActions(getEditor(), getFile())
|
||||
+ "\nInfos are: " + infosBefore
|
||||
);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (!actionShouldBeAvailable) {
|
||||
fail("Action '" + text + "' is available in test " + testFullPath);
|
||||
}
|
||||
if(action != null) {
|
||||
WriteCommandAction.runWriteCommandAction(null, () -> action.invoke(getProject(), getEditor(), getFile()));
|
||||
|
||||
Collection<HighlightInfo> infosAfter = highlightErrors();
|
||||
final IntentionAction afterAction = findActionWithText(text, infosAfter);
|
||||
final IntentionAction afterAction = findActionWithText(action.getText());
|
||||
if (afterAction != null) {
|
||||
fail("Action '" + text + "' is still available after its invocation in test " + testFullPath);
|
||||
fail("Action '" + action.getText() + "' is still available after its invocation in test " + testFullPath);
|
||||
}
|
||||
assertEquals(infosBefore.size() - 1, infosAfter.size());
|
||||
}
|
||||
}
|
||||
|
||||
private IntentionAction findActionWithText(final String actionText, final Collection<HighlightInfo> infos) {
|
||||
private IntentionAction findActionWithText(final String actionText) {
|
||||
List<IntentionAction> actions = LightQuickFixTestCase.getAvailableActions(getEditor(), getFile());
|
||||
return LightQuickFixTestCase.findActionWithText(actions, actionText);
|
||||
}
|
||||
|
||||
private IntentionAction findActionAndCheck(final ActionHint actionHint, Collection<HighlightInfo> infosBefore) {
|
||||
List<IntentionAction> actions = LightQuickFixTestCase.getAvailableActions(getEditor(), getFile());
|
||||
return actionHint.findAndCheck(actions, () -> "Infos: " + infosBefore);
|
||||
}
|
||||
|
||||
public void testAddDependency() throws Exception {
|
||||
doTest("B/src/y/AddDependency.java");
|
||||
}
|
||||
|
||||
+3
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2012 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.
|
||||
@@ -21,6 +21,7 @@
|
||||
package com.intellij.codeInspection;
|
||||
|
||||
import com.intellij.JavaTestUtil;
|
||||
import com.intellij.codeInsight.daemon.quickFix.ActionHint;
|
||||
import com.intellij.codeInsight.daemon.quickFix.LightQuickFixParameterizedTestCase;
|
||||
import com.intellij.codeInspection.varScopeCanBeNarrowed.ParameterCanBeLocalInspection;
|
||||
import com.intellij.psi.PsiElement;
|
||||
@@ -39,7 +40,7 @@ public class ConvertParameterToLocalVariableTest extends LightQuickFixParameteri
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doAction(@NotNull final String text, final boolean actionShouldBeAvailable, final String testFullPath, final String testName)
|
||||
protected void doAction(@NotNull final ActionHint actionHint, final String testFullPath, final String testName)
|
||||
throws Exception {
|
||||
|
||||
final LocalQuickFix fix = new ParameterCanBeLocalInspection.ConvertParameterToLocalQuickFix();
|
||||
|
||||
+19
-2
@@ -1,3 +1,19 @@
|
||||
/*
|
||||
* 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* User: anna
|
||||
* Date: 16-May-2007
|
||||
@@ -5,6 +21,7 @@
|
||||
package com.intellij.codeInspection;
|
||||
|
||||
import com.intellij.JavaTestUtil;
|
||||
import com.intellij.codeInsight.daemon.quickFix.ActionHint;
|
||||
import com.intellij.codeInsight.daemon.quickFix.LightQuickFixParameterizedTestCase;
|
||||
import com.intellij.codeInspection.sameParameterValue.SameParameterValueInspection;
|
||||
import com.intellij.psi.PsiElement;
|
||||
@@ -23,9 +40,9 @@ public class InlineSameParameterValueTest extends LightQuickFixParameterizedTest
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doAction(@NotNull final String text, final boolean actionShouldBeAvailable, final String testFullPath, final String testName)
|
||||
protected void doAction(@NotNull final ActionHint actionHint, final String testFullPath, final String testName)
|
||||
throws Exception {
|
||||
final LocalQuickFix fix = (LocalQuickFix)new SameParameterValueInspection().getQuickFix(text);
|
||||
final LocalQuickFix fix = (LocalQuickFix)new SameParameterValueInspection().getQuickFix(actionHint.getExpectedText());
|
||||
assert fix != null;
|
||||
final int offset = getEditor().getCaretModel().getOffset();
|
||||
final PsiElement psiElement = getFile().findElementAt(offset);
|
||||
|
||||
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
* 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.codeInsight.daemon.quickFix;
|
||||
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.lang.Commenter;
|
||||
import com.intellij.lang.LanguageCommenters;
|
||||
import com.intellij.lang.injection.InjectedLanguageManager;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import junit.framework.TestCase;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
/**
|
||||
* An object representing a wanted assertion of given quick-fix test file.
|
||||
*
|
||||
* @author Tagir Valeev
|
||||
*/
|
||||
public class ActionHint {
|
||||
final String myExpectedText;
|
||||
final boolean myShouldPresent;
|
||||
|
||||
private ActionHint(String expectedText, boolean shouldPresent) {
|
||||
myExpectedText = expectedText;
|
||||
myShouldPresent = shouldPresent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an expected text of the action.
|
||||
* <p>
|
||||
* Usage of this method is discouraged: it's not guaranteed that ActionHint actually looks for text.
|
||||
* </p>
|
||||
*
|
||||
* @return an expected action text. May throw an {@link IllegalStateException} if this ActionHint expects something else
|
||||
* (e.g. quick-fix of specific type, etc.)
|
||||
*/
|
||||
public String getExpectedText() {
|
||||
return myExpectedText;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if this ActionHint checks that some action should be present
|
||||
* or false if it checks that some action should be absent
|
||||
*/
|
||||
public boolean shouldPresent() {
|
||||
return myShouldPresent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the action which matches this ActionHint and returns it or returns null
|
||||
* if this ActionHint asserts that no action should be present.
|
||||
*
|
||||
* @param actions actions collection to search inside
|
||||
* @param infoSupplier a supplier which provides additional info which will be appended to exception message if check fails
|
||||
* @return the action or null
|
||||
* @throws AssertionError if no action is found, but it should present, or if action is found, but it should not present.
|
||||
*/
|
||||
@Nullable
|
||||
public IntentionAction findAndCheck(Collection<IntentionAction> actions, Supplier<String> infoSupplier) {
|
||||
IntentionAction result = actions.stream().filter(t -> t.getText().equals(myExpectedText)).findFirst().orElse(null);
|
||||
if(result == null && myShouldPresent) {
|
||||
fail("Action with text '" + myExpectedText + "' not found\nAvailable actions: " +
|
||||
actions.stream().map(IntentionAction::getText).collect(Collectors.joining(", ", "[", "]\n")) +
|
||||
infoSupplier.get());
|
||||
} else if(result != null && !myShouldPresent) {
|
||||
fail("Action with text '" + myExpectedText + "' is present, but should not\n" + infoSupplier.get());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse given file with given contents extracting ActionHint of it.
|
||||
* <p>
|
||||
* Currently the following syntax is supported:
|
||||
* // "quick-fix name or intention text" "true|false"
|
||||
* (replace // with line comment prefix in the corresponding language if necessary)
|
||||
* </p>
|
||||
*
|
||||
* @param file PsiFile associated with contents (used to determine the language)
|
||||
* @param contents file contents
|
||||
* @return ActionHint object
|
||||
* @throws AssertionError if action hint is absent or has invalid format
|
||||
*/
|
||||
@NotNull
|
||||
public static ActionHint parse(@NotNull PsiFile file, @NotNull String contents) {
|
||||
PsiFile hostFile = InjectedLanguageManager.getInstance(file.getProject()).getTopLevelFile(file);
|
||||
|
||||
final Commenter commenter = LanguageCommenters.INSTANCE.forLanguage(hostFile.getLanguage());
|
||||
String comment = commenter.getLineCommentPrefix();
|
||||
if (comment == null) {
|
||||
comment = commenter.getBlockCommentPrefix();
|
||||
}
|
||||
|
||||
assert comment != null : commenter;
|
||||
// "quick fix action text to perform" "should be available"
|
||||
Pattern pattern = Pattern.compile("^" + Pattern.quote(comment) + " \"(.*)\" \"(true|false)\".*", Pattern.DOTALL);
|
||||
Matcher matcher = pattern.matcher(contents);
|
||||
TestCase.assertTrue("No comment found in " + file.getVirtualFile(), matcher.matches());
|
||||
final String text = matcher.group(1);
|
||||
final Boolean actionShouldBeAvailable = Boolean.valueOf(matcher.group(2));
|
||||
return new ActionHint(text, actionShouldBeAvailable);
|
||||
}
|
||||
}
|
||||
+19
-68
@@ -19,14 +19,10 @@ import com.intellij.codeInsight.daemon.LightDaemonAnalyzerTestCase;
|
||||
import com.intellij.codeInsight.daemon.impl.HighlightInfo;
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.codeInsight.intention.impl.ShowIntentionActionsHandler;
|
||||
import com.intellij.lang.Commenter;
|
||||
import com.intellij.lang.LanguageCommenters;
|
||||
import com.intellij.lang.injection.InjectedLanguageManager;
|
||||
import com.intellij.openapi.application.WriteAction;
|
||||
import com.intellij.openapi.command.CommandProcessor;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vcs.readOnlyHandler.ReadonlyStatusHandlerImpl;
|
||||
@@ -41,18 +37,13 @@ import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.util.ObjectUtils;
|
||||
import com.intellij.util.io.ReadOnlyAttributeUtil;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import org.intellij.lang.annotations.RegExp;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public abstract class LightQuickFixTestCase extends LightDaemonAnalyzerTestCase {
|
||||
@NonNls protected static final String BEFORE_PREFIX = "before";
|
||||
@@ -65,8 +56,8 @@ public abstract class LightQuickFixTestCase extends LightDaemonAnalyzerTestCase
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected Pair<String, Boolean> parseActionHintImpl(@NotNull PsiFile file, @NotNull String contents) {
|
||||
return parseActionHint(file, contents);
|
||||
protected ActionHint parseActionHintImpl(@NotNull PsiFile file, @NotNull String contents) {
|
||||
return ActionHint.parse(file, contents);
|
||||
}
|
||||
|
||||
private static void doTestFor(final String testName, final QuickFixTestCase quickFixTestCase) {
|
||||
@@ -78,15 +69,13 @@ public abstract class LightQuickFixTestCase extends LightDaemonAnalyzerTestCase
|
||||
String contents = StringUtil.convertLineSeparators(FileUtil.loadFile(testFile, CharsetToolkit.UTF8_CHARSET));
|
||||
quickFixTestCase.configureFromFileText(testFile.getName(), contents);
|
||||
quickFixTestCase.bringRealEditorBack();
|
||||
final Pair<String, Boolean> pair = quickFixTestCase.parseActionHintImpl(quickFixTestCase.getFile(), contents);
|
||||
final String text = pair.getFirst();
|
||||
final boolean actionShouldBeAvailable = pair.getSecond().booleanValue();
|
||||
final ActionHint actionHint = quickFixTestCase.parseActionHintImpl(quickFixTestCase.getFile(), contents);
|
||||
|
||||
quickFixTestCase.beforeActionStarted(testName, contents);
|
||||
|
||||
try {
|
||||
myWrapper = quickFixTestCase;
|
||||
quickFixTestCase.doAction(text, actionShouldBeAvailable, testFullPath, testName);
|
||||
quickFixTestCase.doAction(actionHint, testFullPath, testName);
|
||||
}
|
||||
finally {
|
||||
myWrapper = null;
|
||||
@@ -109,62 +98,20 @@ public abstract class LightQuickFixTestCase extends LightDaemonAnalyzerTestCase
|
||||
protected void beforeActionStarted(final String testName, final String contents) {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Pair<String, Boolean> parseActionHint(@NotNull PsiFile file, @NotNull String contents) {
|
||||
return parseActionHint(file, contents, " \"(.*)\" \"(true|false)\".*");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Pair<String, Boolean> parseActionHint(@NotNull PsiFile file,
|
||||
@NotNull String contents,
|
||||
@NotNull @NonNls @RegExp String actionPattern) {
|
||||
PsiFile hostFile = InjectedLanguageManager.getInstance(file.getProject()).getTopLevelFile(file);
|
||||
|
||||
final Commenter commenter = LanguageCommenters.INSTANCE.forLanguage(hostFile.getLanguage());
|
||||
String comment = commenter.getLineCommentPrefix();
|
||||
if (comment == null) {
|
||||
comment = commenter.getBlockCommentPrefix();
|
||||
}
|
||||
|
||||
// "quick fix action text to perform" "should be available"
|
||||
assert comment != null : commenter;
|
||||
Pattern pattern = Pattern.compile("^" + comment.replace("*", "\\*") + actionPattern, Pattern.DOTALL);
|
||||
Matcher matcher = pattern.matcher(contents);
|
||||
assertTrue("No comment found in "+file.getVirtualFile(), matcher.matches());
|
||||
final String text = matcher.group(1);
|
||||
final Boolean actionShouldBeAvailable = Boolean.valueOf(matcher.group(2));
|
||||
return Pair.create(text, actionShouldBeAvailable);
|
||||
}
|
||||
|
||||
public static void doAction(@NotNull String text,
|
||||
boolean actionShouldBeAvailable,
|
||||
public static void doAction(@NotNull ActionHint actionHint,
|
||||
String testFullPath,
|
||||
String testName,
|
||||
QuickFixTestCase quickFix) throws Exception {
|
||||
IntentionAction action = quickFix.findActionWithText(text);
|
||||
if (action == null) {
|
||||
if (actionShouldBeAvailable) {
|
||||
List<IntentionAction> actions = quickFix.getAvailableActions();
|
||||
List<String> texts = new ArrayList<>();
|
||||
for (IntentionAction intentionAction : actions) {
|
||||
texts.add(intentionAction.getText());
|
||||
}
|
||||
Collection<HighlightInfo> infos = quickFix.doHighlighting();
|
||||
fail("Action with text '" + text + "' is not available in test " + testFullPath + "\n" +
|
||||
"Available actions (" + texts.size() + "): " + texts + "\n" + actions + "\nInfos:" + infos);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (!actionShouldBeAvailable) {
|
||||
fail("Action '" + text + "' is available (but must not) in test " + testFullPath);
|
||||
}
|
||||
IntentionAction action = actionHint.findAndCheck(quickFix.getAvailableActions(),
|
||||
() -> "Test: "+testFullPath+"\nInfos: "+quickFix.doHighlighting());
|
||||
if (action != null) {
|
||||
quickFix.invoke(action);
|
||||
UIUtil.dispatchAllInvocationEvents();
|
||||
UIUtil.dispatchAllInvocationEvents();
|
||||
if (!quickFix.shouldBeAvailableAfterExecution()) {
|
||||
final IntentionAction afterAction = quickFix.findActionWithText(text);
|
||||
final IntentionAction afterAction = quickFix.findActionWithText(action.getText());
|
||||
if (afterAction != null) {
|
||||
fail("Action '" + text + "' is still available after its invocation in test " + testFullPath);
|
||||
fail("Action '" + action.getText() + "' is still available after its invocation in test " + testFullPath);
|
||||
}
|
||||
}
|
||||
String expectedFilePath = ObjectUtils.notNull(quickFix.getBasePath(), "") + "/" + AFTER_PREFIX + testName;
|
||||
@@ -172,9 +119,9 @@ public abstract class LightQuickFixTestCase extends LightDaemonAnalyzerTestCase
|
||||
}
|
||||
}
|
||||
|
||||
protected void doAction(@NotNull String text, final boolean actionShouldBeAvailable, final String testFullPath, final String testName)
|
||||
protected void doAction(@NotNull ActionHint actionHint, final String testFullPath, final String testName)
|
||||
throws Exception {
|
||||
doAction(text, actionShouldBeAvailable, testFullPath, testName, myWrapper);
|
||||
doAction(actionHint, testFullPath, testName, myWrapper);
|
||||
}
|
||||
|
||||
protected void doAction(@NotNull String actionName) {
|
||||
@@ -208,6 +155,10 @@ public abstract class LightQuickFixTestCase extends LightDaemonAnalyzerTestCase
|
||||
}
|
||||
}
|
||||
|
||||
protected IntentionAction findActionAndCheck(@NotNull ActionHint hint, String testFullPath) {
|
||||
return hint.findAndCheck(getAvailableActions(), () -> "Test: "+testFullPath);
|
||||
}
|
||||
|
||||
protected IntentionAction findActionWithText(@NotNull String text) {
|
||||
return findActionWithText(getAvailableActions(), text);
|
||||
}
|
||||
@@ -283,7 +234,7 @@ public abstract class LightQuickFixTestCase extends LightDaemonAnalyzerTestCase
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Pair<String, Boolean> parseActionHintImpl(@NotNull PsiFile file, @NotNull String contents) {
|
||||
public ActionHint parseActionHintImpl(@NotNull PsiFile file, @NotNull String contents) {
|
||||
return LightQuickFixTestCase.this.parseActionHintImpl(file, contents);
|
||||
}
|
||||
|
||||
@@ -298,8 +249,8 @@ public abstract class LightQuickFixTestCase extends LightDaemonAnalyzerTestCase
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doAction(String text, boolean actionShouldBeAvailable, String testFullPath, String testName) throws Exception {
|
||||
LightQuickFixTestCase.this.doAction(text, actionShouldBeAvailable, testFullPath, testName);
|
||||
public void doAction(ActionHint actionHint, String testFullPath, String testName) throws Exception {
|
||||
LightQuickFixTestCase.this.doAction(actionHint, testFullPath, testName);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+3
-4
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 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.
|
||||
@@ -18,7 +18,6 @@ package com.intellij.codeInsight.daemon.quickFix;
|
||||
import com.intellij.codeInsight.daemon.impl.HighlightInfo;
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -35,13 +34,13 @@ public interface QuickFixTestCase {
|
||||
String getTestDataPath();
|
||||
|
||||
@NotNull
|
||||
Pair<String, Boolean> parseActionHintImpl(@NotNull PsiFile file, @NotNull String contents);
|
||||
ActionHint parseActionHintImpl(@NotNull PsiFile file, @NotNull String contents);
|
||||
|
||||
void beforeActionStarted(String testName, String contents);
|
||||
|
||||
void afterActionCompleted(String testName, String contents);
|
||||
|
||||
void doAction(String text, boolean actionShouldBeAvailable, String testFullPath, String testName) throws Exception;
|
||||
void doAction(ActionHint actionHint, String testFullPath, String testName) throws Exception;
|
||||
|
||||
void checkResultByFile(String s, @NotNull String expectedFilePath, boolean b) throws Exception;
|
||||
|
||||
|
||||
+18
-7
@@ -1,3 +1,18 @@
|
||||
/*
|
||||
* 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.codeInsight.daemon.quickFix;
|
||||
|
||||
import com.intellij.codeInsight.daemon.impl.quickfix.FetchExtResourceAction;
|
||||
@@ -24,13 +39,9 @@ public class FetchExternalResourcesFixTest extends LightQuickFixParameterizedTes
|
||||
|
||||
// just check for action availability
|
||||
@Override
|
||||
protected void doAction(@NotNull String text, boolean actionShouldBeAvailable, String testFullPath, String testName) throws Exception {
|
||||
IntentionAction action = findActionWithText(text);
|
||||
if (action == null && actionShouldBeAvailable) {
|
||||
fail("Action with text '" + text + "' is not available in test " + testFullPath);
|
||||
}
|
||||
|
||||
if (actionShouldBeAvailable && testName.equals("5.xml")) {
|
||||
protected void doAction(@NotNull ActionHint actionHint, String testFullPath, String testName) throws Exception {
|
||||
IntentionAction action = findActionAndCheck(actionHint, testFullPath);
|
||||
if (action != null && testName.equals("5.xml")) {
|
||||
final String uri = FetchExtResourceAction.findUri(myFile, myEditor.getCaretModel().getOffset());
|
||||
final String url = FetchExtResourceAction.findUrl(myFile, myEditor.getCaretModel().getOffset(),uri);
|
||||
assertEquals("http://www.springframework.org/schema/aop/spring-aop.xsd",url);
|
||||
|
||||
+17
-6
@@ -1,6 +1,20 @@
|
||||
/*
|
||||
* 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.codeInsight.daemon.quickFix;
|
||||
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.testFramework.PlatformTestUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -16,11 +30,8 @@ public class IgnoreExternalResourcesFixTest extends LightQuickFixParameterizedTe
|
||||
|
||||
// just check for action availability
|
||||
@Override
|
||||
protected void doAction(@NotNull String text, boolean actionShouldBeAvailable, String testFullPath, String testName) throws Exception {
|
||||
IntentionAction action = findActionWithText(text);
|
||||
if (action == null && actionShouldBeAvailable) {
|
||||
fail("Action with text '" + text + "' is not available in test " + testFullPath);
|
||||
}
|
||||
protected void doAction(@NotNull ActionHint actionHint, String testFullPath, String testName) throws Exception {
|
||||
findActionAndCheck(actionHint, testFullPath);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
+17
-6
@@ -1,6 +1,20 @@
|
||||
/*
|
||||
* 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.codeInsight.daemon.quickFix;
|
||||
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.testFramework.PlatformTestUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -16,11 +30,8 @@ public class ManuallySetupExternalResourcesFixTest extends LightQuickFixParamete
|
||||
|
||||
// just check for action availability
|
||||
@Override
|
||||
protected void doAction(@NotNull String text, boolean actionShouldBeAvailable, String testFullPath, String testName) throws Exception {
|
||||
IntentionAction action = findActionWithText(text);
|
||||
if (action == null && actionShouldBeAvailable) {
|
||||
fail("Action with text '" + text + "' is not available in test " + testFullPath);
|
||||
}
|
||||
protected void doAction(@NotNull ActionHint actionHint, String testFullPath, String testName) throws Exception {
|
||||
findActionAndCheck(actionHint, testFullPath);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
Reference in New Issue
Block a user