Java Code Examples for com.intellij.util.PlatformUtils

The following examples show how to use com.intellij.util.PlatformUtils. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: tabnine-intellij   Source File: TabNineProcess.java    License: MIT License 6 votes vote down vote up
void startTabNine() throws IOException {
    if (this.proc != null) {
        this.proc.destroy();
        this.proc = null;
    }
    // When we tell TabNine that it's talking to IntelliJ, it won't suggest language server
    // setup since we assume it's already built into the IDE
    List<String> command = new ArrayList<>();
    command.add(TabNineFinder.getTabNinePath());
    List<String> metadata = new ArrayList<>();
    metadata.add("--client-metadata");
    metadata.add("pluginVersion=" + Utils.getPluginVersion());
    metadata.add("clientIsUltimate=" + PlatformUtils.isIdeaUltimate());
    final ApplicationInfo applicationInfo = ApplicationInfo.getInstance();
    if (applicationInfo != null) {
        command.add("--client");
        command.add(applicationInfo.getVersionName());
        metadata.add("clientVersion=" + applicationInfo.getFullVersion());
        metadata.add("clientApiVersion=" + applicationInfo.getApiVersion());
    }
    command.addAll(metadata);
    ProcessBuilder builder = new ProcessBuilder(command);
    this.proc = builder.start();
    this.procLineReader = new BufferedReader(new InputStreamReader(this.proc.getInputStream(), StandardCharsets.UTF_8));
}
 
Example 2
public void addSettingsFields(@NotNull SettingsStep settingsStep) {
  settingsStep.addSettingsField(FlutterBundle.message("flutter.module.create.settings.description.label"), descriptionField);
  settingsStep.addSettingsField(FlutterBundle.message("flutter.module.create.settings.type.label"),
                                projectTypeForm.getComponent());
  settingsStep.addSettingsField(FlutterBundle.message("flutter.module.create.settings.radios.org.label"), orgField);
  settingsStep.addSettingsField(FlutterBundle.message("flutter.module.create.settings.radios.android.label"),
                                androidLanguageRadios.getComponent());
  settingsStep.addSettingsField(FlutterBundle.message("flutter.module.create.settings.radios.ios.label"),
                                iosLanguageRadios.getComponent());
  // WebStorm has a smaller area for the wizard UI.
  if (!PlatformUtils.isWebStorm()) {
    settingsStep.addSettingsComponent(new SettingsHelpForm().getComponent());
  }

  settingsStep.addSettingsComponent(createParams.setInitialValues().getComponent());
}
 
Example 3
/**
 * Return true if the passed module is of a Flutter type. Before version M16 this plugin had its own Flutter {@link ModuleType}.
 * Post M16 a Flutter module is defined by the following:
 * <p>
 * <code>
 * [Flutter support enabled for a module] ===
 * [Dart support enabled && referenced Dart SDK is the one inside a Flutter SDK]
 * </code>
 */
public static boolean isFlutterModule(@Nullable final Module module) {
  if (module == null || module.isDisposed()) return false;

  if (PlatformUtils.isIntelliJ() || FlutterUtils.isAndroidStudio()) {
    // [Flutter support enabled for a module] ===
    //   [Dart support enabled && referenced Dart SDK is the one inside a Flutter SDK]
    final DartSdk dartSdk = DartPlugin.getDartSdk(module.getProject());
    final String dartSdkPath = dartSdk != null ? dartSdk.getHomePath() : null;
    return validDartSdkPath(dartSdkPath) && DartPlugin.isDartSdkEnabled(module);
  }
  else {
    // If not IntelliJ, assume a small IDE (no multi-module project support).
    return declaresFlutter(module);
  }
}
 
