mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[java] project disposal check (EA-81095); formatting
This commit is contained in:
+30
-40
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -18,7 +18,7 @@ package com.intellij.codeInsight.daemon.impl;
|
||||
import com.intellij.ProjectTopics;
|
||||
import com.intellij.ide.highlighter.JavaClassFileType;
|
||||
import com.intellij.lang.java.JavaLanguage;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.WriteAction;
|
||||
import com.intellij.openapi.fileEditor.FileEditor;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleUtilCore;
|
||||
@@ -26,7 +26,10 @@ import com.intellij.openapi.project.DumbAware;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.project.ProjectBundle;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.roots.*;
|
||||
import com.intellij.openapi.roots.ModuleRootAdapter;
|
||||
import com.intellij.openapi.roots.ModuleRootEvent;
|
||||
import com.intellij.openapi.roots.ModuleRootManager;
|
||||
import com.intellij.openapi.roots.ModuleRootModificationUtil;
|
||||
import com.intellij.openapi.roots.ui.configuration.ProjectSettingsService;
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
@@ -62,50 +65,37 @@ public class SetupSDKNotificationProvider extends EditorNotifications.Provider<E
|
||||
|
||||
@Override
|
||||
public EditorNotificationPanel createNotificationPanel(@NotNull VirtualFile file, @NotNull FileEditor fileEditor) {
|
||||
if (file.getFileType() == JavaClassFileType.INSTANCE) return null;
|
||||
|
||||
final PsiFile psiFile = PsiManager.getInstance(myProject).findFile(file);
|
||||
if (psiFile == null) {
|
||||
return null;
|
||||
if (file.getFileType() != JavaClassFileType.INSTANCE) {
|
||||
PsiFile psiFile = PsiManager.getInstance(myProject).findFile(file);
|
||||
if (psiFile != null) {
|
||||
if (psiFile.getLanguage() == JavaLanguage.INSTANCE) {
|
||||
Module module = ModuleUtilCore.findModuleForPsiElement(psiFile);
|
||||
if (module != null && !module.isDisposed()) {
|
||||
Sdk sdk = ModuleRootManager.getInstance(module).getSdk();
|
||||
if (sdk == null) {
|
||||
return createPanel(myProject, psiFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (psiFile.getLanguage() != JavaLanguage.INSTANCE) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Module module = ModuleUtilCore.findModuleForPsiElement(psiFile);
|
||||
if (module == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Sdk sdk = ModuleRootManager.getInstance(module).getSdk();
|
||||
if (sdk != null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return createPanel(myProject, psiFile);
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static EditorNotificationPanel createPanel(@NotNull final Project project, @NotNull final PsiFile file) {
|
||||
final EditorNotificationPanel panel = new EditorNotificationPanel();
|
||||
private static EditorNotificationPanel createPanel(@NotNull Project project, @NotNull PsiFile file) {
|
||||
EditorNotificationPanel panel = new EditorNotificationPanel();
|
||||
panel.setText(ProjectBundle.message("project.sdk.not.defined"));
|
||||
panel.createActionLabel(ProjectBundle.message("project.sdk.setup"), new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final Sdk projectSdk = ProjectSettingsService.getInstance(project).chooseAndSetSdk();
|
||||
if (projectSdk == null) return;
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final Module module = ModuleUtilCore.findModuleForPsiElement(file);
|
||||
if (module != null) {
|
||||
ModuleRootModificationUtil.setSdkInherited(module);
|
||||
}
|
||||
}
|
||||
});
|
||||
panel.createActionLabel(ProjectBundle.message("project.sdk.setup"), () -> {
|
||||
Sdk projectSdk = ProjectSettingsService.getInstance(project).chooseAndSetSdk();
|
||||
if (projectSdk != null) {
|
||||
Module module = ModuleUtilCore.findModuleForPsiElement(file);
|
||||
if (module != null) {
|
||||
WriteAction.run(() -> ModuleRootModificationUtil.setSdkInherited(module));
|
||||
}
|
||||
}
|
||||
});
|
||||
return panel;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user