Skip to content

Commit

Permalink
Merge pull request #9 from d1820/bug-fixes
Browse files Browse the repository at this point in the history
bug fixes
  • Loading branch information
d1820 authored Oct 2, 2022
2 parents c51ff74 + 122af24 commit b7a6dbc
Show file tree
Hide file tree
Showing 19 changed files with 231 additions and 40 deletions.
7 changes: 5 additions & 2 deletions CodeDocumentor.Test/Classes/ClassUnitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void NoDiagnosticsShow(string testCode)
/// <param name="column">The column.</param>
[Theory]
[InlineData("ClassTester.cs", "ClassTesterFix.cs", 7, 19, TestFixure.DIAG_TYPE_PRIVATE)]
[InlineData("PublicClassTester.cs", "PublicClassTesterFix.cs", 7, 26, TestFixure.DIAG_TYPE_PUBLIC)]
[InlineData("PublicClassTester.cs", "PublicClassTesterFix.cs", 7, 26, TestFixure.DIAG_TYPE_PUBLIC_ONLY)]
public void ShowDiagnosticAndFix(string testCode, string fixCode, int line, int column, string diagType)
{
var fix = _fixture.LoadTestFile($@"./Classes/{fixCode}");
Expand Down Expand Up @@ -88,7 +88,10 @@ protected override DiagnosticAnalyzer GetCSharpDiagnosticAnalyzer(string diagTyp
CodeDocumentorPackage.Options.IsEnabledForPublishMembersOnly = false;
return new NonPublicClassAnalyzer();
}
CodeDocumentorPackage.Options.IsEnabledForPublishMembersOnly = true;
if (diagType == TestFixure.DIAG_TYPE_PUBLIC_ONLY)
{
CodeDocumentorPackage.Options.IsEnabledForPublishMembersOnly = true;
}
return new ClassAnalyzer();
}
}
Expand Down
9 changes: 6 additions & 3 deletions CodeDocumentor.Test/ConstructorUnitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,9 @@ public void NoDiagnosticsShow(string testCode)
/// <param name="line">The line.</param>
/// <param name="column">The column.</param>
[Theory]
[InlineData(PublicConstructorTestCode, PublicContructorTestFixCode, 10, 10, TestFixure.DIAG_TYPE_PUBLIC)]
[InlineData(PublicConstructorTestCode, PublicContructorTestFixCode, 10, 10, TestFixure.DIAG_TYPE_PUBLIC_ONLY)]
[InlineData(PrivateConstructorTestCode, PrivateContructorTestFixCode, 10, 11, TestFixure.DIAG_TYPE_PRIVATE)]
[InlineData(PublicConstructorWithBooleanParameterTestCode, PublicContructorWithBooleanParameterTestFixCode, 10, 10, TestFixure.DIAG_TYPE_PUBLIC)]
[InlineData(PublicConstructorWithBooleanParameterTestCode, PublicContructorWithBooleanParameterTestFixCode, 10, 10, TestFixure.DIAG_TYPE_PUBLIC_ONLY)]
public void ShowDiagnosticAndFix(string testCode, string fixCode, int line, int column, string diagType)
{
var expected = new DiagnosticResult
Expand Down Expand Up @@ -227,7 +227,10 @@ protected override DiagnosticAnalyzer GetCSharpDiagnosticAnalyzer(string diagTyp
CodeDocumentorPackage.Options.IsEnabledForPublishMembersOnly = false;
return new NonPublicConstructorAnalyzer();
}
CodeDocumentorPackage.Options.IsEnabledForPublishMembersOnly = true;
if (diagType == TestFixure.DIAG_TYPE_PUBLIC_ONLY)
{
CodeDocumentorPackage.Options.IsEnabledForPublishMembersOnly = true;
}
return new ConstructorAnalyzer();
}
}
Expand Down
4 changes: 2 additions & 2 deletions CodeDocumentor.Test/EnumUnitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ public void ShowDiagnosticAndFix(string testCode, string fixCode, int line, int
}
};

this.VerifyCSharpDiagnostic(testCode, TestFixure.DIAG_TYPE_PUBLIC, expected);
this.VerifyCSharpDiagnostic(testCode, TestFixure.DIAG_TYPE_PUBLIC_ONLY, expected);

