• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Sholtee / proxygen / 1060

02 May 2025 09:09AM UTC coverage: 92.623% (-0.08%) from 92.705%
1060

push

appveyor

Sholtee
fix RoslynV3 ParameterList issue

4859 of 5246 relevant lines covered (92.62%)

0.93 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

70.27
/SRC/Private/SyntaxFactories/ClassSyntaxFactoryBase.Common.cs
1
/********************************************************************************
2
* ClassSyntaxFactoryBase.Common                                                 *
3
*                                                                               *
4
* Author: Denes Solti                                                           *
5
********************************************************************************/
6
using System;
7
using System.Collections.Generic;
8
using System.Diagnostics;
9
using System.Linq;
10

11
using Microsoft.CodeAnalysis.CSharp;
12
using Microsoft.CodeAnalysis.CSharp.Syntax;
13

14
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
15

16
namespace Solti.Utils.Proxy.Internals
17
{
18
    using Properties;
19

20
    internal partial class ClassSyntaxFactoryBase
21
    {
22
        // https://github.com/dotnet/roslyn/issues/4861
23
        [DebuggerBrowsable(DebuggerBrowsableState.Never)]
24
        protected static readonly IdentifierNameSyntax FValue = IdentifierName("value");
1✔
25

26
        private static T Fail<T>(string message)
27
        {
×
28
            Debug.Fail(message);
×
29
            return default!;
×
30
        }
×
31

32
        private static AccessorDeclarationSyntax ResolveAccessor(SyntaxKind kind, CSharpSyntaxNode? body, params IEnumerable<SyntaxKind> modifiers)
33
        {
1✔
34
            AccessorDeclarationSyntax declaration = AccessorDeclaration(kind);
1✔
35

36
            declaration = body switch
1✔
37
            {
1✔
38
                BlockSyntax block => declaration.WithBody(block),
1✔
39
                ArrowExpressionClauseSyntax arrow => declaration.WithExpressionBody(arrow).WithSemicolonToken
1✔
40
                (
1✔
41
                    Token(SyntaxKind.SemicolonToken)
1✔
42
                ),
1✔
43
                null => declaration.WithSemicolonToken
×
44
                (
×
45
                    Token(SyntaxKind.SemicolonToken)
×
46
                ),
×
47
                _ => Fail<AccessorDeclarationSyntax>("Unknown node type")
×
48
            };
1✔
49

50
            if (modifiers.Any()) declaration = declaration.WithModifiers
×
51
            (
×
52
                modifiers: TokenList
×
53
                (
×
54
                    modifiers.Select(Token)
×
55
                )
×
56
            );
×
57

58
            return declaration;
1✔
59
        }
1✔
60

61
        private IEnumerable<SyntaxKind> ResolveAccessModifiers(IMethodInfo method)
62
        {
1✔
63
            bool internalAllowed = method.DeclaringType.DeclaringAssembly?.IsFriend(ContainingAssembly) is true;
×
64

65
            IEnumerable<SyntaxKind> ams = method
1✔
66
                .AccessModifiers
1✔
67
                .SetFlags()
1✔
68

1✔
69
                //
1✔
70
                // When overriding an "internal protected" member we cannot reuse the "internal" keyword
1✔
71
                // if the base is declared in a different assembly
1✔
72
                //
1✔
73

1✔
74
                .Where(am => am >= AccessModifiers.Protected && (am is not AccessModifiers.Internal || internalAllowed))
×
75
                .Select
1✔
76
                (
1✔
77
                    static am => am switch
1✔
78
                    {
1✔
79
                        AccessModifiers.Public => SyntaxKind.PublicKeyword,
1✔
80
                        AccessModifiers.Protected => SyntaxKind.ProtectedKeyword,
1✔
81
                        AccessModifiers.Internal => SyntaxKind.InternalKeyword,
1✔
82
                        _ => Fail<SyntaxKind>("Member not visible")
×
83
                    }
1✔
84
                );
1✔
85
            if (!ams.Any())
1✔
86
                throw new InvalidOperationException(Resources.UNDETERMINED_ACCESS_MODIFIER);
×
87

88
            return ams;
1✔
89
        }
1✔
90

91
        private static string EnsureUnused(IEnumerable<string> values, string val)
92
        {
1✔
93
            while (values.Any(actual => actual == val))
1✔
94
                val = $"_{val}";
1✔
95

96
            return val;
1✔
97
        }
1✔
98

99
        /// <summary>
100
        /// <code>
101
        /// new System.Object[] {..., ..., ...}
102
        /// </code>
103
        /// </summary>
104
        #if DEBUG
105
        internal
106
        #endif
107
        protected ArrayCreationExpressionSyntax ResolveArray(ITypeInfo elementType, IEnumerable<ExpressionSyntax> elements) => ArrayCreationExpression
1✔
108
        (
1✔
109
            type: ArrayType
1✔
110
            (
1✔
111
                elementType: ResolveType(elementType)
1✔
112
            )
1✔
113
            .WithRankSpecifiers
1✔
114
            (
1✔
115
                rankSpecifiers: SingletonList
1✔
116
                (
1✔
117
                    ArrayRankSpecifier
1✔
118
                    (
1✔
119
                        SingletonSeparatedList
1✔
120
                        (
1✔
121
                            elements.Any() ? OmittedArraySizeExpression() : (ExpressionSyntax) 0.AsLiteral()
1✔
122
                        )
1✔
123
                    )
1✔
124
                )
1✔
125
            ),
1✔
126
            initializer: !elements.Any() ? null : InitializerExpression(SyntaxKind.ArrayInitializerExpression).WithExpressions
1✔
127
            (
1✔
128
                expressions: elements.ToSyntaxList()
1✔
129
            )
1✔
130
        );
1✔
131

132
        /// <summary>
133
        /// <code>
134
        /// new System.Object[] {..., ..., ...}
135
        /// </code>
136
        /// </summary>
137
        #if DEBUG
138
        internal
139
        #endif
140
        protected ArrayCreationExpressionSyntax ResolveArray<T>(IEnumerable<ExpressionSyntax> elements) => ResolveArray(MetadataTypeInfo.CreateFrom(typeof(T)), elements);
1✔
141

142
        /// <summary>
143
        /// <code>
144
        /// new NameSpace.T(.., ...,)
145
        /// </code>
146
        /// </summary>
147
        #if DEBUG
148
        internal
149
        #endif
150
        protected ObjectCreationExpressionSyntax ResolveObject<T>(params IEnumerable<ArgumentSyntax> arguments) => ObjectCreationExpression(type: ResolveType<T>()).WithArgumentList
1✔
151
        (
1✔
152
            ArgumentList
1✔
153
            (
1✔
154
                arguments.ToSyntaxList()
1✔
155
            )
1✔
156
        );
1✔
157

158
        #if DEBUG
159
        internal
160
        #endif
161
        protected static SimpleNameSyntax ResolveIdentifierName(LocalDeclarationStatementSyntax variable) => IdentifierName(variable.Declaration.Variables.Single().Identifier);
1✔
162

163
        #if DEBUG
164
        internal
165
        #endif
166
        protected static ArgumentSyntax ResolveArgument(LocalDeclarationStatementSyntax variable) => Argument
1✔
167
        (
1✔
168
            ResolveIdentifierName(variable)
1✔
169
        );
1✔
170

171
        #if DEBUG
172
        internal
173
        #endif
174
        protected static SimpleNameSyntax ResolveIdentifierName(FieldDeclarationSyntax field) => IdentifierName(field.Declaration.Variables.Single()!.Identifier);
1✔
175

176
        #if DEBUG
177
        internal
178
        #endif
179
        protected static SimpleNameSyntax ResolveIdentifierName(ClassDeclarationSyntax cls) => cls.TypeParameterList is null
×
180
            ? IdentifierName(cls.Identifier)
×
181
            : GenericName
×
182
            (
×
183
                cls.Identifier,
×
184
                TypeArgumentList
×
185
                (
×
186
                    cls.TypeParameterList.Parameters.ToSyntaxList<TypeParameterSyntax, TypeSyntax>
×
187
                    (
×
188
                        static ga => IdentifierName(ga.Identifier)
×
189
                    )
×
190
                )
×
191
            );
×
192
    }
193
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc