Configure project descriptor with directives
Implement optimize import test with redesigned class
This commit is contained in:
committed by
Natalia.Ukhorskaya
parent
e0d1190d5e
commit
bbc49ca9fc
@@ -64,6 +64,10 @@ public final class InTextDirectivesUtils {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isDirectiveDefined(String fileText, String directive) {
|
||||||
|
return !findListWithPrefixes(fileText, directive).isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public static String findStringWithPrefixes(String fileText, String... prefixes) {
|
public static String findStringWithPrefixes(String fileText, String... prefixes) {
|
||||||
List<String> strings = findListWithPrefixes(fileText, prefixes);
|
List<String> strings = findListWithPrefixes(fileText, prefixes);
|
||||||
|
|||||||
@@ -18,3 +18,5 @@ class Action {
|
|||||||
val test : ArrayList<Int>? = null
|
val test : ArrayList<Int>? = null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RUNTIME
|
||||||
@@ -12,3 +12,5 @@ class Action {
|
|||||||
val test : ArrayList<Int>? = null
|
val test : ArrayList<Int>? = null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RUNTIME
|
||||||
@@ -18,21 +18,43 @@ package org.jetbrains.jet.plugin;
|
|||||||
|
|
||||||
import com.intellij.ide.startup.impl.StartupManagerImpl;
|
import com.intellij.ide.startup.impl.StartupManagerImpl;
|
||||||
import com.intellij.openapi.startup.StartupManager;
|
import com.intellij.openapi.startup.StartupManager;
|
||||||
|
import com.intellij.openapi.util.io.FileUtil;
|
||||||
|
import com.intellij.testFramework.LightProjectDescriptor;
|
||||||
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;
|
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.jet.InTextDirectivesUtils;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
public abstract class JetLightCodeInsightFixtureTestCase extends LightCodeInsightFixtureTestCase {
|
public abstract class JetLightCodeInsightFixtureTestCase extends LightCodeInsightFixtureTestCase {
|
||||||
|
LightProjectDescriptor projectDescriptor = null;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
|
String fileText = FileUtil.loadFile(new File(getTestDataPath(), fileName()));
|
||||||
|
if (InTextDirectivesUtils.isDirectiveDefined(fileText, "RUNTIME")) {
|
||||||
|
projectDescriptor = JetWithJdkAndRuntimeLightProjectDescriptor.INSTANCE;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
projectDescriptor = JetLightProjectDescriptor.INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
super.setUp();
|
super.setUp();
|
||||||
|
|
||||||
((StartupManagerImpl) StartupManager.getInstance(getProject())).runPostStartupActivities();
|
((StartupManagerImpl) StartupManager.getInstance(getProject())).runPostStartupActivities();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void tearDown() throws Exception {
|
protected void tearDown() throws Exception {
|
||||||
super.tearDown();
|
super.tearDown();
|
||||||
|
projectDescriptor = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String fileName() {
|
@NotNull
|
||||||
return getTestName(false) + ".kt";
|
@Override
|
||||||
|
protected LightProjectDescriptor getProjectDescriptor() {
|
||||||
|
return projectDescriptor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected abstract String fileName();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,27 +16,15 @@
|
|||||||
|
|
||||||
package org.jetbrains.jet.plugin.importOptimizer;
|
package org.jetbrains.jet.plugin.importOptimizer;
|
||||||
|
|
||||||
import com.intellij.ide.startup.impl.StartupManagerImpl;
|
|
||||||
import com.intellij.openapi.command.CommandProcessor;
|
import com.intellij.openapi.command.CommandProcessor;
|
||||||
import com.intellij.openapi.command.UndoConfirmationPolicy;
|
import com.intellij.openapi.command.UndoConfirmationPolicy;
|
||||||
import com.intellij.openapi.projectRoots.JavaSdk;
|
import org.jetbrains.jet.plugin.JetLightCodeInsightFixtureTestCase;
|
||||||
import com.intellij.openapi.projectRoots.Sdk;
|
|
||||||
import com.intellij.openapi.startup.StartupManager;
|
|
||||||
import com.intellij.testFramework.LightCodeInsightTestCase;
|
|
||||||
import org.apache.commons.lang.SystemUtils;
|
|
||||||
import org.jetbrains.jet.plugin.PluginTestCaseBase;
|
import org.jetbrains.jet.plugin.PluginTestCaseBase;
|
||||||
import org.jetbrains.jet.plugin.editor.importOptimizer.JetImportOptimizer;
|
import org.jetbrains.jet.plugin.editor.importOptimizer.JetImportOptimizer;
|
||||||
import org.jetbrains.jet.testing.ConfigLibraryUtil;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
public class OptimizeImportsTest extends LightCodeInsightTestCase {
|
public class OptimizeImportsTest extends JetLightCodeInsightFixtureTestCase {
|
||||||
@Override
|
|
||||||
protected void setUp() throws Exception {
|
|
||||||
super.setUp();
|
|
||||||
((StartupManagerImpl) StartupManager.getInstance(getProject())).runPostStartupActivities();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testAlreadyOptimized() throws Exception {
|
public void testAlreadyOptimized() throws Exception {
|
||||||
doTest();
|
doTest();
|
||||||
}
|
}
|
||||||
@@ -54,7 +42,7 @@ public class OptimizeImportsTest extends LightCodeInsightTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testUnusedImports() throws Exception {
|
public void testUnusedImports() throws Exception {
|
||||||
doTestWithKotlinRuntime();
|
doTest();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testWithAliases() throws Exception {
|
public void testWithAliases() throws Exception {
|
||||||
@@ -86,23 +74,9 @@ public class OptimizeImportsTest extends LightCodeInsightTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void doTest() throws Exception {
|
public void doTest() throws Exception {
|
||||||
configureByFile(fileName());
|
myFixture.configureByFile(fileName());
|
||||||
invokeFormatFile();
|
invokeFormatFile();
|
||||||
checkResultByFile(null, checkFileName(), true);
|
myFixture.checkResultByFile(checkFileName(), false);
|
||||||
}
|
|
||||||
|
|
||||||
public void doTestWithKotlinRuntime() {
|
|
||||||
try {
|
|
||||||
ConfigLibraryUtil.configureKotlinRuntime(getModule(), getFullJavaJDK());
|
|
||||||
|
|
||||||
configureByFile(fileName());
|
|
||||||
invokeFormatFile();
|
|
||||||
|
|
||||||
checkResultByFile(null, checkFileName(), false);
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
ConfigLibraryUtil.unConfigureKotlinRuntime(getModule(), getProjectJDK());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -112,14 +86,6 @@ public class OptimizeImportsTest extends LightCodeInsightTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Sdk getProjectJDK() {
|
|
||||||
return PluginTestCaseBase.jdkFromIdeaHome();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected static Sdk getFullJavaJDK() {
|
|
||||||
return JavaSdk.getInstance().createJdk("JDK", SystemUtils.getJavaHome().getAbsolutePath());
|
|
||||||
}
|
|
||||||
|
|
||||||
public String fileName() {
|
public String fileName() {
|
||||||
return getTestName(false) + ".kt";
|
return getTestName(false) + ".kt";
|
||||||
}
|
}
|
||||||
@@ -128,9 +94,8 @@ public class OptimizeImportsTest extends LightCodeInsightTestCase {
|
|||||||
return getTestName(false) + "_after.kt";
|
return getTestName(false) + "_after.kt";
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void invokeFormatFile() {
|
private void invokeFormatFile() {
|
||||||
CommandProcessor.getInstance().executeCommand(
|
CommandProcessor.getInstance().executeCommand(myFixture.getProject(), new JetImportOptimizer().processFile(myFixture.getFile()),
|
||||||
getProject(), new JetImportOptimizer().processFile(getFile()),
|
|
||||||
"Optimize Imports", null, UndoConfirmationPolicy.DO_NOT_REQUEST_CONFIRMATION);
|
"Optimize Imports", null, UndoConfirmationPolicy.DO_NOT_REQUEST_CONFIRMATION);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user