Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable nullable reference types #277

Merged
merged 23 commits into from
Aug 16, 2020
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
f9d075b
Enable nullable reference types
ygra Aug 13, 2020
921fe88
Drop nullable disable flags for WpfMath.Colors.
ygra Aug 13, 2020
6bdc348
Drop nullable diable for SvgConverter.
ygra Aug 13, 2020
ff0c861
Drop nullable disable for Utils.
ygra Aug 13, 2020
06fe829
Fixed nullable reference types in sample app.
ygra Aug 14, 2020
fe99f63
Drop nullable disable on a few Tex* classes.
ygra Aug 14, 2020
fc3a7c1
Drop nullable disable on a few more files.
ygra Aug 14, 2020
261695e
Drop nullable disable for Matrices folder.
ygra Aug 14, 2020
f43f6c2
Drop nullable disable for Rendering folder.
ygra Aug 14, 2020
b9ecf56
Drop nullable disable for exceptions.
ygra Aug 14, 2020
290de97
Drop nullable disable for controls.
ygra Aug 14, 2020
7f55098
Drop nullable disable for Glue classes.
ygra Aug 14, 2020
33384cd
Drop nullable disable in Parsers folder.
ygra Aug 14, 2020
5e34df8
Drop nullable disable on first half of Atoms.
ygra Aug 14, 2020
b38d86e
Drop nullable disable on second half of Atoms.
ygra Aug 14, 2020
021704e
Drop nullable disable on third half of Atoms.
ygra Aug 14, 2020
d477cce
Drop nullable disable in RowAtom.
ygra Aug 14, 2020
2314ecc
Drop nullable disable for Box classes.
ygra Aug 14, 2020
6586f26
Drop nullable disable on TexFormulaParser.
ygra Aug 14, 2020
4717e58
Made nullability attributes conditional.
ygra Aug 15, 2020
b6582a3
Review fixes.
ygra Aug 15, 2020
ff1bbfa
Rollback of null handling in RowAtom.
ygra Aug 15, 2020
5b4fd21
Fixed tests after removal of IsDefaultStyle.
ygra Aug 15, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/WpfMath.Example/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public partial class App : Application
{
public static new App Current
{
get { return Application.Current as App; }
get { return (App) Application.Current; }
}

private void Application_Startup(object sender, StartupEventArgs e)
Expand Down
4 changes: 2 additions & 2 deletions src/WpfMath.Example/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ public MainWindow()
FormulaSelector.SelectedIndex = 0;
}

