Skip to content

Commit

Permalink
Merge pull request #3309 from sharwell/generic-ptr
Browse files Browse the repository at this point in the history
Fix handling of pointers to generic types
  • Loading branch information
sharwell authored Mar 1, 2021
2 parents a65f49a + 3d6a972 commit 32818be
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,37 @@

namespace StyleCop.Analyzers.Test.CSharp8.SpacingRules
{
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Testing;
using StyleCop.Analyzers.Test.CSharp7.SpacingRules;
using Xunit;
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
StyleCop.Analyzers.SpacingRules.SA1015ClosingGenericBracketsMustBeSpacedCorrectly,
StyleCop.Analyzers.SpacingRules.TokenSpacingCodeFixProvider>;

public class SA1015CSharp8UnitTests : SA1015CSharp7UnitTests
{
[Fact]
[WorkItem(3302, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3302")]
public async Task TestGenericTypePointerAsync()
{
const string testCode = @"using System;
public struct Foo<T>
{
internal unsafe Foo<T [|>|] * Next1;
internal unsafe Foo<T [|>|]* Next2;
}";
const string fixedCode = @"using System;
public struct Foo<T>
{
internal unsafe Foo<T> * Next1;
internal unsafe Foo<T>* Next2;
}";

await VerifyCSharpFixAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, fixedCode, CancellationToken.None).ConfigureAwait(false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,39 @@

namespace StyleCop.Analyzers.Test.CSharp8.SpacingRules
{
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Testing;
using StyleCop.Analyzers.Test.CSharp7.SpacingRules;
using Xunit;
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
StyleCop.Analyzers.SpacingRules.SA1023DereferenceAndAccessOfSymbolsMustBeSpacedCorrectly,
StyleCop.Analyzers.SpacingRules.TokenSpacingCodeFixProvider>;

public class SA1023CSharp8UnitTests : SA1023CSharp7UnitTests
{
[Fact]
[WorkItem(3302, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3302")]
public async Task TestGenericTypePointerAsync()
{
const string testCode = @"using System;
public struct Foo<T>
{
internal unsafe Foo<T> [|*|] Next1;
internal unsafe Foo<T>[|*|]Next2;
internal unsafe Foo<T> [|[|*|]|]Next3;
}";
const string fixedCode = @"using System;
public struct Foo<T>
{
internal unsafe Foo<T>* Next1;
internal unsafe Foo<T>* Next2;
internal unsafe Foo<T>* Next3;
}";

await VerifyCSharpFixAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, fixedCode, CancellationToken.None).ConfigureAwait(false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ private static void HandleGreaterThanToken(SyntaxTreeAnalysisContext context, Sy
allowTrailingSpace = true;
break;

case SyntaxKind.AsteriskToken:
allowTrailingNoSpace = nextToken.Parent.IsKind(SyntaxKind.PointerType);
allowTrailingSpace = true;
break;

case SyntaxKind.QuestionToken:
allowTrailingNoSpace = nextToken.Parent.IsKind(SyntaxKind.NullableType);
allowTrailingSpace = true;
Expand Down

0 comments on commit 32818be

Please sign in to comment.