this.VerifyCSharpFix(testCode, fixCode, TestFixure.DIAG_TYPE_PUBLIC);
this.VerifyCSharpFix(testCode, fixCode, TestFixure.DIAG_TYPE_PUBLIC_ONLY);
}

/// <summary>
Expand Down
9 changes: 6 additions & 3 deletions CodeDocumentor.Test/FieldUnitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ public void ShowDiagnosticAndFix(string testCode, string fixCode, int line, int
}
};

this.VerifyCSharpDiagnostic(testCode, TestFixure.DIAG_TYPE_PUBLIC, expected);
this.VerifyCSharpDiagnostic(testCode, TestFixure.DIAG_TYPE_PUBLIC_ONLY, expected);

this.VerifyCSharpFix(testCode, fixCode, TestFixure.DIAG_TYPE_PUBLIC);
this.VerifyCSharpFix(testCode, fixCode, TestFixure.DIAG_TYPE_PUBLIC_ONLY);
}

/// <summary>
Expand All @@ -151,7 +151,10 @@ protected override DiagnosticAnalyzer GetCSharpDiagnosticAnalyzer(string diagTyp
CodeDocumentorPackage.Options.IsEnabledForPublishMembersOnly = false;
return new NonPublicFieldAnalyzer();
}
CodeDocumentorPackage.Options.IsEnabledForPublishMembersOnly = true;
if (diagType == TestFixure.DIAG_TYPE_PUBLIC_ONLY)
{
CodeDocumentorPackage.Options.IsEnabledForPublishMembersOnly = true;
}
return new FieldAnalyzer();
}
}
Expand Down
4 changes: 2 additions & 2 deletions CodeDocumentor.Test/InterfaceUnitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ public void ShowDiagnosticAndFix(string testCode, string fixCode, int line, int
}
};

this.VerifyCSharpDiagnostic(testCode, TestFixure.DIAG_TYPE_PUBLIC, expected);
this.VerifyCSharpDiagnostic(testCode, TestFixure.DIAG_TYPE_PUBLIC_ONLY, expected);

this.VerifyCSharpFix(testCode, fixCode, TestFixure.DIAG_TYPE_PUBLIC);
this.VerifyCSharpFix(testCode, fixCode, TestFixure.DIAG_TYPE_PUBLIC_ONLY);
}

/// <summary>
Expand Down
9 changes: 6 additions & 3 deletions CodeDocumentor.Test/MethodUnitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -606,9 +606,9 @@ public void ShowDiagnosticAndFix(string testCode, string fixCode, int line, int
}
};

this.VerifyCSharpDiagnostic(testCode, TestFixure.DIAG_TYPE_PUBLIC, expected);
this.VerifyCSharpDiagnostic(testCode, TestFixure.DIAG_TYPE_PUBLIC_ONLY, expected);

this.VerifyCSharpFix(testCode, fixCode, TestFixure.DIAG_TYPE_PUBLIC);
this.VerifyCSharpFix(testCode, fixCode, TestFixure.DIAG_TYPE_PUBLIC_ONLY);
}

/// <summary>
Expand All @@ -631,7 +631,10 @@ protected override DiagnosticAnalyzer GetCSharpDiagnosticAnalyzer(string diagTyp
CodeDocumentorPackage.Options.IsEnabledForPublishMembersOnly = false;
return new NonPublicMethodAnalyzer();
}
CodeDocumentorPackage.Options.IsEnabledForPublishMembersOnly = true;
if (diagType == TestFixure.DIAG_TYPE_PUBLIC_ONLY)
{
CodeDocumentorPackage.Options.IsEnabledForPublishMembersOnly = true;
}
return new MethodAnalyzer();
}

Expand Down
105 changes: 92 additions & 13 deletions CodeDocumentor.Test/PropertyUnitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,80 @@ public class PropertyTester
}";



/// <summary>
/// The public property test code.
/// </summary>
private const string PublicPropertyInterfaceTestCode = @"
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApp4
{
public interface PropertyTester
{
public string PersonName => ""Person Name"";
}
}";

/// <summary>
/// The public property test fix code.
/// </summary>
private const string PublicPropertyInterfaceTestFixCode = @"
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApp4
{
public interface PropertyTester
{
/// <summary>
/// Gets the person name.
/// </summary>
public string PersonName => ""Person Name"";
}
}";