Example 4
public void addSettingsFields(@NotNull SettingsStep settingsStep) {
  settingsStep.addSettingsField(FlutterBundle.message("flutter.module.create.settings.description.label"), descriptionField);
  settingsStep.addSettingsField(FlutterBundle.message("flutter.module.create.settings.type.label"),
                                projectTypeForm.getComponent());
  settingsStep.addSettingsField(FlutterBundle.message("flutter.module.create.settings.radios.org.label"), orgField);
  settingsStep.addSettingsField(FlutterBundle.message("flutter.module.create.settings.radios.android.label"),
                                androidLanguageRadios.getComponent());
  settingsStep.addSettingsField(FlutterBundle.message("flutter.module.create.settings.radios.ios.label"),
                                iosLanguageRadios.getComponent());
  // WebStorm has a smaller area for the wizard UI.
  if (!PlatformUtils.isWebStorm()) {
    settingsStep.addSettingsComponent(new SettingsHelpForm().getComponent());
  }

  settingsStep.addSettingsComponent(createParams.setInitialValues().getComponent());
}
 
Example 5
/**
 * Return true if the passed module is of a Flutter type. Before version M16 this plugin had its own Flutter {@link ModuleType}.
 * Post M16 a Flutter module is defined by the following:
 * <p>
 * <code>
 * [Flutter support enabled for a module] ===
 * [Dart support enabled && referenced Dart SDK is the one inside a Flutter SDK]
 * </code>
 */
public static boolean isFlutterModule(@Nullable final Module module) {
  if (module == null || module.isDisposed()) return false;

  if (PlatformUtils.isIntelliJ() || FlutterUtils.isAndroidStudio()) {
    // [Flutter support enabled for a module] ===
    //   [Dart support enabled && referenced Dart SDK is the one inside a Flutter SDK]
    final DartSdk dartSdk = DartPlugin.getDartSdk(module.getProject());
    final String dartSdkPath = dartSdk != null ? dartSdk.getHomePath() : null;
    return validDartSdkPath(dartSdkPath) && DartPlugin.isDartSdkEnabled(module);
  }
  else {
    // If not IntelliJ, assume a small IDE (no multi-module project support).
    return declaresFlutter(module);
  }
}
 
Example 6
Source Project: intellij   Source File: BlazeJavascriptSyncPluginTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testJavascriptLanguageAvailableForUltimateEdition() {
  TestUtils.setPlatformPrefix(testDisposable, PlatformUtils.IDEA_PREFIX);
  ProjectViewSet projectViewSet =
      ProjectViewSet.builder()
          .add(
              ProjectView.builder()
                  .add(
                      ScalarSection.builder(WorkspaceTypeSection.KEY)
                          .set(WorkspaceType.JAVASCRIPT))
                  .add(
                      ListSection.builder(AdditionalLanguagesSection.KEY)
                          .add(LanguageClass.JAVASCRIPT))
                  .build())
          .build();
  WorkspaceLanguageSettings workspaceLanguageSettings =
      LanguageSupport.createWorkspaceLanguageSettings(projectViewSet);
  errorCollector.assertNoIssues();
  assertThat(workspaceLanguageSettings)
      .isEqualTo(
          new WorkspaceLanguageSettings(
              WorkspaceType.JAVASCRIPT,
              ImmutableSet.of(LanguageClass.JAVASCRIPT, LanguageClass.GENERIC)));
}
 
Example 7
Source Project: intellij   Source File: BlazeJavascriptSyncPluginTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testJavascriptWorkspaceTypeUnavailableForCommunityEdition() {
  TestUtils.setPlatformPrefix(testDisposable, PlatformUtils.IDEA_CE_PREFIX);
  ProjectViewSet projectViewSet =
      ProjectViewSet.builder()
          .add(
              ProjectView.builder()
                  .add(
                      ScalarSection.builder(WorkspaceTypeSection.KEY)
                          .set(WorkspaceType.JAVASCRIPT))
                  .build())
          .build();
  WorkspaceLanguageSettings workspaceLanguageSettings =
      LanguageSupport.createWorkspaceLanguageSettings(projectViewSet);
  LanguageSupport.validateLanguageSettings(context, workspaceLanguageSettings);
  errorCollector.assertIssues("Workspace type 'javascript' is not supported by this plugin");
}
 
