Skip to content

Commit 3441c44

Browse files
committed
fix(SymbolInfoCreator): use regex
1 parent 1966721 commit 3441c44

File tree

3 files changed

+98
-4
lines changed

3 files changed

+98
-4
lines changed

src/M31.FluentApi.Generator/SourceGenerators/SymbolInfoCreator.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Text.RegularExpressions;
12
using M31.FluentApi.Generator.CodeBuilding;
23
using M31.FluentApi.Generator.CodeGeneration.CodeBoardElements;
34
using M31.FluentApi.Generator.CodeGeneration.CodeBoardElements.FluentApiComments;
@@ -199,6 +200,7 @@ private static ParameterKinds GetParameterKinds(IParameterSymbol parameterSymbol
199200
return parameterKinds;
200201
}
201202

203+
private static readonly Regex fluentApiCommentStart = new Regex(@"^\s*////(?!/)", RegexOptions.Compiled);
202204
private static Comments GetFluentSymbolComments(ISymbol symbol)
203205
{
204206
SyntaxReference? syntaxRef = symbol.DeclaringSyntaxReferences.FirstOrDefault();
@@ -220,12 +222,10 @@ private static Comments GetFluentSymbolComments(ISymbol symbol)
220222
}
221223

222224
string str = syntaxTrivia.ToString();
223-
if (!str.Trim().StartsWith("////")) // todo: regex
225+
if (fluentApiCommentStart.IsMatch(str))
224226
{
225-
continue;
227+
commentLines.Add(str.TrimStart('/', ' '));
226228
}
227-
228-
commentLines.Add(str.TrimStart('/', ' '));
229229
}
230230

231231
string comments = string.Join(Environment.NewLine, commentLines);
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// <auto-generated/>
2+
// This code was generated by the library M31.FluentAPI.
3+
// Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
4+
5+
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
6+
#nullable enable
7+
8+
namespace M31.FluentApi.Tests.CodeGeneration.TestClasses.Abstract.FluentApiComments.WronglyCommentedClass;
9+
10+
public class CreateStudent :
11+
CreateStudent.ICreateStudent,
12+
CreateStudent.IWithName
13+
{
14+
private readonly Student student;
15+
16+
private CreateStudent()
17+
{
18+
student = new Student();
19+
}
20+
21+
public static ICreateStudent InitialStep()
22+
{
23+
return new CreateStudent();
24+
}
25+
26+
public static Student WithName(string name)
27+
{
28+
CreateStudent createStudent = new CreateStudent();
29+
createStudent.student.Name = name;
30+
return createStudent.student;
31+
}
32+
33+
Student IWithName.WithName(string name)
34+
{
35+
student.Name = name;
36+
return student;
37+
}
38+
39+
public interface ICreateStudent : IWithName
40+
{
41+
}
42+
43+
public interface IWithName
44+
{
45+
Student WithName(string name);
46+
}
47+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// <auto-generated/>
2+
// This code was generated by the library M31.FluentAPI.
3+
// Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
4+
5+
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
6+
#nullable enable
7+
8+
namespace M31.FluentApi.Tests.CodeGeneration.TestClasses.Abstract.FluentApiComments.WronglyCommentedClass2;
9+
10+
public class CreateStudent :
11+
CreateStudent.ICreateStudent,
12+
CreateStudent.IWithName
13+
{
14+
private readonly Student student;
15+
16+
private CreateStudent()
17+
{
18+
student = new Student();
19+
}
20+
21+
public static ICreateStudent InitialStep()
22+
{
23+
return new CreateStudent();
24+
}
25+
26+
public static Student WithName(string name)
27+
{
28+
CreateStudent createStudent = new CreateStudent();
29+
createStudent.student.Name = name;
30+
return createStudent.student;
31+
}
32+
33+
Student IWithName.WithName(string name)
34+
{
35+
student.Name = name;
36+
return student;
37+
}
38+
39+
public interface ICreateStudent : IWithName
40+
{
41+
}
42+
43+
public interface IWithName
44+
{
45+
Student WithName(string name);
46+
}
47+
}

0 commit comments

Comments
 (0)