Created module idea-test-framework and moved classes needed for idea tests there

Moved tests for completion and their test data into module idea-completion
This commit is contained in:
Valentin Kipyatkov
2015-04-13 18:11:53 +03:00
parent 63825c45dd
commit bb808b5620
1303 changed files with 1741 additions and 1733 deletions
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="true" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="kotlin-runtime" level="project" />
<orderEntry type="module" module-name="compiler-tests" />
<orderEntry type="module" module-name="frontend" />
<orderEntry type="library" name="idea-full" level="project" />
<orderEntry type="module" module-name="idea-analysis" />
<orderEntry type="module" module-name="util" />
<orderEntry type="module" module-name="idea-core" />
</component>
</module>
@@ -0,0 +1,86 @@
/*
* Copyright 2010-2015 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 org.jetbrains.kotlin.idea.test
import com.intellij.openapi.Disposable
import com.intellij.openapi.project.Project
import com.intellij.openapi.vfs.VfsUtilCore
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.openapi.vfs.VirtualFileFilter
import com.intellij.psi.PsiManager
import com.intellij.psi.impl.PsiManagerImpl
import org.jetbrains.kotlin.idea.JetFileType
import org.jetbrains.kotlin.test.InTextDirectivesUtils
import kotlin.test.fail
public object AstAccessControl {
public val ALLOW_AST_ACCESS_DIRECTIVE: String = "ALLOW_AST_ACCESS"
// Please provide at least one test that fails ast switch check (shouldFail should be true for at least one test)
// This kind of inconvenience is justified by the fact that the check can be invalidated by slight misconfiguration of the test
// leading to all tests passing
fun testWithControlledAccessToAst(shouldFail: Boolean, project: Project, disposable: Disposable, testBody: () -> Unit) {
testWithControlledAccessToAst(shouldFail, listOf(), project, disposable, testBody)
}
fun testWithControlledAccessToAst(
shouldFail: Boolean, allowedFile: VirtualFile,
project: Project, disposable: Disposable, testBody: () -> Unit
) {
testWithControlledAccessToAst(shouldFail, listOf(allowedFile), project, disposable, testBody)
}
fun testWithControlledAccessToAst(
shouldFail: Boolean, allowedFiles: List<VirtualFile>,
project: Project, disposable: Disposable, testBody: () -> Unit
) {
setFilter(allowedFiles, disposable, project)
performTest(shouldFail, testBody)
}
private fun setFilter(allowedFiles: List<VirtualFile>, disposable: Disposable, project: Project) {
val manager = (PsiManager.getInstance(project) as PsiManagerImpl)
val filter = VirtualFileFilter {
file ->
if (file!!.getFileType() != JetFileType.INSTANCE || file in allowedFiles) {
false
}
else {
val text = VfsUtilCore.loadText(file)
!InTextDirectivesUtils.isDirectiveDefined(text, ALLOW_AST_ACCESS_DIRECTIVE)
}
}
manager.setAssertOnFileLoadingFilter(filter, disposable)
}
private fun performTest(shouldFail: Boolean, testBody: () -> Unit) {
try {
testBody()
if (shouldFail) {
fail("This failure means that that a test that should fail (by triggering ast switch) in fact did not.\n" +
"This could happen for the following reasons:\n" +
"1. This kind of operation no longer trigger ast switch, choose better indicator test case." +
"2. Test is now misconfigured and no longer checks for ast switch, reconfigure the test.")
}
}
catch (e: Throwable) {
if (!shouldFail) {
throw e
}
}
}
}
@@ -0,0 +1,156 @@
/*
* Copyright 2010-2015 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 org.jetbrains.kotlin.idea.test;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.roots.*;
import com.intellij.openapi.roots.impl.libraries.LibraryEx;
import com.intellij.openapi.roots.libraries.Library;
import com.intellij.openapi.roots.ui.configuration.libraryEditor.NewLibraryEditor;
import com.intellij.openapi.util.Computable;
import com.intellij.openapi.vfs.VfsUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.utils.PathUtil;
import java.io.File;
/**
* Helper for configuring kotlin runtime in tested project.
*/
public class ConfigLibraryUtil {
private static final String DEFAULT_JAVA_RUNTIME_LIB_NAME = "JAVA_RUNTIME_LIB_NAME";
private static final String DEFAULT_KOTLIN_JS_STDLIB_NAME = "KOTLIN_JS_STDLIB_NAME";
private ConfigLibraryUtil() {
}
private static NewLibraryEditor getKotlinRuntimeLibEditor(String libName, File library) {
NewLibraryEditor editor = new NewLibraryEditor();
editor.setName(libName);
editor.addRoot(VfsUtil.getUrlForLibraryRoot(library), OrderRootType.CLASSES);
return editor;
}
public static void configureKotlinRuntime(Module module, Sdk sdk) {
configureLibrary(module, sdk, getKotlinRuntimeLibEditor(DEFAULT_JAVA_RUNTIME_LIB_NAME, PathUtil.getKotlinPathsForDistDirectory().getRuntimePath()));
}
public static void configureKotlinJsRuntime(Module module, Sdk sdk) {
configureLibrary(module, sdk, getKotlinRuntimeLibEditor(DEFAULT_KOTLIN_JS_STDLIB_NAME, PathUtil.getKotlinPathsForDistDirectory().getJsStdLibJarPath()));
}
public static void unConfigureKotlinRuntime(Module module, Sdk sdk) {
unConfigureLibrary(module, sdk, DEFAULT_JAVA_RUNTIME_LIB_NAME);
}
public static void unConfigureKotlinJsRuntime(Module module, Sdk sdk) {
unConfigureLibrary(module, sdk, DEFAULT_KOTLIN_JS_STDLIB_NAME);
}
public static void configureLibrary(Module module, Sdk sdk, NewLibraryEditor libraryEditor) {
configureSdk(module, sdk);
addLibrary(libraryEditor, module);
}
public static void unConfigureLibrary(Module module, Sdk sdk, String libraryName) {
configureSdk(module, sdk);
removeLibrary(module, libraryName);
}
public static void configureSdk(@NotNull final Module module, @NotNull final Sdk sdk) {
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
ModifiableRootModel rootModel = rootManager.getModifiableModel();
rootModel.setSdk(sdk);
rootModel.commit();
}
});
}
public static Library addLibrary(final NewLibraryEditor editor, final Module module) {
return ApplicationManager.getApplication().runWriteAction(new Computable<Library>() {
@Override
public Library compute() {
ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
ModifiableRootModel model = rootManager.getModifiableModel();
Library library = addLibrary(editor, model);
model.commit();
return library;
}
});
}
public static Library addLibrary(NewLibraryEditor editor, ModifiableRootModel model) {
Library library = model.getModuleLibraryTable().createLibrary(editor.getName());
Library.ModifiableModel libModel = library.getModifiableModel();
editor.applyTo((LibraryEx.ModifiableModelEx) libModel);
libModel.commit();
return library;
}
public static void removeLibrary(@NotNull final Module module, @NotNull final String libraryName) {
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
ModifiableRootModel model = rootManager.getModifiableModel();
for (OrderEntry orderEntry : model.getOrderEntries()) {
if (orderEntry instanceof LibraryOrderEntry) {
LibraryOrderEntry libraryOrderEntry = (LibraryOrderEntry) orderEntry;
Library library = libraryOrderEntry.getLibrary();
if (library != null) {
String name = library.getName();
if (name != null && name.equals(libraryName)) {
// Dispose attached roots
Library.ModifiableModel modifiableModel = library.getModifiableModel();
for (String rootUrl : library.getRootProvider().getUrls(OrderRootType.CLASSES)) {
modifiableModel.removeRoot(rootUrl, OrderRootType.CLASSES);
}
for (String rootUrl : library.getRootProvider().getUrls(OrderRootType.SOURCES)) {
modifiableModel.removeRoot(rootUrl, OrderRootType.SOURCES);
}
modifiableModel.commit();
model.getModuleLibraryTable().removeLibrary(library);
break;
}
}
}
}
model.commit();
}
});
}
}
@@ -0,0 +1,109 @@
/*
* Copyright 2010-2015 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 org.jetbrains.kotlin.idea.test;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.collect.Collections2;
import com.google.common.collect.Lists;
import com.google.common.collect.Ordering;
import com.intellij.codeInsight.intention.IntentionAction;
import com.intellij.testFramework.UsefulTestCase;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.diagnostics.Diagnostic;
import org.jetbrains.kotlin.diagnostics.Severity;
import org.jetbrains.kotlin.idea.caches.resolve.ResolvePackage;
import org.jetbrains.kotlin.idea.highlighter.IdeErrorMessages;
import org.jetbrains.kotlin.psi.JetFile;
import org.jetbrains.kotlin.test.InTextDirectivesUtils;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
public class DirectiveBasedActionUtils {
private DirectiveBasedActionUtils() {
}
public static void checkForUnexpectedErrors(JetFile file) {
if (!InTextDirectivesUtils.findLinesWithPrefixesRemoved(file.getText(), "// DISABLE-ERRORS").isEmpty()) {
return;
}
Collection<Diagnostic> diagnostics = ResolvePackage.analyzeFully(file).getDiagnostics().all();
Collection<Diagnostic> errorDiagnostics = Collections2.filter(diagnostics, new Predicate<Diagnostic>() {
@Override
public boolean apply(@Nullable Diagnostic diagnostic) {
assert (diagnostic != null);
return diagnostic.getSeverity() == Severity.ERROR;
}
});
Collection<String> actualErrorStrings = Collections2.transform(errorDiagnostics, new Function<Diagnostic, String>() {
@Override
public String apply(@Nullable Diagnostic diagnostic) {
assert (diagnostic != null);
return IdeErrorMessages.render(diagnostic);
}
});
List<String> expectedErrorStrings = InTextDirectivesUtils.findLinesWithPrefixesRemoved(file.getText(), "// ERROR:");
Collections.sort(expectedErrorStrings);
UsefulTestCase.assertOrderedEquals(
"All actual errors should be mentioned in test data with // ERROR: directive. But no unnecessary errors should be me mentioned",
Ordering.natural().sortedCopy(actualErrorStrings), expectedErrorStrings);
}
public static void checkAvailableActionsAreExpected(JetFile file, Collection<IntentionAction> availableActions) {
List<String> validActions = Ordering.natural().sortedCopy(
Lists.newArrayList(InTextDirectivesUtils.findLinesWithPrefixesRemoved(file.getText(), "// ACTION:")));
Collection<String> actualActions = Ordering.natural().sortedCopy(
Lists.newArrayList(Collections2.transform(availableActions, new Function<IntentionAction, String>() {
@Override
public String apply(@Nullable IntentionAction input) {
assert input != null;
return input.getText();
}
})));
UsefulTestCase.assertOrderedEquals("Some unexpected actions available at current position: %s. Use // ACTION: directive",
filterOutIrrelevantActions(actualActions), filterOutIrrelevantActions(validActions));
}
@NotNull
//TODO: hack, implemented because irrelevant actions behave in different ways on build server and locally
// this behaviour should be investigated and hack can be removed
private static Collection<String> filterOutIrrelevantActions(@NotNull Collection<String> actions) {
return Collections2.filter(actions, new Predicate<String>() {
@Override
public boolean apply(String input) {
for (String prefix : IRRELEVANT_ACTION_PREFIXES) {
if (input.startsWith(prefix)) {
return false;
}
}
return true;
}
});
}
private static final Collection<String> IRRELEVANT_ACTION_PREFIXES =
Arrays.asList("Disable ", "Edit intention settings", "Edit inspection profile setting", "Inject language or reference");
}
@@ -0,0 +1,73 @@
/*
* Copyright 2010-2015 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 org.jetbrains.kotlin.idea.test;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.roots.ContentEntry;
import com.intellij.openapi.roots.ModifiableRootModel;
import com.intellij.openapi.roots.OrderRootType;
import com.intellij.openapi.roots.libraries.Library;
import com.intellij.openapi.util.io.FileUtilRt;
import org.jetbrains.kotlin.test.MockLibraryUtil;
import java.io.File;
public class JdkAndMockLibraryProjectDescriptor extends JetLightProjectDescriptor {
public static final String LIBRARY_NAME = "myKotlinLib";
private final String sourcesPath;
private final boolean withSources;
public JdkAndMockLibraryProjectDescriptor(String sourcesPath, boolean withSources) {
this.sourcesPath = sourcesPath;
this.withSources = withSources;
}
@Override
public void configureModule(Module module, ModifiableRootModel model, ContentEntry contentEntry) {
File libraryJar = MockLibraryUtil.compileLibraryToJar(sourcesPath, LIBRARY_NAME, withSources);
String jarUrl = "jar://" + FileUtilRt.toSystemIndependentName(libraryJar.getAbsolutePath()) + "!/";
Library.ModifiableModel libraryModel = model.getModuleLibraryTable().getModifiableModel().createLibrary(LIBRARY_NAME).getModifiableModel();
libraryModel.addRoot(jarUrl, OrderRootType.CLASSES);
if (withSources) {
libraryModel.addRoot(jarUrl + "src/", OrderRootType.SOURCES);
}
libraryModel.commit();
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
JdkAndMockLibraryProjectDescriptor that = (JdkAndMockLibraryProjectDescriptor) o;
if (withSources != that.withSources) return false;
if (sourcesPath != null ? !sourcesPath.equals(that.sourcesPath) : that.sourcesPath != null) return false;
return true;
}
@Override
public int hashCode() {
int result = sourcesPath != null ? sourcesPath.hashCode() : 0;
result = 31 * result + (withSources ? 1 : 0);
return result;
}
}
@@ -0,0 +1,62 @@
/*
* Copyright 2010-2015 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 org.jetbrains.kotlin.idea.test;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleType;
import com.intellij.openapi.module.StdModuleTypes;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.roots.ContentEntry;
import com.intellij.openapi.roots.ModifiableRootModel;
import com.intellij.openapi.roots.OrderRootType;
import com.intellij.openapi.roots.ui.configuration.libraryEditor.NewLibraryEditor;
import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.testFramework.LightProjectDescriptor;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.File;
public class JetJdkAndLibraryProjectDescriptor implements LightProjectDescriptor {
public static final String LIBRARY_NAME = "myLibrary";
private final File libraryFile;
public JetJdkAndLibraryProjectDescriptor(File libraryFile) {
assert libraryFile.exists() : "Library file doesn't exist: " + libraryFile.getAbsolutePath();
this.libraryFile = libraryFile;
}
@Override
public ModuleType getModuleType() {
return StdModuleTypes.JAVA;
}
@Override
public Sdk getSdk() {
return PluginTestCaseBase.mockJdk();
}
@Override
public void configureModule(@NotNull Module module, @NotNull ModifiableRootModel model, @Nullable ContentEntry contentEntry) {
NewLibraryEditor editor = new NewLibraryEditor();
editor.setName(LIBRARY_NAME);
editor.addRoot(VfsUtil.getUrlForLibraryRoot(libraryFile), OrderRootType.CLASSES);
ConfigLibraryUtil.addLibrary(editor, model);
}
}
@@ -0,0 +1,142 @@
/*
* Copyright 2010-2015 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 org.jetbrains.kotlin.idea.test
import com.intellij.ide.startup.impl.StartupManagerImpl
import com.intellij.openapi.actionSystem.*
import com.intellij.openapi.actionSystem.ex.ActionManagerEx
import com.intellij.openapi.editor.ex.EditorEx
import com.intellij.openapi.startup.StartupManager
import com.intellij.openapi.util.io.FileUtil
import com.intellij.openapi.util.text.StringUtil
import com.intellij.openapi.vfs.newvfs.impl.VfsRootAccess
import com.intellij.psi.FileViewProvider
import com.intellij.psi.PsiManager
import com.intellij.psi.impl.PsiManagerEx
import com.intellij.psi.impl.file.impl.FileManager
import com.intellij.testFramework.LightProjectDescriptor
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase
import org.jetbrains.kotlin.idea.actions.internal.KotlinInternalMode
import org.jetbrains.kotlin.idea.test.KotlinStdJSProjectDescriptor
import org.jetbrains.kotlin.idea.references.BuiltInsReferenceResolver
import org.jetbrains.kotlin.psi.JetFile
import org.jetbrains.kotlin.test.InTextDirectivesUtils
import org.jetbrains.kotlin.test.JetTestUtils
import org.jetbrains.kotlin.utils.*
import java.io.File
import java.io.IOException
public abstract class JetLightCodeInsightFixtureTestCase : LightCodeInsightFixtureTestCase() {
private var kotlinInternalModeOriginalValue = false
throws(javaClass<Exception>())
override fun setUp() {
super.setUp()
(StartupManager.getInstance(getProject()) as StartupManagerImpl).runPostStartupActivities()
VfsRootAccess.allowRootAccess(JetTestUtils.getHomeDirectory())
kotlinInternalModeOriginalValue = KotlinInternalMode.enabled
KotlinInternalMode.enabled = true
}
throws(javaClass<Exception>())
override fun tearDown() {
KotlinInternalMode.enabled = kotlinInternalModeOriginalValue
VfsRootAccess.disallowRootAccess(JetTestUtils.getHomeDirectory())
val builtInsSources = getProject().getComponent<BuiltInsReferenceResolver>(javaClass<BuiltInsReferenceResolver>()).getBuiltInsSources()
val fileManager = (PsiManager.getInstance(getProject()) as PsiManagerEx).getFileManager()
super.tearDown()
// Restore mapping between PsiFiles and VirtualFiles dropped in FileManager.cleanupForNextTest(),
// otherwise built-ins psi elements will become invalid in next test.
for (source in builtInsSources) {
val provider = source.getViewProvider()
fileManager.setViewProvider(provider.getVirtualFile(), provider)
}
}
override fun getProjectDescriptor(): LightProjectDescriptor
= getProjectDescriptorFromFileDirective()
protected fun getProjectDescriptorFromTestName(): LightProjectDescriptor {
val testName = StringUtil.toLowerCase(getTestName(false))
if (testName.endsWith("runtime")) {
return JetWithJdkAndRuntimeLightProjectDescriptor.INSTANCE
}
else if (testName.endsWith("stdlib")) {
return ProjectDescriptorWithStdlibSources.INSTANCE
}
return JetLightProjectDescriptor.INSTANCE
}
protected fun getProjectDescriptorFromFileDirective(): LightProjectDescriptor {
if (!isAllFilesPresentInTest()) {
try {
val fileText = FileUtil.loadFile(File(getTestDataPath(), fileName()), true)
val withLibraryDirective = InTextDirectivesUtils.findLinesWithPrefixesRemoved(fileText, "WITH_LIBRARY:")
if (!withLibraryDirective.isEmpty()) {
return JdkAndMockLibraryProjectDescriptor(PluginTestCaseBase.getTestDataPathBase() + "/" + withLibraryDirective.get(0), true)
}
else if (InTextDirectivesUtils.isDirectiveDefined(fileText, "RUNTIME_WITH_SOURCES")) {
return ProjectDescriptorWithStdlibSources.INSTANCE
}
else if (InTextDirectivesUtils.isDirectiveDefined(fileText, "RUNTIME")) {
return JetWithJdkAndRuntimeLightProjectDescriptor.INSTANCE
}
else if (InTextDirectivesUtils.isDirectiveDefined(fileText, "JS")) {
return KotlinStdJSProjectDescriptor.instance
}
}
catch (e: IOException) {
throw rethrow(e)
}
}
return JetLightProjectDescriptor.INSTANCE
}
protected fun isAllFilesPresentInTest(): Boolean
= getTestName(false).startsWith("AllFilesPresentIn")
protected open fun fileName(): String
= getTestName(false) + ".kt"
protected fun performNotWriteEditorAction(actionId: String): Boolean {
val dataContext = (myFixture.getEditor() as EditorEx).getDataContext()
val managerEx = ActionManagerEx.getInstanceEx()
val action = managerEx.getAction(actionId)
val event = AnActionEvent(null, dataContext, ActionPlaces.UNKNOWN, Presentation(), managerEx, 0)
action.update(event)
if (!event.getPresentation().isEnabled()) {
return false
}
managerEx.fireBeforeActionPerformed(action, dataContext, event)
action.actionPerformed(event)
managerEx.fireAfterActionPerformed(action, dataContext, event)
return true
}
}
@@ -0,0 +1,46 @@
/*
* Copyright 2010-2015 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 org.jetbrains.kotlin.idea.test;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleType;
import com.intellij.openapi.module.StdModuleTypes;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.roots.ContentEntry;
import com.intellij.openapi.roots.ModifiableRootModel;
import com.intellij.testFramework.LightProjectDescriptor;
public class JetLightProjectDescriptor implements LightProjectDescriptor {
protected JetLightProjectDescriptor() {
}
public static final JetLightProjectDescriptor INSTANCE = new JetLightProjectDescriptor();
@Override
public ModuleType getModuleType() {
return StdModuleTypes.JAVA;
}
@Override
public Sdk getSdk() {
return PluginTestCaseBase.mockJdk();
}
@Override
public void configureModule(Module module, ModifiableRootModel model, ContentEntry contentEntry) {
}
}
@@ -0,0 +1,27 @@
/*
* Copyright 2010-2015 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 org.jetbrains.kotlin.idea.test;
import org.jetbrains.kotlin.codegen.forTestCompile.ForTestCompileRuntime;
public class JetWithJdkAndRuntimeLightProjectDescriptor extends JetJdkAndLibraryProjectDescriptor {
protected JetWithJdkAndRuntimeLightProjectDescriptor() {
super(ForTestCompileRuntime.runtimeJarForTests());
}
public static final JetWithJdkAndRuntimeLightProjectDescriptor INSTANCE = new JetWithJdkAndRuntimeLightProjectDescriptor();
}
@@ -0,0 +1,35 @@
/*
* Copyright 2010-2015 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 org.jetbrains.kotlin.idea.test;
import com.intellij.codeInsight.CodeInsightTestCase;
import com.intellij.openapi.vfs.newvfs.impl.VfsRootAccess;
import org.jetbrains.kotlin.test.JetTestUtils;
public abstract class KotlinCodeInsightTestCase extends CodeInsightTestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
VfsRootAccess.allowRootAccess(JetTestUtils.getHomeDirectory());
}
@Override
protected void tearDown() throws Exception {
VfsRootAccess.disallowRootAccess(JetTestUtils.getHomeDirectory());
super.tearDown();
}
}
@@ -0,0 +1,33 @@
/*
* Copyright 2010-2015 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 org.jetbrains.kotlin.idea.test
import com.intellij.openapi.vfs.newvfs.impl.VfsRootAccess
import com.intellij.refactoring.MultiFileTestCase
import org.jetbrains.kotlin.test.JetTestUtils
public abstract class KotlinMultiFileTestCase : MultiFileTestCase() {
override fun setUp() {
super.setUp()
VfsRootAccess.allowRootAccess(JetTestUtils.getHomeDirectory())
}
override fun tearDown() {
VfsRootAccess.disallowRootAccess(JetTestUtils.getHomeDirectory())
super.tearDown()
}
}
@@ -0,0 +1,26 @@
/*
* Copyright 2010-2015 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 org.jetbrains.kotlin.idea.test
import com.intellij.testFramework.LightProjectDescriptor
public trait KotlinStdJSProjectDescriptor : LightProjectDescriptor {
companion object {
public val instance: KotlinStdJSProjectDescriptor
= Class.forName("org.jetbrains.kotlin.test.KotlinStdJSProjectDescriptorImpl").newInstance() as KotlinStdJSProjectDescriptor
}
}
@@ -0,0 +1,66 @@
/*
* Copyright 2010-2015 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 org.jetbrains.kotlin.idea.test;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.projectRoots.SdkModificator;
import com.intellij.openapi.projectRoots.impl.JavaSdkImpl;
import com.intellij.openapi.roots.AnnotationOrderRootType;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.JarFileSystem;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.test.JetTestUtils;
import java.io.File;
public class PluginTestCaseBase {
public static final String TEST_DATA_PROJECT_RELATIVE = "/idea/testData";
private PluginTestCaseBase() {
}
@NotNull
public static String getTestDataPathBase() {
return JetTestUtils.getHomeDirectory() + TEST_DATA_PROJECT_RELATIVE;
}
private static Sdk getSdk(String sdkHome) {
Sdk sdk = new JavaSdkImpl().createJdk("JDK", sdkHome, true);
SdkModificator modificator = sdk.getSdkModificator();
VirtualFile file = LocalFileSystem.getInstance().findFileByIoFile(JetTestUtils.getJdkAnnotationsJar());
assert file != null;
modificator.addRoot(JarFileSystem.getInstance().getJarRootForLocalFile(file), AnnotationOrderRootType.getInstance());
modificator.commitChanges();
return sdk;
}
public static Sdk mockJdk() {
return getSdk("compiler/testData/mockJDK/jre");
}
public static Sdk fullJdk() {
String javaHome = System.getProperty("java.home");
assert new File(javaHome).isDirectory();
return getSdk(javaHome);
}
public static boolean isAllFilesPresentTest(@NotNull String testName) {
return StringUtil.startsWithIgnoreCase(testName, "allFilesPresentIn");
}
}
@@ -0,0 +1,43 @@
/*
* Copyright 2010-2015 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 org.jetbrains.kotlin.idea.test;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.roots.ContentEntry;
import com.intellij.openapi.roots.ModifiableRootModel;
import com.intellij.openapi.roots.OrderRootType;
import com.intellij.openapi.roots.libraries.Library;
import com.intellij.openapi.vfs.VfsUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.File;
public class ProjectDescriptorWithStdlibSources extends JetWithJdkAndRuntimeLightProjectDescriptor {
public static final ProjectDescriptorWithStdlibSources INSTANCE = new ProjectDescriptorWithStdlibSources();
@Override
public void configureModule(@NotNull Module module, @NotNull ModifiableRootModel model, @Nullable ContentEntry contentEntry) {
super.configureModule(module, model, contentEntry);
Library library = model.getModuleLibraryTable().getLibraryByName(LIBRARY_NAME);
assert library != null;
Library.ModifiableModel modifiableModel = library.getModifiableModel();
modifiableModel.addRoot(VfsUtil.getUrlForLibraryRoot(new File("libraries/stdlib/src")), OrderRootType.SOURCES);
modifiableModel.commit();
}
}
@@ -0,0 +1,67 @@
/*
* Copyright 2010-2015 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 org.jetbrains.kotlin.idea.test
import com.intellij.openapi.module.Module
import com.intellij.openapi.roots.ModifiableRootModel
import com.intellij.openapi.roots.ModuleRootModificationUtil.updateModel
import com.intellij.testFramework.LightProjectDescriptor
import com.intellij.util.Consumer
import org.jetbrains.kotlin.diagnostics.Severity
import org.jetbrains.kotlin.diagnostics.rendering.DefaultErrorMessages
import org.jetbrains.kotlin.idea.caches.resolve.analyzeFullyAndGetResult
import org.jetbrains.kotlin.idea.test.KotlinStdJSProjectDescriptor
import org.jetbrains.kotlin.idea.test.ProjectDescriptorWithStdlibSources
import org.jetbrains.kotlin.psi.JetFile
public enum class ModuleKind {
KOTLIN_JVM_WITH_STDLIB_SOURCES
KOTLIN_JAVASCRIPT
}
public fun Module.configureAs(descriptor: LightProjectDescriptor) {
val module = this
updateModel(module, object : Consumer<ModifiableRootModel> {
override fun consume(model: ModifiableRootModel) {
if (descriptor.getSdk() != null) {
model.setSdk(descriptor.getSdk())
}
val entries = model.getContentEntries()
val entry = if (entries.size() > 0) entries[0] else null
descriptor.configureModule(module, model, entry)
}
})
}
public fun Module.configureAs(kind: ModuleKind) {
when(kind) {
ModuleKind.KOTLIN_JVM_WITH_STDLIB_SOURCES ->
this.configureAs(ProjectDescriptorWithStdlibSources.INSTANCE)
ModuleKind.KOTLIN_JAVASCRIPT ->
this.configureAs(KotlinStdJSProjectDescriptor.instance)
else -> throw IllegalArgumentException("Unknown kind=$kind")
}
}
public fun JetFile.dumpTextWithErrors(): String {
val diagnostics = analyzeFullyAndGetResult().bindingContext.getDiagnostics()
val errors = diagnostics.filter { it.getSeverity() == Severity.ERROR }
if (errors.isEmpty()) return getText()
val header = errors.map { "// ERROR: " + DefaultErrorMessages.render(it).replace('\n', ' ') }.joinToString("\n", postfix = "\n")
return header + getText()
}