Example 8
Source Project: intellij   Source File: BlazeTypescriptSyncPluginTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testTypescriptLanguageAvailableInUltimateEdition() {
  TestUtils.setPlatformPrefix(testDisposable, PlatformUtils.IDEA_PREFIX);
  ProjectViewSet projectViewSet =
      ProjectViewSet.builder()
          .add(
              ProjectView.builder()
                  .add(ScalarSection.builder(WorkspaceTypeSection.KEY).set(WorkspaceType.JAVA))
                  .add(
                      ListSection.builder(AdditionalLanguagesSection.KEY)
                          .add(LanguageClass.TYPESCRIPT))
                  .build())
          .build();
  WorkspaceLanguageSettings workspaceLanguageSettings =
      LanguageSupport.createWorkspaceLanguageSettings(projectViewSet);
  errorCollector.assertNoIssues();
  assertThat(workspaceLanguageSettings)
      .isEqualTo(
          new WorkspaceLanguageSettings(
              WorkspaceType.JAVA,
              ImmutableSet.of(
                  LanguageClass.TYPESCRIPT, LanguageClass.GENERIC, LanguageClass.JAVA)));
}
 
Example 9
Source Project: intellij   Source File: BlazeTypescriptSyncPluginTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testTypescriptNotLanguageAvailableInCommunityEdition() {
  TestUtils.setPlatformPrefix(testDisposable, PlatformUtils.IDEA_CE_PREFIX);
  ProjectViewSet projectViewSet =
      ProjectViewSet.builder()
          .add(
              ProjectView.builder()
                  .add(ScalarSection.builder(WorkspaceTypeSection.KEY).set(WorkspaceType.JAVA))
                  .add(
                      ListSection.builder(AdditionalLanguagesSection.KEY)
                          .add(LanguageClass.TYPESCRIPT))
                  .build())
          .build();
  WorkspaceLanguageSettings workspaceLanguageSettings =
      LanguageSupport.createWorkspaceLanguageSettings(projectViewSet);
  LanguageSupport.validateLanguageSettings(context, workspaceLanguageSettings);
  errorCollector.assertIssues("Language 'typescript' is not supported by this plugin");
}
 
Example 10
Source Project: intellij   Source File: JavascriptSyncTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testErrorMessageInCommunityEdition() {
  TestUtils.setPlatformPrefix(getTestRootDisposable(), PlatformUtils.IDEA_CE_PREFIX);
  setProjectView(
      "directories:",
      "  common/jslayout",
      "targets:",
      "  //common/jslayout/...:all",
      "workspace_type: javascript");

  workspace.createDirectory(new WorkspacePath("common/jslayout"));

  BlazeSyncParams syncParams =
      BlazeSyncParams.builder()
          .setTitle("Full Sync")
          .setSyncMode(SyncMode.FULL)
          .setSyncOrigin("test")
          .setBlazeBuildParams(BlazeBuildParams.fromProject(getProject()))
          .setAddProjectViewTargets(true)
          .build();
  runBlazeSync(syncParams);
  errorCollector.assertHasErrors();
}
 
Example 11
public void initComponent() {
    VERSION = PluginManager.getPlugin(PluginId.getId("com.wakatime.intellij.plugin")).getVersion();
    log.info("Initializing WakaTime plugin v" + VERSION + " (https://wakatime.com/)");
    //System.out.println("Initializing WakaTime plugin v" + VERSION + " (https://wakatime.com/)");

    // Set runtime constants
    IDE_NAME = PlatformUtils.getPlatformPrefix();
    IDE_VERSION = ApplicationInfo.getInstance().getFullVersion();

    setupDebugging();
    setLoggingLevel();
    Dependencies.configureProxy();
    checkApiKey();
    checkCli();
    setupEventListeners();
    setupQueueProcessor();
    checkDebug();
    log.info("Finished initializing WakaTime plugin");
}
 
Example 12
Source Project: intellij   Source File: FileGitHubIssueAction.java    License: Apache License 2.0 5 votes vote down vote up
private static String getProductId() {
  String platformPrefix = PlatformUtils.getPlatformPrefix();

  // IDEA Community Edition is "Idea", whereas IDEA Ultimate Edition is "idea". Let's make them
  // more useful.
  if (PlatformUtils.isIdeaCommunity()) {
    platformPrefix = "IdeaCommunity";
  } else if (PlatformUtils.isIdeaUltimate()) {
    platformPrefix = "IdeaUltimate";
  }
  return platformPrefix;
}
 
