Skip to content

Commit 6465775

Browse files
committed
Remove leftover internal helpers and adjust visibility
1 parent 9c581dc commit 6465775

File tree

5 files changed

+8
-185
lines changed

5 files changed

+8
-185
lines changed

CommunityToolkit.Mvvm.SourceGenerators/Diagnostics/DiagnosticExtensions.cs

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -16,38 +16,6 @@ namespace CommunityToolkit.Mvvm.SourceGenerators.Diagnostics;
1616
/// </summary>
1717
internal static class DiagnosticExtensions
1818
{
19-
/// <summary>
20-
/// Adds a new diagnostics to the current compilation.
21-
/// </summary>
22-
/// <param name="context">The <see cref="GeneratorExecutionContext"/> instance currently in use.</param>
23-
/// <param name="descriptor">The input <see cref="DiagnosticDescriptor"/> for the diagnostics to create.</param>
24-
/// <param name="symbol">The source <see cref="ISymbol"/> to attach the diagnostics to.</param>
25-
/// <param name="args">The optional arguments for the formatted message to include.</param>
26-
public static void ReportDiagnostic(
27-
this GeneratorExecutionContext context,
28-
DiagnosticDescriptor descriptor,
29-
ISymbol symbol,
30-
params object[] args)
31-
{
32-
context.ReportDiagnostic(Diagnostic.Create(descriptor, symbol.Locations.FirstOrDefault(), args));
33-
}
34-
35-
/// <summary>
36-
/// Adds a new diagnostics to the current compilation.
37-
/// </summary>
38-
/// <param name="context">The <see cref="GeneratorExecutionContext"/> instance currently in use.</param>
39-
/// <param name="descriptor">The input <see cref="DiagnosticDescriptor"/> for the diagnostics to create.</param>
40-
/// <param name="node">The source <see cref="SyntaxNode"/> to attach the diagnostics to.</param>
41-
/// <param name="args">The optional arguments for the formatted message to include.</param>
42-
public static void ReportDiagnostic(
43-
this GeneratorExecutionContext context,
44-
DiagnosticDescriptor descriptor,
45-
SyntaxNode node,
46-
params object[] args)
47-
{
48-
context.ReportDiagnostic(Diagnostic.Create(descriptor, node.GetLocation(), args));
49-
}
50-
5119
/// <summary>
5220
/// Adds a new diagnostics to the target builder.
5321
/// </summary>
@@ -64,22 +32,6 @@ public static void Add(
6432
diagnostics.Add(Diagnostic.Create(descriptor, symbol.Locations.FirstOrDefault(), args));
6533
}
6634

67-
/// <summary>
68-
/// Adds a new diagnostics to the target builder.
69-
/// </summary>
70-
/// <param name="diagnostics">The collection of produced <see cref="Diagnostic"/> instances.</param>
71-
/// <param name="descriptor">The input <see cref="DiagnosticDescriptor"/> for the diagnostics to create.</param>
72-
/// <param name="node">The source <see cref="SyntaxNode"/> to attach the diagnostics to.</param>
73-
/// <param name="args">The optional arguments for the formatted message to include.</param>
74-
public static void Add(
75-
this ImmutableArray<Diagnostic>.Builder diagnostics,
76-
DiagnosticDescriptor descriptor,
77-
SyntaxNode node,
78-
params object[] args)
79-
{
80-
diagnostics.Add(Diagnostic.Create(descriptor, node.GetLocation(), args));
81-
}
82-
8335
/// <summary>
8436
/// Registers an output node into an <see cref="IncrementalGeneratorInitializationContext"/> to output diagnostics.
8537
/// </summary>
@@ -95,24 +47,4 @@ public static void ReportDiagnostics(this IncrementalGeneratorInitializationCont
9547
}
9648
});
9749
}
98-
99-
/// <summary>
100-
/// Registers an output node into an <see cref="IncrementalGeneratorInitializationContext"/> to output diagnostics.
101-
/// </summary>
102-
/// <param name="context">The input <see cref="IncrementalGeneratorInitializationContext"/> instance.</param>
103-
/// <param name="isSupported">An <see cref="IncrementalValueProvider{TValue}"/> instance indicating support for a feature.</param>
104-
/// <param name="diagnostic">The <see cref="Diagnostic"/> to emit if <paramref name="isSupported"/> fails.</param>
105-
public static void ReportDiagnosticsIsNotSupported(
106-
this IncrementalGeneratorInitializationContext context,
107-
IncrementalValueProvider<bool> isSupported,
108-
Diagnostic diagnostic)
109-
{
110-
context.RegisterSourceOutput(isSupported, (context, isSupported) =>
111-
{
112-
if (!isSupported)
113-
{
114-
context.ReportDiagnostic(diagnostic);
115-
}
116-
});
117-
}
11850
}

