Skip to content

Commit

Permalink
Test
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 374604355
  • Loading branch information
mai93 authored and copybara-github committed May 19, 2021
1 parent 75a4121 commit 1b0cb2b
Show file tree
Hide file tree
Showing 11 changed files with 349 additions and 5 deletions.
4 changes: 2 additions & 2 deletions testing/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
2 changes: 1 addition & 1 deletion testing/src/com/google/idea/testing/ServiceHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static <T> void registerExtensionPoint(
ExtensionPointName<T> name, Class<T> 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));
}

Expand Down
2 changes: 0 additions & 2 deletions testing/src/com/google/idea/testing/TestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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<Throwable> r) throws Throwable {
EdtTestUtil.runInEdtAndWait(r);
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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<HeadersSearchPath> getHeadersSearchPaths() {
return Collections.emptyList();
}

@Override
public List<VirtualFile> getImplicitIncludes() {
return Collections.emptyList();
}

@Override
public List<String> getImplicitIncludeUrls() {
return Collections.emptyList();
}

@Nullable
@Override
public VirtualFile getMappedInclude(String include) {
return null;
}

@Override
public String getMappedIncludeUrl(String include) {
return "";
}

@Override
public List<String> getPreprocessorDefines() {
return Collections.emptyList();
}

@Override
public Map<OCCompilerFeatures.Type<?>, ?> getCompilerFeatures() {
return new HashMap<>();
}

@Nullable
@Override
public CompilerSettingsKey getCachingKey() {
return null;
}

@Override
public Object getIndexingCluster() {
return null;
}

public void setLibraryIncludeRoots(List<HeadersSearchRoot> roots) {
this.roots = HeadersSearchRoots.create(roots);
}
}
Loading

0 comments on commit 1b0cb2b

Please sign in to comment.