/// <summary>
/// The public property test code.
/// </summary>
private const string PrivatePropertyInterfaceTestCode = @"
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApp4
{
public interface PropertyTester
{
string PersonName => ""Person Name"";
}
}";

/// <summary>
/// The public property test fix code.
/// </summary>
private const string PrivatePropertyInterfaceTestFixCode = @"
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApp4
{
public interface PropertyTester
{
/// <summary>
/// Gets the person name.
/// </summary>
string PersonName => ""Person Name"";
}
}";

}
/// <summary>
/// The property unit test.
Expand Down Expand Up @@ -344,15 +418,17 @@ public void NoDiagnosticsShow(string testCode)
/// <param name="line">The line.</param>
/// <param name="column">The column.</param>
[Theory]
[InlineData(PropertyWithGetterSetterTestCode, PropertyWithGetterSetterTestFixCode, 10, 17)]
[InlineData(PropertyOnlyGetterTestCode, PropertyOnlyGetterTestFixCode, 10, 17)]
[InlineData(PropertyPrivateGetterTestCode, PropertyPrivateGetterTestFixCode, 10, 23)]
[InlineData(PropertyInternalGetterTestCode, PropertyInternalGetterTestFixCode, 10, 23)]
[InlineData(BooleanPropertyTestCode, BooleanPropertyTestFixCode, 10, 15)]
[InlineData(NullableBooleanPropertyTestCode, NullableBooleanPropertyTestFixCode, 10, 16)]
[InlineData(ExpressionBodyPropertyTestCode, ExpressionBodyPropertyTestFixCode, 10, 17)]
[InlineData(NullableDateTimePropertyTestCode, NullableDateTimePropertyTestFixCode, 10, 20)]
public void ShowDiagnosticAndFix(string testCode, string fixCode, int line, int column)
[InlineData(PropertyWithGetterSetterTestCode, PropertyWithGetterSetterTestFixCode, 10, 17, TestFixure.DIAG_TYPE_PUBLIC_ONLY)]
[InlineData(PropertyOnlyGetterTestCode, PropertyOnlyGetterTestFixCode, 10, 17, TestFixure.DIAG_TYPE_PUBLIC_ONLY)]
[InlineData(PropertyPrivateGetterTestCode, PropertyPrivateGetterTestFixCode, 10, 23, TestFixure.DIAG_TYPE_PUBLIC_ONLY)]
[InlineData(PropertyInternalGetterTestCode, PropertyInternalGetterTestFixCode, 10, 23, TestFixure.DIAG_TYPE_PUBLIC_ONLY)]
[InlineData(BooleanPropertyTestCode, BooleanPropertyTestFixCode, 10, 15, TestFixure.DIAG_TYPE_PUBLIC_ONLY)]
[InlineData(NullableBooleanPropertyTestCode, NullableBooleanPropertyTestFixCode, 10, 16, TestFixure.DIAG_TYPE_PUBLIC_ONLY)]
[InlineData(ExpressionBodyPropertyTestCode, ExpressionBodyPropertyTestFixCode, 10, 17, TestFixure.DIAG_TYPE_PUBLIC_ONLY)]
[InlineData(NullableDateTimePropertyTestCode, NullableDateTimePropertyTestFixCode, 10, 20, TestFixure.DIAG_TYPE_PUBLIC_ONLY)]
[InlineData(PublicPropertyInterfaceTestCode, PublicPropertyInterfaceTestFixCode, 10, 17, TestFixure.DIAG_TYPE_PUBLIC)]
[InlineData(PrivatePropertyInterfaceTestCode, PrivatePropertyInterfaceTestFixCode, 10, 10, TestFixure.DIAG_TYPE_PRIVATE)]
public void ShowDiagnosticAndFix(string testCode, string fixCode, int line, int column, string diagType)
{
var expected = new DiagnosticResult
{
Expand All @@ -365,9 +441,9 @@ public void ShowDiagnosticAndFix(string testCode, string fixCode, int line, int
}
};

this.VerifyCSharpDiagnostic(testCode, TestFixure.DIAG_TYPE_PUBLIC, expected);
this.VerifyCSharpDiagnostic(testCode, diagType, expected);

this.VerifyCSharpFix(testCode, fixCode, TestFixure.DIAG_TYPE_PUBLIC);
this.VerifyCSharpFix(testCode, fixCode, diagType);
}