Example 13
Source Project: intellij   Source File: BlazeFlags.java    License: Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
public static String getToolTagFlag() {
  String platformPrefix = PlatformUtils.getPlatformPrefix();

  // IDEA Community Edition is "Idea", whereas IDEA Ultimate Edition is "idea".
  // That's dumb. Let's make them more useful.
  if (PlatformUtils.isIdeaCommunity()) {
    platformPrefix = "IDEA:community";
  } else if (PlatformUtils.isIdeaUltimate()) {
    platformPrefix = "IDEA:ultimate";
  }
  return TOOL_TAG + platformPrefix;
}
 
Example 14
Source Project: intellij   Source File: TestUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Sets the platform prefix system property, reverting to the previous value when the supplied
 * parent disposable is disposed.
 */
public static void setPlatformPrefix(Disposable parentDisposable, String platformPrefix) {
  String prevValue = System.getProperty(PlatformUtils.PLATFORM_PREFIX_KEY);
  System.setProperty(PlatformUtils.PLATFORM_PREFIX_KEY, platformPrefix);
  Disposer.register(
      parentDisposable,
      () -> {
        if (prevValue != null) {
          System.setProperty(PlatformUtils.PLATFORM_PREFIX_KEY, prevValue);
        } else {
          System.clearProperty(PlatformUtils.PLATFORM_PREFIX_KEY);
        }
      });
}
 
Example 15
Source Project: intellij   Source File: JUnitPluginDependencyWarning.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void initComponent() {
  Topics.subscribe(
      AppLifecycleListener.TOPIC,
      /* disposable= */ null,
      new AppLifecycleListener() {
        @Override
        public void appStarting(@Nullable Project projectFromCommandLine) {
          if (PlatformUtils.isIntelliJ() && !PluginUtils.isPluginEnabled(JUNIT_PLUGIN_ID)) {
            notifyJUnitNotEnabled();
          }
        }
      });
}
 
Example 16
@Test
public void testPrefetchedExtensions() {
  if (PlatformUtils.isIdeaUltimate()) {
    assertThat(PrefetchFileSource.getAllPrefetchFileExtensions())
        .containsExactly("java", "proto", "dart", "js", "html", "css", "gss", "ts", "tsx");
  } else {
    assertThat(PrefetchFileSource.getAllPrefetchFileExtensions())
        .containsExactly("java", "proto", "dart");
  }
}
 
Example 17
Source Project: intellij   Source File: JavascriptSyncTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testTestSourcesMissingFromDirectoriesSectionAreAdded() {
  TestUtils.setPlatformPrefix(getTestRootDisposable(), PlatformUtils.IDEA_PREFIX);
  setProjectView(
      "directories:",
      "  common/jslayout",
      "targets:",
      "  //common/jslayout/...:all",
      "test_sources:",
      "  */tests",
      "workspace_type: javascript");

  VirtualFile testDir = workspace.createDirectory(new WorkspacePath("common/jslayout/tests"));

  BlazeSyncParams syncParams =
      BlazeSyncParams.builder()
          .setTitle("Full Sync")
          .setSyncMode(SyncMode.FULL)
          .setSyncOrigin("test")
          .setBlazeBuildParams(BlazeBuildParams.fromProject(getProject()))
          .setAddProjectViewTargets(true)
          .build();
  runBlazeSync(syncParams);

  errorCollector.assertNoIssues();

  ImmutableList<ContentEntry> contentEntries = getWorkspaceContentEntries();
  assertThat(contentEntries).hasSize(1);

  SourceFolder root = findSourceFolder(contentEntries.get(0), testDir.getParent());
  assertThat(root.isTestSource()).isFalse();

  SourceFolder testRoot = findSourceFolder(contentEntries.get(0), testDir);
  assertThat(testRoot).isNotNull();
  assertThat(testRoot.isTestSource()).isTrue();
}
 
Example 18
Source Project: Custom-Syntax-Highlighter   Source File: TSColorSettings.java    License: MIT License 4 votes vote down vote up
@Override
public DisplayPriority getPriority() {
  return PlatformUtils.isWebStorm() ? DisplayPriority.KEY_LANGUAGE_SETTINGS : DisplayPriority.LANGUAGE_SETTINGS;
}
 
