mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
deprecate SdkSetupNotificationProvider, remove SdkSetupNotificationProvider, inline JavaFxProjectSdkSetupValidator
GitOrigin-RevId: 54b8cef494de3cc8537db2ca3add5c93940514d9
This commit is contained in:
committed by
intellij-monorepo-bot
parent
67630b2484
commit
c324d2d27f
@@ -29,8 +29,6 @@
|
||||
id="Template Data Languages" key="template.data.language.configurable" bundle="messages.LangBundle"
|
||||
nonDefaultProject="true"/>
|
||||
|
||||
<editorNotificationProvider implementation="com.intellij.codeInsight.daemon.impl.SdkSetupNotificationProvider"/>
|
||||
|
||||
<vcsAwareCheckoutListener implementation="com.intellij.openapi.vcs.checkout.RegisterMappingCheckoutListener"/>
|
||||
|
||||
<projectTemplatesFactory implementation="com.intellij.platform.templates.ArchivedTemplatesFactory"/>
|
||||
|
||||
+2
-1
@@ -34,8 +34,9 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* @author Pavel.Dolgov
|
||||
* @deprecated {@link com.intellij.openapi.projectRoots.impl.UnknownSdkTracker} shows the similar notification
|
||||
*/
|
||||
@Deprecated
|
||||
public class JavaProjectSdkSetupValidator implements ProjectSdkSetupValidator {
|
||||
public static final JavaProjectSdkSetupValidator INSTANCE = new JavaProjectSdkSetupValidator();
|
||||
@Override
|
||||
|
||||
@@ -493,7 +493,6 @@
|
||||
<editorNotificationProvider implementation="com.intellij.codeInsight.daemon.impl.AttachSourcesNotificationProvider"/>
|
||||
<editorNotificationProvider implementation="com.intellij.codeInsight.daemon.impl.LibrarySourceNotificationProvider"/>
|
||||
|
||||
<projectSdkSetupValidator id="javaSdk" implementation="com.intellij.codeInsight.daemon.impl.JavaProjectSdkSetupValidator"/>
|
||||
<editorNotificationProvider implementation="com.intellij.debugger.ui.AlternativeSourceNotificationProvider"/>
|
||||
|
||||
<attachSourcesProvider implementation="com.intellij.jarFinder.InternetAttachSourceProvider"/>
|
||||
|
||||
+88
-1
@@ -1,15 +1,37 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.java.codeInsight.daemon.impl;
|
||||
|
||||
import com.intellij.codeInsight.intention.IntentionActionWithOptions;
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.application.ReadAction;
|
||||
import com.intellij.openapi.application.WriteAction;
|
||||
import com.intellij.openapi.fileEditor.FileEditor;
|
||||
import com.intellij.openapi.fileEditor.ex.FileEditorManagerEx;
|
||||
import com.intellij.openapi.projectRoots.ProjectJdkTable;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.projectRoots.impl.UnknownSdkTracker;
|
||||
import com.intellij.openapi.roots.ModuleRootModificationUtil;
|
||||
import com.intellij.openapi.roots.ProjectRootManager;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.testFramework.IdeaTestUtil;
|
||||
import com.intellij.testFramework.fixtures.JavaCodeInsightFixtureTestCase;
|
||||
import com.intellij.ui.EditorNotificationPanel;
|
||||
import com.intellij.ui.EditorNotificationsImpl;
|
||||
import org.assertj.core.api.AssertionsForClassTypes;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.junit.Assert;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Pavel.Dolgov
|
||||
*/
|
||||
public class SdkSetupNotificationTest extends SdkSetupNotificationTestBase {
|
||||
public class SdkSetupNotificationTest extends JavaCodeInsightFixtureTestCase {
|
||||
public void testProjectSdk() {
|
||||
final EditorNotificationPanel panel = configureBySdkAndText(IdeaTestUtil.getMockJdk18(), false, "Sample.java", "class Sample {}");
|
||||
assertThat(panel).isNull();
|
||||
@@ -29,4 +51,69 @@ public class SdkSetupNotificationTest extends SdkSetupNotificationTestBase {
|
||||
final EditorNotificationPanel panel = configureBySdkAndText(null, true, "Sample.java", "class Sample {}");
|
||||
assertSdkSetupPanelShown(panel, "Setup SDK");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
setProjectSdk(IdeaTestUtil.getMockJdk17());
|
||||
}
|
||||
|
||||
|
||||
@Nullable
|
||||
@SuppressWarnings("SameParameterValue")
|
||||
protected EditorNotificationPanel configureBySdkAndText(@Nullable Sdk sdk,
|
||||
boolean isModuleSdk,
|
||||
@NotNull String name,
|
||||
@NotNull String text) {
|
||||
if (isModuleSdk) {
|
||||
ModuleRootModificationUtil.setModuleSdk(getModule(), sdk);
|
||||
}
|
||||
else {
|
||||
setProjectSdk(sdk);
|
||||
ModuleRootModificationUtil.setSdkInherited(getModule());
|
||||
}
|
||||
|
||||
final PsiFile psiFile = myFixture.configureByText(name, text);
|
||||
FileEditorManagerEx fileEditorManager = FileEditorManagerEx.getInstanceEx(getProject());
|
||||
VirtualFile virtualFile = psiFile.getVirtualFile();
|
||||
final FileEditor[] editors = fileEditorManager.openFile(virtualFile, true);
|
||||
Disposer.register(myFixture.getTestRootDisposable(), new Disposable() {
|
||||
@Override
|
||||
public void dispose() {
|
||||
fileEditorManager.closeFile(virtualFile);
|
||||
}
|
||||
});
|
||||
AssertionsForClassTypes.assertThat(editors).hasSize(1);
|
||||
EditorNotificationsImpl.completeAsyncTasks();
|
||||
|
||||
List<? extends EditorNotificationPanel> data = editors[0].getUserData(UnknownSdkTracker.GlobalEditorNotification.NOTIFICATIONS);
|
||||
if (data == null) return null;
|
||||
Assert.assertEquals("Only one notification was expected, but were " + data, 1, data.size());
|
||||
return data.iterator().next();
|
||||
}
|
||||
|
||||
private void setProjectSdk(@Nullable Sdk sdk) {
|
||||
if (sdk != null) {
|
||||
final Sdk foundJdk = ReadAction.compute(() -> ProjectJdkTable.getInstance().findJdk(sdk.getName()));
|
||||
if (foundJdk == null) {
|
||||
WriteAction.run(() -> ProjectJdkTable.getInstance().addJdk(sdk, myFixture.getProjectDisposable()));
|
||||
}
|
||||
}
|
||||
WriteAction.run(() -> ProjectRootManager.getInstance(getProject()).setProjectSdk(sdk));
|
||||
}
|
||||
|
||||
@SuppressWarnings("SameParameterValue")
|
||||
private static void assertSdkSetupPanelShown(@Nullable EditorNotificationPanel panel,
|
||||
@NotNull String expectedMessagePrefix) {
|
||||
AssertionsForClassTypes.assertThat(panel).isNotNull();
|
||||
final IntentionActionWithOptions action = panel.getIntentionAction();
|
||||
AssertionsForClassTypes.assertThat(action).isNotNull();
|
||||
final String text = action.getText();
|
||||
AssertionsForClassTypes.assertThat(text).isNotNull();
|
||||
if (!text.startsWith(expectedMessagePrefix)) {
|
||||
final int length = Math.min(text.length(), expectedMessagePrefix.length());
|
||||
AssertionsForClassTypes.assertThat(text.substring(0, length)).isEqualTo(expectedMessagePrefix);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
-88
@@ -1,88 +0,0 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.java.codeInsight.daemon.impl;
|
||||
|
||||
import com.intellij.codeInsight.daemon.impl.SdkSetupNotificationProvider;
|
||||
import com.intellij.codeInsight.intention.IntentionActionWithOptions;
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.application.ReadAction;
|
||||
import com.intellij.openapi.application.WriteAction;
|
||||
import com.intellij.openapi.fileEditor.FileEditor;
|
||||
import com.intellij.openapi.fileEditor.ex.FileEditorManagerEx;
|
||||
import com.intellij.openapi.projectRoots.ProjectJdkTable;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.roots.ModuleRootModificationUtil;
|
||||
import com.intellij.openapi.roots.ProjectRootManager;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.testFramework.IdeaTestUtil;
|
||||
import com.intellij.testFramework.fixtures.JavaCodeInsightFixtureTestCase;
|
||||
import com.intellij.ui.EditorNotificationPanel;
|
||||
import com.intellij.ui.EditorNotificationsImpl;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
|
||||
|
||||
/**
|
||||
* @author Pavel.Dolgov
|
||||
*/
|
||||
public abstract class SdkSetupNotificationTestBase extends JavaCodeInsightFixtureTestCase {
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
setProjectSdk(IdeaTestUtil.getMockJdk17());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected EditorNotificationPanel configureBySdkAndText(@Nullable Sdk sdk,
|
||||
boolean isModuleSdk,
|
||||
@NotNull String name,
|
||||
@NotNull String text) {
|
||||
if (isModuleSdk) {
|
||||
ModuleRootModificationUtil.setModuleSdk(getModule(), sdk);
|
||||
}
|
||||
else {
|
||||
setProjectSdk(sdk);
|
||||
ModuleRootModificationUtil.setSdkInherited(getModule());
|
||||
}
|
||||
|
||||
final PsiFile psiFile = myFixture.configureByText(name, text);
|
||||
FileEditorManagerEx fileEditorManager = FileEditorManagerEx.getInstanceEx(getProject());
|
||||
VirtualFile virtualFile = psiFile.getVirtualFile();
|
||||
final FileEditor[] editors = fileEditorManager.openFile(virtualFile, true);
|
||||
Disposer.register(myFixture.getTestRootDisposable(), new Disposable() {
|
||||
@Override
|
||||
public void dispose() {
|
||||
fileEditorManager.closeFile(virtualFile);
|
||||
}
|
||||
});
|
||||
assertThat(editors).hasSize(1);
|
||||
EditorNotificationsImpl.completeAsyncTasks();
|
||||
|
||||
return editors[0].getUserData(SdkSetupNotificationProvider.KEY);
|
||||
}
|
||||
|
||||
protected void setProjectSdk(@Nullable Sdk sdk) {
|
||||
if (sdk != null) {
|
||||
final Sdk foundJdk = ReadAction.compute(() -> ProjectJdkTable.getInstance().findJdk(sdk.getName()));
|
||||
if (foundJdk == null) {
|
||||
WriteAction.run(() -> ProjectJdkTable.getInstance().addJdk(sdk, myFixture.getProjectDisposable()));
|
||||
}
|
||||
}
|
||||
WriteAction.run(() -> ProjectRootManager.getInstance(getProject()).setProjectSdk(sdk));
|
||||
}
|
||||
|
||||
protected static void assertSdkSetupPanelShown(EditorNotificationPanel panel, @NotNull String expectedMessagePrefix) {
|
||||
assertThat(panel).isNotNull();
|
||||
final IntentionActionWithOptions action = panel.getIntentionAction();
|
||||
assertThat(action).isNotNull();
|
||||
final String text = action.getText();
|
||||
assertThat(text).isNotNull();
|
||||
if (!text.startsWith(expectedMessagePrefix)) {
|
||||
final int length = Math.min(text.length(), expectedMessagePrefix.length());
|
||||
assertThat(text.substring(0, length)).isEqualTo(expectedMessagePrefix);
|
||||
}
|
||||
}
|
||||
}
|
||||
+5
-1
@@ -23,8 +23,12 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* @author Pavel.Dolgov
|
||||
* <stong>This extension point is not executed any more</stong>
|
||||
*
|
||||
* @deprecated {@link com.intellij.openapi.projectRoots.impl.UnknownSdkTracker} takes care about
|
||||
* possible actions to fix the Sdks in the project.
|
||||
*/
|
||||
@Deprecated
|
||||
public interface ProjectSdkSetupValidator {
|
||||
ExtensionPointName<ProjectSdkSetupValidator> EP_NAME = ExtensionPointName.create("com.intellij.projectSdkSetupValidator");
|
||||
|
||||
|
||||
-45
@@ -1,45 +0,0 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.codeInsight.daemon.impl;
|
||||
|
||||
import com.intellij.codeInsight.daemon.ProjectSdkSetupValidator;
|
||||
import com.intellij.openapi.fileEditor.FileEditor;
|
||||
import com.intellij.openapi.project.DumbAware;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.project.ProjectBundle;
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.ui.EditorNotificationPanel;
|
||||
import com.intellij.ui.EditorNotifications;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author Danila Ponomarenko
|
||||
*/
|
||||
public final class SdkSetupNotificationProvider extends EditorNotifications.Provider<EditorNotificationPanel> implements DumbAware {
|
||||
public static final Key<EditorNotificationPanel> KEY = Key.create("SdkSetupNotification");
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Key<EditorNotificationPanel> getKey() {
|
||||
return KEY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EditorNotificationPanel createNotificationPanel(@NotNull VirtualFile file, @NotNull FileEditor fileEditor, @NotNull Project project) {
|
||||
for (ProjectSdkSetupValidator validator : ProjectSdkSetupValidator.EP_NAME.getExtensionList()) {
|
||||
if (validator.isApplicableFor(project, file)) {
|
||||
String errorMessage = validator.getErrorMessage(project, file);
|
||||
return errorMessage != null ? createPanel(errorMessage, () -> validator.doFix(project, file)) : null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static EditorNotificationPanel createPanel(@NotNull String message, @NotNull Runnable fix) {
|
||||
EditorNotificationPanel panel = new EditorNotificationPanel();
|
||||
panel.setText(message);
|
||||
panel.createActionLabel(ProjectBundle.message("project.sdk.setup"), fix);
|
||||
return panel;
|
||||
}
|
||||
}
|
||||
+7
-8
@@ -40,7 +40,6 @@ import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.ui.EditorNotificationPanel;
|
||||
import com.intellij.ui.awt.RelativePoint;
|
||||
import com.intellij.util.SmartList;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -319,9 +318,9 @@ public class UnknownSdkTracker {
|
||||
}
|
||||
}
|
||||
|
||||
static class GlobalEditorNotification implements Disposable {
|
||||
private final Key<List<MissingSdkNotificationPanel>> NOTIFICATIONS_ADDED = Key.create("notifications added to the editor");
|
||||
private final Key<?> myEditorNotificationKeyForFus = Key.create("fix project SDK");
|
||||
public static class GlobalEditorNotification implements Disposable {
|
||||
public static final Key<List<MissingSdkNotificationPanel>> NOTIFICATIONS = Key.create("notifications added to the editor");
|
||||
private static final Key<?> EDITOR_NOTIFICATIONS_KEY = Key.create("SdkSetupNotificationNew");
|
||||
|
||||
@NotNull
|
||||
public static GlobalEditorNotification getInstance(@NotNull Project project) {
|
||||
@@ -366,7 +365,7 @@ public class UnknownSdkTracker {
|
||||
|
||||
MissingSdkNotificationPanel panel = new MissingSdkNotificationPanel(info);
|
||||
panel.setProject(myProject);
|
||||
panel.setProviderKey(myEditorNotificationKeyForFus);
|
||||
panel.setProviderKey(EDITOR_NOTIFICATIONS_KEY);
|
||||
panel.setText(sdkName + " \"" + info.getSdkName() + "\" is missing");
|
||||
|
||||
panel.createActionLabel("Download " + sdkName + " (" + fix.getDownloadDescription() + ")", () -> {
|
||||
@@ -439,7 +438,7 @@ public class UnknownSdkTracker {
|
||||
private void removeNotification(@NotNull MissingSdkNotificationPanel expiredPanel) {
|
||||
myNotifications.remove(expiredPanel.myInfo);
|
||||
for (FileEditor editor : myFileEditorManager.getAllEditors()) {
|
||||
List<MissingSdkNotificationPanel> notifications = editor.getUserData(NOTIFICATIONS_ADDED);
|
||||
List<MissingSdkNotificationPanel> notifications = editor.getUserData(NOTIFICATIONS);
|
||||
if (notifications == null) continue;
|
||||
for (MissingSdkNotificationPanel panel : new ArrayList<>(notifications)) {
|
||||
if (panel.isSameProblemAs(expiredPanel)) {
|
||||
@@ -453,7 +452,7 @@ public class UnknownSdkTracker {
|
||||
private void updateEditorNotifications(@NotNull FileEditor editor) {
|
||||
if (!editor.isValid()) return;
|
||||
|
||||
List<MissingSdkNotificationPanel> notifications = editor.getUserData(NOTIFICATIONS_ADDED);
|
||||
List<MissingSdkNotificationPanel> notifications = editor.getUserData(NOTIFICATIONS);
|
||||
if (notifications != null) {
|
||||
for (JComponent component : notifications) {
|
||||
myFileEditorManager.removeTopComponent(editor, component);
|
||||
@@ -461,7 +460,7 @@ public class UnknownSdkTracker {
|
||||
notifications.clear();
|
||||
} else {
|
||||
notifications = new SmartList<>();
|
||||
editor.putUserData(NOTIFICATIONS_ADDED, notifications);
|
||||
editor.putUserData(NOTIFICATIONS, notifications);
|
||||
}
|
||||
|
||||
for (Map.Entry<MissingSdkInfo, DownloadSdkFix> e : myNotifications.entrySet()) {
|
||||
|
||||
@@ -17,5 +17,6 @@
|
||||
<orderEntry type="module" module-name="intellij.java.tests" scope="TEST" />
|
||||
<orderEntry type="module" module-name="intellij.groovy.structuralSearch" scope="TEST" />
|
||||
<orderEntry type="module" module-name="intellij.java.compiler" scope="TEST" />
|
||||
<orderEntry type="library" scope="TEST" name="assertJ" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
+79
-2
@@ -1,18 +1,34 @@
|
||||
package org.jetbrains.plugins.javaFX.fxml;
|
||||
|
||||
import com.intellij.java.codeInsight.daemon.impl.SdkSetupNotificationTestBase;
|
||||
import com.intellij.codeInsight.intention.IntentionActionWithOptions;
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.application.ReadAction;
|
||||
import com.intellij.openapi.application.WriteAction;
|
||||
import com.intellij.openapi.fileEditor.FileEditor;
|
||||
import com.intellij.openapi.fileEditor.ex.FileEditorManagerEx;
|
||||
import com.intellij.openapi.projectRoots.JavaSdk;
|
||||
import com.intellij.openapi.projectRoots.ProjectJdkTable;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.projectRoots.impl.JavaSdkImpl;
|
||||
import com.intellij.openapi.roots.ModuleRootModificationUtil;
|
||||
import com.intellij.openapi.roots.ProjectRootManager;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.testFramework.IdeaTestUtil;
|
||||
import com.intellij.testFramework.fixtures.JavaCodeInsightFixtureTestCase;
|
||||
import com.intellij.ui.EditorNotificationPanel;
|
||||
import com.intellij.ui.EditorNotificationsImpl;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.javaFX.JavaFxProjectSdkSetupValidator;
|
||||
|
||||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
|
||||
|
||||
/**
|
||||
* @author Pavel.Dolgov
|
||||
*/
|
||||
public class JavaFxSdkSetupNotificationTest extends SdkSetupNotificationTestBase {
|
||||
public class JavaFxSdkSetupNotificationTest extends JavaCodeInsightFixtureTestCase {
|
||||
private static final String SAMPLE_FXML = "<?import javafx.scene.layout.VBox?>\n<VBox/>";
|
||||
|
||||
public void testJavaFxAsLibrary() {
|
||||
@@ -40,4 +56,65 @@ public class JavaFxSdkSetupNotificationTest extends SdkSetupNotificationTestBase
|
||||
private static Sdk getTestJdk() {
|
||||
return ((JavaSdkImpl)JavaSdk.getInstance()).createMockJdk("testJdk", System.getProperty("java.home"), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
setProjectSdk(IdeaTestUtil.getMockJdk17());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@SuppressWarnings("SameParameterValue")
|
||||
private EditorNotificationPanel configureBySdkAndText(@Nullable Sdk sdk,
|
||||
boolean isModuleSdk,
|
||||
@NotNull String name,
|
||||
@NotNull String text) {
|
||||
if (isModuleSdk) {
|
||||
ModuleRootModificationUtil.setModuleSdk(getModule(), sdk);
|
||||
}
|
||||
else {
|
||||
setProjectSdk(sdk);
|
||||
ModuleRootModificationUtil.setSdkInherited(getModule());
|
||||
}
|
||||
|
||||
final PsiFile psiFile = myFixture.configureByText(name, text);
|
||||
FileEditorManagerEx fileEditorManager = FileEditorManagerEx.getInstanceEx(getProject());
|
||||
VirtualFile virtualFile = psiFile.getVirtualFile();
|
||||
final FileEditor[] editors = fileEditorManager.openFile(virtualFile, true);
|
||||
Disposer.register(myFixture.getTestRootDisposable(), new Disposable() {
|
||||
@Override
|
||||
public void dispose() {
|
||||
fileEditorManager.closeFile(virtualFile);
|
||||
}
|
||||
});
|
||||
assertThat(editors).hasSize(1);
|
||||
EditorNotificationsImpl.completeAsyncTasks();
|
||||
|
||||
return editors[0].getUserData(JavaFxProjectSdkSetupValidator.KEY);
|
||||
}
|
||||
|
||||
private void setProjectSdk(@Nullable Sdk sdk) {
|
||||
if (sdk != null) {
|
||||
final Sdk foundJdk = ReadAction.compute(() -> ProjectJdkTable.getInstance().findJdk(sdk.getName()));
|
||||
if (foundJdk == null) {
|
||||
WriteAction.run(() -> ProjectJdkTable.getInstance().addJdk(sdk, myFixture.getProjectDisposable()));
|
||||
}
|
||||
}
|
||||
WriteAction.run(() -> ProjectRootManager.getInstance(getProject()).setProjectSdk(sdk));
|
||||
}
|
||||
|
||||
@SuppressWarnings("SameParameterValue")
|
||||
private static void assertSdkSetupPanelShown(@Nullable EditorNotificationPanel panel,
|
||||
@NotNull String expectedMessagePrefix) {
|
||||
assertThat(panel).isNotNull();
|
||||
final IntentionActionWithOptions action = panel.getIntentionAction();
|
||||
assertThat(action).isNotNull();
|
||||
final String text = action.getText();
|
||||
assertThat(text).isNotNull();
|
||||
if (!text.startsWith(expectedMessagePrefix)) {
|
||||
final int length = Math.min(text.length(), expectedMessagePrefix.length());
|
||||
assertThat(text.substring(0, length)).isEqualTo(expectedMessagePrefix);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@
|
||||
<projectTemplate projectType="Java FX" templatePath="resources/projectTemplates/Java/JavaFX Application.zip" category="true"/>
|
||||
<javaMainMethodProvider implementation="org.jetbrains.plugins.javaFX.JavaFxMainMethodRunConfigurationProvider"/>
|
||||
<deadCode implementation="org.jetbrains.plugins.javaFX.JavaFxEntryPoint"/>
|
||||
<projectSdkSetupValidator implementation="org.jetbrains.plugins.javaFX.JavaFxProjectSdkSetupValidator" order="after javaSdk"/>
|
||||
<editorNotificationProvider implementation="org.jetbrains.plugins.javaFX.JavaFxProjectSdkSetupValidator"/>
|
||||
<predefinedMigrationMapProvider implementation="org.jetbrains.plugins.javaFX.refactoring.migration.JavaFx9Migration"/>
|
||||
<postStartupActivity implementation="org.jetbrains.plugins.javaFX.fxml.JavaFxModuleUtil$JavaFxDetectionStartupActivity"/>
|
||||
<runConfigurationExtension implementation="org.jetbrains.plugins.javaFX.execution.JavaFxRunConfigurationExtension"/>
|
||||
|
||||
+36
-17
@@ -1,18 +1,23 @@
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package org.jetbrains.plugins.javaFX;
|
||||
|
||||
import com.intellij.codeInsight.daemon.ProjectSdkSetupValidator;
|
||||
import com.intellij.codeInsight.daemon.impl.JavaProjectSdkSetupValidator;
|
||||
import com.intellij.openapi.fileEditor.FileEditor;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleUtilCore;
|
||||
import com.intellij.openapi.project.DumbAware;
|
||||
import com.intellij.openapi.project.DumbService;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.project.ProjectBundle;
|
||||
import com.intellij.openapi.roots.ModuleRootManager;
|
||||
import com.intellij.openapi.roots.ui.configuration.ClasspathEditor;
|
||||
import com.intellij.openapi.roots.ui.configuration.ProjectSettingsService;
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.JavaPsiFacade;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.ui.EditorNotificationPanel;
|
||||
import com.intellij.ui.EditorNotifications;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.javaFX.fxml.JavaFxCommonNames;
|
||||
@@ -21,23 +26,26 @@ import org.jetbrains.plugins.javaFX.fxml.JavaFxFileTypeFactory;
|
||||
/**
|
||||
* @author Pavel.Dolgov
|
||||
*/
|
||||
public class JavaFxProjectSdkSetupValidator implements ProjectSdkSetupValidator {
|
||||
public class JavaFxProjectSdkSetupValidator extends EditorNotifications.Provider<EditorNotificationPanel> implements DumbAware {
|
||||
public static final Key<EditorNotificationPanel> KEY = Key.create("SdkSetupNotificationJavaFX");
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public boolean isApplicableFor(@NotNull Project project, @NotNull VirtualFile file) {
|
||||
return JavaFxFileTypeFactory.isFxml(file);
|
||||
public Key<EditorNotificationPanel> getKey() {
|
||||
return KEY;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getErrorMessage(@NotNull Project project, @NotNull VirtualFile file) {
|
||||
final String javaErrorMessage = JavaProjectSdkSetupValidator.INSTANCE.getErrorMessage(project, file);
|
||||
if (javaErrorMessage != null) {
|
||||
return javaErrorMessage;
|
||||
}
|
||||
private static String getErrorMessage(@NotNull Project project, @NotNull VirtualFile file) {
|
||||
if (DumbService.isDumb(project)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final Module module = ModuleUtilCore.findModuleForFile(file, project);
|
||||
if (module == null || module.isDisposed() || ModuleRootManager.getInstance(module).getSdk() == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final PsiClass nodeClass =
|
||||
JavaPsiFacade.getInstance(project).findClass(JavaFxCommonNames.JAVAFX_SCENE_NODE, GlobalSearchScope.allScope(project));
|
||||
if (nodeClass == null) {
|
||||
@@ -47,15 +55,26 @@ public class JavaFxProjectSdkSetupValidator implements ProjectSdkSetupValidator
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doFix(@NotNull Project project, @NotNull VirtualFile file) {
|
||||
final String javaErrorMessage = JavaProjectSdkSetupValidator.INSTANCE.getErrorMessage(project, file);
|
||||
if (javaErrorMessage != null) {
|
||||
JavaProjectSdkSetupValidator.INSTANCE.doFix(project, file);
|
||||
return;
|
||||
}
|
||||
final Module module = ModuleUtilCore.findModuleForFile(file, project);
|
||||
final String moduleName = module != null && !module.isDisposed() ? module.getName() : null;
|
||||
ProjectSettingsService.getInstance(project).showModuleConfigurationDialog(moduleName, ClasspathEditor.NAME);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EditorNotificationPanel createNotificationPanel(@NotNull VirtualFile file, @NotNull FileEditor fileEditor, @NotNull Project project) {
|
||||
if (JavaFxFileTypeFactory.isFxml(file)) {
|
||||
String errorMessage = getErrorMessage(project, file);
|
||||
return errorMessage != null ? createPanel(errorMessage, () -> doFix(project, file)) : null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static EditorNotificationPanel createPanel(@NotNull String message, @NotNull Runnable fix) {
|
||||
EditorNotificationPanel panel = new EditorNotificationPanel();
|
||||
panel.setText(message);
|
||||
panel.createActionLabel(ProjectBundle.message("project.sdk.setup"), fix);
|
||||
return panel;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user