/// <summary>
Expand All @@ -385,12 +461,15 @@ protected override CodeFixProvider GetCSharpCodeFixProvider()
/// <returns>A DiagnosticAnalyzer.</returns>
protected override DiagnosticAnalyzer GetCSharpDiagnosticAnalyzer(string diagType)
{
if (diagType == "private")
if (diagType == TestFixure.DIAG_TYPE_PRIVATE)
{
CodeDocumentorPackage.Options.IsEnabledForPublishMembersOnly = false;
return new NonPublicPropertyAnalyzer();
}
CodeDocumentorPackage.Options.IsEnabledForPublishMembersOnly = true;
if (diagType == TestFixure.DIAG_TYPE_PUBLIC_ONLY)
{
CodeDocumentorPackage.Options.IsEnabledForPublishMembersOnly = true;
}
return new PropertyAnalyzer();
}
}
Expand Down
1 change: 1 addition & 0 deletions CodeDocumentor.Test/TestFixure.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace CodeDocumentor.Test
public class TestFixure
{
public const string DIAG_TYPE_PUBLIC = "public";
public const string DIAG_TYPE_PUBLIC_ONLY = "publicOnly";
public const string DIAG_TYPE_PRIVATE = "private";

public TestFixure()
Expand Down
3 changes: 2 additions & 1 deletion CodeDocumentor/Analyzers/Classes/ClassCodeFixProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ private async Task<Document> AddDocumentationHeaderAsync(Document document, Synt

//append to any existing leading trivia [attributes, decorators, etc)
SyntaxTriviaList leadingTrivia = declarationSyntax.GetLeadingTrivia();
SyntaxTriviaList newLeadingTrivia = leadingTrivia.Insert(leadingTrivia.Count - 1, SyntaxFactory.Trivia(commentTrivia));

var newLeadingTrivia = DocumentationHeaderHelper.BuildLeadingTrivia(leadingTrivia, commentTrivia);
ClassDeclarationSyntax newDeclaration = declarationSyntax.WithLeadingTrivia(newLeadingTrivia);
SyntaxNode newRoot = root.ReplaceNode(declarationSyntax, newDeclaration);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ private async Task<Document> AddDocumentationHeaderAsync(Document document, Synt
SyntaxTriviaList leadingTrivia = declarationSyntax.GetLeadingTrivia();
DocumentationCommentTriviaSyntax commentTrivia = await Task.Run(() => CreateDocumentationCommentTriviaSyntax(declarationSyntax), cancellationToken);

SyntaxTriviaList newLeadingTrivia = leadingTrivia.Insert(leadingTrivia.Count - 1, SyntaxFactory.Trivia(commentTrivia));
var newLeadingTrivia = DocumentationHeaderHelper.BuildLeadingTrivia(leadingTrivia, commentTrivia);
ConstructorDeclarationSyntax newDeclaration = declarationSyntax.WithLeadingTrivia(newLeadingTrivia);

SyntaxNode newRoot = root.ReplaceNode(declarationSyntax, newDeclaration);
Expand Down
2 changes: 1 addition & 1 deletion CodeDocumentor/Analyzers/Enums/EnumCodeFixProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ private async Task<Document> AddDocumentationHeaderAsync(Document document, Synt
string comment = CommentHelper.CreateEnumComment(declarationSyntax.Identifier.ValueText.AsSpan());
DocumentationCommentTriviaSyntax commentTrivia = await Task.Run(() => DocumentationHeaderHelper.CreateOnlySummaryDocumentationCommentTrivia(comment), cancellationToken);

SyntaxTriviaList newLeadingTrivia = leadingTrivia.Insert(leadingTrivia.Count - 1, SyntaxFactory.Trivia(commentTrivia));
var newLeadingTrivia = DocumentationHeaderHelper.BuildLeadingTrivia(leadingTrivia, commentTrivia);
EnumDeclarationSyntax newDeclaration = declarationSyntax.WithLeadingTrivia(newLeadingTrivia);

SyntaxNode newRoot = root.ReplaceNode(declarationSyntax, newDeclaration);
Expand Down
2 changes: 1 addition & 1 deletion CodeDocumentor/Analyzers/Fields/FieldCodeFixProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ private async Task<Document> AddDocumentationHeaderAsync(Document document, Synt
string comment = CommentHelper.CreateFieldComment(field.Identifier.ValueText.AsSpan());
DocumentationCommentTriviaSyntax commentTrivia = await Task.Run(() => DocumentationHeaderHelper.CreateOnlySummaryDocumentationCommentTrivia(comment), cancellationToken);

SyntaxTriviaList newLeadingTrivia = leadingTrivia.Insert(leadingTrivia.Count - 1, SyntaxFactory.Trivia(commentTrivia));
var newLeadingTrivia = DocumentationHeaderHelper.BuildLeadingTrivia(leadingTrivia, commentTrivia);
FieldDeclarationSyntax newDeclaration = declarationSyntax.WithLeadingTrivia(newLeadingTrivia);

SyntaxNode newRoot = root.ReplaceNode(declarationSyntax, newDeclaration);
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ private async Task<Document> AddDocumentationHeaderAsync(Document document, Synt
DocumentationCommentTriviaSyntax commentTrivia = SyntaxFactory.DocumentationCommentTrivia(SyntaxKind.SingleLineDocumentationCommentTrivia, list);

SyntaxTriviaList leadingTrivia = declarationSyntax.GetLeadingTrivia();
SyntaxTriviaList newLeadingTrivia = leadingTrivia.Insert(leadingTrivia.Count - 1, SyntaxFactory.Trivia(commentTrivia));
var newLeadingTrivia = DocumentationHeaderHelper.BuildLeadingTrivia(leadingTrivia, commentTrivia);
InterfaceDeclarationSyntax newDeclaration = declarationSyntax.WithLeadingTrivia(newLeadingTrivia);

SyntaxNode newRoot = root.ReplaceNode(declarationSyntax, newDeclaration);
Expand Down
4 changes: 2 additions & 2 deletions CodeDocumentor/CodeDocumentor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@
<Compile Include="Helper\ReturnCommentConstruction.cs" />
<Compile Include="Helper\SingleWordMethodCommentConstruction.cs" />
<Compile Include="Helper\Translator.cs" />
<Compile Include="InterfaceAnalyzer.cs" />
<Compile Include="InterfaceCodeFixProvider.cs" />
<Compile Include="Analyzers\Interfaces\InterfaceAnalyzer.cs" />
<Compile Include="Analyzers\Interfaces\InterfaceCodeFixProvider.cs" />
<Compile Include="Interfaces\IOptionPageGrid.cs" />
<Compile Include="Analyzers\Methods\MethodAnalyzer.cs" />
<Compile Include="Analyzers\Methods\MethodCodeFixProvider.cs" />
Expand Down
20 changes: 20 additions & 0 deletions CodeDocumentor/Helper/DocumentationHeaderHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,26 @@ internal static XmlTextSyntax CreateSummaryTextSyntax(string content)
return SyntaxFactory.XmlText(newLine0Token, text1Token, newLine2Token, text2Token);
}

/// <summary>
/// Builds the leading trivia.
/// </summary>
/// <param name="leadingTrivia">The leading trivia.</param>
/// <param name="commentTrivia">The comment trivia.</param>
/// <returns>A SyntaxTriviaList.</returns>
internal static SyntaxTriviaList BuildLeadingTrivia(SyntaxTriviaList leadingTrivia, DocumentationCommentTriviaSyntax commentTrivia)
{
SyntaxTriviaList newLeadingTrivia;
if (leadingTrivia.All(a=> a.IsKind(SyntaxKind.EndOfLineTrivia)))
{
newLeadingTrivia = leadingTrivia.Add(SyntaxFactory.Trivia(commentTrivia));
}
else
{
newLeadingTrivia = leadingTrivia.Insert(leadingTrivia.Count - 1, SyntaxFactory.Trivia(commentTrivia));
}
return newLeadingTrivia;
}

/// <summary>
/// Creates line start text syntax.
/// </summary>
Expand Down
Loading

0 comments on commit b7a6dbc

Please sign in to comment.