|
| 1 | +// Copyright (c) 2024 Files Community |
| 2 | +// Licensed under the MIT License. See the LICENSE. |
| 3 | + |
| 4 | +namespace Files.Core.SourceGenerator |
| 5 | +{ |
| 6 | + /// <summary> |
| 7 | + /// Contains various constants used within the source generator. |
| 8 | + /// </summary> |
| 9 | + internal class Constants |
| 10 | + { |
| 11 | + /// <summary> |
| 12 | + /// Contains diagnostic descriptors used for error reporting. |
| 13 | + /// </summary> |
| 14 | + internal class DiagnosticDescriptors |
| 15 | + { |
| 16 | + /// <summary> |
| 17 | + /// Diagnostic descriptor for unsupported types in Windows Registry. |
| 18 | + /// </summary> |
| 19 | + internal static readonly DiagnosticDescriptor FSG1001 = new( |
| 20 | + id: nameof(FSG1001), |
| 21 | + title: "Types that are not supported by Windows Registry", |
| 22 | + messageFormat: "Type '{0}' is not supported by Windows Registry", |
| 23 | + category: "Design", |
| 24 | + defaultSeverity: DiagnosticSeverity.Error, |
| 25 | + isEnabledByDefault: true); |
| 26 | + |
| 27 | + /// <summary> |
| 28 | + /// Diagnostic descriptor for a refactoring suggestion to replace string literals with constants from the Strings class. |
| 29 | + /// </summary> |
| 30 | + internal static readonly DiagnosticDescriptor FSG1002 = new( |
| 31 | + id: nameof(FSG1002), |
| 32 | + title: "String literal can be replaced with constant", |
| 33 | + messageFormat: $"Replace '{{0}}' with '{StringsPropertyGenerator.StringsClassName}.{{1}}'", |
| 34 | + category: "Refactoring", |
| 35 | + defaultSeverity: DiagnosticSeverity.Warning, |
| 36 | + isEnabledByDefault: true, |
| 37 | + description: $"Detects string literals that can be replaced with constants from the {StringsPropertyGenerator.StringsClassName} class."); |
| 38 | + |
| 39 | + /// <summary> |
| 40 | + /// Diagnostic descriptor for a scenario where multiple files with the same name are detected. |
| 41 | + /// </summary> |
| 42 | + internal static readonly DiagnosticDescriptor FSG1003 = new( |
| 43 | + id: nameof(FSG1003), |
| 44 | + title: "Multiple files with the same name detected", |
| 45 | + messageFormat: "Multiple files named '{0}' were detected. Ensure all generated localization string files have unique names.", |
| 46 | + category: "FileGeneration", |
| 47 | + defaultSeverity: DiagnosticSeverity.Error, |
| 48 | + isEnabledByDefault: true, |
| 49 | + description: "This diagnostic detects cases where multiple localization string files are being generated with the same name," + |
| 50 | + "which can cause conflicts and overwrite issues."); |
| 51 | + |
| 52 | + } |
| 53 | + |
| 54 | + /// <summary> |
| 55 | + /// Contains constants related to DependencyProperty generation. |
| 56 | + /// </summary> |
| 57 | + internal class DependencyPropertyGenerator |
| 58 | + { |
| 59 | + /// <summary> |
| 60 | + /// The name of the attribute used for DependencyProperty. |
| 61 | + /// </summary> |
| 62 | + internal static readonly string AttributeName = "DependencyPropertyAttribute"; |
| 63 | + } |
| 64 | + |
| 65 | + internal class StringsPropertyGenerator |
| 66 | + { |
| 67 | + /// <summary> |
| 68 | + /// The name of the generated class that contains string constants. |
| 69 | + /// </summary> |
| 70 | + internal const string StringsClassName = "Strings"; |
| 71 | + |
| 72 | + /// <summary> |
| 73 | + /// The fully qualified name of the generated metadata class that contains string constants. |
| 74 | + /// </summary> |
| 75 | + internal const string StringsMetadataName = $"{SourceGeneratorHelper.HelperNamespace}{StringsClassName}"; |
| 76 | + |
| 77 | + /// <summary> |
| 78 | + /// The name of the property that represents the name of the constant. |
| 79 | + /// </summary> |
| 80 | + internal const string ConstantNameProperty = nameof(ConstantNameProperty); |
| 81 | + |
| 82 | + /// <summary> |
| 83 | + /// A collection of method names that are considered localized methods. |
| 84 | + /// These methods are used to identify string literals that can be replaced with constants from the Strings class. |
| 85 | + /// </summary> |
| 86 | + internal static HashSet<string> LocalizedMethodNames = [ |
| 87 | + /* TODO: Future use only this */ "ToLocalized", |
| 88 | + /* TODO: Rewrite with ToLocalized */ "GetLocalizedResource", |
| 89 | + /* TODO: Rewrite with ToLocalized */ "GetLocalizedFormatResource"]; |
| 90 | + |
| 91 | + /// <summary> |
| 92 | + /// The title of the code fix provider that suggests replacing string literals with constants from the Strings class. |
| 93 | + /// </summary> |
| 94 | + internal const string CodeFixProviderTitle = $"Replace with constant from {StringsClassName}"; |
| 95 | + |
| 96 | + /// <summary> |
| 97 | + /// Represents a character used as a separator in constant names. |
| 98 | + /// </summary> |
| 99 | + internal const char ConstantSeparator = '/'; |
| 100 | + } |
| 101 | + } |
| 102 | +} |
0 commit comments