CommunityToolkit.Mvvm.SourceGenerators/Extensions/AttributeDataExtensions.cs

Lines changed: 1 addition & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,9 @@
55
// This file is ported and adapted from ComputeSharp (Sergio0694/ComputeSharp),
66
// more info in ThirdPartyNotices.txt in the root of the project.
77

8-
using System;
98
using System.Collections.Generic;
10-
using System.Linq;
9+
using System.Diagnostics.Contracts;
1110
using Microsoft.CodeAnalysis;
12-
using Microsoft.CodeAnalysis.CSharp;
13-
using Microsoft.CodeAnalysis.CSharp.Syntax;
14-
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
1511

1612
namespace CommunityToolkit.Mvvm.SourceGenerators.Extensions;
1713

@@ -120,76 +116,4 @@ static IEnumerable<T> Enumerate(IEnumerable<TypedConstant> constants)
120116

121117
return Enumerate(attributeData.ConstructorArguments);
122118
}
123-
124-
/// <summary>
125-
/// Creates an <see cref="AttributeSyntax"/> node that is equivalent to the input <see cref="AttributeData"/> instance.
126-
/// </summary>
127-
/// <param name="attributeData">The input <see cref="AttributeData"/> instance to process.</param>
128-
/// <returns>An <see cref="AttributeSyntax"/> replicating the data in <paramref name="attributeData"/>.</returns>
129-
public static AttributeSyntax AsAttributeSyntax(this AttributeData attributeData)
130-
{
131-
IdentifierNameSyntax attributeType = IdentifierName(attributeData.AttributeClass!.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat));
132-
AttributeArgumentSyntax[] arguments =
133-
attributeData.ConstructorArguments
134-
.Select(static arg => AttributeArgument(ToExpression(arg))).Concat(
135-
attributeData.NamedArguments
136-
.Select(static arg =>
137-
AttributeArgument(ToExpression(arg.Value))
138-
.WithNameEquals(NameEquals(IdentifierName(arg.Key))))).ToArray();
139-
140-
return Attribute(attributeType, AttributeArgumentList(SeparatedList(SeparatedList(arguments))));
141-
142-
static ExpressionSyntax ToExpression(TypedConstant arg)
143-
{
144-
if (arg.IsNull)
145-
{
146-
return LiteralExpression(SyntaxKind.NullLiteralExpression);
147-
}
148-
149-
if (arg.Kind == TypedConstantKind.Array)
150-
{
151-
string elementType = ((IArrayTypeSymbol)arg.Type!).ElementType.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat);
152-
153-
return
154-
ArrayCreationExpression(
155-
ArrayType(IdentifierName(elementType))
156-
.AddRankSpecifiers(ArrayRankSpecifier(SingletonSeparatedList<ExpressionSyntax>(OmittedArraySizeExpression()))))
157-
.WithInitializer(InitializerExpression(SyntaxKind.ArrayInitializerExpression)
158-
.AddExpressions(arg.Values.Select(ToExpression).ToArray()));
159-
}
160-
161-
switch ((arg.Kind, arg.Value))
162-
{
163-
case (TypedConstantKind.Primitive, string text):
164-
return LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(text));
165-
case (TypedConstantKind.Primitive, bool flag) when flag:
166-
return LiteralExpression(SyntaxKind.TrueLiteralExpression);
167-
case (TypedConstantKind.Primitive, bool):
168-
return LiteralExpression(SyntaxKind.FalseLiteralExpression);
169-
case (TypedConstantKind.Primitive, object value):
170-
return LiteralExpression(SyntaxKind.NumericLiteralExpression, value switch
171-
{
172-
byte b => Literal(b),
173-
char c => Literal(c),
174-
double d => Literal(d),
175-
float f => Literal(f),
176-
int i => Literal(i),
177-
long l => Literal(l),
178-
sbyte sb => Literal(sb),
179-
short sh => Literal(sh),
180-
uint ui => Literal(ui),
181-
ulong ul => Literal(ul),
182-
ushort ush => Literal(ush),
183-
_ => throw new ArgumentException()
184-
});
185-
case (TypedConstantKind.Type, ITypeSymbol type):
186-
return TypeOfExpression(IdentifierName(type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)));
187-
case (TypedConstantKind.Enum, object value):
188-
return CastExpression(
189-
IdentifierName(arg.Type!.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)),
190-
LiteralExpression(SyntaxKind.NumericLiteralExpression, ParseToken(value.ToString())));
191-
default: throw new ArgumentException();
192-
}
193-
}
194-
}
195119
}

