Skip to content

Commit

Permalink
Fixed nullability warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasherceg committed Nov 3, 2024
1 parent 11784bb commit 4a53635
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/Framework/Framework/Compilation/DotHtmlFileInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public sealed class DotHtmlFileInfo
public ImmutableArray<CompilationDiagnosticViewModel> Warnings { get; internal set; } = ImmutableArray<CompilationDiagnosticViewModel>.Empty;

/// <summary>Gets or sets the virtual path to the view.</summary>
public string VirtualPath { get; }
public string? VirtualPath { get; }

public string? TagName { get; }
public string? Namespace { get; }
Expand All @@ -25,7 +25,7 @@ public sealed class DotHtmlFileInfo
public ImmutableArray<string>? DefaultValues { get; }
public bool? HasParameters { get; }

public DotHtmlFileInfo(string virtualPath, string? tagName = null, string? nameSpace = null, string? assembly = null, string? tagPrefix = null, string? url = null, string? routeName = null, ImmutableArray<string>? defaultValues = null, bool? hasParameters = null)
public DotHtmlFileInfo(string? virtualPath, string? tagName = null, string? nameSpace = null, string? assembly = null, string? tagPrefix = null, string? url = null, string? routeName = null, ImmutableArray<string>? defaultValues = null, bool? hasParameters = null)
{
VirtualPath = virtualPath;
Status = IsDothtmlFile(virtualPath) ? CompilationState.None : CompilationState.NonCompilable;
Expand All @@ -40,7 +40,7 @@ public DotHtmlFileInfo(string virtualPath, string? tagName = null, string? nameS
HasParameters = hasParameters;
}

private static bool IsDothtmlFile(string virtualPath)
private static bool IsDothtmlFile(string? virtualPath)
{
return !string.IsNullOrWhiteSpace(virtualPath) &&
(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public async Task<bool> CompileAll(bool buildInParallel = true, bool forceRecomp
var compilationTaskFactory = (DotHtmlFileInfo t) => () => {
BuildView(t, forceRecompile, out var masterPage);
if (masterPage != null && masterPage.Status == CompilationState.None)
discoveredMasterPages.TryAdd(masterPage.VirtualPath, masterPage);
discoveredMasterPages.TryAdd(masterPage.VirtualPath!, masterPage);
};

var compileTasks = filesToCompile.Select(compilationTaskFactory).ToArray();
Expand Down Expand Up @@ -185,9 +185,9 @@ public bool BuildView(DotHtmlFileInfo file, bool forceRecompile, out DotHtmlFile
{
if (forceRecompile)
// TODO: next major version - add method to interface
(controlBuilderFactory as DefaultControlBuilderFactory)?.InvalidateCache(file.VirtualPath);
(controlBuilderFactory as DefaultControlBuilderFactory)?.InvalidateCache(file.VirtualPath!);

var pageBuilder = controlBuilderFactory.GetControlBuilder(file.VirtualPath);
var pageBuilder = controlBuilderFactory.GetControlBuilder(file.VirtualPath!);

using var scopedServices = dotvvmConfiguration.ServiceProvider.CreateScope(); // dependencies that are configured as scoped cannot be resolved from root service provider
scopedServices.ServiceProvider.GetRequiredService<DotvvmRequestContextStorage>().Context = new ViewCompilationFakeRequestContext(scopedServices.ServiceProvider);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using DotVVM.Framework.Configuration;
using DotVVM.Framework.Hosting;
using DotVVM.Framework.Security;
using DotVVM.Framework.Utils;
using Microsoft.CodeAnalysis;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
Expand All @@ -33,7 +34,7 @@ public static ImmutableArray<DotvvmCompilationDiagnostic> CompileAll(
diagnostics.AddRange(CompileNoThrow(configuration, markupControl!));
}

var views = configuration.RouteTable.Select(r => r.VirtualPath).ToImmutableArray();
var views = configuration.RouteTable.Select(r => r.VirtualPath).WhereNotNull().ToImmutableArray();
foreach(var view in views)
{
diagnostics.AddRange(CompileNoThrow(configuration, view));
Expand Down
4 changes: 3 additions & 1 deletion src/Framework/Framework/Hosting/AggregateMarkupFileLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using System.Text;
using DotVVM.Framework.Configuration;
using DotVVM.Framework.Utils;

namespace DotVVM.Framework.Hosting
{
Expand Down Expand Up @@ -39,7 +40,8 @@ public AggregateMarkupFileLoader()
/// </summary>
public string GetMarkupFileVirtualPath(IDotvvmRequestContext context)
{
return context.Route!.VirtualPath;
return context.Route!.VirtualPath
?? throw new Exception($"The route {context.Route.RouteName} must have a non-null virtual path.");
}
}
}
3 changes: 2 additions & 1 deletion src/Framework/Framework/Hosting/DefaultMarkupFileLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ public class DefaultMarkupFileLoader : IMarkupFileLoader
/// </summary>
public string GetMarkupFileVirtualPath(IDotvvmRequestContext context)
{
return context.Route!.VirtualPath;
return context.Route!.VirtualPath
?? throw new Exception($"The route {context.Route.RouteName} must have a non-null virtual path.");
}
}
}
3 changes: 2 additions & 1 deletion src/Framework/Framework/Hosting/EmbeddedMarkupFileLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ public class EmbeddedMarkupFileLoader : IMarkupFileLoader
/// </summary>
public string GetMarkupFileVirtualPath(IDotvvmRequestContext context)
{
return context.Route!.VirtualPath;
return context.Route!.VirtualPath
?? throw new Exception($"The route {context.Route.RouteName} must have a non-null virtual path.");
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Framework/Framework/Routing/RouteHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static void AssertConfigurationIsValid(this DotvvmConfiguration config)
invalidRoutes.Add(new DotvvmConfigurationAssertResult<RouteBase>(route, DotvvmConfigurationAssertReason.MissingRouteName));
}

var content = loader.GetMarkup(config, route.VirtualPath);
var content = loader.GetMarkup(config, route.VirtualPath!);
if (content == null)
{
invalidRoutes.Add(new DotvvmConfigurationAssertResult<RouteBase>(route, DotvvmConfigurationAssertReason.MissingFile));
Expand Down

0 comments on commit 4a53635

Please sign in to comment.