private static void Configure(AsyncGenerator configuration, CancellationTokens config, IFluentProjectCancellationTokenConfiguration fluentConfig) { if (config.Guards.HasValue) { fluentConfig.Guards(config.Guards.Value); } if (config.MethodParameter.Any()) { fluentConfig.ParameterGeneration(CreateParameterGenerationFunction(configuration, config.MethodParameter)); } if (config.WithoutCancellationToken.Any() || config.RequiresCancellationToken.Any()) { foreach (ExecutionPhase value in Enum.GetValues(typeof(ExecutionPhase))) { var withoutTokenGroup = config.WithoutCancellationToken.GroupBy(o => o.ExecutionPhase).FirstOrDefault(o => o.Key == value); var requiresTokenGroup = config.RequiresCancellationToken.GroupBy(o => o.ExecutionPhase).FirstOrDefault(o => o.Key == value); if (withoutTokenGroup != null || requiresTokenGroup != null) { fluentConfig.RequiresCancellationToken( CreateMethodNullablePredicate(configuration, withoutTokenGroup?.ToList() ?? new List <MethodFilter>(), requiresTokenGroup?.ToList() ?? new List <MethodFilter>() ), value); } } fluentConfig.RequiresCancellationToken(CreateMethodNullablePredicate(configuration, config.WithoutCancellationToken, config.RequiresCancellationToken)); } }
public virtual void Configure(AsyncGenerator configuration, Solution solution, IFluentSolutionConfiguration solutionConfiguration, Assembly assembly) { if (solution.ApplyChanges.HasValue) { solutionConfiguration.ApplyChanges(solution.ApplyChanges.Value); } if (solution.ConcurrentRun.HasValue) { solutionConfiguration.ConcurrentRun(solution.ConcurrentRun.Value); } if (!string.IsNullOrEmpty(solution.TargetFramework)) { solutionConfiguration.TargetFramework(solution.TargetFramework); } foreach (var item in solution.SuppressDiagnosticFailures) { solutionConfiguration.SuppressDiagnosticFailures(item.Pattern); } // Configure projects foreach (var projectConfig in solution.Projects) { solutionConfiguration.ConfigureProject(projectConfig.Name, o => Configure(configuration, projectConfig, o, assembly)); } }
public virtual void Configure(AsyncGenerator configuration, Project project, IFluentProjectConfiguration projectConfiguration, Assembly assembly) { if (project.ApplyChanges.HasValue) { projectConfiguration.ApplyChanges(project.ApplyChanges.Value); } if (project.ConcurrentRun.HasValue) { projectConfiguration.ConcurrentRun(project.ConcurrentRun.Value); } if (!string.IsNullOrEmpty(project.TargetFramework)) { projectConfiguration.TargetFramework(project.TargetFramework); } foreach (var item in project.SuppressDiagnosticFailures) { projectConfiguration.SuppressDiagnosticFailures(item.Pattern); } projectConfiguration.ConfigureAnalyzation(o => Configure(configuration, project.Analyzation, o)); projectConfiguration.ConfigureTransformation(o => Configure(configuration, project.Transformation, o)); if (!project.RegisterPlugin.Any()) { return; } var assemblies = AppDomain.CurrentDomain.GetAssemblies() .Where(o => !o.IsDynamic) .Distinct() .GroupBy(o => o.GetName().Name) // there may be multiple versions of the same assembly .ToDictionary(o => o.Key, o => o.First()); foreach (var plugin in project.RegisterPlugin) { if (!string.IsNullOrEmpty(plugin.AssemblyName) && !assemblies.ContainsKey(plugin.AssemblyName)) { assemblies[plugin.AssemblyName] = Assembly.Load(plugin.AssemblyName); } if (string.IsNullOrEmpty(plugin.AssemblyName) && assembly == null) { throw new InvalidOperationException($"Assembly name must be provided for type {plugin.Type}."); } var type = string.IsNullOrEmpty(plugin.AssemblyName) ? assembly.GetExportedTypes().FirstOrDefault(o => o.Name == plugin.Type) : assemblies[plugin.AssemblyName].GetExportedTypes().FirstOrDefault(o => o.FullName == plugin.Type); if (type == null) { throw new InvalidOperationException($"Type {plugin.Type} was not found inside assembly {plugin.AssemblyName}. Hint: Make sure that the type is public."); } var pluginInstance = Activator.CreateInstance(type) as IPlugin; if (pluginInstance == null) { throw new InvalidOperationException($"Type {plugin.Type} from assembly {plugin.AssemblyName} does not implement IPlugin interaface"); } projectConfiguration.RegisterPlugin(pluginInstance); } }
private static void Configure(AsyncGenerator configuration, Analyzation config, IFluentProjectAnalyzeConfiguration fluentConfig) { if (config.CallForwarding.HasValue) { fluentConfig.CallForwarding(config.CallForwarding.Value); } if (config.PropertyConversion.HasValue) { fluentConfig.PropertyConversion(config.PropertyConversion.Value); } if (config.ScanMethodBody.HasValue) { fluentConfig.ScanMethodBody(config.ScanMethodBody.Value); } if (config.ScanForMissingAsyncMembers.Any()) { fluentConfig.ScanForMissingAsyncMembers(CreateTypePredicate(configuration, config.ScanForMissingAsyncMembers)); } if (config.CancellationTokens.IsEnabled) { fluentConfig.CancellationTokens(o => Configure(configuration, config.CancellationTokens, o)); } fluentConfig.AsyncExtensionMethods(o => Configure(config.AsyncExtensionMethods, o)); fluentConfig.Diagnostics(o => Configure(configuration, config.Diagnostics, o)); fluentConfig.ExceptionHandling(o => Configure(configuration, config.ExceptionHandling, o)); if (config.IgnoreDocuments.Any()) { fluentConfig.DocumentSelection(CreateDocumentPredicate(config.IgnoreDocuments, false)); } if (config.MethodConversion.Any()) { fluentConfig.MethodConversion(CreateMethodConversionFunction(configuration, config.MethodConversion)); } if (config.PreserveReturnType.Any()) { fluentConfig.PreserveReturnType(CreateMethodPredicate(configuration, config.PreserveReturnType, true)); } if (config.AlwaysAwait.Any()) { fluentConfig.AlwaysAwait(CreateMethodPredicate(configuration, config.AlwaysAwait, true)); } if (config.IgnoreSearchForAsyncCounterparts.Any()) { fluentConfig.SearchForAsyncCounterparts(CreateMethodPredicate(configuration, config.IgnoreSearchForAsyncCounterparts, false)); } if (config.IgnoreAsyncCounterparts.Any()) { fluentConfig.IgnoreAsyncCounterparts(CreateMethodPredicate(configuration, config.IgnoreAsyncCounterparts, true)); } if (config.IgnoreSearchForMethodReferences.Any()) { fluentConfig.SearchForMethodReferences(CreateMethodPredicate(configuration, config.IgnoreSearchForMethodReferences, false)); } if (config.TypeConversion.Any()) { fluentConfig.TypeConversion(CreateTypeConversionFunction(configuration, config.TypeConversion)); } }
private static void Configure(AsyncGenerator configuration, ExceptionHandling config, IFluentProjectExceptionHandlingConfiguration fluentConfig) { if (config.CatchPropertyGetterCalls.Any()) { fluentConfig.CatchPropertyGetterCalls(CreateMethodPredicateFunction(configuration, config.CatchPropertyGetterCalls, false)); } if (config.CatchMethodBody.Any()) { fluentConfig.CatchMethodBody(CreateMethodNullablePredicate(configuration, config.CatchMethodBody)); } }
private static Predicate <IMethodSymbol> CreateMethodPredicateFunction(AsyncGenerator globalConfig, IList <MethodPredicateFilter> filters, bool defaultResult) { var rules = globalConfig.MethodRules.ToDictionary(o => o.Name, o => o.Filters); return(symbol => { foreach (var filter in filters) { if (CanApply(symbol, filter, rules)) { return filter.Result; } } return defaultResult; // Default value }); }
private static Predicate <INamedTypeSymbol> CreateTypePredicate(AsyncGenerator globalConfig, IList <TypeFilter> filters) { var rules = globalConfig.TypeRules.ToDictionary(o => o.Name, o => o.Filters); return(symbol => { foreach (var filter in filters) { if (CanApply(symbol, filter, rules)) { return true; } } return false; }); }
private static Predicate <IMethodSymbol> CreateMethodPredicate(AsyncGenerator globalConfig, IList <MethodFilter> filters, bool validValue) { var rules = globalConfig.MethodRules.ToDictionary(o => o.Name, o => o.Filters); return(symbol => { foreach (var filter in filters) { if (CanApply(symbol, filter, rules)) { return validValue; } } return !validValue; }); }
private static Func <IMethodSymbol, string> CreateMethodContentFunction(AsyncGenerator globalConfig, List <MethodContentFilter> filters) { var rules = globalConfig.MethodRules.ToDictionary(o => o.Name, o => o.Filters); return(symbol => { foreach (var filter in filters) { if (CanApply(symbol, filter, rules)) { return filter.Content; } } return null; }); }
private static Func <IMethodSymbol, bool?> CreateMethodNullablePredicate(AsyncGenerator globalConfig, IList <MethodPredicateFilter> filters) { var rules = globalConfig.MethodRules.ToDictionary(o => o.Name, o => o.Filters); return(symbol => { foreach (var filter in filters) { if (CanApply(symbol, filter, rules)) { return filter.Result; } } return null; }); }
private static void Configure(AsyncGenerator configuration, CancellationTokens config, IFluentProjectCancellationTokenConfiguration fluentConfig) { if (config.Guards.HasValue) { fluentConfig.Guards(config.Guards.Value); } if (config.MethodParameter.Any()) { fluentConfig.ParameterGeneration(CreateParameterGenerationFunction(configuration, config.MethodParameter)); } if (config.WithoutCancellationToken.Any() || config.RequiresCancellationToken.Any()) { fluentConfig.RequiresCancellationToken(CreateMethodNullablePredicate(configuration, config.WithoutCancellationToken, config.RequiresCancellationToken)); } }
private static void Configure(AsyncGenerator configuration, Diagnostics config, IFluentProjectDiagnosticsConfiguration fluentConfig) { if (config.Disable == true) { fluentConfig.Disable(); } if (config.DiagnoseDocument.Any()) { fluentConfig.DiagnoseDocument(CreateDocumentPredicateFunction(config.DiagnoseDocument, true)); } if (config.DiagnoseType.Any()) { fluentConfig.DiagnoseType(CreateTypePredicateFunction(configuration, config.DiagnoseType, true)); } if (config.DiagnoseMethod.Any()) { fluentConfig.DiagnoseMethod(CreateMethodPredicateFunction(configuration, config.DiagnoseMethod, true)); } }
private static void Configure(AsyncGenerator configuration, DocumentationComments config, IFluentProjectDocumentationCommentConfiguration fluentConfig) { if (config.AddOrReplacePartialTypeComments.Any()) { fluentConfig.AddOrReplacePartialTypeComments(CreateTypeContentFunction(configuration, config.AddOrReplacePartialTypeComments)); } if (config.RemovePartialTypeComments.Any()) { fluentConfig.RemovePartialTypeComments(CreateTypePredicate(configuration, config.RemovePartialTypeComments)); } if (config.AddOrReplaceNewTypeComments.Any()) { fluentConfig.AddOrReplaceNewTypeComments(CreateTypeContentFunction(configuration, config.AddOrReplaceNewTypeComments)); } if (config.RemoveNewTypeComments.Any()) { fluentConfig.RemoveNewTypeComments(CreateTypePredicate(configuration, config.RemoveNewTypeComments)); } if (config.AddOrReplaceMethodRemarks.Any()) { fluentConfig.AddOrReplaceMethodRemarks(CreateMethodContentFunction(configuration, config.AddOrReplaceMethodRemarks)); } if (config.RemoveMethodRemarks.Any()) { fluentConfig.RemoveMethodRemarks(CreateMethodPredicate(configuration, config.RemoveMethodRemarks, true)); } if (config.AddOrReplaceMethodSummary.Any()) { fluentConfig.AddOrReplaceMethodSummary(CreateMethodContentFunction(configuration, config.AddOrReplaceMethodSummary)); } if (config.RemoveMethodSummary.Any()) { fluentConfig.RemoveMethodSummary(CreateMethodPredicate(configuration, config.RemoveMethodSummary, true)); } }
private static void Configure(AsyncGenerator configuration, Transformation config, IFluentProjectTransformConfiguration fluentConfig) { if (config.LocalFunctions.HasValue) { fluentConfig.LocalFunctions(config.LocalFunctions.Value); } if (!string.IsNullOrEmpty(config.AsyncFolder)) { fluentConfig.AsyncFolder(config.AsyncFolder); } if (config.ConfigureAwaitArgument.HasValue) { fluentConfig.ConfigureAwaitArgument(config.ConfigureAwaitArgument.Value); } if (config.Disable == true) { fluentConfig.Disable(); } if (!string.IsNullOrEmpty(config.AsyncLock.Type)) { fluentConfig.AsyncLock(config.AsyncLock.Type, config.AsyncLock.MethodName); } fluentConfig.DocumentationComments(o => Configure(configuration, config.DocumentationComments, o)); }
private static Func <IMethodSymbol, MethodConversion> CreateMethodConversionFunction(AsyncGenerator globalConfig, IList <MethodConversionFilter> filters) { var rules = globalConfig.MethodRules.ToDictionary(o => o.Name, o => o.Filters); return(symbol => { foreach (var filter in filters) { if (CanApply(symbol, filter, rules)) { return filter.Conversion; } } return MethodConversion.Unknown; // Default value }); }
private static Func <INamedTypeSymbol, TypeConversion> CreateTypeConversionFunction(AsyncGenerator globalConfig, IList <TypeConversionFilter> filters) { var rules = globalConfig.TypeRules.ToDictionary(o => o.Name, o => o.Filters); return(symbol => { foreach (var filter in filters) { if (CanApply(symbol, filter, rules)) { return filter.Conversion; } } return TypeConversion.Unknown; }); }
private static Func <IMethodSymbolInfo, MethodCancellationToken> CreateParameterGenerationFunction(AsyncGenerator globalConfig, IList <MethodCancellationTokenFilter> filters) { var rules = globalConfig.MethodRules.ToDictionary(o => o.Name, o => o.Filters); return(symbol => { foreach (var filter in filters) { if (!string.IsNullOrEmpty(filter.AnyInterfaceRule) && !symbol.ImplementedInterfaces.Any(i => rules[filter.AnyInterfaceRule].Any(o => CanApply(i, o, rules)))) { continue; } if (CanApply(symbol.Symbol, filter, rules)) { return filter.Parameter; } } return MethodCancellationToken.Optional; }); }