diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ProjectStructureConfigurable.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ProjectStructureConfigurable.java index 74baa2b4e7cb..ac96b072245e 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ProjectStructureConfigurable.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ProjectStructureConfigurable.java @@ -1,4 +1,4 @@ -// 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. +// Copyright 2000-2020 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.openapi.roots.ui.configuration; import com.intellij.compiler.server.BuildManager; @@ -558,7 +558,7 @@ public class ProjectStructureConfigurable implements SearchableConfigurable, Pla myDetails.add(myEmptySelection, BorderLayout.CENTER); } - public static ProjectStructureConfigurable getInstance(final Project project) { + public static ProjectStructureConfigurable getInstance(@NotNull final Project project) { return ServiceManager.getService(project, ProjectStructureConfigurable.class); } diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/UIRootConfigurationAccessor.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/UIRootConfigurationAccessor.java index f6e038178ef9..421f632fc025 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/UIRootConfigurationAccessor.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/UIRootConfigurationAccessor.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2009 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. - * 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. - */ +// Copyright 2000-2020 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.openapi.roots.ui.configuration; import com.intellij.openapi.module.Module; @@ -24,6 +10,7 @@ import com.intellij.openapi.roots.libraries.Library; import com.intellij.openapi.roots.ui.configuration.projectRoot.ModuleStructureConfigurable; import com.intellij.openapi.roots.ui.configuration.projectRoot.ProjectSdksModel; import com.intellij.openapi.roots.ui.configuration.projectRoot.StructureConfigurableContext; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; /** @@ -70,13 +57,13 @@ public class UIRootConfigurationAccessor extends RootConfigurationAccessor { } @Override - public Sdk getProjectSdk(final Project project) { + public Sdk getProjectSdk(@NotNull final Project project) { return ProjectStructureConfigurable.getInstance(project).getProjectJdksModel().getProjectSdk(); } @Override @Nullable - public String getProjectSdkName(final Project project) { + public String getProjectSdkName(@NotNull final Project project) { final Sdk projectJdk = getProjectSdk(project); if (projectJdk != null) { return projectJdk.getName(); diff --git a/platform/analysis-impl/src/com/intellij/openapi/module/impl/scopes/JdkScope.java b/platform/analysis-impl/src/com/intellij/openapi/module/impl/scopes/JdkScope.java index ba77373f72ce..c01256bd5ebb 100644 --- a/platform/analysis-impl/src/com/intellij/openapi/module/impl/scopes/JdkScope.java +++ b/platform/analysis-impl/src/com/intellij/openapi/module/impl/scopes/JdkScope.java @@ -6,9 +6,12 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.JdkOrderEntry; import com.intellij.openapi.roots.OrderRootType; import com.intellij.openapi.vfs.VirtualFile; +import org.jetbrains.annotations.Nullable; + +import java.util.Objects; public class JdkScope extends LibraryScopeBase { - private final String myJdkName; + private final @Nullable String myJdkName; public JdkScope(Project project, JdkOrderEntry entry) { this(project, entry.getRootFiles(OrderRootType.CLASSES), entry.getRootFiles(OrderRootType.SOURCES), entry.getJdkName()); @@ -17,14 +20,14 @@ public class JdkScope extends LibraryScopeBase { public JdkScope(Project project, VirtualFile[] classes, VirtualFile[] sources, - String jdkName) { + @Nullable String jdkName) { super(project, classes, sources); myJdkName = jdkName; } @Override public int calcHashCode() { - return 31 * super.calcHashCode() + myJdkName.hashCode(); + return 31 * super.calcHashCode() + (myJdkName == null ? 0 : myJdkName.hashCode()); } @Override @@ -32,6 +35,6 @@ public class JdkScope extends LibraryScopeBase { if (object == this) return true; if (object.getClass() != getClass()) return false; - return myJdkName.equals(((JdkScope)object).myJdkName) && super.equals(object); + return Objects.equals(myJdkName, ((JdkScope)object).myJdkName) && super.equals(object); } } diff --git a/platform/lang-impl/src/com/intellij/ide/navigationToolbar/NavBarPresentation.java b/platform/lang-impl/src/com/intellij/ide/navigationToolbar/NavBarPresentation.java index 080847cb6f91..785c946bb450 100644 --- a/platform/lang-impl/src/com/intellij/ide/navigationToolbar/NavBarPresentation.java +++ b/platform/lang-impl/src/com/intellij/ide/navigationToolbar/NavBarPresentation.java @@ -1,4 +1,4 @@ -// 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. +// Copyright 2000-2020 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.ide.navigationToolbar; import com.intellij.icons.AllIcons; @@ -11,6 +11,7 @@ import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.module.ModuleUtil; import com.intellij.openapi.project.IndexNotReadyException; import com.intellij.openapi.project.Project; +import com.intellij.openapi.projectRoots.Sdk; import com.intellij.openapi.projectRoots.SdkType; import com.intellij.openapi.projectRoots.SdkTypeId; import com.intellij.openapi.roots.JdkOrderEntry; @@ -72,7 +73,10 @@ public class NavBarPresentation { return null; } if (object instanceof JdkOrderEntry) { - final SdkTypeId sdkType = ((JdkOrderEntry)object).getJdk().getSdkType(); + Sdk jdk = ((JdkOrderEntry)object).getJdk(); + if (jdk == null) return null; + + final SdkTypeId sdkType = jdk.getSdkType(); return ((SdkType) sdkType).getIcon(); } if (object instanceof LibraryOrderEntry) return AllIcons.Nodes.PpLibFolder; diff --git a/platform/lang-impl/testSources/com/intellij/openapi/roots/SdkInRootModelTest.kt b/platform/lang-impl/testSources/com/intellij/openapi/roots/SdkInRootModelTest.kt index a2c3af4402c3..fd9d010a01ea 100644 --- a/platform/lang-impl/testSources/com/intellij/openapi/roots/SdkInRootModelTest.kt +++ b/platform/lang-impl/testSources/com/intellij/openapi/roots/SdkInRootModelTest.kt @@ -132,8 +132,8 @@ class SdkInRootModelTest { fun `set project sdk from accessor`() { val sdk = projectModel.createSdk("my sdk") val model = createModifiableModel(module, object : RootConfigurationAccessor() { - override fun getProjectSdk(project: Project?): Sdk = sdk - override fun getProjectSdkName(project: Project?): String? = "my sdk" + override fun getProjectSdk(project: Project): Sdk = sdk + override fun getProjectSdkName(project: Project): String? = "my sdk" }) model.inheritSdk() assertThat(model.sdk).isEqualTo(sdk) @@ -150,7 +150,7 @@ class SdkInRootModelTest { fun `set project sdk from accessor by name`() { val sdk = projectModel.createSdk("my sdk") val model = createModifiableModel(module, object : RootConfigurationAccessor() { - override fun getProjectSdkName(project: Project?): String? = "my sdk" + override fun getProjectSdkName(project: Project): String? = "my sdk" }) model.inheritSdk() assertThat(model.sdk).isNull() diff --git a/platform/projectModel-api/src/com/intellij/openapi/roots/JdkOrderEntry.java b/platform/projectModel-api/src/com/intellij/openapi/roots/JdkOrderEntry.java index c2b742e8f80c..ee5a250ac20f 100644 --- a/platform/projectModel-api/src/com/intellij/openapi/roots/JdkOrderEntry.java +++ b/platform/projectModel-api/src/com/intellij/openapi/roots/JdkOrderEntry.java @@ -1,25 +1,15 @@ -/* - * Copyright 2000-2009 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. - * 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. - */ +// Copyright 2000-2020 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.openapi.roots; import com.intellij.openapi.projectRoots.Sdk; import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.Nullable; @ApiStatus.NonExtendable public interface JdkOrderEntry extends LibraryOrSdkOrderEntry { + @Nullable Sdk getJdk(); + + @Nullable String getJdkName(); } diff --git a/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/InheritedJdkOrderEntryImpl.java b/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/InheritedJdkOrderEntryImpl.java index 2202a9a0d06f..637810072eb4 100644 --- a/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/InheritedJdkOrderEntryImpl.java +++ b/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/InheritedJdkOrderEntryImpl.java @@ -13,6 +13,7 @@ import com.intellij.openapi.vfs.pointers.VirtualFilePointerManager; import org.jdom.Element; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import org.jetbrains.jps.model.serialization.module.JpsModuleRootModelSerializer; final class InheritedJdkOrderEntryImpl extends LibraryOrderEntryBaseImpl implements InheritedJdkOrderEntry, ClonableOrderEntry, WritableOrderEntry { @@ -63,12 +64,14 @@ final class InheritedJdkOrderEntryImpl extends LibraryOrderEntryBaseImpl impleme } @Override + @Nullable public Sdk getJdk() { final Project project = getRootModel().getModule().getProject(); return getRootModel().getConfigurationAccessor().getProjectSdk(project); } @Override + @Nullable public String getJdkName() { final Project project = getRootModel().getModule().getProject(); return getRootModel().getConfigurationAccessor().getProjectSdkName(project); diff --git a/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/ModuleJdkOrderEntryImpl.java b/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/ModuleJdkOrderEntryImpl.java index 1ae54827fd9d..51cc66f97602 100644 --- a/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/ModuleJdkOrderEntryImpl.java +++ b/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/ModuleJdkOrderEntryImpl.java @@ -24,7 +24,7 @@ final class ModuleJdkOrderEntryImpl extends LibraryOrderEntryBaseImpl implements @NonNls private static final String JDK_TYPE_ATTR = JpsModuleRootModelSerializer.JDK_TYPE_ATTRIBUTE; @Nullable private Sdk myJdk; - private String myJdkName; + @Nullable private String myJdkName; private String myJdkType; ModuleJdkOrderEntryImpl(@NotNull Sdk projectJdk, @NotNull RootModelImpl rootModel, @NotNull ProjectRootManagerImpl projectRootManager) { @@ -79,7 +79,7 @@ final class ModuleJdkOrderEntryImpl extends LibraryOrderEntryBaseImpl implements init(null, jdkName, jdkType); } - private void init(final Sdk jdk, final String jdkName, final String jdkType) { + private void init(final Sdk jdk, @Nullable final String jdkName, final String jdkType) { myJdk = jdk; myJdkName = jdkName; myJdkType = jdkType; diff --git a/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/RootConfigurationAccessor.java b/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/RootConfigurationAccessor.java index cd95542b72b9..3f10241fddfc 100644 --- a/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/RootConfigurationAccessor.java +++ b/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/RootConfigurationAccessor.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2009 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. - * 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. - */ +// Copyright 2000-2020 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.openapi.roots.impl; @@ -22,6 +8,7 @@ import com.intellij.openapi.projectRoots.Sdk; import com.intellij.openapi.roots.ProjectRootManager; import com.intellij.openapi.roots.libraries.Library; import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; /** @@ -43,12 +30,13 @@ public class RootConfigurationAccessor { return module; } - public Sdk getProjectSdk(Project project) { + @Nullable + public Sdk getProjectSdk(@NotNull Project project) { return ProjectRootManager.getInstance(project).getProjectSdk(); } @Nullable - public String getProjectSdkName(final Project project) { + public String getProjectSdkName(@NotNull final Project project) { return ProjectRootManager.getInstance(project).getProjectSdkName(); } } \ No newline at end of file diff --git a/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/RootModelImpl.java b/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/RootModelImpl.java index b7093f394b30..a719fc1a0d90 100644 --- a/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/RootModelImpl.java +++ b/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/RootModelImpl.java @@ -516,6 +516,7 @@ public class RootModelImpl extends RootModelBase implements ModifiableRootModel } @Override + @Nullable public String getSdkName() { for (OrderEntry orderEntry : getOrderEntries()) { if (orderEntry instanceof JdkOrderEntry) { diff --git a/platform/testGuiFramework/src/com/intellij/testGuiFramework/fixtures/ProjectViewFixture.kt b/platform/testGuiFramework/src/com/intellij/testGuiFramework/fixtures/ProjectViewFixture.kt index 35db134a35d9..259a66416cb8 100644 --- a/platform/testGuiFramework/src/com/intellij/testGuiFramework/fixtures/ProjectViewFixture.kt +++ b/platform/testGuiFramework/src/com/intellij/testGuiFramework/fixtures/ProjectViewFixture.kt @@ -1,18 +1,4 @@ -/* - * 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. - * 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. - */ +// Copyright 2000-2020 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.testGuiFramework.fixtures import com.intellij.ide.projectView.ProjectView @@ -261,7 +247,7 @@ class ProjectViewFixture internal constructor(project: Project, robot: Robot) : val orderEntry = value!!.orderEntry if (orderEntry is JdkOrderEntry) { val sdk = orderEntry.jdk - return sdk.sdkType is JavaSdk + return sdk?.sdkType is JavaSdk } } return false diff --git a/plugins/eclipse/src/org/jetbrains/idea/eclipse/conversion/IdeaSpecificSettings.java b/plugins/eclipse/src/org/jetbrains/idea/eclipse/conversion/IdeaSpecificSettings.java index 3c4c531615c9..11fa90578902 100644 --- a/plugins/eclipse/src/org/jetbrains/idea/eclipse/conversion/IdeaSpecificSettings.java +++ b/plugins/eclipse/src/org/jetbrains/idea/eclipse/conversion/IdeaSpecificSettings.java @@ -1,4 +1,4 @@ -// Copyright 2000-2017 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. +// Copyright 2000-2020 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.idea.eclipse.conversion; @@ -302,7 +302,10 @@ public class IdeaSpecificSettings extends AbstractIdeaSpecificSettings