Allow regex matching of available action names; accept both 2016.2 and 2016.3 names of static import quickfix
This commit is contained in:
+2
-2
@@ -1,5 +1,5 @@
|
||||
// FILE: bar/Foo.before.java
|
||||
// "Static import constant 'foo.Bar.Companion.foobar'" "true"
|
||||
// "/(Static import|Import static) constant 'foo.Bar.Companion.foobar'/" "true"
|
||||
// ERROR: Unresolved reference: foobar
|
||||
// ACTION: Rename reference
|
||||
// ACTION: Create field 'foobar'
|
||||
@@ -26,7 +26,7 @@ object Bar {
|
||||
}
|
||||
|
||||
// FILE: bar/Foo.after.java
|
||||
// "Static import constant 'foo.Bar.Companion.foobar'" "true"
|
||||
// "/(Static import|Import static) constant 'foo.Bar.Companion.foobar'/" "true"
|
||||
// ERROR: Unresolved reference: foobar
|
||||
// ACTION: Rename reference
|
||||
// ACTION: Create field 'foobar'
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
// FILE: bar/Foo.before.java
|
||||
// "Static import method 'foo.Bar.foobar'" "true"
|
||||
// "/(Static import|Import static) method 'foo.Bar.foobar'/" "true"
|
||||
// ERROR: Unresolved reference: foobar
|
||||
// ACTION: Create method 'foobar'
|
||||
// WITH_RUNTIME
|
||||
@@ -25,7 +25,7 @@ class Bar {
|
||||
}
|
||||
|
||||
// FILE: bar/Foo.after.java
|
||||
// "Static import method 'foo.Bar.foobar'" "true"
|
||||
// "/(Static import|Import static) method 'foo.Bar.foobar'/" "true"
|
||||
// ERROR: Unresolved reference: foobar
|
||||
// ACTION: Create method 'foobar'
|
||||
// WITH_RUNTIME
|
||||
|
||||
Vendored
+2
-2
@@ -1,5 +1,5 @@
|
||||
// FILE: bar/Foo.before.java
|
||||
// "Static import method 'foo.Bar.getValue'" "true"
|
||||
// "/(Static import|Import static) method 'foo.Bar.getValue'/" "true"
|
||||
// ERROR: Unresolved reference: getValue
|
||||
// ACTION: Create method 'foobar'
|
||||
// WITH_RUNTIME
|
||||
@@ -23,7 +23,7 @@ object Bar {
|
||||
}
|
||||
|
||||
// FILE: bar/Foo.after.java
|
||||
// "Static import method 'foo.Bar.getValue'" "true"
|
||||
// "/(Static import|Import static) method 'foo.Bar.getValue'/" "true"
|
||||
// ERROR: Unresolved reference: getValue
|
||||
// ACTION: Create method 'foobar'
|
||||
// WITH_RUNTIME
|
||||
|
||||
Vendored
+2
-2
@@ -1,5 +1,5 @@
|
||||
// FILE: bar/Foo.before.java
|
||||
// "Static import method 'foo.Bar.setVariable'" "true"
|
||||
// "/(Static import|Import static) method 'foo.Bar.setVariable'/" "true"
|
||||
// ERROR: Unresolved reference: setVariable
|
||||
// ACTION: Create method 'foobar'
|
||||
// WITH_RUNTIME
|
||||
@@ -23,7 +23,7 @@ object Bar {
|
||||
}
|
||||
|
||||
// FILE: bar/Foo.after.java
|
||||
// "Static import method 'foo.Bar.setVariable'" "true"
|
||||
// "/(Static import|Import static) method 'foo.Bar.setVariable'/" "true"
|
||||
// ERROR: Unresolved reference: setVariable
|
||||
// ACTION: Create method 'foobar'
|
||||
// WITH_RUNTIME
|
||||
|
||||
Vendored
+2
-2
@@ -1,5 +1,5 @@
|
||||
// FILE: bar/Foo.before.java
|
||||
// "Static import method 'foo.Bar.getValue'" "true"
|
||||
// "/(Static import|Import static) method 'foo.Bar.getValue'/" "true"
|
||||
// ERROR: Unresolved reference: getValue
|
||||
// ACTION: Create method 'foobar'
|
||||
// WITH_RUNTIME
|
||||
@@ -25,7 +25,7 @@ object Bar {
|
||||
}
|
||||
|
||||
// FILE: bar/Foo.after.java
|
||||
// "Static import method 'foo.Bar.getValue'" "true"
|
||||
// "/(Static import|Import static) method 'foo.Bar.getValue'/" "true"
|
||||
// ERROR: Unresolved reference: getValue
|
||||
// ACTION: Create method 'foobar'
|
||||
// WITH_RUNTIME
|
||||
|
||||
Vendored
+2
-2
@@ -1,5 +1,5 @@
|
||||
// FILE: bar/Foo.before.java
|
||||
// "Static import method 'foo.Bar.setVariable'" "true"
|
||||
// "/(Static import|Import static) method 'foo.Bar.setVariable'/" "true"
|
||||
// ERROR: Unresolved reference: setVariable
|
||||
// ACTION: Create method 'foobar'
|
||||
// WITH_RUNTIME
|
||||
@@ -26,7 +26,7 @@ object Bar {
|
||||
}
|
||||
|
||||
// FILE: bar/Foo.after.java
|
||||
// "Static import method 'foo.Bar.setVariable'" "true"
|
||||
// "/(Static import|Import static) method 'foo.Bar.setVariable'/" "true"
|
||||
// ERROR: Unresolved reference: setVariable
|
||||
// ACTION: Create method 'foobar'
|
||||
// WITH_RUNTIME
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
// FILE: bar/Foo.before.java
|
||||
// "Static import constant 'foo.Bar.foobar'" "true"
|
||||
// "/(Static import|Import static) constant 'foo.Bar.foobar'/" "true"
|
||||
// ERROR: Unresolved reference: foobar
|
||||
// ACTION: Rename reference
|
||||
// ACTION: Create field 'foobar'
|
||||
@@ -24,7 +24,7 @@ object Bar {
|
||||
}
|
||||
|
||||
// FILE: bar/Foo.after.java
|
||||
// "Static import constant 'foo.Bar.foobar'" "true"
|
||||
// "/(Static import|Import static) constant 'foo.Bar.foobar'/" "true"
|
||||
// ERROR: Unresolved reference: foobar
|
||||
// ACTION: Rename reference
|
||||
// ACTION: Create field 'foobar'
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// FILE: bar/Foo.before.java
|
||||
// "Static import method 'foo.Bar.foobar'" "true"
|
||||
// "/(Static import|Import static) method 'foo.Bar.foobar'/" "true"
|
||||
// ERROR: Unresolved reference: foobar
|
||||
// ACTION: Create method 'foobar'
|
||||
// WITH_RUNTIME
|
||||
@@ -22,7 +22,7 @@ object Bar {
|
||||
}
|
||||
|
||||
// FILE: bar/Foo.after.java
|
||||
// "Static import method 'foo.Bar.foobar'" "true"
|
||||
// "/(Static import|Import static) method 'foo.Bar.foobar'/" "true"
|
||||
// ERROR: Unresolved reference: foobar
|
||||
// ACTION: Create method 'foobar'
|
||||
// WITH_RUNTIME
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
// FILE: bar/Foo.before.java
|
||||
// "Static import method 'foo.Bar.getValue'" "true"
|
||||
// "/(Static import|Import static) method 'foo.Bar.getValue'/" "true"
|
||||
// ERROR: Unresolved reference: getValue
|
||||
// ACTION: Create method 'foobar'
|
||||
// WITH_RUNTIME
|
||||
@@ -21,7 +21,7 @@ object Bar {
|
||||
}
|
||||
|
||||
// FILE: bar/Foo.after.java
|
||||
// "Static import method 'foo.Bar.getValue'" "true"
|
||||
// "/(Static import|Import static) method 'foo.Bar.getValue'/" "true"
|
||||
// ERROR: Unresolved reference: getValue
|
||||
// ACTION: Create method 'foobar'
|
||||
// WITH_RUNTIME
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
// FILE: bar/Foo.before.java
|
||||
// "Static import method 'foo.Bar.setVariable'" "true"
|
||||
// "/(Static import|Import static) method 'foo.Bar.setVariable'/" "true"
|
||||
// ERROR: Unresolved reference: setVariable
|
||||
// ACTION: Create method 'foobar'
|
||||
// WITH_RUNTIME
|
||||
@@ -21,7 +21,7 @@ object Bar {
|
||||
}
|
||||
|
||||
// FILE: bar/Foo.after.java
|
||||
// "Static import method 'foo.Bar.setVariable'" "true"
|
||||
// "/(Static import|Import static) method 'foo.Bar.setVariable'/" "true"
|
||||
// ERROR: Unresolved reference: setVariable
|
||||
// ACTION: Create method 'foobar'
|
||||
// WITH_RUNTIME
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
// FILE: bar/Foo.before.java
|
||||
// "Static import method 'foo.Bar.getValue'" "true"
|
||||
// "/(Static import|Import static) method 'foo.Bar.getValue'/" "true"
|
||||
// ERROR: Unresolved reference: getValue
|
||||
// ACTION: Create method 'foobar'
|
||||
// WITH_RUNTIME
|
||||
@@ -23,7 +23,7 @@ object Bar {
|
||||
}
|
||||
|
||||
// FILE: bar/Foo.after.java
|
||||
// "Static import method 'foo.Bar.getValue'" "true"
|
||||
// "/(Static import|Import static) method 'foo.Bar.getValue'/" "true"
|
||||
// ERROR: Unresolved reference: getValue
|
||||
// ACTION: Create method 'foobar'
|
||||
// WITH_RUNTIME
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
// FILE: bar/Foo.before.java
|
||||
// "Static import method 'foo.Bar.setVariable'" "true"
|
||||
// "/(Static import|Import static) method 'foo.Bar.setVariable'/" "true"
|
||||
// ERROR: Unresolved reference: setVariable
|
||||
// ACTION: Create method 'foobar'
|
||||
// WITH_RUNTIME
|
||||
@@ -24,7 +24,7 @@ object Bar {
|
||||
}
|
||||
|
||||
// FILE: bar/Foo.after.java
|
||||
// "Static import method 'foo.Bar.setVariable'" "true"
|
||||
// "/(Static import|Import static) method 'foo.Bar.setVariable'/" "true"
|
||||
// ERROR: Unresolved reference: setVariable
|
||||
// ACTION: Create method 'foobar'
|
||||
// WITH_RUNTIME
|
||||
|
||||
@@ -50,6 +50,7 @@ import kotlin.collections.ArraysKt;
|
||||
import kotlin.collections.CollectionsKt;
|
||||
import kotlin.jvm.functions.Function1;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.idea.KotlinDaemonAnalyzerTestCase;
|
||||
import org.jetbrains.kotlin.idea.KotlinFileType;
|
||||
import org.jetbrains.kotlin.idea.quickfix.utils.QuickfixTestUtilsKt;
|
||||
@@ -64,6 +65,7 @@ import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public abstract class AbstractQuickFixMultiFileTest extends KotlinDaemonAnalyzerTestCase {
|
||||
|
||||
@@ -445,8 +447,12 @@ public abstract class AbstractQuickFixMultiFileTest extends KotlinDaemonAnalyzer
|
||||
|
||||
@SuppressWarnings({"HardCodedStringLiteral"})
|
||||
public void doAction(String text, boolean actionShouldBeAvailable, String testFilePath) throws Exception {
|
||||
Pattern pattern = text.startsWith("/")
|
||||
? Pattern.compile(text.substring(1, text.length()-1))
|
||||
: Pattern.compile(StringUtil.escapeToRegexp(text));
|
||||
|
||||
List<IntentionAction> availableActions = getAvailableActions();
|
||||
IntentionAction action = LightQuickFixTestCase.findActionWithText(availableActions, text);
|
||||
IntentionAction action = findActionByPattern(pattern, availableActions);
|
||||
|
||||
if (action == null) {
|
||||
if (actionShouldBeAvailable) {
|
||||
@@ -475,7 +481,7 @@ public abstract class AbstractQuickFixMultiFileTest extends KotlinDaemonAnalyzer
|
||||
|
||||
//noinspection ConstantConditions
|
||||
if (!shouldBeAvailableAfterExecution()) {
|
||||
IntentionAction afterAction = LightQuickFixTestCase.findActionWithText(getAvailableActions(), text);
|
||||
IntentionAction afterAction = findActionByPattern(pattern, getAvailableActions());
|
||||
|
||||
if (afterAction != null) {
|
||||
fail("Action '" + text + "' is still available after its invocation in test " + testFilePath);
|
||||
@@ -484,6 +490,17 @@ public abstract class AbstractQuickFixMultiFileTest extends KotlinDaemonAnalyzer
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static IntentionAction findActionByPattern(Pattern pattern, List<IntentionAction> availableActions) {
|
||||
for (IntentionAction availableAction : availableActions) {
|
||||
if (pattern.matcher(availableAction.getText()).matches()) {
|
||||
return availableAction;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
private List<IntentionAction> getAvailableActions() {
|
||||
doHighlighting();
|
||||
return LightQuickFixTestCase.getAvailableActions(getEditor(), getFile());
|
||||
|
||||
Reference in New Issue
Block a user