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

Sholtee / proxygen / 1032

26 Apr 2025 04:30AM UTC coverage: 92.643% (+1.0%) from 91.629%
1032

push

appveyor

Sholtee
+1 test case

4810 of 5192 relevant lines covered (92.64%)

0.93 hits per line

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

72.64
/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
1✔
44
                (
1✔
45
                    Token(SyntaxKind.SemicolonToken)
1✔
46
                ),
1✔
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
        /// <summary>
92
        /// <code>
93
        /// new System.Object[] {..., ..., ...}
94
        /// </code>
95
        /// </summary>
96
        #if DEBUG
97
        internal
98
        #endif
99
        protected ArrayCreationExpressionSyntax ResolveArray(ITypeInfo elementType, IEnumerable<ExpressionSyntax> elements) => ArrayCreationExpression
1✔
100
        (
1✔
101
            type: ArrayType
1✔
102
            (
1✔
103
                elementType: ResolveType(elementType)
1✔
104
            )
1✔
105
            .WithRankSpecifiers
1✔
106
            (
1✔
107
                rankSpecifiers: SingletonList
1✔
108
                (
1✔
109
                    ArrayRankSpecifier
1✔
110
                    (
1✔
111
                        SingletonSeparatedList
1✔
112
                        (
1✔
113
                            elements.Any() ? OmittedArraySizeExpression() : (ExpressionSyntax) 0.AsLiteral()
1✔
114
                        )
1✔
115
                    )
1✔
116
                )
1✔
117
            ),
1✔
118
            initializer: !elements.Any() ? null : InitializerExpression(SyntaxKind.ArrayInitializerExpression).WithExpressions
1✔
119
            (
1✔
120
                expressions: elements.ToSyntaxList()
1✔
121
            )
1✔
122
        );
1✔
123

124
        /// <summary>
125
        /// <code>
126
        /// new System.Object[] {..., ..., ...}
127
        /// </code>
128
        /// </summary>
129
        #if DEBUG
130
        internal
131
        #endif
132
        protected ArrayCreationExpressionSyntax ResolveArray<T>(IEnumerable<ExpressionSyntax> elements) => ResolveArray(MetadataTypeInfo.CreateFrom(typeof(T)), elements);
1✔
133

134
        /// <summary>
135
        /// <code>
136
        /// new NameSpace.T(.., ...,)
137
        /// </code>
138
        /// </summary>
139
        #if DEBUG
140
        internal
141
        #endif
142
        protected ObjectCreationExpressionSyntax ResolveObject<T>(params IEnumerable<ArgumentSyntax> arguments) => ObjectCreationExpression(type: ResolveType<T>()).WithArgumentList
1✔
143
        (
1✔
144
            ArgumentList
1✔
145
            (
1✔
146
                arguments.ToSyntaxList()
1✔
147
            )
1✔
148
        );
1✔
149

150
        #if DEBUG
151
        internal
152
        #endif
153
        protected static SimpleNameSyntax ResolveIdentifierName(LocalDeclarationStatementSyntax variable) => IdentifierName(variable.Declaration.Variables.Single().Identifier);
1✔
154

155
        #if DEBUG
156
        internal
157
        #endif
158
        protected static ArgumentSyntax ResolveArgument(LocalDeclarationStatementSyntax variable) => Argument
1✔
159
        (
1✔
160
            ResolveIdentifierName(variable)
1✔
161
        );
1✔
162

163
        #if DEBUG
164
        internal
165
        #endif
166
        protected static SimpleNameSyntax ResolveIdentifierName(FieldDeclarationSyntax field) => IdentifierName(field.Declaration.Variables.Single()!.Identifier);
1✔
167

168
        #if DEBUG
169
        internal
170
        #endif
171
        protected static SimpleNameSyntax ResolveIdentifierName(ClassDeclarationSyntax cls) => cls.TypeParameterList is null
×
172
            ? IdentifierName(cls.Identifier)
×
173
            : GenericName
×
174
            (
×
175
                cls.Identifier,
×
176
                TypeArgumentList
×
177
                (
×
178
                    cls.TypeParameterList.Parameters.ToSyntaxList<TypeParameterSyntax, TypeSyntax>
×
179
                    (
×
180
                        static ga => IdentifierName(ga.Identifier)
×
181
                    )
×
182
                )
×
183
            );
×
184
    }
185
}
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