Example 19
Source Project: Custom-Syntax-Highlighter   Source File: JSColorSettings.java    License: MIT License 4 votes vote down vote up
@Override
public DisplayPriority getPriority() {
  return PlatformUtils.isWebStorm() ? DisplayPriority.KEY_LANGUAGE_SETTINGS : DisplayPriority.LANGUAGE_SETTINGS;
}
 
Example 20
Source Project: Custom-Syntax-Highlighter   Source File: JavaColorSettings.java    License: MIT License 4 votes vote down vote up
@Override
public DisplayPriority getPriority() {
  return PlatformUtils.isIntelliJ() ? DisplayPriority.KEY_LANGUAGE_SETTINGS : DisplayPriority.LANGUAGE_SETTINGS;
}
 
Example 21
@Override
public boolean isPrimaryGenerator() {
    return PlatformUtils.isPhpStorm();
}
 
Example 22
@Override
public boolean isPrimaryGenerator() {
    return PlatformUtils.isPhpStorm();
}
 
Example 23
public static boolean isAndroidStudio() {
  return StringUtil.equals(PlatformUtils.getPlatformPrefix(), "AndroidStudio");
}
 
Example 24
public static boolean isAndroidStudio() {
  return StringUtil.equals(PlatformUtils.getPlatformPrefix(), "AndroidStudio");
}
 
Example 25
Source Project: intellij   Source File: BlazeIntellijPluginConfiguration.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Plugin jar has been previously created via blaze build. This method: - copies jar to sandbox
 * environment - cracks open jar and finds plugin.xml (with ID, etc., needed for JVM args) - sets
 * up the SDK, etc. (use project SDK?) - sets up the JVM, and returns a JavaCommandLineState
 */
@Nullable
@Override
public RunProfileState getState(Executor executor, ExecutionEnvironment env)
    throws ExecutionException {
  final Sdk ideaJdk = pluginSdk;
  if (!IdeaJdkHelper.isIdeaJdk(ideaJdk)) {
    throw new ExecutionException("Choose an IntelliJ Platform Plugin SDK");
  }
  String sandboxHome = IdeaJdkHelper.getSandboxHome(ideaJdk);
  if (sandboxHome == null) {
    throw new ExecutionException("No sandbox specified for IntelliJ Platform Plugin SDK");
  }

  try {
    sandboxHome = new File(sandboxHome).getCanonicalPath();
  } catch (IOException e) {
    throw new ExecutionException("No sandbox specified for IntelliJ Platform Plugin SDK", e);
  }
  String buildNumber = IdeaJdkHelper.getBuildNumber(ideaJdk);
  final BlazeIntellijPluginDeployer deployer =
      new BlazeIntellijPluginDeployer(sandboxHome, buildNumber, target);
  env.putUserData(BlazeIntellijPluginDeployer.USER_DATA_KEY, deployer);

  // copy license from running instance of idea
  IdeaJdkHelper.copyIDEALicense(sandboxHome);

  return new JavaCommandLineState(env) {
    @Override
    protected JavaParameters createJavaParameters() throws ExecutionException {
      DeployedPluginInfo deployedPluginInfo = deployer.deployNonBlocking();

      final JavaParameters params = new JavaParameters();

      ParametersList vm = params.getVMParametersList();

      fillParameterList(vm, vmParameters);
      fillParameterList(params.getProgramParametersList(), programParameters);

      IntellijWithPluginClasspathHelper.addRequiredVmParams(
          params, ideaJdk, deployedPluginInfo.javaAgents);

      vm.defineProperty(
          JetBrainsProtocolHandler.REQUIRED_PLUGINS_KEY,
          Joiner.on(',').join(deployedPluginInfo.pluginIds));

      if (!vm.hasProperty(PlatformUtils.PLATFORM_PREFIX_KEY) && buildNumber != null) {
        String prefix = IdeaJdkHelper.getPlatformPrefix(buildNumber);
        if (prefix != null) {
          vm.defineProperty(PlatformUtils.PLATFORM_PREFIX_KEY, prefix);
        }
      }
      return params;
    }

    /** https://youtrack.jetbrains.com/issue/IDEA-201733 */
    @Override
    protected GeneralCommandLine createCommandLine() throws ExecutionException {
      GeneralCommandLine commandLine = super.createCommandLine();
      for (String jreName : new String[] {"jbr", "jre64", "jre"}) {
        File bundledJre = new File(ideaJdk.getHomePath(), jreName);
        if (bundledJre.isDirectory()) {
          File bundledJava = new File(bundledJre, "bin/java");
          if (bundledJava.canExecute()) {
            commandLine.setExePath(bundledJava.getAbsolutePath());
            break;
          }
        }
      }
      return commandLine;
    }

    @Override
    protected OSProcessHandler startProcess() throws ExecutionException {
      deployer.blockUntilDeployComplete();
      final OSProcessHandler handler = super.startProcess();
      handler.addProcessListener(
          new ProcessAdapter() {
            @Override
            public void processTerminated(ProcessEvent event) {
              deployer.deleteDeployment();
            }
          });
      return handler;
    }
  };
}
 