CommunityToolkit.Mvvm.SourceGenerators/Extensions/IEqualityComparerExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public static IEqualityComparer<ImmutableArray<T>> ForImmutableArray<T>(this IEq
3030
/// <summary>
3131
/// An <see cref="IEqualityComparer{T}"/> implementation for an <see cref="ImmutableArray{T}"/> value.
3232
/// </summary>
33-
public sealed class Comparer<T> : IEqualityComparer<ImmutableArray<T>>
33+
private sealed class Comparer<T> : IEqualityComparer<ImmutableArray<T>>
3434
{
3535
/// <summary>
3636
/// The <typeparamref name="T"/> comparer.

CommunityToolkit.Mvvm.SourceGenerators/Extensions/INamedTypeSymbolExtensions.cs

Lines changed: 4 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ namespace CommunityToolkit.Mvvm.SourceGenerators.Extensions;
1313
internal static class INamedTypeSymbolExtensions
1414
{
1515
/// <summary>
16-
/// Gets the full metadata name for a given <see cref="INamedTypeSymbol"/> instance.
16+
/// Gets a valid filename for a given <see cref="INamedTypeSymbol"/> instance.
1717
/// </summary>
1818
/// <param name="symbol">The input <see cref="INamedTypeSymbol"/> instance.</param>
19-
/// <returns>The full metadata name for <paramref name="symbol"/>.</returns>
20-
public static string GetFullMetadataName(this INamedTypeSymbol symbol)
19+
/// <returns>The full metadata name for <paramref name="symbol"/> that is also a valid filename.</returns>
20+
public static string GetFullMetadataNameForFileName(this INamedTypeSymbol symbol)
2121
{
2222
static StringBuilder BuildFrom(ISymbol? symbol, StringBuilder builder)
2323
{
@@ -33,17 +33,7 @@ static StringBuilder BuildFrom(ISymbol? symbol, StringBuilder builder)
3333
};
3434
}
3535

36-
return BuildFrom(symbol, new StringBuilder(256)).ToString();
37-
}
38-
39-
/// <summary>
40-
/// Gets a valid filename for a given <see cref="INamedTypeSymbol"/> instance.
41-
/// </summary>
42-
/// <param name="symbol">The input <see cref="INamedTypeSymbol"/> instance.</param>
43-
/// <returns>The full metadata name for <paramref name="symbol"/> that is also a valid filename.</returns>
44-
public static string GetFullMetadataNameForFileName(this INamedTypeSymbol symbol)
45-
{
46-
return symbol.GetFullMetadataName().Replace('`', '-').Replace('+', '.');
36+
return BuildFrom(symbol, new StringBuilder(256)).ToString().Replace('`', '-').Replace('+', '.');
4737
}
4838

4939
/// <summary>
@@ -68,27 +58,4 @@ public static bool InheritsFrom(this INamedTypeSymbol typeSymbol, string name)
6858

6959
return false;
7060
}
71-
72-
/// <summary>
73-
/// Checks whether or not a given <see cref="INamedTypeSymbol"/> inherits from a specified type.
74-
/// </summary>
75-
/// <param name="typeSymbol">The target <see cref="INamedTypeSymbol"/> instance to check.</param>
76-
/// <param name="targetTypeSymbol">The type symbol of the type to check for inheritance.</param>
77-
/// <returns>Whether or not <paramref name="typeSymbol"/> inherits from <paramref name="targetTypeSymbol"/>.</returns>
78-
public static bool InheritsFrom(this INamedTypeSymbol typeSymbol, INamedTypeSymbol targetTypeSymbol)
79-
{
80-
INamedTypeSymbol? baseType = typeSymbol.BaseType;
81-
82-
while (baseType != null)
83-
{
84-
if (SymbolEqualityComparer.Default.Equals(baseType, targetTypeSymbol))
85-
{
86-
return true;
87-
}
88-
89-
baseType = baseType.BaseType;
90-
}
91-
92-
return false;
93-
}
9461
}

CommunityToolkit.Mvvm.SourceGenerators/Extensions/IncrementalValuesProviderExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ internal static class IncrementalValuesProviderExtensions
9797
/// <summary>
9898
/// An <see cref="IEqualityComparer{T}"/> implementation for a value tuple.
9999
/// </summary>
100-
public sealed class Comparer<TLeft, TRight> : IEqualityComparer<(TLeft Left, TRight Right)>
100+
private sealed class Comparer<TLeft, TRight> : IEqualityComparer<(TLeft Left, TRight Right)>
101101
{
102102
/// <summary>
103103
/// The <typeparamref name="TLeft"/> comparer.
@@ -140,7 +140,7 @@ public int GetHashCode((TLeft Left, TRight Right) obj)
140140
/// <summary>
141141
/// An <see cref="IEqualityComparer{T}"/> implementation for a value tuple.
142142
/// </summary>
143-
public sealed class Comparer<T1, T2, T3> : IEqualityComparer<(T1, T2, T3)>
143+
private sealed class Comparer<T1, T2, T3> : IEqualityComparer<(T1, T2, T3)>
144144
{
145145
/// <summary>
146146
/// The <typeparamref name="T1"/> comparer.

0 commit comments

Comments
 (0)