diff --git a/testing/BUILD b/testing/BUILD index 8bcea55d180..8c444e8253c 100644 --- a/testing/BUILD +++ b/testing/BUILD @@ -35,8 +35,8 @@ java_library( "intellij-ue-2020.2": glob(["testcompat/v202/com/google/idea/sdkcompat/**/*.java"]), "intellij-2020.3": glob(["testcompat/v203/com/google/idea/sdkcompat/**/*.java"]), "intellij-ue-2020.3": glob(["testcompat/v203/com/google/idea/sdkcompat/**/*.java"]), - "intellij-2021.1": glob(["testcompat/v203/com/google/idea/sdkcompat/**/*.java"]), - "intellij-ue-2021.1": glob(["testcompat/v203/com/google/idea/sdkcompat/**/*.java"]), + "intellij-2021.1": glob(["testcompat/v211/com/google/idea/sdkcompat/**/*.java"]), + "intellij-ue-2021.1": glob(["testcompat/v211/com/google/idea/sdkcompat/**/*.java"]), "default": glob(["testcompat/v203/com/google/idea/sdkcompat/**/*.java"]), }), deps = [ diff --git a/testing/src/com/google/idea/testing/ServiceHelper.java b/testing/src/com/google/idea/testing/ServiceHelper.java index b458c7ce269..8bb285d1359 100644 --- a/testing/src/com/google/idea/testing/ServiceHelper.java +++ b/testing/src/com/google/idea/testing/ServiceHelper.java @@ -39,7 +39,7 @@ public static void registerExtensionPoint( ExtensionPointName name, Class clazz, Disposable parentDisposable) { ExtensionsArea area = Extensions.getRootArea(); String epName = name.getName(); - area.registerExtensionPoint(epName, clazz.getName()); + area.registerExtensionPoint(epName, clazz.getName(), ExtensionPoint.Kind.INTERFACE); Disposer.register(parentDisposable, () -> area.unregisterExtensionPoint(epName)); } diff --git a/testing/src/com/google/idea/testing/TestUtils.java b/testing/src/com/google/idea/testing/TestUtils.java index ace577899ac..c5fe99400bf 100644 --- a/testing/src/com/google/idea/testing/TestUtils.java +++ b/testing/src/com/google/idea/testing/TestUtils.java @@ -22,7 +22,6 @@ import com.intellij.openapi.Disposable; import com.intellij.openapi.application.Application; import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.fileTypes.FileTypeManager; import com.intellij.openapi.util.Disposer; import com.intellij.openapi.vfs.encoding.EncodingManager; @@ -150,7 +149,6 @@ static void createMockApplication(Disposable parentDisposable) { } static MockProject mockProject(@Nullable PicoContainer container, Disposable parentDisposable) { - Extensions.registerAreaClass("IDEA_PROJECT", null); container = container != null ? container : new DefaultPicoContainer(); return new MockProject(container, parentDisposable); } diff --git a/testing/testcompat/v202/com/google/idea/sdkcompat/BaseSdkTestCompat.java b/testing/testcompat/v202/com/google/idea/sdkcompat/BaseSdkTestCompat.java index d3160d52707..84fb048314c 100644 --- a/testing/testcompat/v202/com/google/idea/sdkcompat/BaseSdkTestCompat.java +++ b/testing/testcompat/v202/com/google/idea/sdkcompat/BaseSdkTestCompat.java @@ -15,9 +15,12 @@ */ package com.google.idea.sdkcompat; +import com.intellij.openapi.extensions.ExtensionsArea; import com.intellij.openapi.vfs.VirtualFileSystem; import com.intellij.openapi.vfs.newvfs.impl.StubVirtualFile; import java.io.File; +import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.junit.rules.TemporaryFolder; @@ -42,4 +45,15 @@ public boolean isValid() { } }; } + + /** + * #api203 API to register extensions point requires ExtensionPoint.Kind and isDynamic boolean + * since 2021.1. + */ + public static void registerExtensionPoint( + ExtensionsArea area, + @NonNls @NotNull String extensionPointName, + @NotNull String extensionPointBeanClass) { + // area.registerExtensionPoint(extensionPointName, extensionPointBeanClass); + } } diff --git a/testing/testcompat/v203/com/google/idea/sdkcompat/BaseSdkTestCompat.java b/testing/testcompat/v203/com/google/idea/sdkcompat/BaseSdkTestCompat.java index 72a21638254..1d7d2385b7f 100644 --- a/testing/testcompat/v203/com/google/idea/sdkcompat/BaseSdkTestCompat.java +++ b/testing/testcompat/v203/com/google/idea/sdkcompat/BaseSdkTestCompat.java @@ -15,10 +15,13 @@ */ package com.google.idea.sdkcompat; +import com.intellij.openapi.extensions.ExtensionsArea; import com.intellij.openapi.vfs.VirtualFileSystem; import com.intellij.openapi.vfs.newvfs.impl.StubVirtualFile; import java.io.File; import java.nio.file.Path; +import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.junit.rules.TemporaryFolder; @@ -43,4 +46,15 @@ public boolean isValid() { } }; } + + /** + * #api203 API to register extensions point requires ExtensionPoint.Kind and isDynamic boolean + * since 2021.1. + */ + public static void registerExtensionPoint( + ExtensionsArea area, + @NonNls @NotNull String extensionPointName, + @NotNull String extensionPointBeanClass) { + // area.registerExtensionPoint(extensionPointName, extensionPointBeanClass, null, false); + } } diff --git a/testing/testcompat/v211/com/google/idea/sdkcompat/BaseSdkTestCompat.java b/testing/testcompat/v211/com/google/idea/sdkcompat/BaseSdkTestCompat.java new file mode 100644 index 00000000000..c19c107acff --- /dev/null +++ b/testing/testcompat/v211/com/google/idea/sdkcompat/BaseSdkTestCompat.java @@ -0,0 +1,58 @@ +/* + * Copyright 2021 The Bazel Authors. All rights reserved. + * + * 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 com.google.idea.sdkcompat; + +import com.intellij.openapi.extensions.ExtensionsArea; +import com.intellij.openapi.vfs.VirtualFileSystem; +import com.intellij.openapi.vfs.newvfs.impl.StubVirtualFile; +import java.io.File; +import java.nio.file.Path; +import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.junit.rules.TemporaryFolder; + +/** + * Provides SDK compatibility shims for base plugin API classes, available to all IDEs during + * test-time. + */ +public final class BaseSdkTestCompat { + private BaseSdkTestCompat() {} + /** #api202 {@link TemporaryFolder#getRoot} mock call needs to return Path since 2020.3 */ + @Nullable + public static Path getRootWrapper(@Nullable File file) { + return file == null ? null : file.toPath(); + } + + /** #api202 Creating a StubVirtualFile requires a filesystem parameter in 2020.3 */ + public static StubVirtualFile newValidStubVirtualFile(VirtualFileSystem fileSystem) { + return new StubVirtualFile(fileSystem) { + @Override + public boolean isValid() { + return true; + } + }; + } + + /** #api203 API for register extensions point requires ExtensionPoint.Kind since 2021.1. */ + public static void registerExtensionPoint( + ExtensionsArea area, + @NonNls @NotNull String extensionPointName, + @NotNull String extensionPointBeanClass) { + //area.registerExtensionPoint( + // extensionPointName, extensionPointBeanClass, ExtensionPoint.Kind.INTERFACE); + } +} diff --git a/testing/testcompat/v211/com/google/idea/sdkcompat/codeinsight/navigation/CtrlMouseHandlerCompat.java b/testing/testcompat/v211/com/google/idea/sdkcompat/codeinsight/navigation/CtrlMouseHandlerCompat.java new file mode 100644 index 00000000000..b43ea53b699 --- /dev/null +++ b/testing/testcompat/v211/com/google/idea/sdkcompat/codeinsight/navigation/CtrlMouseHandlerCompat.java @@ -0,0 +1,32 @@ +/* + * Copyright 2020 The Bazel Authors. All rights reserved. + * + * 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 com.google.idea.sdkcompat.codeinsight.navigation; + +import com.intellij.codeInsight.navigation.CtrlMouseHandler; +import com.intellij.openapi.editor.Editor; +import javax.annotation.Nullable; + +/** Compat class for {@link CtrlMouseHandler}. */ +public class CtrlMouseHandlerCompat { + + private CtrlMouseHandlerCompat() {} + + /** #api201: CtrlMouseHandler.BrowseMode.Declaration replaced with dedicated method in 2020.2 */ + @Nullable + public static String getGoToDeclarationOrUsagesText(Editor editor) { + return CtrlMouseHandler.getGoToDeclarationOrUsagesText(editor); + } +} diff --git a/testing/testcompat/v211/com/google/idea/sdkcompat/testframework/EdtTestUtilWrapper.java b/testing/testcompat/v211/com/google/idea/sdkcompat/testframework/EdtTestUtilWrapper.java new file mode 100644 index 00000000000..5a6595b03f7 --- /dev/null +++ b/testing/testcompat/v211/com/google/idea/sdkcompat/testframework/EdtTestUtilWrapper.java @@ -0,0 +1,31 @@ +/* + * Copyright 2021 The Bazel Authors. All rights reserved. + * + * 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 com.google.idea.sdkcompat.testframework; + +import com.intellij.testFramework.EdtTestUtil; +import com.intellij.util.ThrowableRunnable; + +/** + * #api202 {@link EdtTestUtil#runInEdtAndWait} uses {@link ThrowableRunnable} instead of {@link + * Runnable} since 2020.3 + */ +public final class EdtTestUtilWrapper { + private EdtTestUtilWrapper() {} + + public static void runInEdtAndWait(ThrowableRunnable r) throws Throwable { + EdtTestUtil.runInEdtAndWait(r); + } +} diff --git a/testing/testcompat/v211/com/google/idea/sdkcompat/testframework/fixtures/CompletionAutoPopupTesterAdapter.java b/testing/testcompat/v211/com/google/idea/sdkcompat/testframework/fixtures/CompletionAutoPopupTesterAdapter.java new file mode 100644 index 00000000000..13344fdfbc0 --- /dev/null +++ b/testing/testcompat/v211/com/google/idea/sdkcompat/testframework/fixtures/CompletionAutoPopupTesterAdapter.java @@ -0,0 +1,30 @@ +/* + * Copyright 2021 The Bazel Authors. All rights reserved. + * + * 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 com.google.idea.sdkcompat.testframework.fixtures; + +import com.intellij.testFramework.fixtures.CodeInsightTestFixture; +import com.intellij.testFramework.fixtures.CompletionAutoPopupTester; +import com.intellij.util.ThrowableRunnable; + +/** + * #api202 {@link CompletionAutoPopupTester#runWithAutoPopupEnabled} uses {@link ThrowableRunnable} + * instead of {@link Runnable} since 2020.3 + */ +public class CompletionAutoPopupTesterAdapter extends CompletionAutoPopupTester { + public CompletionAutoPopupTesterAdapter(CodeInsightTestFixture fixture) { + super(fixture); + } +} diff --git a/testing/testcompat/v211/com/google/idea/testing/cidr/StubOCCompilerSettings.java b/testing/testcompat/v211/com/google/idea/testing/cidr/StubOCCompilerSettings.java new file mode 100644 index 00000000000..02ec541a76e --- /dev/null +++ b/testing/testcompat/v211/com/google/idea/testing/cidr/StubOCCompilerSettings.java @@ -0,0 +1,124 @@ +/* + * Copyright 2017 The Bazel Authors. All rights reserved. + * + * 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 com.google.idea.testing.cidr; + +import com.intellij.openapi.project.Project; +import com.intellij.openapi.vfs.VfsUtilCore; +import com.intellij.openapi.vfs.VirtualFile; +import com.jetbrains.cidr.lang.toolchains.CidrCompilerSwitches; +import com.jetbrains.cidr.lang.toolchains.CidrSwitchBuilder; +import com.jetbrains.cidr.lang.workspace.OCCompilerSettings; +import com.jetbrains.cidr.lang.workspace.compiler.CompilerSettingsKey; +import com.jetbrains.cidr.lang.workspace.compiler.OCCompilerFeatures; +import com.jetbrains.cidr.lang.workspace.compiler.OCCompilerKind; +import com.jetbrains.cidr.lang.workspace.headerRoots.HeadersSearchPath; +import com.jetbrains.cidr.lang.workspace.headerRoots.HeadersSearchRoot; +import com.jetbrains.cidr.lang.workspace.headerRoots.HeadersSearchRoots; +import java.io.File; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import javax.annotation.Nullable; + +/** Stub {@link OCCompilerSettings} for testing. */ +class StubOCCompilerSettings implements OCCompilerSettings { + private final Project project; + private HeadersSearchRoots roots; + + StubOCCompilerSettings(Project project) { + this.project = project; + } + + @Override + @Nullable + public OCCompilerKind getCompilerKind() { + return OCCompilerKind.CLANG; + } + + @Override + @Nullable + public File getCompilerExecutable() { + return null; + } + + @Override + public File getCompilerWorkingDir() { + return VfsUtilCore.virtualToIoFile(project.getBaseDir()); + } + + @Override + @Nullable + public CidrCompilerSwitches getCompilerSwitches() { + return new CidrSwitchBuilder().build(); + } + + @Override + public HeadersSearchRoots getHeadersSearchRoots() { + return roots; + } + + @Override + public List getHeadersSearchPaths() { + return Collections.emptyList(); + } + + @Override + public List getImplicitIncludes() { + return Collections.emptyList(); + } + + @Override + public List getImplicitIncludeUrls() { + return Collections.emptyList(); + } + + @Nullable + @Override + public VirtualFile getMappedInclude(String include) { + return null; + } + + @Override + public String getMappedIncludeUrl(String include) { + return ""; + } + + @Override + public List getPreprocessorDefines() { + return Collections.emptyList(); + } + + @Override + public Map, ?> getCompilerFeatures() { + return new HashMap<>(); + } + + @Nullable + @Override + public CompilerSettingsKey getCachingKey() { + return null; + } + + @Override + public Object getIndexingCluster() { + return null; + } + + public void setLibraryIncludeRoots(List roots) { + this.roots = HeadersSearchRoots.create(roots); + } +} diff --git a/testing/testcompat/v211/com/google/idea/testing/cidr/StubOCResolveConfiguration.java b/testing/testcompat/v211/com/google/idea/testing/cidr/StubOCResolveConfiguration.java new file mode 100644 index 00000000000..3138f57e806 --- /dev/null +++ b/testing/testcompat/v211/com/google/idea/testing/cidr/StubOCResolveConfiguration.java @@ -0,0 +1,43 @@ +/* + * Copyright 2020 The Bazel Authors. All rights reserved. + * + * 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 com.google.idea.testing.cidr; + +import com.intellij.openapi.project.Project; +import com.intellij.openapi.vfs.VirtualFile; +import com.jetbrains.cidr.lang.toolchains.CidrFileSeparators; +import com.jetbrains.cidr.lang.workspace.OCResolveConfiguration; +import org.jetbrains.annotations.NotNull; + +/** + * Stub {@link OCResolveConfiguration} for testing. + * + *

#api201 + */ +public class StubOCResolveConfiguration extends StubOCResolveConfigurationBase { + public StubOCResolveConfiguration(Project project) { + super(project); + } + + @Override + public CidrFileSeparators getFileSeparators() { + return CidrFileSeparators.UNIX; + } + + @Override + public boolean hasSourceFile(@NotNull VirtualFile virtualFile) { + return false; + } +}