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;
|
||||
}
|
||||
|
||||
public static boolean isDirectiveDefined(String fileText, String directive) {
|
||||
return !findListWithPrefixes(fileText, directive).isEmpty();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static String findStringWithPrefixes(String fileText, String... prefixes) {
|
||||
List<String> strings = findListWithPrefixes(fileText, prefixes);
|
||||
|
||||
@@ -17,4 +17,6 @@ class Action {
|
||||
measureTimeMillis({ println(HashMap<String, Int>().size()) })
|
||||
val test : ArrayList<Int>? = null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// RUNTIME
|
||||
@@ -11,4 +11,6 @@ class Action {
|
||||
measureTimeMillis({ println(HashMap<String, Int>().size()) })
|
||||
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.openapi.startup.StartupManager;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.testFramework.LightProjectDescriptor;
|
||||
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 {
|
||||
LightProjectDescriptor projectDescriptor = null;
|
||||
|
||||
@Override
|
||||
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();
|
||||
|
||||
((StartupManagerImpl) StartupManager.getInstance(getProject())).runPostStartupActivities();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
projectDescriptor = null;
|
||||
}
|
||||
|
||||
protected String fileName() {
|
||||
return getTestName(false) + ".kt";
|
||||
@NotNull
|
||||
@Override
|
||||
protected LightProjectDescriptor getProjectDescriptor() {
|
||||
return projectDescriptor;
|
||||
}
|
||||
|
||||
protected abstract String fileName();
|
||||
}
|
||||
|
||||
@@ -16,27 +16,15 @@
|
||||
|
||||
package org.jetbrains.jet.plugin.importOptimizer;
|
||||
|
||||
import com.intellij.ide.startup.impl.StartupManagerImpl;
|
||||
import com.intellij.openapi.command.CommandProcessor;
|
||||
import com.intellij.openapi.command.UndoConfirmationPolicy;
|
||||
import com.intellij.openapi.projectRoots.JavaSdk;
|
||||
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.JetLightCodeInsightFixtureTestCase;
|
||||
import org.jetbrains.jet.plugin.PluginTestCaseBase;
|
||||
import org.jetbrains.jet.plugin.editor.importOptimizer.JetImportOptimizer;
|
||||
import org.jetbrains.jet.testing.ConfigLibraryUtil;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class OptimizeImportsTest extends LightCodeInsightTestCase {
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
((StartupManagerImpl) StartupManager.getInstance(getProject())).runPostStartupActivities();
|
||||
}
|
||||
|
||||
public class OptimizeImportsTest extends JetLightCodeInsightFixtureTestCase {
|
||||
public void testAlreadyOptimized() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
@@ -54,7 +42,7 @@ public class OptimizeImportsTest extends LightCodeInsightTestCase {
|
||||
}
|
||||
|
||||
public void testUnusedImports() throws Exception {
|
||||
doTestWithKotlinRuntime();
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testWithAliases() throws Exception {
|
||||
@@ -86,23 +74,9 @@ public class OptimizeImportsTest extends LightCodeInsightTestCase {
|
||||
}
|
||||
|
||||
public void doTest() throws Exception {
|
||||
configureByFile(fileName());
|
||||
myFixture.configureByFile(fileName());
|
||||
invokeFormatFile();
|
||||
checkResultByFile(null, checkFileName(), true);
|
||||
}
|
||||
|
||||
public void doTestWithKotlinRuntime() {
|
||||
try {
|
||||
ConfigLibraryUtil.configureKotlinRuntime(getModule(), getFullJavaJDK());
|
||||
|
||||
configureByFile(fileName());
|
||||
invokeFormatFile();
|
||||
|
||||
checkResultByFile(null, checkFileName(), false);
|
||||
}
|
||||
finally {
|
||||
ConfigLibraryUtil.unConfigureKotlinRuntime(getModule(), getProjectJDK());
|
||||
}
|
||||
myFixture.checkResultByFile(checkFileName(), false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -112,14 +86,6 @@ public class OptimizeImportsTest extends LightCodeInsightTestCase {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Sdk getProjectJDK() {
|
||||
return PluginTestCaseBase.jdkFromIdeaHome();
|
||||
}
|
||||
|
||||
protected static Sdk getFullJavaJDK() {
|
||||
return JavaSdk.getInstance().createJdk("JDK", SystemUtils.getJavaHome().getAbsolutePath());
|
||||
}
|
||||
|
||||
public String fileName() {
|
||||
return getTestName(false) + ".kt";
|
||||
}
|
||||
@@ -128,9 +94,8 @@ public class OptimizeImportsTest extends LightCodeInsightTestCase {
|
||||
return getTestName(false) + "_after.kt";
|
||||
}
|
||||
|
||||
private static void invokeFormatFile() {
|
||||
CommandProcessor.getInstance().executeCommand(
|
||||
getProject(), new JetImportOptimizer().processFile(getFile()),
|
||||
private void invokeFormatFile() {
|
||||
CommandProcessor.getInstance().executeCommand(myFixture.getProject(), new JetImportOptimizer().processFile(myFixture.getFile()),
|
||||
"Optimize Imports", null, UndoConfirmationPolicy.DO_NOT_REQUEST_CONFIRMATION);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user