diff --git a/clwb/BUILD b/clwb/BUILD
index 12c2d082196..d2640e5ce1e 100644
--- a/clwb/BUILD
+++ b/clwb/BUILD
@@ -7,6 +7,7 @@ load(
"//build_defs:build_defs.bzl",
"intellij_plugin",
"intellij_plugin_library",
+ "optional_plugin_xml",
"plugin_deploy_zip",
"repackaged_files",
"stamped_plugin_xml",
@@ -30,10 +31,17 @@ licenses(["notice"])
intellij_plugin_library(
name = "plugin_library",
plugin_xmls = ["src/META-INF/clwb.xml"],
+ optional_plugin_xmls = ["optional_clwb_oclang"],
visibility = PLUGIN_PACKAGES_VISIBILITY,
deps = [":clwb_lib"],
)
+optional_plugin_xml(
+ name = "optional_clwb_oclang",
+ module = "com.intellij.modules.cidr.lang",
+ plugin_xml = "src/META-INF/clwb-oclang.xml",
+)
+
stamped_plugin_xml(
name = "stamped_plugin_xml",
changelog_file = "//:changelog",
diff --git a/clwb/src/META-INF/clwb-oclang.xml b/clwb/src/META-INF/clwb-oclang.xml
new file mode 100644
index 00000000000..ce48b2a6db8
--- /dev/null
+++ b/clwb/src/META-INF/clwb-oclang.xml
@@ -0,0 +1,25 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/clwb/src/META-INF/clwb.xml b/clwb/src/META-INF/clwb.xml
index 109f5077a8d..b8ffab8b6d7 100644
--- a/clwb/src/META-INF/clwb.xml
+++ b/clwb/src/META-INF/clwb.xml
@@ -19,6 +19,10 @@
com.intellij.modules.clion
org.jetbrains.plugins.clion.test.google
+
+
+
+
@@ -31,15 +35,10 @@
-
-
-
-
-
-
+
diff --git a/clwb/src/com/google/idea/blaze/clwb/run/BlazeCidrDebuggerSupportFactory.java b/clwb/src/com/google/idea/blaze/clwb/oclang/run/BlazeCidrDebuggerSupportFactory.java
similarity index 93%
rename from clwb/src/com/google/idea/blaze/clwb/run/BlazeCidrDebuggerSupportFactory.java
rename to clwb/src/com/google/idea/blaze/clwb/oclang/run/BlazeCidrDebuggerSupportFactory.java
index 50b6e6a6772..5453d6d9a06 100644
--- a/clwb/src/com/google/idea/blaze/clwb/run/BlazeCidrDebuggerSupportFactory.java
+++ b/clwb/src/com/google/idea/blaze/clwb/oclang/run/BlazeCidrDebuggerSupportFactory.java
@@ -13,9 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.google.idea.blaze.clwb.run;
+package com.google.idea.blaze.clwb.oclang.run;
import com.google.idea.blaze.base.run.BlazeCommandRunConfiguration;
+import com.google.idea.blaze.clwb.run.RunConfigurationUtils;
import com.intellij.execution.configurations.RunProfile;
import com.intellij.xdebugger.evaluation.XDebuggerEditorsProvider;
import com.jetbrains.cidr.execution.debugger.OCDebuggerLanguageSupport;
diff --git a/clwb/src/com/google/idea/blaze/clwb/CidrGoogleTestUtilAdapter.java b/clwb/src/com/google/idea/blaze/clwb/oclang/run/CidrGoogleTestUtilAdapter.java
similarity index 96%
rename from clwb/src/com/google/idea/blaze/clwb/CidrGoogleTestUtilAdapter.java
rename to clwb/src/com/google/idea/blaze/clwb/oclang/run/CidrGoogleTestUtilAdapter.java
index 765b7865563..ec5aa1aeb4f 100644
--- a/clwb/src/com/google/idea/blaze/clwb/CidrGoogleTestUtilAdapter.java
+++ b/clwb/src/com/google/idea/blaze/clwb/oclang/run/CidrGoogleTestUtilAdapter.java
@@ -13,9 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.google.idea.blaze.clwb;
+package com.google.idea.blaze.clwb.oclang.run;
import com.google.common.collect.Iterables;
+import com.google.idea.blaze.clwb.run.GoogleTestUtilAdapter;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Couple;
import com.intellij.psi.PsiElement;
@@ -33,12 +34,7 @@
import javax.annotation.Nullable;
/** Adapter to bridge different SDK versions. */
-public class CidrGoogleTestUtilAdapter {
- @Nullable
- public static PsiElement findGoogleTestSymbol(Project project) {
- return findGoogleTestSymbol(project, testScopeElement -> true);
- }
-
+public class CidrGoogleTestUtilAdapter implements GoogleTestUtilAdapter {
@Nullable
public static PsiElement findGoogleTestSymbol(
Project project, String suiteName, String testName) {
@@ -132,7 +128,7 @@ public static Couple extractFullSuiteNameFromMacro(PsiElement element) {
}
@Nullable
- private static PsiElement findGoogleTestSymbol(
+ public PsiElement findGoogleTestSymbol(
Project project, Predicate predicate) {
CidrGoogleTestFramework instance = CidrGoogleTestFramework.getInstance();
FindFirstWithPredicateProcessor processor =
diff --git a/clwb/src/com/google/idea/blaze/clwb/run/producers/CppTestContextProvider.java b/clwb/src/com/google/idea/blaze/clwb/oclang/run/producers/CppTestContextProvider.java
similarity index 96%
rename from clwb/src/com/google/idea/blaze/clwb/run/producers/CppTestContextProvider.java
rename to clwb/src/com/google/idea/blaze/clwb/oclang/run/producers/CppTestContextProvider.java
index 0d9ae5a5bfc..2ce2098e8d9 100644
--- a/clwb/src/com/google/idea/blaze/clwb/run/producers/CppTestContextProvider.java
+++ b/clwb/src/com/google/idea/blaze/clwb/oclang/run/producers/CppTestContextProvider.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.google.idea.blaze.clwb.run.producers;
+package com.google.idea.blaze.clwb.oclang.run.producers;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
@@ -25,8 +25,8 @@
import com.google.idea.blaze.base.run.producers.TestContext;
import com.google.idea.blaze.base.run.producers.TestContextProvider;
import com.google.idea.blaze.base.run.targetfinder.FuturesUtil;
-import com.google.idea.blaze.clwb.run.test.GoogleTestLocation;
-import com.google.idea.blaze.clwb.run.test.GoogleTestSpecification;
+import com.google.idea.blaze.clwb.oclang.run.test.GoogleTestLocation;
+import com.google.idea.blaze.clwb.oclang.run.test.GoogleTestSpecification;
import com.google.idea.blaze.cpp.CppBlazeRules.RuleTypes;
import com.intellij.execution.Location;
import com.intellij.execution.actions.ConfigurationContext;
diff --git a/clwb/src/com/google/idea/blaze/clwb/run/test/BlazeCidrTestEventsHandler.java b/clwb/src/com/google/idea/blaze/clwb/oclang/run/test/BlazeCidrTestEventsHandler.java
similarity index 97%
rename from clwb/src/com/google/idea/blaze/clwb/run/test/BlazeCidrTestEventsHandler.java
rename to clwb/src/com/google/idea/blaze/clwb/oclang/run/test/BlazeCidrTestEventsHandler.java
index ec2eeff0d9f..3c8cabef8d8 100644
--- a/clwb/src/com/google/idea/blaze/clwb/run/test/BlazeCidrTestEventsHandler.java
+++ b/clwb/src/com/google/idea/blaze/clwb/oclang/run/test/BlazeCidrTestEventsHandler.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.google.idea.blaze.clwb.run.test;
+package com.google.idea.blaze.clwb.oclang.run.test;
import static com.google.common.collect.ImmutableList.toImmutableList;
diff --git a/clwb/src/com/google/idea/blaze/clwb/run/test/BlazeCppTestInfo.java b/clwb/src/com/google/idea/blaze/clwb/oclang/run/test/BlazeCppTestInfo.java
similarity index 98%
rename from clwb/src/com/google/idea/blaze/clwb/run/test/BlazeCppTestInfo.java
rename to clwb/src/com/google/idea/blaze/clwb/oclang/run/test/BlazeCppTestInfo.java
index 87c507b2d9c..cba65acfa8f 100644
--- a/clwb/src/com/google/idea/blaze/clwb/run/test/BlazeCppTestInfo.java
+++ b/clwb/src/com/google/idea/blaze/clwb/oclang/run/test/BlazeCppTestInfo.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.google.idea.blaze.clwb.run.test;
+package com.google.idea.blaze.clwb.oclang.run.test;
import com.google.common.collect.ImmutableList;
import com.google.idea.blaze.base.run.smrunner.SmRunnerUtils;
diff --git a/clwb/src/com/google/idea/blaze/clwb/run/test/BlazeCppTestLocator.java b/clwb/src/com/google/idea/blaze/clwb/oclang/run/test/BlazeCppTestLocator.java
similarity index 96%
rename from clwb/src/com/google/idea/blaze/clwb/run/test/BlazeCppTestLocator.java
rename to clwb/src/com/google/idea/blaze/clwb/oclang/run/test/BlazeCppTestLocator.java
index 29aa142ae00..0f3442d24fe 100644
--- a/clwb/src/com/google/idea/blaze/clwb/run/test/BlazeCppTestLocator.java
+++ b/clwb/src/com/google/idea/blaze/clwb/oclang/run/test/BlazeCppTestLocator.java
@@ -13,10 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.google.idea.blaze.clwb.run.test;
+package com.google.idea.blaze.clwb.oclang.run.test;
import com.google.common.collect.ImmutableList;
-import com.google.idea.blaze.clwb.CidrGoogleTestUtilAdapter;
+import com.google.idea.blaze.clwb.oclang.run.CidrGoogleTestUtilAdapter;
import com.intellij.execution.Location;
import com.intellij.execution.testframework.sm.runner.SMTestLocator;
import com.intellij.openapi.project.Project;
diff --git a/clwb/src/com/google/idea/blaze/clwb/run/test/GoogleTestLocation.java b/clwb/src/com/google/idea/blaze/clwb/oclang/run/test/GoogleTestLocation.java
similarity index 98%
rename from clwb/src/com/google/idea/blaze/clwb/run/test/GoogleTestLocation.java
rename to clwb/src/com/google/idea/blaze/clwb/oclang/run/test/GoogleTestLocation.java
index 3a0f1bf3f52..7aa388c605a 100644
--- a/clwb/src/com/google/idea/blaze/clwb/run/test/GoogleTestLocation.java
+++ b/clwb/src/com/google/idea/blaze/clwb/oclang/run/test/GoogleTestLocation.java
@@ -13,11 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.google.idea.blaze.clwb.run.test;
+package com.google.idea.blaze.clwb.oclang.run.test;
import com.google.idea.blaze.base.sync.autosync.ProjectTargetManager.SyncStatus;
import com.google.idea.blaze.base.syncstatus.SyncStatusContributor;
-import com.google.idea.blaze.clwb.CidrGoogleTestUtilAdapter;
+import com.google.idea.blaze.clwb.oclang.run.CidrGoogleTestUtilAdapter;
import com.intellij.execution.Location;
import com.intellij.execution.PsiLocation;
import com.intellij.openapi.project.Project;
diff --git a/clwb/src/com/google/idea/blaze/clwb/run/test/GoogleTestSpecification.java b/clwb/src/com/google/idea/blaze/clwb/oclang/run/test/GoogleTestSpecification.java
similarity index 98%
rename from clwb/src/com/google/idea/blaze/clwb/run/test/GoogleTestSpecification.java
rename to clwb/src/com/google/idea/blaze/clwb/oclang/run/test/GoogleTestSpecification.java
index 5f30cd78976..4c84608e2bf 100644
--- a/clwb/src/com/google/idea/blaze/clwb/run/test/GoogleTestSpecification.java
+++ b/clwb/src/com/google/idea/blaze/clwb/oclang/run/test/GoogleTestSpecification.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.google.idea.blaze.clwb.run.test;
+package com.google.idea.blaze.clwb.oclang.run.test;
import com.google.common.base.Joiner;
import com.intellij.openapi.util.text.StringUtil;
diff --git a/clwb/src/com/google/idea/blaze/clwb/run/BlazeCidrLauncher.java b/clwb/src/com/google/idea/blaze/clwb/run/BlazeCidrLauncher.java
index 87ba9925bef..b4da2bc712b 100644
--- a/clwb/src/com/google/idea/blaze/clwb/run/BlazeCidrLauncher.java
+++ b/clwb/src/com/google/idea/blaze/clwb/run/BlazeCidrLauncher.java
@@ -44,7 +44,6 @@
import com.google.idea.blaze.base.settings.Blaze;
import com.google.idea.blaze.base.settings.BlazeUserSettings;
import com.google.idea.blaze.base.settings.BuildSystemName;
-import com.google.idea.blaze.clwb.CidrGoogleTestUtilAdapter;
import com.google.idea.blaze.clwb.ToolchainUtils;
import com.google.idea.blaze.cpp.CppBlazeRules;
import com.intellij.execution.ExecutionException;
@@ -296,7 +295,7 @@ private boolean shouldDisplayBazelTestFilterWarning() {
&& handlerState.getTestFilterFlag() != null
&& !PropertiesComponent.getInstance()
.getBoolean(DISABLE_BAZEL_GOOGLETEST_FILTER_WARNING, false)
- && CidrGoogleTestUtilAdapter.findGoogleTestSymbol(getProject()) != null;
+ && GoogleTestUtilAdapter.findGoogleTestSymbol(getProject()) != null;
}
/**
diff --git a/clwb/src/com/google/idea/blaze/clwb/run/GoogleTestUtilAdapter.java b/clwb/src/com/google/idea/blaze/clwb/run/GoogleTestUtilAdapter.java
new file mode 100644
index 00000000000..0c23edb2d14
--- /dev/null
+++ b/clwb/src/com/google/idea/blaze/clwb/run/GoogleTestUtilAdapter.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2023 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.blaze.clwb.run;
+
+import com.intellij.openapi.extensions.ExtensionPointName;
+import com.intellij.openapi.project.Project;
+import com.intellij.psi.PsiElement;
+import com.jetbrains.cidr.execution.testing.CidrTestScopeElement;
+import java.util.function.Predicate;
+import javax.annotation.Nullable;
+
+public interface GoogleTestUtilAdapter {
+ ExtensionPointName EP_NAME =
+ ExtensionPointName.create("com.google.idea.blaze.clwb.googleTestUtilAdapter");
+
+ @Nullable
+ static PsiElement findGoogleTestSymbol(Project project) {
+ if (EP_NAME.getExtensionList().size() > 1) {
+ throw new IllegalStateException("More than 1 extension for " + EP_NAME.getName() + " is not supported");
+ }
+
+ GoogleTestUtilAdapter adapter = EP_NAME.getPoint().extensions().findFirst().orElse(null);
+ if (adapter != null) {
+ return adapter.findGoogleTestSymbol(project, testScopeElement -> true);
+ }
+
+ return null;
+ }
+
+ PsiElement findGoogleTestSymbol(
+ Project project, Predicate predicate);
+}
diff --git a/clwb/src/com/google/idea/blaze/clwb/run/RunConfigurationUtils.java b/clwb/src/com/google/idea/blaze/clwb/run/RunConfigurationUtils.java
index e39cf77a476..2431cd836d4 100644
--- a/clwb/src/com/google/idea/blaze/clwb/run/RunConfigurationUtils.java
+++ b/clwb/src/com/google/idea/blaze/clwb/run/RunConfigurationUtils.java
@@ -30,7 +30,7 @@ static boolean canUseClionHandler(@Nullable Kind kind) {
|| kind == CppBlazeRules.RuleTypes.CC_BINARY.getKind();
}
- static boolean canUseClionRunner(BlazeCommandRunConfiguration config) {
+ public static boolean canUseClionRunner(BlazeCommandRunConfiguration config) {
Kind kind = config.getTargetKind();
BlazeCommandRunConfigurationCommonState handlerState =
config.getHandlerStateIfType(BlazeCommandRunConfigurationCommonState.class);
diff --git a/clwb/tests/unittests/com/google/idea/blaze/clwb/run/test/BlazeCppTestInfoTest.java b/clwb/tests/unittests/com/google/idea/blaze/clwb/oclang/run/test/BlazeCppTestInfoTest.java
similarity index 98%
rename from clwb/tests/unittests/com/google/idea/blaze/clwb/run/test/BlazeCppTestInfoTest.java
rename to clwb/tests/unittests/com/google/idea/blaze/clwb/oclang/run/test/BlazeCppTestInfoTest.java
index 8d6a8d313c3..2c6b6a932b3 100644
--- a/clwb/tests/unittests/com/google/idea/blaze/clwb/run/test/BlazeCppTestInfoTest.java
+++ b/clwb/tests/unittests/com/google/idea/blaze/clwb/oclang/run/test/BlazeCppTestInfoTest.java
@@ -13,11 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.google.idea.blaze.clwb.run.test;
+package com.google.idea.blaze.clwb.oclang.run.test;
import static com.google.common.truth.Truth.assertThat;
import com.google.idea.blaze.base.run.smrunner.SmRunnerUtils;
+import com.google.idea.blaze.clwb.oclang.run.test.BlazeCppTestInfo;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
diff --git a/cpp/BUILD b/cpp/BUILD
index 182a07076b7..7b69ef289a2 100644
--- a/cpp/BUILD
+++ b/cpp/BUILD
@@ -25,6 +25,7 @@ java_library(
"src/com/google/idea/blaze/cpp/includes/*.java",
"src/com/google/idea/blaze/cpp/syncstatus/*.java",
"src/com/google/idea/blaze/cpp/navigation/*.java",
+ "src/com/google/idea/blaze/cpp/oclang/*.java",
]),
visibility = PLUGIN_PACKAGES_VISIBILITY,
deps = [
@@ -40,14 +41,20 @@ java_library(
],
)
+stamped_plugin_xml(
+ name = "non_optional_cidr",
+ plugin_xml = "src/META-INF/blaze-cpp.xml",
+)
+
optional_plugin_xml(
name = "optional_cidr",
module = "com.intellij.modules.cidr.lang",
- plugin_xml = "src/META-INF/blaze-cpp.xml",
+ plugin_xml = "src/META-INF/blaze-cpp-oclang.xml",
)
intellij_plugin_library(
name = "plugin_library",
+ plugin_xmls = [":non_optional_cidr"],
optional_plugin_xmls = [":optional_cidr"],
visibility = PLUGIN_PACKAGES_VISIBILITY,
deps = [":cpp"],
diff --git a/cpp/src/META-INF/blaze-cpp-oclang.xml b/cpp/src/META-INF/blaze-cpp-oclang.xml
new file mode 100644
index 00000000000..a53553e74c1
--- /dev/null
+++ b/cpp/src/META-INF/blaze-cpp-oclang.xml
@@ -0,0 +1,27 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/cpp/src/META-INF/blaze-cpp.xml b/cpp/src/META-INF/blaze-cpp.xml
index eb723af7302..e35073ea9ec 100644
--- a/cpp/src/META-INF/blaze-cpp.xml
+++ b/cpp/src/META-INF/blaze-cpp.xml
@@ -14,7 +14,6 @@
~ limitations under the License.
-->
- com.intellij.modules.cidr.lang
com.intellij.modules.cidr.debugger
@@ -26,12 +25,14 @@
+
+
-
@@ -39,9 +40,6 @@
-
-
-
diff --git a/cpp/src/com/google/idea/blaze/cpp/BlazeResolveConfiguration.java b/cpp/src/com/google/idea/blaze/cpp/BlazeResolveConfiguration.java
index 8f0e5df1f2a..c87b5628efd 100644
--- a/cpp/src/com/google/idea/blaze/cpp/BlazeResolveConfiguration.java
+++ b/cpp/src/com/google/idea/blaze/cpp/BlazeResolveConfiguration.java
@@ -31,8 +31,6 @@
import com.jetbrains.cidr.lang.CLanguageKind;
import com.jetbrains.cidr.lang.OCFileTypeHelpers;
import com.jetbrains.cidr.lang.OCLanguageKind;
-import com.jetbrains.cidr.lang.preprocessor.OCImportGraph;
-import com.jetbrains.cidr.lang.workspace.OCLanguageKindCalculator;
import com.jetbrains.cidr.lang.workspace.OCResolveConfiguration;
import java.io.File;
import java.util.Collection;
@@ -109,29 +107,18 @@ OCLanguageKind getDeclaredLanguageKind(VirtualFile sourceOrHeaderFile) {
}
if (OCFileTypeHelpers.isHeaderFile(fileName)) {
- return getLanguageKind(getSourceFileForHeaderFile(sourceOrHeaderFile));
+ return getLanguageKind(SourceFileFinder.findAndGetSourceFileForHeaderFile(project, sourceOrHeaderFile));
}
return null;
}
private OCLanguageKind getLanguageKind(@Nullable VirtualFile sourceFile) {
- OCLanguageKind kind = OCLanguageKindCalculator.tryFileTypeAndExtension(project, sourceFile);
- return kind != null ? kind : getMaximumLanguageKind();
- }
+ if (sourceFile == null)
+ return getMaximumLanguageKind();
- @Nullable
- private VirtualFile getSourceFileForHeaderFile(VirtualFile headerFile) {
- Collection roots =
- OCImportGraph.getInstance(project).getAllHeaderRoots(headerFile);
-
- final String headerNameWithoutExtension = headerFile.getNameWithoutExtension();
- for (VirtualFile root : roots) {
- if (root.getNameWithoutExtension().equals(headerNameWithoutExtension)) {
- return root;
- }
- }
- return null;
+ OCLanguageKind kind = OCFileTypeHelpers.getLanguageKind(sourceFile.getName());
+ return kind != null ? kind : getMaximumLanguageKind();
}
private static OCLanguageKind getMaximumLanguageKind() {
diff --git a/cpp/src/com/google/idea/blaze/cpp/SourceFileFinder.java b/cpp/src/com/google/idea/blaze/cpp/SourceFileFinder.java
new file mode 100644
index 00000000000..a1e23593672
--- /dev/null
+++ b/cpp/src/com/google/idea/blaze/cpp/SourceFileFinder.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2023 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.blaze.cpp;
+
+import com.intellij.openapi.extensions.ExtensionPointName;
+import com.intellij.openapi.project.Project;
+import com.intellij.openapi.vfs.VirtualFile;
+import javax.annotation.Nullable;
+
+public interface SourceFileFinder {
+ ExtensionPointName EP_NAME =
+ ExtensionPointName.create("com.google.idea.blaze.cpp.SourceFileFinder");
+
+ @Nullable
+ VirtualFile getSourceFileForHeaderFile(Project project, VirtualFile headerFile);
+
+ static VirtualFile findAndGetSourceFileForHeaderFile(Project project, VirtualFile headerFile) {
+ if (EP_NAME.getExtensionList().size() > 1) {
+ throw new IllegalStateException("More than 1 extension for " + EP_NAME.getName() + " is not supported");
+ }
+
+ SourceFileFinder finder = EP_NAME.getPoint().extensions().findFirst().orElse(null);
+ if (finder != null) {
+ return finder.getSourceFileForHeaderFile(project, headerFile);
+ }
+
+ return null;
+ }
+}
diff --git a/cpp/src/com/google/idea/blaze/cpp/BlazeCppAutoImportHelper.java b/cpp/src/com/google/idea/blaze/cpp/oclang/BlazeCppAutoImportHelper.java
similarity index 99%
rename from cpp/src/com/google/idea/blaze/cpp/BlazeCppAutoImportHelper.java
rename to cpp/src/com/google/idea/blaze/cpp/oclang/BlazeCppAutoImportHelper.java
index fa9e596b15e..25d53bb28c5 100644
--- a/cpp/src/com/google/idea/blaze/cpp/BlazeCppAutoImportHelper.java
+++ b/cpp/src/com/google/idea/blaze/cpp/oclang/BlazeCppAutoImportHelper.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.google.idea.blaze.cpp;
+package com.google.idea.blaze.cpp.oclang;
import com.google.common.collect.ImmutableList;
import com.google.idea.blaze.base.settings.Blaze;
diff --git a/cpp/src/com/google/idea/blaze/cpp/BlazeCustomHeaderProvider.java b/cpp/src/com/google/idea/blaze/cpp/oclang/BlazeCustomHeaderProvider.java
similarity index 99%
rename from cpp/src/com/google/idea/blaze/cpp/BlazeCustomHeaderProvider.java
rename to cpp/src/com/google/idea/blaze/cpp/oclang/BlazeCustomHeaderProvider.java
index d8c16b0268a..8d0530d8b37 100644
--- a/cpp/src/com/google/idea/blaze/cpp/BlazeCustomHeaderProvider.java
+++ b/cpp/src/com/google/idea/blaze/cpp/oclang/BlazeCustomHeaderProvider.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.google.idea.blaze.cpp;
+package com.google.idea.blaze.cpp.oclang;
import com.google.idea.blaze.base.io.VirtualFileSystemProvider;
import com.google.idea.blaze.base.model.BlazeProjectData;
diff --git a/cpp/src/com/google/idea/blaze/cpp/BlazeIncludeHelper.java b/cpp/src/com/google/idea/blaze/cpp/oclang/BlazeIncludeHelper.java
similarity index 97%
rename from cpp/src/com/google/idea/blaze/cpp/BlazeIncludeHelper.java
rename to cpp/src/com/google/idea/blaze/cpp/oclang/BlazeIncludeHelper.java
index 5b8617e7e9f..1033bd561b2 100644
--- a/cpp/src/com/google/idea/blaze/cpp/BlazeIncludeHelper.java
+++ b/cpp/src/com/google/idea/blaze/cpp/oclang/BlazeIncludeHelper.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.google.idea.blaze.cpp;
+package com.google.idea.blaze.cpp.oclang;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
diff --git a/cpp/src/com/google/idea/blaze/cpp/syncstatus/CppSyncStatusContributor.java b/cpp/src/com/google/idea/blaze/cpp/oclang/CppSyncStatusContributor.java
similarity index 97%
rename from cpp/src/com/google/idea/blaze/cpp/syncstatus/CppSyncStatusContributor.java
rename to cpp/src/com/google/idea/blaze/cpp/oclang/CppSyncStatusContributor.java
index f25674a6ddf..a79ddda74ac 100644
--- a/cpp/src/com/google/idea/blaze/cpp/syncstatus/CppSyncStatusContributor.java
+++ b/cpp/src/com/google/idea/blaze/cpp/oclang/CppSyncStatusContributor.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.google.idea.blaze.cpp.syncstatus;
+package com.google.idea.blaze.cpp.oclang;
import com.google.idea.blaze.base.model.BlazeProjectData;
import com.google.idea.blaze.base.model.primitives.LanguageClass;
diff --git a/cpp/src/com/google/idea/blaze/cpp/oclang/OCSourceFileFinder.java b/cpp/src/com/google/idea/blaze/cpp/oclang/OCSourceFileFinder.java
new file mode 100644
index 00000000000..21f64ebb8cc
--- /dev/null
+++ b/cpp/src/com/google/idea/blaze/cpp/oclang/OCSourceFileFinder.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2023 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.blaze.cpp.oclang;
+
+import com.google.idea.blaze.cpp.SourceFileFinder;
+import com.intellij.openapi.project.Project;
+import com.intellij.openapi.vfs.VirtualFile;
+import com.jetbrains.cidr.lang.preprocessor.OCImportGraph;
+import java.util.Collection;
+import javax.annotation.Nullable;
+
+public class OCSourceFileFinder implements SourceFileFinder {
+ @Nullable
+ public VirtualFile getSourceFileForHeaderFile(Project project, VirtualFile headerFile) {
+ Collection roots =
+ OCImportGraph.getInstance(project).getAllHeaderRoots(headerFile);
+
+ final String headerNameWithoutExtension = headerFile.getNameWithoutExtension();
+ for (VirtualFile root : roots) {
+ if (root.getNameWithoutExtension().equals(headerNameWithoutExtension)) {
+ return root;
+ }
+ }
+ return null;
+ }
+}