Example 26
Source Project: intellij   Source File: BlazeJavaUserSettings.java    License: Apache License 2.0 4 votes vote down vote up
static boolean allowJarCache() {
  return !SystemInfo.isMac
      || BuildSystemProvider.defaultBuildSystem().buildSystem() == BuildSystem.Bazel
      || "AndroidStudio".equals(PlatformUtils.getPlatformPrefix());
}
 
Example 27
Source Project: intellij   Source File: PythonFacetUtil.java    License: Apache License 2.0 4 votes vote down vote up
static boolean usePythonFacets() {
  return !PlatformUtils.isPyCharm();
}
 
Example 28
Source Project: intellij   Source File: BlazePythonSyncPlugin.java    License: Apache License 2.0 4 votes vote down vote up
@Nullable
@Override
public WorkspaceType getDefaultWorkspaceType() {
  return PlatformUtils.isPyCharm() ? WorkspaceType.PYTHON : null;
}
 
Example 29
Source Project: intellij   Source File: BlazePythonSyncPlugin.java    License: Apache License 2.0 4 votes vote down vote up
private static boolean supportsPythonWorkspaceType() {
  // support python workspace type in IntelliJ for historical reasons (this is discouraged for new
  // projects)
  return PlatformUtils.isIntelliJ() || PlatformUtils.isPyCharm();
}
 
Example 30
Source Project: intellij   Source File: BlazePythonSyncPlugin.java    License: Apache License 2.0 4 votes vote down vote up
@Nullable
private static LibraryContributingFacet<?> getOrCreatePythonFacet(
    Project project, BlazeContext context, Module module, BlazeProjectData blazeProjectData) {
  LibraryContributingFacet<?> facet = findPythonFacet(module);
  if (facet != null && isValidPythonSdk(PythonFacetUtil.getSdk(facet))) {
    return facet;
  }
  FacetManager manager = FacetManager.getInstance(module);
  ModifiableFacetModel facetModel = manager.createModifiableModel();
  if (facet != null) {
    // we can't modify in place, IntelliJ has no hook to trigger change events. Instead we create
    // a new facet.
    facetModel.removeFacet(facet);
  }

  Sdk sdk = getPythonSdk(project, blazeProjectData, context);
  if (sdk == null) {
    String fixDirections =
        "Configure a suitable Python Interpreter for the module \""
            + module.getName()
            + "\" via File->\"Project Structure...\", \"Project Settings\"->\"Facets\", then"
            + " sync the project again.";
    if (PlatformUtils.isCLion()) {
      fixDirections =
          "Configure a suitable Python Interpreter for the module \""
              + module.getName()
              + "\" via File->\"Settings...\", \"Build,"
              + " Execution, Deployment\"->\"Python Interpreter\", then sync the project again.";
    }
    String msg = "Unable to find a compatible Python SDK installed.\n" + fixDirections;
    IssueOutput.error(msg).submit(context);
    return null;
  }

  facet = manager.createFacet(PythonFacetUtil.getFacetType(), "Python", null);
  // This is ugly like this to get around PythonFacet related classes being in different package
  // paths in different IDEs. Thankfully, PythonFacetSettings is in the same packackage path.
  if (facet.getConfiguration() instanceof PythonFacetSettings) {
    ((PythonFacetSettings) facet.getConfiguration()).setSdk(sdk);
  }
  facetModel.addFacet(facet);
  facetModel.commit();
  return facet;
}