Refactoring: change parameters order in InTextDirectivesUtils
This commit is contained in:
@@ -34,7 +34,7 @@ public final class InTextDirectivesUtils {
|
||||
|
||||
@Nullable
|
||||
public static Integer getPrefixedInt(String fileText, String prefix) {
|
||||
String[] numberStrings = findArrayWithPrefix(prefix, fileText);
|
||||
String[] numberStrings = findArrayWithPrefix(fileText, prefix);
|
||||
if (numberStrings.length > 0) {
|
||||
return Integer.parseInt(numberStrings[0]);
|
||||
}
|
||||
@@ -43,15 +43,15 @@ public final class InTextDirectivesUtils {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String[] findArrayWithPrefix(String prefix, String fileText) {
|
||||
return ArrayUtil.toStringArray(findListWithPrefix(prefix, fileText));
|
||||
public static String[] findArrayWithPrefix(String fileText, String prefix) {
|
||||
return ArrayUtil.toStringArray(findListWithPrefix(fileText, prefix));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static List<String> findListWithPrefix(String prefix, String fileText) {
|
||||
public static List<String> findListWithPrefix(String fileText, String prefix) {
|
||||
ArrayList<String> result = new ArrayList<String>();
|
||||
|
||||
for (String line : findLinesWithPrefixRemoved(prefix, fileText)) {
|
||||
for (String line : findLinesWithPrefixRemoved(fileText, prefix)) {
|
||||
String[] variants = line.split(",");
|
||||
|
||||
for (String variant : variants) {
|
||||
@@ -63,8 +63,8 @@ public final class InTextDirectivesUtils {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static String findStringWithPrefix(String prefix, String fileText) {
|
||||
List<String> strings = findListWithPrefix(prefix, fileText);
|
||||
public static String findStringWithPrefix(String fileText, String prefix) {
|
||||
List<String> strings = findListWithPrefix(fileText, prefix);
|
||||
if (strings.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
@@ -73,7 +73,7 @@ public final class InTextDirectivesUtils {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static List<String> findLinesWithPrefixRemoved(String prefix, String fileText) {
|
||||
public static List<String> findLinesWithPrefixRemoved(String fileText, String prefix) {
|
||||
ArrayList<String> result = new ArrayList<String>();
|
||||
|
||||
for (String line : fileNonEmptyLines(fileText)) {
|
||||
|
||||
+1
-1
@@ -64,7 +64,7 @@ public abstract class AbstractDefaultConstructorCodegenTest extends CodegenTestC
|
||||
}
|
||||
|
||||
private String loadInstructionValue(String fileContent, String instructionName) {
|
||||
List<String> testedClass = findListWithPrefix("// " + instructionName + ": ", fileContent);
|
||||
List<String> testedClass = findListWithPrefix(fileContent, "// " + instructionName + ": ");
|
||||
assertTrue("Cannot find " + instructionName + " instruction", !testedClass.isEmpty());
|
||||
assertTrue(instructionName + " instruction must have only one element", testedClass.size() == 1);
|
||||
return testedClass.get(0);
|
||||
|
||||
@@ -94,7 +94,7 @@ public abstract class AbstractWriteFlagsTest extends UsefulTestCase {
|
||||
|
||||
private static TestedObject parseExpectedTestedObject(String fileText) {
|
||||
TestedObject result = new TestedObject();
|
||||
List<String> testedObjects = findListWithPrefix("// TESTED_OBJECTS: ", fileText);
|
||||
List<String> testedObjects = findListWithPrefix(fileText, "// TESTED_OBJECTS: ");
|
||||
assertTrue("Cannot find TESTED_OBJECTS instruction", !testedObjects.isEmpty());
|
||||
result.containingClass = testedObjects.get(0);
|
||||
if (testedObjects.size() == 1) {
|
||||
@@ -108,8 +108,8 @@ public abstract class AbstractWriteFlagsTest extends UsefulTestCase {
|
||||
"TESTED_OBJECTS instruction must contains one (for class) or two (for function and property) values");
|
||||
}
|
||||
|
||||
result.kind = findStringWithPrefix("// TESTED_OBJECT_KIND: ", fileText);
|
||||
List<String> isFullName = findListWithPrefix("// IS_FULL_CONTAINING_CLASS_NAME: ", fileText);
|
||||
result.kind = findStringWithPrefix(fileText, "// TESTED_OBJECT_KIND: ");
|
||||
List<String> isFullName = findListWithPrefix(fileText, "// IS_FULL_CONTAINING_CLASS_NAME: ");
|
||||
if (isFullName.size() == 1) {
|
||||
result.isFullContainingClassName = Boolean.parseBoolean(isFullName.get(0));
|
||||
}
|
||||
@@ -150,7 +150,7 @@ public abstract class AbstractWriteFlagsTest extends UsefulTestCase {
|
||||
private static int getExpectedFlags(String text) {
|
||||
int expectedAccess = 0;
|
||||
Class klass = Opcodes.class;
|
||||
List<String> flags = findListWithPrefix("// FLAGS: ", text);
|
||||
List<String> flags = findListWithPrefix(text, "// FLAGS: ");
|
||||
for (String flag : flags) {
|
||||
try {
|
||||
Field field = klass.getDeclaredField(flag);
|
||||
|
||||
@@ -126,7 +126,7 @@ public class ExpectedCompletionUtils {
|
||||
|
||||
public static CompletionProposal[] processProposalAssertions(String prefix, String fileText) {
|
||||
Collection<CompletionProposal> proposals = new ArrayList<CompletionProposal>();
|
||||
for (String proposalStr : InTextDirectivesUtils.findListWithPrefix(prefix, fileText)) {
|
||||
for (String proposalStr : InTextDirectivesUtils.findListWithPrefix(fileText, prefix)) {
|
||||
Matcher matcher = CompletionProposal.PATTERN.matcher(proposalStr);
|
||||
matcher.find();
|
||||
proposals.add(new CompletionProposal(matcher.group(CompletionProposal.LOOKUP_STRING_GROUP_INDEX),
|
||||
|
||||
@@ -79,7 +79,7 @@ public class JetConfidenceTest extends LightCompletionTestCase {
|
||||
protected static String getTypeTextFromFile() {
|
||||
String text = getEditor().getDocument().getText();
|
||||
|
||||
String[] directives = InTextDirectivesUtils.findArrayWithPrefix(TYPE_DIRECTIVE_PREFIX, text);
|
||||
String[] directives = InTextDirectivesUtils.findArrayWithPrefix(text, TYPE_DIRECTIVE_PREFIX);
|
||||
assertEquals("One directive with \"" + TYPE_DIRECTIVE_PREFIX +"\" expected", 1, directives.length);
|
||||
|
||||
return StringUtil.unquoteString(directives[0]);
|
||||
|
||||
@@ -18,9 +18,9 @@ package org.jetbrains.jet.formatter;
|
||||
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettings;
|
||||
import com.intellij.psi.codeStyle.CommonCodeStyleSettings;
|
||||
import org.jetbrains.jet.InTextDirectivesUtils;
|
||||
import org.jetbrains.jet.plugin.JetLanguage;
|
||||
import org.jetbrains.jet.plugin.formatter.JetCodeStyleSettings;
|
||||
import org.jetbrains.jet.InTextDirectivesUtils;
|
||||
import org.junit.Assert;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
@@ -30,8 +30,8 @@ public class FormattingSettingsConfigurator {
|
||||
private final String[] settingsToFalse;
|
||||
|
||||
public FormattingSettingsConfigurator(String fileText) {
|
||||
settingsToTrue = InTextDirectivesUtils.findArrayWithPrefix("// SET_TRUE:", fileText);
|
||||
settingsToFalse = InTextDirectivesUtils.findArrayWithPrefix("// SET_FALSE:", fileText);
|
||||
settingsToTrue = InTextDirectivesUtils.findArrayWithPrefix(fileText, "// SET_TRUE:");
|
||||
settingsToFalse = InTextDirectivesUtils.findArrayWithPrefix(fileText, "// SET_FALSE:");
|
||||
}
|
||||
|
||||
public void configureSettings(CodeStyleSettings settings) {
|
||||
|
||||
+1
-1
@@ -37,7 +37,7 @@ public abstract class AbstractCodeTransformationTest extends LightCodeInsightTes
|
||||
configureByFile(path);
|
||||
|
||||
String fileText = FileUtil.loadFile(new File(path));
|
||||
String isApplicableString = InTextDirectivesUtils.findStringWithPrefix("// IS_APPLICABLE: ", fileText);
|
||||
String isApplicableString = InTextDirectivesUtils.findStringWithPrefix(fileText, "// IS_APPLICABLE: ");
|
||||
boolean isApplicableExpected = isApplicableString == null || isApplicableString.equals("true");
|
||||
|
||||
assert isApplicableExpected == intentionAction.isAvailable(getProject(), getEditor(), getFile())
|
||||
|
||||
+5
-2
@@ -27,7 +27,10 @@ import com.intellij.testFramework.LightCodeInsightTestCase;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.InTextDirectivesUtils;
|
||||
import org.jetbrains.jet.plugin.codeInsight.surroundWith.expression.*;
|
||||
import org.jetbrains.jet.plugin.codeInsight.surroundWith.expression.KotlinNotSurrounder;
|
||||
import org.jetbrains.jet.plugin.codeInsight.surroundWith.expression.KotlinParenthesesSurrounder;
|
||||
import org.jetbrains.jet.plugin.codeInsight.surroundWith.expression.KotlinStringTemplateSurrounder;
|
||||
import org.jetbrains.jet.plugin.codeInsight.surroundWith.expression.KotlinWhenSurrounder;
|
||||
import org.jetbrains.jet.plugin.codeInsight.surroundWith.statement.*;
|
||||
|
||||
import java.io.File;
|
||||
@@ -79,7 +82,7 @@ public abstract class AbstractSurroundWithTest extends LightCodeInsightTestCase
|
||||
configureByFile(path);
|
||||
|
||||
String fileText = FileUtil.loadFile(new File(path));
|
||||
String isApplicableString = InTextDirectivesUtils.findStringWithPrefix("// IS_APPLICABLE: ", fileText);
|
||||
String isApplicableString = InTextDirectivesUtils.findStringWithPrefix(fileText, "// IS_APPLICABLE: ");
|
||||
|
||||
if (isApplicableString != null) {
|
||||
boolean isApplicableExpected = toString().equals("true");
|
||||
|
||||
@@ -49,7 +49,7 @@ public final class NavigationTestUtils {
|
||||
|
||||
public static void assertGotoImplementations(Editor editor, GotoTargetHandler.GotoData gotoData) {
|
||||
// Get expected references from the tested document
|
||||
List<String> expectedReferences = InTextDirectivesUtils.findListWithPrefix("// REF:", editor.getDocument().getText());
|
||||
List<String> expectedReferences = InTextDirectivesUtils.findListWithPrefix(editor.getDocument().getText(), "// REF:");
|
||||
Collections.sort(expectedReferences);
|
||||
|
||||
if (gotoData != null) {
|
||||
@@ -72,11 +72,11 @@ public final class NavigationTestUtils {
|
||||
|
||||
public static void assertGotoSymbol(@NotNull Project project, @NotNull Editor editor) {
|
||||
|
||||
List<String> searchTextList = InTextDirectivesUtils.findListWithPrefix("// SEARCH_TEXT:", editor.getDocument().getText());
|
||||
List<String> searchTextList = InTextDirectivesUtils.findListWithPrefix(editor.getDocument().getText(), "// SEARCH_TEXT:");
|
||||
Assert.assertFalse("There's no search text in test data file given. Use '// SEARCH_TEXT:' directive",
|
||||
searchTextList.isEmpty());
|
||||
|
||||
List<String> expectedReferences = InTextDirectivesUtils.findListWithPrefix("// REF:", editor.getDocument().getText());
|
||||
List<String> expectedReferences = InTextDirectivesUtils.findListWithPrefix(editor.getDocument().getText(), "// REF:");
|
||||
|
||||
String searchText = searchTextList.get(0);
|
||||
|
||||
|
||||
@@ -59,7 +59,7 @@ public class QuickFixActionsUtils {
|
||||
}
|
||||
});
|
||||
|
||||
List<String> expectedErrorStrings = InTextDirectivesUtils.findLinesWithPrefixRemoved("// ERROR:", file.getText());
|
||||
List<String> expectedErrorStrings = InTextDirectivesUtils.findLinesWithPrefixRemoved(file.getText(), "// ERROR:");
|
||||
Collections.sort(expectedErrorStrings);
|
||||
|
||||
UsefulTestCase.assertOrderedEquals(
|
||||
@@ -69,7 +69,7 @@ public class QuickFixActionsUtils {
|
||||
|
||||
public static void checkAvailableActionsAreExpected(JetFile file, Collection<IntentionAction> availableActions) {
|
||||
List<String> validActions = Ordering.natural().sortedCopy(
|
||||
Sets.newHashSet(InTextDirectivesUtils.findLinesWithPrefixRemoved("// ACTION:", file.getText())));
|
||||
Sets.newHashSet(InTextDirectivesUtils.findLinesWithPrefixRemoved(file.getText(), "// ACTION:")));
|
||||
|
||||
Collection<String> actualActions = Ordering.natural().sortedCopy(
|
||||
Collections2.transform(availableActions, new Function<IntentionAction, String>() {
|
||||
|
||||
@@ -24,8 +24,8 @@ import com.intellij.testFramework.LightProjectDescriptor;
|
||||
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;
|
||||
import com.intellij.util.Query;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.plugin.JetLightProjectDescriptor;
|
||||
import org.jetbrains.jet.InTextDirectivesUtils;
|
||||
import org.jetbrains.jet.plugin.JetLightProjectDescriptor;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -50,7 +50,7 @@ public abstract class AbstractSearcherTest extends LightCodeInsightFixtureTestCa
|
||||
}
|
||||
|
||||
protected void checkResult(Query<?> actual) throws IOException {
|
||||
List<String> expected = InTextDirectivesUtils.findListWithPrefix("// SEARCH: ", FileUtil.loadFile(new File(getPathToFile())));
|
||||
List<String> expected = InTextDirectivesUtils.findListWithPrefix(FileUtil.loadFile(new File(getPathToFile())), "// SEARCH: ");
|
||||
List<String> actualModified = new ArrayList<String>();
|
||||
for (Object member : actual) {
|
||||
actualModified.add(member.toString());
|
||||
|
||||
@@ -19,8 +19,8 @@ package org.jetbrains.jet.search;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.search.searches.AnnotatedMembersSearch;
|
||||
import org.jetbrains.jet.plugin.PluginTestCaseBase;
|
||||
import org.jetbrains.jet.InTextDirectivesUtils;
|
||||
import org.jetbrains.jet.plugin.PluginTestCaseBase;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -42,7 +42,7 @@ public class AnnotatedMembersSearchTest extends AbstractSearcherTest {
|
||||
|
||||
private void doTest() throws IOException {
|
||||
myFixture.configureByFile(getFileName());
|
||||
List<String> directives = InTextDirectivesUtils.findListWithPrefix("// ANNOTATION: ", FileUtil.loadFile(new File(getPathToFile())));
|
||||
List<String> directives = InTextDirectivesUtils.findListWithPrefix(FileUtil.loadFile(new File(getPathToFile())), "// ANNOTATION: ");
|
||||
assertFalse("Specify ANNOTATION directive in test file", directives.isEmpty());
|
||||
String annotationClassName = directives.get(0);
|
||||
PsiClass psiClass = getPsiClass(annotationClassName);
|
||||
|
||||
@@ -19,8 +19,8 @@ package org.jetbrains.jet.search;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.search.searches.ClassInheritorsSearch;
|
||||
import org.jetbrains.jet.plugin.PluginTestCaseBase;
|
||||
import org.jetbrains.jet.InTextDirectivesUtils;
|
||||
import org.jetbrains.jet.plugin.PluginTestCaseBase;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -38,7 +38,7 @@ public class ClassInheritorsSearchTest extends AbstractSearcherTest {
|
||||
|
||||
private void doTest() throws IOException {
|
||||
myFixture.configureByFile(getFileName());
|
||||
List<String> directives = InTextDirectivesUtils.findListWithPrefix("// CLASS: ", FileUtil.loadFile(new File(getPathToFile())));
|
||||
List<String> directives = InTextDirectivesUtils.findListWithPrefix(FileUtil.loadFile(new File(getPathToFile())), "// CLASS: ");
|
||||
assertFalse("Specify CLASS directive in test file", directives.isEmpty());
|
||||
String superClassName = directives.get(0);
|
||||
PsiClass psiClass = getPsiClass(superClassName);
|
||||
|
||||
@@ -23,9 +23,9 @@ import com.intellij.psi.search.searches.AnnotatedMembersSearch;
|
||||
import com.intellij.psi.search.searches.ClassInheritorsSearch;
|
||||
import com.intellij.testFramework.LightProjectDescriptor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.InTextDirectivesUtils;
|
||||
import org.jetbrains.jet.plugin.JetJdkAndLibraryProjectDescriptor;
|
||||
import org.jetbrains.jet.plugin.PluginTestCaseBase;
|
||||
import org.jetbrains.jet.InTextDirectivesUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -49,7 +49,7 @@ public class JUnitMembersSearcherTest extends AbstractSearcherTest {
|
||||
|
||||
private void doJUnit3test() throws IOException {
|
||||
myFixture.configureByFile(getFileName());
|
||||
List<String> directives = InTextDirectivesUtils.findListWithPrefix("// CLASS: ", FileUtil.loadFile(new File(getPathToFile())));
|
||||
List<String> directives = InTextDirectivesUtils.findListWithPrefix(FileUtil.loadFile(new File(getPathToFile())), "// CLASS: ");
|
||||
assertFalse("Specify CLASS directive in test file", directives.isEmpty());
|
||||
String superClassName = directives.get(0);
|
||||
PsiClass psiClass = getPsiClass(superClassName);
|
||||
@@ -58,7 +58,7 @@ public class JUnitMembersSearcherTest extends AbstractSearcherTest {
|
||||
|
||||
private void doJUnit4test() throws IOException {
|
||||
myFixture.configureByFile(getFileName());
|
||||
List<String> directives = InTextDirectivesUtils.findListWithPrefix("// ANNOTATION: ", FileUtil.loadFile(new File(getPathToFile())));
|
||||
List<String> directives = InTextDirectivesUtils.findListWithPrefix(FileUtil.loadFile(new File(getPathToFile())), "// ANNOTATION: ");
|
||||
assertFalse("Specify ANNOTATION directive in test file", directives.isEmpty());
|
||||
String annotationClassName = directives.get(0);
|
||||
PsiClass psiClass = getPsiClass(annotationClassName);
|
||||
|
||||
Reference in New Issue
Block a user