Skip to content

Commit

Permalink
Refactoring and fixing code analyse issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Baudin999 committed Dec 19, 2019
1 parent 11b1e0c commit 6bc2bd5
Show file tree
Hide file tree
Showing 46 changed files with 121 additions and 132 deletions.
12 changes: 8 additions & 4 deletions ApplicationTests/ParseMultipleFiles.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Threading.Tasks;
using CLI;
Expand All @@ -9,15 +10,17 @@ namespace ApplicationTests
{
public class ParseMultipleFiles : IDisposable
{
private readonly ITestOutputHelper output;

private readonly string dir = Path.GetFullPath("ParseMultipleFiles", Directory.GetCurrentDirectory());
private readonly Project project;
public ParseMultipleFiles(ITestOutputHelper output)
public ParseMultipleFiles()
{
try
{
Directory.Delete(dir, true);
} catch (Exception) { }
} catch (Exception) {
Debug.WriteLine("Delete Directory failed in unit test.");
}
Directory.CreateDirectory(dir);
File.WriteAllText(path("First.car"), @"# The first document
Expand All @@ -29,12 +32,13 @@ open Person
type School
");

this.output = output;
project = new Project(dir);
}

[Fact]
#pragma warning disable IDE0051 // Remove unused private members
private void CreateModule()
#pragma warning restore IDE0051 // Remove unused private members
{
Assert.Equal(2, project.Modules.Count);
var second = project.FindModule("Second");
Expand Down
7 changes: 6 additions & 1 deletion ApplicationTests/ProjectFileWatcher.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Threading.Tasks;
using CLI;
Expand All @@ -17,7 +18,9 @@ public ProjectFileWatcher(ITestOutputHelper output)
try
{
Directory.Delete(dir, true);
} catch (Exception) { }
} catch (Exception) {
Debug.WriteLine("Delete Directory failed in unit test.");
}

this.output = output;
project = new Project(dir);
Expand All @@ -30,7 +33,9 @@ public ProjectFileWatcher(ITestOutputHelper output)
}

[Fact]
#pragma warning disable IDE0051 // Remove unused private members
private void CreateModule()
#pragma warning restore IDE0051 // Remove unused private members
{
project.CreateModule("Test");
Assert.True(File.Exists(path("Test.car")));
Expand Down
3 changes: 2 additions & 1 deletion CLI/CLI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@
<ProjectReference Include="..\Mapper.JSON\Mapper.JSON.csproj" />
<ProjectReference Include="..\Mapper.HTML\Mapper.HTML.csproj" />
<ProjectReference Include="..\Mapper.Application\Mapper.Application.csproj" />
<ProjectReference Include="..\Configuration\Configuration.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.CommandLineUtils" Version="1.1.1" />
<PackageReference Include="System.IO.FileSystem" Version="4.3.0" />
<PackageReference Include="System.IO.FileSystem.Watcher" Version="4.3.0" />
<PackageReference Include="Bogus" Version="28.4.2" />
<PackageReference Include="Bogus" Version="28.4.4" />
<PackageReference Include="LiteDB" Version="4.1.4" />
</ItemGroup>
<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion CLI/Controllers/ModuleController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public async Task<IActionResult> SaveModuleTextAsync(string module)

if (m is null)
{
return await Task.Run(() => NotFound());
return await Task.Run(NotFound);
}
else {
using (var reader = new StreamReader(Request.Body, Encoding.UTF8))
Expand Down
10 changes: 5 additions & 5 deletions CLI/Controllers/RouteController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ public MonitorController(IActionDescriptorCollectionProvider provider)
public IActionResult GetRoutes()
{
var rs = _provider.ActionDescriptors.Items;
var routes = rs.Select(x => new {
Controller = x.RouteValues["controller"],
Action = x.RouteValues["action"],
Url = $"{x.RouteValues["controller"]}/{x.RouteValues["action"]}"
}).ToList();
var routes = rs.Select(x => (
Controller: x.RouteValues["controller"],
Action: x.RouteValues["action"],
Url: $"{x.RouteValues["controller"]}/{x.RouteValues["action"]}"
)).ToList();
return Ok(routes);
}
}
Expand Down
2 changes: 1 addition & 1 deletion CLI/Database.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace CLI
{
public class Database
public static class Database
{
private static string path = Path.Combine(Project.Current?.OutPath ?? "", "Lexicon.db");
private static ConnectionString ConnectionString()
Expand Down
6 changes: 3 additions & 3 deletions CLI/Module.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Compiler;
using Compiler.AST;
using Mapper.Application;
using Configuration;

namespace CLI
{
Expand All @@ -20,7 +21,6 @@ public class Module : IDisposable
public ASTGenerator Generator { get; private set; }
public DateTime LastParsed { get; private set; }


public Module(string path, string basePath, Project project)
{
this.Path = path;
Expand All @@ -45,7 +45,7 @@ public void Parse()

public void SaveModuleOutput(bool decend = true, bool suppressMessage = false)
{
this.Transpiler.StartTranspilation(this.Name);
this.Transpiler.StartTranspilation(this.Name, Project.CarConfig?.ErdConfig ?? new ErdConfig());
if (!suppressMessage)
{
Console.WriteLine($"Perfectly parsed: {Name}");
Expand Down Expand Up @@ -114,7 +114,7 @@ private string ReadModuleText()
}
catch (IOException ioe)
{
Console.WriteLine("ReadModuleText: Caught Exception reading file [{0}]", ioe.ToString());
Console.WriteLine("ReadModuleText: Caught Exception reading file [{0}]", ioe);
throw ioe;
}
}
Expand Down
1 change: 1 addition & 0 deletions CLI/Project.CarConfig.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Configuration;

namespace CLI
{
Expand Down
5 changes: 3 additions & 2 deletions CLI/Project.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Threading.Tasks;
using CLI.Signals;
using Compiler.AST;
using Configuration;

namespace CLI
{
Expand Down Expand Up @@ -103,7 +104,7 @@ Have fun with your module!
}
catch (IOException ioe)
{
Console.WriteLine("ReadModuleText: Caught Exception reading file [{0}]", ioe.ToString());
Console.WriteLine("ReadModuleText: Caught Exception reading file [{0}]", ioe);
throw ioe;
}
}
Expand Down Expand Up @@ -249,7 +250,7 @@ public void Dispose()

}

private class Helpers
private static class Helpers
{
public static string ReadAsset(string name)
{
Expand Down
5 changes: 3 additions & 2 deletions CLI/Transpiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Mapper.HTML;
using Mapper.JSON;
using Mapper.XSD;
using Configuration;

namespace CLI
{
Expand Down Expand Up @@ -63,15 +64,15 @@ public Dictionary<string, string> JsonToString()
}


public void StartTranspilation(string moduleName = "")
public void StartTranspilation(string moduleName, ErdConfig erdConfig)
{
this.Imports = ImportResolver.ResolveImports(this.Generator);
this.Generator.Resolve(this.Imports);

this.XsdMapper = new XSDMapper(this.Generator);
this.XsdMapper.Start().ToList();

this.HtmlMapper = new HtmlMapper(this.Generator);
this.HtmlMapper = new HtmlMapper(this.Generator, erdConfig);
this.HtmlMapper.Start().ToList();

this.JsonMapper = new JsonMapper(this.Generator);
Expand Down
2 changes: 1 addition & 1 deletion CLI/WebServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace CLI
{
public class WebServer
public static class WebServer
{
public static string RootPath = "";
public static Task Start(string rootPath)
Expand Down
1 change: 0 additions & 1 deletion Compiler/AST/ASTData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ public object Clone()
ObjectCloner.CloneList(this.Annotations.ToList()),
ObjectCloner.CloneList(this.Directives.ToList()),
ObjectCloner.CloneList(this.Options.ToList()));
{ };
}
}
}
9 changes: 0 additions & 9 deletions Compiler/AST/ASTMarkdown.cs

This file was deleted.

2 changes: 1 addition & 1 deletion Compiler/AST/ASTTypeField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public void SetRestriction(string key, string value, ASTRestriction original)
}

public bool Equals([AllowNull] ASTTypeField x, [AllowNull] ASTTypeField y) => x.Name == y.Name;
public int GetHashCode([DisallowNull] ASTTypeField obj) => ((object)obj).GetHashCode();
public int GetHashCode([DisallowNull] ASTTypeField obj) => obj.GetHashCode();

public override string ToString() => $"{Name}: {String.Join(" ", Types)};";
}
Expand Down
10 changes: 5 additions & 5 deletions Compiler/Lexer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public IEnumerable<Token> Lex(string code)
{
context = true;
var token = TokenLexers.Word(input);
yield return new Token() {
yield return new Token {
EndLine = input.Line,
EndColumn = 0,
StartLine = input.Line,
Expand Down Expand Up @@ -75,7 +75,7 @@ public IEnumerable<Token> Lex(string code)
yield return TokenLexers.TakeUntillEndOfContext(input);
if (context)
{
yield return new Token() {
yield return new Token {
EndLine = input.Line,
EndColumn = 0,
StartLine = input.Line,
Expand All @@ -87,7 +87,7 @@ public IEnumerable<Token> Lex(string code)
else if (context && Char2.IsNewLine(input.Current) && TokenLexers.EndContext(input, 1))
{
context = false;
yield return new Token() {
yield return new Token {
EndLine = input.Line,
EndColumn = 0,
StartLine = input.Line,
Expand Down Expand Up @@ -203,7 +203,7 @@ public IEnumerable<Token> Lex(string code)
// we'll want to end the context, jsut for good measure!
if (context)
{
yield return new Token() {
yield return new Token {
EndLine = input.Line,
EndColumn = 0,
StartLine = input.Line,
Expand All @@ -213,7 +213,7 @@ public IEnumerable<Token> Lex(string code)
context = false;
}

yield return new Token() {
yield return new Token {
EndLine = input.Line,
EndColumn = 0,
StartLine = input.Line,
Expand Down
25 changes: 0 additions & 25 deletions Compiler/Pipeline.cs

This file was deleted.

2 changes: 1 addition & 1 deletion Compiler/Token.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public object Clone()
{
Value = (string)this.Value.Clone(),
// Performing a lookup will ensure copy by value
TokenType = (TokenType)((int)this.TokenType),
TokenType = (TokenType)this.TokenType,

// int's are never copied by reference, no need to clone
StartColumn = this.StartColumn,
Expand Down
4 changes: 2 additions & 2 deletions Compiler/Tokens/Lexer.GenericParameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ public static Token GenericParameter(Input input)
var startColumn = input.Column;
var startLine = input.Line;

StringBuilder builder = new StringBuilder();
var builder = new StringBuilder();
builder.Append(input.Current);

while (input.HasNext() && Char.IsLetter(input.Next()))
{
builder.Append(input.Current);
}

return new Token()
return new Token
{
StartIndex = start,
StartColumn = startColumn,
Expand Down
8 changes: 4 additions & 4 deletions Compiler/Tokens/Lexer.Identifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ public static Token Identifier(Input input)
var startColumn = input.Column;
var startLine = input.Line;

StringBuilder builder = new StringBuilder();
var builder = new StringBuilder();
while (input.HasNext() && (char.IsLetter(input.Current) || char.IsNumber(input.Current)))
{
builder.Append(input.Current);
input.Next();
}
return new Token()
return new Token
{
StartIndex = start,
StartColumn = startColumn,
Expand All @@ -46,13 +46,13 @@ public static Token QualifiedIdentifier(Input input)
var startColumn = input.Column;
var startLine = input.Line;

StringBuilder builder = new StringBuilder();
var builder = new StringBuilder();
while (input.HasNext() && (char.IsLetter(input.Current) || char.IsNumber(input.Current) || input.Current == '.'))
{
builder.Append(input.Current);
input.Next();
}
return new Token()
return new Token
{
StartIndex = start,
StartColumn = startColumn,
Expand Down
2 changes: 1 addition & 1 deletion Compiler/Tokens/Lexer.Indent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ internal static Token TakeIndent(Input input)
{
input.Next();

return new Token()
return new Token
{
StartIndex = input.Position - 1,
StartColumn = input.Column - 1,
Expand Down
2 changes: 1 addition & 1 deletion Compiler/Tokens/Lexer.NewLine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ public static partial class TokenLexers
{
internal static Token TakeNewLine(Input input)
{
var result = new Token()
var result = new Token
{
StartIndex = input.Position,
StartColumn = input.Column,
Expand Down
Loading

0 comments on commit 6bc2bd5

Please sign in to comment.