private TexFormula ParseFormula(string input)
private TexFormula? ParseFormula(string input)
{
// Create formula object from input text.
TexFormula formula = null;
TexFormula? formula = null;
try
{
formula = this._formulaParser.Parse(input);
Expand Down
9 changes: 8 additions & 1 deletion src/WpfMath.Example/WpfMath.Example.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,15 @@
<UseWpf>true</UseWpf>
<DebugType>Full</DebugType>
<IsPackable>false</IsPackable>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="../WpfMath/WpfMath.csproj"/>
<ProjectReference Include="../WpfMath/WpfMath.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Nullable" Version="1.2.1">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
</Project>
8 changes: 4 additions & 4 deletions src/WpfMath/Atoms/AccentedAtom.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace WpfMath.Atoms
// Atom representing base atom with accent above it.
internal class AccentedAtom : Atom
{
public AccentedAtom(SourceSpan source, Atom baseAtom, string accentName)
public AccentedAtom(SourceSpan? source, Atom? baseAtom, string accentName)
: base(source)
{
this.BaseAtom = baseAtom;
Expand All @@ -16,7 +16,7 @@ public AccentedAtom(SourceSpan source, Atom baseAtom, string accentName)
throw new ArgumentException("The specified symbol name is not an accent.", "accent");
}

public AccentedAtom(SourceSpan source, Atom baseAtom, TexFormula accent)
public AccentedAtom(SourceSpan? source, Atom? baseAtom, TexFormula accent)
: base(source)
{
if (!(accent.RootAtom is SymbolAtom rootSymbol))
Expand All @@ -30,14 +30,14 @@ public AccentedAtom(SourceSpan source, Atom baseAtom, TexFormula accent)
}

// Atom over which accent symbol is placed.
public Atom BaseAtom { get; }
public Atom? BaseAtom { get; }

// Atom representing accent symbol to place over base atom.
public SymbolAtom AccentAtom { get; }

protected override Box CreateBoxCore(TexEnvironment environment)
{
CharSymbol GetBaseChar()
CharSymbol? GetBaseChar()
{
var baseAtom = this.BaseAtom;
while (baseAtom is AccentedAtom a)
Expand Down
4 changes: 2 additions & 2 deletions src/WpfMath/Atoms/Atom.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ namespace WpfMath.Atoms
// Atom (smallest unit) of TexFormula.
internal abstract class Atom
{
protected Atom(SourceSpan source, TexAtomType type = TexAtomType.Ordinary)
protected Atom(SourceSpan? source, TexAtomType type = TexAtomType.Ordinary)
{
this.Source = source;
this.Type = type;
}

public TexAtomType Type { get; }

public SourceSpan Source { get; }
public SourceSpan? Source { get; }

public Box CreateBox(TexEnvironment environment)
{
Expand Down
28 changes: 14 additions & 14 deletions src/WpfMath/Atoms/BigOperatorAtom.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ private static Box ChangeWidth(Box box, double maxWidth)
}

public BigOperatorAtom(
SourceSpan source,
Atom baseAtom,
Atom lowerLimitAtom,
Atom upperLimitAtom,
SourceSpan? source,
Atom? baseAtom,
Atom? lowerLimitAtom,
Atom? upperLimitAtom,
bool? useVerticalLimits = null)
: this(source, baseAtom, lowerLimitAtom, upperLimitAtom)
{
this.UseVerticalLimits = useVerticalLimits;
}

public BigOperatorAtom(SourceSpan source, Atom baseAtom, Atom lowerLimitAtom, Atom upperLimitAtom)
public BigOperatorAtom(SourceSpan? source, Atom? baseAtom, Atom? lowerLimitAtom, Atom? upperLimitAtom)
: base(source, TexAtomType.BigOperator)
{
this.BaseAtom = baseAtom;
Expand All @@ -36,12 +36,12 @@ public BigOperatorAtom(SourceSpan source, Atom baseAtom, Atom lowerLimitAtom, At
}

// Atom representing big operator.
public Atom BaseAtom { get; }
public Atom? BaseAtom { get; }

// Atoms representing lower and upper limits.
public Atom LowerLimitAtom { get; }
public Atom? LowerLimitAtom { get; }

public Atom UpperLimitAtom { get; }
public Atom? UpperLimitAtom { get; }

// True if limits should be drawn over and under the base atom; false if they should be drawn as scripts.
public bool? UseVerticalLimits { get; }
Expand Down Expand Up @@ -83,9 +83,9 @@ protected override Box CreateBoxCore(TexEnvironment environment)
}

// Create boxes for upper and lower limits.
var upperLimitBox = this.UpperLimitAtom == null ? null : this.UpperLimitAtom.CreateBox(
Box? upperLimitBox = this.UpperLimitAtom == null ? null : this.UpperLimitAtom.CreateBox(
environment.GetSuperscriptStyle());
var lowerLimitBox = this.LowerLimitAtom == null ? null : this.LowerLimitAtom.CreateBox(
Box? lowerLimitBox = this.LowerLimitAtom == null ? null : this.LowerLimitAtom.CreateBox(
environment.GetSubscriptStyle());

// Make all component boxes equally wide.
Expand All @@ -106,28 +106,28 @@ protected override Box CreateBoxCore(TexEnvironment environment)
if (this.UpperLimitAtom != null)
{
resultBox.Add(new StrutBox(0, opSpacing5, 0, 0));
upperLimitBox.Shift = delta / 2;
upperLimitBox!.Shift = delta / 2;
resultBox.Add(upperLimitBox);
kern = Math.Max(texFont.GetBigOpSpacing1(style), texFont.GetBigOpSpacing3(style) -
upperLimitBox.Depth);
resultBox.Add(new StrutBox(0, kern, 0, 0));
}

// Add box for base atom.
resultBox.Add(baseBox);
resultBox.Add(baseBox!);
ygra marked this conversation as resolved.
Show resolved Hide resolved

// Create and add box for lower limit.
if (this.LowerLimitAtom != null)
{
resultBox.Add(new StrutBox(0, Math.Max(texFont.GetBigOpSpacing2(style), texFont.GetBigOpSpacing4(style) -
lowerLimitBox.Height), 0, 0));
lowerLimitBox!.Height), 0, 0));
lowerLimitBox.Shift = -delta / 2;
resultBox.Add(lowerLimitBox);
resultBox.Add(new StrutBox(0, opSpacing5, 0, 0));
}

// Adjust height and depth of result box.
var baseBoxHeight = baseBox.Height;
var baseBoxHeight = baseBox!.Height;
ygra marked this conversation as resolved.
Show resolved Hide resolved
var totalHeight = resultBox.Height + resultBox.Depth;
if (upperLimitBox != null)
baseBoxHeight += opSpacing5 + kern + upperLimitBox.Height + upperLimitBox.Depth;
Expand Down
6 changes: 3 additions & 3 deletions src/WpfMath/Atoms/CharAtom.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace WpfMath.Atoms
// Atom representing single character in specific text style.
internal class CharAtom : CharSymbol
{
public CharAtom(SourceSpan source, char character, string textStyle = null)
public CharAtom(SourceSpan? source, char character, string? textStyle = null)
: base(source)
{
this.TextStyle = textStyle;
Expand All @@ -15,7 +15,7 @@ public CharAtom(SourceSpan source, char character, string textStyle = null)
public char Character { get; }

// Null means default text style.
public string TextStyle { get; }
public string? TextStyle { get; }

private bool IsDefaultTextStyle => this.TextStyle == null;

Expand All @@ -25,7 +25,7 @@ public override ITeXFont GetStyledFont(TexEnvironment environment) =>
protected override Result<CharInfo> GetCharInfo(ITeXFont texFont, TexStyle style) =>
this.IsDefaultTextStyle
? texFont.GetDefaultCharInfo(this.Character, style)
: texFont.GetCharInfo(this.Character, this.TextStyle, style);
: texFont.GetCharInfo(this.Character, this.TextStyle!, style); // Nullable: CS8604, could be resolved by inlining IsDefaultTextStyle
ygra marked this conversation as resolved.
Show resolved Hide resolved

public override Result<CharFont> GetCharFont(ITeXFont texFont) =>
// Style is irrelevant here.
Expand Down
2 changes: 1 addition & 1 deletion src/WpfMath/Atoms/CharSymbol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace WpfMath.Atoms
// Atom representing single character that can be marked as text symbol.
internal abstract class CharSymbol : Atom
{
protected CharSymbol(SourceSpan source, TexAtomType type = TexAtomType.Ordinary)
protected CharSymbol(SourceSpan? source, TexAtomType type = TexAtomType.Ordinary)
: base(source, type)
{
this.IsTextSymbol = false;
Expand Down
2 changes: 1 addition & 1 deletion src/WpfMath/Atoms/DummyAtom.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public DummyAtom(Atom atom)
{
}

public Atom WithPreviousAtom(DummyAtom previousAtom)
public Atom WithPreviousAtom(DummyAtom? previousAtom)
{
if (this.Atom is IRow row)
{
Expand Down
6 changes: 3 additions & 3 deletions src/WpfMath/Atoms/FencedAtom.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ private static void CentreBox(Box box, double axis)
box.Shift = -(totalHeight / 2 - box.Height) - axis;
}

public FencedAtom(SourceSpan source, Atom baseAtom, SymbolAtom leftDelimeter, SymbolAtom rightDelimeter)
public FencedAtom(SourceSpan? source, Atom? baseAtom, SymbolAtom? leftDelimeter, SymbolAtom? rightDelimeter)
: base(source)
{
this.BaseAtom = baseAtom ?? new RowAtom(null);
Expand All @@ -25,9 +25,9 @@ public FencedAtom(SourceSpan source, Atom baseAtom, SymbolAtom leftDelimeter, Sy

public Atom BaseAtom { get; }

private SymbolAtom LeftDelimeter { get; }
private SymbolAtom? LeftDelimeter { get; }

private SymbolAtom RightDelimeter { get; }
private SymbolAtom? RightDelimeter { get; }

protected override Box CreateBoxCore(TexEnvironment environment)
{
Expand Down
2 changes: 1 addition & 1 deletion src/WpfMath/Atoms/FixedCharAtom.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace WpfMath.Atoms
// Atom representing character that does not depend on text style.
internal class FixedCharAtom : CharSymbol
{
public FixedCharAtom(SourceSpan source, CharFont charFont)
public FixedCharAtom(SourceSpan? source, CharFont charFont)
: base(source)
{
this.CharFont = charFont;
Expand Down
32 changes: 16 additions & 16 deletions src/WpfMath/Atoms/FractionAtom.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ private static TexAlignment CheckAlignment(TexAlignment alignment)
private readonly double? lineRelativeThickness;

public FractionAtom(
SourceSpan source,
Atom numerator,
Atom denominator,
SourceSpan? source,
Atom? numerator,
Atom? denominator,
double relativeThickness,
TexAlignment numeratorAlignment,
TexAlignment denominatorAlignment)
Expand All @@ -35,9 +35,9 @@ public FractionAtom(
}

public FractionAtom(
SourceSpan source,
Atom numerator,
Atom denominator,
SourceSpan? source,
Atom? numerator,
Atom? denominator,
bool drawLine,
TexAlignment numeratorAlignment,
TexAlignment denominatorAlignment)
Expand All @@ -47,15 +47,15 @@ public FractionAtom(
this.denominatorAlignment = CheckAlignment(denominatorAlignment);
}

public FractionAtom(SourceSpan source, Atom numerator, Atom denominator, bool drawLine)
public FractionAtom(SourceSpan? source, Atom? numerator, Atom? denominator, bool drawLine)
: this(source, numerator, denominator, drawLine, TexUnit.Pixel, 0d)
{
}

public FractionAtom(
SourceSpan source,
Atom numerator,
Atom denominator,
SourceSpan? source,
Atom? numerator,
Atom? denominator,
TexUnit unit,
double thickness,
TexAlignment numeratorAlignment,
Expand All @@ -66,15 +66,15 @@ public FractionAtom(
this.denominatorAlignment = CheckAlignment(denominatorAlignment);
}

public FractionAtom(SourceSpan source, Atom numerator, Atom denominator, TexUnit unit, double thickness)
public FractionAtom(SourceSpan? source, Atom? numerator, Atom? denominator, TexUnit unit, double thickness)
: this(source, numerator, denominator, false, unit, thickness)
{
}

protected FractionAtom(
SourceSpan source,
Atom numerator,
Atom denominator,
SourceSpan? source,
Atom? numerator,
Atom? denominator,
bool useDefaultThickness,
TexUnit unit,
double thickness)
Expand All @@ -91,9 +91,9 @@ protected FractionAtom(
this.lineThickness = thickness;
}

public Atom Numerator { get; }
public Atom? Numerator { get; }

public Atom Denominator { get; }
public Atom? Denominator { get; }

protected override Box CreateBoxCore(TexEnvironment environment)
{
Expand Down
2 changes: 1 addition & 1 deletion src/WpfMath/Atoms/IRow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ namespace WpfMath
internal interface IRow
{
// Dummy atom representing atom just before first child atom.
Atom WithPreviousAtom(DummyAtom previousAtom);
Atom WithPreviousAtom(DummyAtom? previousAtom);
}
}
16 changes: 8 additions & 8 deletions src/WpfMath/Atoms/MatrixAtom.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@ internal class MatrixAtom : Atom
public const double DefaultPadding = 0.35;

public MatrixAtom(
SourceSpan source,
IEnumerable<IEnumerable<Atom>> cells,
SourceSpan? source,
IEnumerable<IEnumerable<Atom?>> cells,
MatrixCellAlignment matrixCellAlignment,
double verticalPadding = DefaultPadding,
double horizontalPadding = DefaultPadding) : base(source)
{
MatrixCells = new ReadOnlyCollection<ReadOnlyCollection<Atom>>(
cells.Select(row => new ReadOnlyCollection<Atom>(row.ToList())).ToList());
MatrixCells = new ReadOnlyCollection<ReadOnlyCollection<Atom?>>(
cells.Select(row => new ReadOnlyCollection<Atom?>(row.ToList())).ToList());
MatrixCellAlignment = matrixCellAlignment;
VerticalPadding = verticalPadding;
HorizontalPadding = horizontalPadding;
}

public ReadOnlyCollection<ReadOnlyCollection<Atom>> MatrixCells { get; }
public ReadOnlyCollection<ReadOnlyCollection<Atom?>> MatrixCells { get; }

public double VerticalPadding { get; }

Expand All @@ -45,7 +45,7 @@ protected override Box CreateBoxCore(TexEnvironment environment)
return ApplyCellPaddings(environment, cells, columnCount, matrixCellGaps);
}

private IEnumerable<Box> CreateRowCellBoxes(TexEnvironment environment, ReadOnlyCollection<Atom> row) =>
private IEnumerable<Box> CreateRowCellBoxes(TexEnvironment environment, ReadOnlyCollection<Atom?> row) =>
row.Select(atom => atom == null ? StrutBox.Empty : atom.CreateBox(environment));

/// <summary>
Expand Down Expand Up @@ -142,7 +142,7 @@ Tuple<Box, Box> GetTopBottomPadding(int i, int j)
return new Tuple<Box, Box>(topBox, bottomBox);
}

Tuple<Box, Box> GetLeftRightPadding(int i, int j)
Tuple<Box?, Box> GetLeftRightPadding(int i, int j)
{
var value = matrixCellGaps[i][j].Horizontal;
var leftPadding = MatrixCellAlignment == MatrixCellAlignment.Left ? 0.0 : value;
Expand All @@ -151,7 +151,7 @@ Tuple<Box, Box> GetLeftRightPadding(int i, int j)
? null
: new StrutBox(HorizontalPadding / 2 + leftPadding, 0.0, 0.0, 0.0);
var rightBox = new StrutBox(HorizontalPadding / 2 + rightPadding, 0.0, 0.0, 0.0);
return new Tuple<Box, Box>(leftBox, rightBox);
return new Tuple<Box?, Box>(leftBox, rightBox);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/WpfMath/Atoms/NullAtom.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace WpfMath.Atoms
{
internal class NullAtom : Atom
{
public NullAtom(SourceSpan source = null, TexAtomType type = TexAtomType.Ordinary) : base(source, type)
public NullAtom(SourceSpan? source = null, TexAtomType type = TexAtomType.Ordinary) : base(source, type)
{
}

Expand Down
Loading