Skip to content

Commit

Permalink
修改命名
Browse files Browse the repository at this point in the history
  • Loading branch information
lindexi committed Sep 2, 2023
1 parent a347ab7 commit dde5876
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@ namespace dotnetCampus.Telescope.SourceGeneratorAnalyzers.Core;

static class AssemblySymbolHelper
{
public static IEnumerable<INamedTypeSymbol> GetAllTypeSymbol(IAssemblySymbol assemblySymbol) => GetAllTypeSymbol(assemblySymbol.GlobalNamespace);
/// <summary>
/// 获取当前程序集里面的所有类型
/// </summary>
/// <param name="assemblySymbol"></param>
/// <returns></returns>
public static IEnumerable<INamedTypeSymbol> GetAllTypeSymbols(IAssemblySymbol assemblySymbol) => GetAllTypeSymbols(assemblySymbol.GlobalNamespace);

public static IEnumerable<INamedTypeSymbol> GetAllTypeSymbol(INamespaceSymbol namespaceSymbol)
public static IEnumerable<INamedTypeSymbol> GetAllTypeSymbols(INamespaceSymbol namespaceSymbol)
{
var typeMemberList = namespaceSymbol.GetTypeMembers();

Expand All @@ -19,7 +24,7 @@ public static IEnumerable<INamedTypeSymbol> GetAllTypeSymbol(INamespaceSymbol na

foreach (var namespaceMember in namespaceSymbol.GetNamespaceMembers())
{
foreach (var typeSymbol in GetAllTypeSymbol(namespaceMember))
foreach (var typeSymbol in GetAllTypeSymbols(namespaceMember))
{
yield return typeSymbol;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ static class IncrementalValuesProviderHelper
/// <typeparam name="T"></typeparam>
/// <param name="provider"></param>
/// <returns></returns>
public static IncrementalValuesProvider<T> FilterNull<T>(this IncrementalValuesProvider<T?> provider)
public static IncrementalValuesProvider<T> ExcludeNulls<T>(this IncrementalValuesProvider<T?> provider)
{
return provider.Where(static t => t != null).Select(static (t, _) => t!);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ sealed class TelescopeExportAttribute : global::System.Attribute
/// <summary>
/// 是否包含引用的程序集和 DLL 里面的类型导出。默认只导出当前程序集
/// </summary>
public bool IncludeReference { set; get; }
public bool IncludeReferences { set; get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
var attributeDataNamedArguments = attributeData.NamedArguments;
var includeReference =
attributeDataNamedArguments
.FirstOrDefault(t => t.Key == nameof(TelescopeExportAttribute.IncludeReference)).Value
.FirstOrDefault(t => t.Key == nameof(TelescopeExportAttribute.IncludeReferences)).Value
.Value is true;
return new ExportTypeCollectionResult(methodSymbol, generatorSyntaxContext)
Expand All @@ -91,7 +91,7 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
return null;
})
// 过滤不满足条件的
.FilterNull();
.ExcludeNulls();

// 获取方法返回值导出类型
var exportMethodReturnTypeCollectionResultIncrementalValuesProvider = exportMethodIncrementalValuesProvider.Select(static (exportTypeCollectionResult, token) =>
Expand Down Expand Up @@ -171,7 +171,7 @@ ExportMethodReturnTypeCollectionDiagnostic ReturnTypeError(string messageKey)

// 这是有定义出错的,需要反馈给到开发者的
var diagnosticIncrementalValuesProvider = exportMethodReturnTypeCollectionResultIncrementalValuesProvider.Select(static (t, _) => t as ExportMethodReturnTypeCollectionDiagnostic)
.FilterNull();
.ExcludeNulls();

context.RegisterSourceOutput(diagnosticIncrementalValuesProvider, static (productionContext, diagnostic) =>
{
Expand Down Expand Up @@ -230,7 +230,7 @@ ExportMethodReturnTypeCollectionDiagnostic ReturnTypeError(string messageKey)
// 判断 referencedAssemblySymbol 是否设置 internal 可见
var isInternalsVisibleTo = referencedAssemblySymbol.GivesAccessTo(currentAssembly);
foreach (var assemblyClassTypeSymbol in AssemblySymbolHelper.GetAllTypeSymbol(referencedAssemblySymbol))
foreach (var assemblyClassTypeSymbol in AssemblySymbolHelper.GetAllTypeSymbols(referencedAssemblySymbol))
{
if (!isInternalsVisibleTo &&
assemblyClassTypeSymbol.DeclaredAccessibility != Accessibility.Public)
Expand All @@ -254,7 +254,7 @@ ExportMethodReturnTypeCollectionDiagnostic ReturnTypeError(string messageKey)
// 收集所有的带返回类型,用来进行下一步的收集项目里的所有类型
IncrementalValueProvider<ImmutableArray<ExportMethodReturnTypeCollectionResult>> returnTypeCollectionIncrementalValuesProvider = exportMethodReturnTypeCollectionResultIncrementalValuesProvider
.Select(static (t, _) => t as ExportMethodReturnTypeCollectionResult)
.FilterNull()
.ExcludeNulls()
.Collect();

// 收集整个项目里面所有的类型
Expand All @@ -275,7 +275,7 @@ ExportMethodReturnTypeCollectionDiagnostic ReturnTypeError(string messageKey)
return null;
})
.FilterNull()
.ExcludeNulls()
.Combine(returnTypeCollectionIncrementalValuesProvider)
.Select(static (tuple, token) =>
{
Expand Down Expand Up @@ -303,7 +303,7 @@ ExportMethodReturnTypeCollectionDiagnostic ReturnTypeError(string messageKey)
return null;
}
})
.FilterNull();
.ExcludeNulls();

var collectionResultIncrementalValueProvider = referenceAssemblyTypeIncrementalValueProvider.Combine(candidateClassCollectionResultIncrementalValuesProvider.Collect())
.SelectMany(static (tuple, _) => { return tuple.Right.Add(tuple.Left); })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ static void Main(string[] args)
}
}

[dotnetCampus.Telescope.TelescopeExportAttribute(IncludeReference = true)]
[dotnetCampus.Telescope.TelescopeExportAttribute(IncludeReferences = true)]
private static partial IEnumerable<(Type, F1Attribute xx, Func<DemoLib1.F1> xxx)> ExportFooEnumerable();
}

Expand Down

0 comments on commit dde5876

Please sign in to comment.