JdkOrderEntry - add @Nullable annotations to getJdk() and getJdkName() methods, update usages

GitOrigin-RevId: a6c0a0bc7064ed17457ffe414b86042d325fcaae
This commit is contained in:
Eugene Petrenko
2020-05-13 11:22:08 +00:00
committed by intellij-monorepo-bot
parent 86618d10a8
commit 6497d2f2c3
13 changed files with 46 additions and 81 deletions
@@ -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);
}
@@ -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();
@@ -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);
}
}
@@ -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;
@@ -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()
@@ -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();
}
@@ -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);
@@ -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;
@@ -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();
}
}
@@ -516,6 +516,7 @@ public class RootModelImpl extends RootModelBase implements ModifiableRootModel
}
@Override
@Nullable
public String getSdkName() {
for (OrderEntry orderEntry : getOrderEntries()) {
if (orderEntry instanceof JdkOrderEntry) {
@@ -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
@@ -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<Modifiabl
root.setAttribute(INHERIT_JDK, "true");
}
else {
root.setAttribute("jdk", ((JdkOrderEntry)entry).getJdkName());
String jdkName = ((JdkOrderEntry)entry).getJdkName();
if (jdkName != null) {
root.setAttribute("jdk", jdkName);
}
if (jdk != null) {
root.setAttribute("jdk_type", jdk.getSdkType().getName());
}
@@ -92,7 +92,7 @@ public class PyTreeStructureProvider implements SelectableTreeStructureProvider,
final LibraryOrSdkOrderEntry entry = value.getOrderEntry();
if (entry instanceof JdkOrderEntry) {
final Sdk sdk = ((JdkOrderEntry)entry).getJdk();
final SdkTypeId type = sdk.getSdkType();
final SdkTypeId type = sdk == null ? null : sdk.getSdkType();
if (type instanceof PythonSdkType) {
return sdk;
}