Skip to content

Commit

Permalink
rework null propagation for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
stevebarrau committed Nov 7, 2023
1 parent 9b430c4 commit 4414542
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,17 @@ public static WorkspaceRoot fromImportSettings(BlazeImportSettings blazeSettings
/**
* Tries to load the import settings for the given project and get the workspace root directory.
* <br>
* Unlike {@link #fromProject}, it will silently return null if this is not a blaze project.
* Unlike {@link #fromProject}, it will silently return null if this is not a blaze project of if
* the project is not properly initialized (eg. in tests).
*/
@Nullable
public static WorkspaceRoot fromProjectSafe(Project project) {
BlazeImportSettings importSettings =
BlazeImportSettingsManager.getInstance(project).getImportSettings();
BlazeImportSettingsManager manager = BlazeImportSettingsManager.getInstance(project);
if (manager == null) {
return null;
}

BlazeImportSettings importSettings = manager.getImportSettings();
return importSettings != null ? fromImportSettings(importSettings) : null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,20 @@ public final class ImportRoots {
@Nullable
public static ImportRoots forProjectSafe(Project project) {
WorkspaceRoot root = WorkspaceRoot.fromProjectSafe(project);
ProjectViewSet projectViewSet = ProjectViewManager.getInstance(project).getProjectViewSet();
if (root == null || projectViewSet == null) {
if (root == null) {
return null;
}

ProjectViewManager manager = ProjectViewManager.getInstance(project);
if (manager == null) {
return null;
}

ProjectViewSet projectViewSet = manager.getProjectViewSet();
if (projectViewSet == null) {
return null;
}

return ImportRoots.builder(root, Blaze.getBuildSystemName(project)).add(projectViewSet).build();
}

Expand Down

0 comments on commit 4414542

Please sign in to comment.