From b7cb4ef1f7d799b21e1df3e486f8155d6c00d3dc Mon Sep 17 00:00:00 2001 From: Josef Pihrt Date: Thu, 23 Nov 2023 03:11:27 +0100 Subject: [PATCH] Remove unused symbols (#80) --- .../EnvironmentKind.cs | 1 - .../IO/IOUtility.cs | 100 ------------------ .../IO/Utf8StringWriter.cs | 14 --- .../KeywordDefinition.cs | 29 ----- .../KnownNames.cs | 5 - .../KnownTags.cs | 9 -- .../LiteralIdentifiers.cs | 2 - .../ModifierDefinition.cs | 14 --- .../ShortcutInfo.cs | 27 ----- .../SnippetDirectory.cs | 22 ---- .../SnippetExtensions.cs | 92 ---------------- .../StringExtensions.cs | 41 ------- .../Validations/RegexHelper.cs | 4 - .../Validations/Validator.cs | 11 -- .../Xml/XElementExtensions.cs | 21 ---- .../CodeGenerationUtility.cs | 39 ------- .../Commands/BasicTypeCommand.cs | 3 +- .../Commands/CommandKind.cs | 1 - .../Commands/TypeCommand.cs | 1 - .../Commands/XamlPropertyCommand.cs | 30 ------ .../DirectoryReadmeSettings.cs | 29 ----- .../ProjectReadmeSettings.cs | 18 ---- .../SnippetCodeBuilder.cs | 5 - .../SnippetEnvironment.cs | 31 ------ .../SnippetGeneratorResult.cs | 7 -- .../VisualStudio/ProjectDocument.cs | 1 - .../XmlSnippetGenerator.cs | 1 - .../Comparers/NamespaceComparer.cs | 2 - .../Serialization/SerializationContext.cs | 2 - .../Serialization/SnippetMapper.cs | 1 - src/Snippetica.VisualStudio/Snippet.cs | 1 - .../SnippetExtensions.cs | 2 +- 32 files changed, 2 insertions(+), 564 deletions(-) delete mode 100644 src/Snippetica.CodeGeneration.Common/IO/Utf8StringWriter.cs delete mode 100644 src/Snippetica.CodeGeneration.Common/StringExtensions.cs delete mode 100644 src/Snippetica.CodeGeneration/CodeGenerationUtility.cs delete mode 100644 src/Snippetica.CodeGeneration/Commands/XamlPropertyCommand.cs delete mode 100644 src/Snippetica.CodeGeneration/DirectoryReadmeSettings.cs delete mode 100644 src/Snippetica.CodeGeneration/ProjectReadmeSettings.cs diff --git a/src/Snippetica.CodeGeneration.Common/EnvironmentKind.cs b/src/Snippetica.CodeGeneration.Common/EnvironmentKind.cs index 114a63c9..16fa7f32 100644 --- a/src/Snippetica.CodeGeneration.Common/EnvironmentKind.cs +++ b/src/Snippetica.CodeGeneration.Common/EnvironmentKind.cs @@ -4,7 +4,6 @@ namespace Snippetica; public enum EnvironmentKind { - None, VisualStudio, VisualStudioCode, } diff --git a/src/Snippetica.CodeGeneration.Common/IO/IOUtility.cs b/src/Snippetica.CodeGeneration.Common/IO/IOUtility.cs index 17cfb402..51eeda46 100644 --- a/src/Snippetica.CodeGeneration.Common/IO/IOUtility.cs +++ b/src/Snippetica.CodeGeneration.Common/IO/IOUtility.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; using System.IO; -using System.Linq; using System.Text; using Snippetica.VisualStudio; @@ -85,55 +84,6 @@ private static SaveOptions CreateSaveSettings() }; } - public static void SaveSnippetsToSingleFile( - IEnumerable snippets, - string filePath, - bool onlyIfChanged = true) - { - if (snippets is null) - throw new ArgumentNullException(nameof(snippets)); - - SaveOptions settings = CreateSaveSettings(); - - string content = SnippetSerializer.CreateXml(snippets, settings); - - if (!ShouldSave(filePath, content, Encoding.UTF8, onlyIfChanged)) - return; - - using (var fileStream = new FileStream(filePath, FileMode.Create)) - { - Console.WriteLine($"saving file {filePath}"); - SnippetSerializer.Serialize(fileStream, snippets, settings); - } - } - - public static void SaveSnippetBrowserFile(IEnumerable snippets, string filePath) - { - snippets = snippets - .Where(f => !f.HasTag(KnownTags.ExcludeFromSnippetBrowser)) - .Select(snippet => - { - snippet = (Snippet)snippet.Clone(); - - string submenuShortcut = snippet.GetShortcutFromTitle(); - - snippet.RemoveShortcutFromTitle(); - - snippet.RemoveMetaKeywords(); - - snippet.Keywords.Add($"{KnownTags.MetaPrefix}Name {snippet.GetFileNameWithoutExtension()}"); - - if (!string.IsNullOrEmpty(submenuShortcut)) - snippet.Keywords.Add($"{KnownTags.MetaPrefix}SubmenuShortcut {submenuShortcut}"); - - return snippet; - }) - .OrderBy(f => f.Language.ToString()) - .ThenBy(f => f.GetFileNameWithoutExtension()); - - SaveSnippetsToSingleFile(snippets, filePath); - } - public static void WriteAllText( string filePath, string content, @@ -167,59 +117,9 @@ private static bool ShouldSave(string filePath, string content, Encoding encodin return !string.Equals(content, content2, StringComparison.Ordinal); } - public static void CleanOrCreateDirectory(string directoryPath) - { - if (Directory.Exists(directoryPath)) - { - CleanDirectory(directoryPath); - } - else - { - CreateDirectory(directoryPath); - } - } - - private static void CleanDirectory(string directoryPath) - { - DeleteDirectories(directoryPath); - DeleteFiles(directoryPath); - } - - private static void DeleteFiles(string directoryPath) - { - foreach (string path in Directory.EnumerateFiles(directoryPath)) - DeleteFile(path); - } - - private static void DeleteDirectories(string directoryPath) - { - foreach (string path in Directory.EnumerateDirectories(directoryPath)) - DeleteDirectory(path); - } - public static void DeleteFile(string path) { Console.WriteLine($"deleting file {path}"); File.Delete(path); } - - private static void DeleteDirectory(string path) - { - Console.WriteLine($"deleting directory {path}"); - Directory.Delete(path); - } - - public static void DeleteAndCreateDirectory(string directoryPath) - { - if (Directory.Exists(directoryPath)) - DeleteDirectory(directoryPath); - - CreateDirectory(directoryPath); - } - - private static void CreateDirectory(string directoryPath) - { - Console.WriteLine($"creating directory {directoryPath}"); - Directory.CreateDirectory(directoryPath); - } } diff --git a/src/Snippetica.CodeGeneration.Common/IO/Utf8StringWriter.cs b/src/Snippetica.CodeGeneration.Common/IO/Utf8StringWriter.cs deleted file mode 100644 index 26556951..00000000 --- a/src/Snippetica.CodeGeneration.Common/IO/Utf8StringWriter.cs +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright (c) Josef Pihrt. All rights reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.IO; -using System.Text; - -namespace Snippetica.IO; - -public class Utf8StringWriter : StringWriter -{ - public override Encoding Encoding - { - get { return Encoding.UTF8; } - } -} diff --git a/src/Snippetica.CodeGeneration.Common/KeywordDefinition.cs b/src/Snippetica.CodeGeneration.Common/KeywordDefinition.cs index 2c9213ad..6246d1c8 100644 --- a/src/Snippetica.CodeGeneration.Common/KeywordDefinition.cs +++ b/src/Snippetica.CodeGeneration.Common/KeywordDefinition.cs @@ -1,7 +1,6 @@ // Copyright (c) Josef Pihrt. All rights reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Collections.Generic; using System.Diagnostics; using Snippetica.VisualStudio; @@ -12,42 +11,14 @@ public class KeywordDefinition { private static readonly Version _formatVersion = new(1, 1, 0); - public static KeywordDefinition Default { get; } = new(null, null, null, null, false, Array.Empty()); - - public KeywordDefinition( - string name, - string value, - string title, - string shortcut, - bool isDevelopment, - string[] tags) - { - Name = name; - Value = value; - Title = title; - Shortcut = shortcut; - IsDevelopment = isDevelopment; - Tags = new List(tags); - } - - public KeywordDefinition() - { - } - public string Name { get; init; } public string Value { get; init; } - public string Title { get; init; } - public string Shortcut { get; init; } public bool IsDevelopment { get; init; } - public List Tags { get; init; } - - public bool HasTag(string tag) => Tags.Contains(tag); - public Snippet ToSnippet() { string title = $"{Value} keyword"; diff --git a/src/Snippetica.CodeGeneration.Common/KnownNames.cs b/src/Snippetica.CodeGeneration.Common/KnownNames.cs index 66477efe..a8f61efe 100644 --- a/src/Snippetica.CodeGeneration.Common/KnownNames.cs +++ b/src/Snippetica.CodeGeneration.Common/KnownNames.cs @@ -4,11 +4,6 @@ namespace Snippetica; public static class KnownNames { - public const string ProductName = "Snippetica"; - public const string ChangeLogFileName = "ChangeLog.md"; - public const string SourceDirectoryName = "src"; - public const string VisualStudioExtensionProjectName = ProductName + ".VisualStudio"; - public const string VisualStudioCodeExtensionProjectName = ProductName + ".VisualStudioCode"; public const string AutoGeneration = "AutoGeneration"; public const string Dev = "Dev"; public const string DevSuffix = "." + Dev; diff --git a/src/Snippetica.CodeGeneration.Common/KnownTags.cs b/src/Snippetica.CodeGeneration.Common/KnownTags.cs index 913aa45a..cf5f6fb2 100644 --- a/src/Snippetica.CodeGeneration.Common/KnownTags.cs +++ b/src/Snippetica.CodeGeneration.Common/KnownTags.cs @@ -12,7 +12,6 @@ public static class KnownTags public const string BasicType = nameof(BasicType); public const string Collection = nameof(Collection); public const string Default = nameof(Default); - public const string Disabled = nameof(Disabled); public const string Environment = nameof(Environment); public const string ExcludeFromDocs = nameof(ExcludeFromDocs); public const string ExcludeFromSnippetBrowser = nameof(ExcludeFromSnippetBrowser); @@ -20,26 +19,19 @@ public static class KnownTags public const string ExcludeFromVisualStudioCode = nameof(ExcludeFromVisualStudioCode); public const string GenerateXmlSnippets = nameof(GenerateXmlSnippets); public const string Initializer = nameof(Initializer); - public const string Language = nameof(Language); public const string NonUniqueShortcut = nameof(NonUniqueShortcut); public const string NonUniqueTitle = nameof(NonUniqueTitle); - public const string NoQuickReference = nameof(NoQuickReference); public const string ObsoleteShortcut = nameof(ObsoleteShortcut); public const string ShortcutSuffix = nameof(ShortcutSuffix); public const string TitleEndsWithUnderscore = nameof(TitleEndsWithUnderscore); public const string TitleStartsWithShortcut = nameof(TitleStartsWithShortcut); public const string TryParse = nameof(TryParse); public const string Variable = nameof(Variable); - public const string VisualStudio = nameof(VisualStudio); public const string MetaPrefix = "Meta-"; public const string GeneratePrefix = "Generate"; public const string GenerateAccessModifier = GeneratePrefix + "AccessModifier"; - public const string GeneratePublicModifier = GeneratePrefix + "PublicModifier"; - public const string GenerateInternalModifier = GeneratePrefix + "InternalModifier"; - public const string GeneratePrivateModifier = GeneratePrefix + "PrivateModifier"; - public const string GenerateProtectedModifier = GeneratePrefix + "ProtectedModifier"; public const string GenerateStaticModifier = GeneratePrefix + "StaticModifier"; public const string GenerateVirtualModifier = GeneratePrefix + "VirtualModifier"; @@ -48,7 +40,6 @@ public static class KnownTags public const string GenerateConstModifier = GeneratePrefix + "ConstModifier"; public const string GenerateConstExprModifier = GeneratePrefix + "ConstExprModifier"; public const string GenerateInitializer = GeneratePrefix + "Initializer"; - public const string GenerateXamlProperty = GeneratePrefix + "XamlProperty"; public const string GenerateType = GeneratePrefix + "Type"; public const string GenerateAlternativeShortcut = GeneratePrefix + "AlternativeShortcut"; public const string GenerateDeclarationAndDefinition = GeneratePrefix + "DeclarationAndDefinition"; diff --git a/src/Snippetica.CodeGeneration.Common/LiteralIdentifiers.cs b/src/Snippetica.CodeGeneration.Common/LiteralIdentifiers.cs index 8455d05d..4f4a8ecc 100644 --- a/src/Snippetica.CodeGeneration.Common/LiteralIdentifiers.cs +++ b/src/Snippetica.CodeGeneration.Common/LiteralIdentifiers.cs @@ -10,8 +10,6 @@ public static class LiteralIdentifiers public const string Identifier = "_identifier"; public const string Initializer = "_initializer"; public const string Modifiers = "_modifiers"; - public const string ParameterList = "_parameterList"; - public const string Semicolon = "_semicolon"; public const string SubOrFunction = "_subOrFunction"; public const string Type = "_type"; public const string TypeParameterList = "_typeParameterList"; diff --git a/src/Snippetica.CodeGeneration.Common/ModifierDefinition.cs b/src/Snippetica.CodeGeneration.Common/ModifierDefinition.cs index 1d6d1525..fa3de308 100644 --- a/src/Snippetica.CodeGeneration.Common/ModifierDefinition.cs +++ b/src/Snippetica.CodeGeneration.Common/ModifierDefinition.cs @@ -1,25 +1,11 @@ // Copyright (c) Josef Pihrt. All rights reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; using System.Collections.Generic; namespace Snippetica; public class ModifierDefinition { - public ModifierDefinition(string name, string keyword, string shortcut, string[] tags) - { - Name = name; - Keyword = keyword; - Shortcut = shortcut; - Tags = new List(tags); - Kind = (ModifierKind)Enum.Parse(typeof(ModifierKind), Name); - } - - public ModifierDefinition() - { - } - public string Name { get; init; } public string Keyword { get; init; } public string Shortcut { get; init; } diff --git a/src/Snippetica.CodeGeneration.Common/ShortcutInfo.cs b/src/Snippetica.CodeGeneration.Common/ShortcutInfo.cs index 1cb459bb..5f586a3f 100644 --- a/src/Snippetica.CodeGeneration.Common/ShortcutInfo.cs +++ b/src/Snippetica.CodeGeneration.Common/ShortcutInfo.cs @@ -1,35 +1,12 @@ // Copyright (c) Josef Pihrt. All rights reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; -using System.Linq; using Snippetica.VisualStudio; namespace Snippetica; public class ShortcutInfo { - public ShortcutInfo( - string value, - string description, - string comment, - ShortcutKind kind, - IEnumerable languages, - IEnumerable environments, - IEnumerable tags) - { - Value = value; - Description = description; - Comment = comment; - Kind = kind; - Environments = new List(environments.ToArray()); - Languages = new List(languages.ToArray()); - Tags = new List(tags.ToArray()); - } - - public ShortcutInfo() - { - } - public string Value { get; set; } public string Description { get; set; } @@ -41,8 +18,4 @@ public ShortcutInfo() public List Languages { get; set; } public List Environments { get; set; } - - public List Tags { get; set; } - - public bool HasTag(string value) => Tags.Contains(value); } diff --git a/src/Snippetica.CodeGeneration.Common/SnippetDirectory.cs b/src/Snippetica.CodeGeneration.Common/SnippetDirectory.cs index a1d5ec9b..74c4dc1f 100644 --- a/src/Snippetica.CodeGeneration.Common/SnippetDirectory.cs +++ b/src/Snippetica.CodeGeneration.Common/SnippetDirectory.cs @@ -27,28 +27,6 @@ public SnippetDirectory WithPath(string path) public bool HasTag(string tag) => Tags.Any(f => f.Equals(tag, StringComparison.Ordinal)); - public bool HasTags(params string[] tags) - { - foreach (string tag in tags) - { - if (!HasTag(tag)) - return false; - } - - return true; - } - - public bool HasAnyTag(params string[] tags) - { - foreach (string tag in tags) - { - if (HasTag(tag)) - return true; - } - - return false; - } - [DebuggerBrowsable(DebuggerBrowsableState.Never)] private string DebuggerDisplay { diff --git a/src/Snippetica.CodeGeneration.Common/SnippetExtensions.cs b/src/Snippetica.CodeGeneration.Common/SnippetExtensions.cs index 6d6b2b39..a6aa759f 100644 --- a/src/Snippetica.CodeGeneration.Common/SnippetExtensions.cs +++ b/src/Snippetica.CodeGeneration.Common/SnippetExtensions.cs @@ -23,31 +23,6 @@ public static void SetFilePath(this Snippet snippet, string filePath) snippet.Properties["FilePath"] = filePath; } - public static string GetShortcutFromTitle(this Snippet snippet) - { - if (!snippet.HasTag(KnownTags.TitleStartsWithShortcut)) - return null; - - string s = snippet.Title; - - int i = 0; - - while (i < s.Length - && s[i] != ' ') - { - i++; - } - - return s.Substring(0, i); - } - - public static Snippet RemoveShortcutFromTitle(this Snippet snippet) - { - snippet.Title = snippet.GetTitle(trimLeadingShortcut: true, trimTrailingUnderscore: false); - - return snippet; - } - public static string GetTitle( this Snippet snippet, bool trimLeadingShortcut = true, @@ -94,17 +69,6 @@ public static string GetTitle( return s.Substring(i, j - i + 1); } - public static void RemoveMetaKeywords(this Snippet snippet) - { - List keywords = snippet.Keywords; - - for (int i = keywords.Count - 1; i >= 0; i--) - { - if (keywords[i].StartsWith(KnownTags.MetaPrefix)) - keywords.RemoveAt(i); - } - } - public static string GetFileName(this Snippet snippet) { return Path.GetFileName(snippet.GetFilePath()); @@ -324,62 +288,12 @@ public static void SetFileName(this Snippet snippet, string fileName) snippet.SetFilePath(Path.Combine(Path.GetDirectoryName(snippet.GetFilePath()), fileName)); } - public static bool ContainsKeyword(this Snippet snippet, string keyword) - { - return snippet.Keywords.Contains(keyword); - } - - public static bool ContainsAnyKeyword(this Snippet snippet, params string[] keywords) - { - foreach (string keyword in keywords) - { - if (snippet.ContainsKeyword(keyword)) - return true; - } - - return false; - } - - public static bool ContainsAnyKeyword(this Snippet snippet, IEnumerable keywords) - { - foreach (string keyword in keywords) - { - if (snippet.ContainsKeyword(keyword)) - return true; - } - - return false; - } - - public static void RemoveKeywords(this Snippet snippet, IEnumerable keywords) - { - foreach (string keyword in keywords) - snippet.Keywords.Remove(keyword); - } - - public static void RemoveKeywords(this Snippet snippet, params string[] keywords) - { - foreach (string keyword in keywords) - snippet.Keywords.Remove(keyword); - } - - public static bool RemoveKeyword(this Snippet snippet, string keyword) - { - return snippet.Keywords.Remove(keyword); - } - public static void AddKeyword(this Snippet snippet, string keyword) { if (!snippet.Keywords.Contains(keyword)) snippet.Keywords.Add(keyword); } - public static void AddKeywords(this Snippet snippet, params string[] keywords) - { - foreach (string keyword in keywords) - AddKeyword(snippet, keyword); - } - public static bool RemoveLiteral(this Snippet snippet, string identifier) { return snippet.Literals.Remove(identifier); @@ -407,12 +321,6 @@ public static void RemoveLiteralAndPlaceholders(this Snippet snippet, string ide snippet.ReplacePlaceholders(literal.Identifier, ""); } - public static void RemoveLiterals(this Snippet snippet, params string[] identifiers) - { - foreach (string identifier in identifiers) - RemoveLiteral(snippet, identifier); - } - public static void ReplacePlaceholders(this Snippet snippet, string identifier, string replacement) { string s = snippet.CodeText; diff --git a/src/Snippetica.CodeGeneration.Common/StringExtensions.cs b/src/Snippetica.CodeGeneration.Common/StringExtensions.cs deleted file mode 100644 index d929d37d..00000000 --- a/src/Snippetica.CodeGeneration.Common/StringExtensions.cs +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright (c) Josef Pihrt. All rights reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; - -namespace Snippetica; - -public static class StringExtensions -{ - public static string Enclose(this string value, string enclosingValue) - { - if (value is null) - throw new ArgumentNullException(nameof(value)); - - if (enclosingValue is null) - throw new ArgumentNullException(nameof(enclosingValue)); - - return enclosingValue + value + enclosingValue; - } - - public static string FirstCharToLowerInvariant(this string value) - { - if (value is null) - throw new ArgumentNullException(nameof(value)); - - if (value.Length == 0) - return value; - - return char.ToLowerInvariant(value[0]) + value.Substring(1); - } - - public static string FirstCharToUpperInvariant(this string value) - { - if (value is null) - throw new ArgumentNullException(nameof(value)); - - if (value.Length == 0) - return value; - - return char.ToUpperInvariant(value[0]) + value.Substring(1); - } -} diff --git a/src/Snippetica.CodeGeneration.Common/Validations/RegexHelper.cs b/src/Snippetica.CodeGeneration.Common/Validations/RegexHelper.cs index 6c73b9ba..f1aaf181 100644 --- a/src/Snippetica.CodeGeneration.Common/Validations/RegexHelper.cs +++ b/src/Snippetica.CodeGeneration.Common/Validations/RegexHelper.cs @@ -6,10 +6,6 @@ namespace Snippetica.Validations; public static class RegexHelper { - public static readonly Regex InvalidLeadingSpacesPattern = new(@"(?m:^)(?:\ {2})+\ (?:[^ ]|\z)[^\r\n]*"); - - public static readonly Regex TrimEndPattern = new(@"\ +(?=(?:\r?\n)|\z)"); - public static readonly Regex InvalidLeadingSpaces = new(@"(?m:^)(?:\ {2})+\ (?:[^ ]|\z)[^\r\n]*"); public static readonly Regex TrimEnd = new(@"\ +(?=(?:\r?\n)|\z)"); diff --git a/src/Snippetica.CodeGeneration.Common/Validations/Validator.cs b/src/Snippetica.CodeGeneration.Common/Validations/Validator.cs index 874efa88..9085df3f 100644 --- a/src/Snippetica.CodeGeneration.Common/Validations/Validator.cs +++ b/src/Snippetica.CodeGeneration.Common/Validations/Validator.cs @@ -2,7 +2,6 @@ using System; using System.Collections.Generic; -using System.IO; using System.Linq; using Snippetica.VisualStudio; using Snippetica.VisualStudio.Validations; @@ -51,14 +50,4 @@ public static void ThrowOnDuplicateFileName(IEnumerable snippets) if (duplicate is not null) throw new InvalidOperationException($"Multiple snippets with same file name '{duplicate.Key}'"); } - - public static void ThrowOnDuplicateShortcut(IEnumerable snippets) - { - IGrouping duplicate = snippets - .GroupBy(f => f.Shortcut) - .FirstOrDefault(f => f.CountExceeds(1)); - - if (duplicate is not null) - throw new InvalidOperationException($"Multiple snippets with same shortcut '{duplicate.Key}'"); - } } diff --git a/src/Snippetica.CodeGeneration.Common/Xml/XElementExtensions.cs b/src/Snippetica.CodeGeneration.Common/Xml/XElementExtensions.cs index e9be5361..adcdc234 100644 --- a/src/Snippetica.CodeGeneration.Common/Xml/XElementExtensions.cs +++ b/src/Snippetica.CodeGeneration.Common/Xml/XElementExtensions.cs @@ -1,6 +1,5 @@ // Copyright (c) Josef Pihrt. All rights reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; using System.Xml.Linq; namespace Snippetica.Xml; @@ -11,24 +10,4 @@ public static string LocalName(this XElement element) { return element.Name.LocalName; } - - public static string AttributeValue(this XElement element, string attributeName) - { - return element.Attribute(attributeName).Value; - } - - public static string AttributeValueOrDefault(this XElement element, string attributeName) - { - return element.Attribute(attributeName)?.Value; - } - - public static TEnum AttributeValueAsEnumOrDefault(this XElement element, string attributeName, TEnum defaultValue) where TEnum : struct - { - string s = AttributeValueOrDefault(element, attributeName); - - if (s is not null) - return (TEnum)Enum.Parse(typeof(TEnum), s); - - return defaultValue; - } } diff --git a/src/Snippetica.CodeGeneration/CodeGenerationUtility.cs b/src/Snippetica.CodeGeneration/CodeGenerationUtility.cs deleted file mode 100644 index d253fe1f..00000000 --- a/src/Snippetica.CodeGeneration/CodeGenerationUtility.cs +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright (c) Josef Pihrt. All rights reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.Collections.Generic; -using System.Linq; -using Snippetica.VisualStudio; - -namespace Snippetica.CodeGeneration; - -public static class CodeGenerationUtility -{ - public static string GetProjectSubtitle(IEnumerable results) - { - IEnumerable languages = results.Select(f => f.Language).Distinct(); - - return GetProjectSubtitle(languages); - } - - public static string GetProjectSubtitle(IEnumerable languages) - { - return $"A collection of snippets for {GetLanguagesSeparatedWithComma(languages)}."; - } - - private static string GetLanguagesSeparatedWithComma(IEnumerable languages) - { - string[] titles = languages - .Select(f => f.GetTitle()) - .OrderBy(f => f) - .ToArray(); - - for (int i = 1; i < titles.Length - 1; i++) - { - titles[i] = ", " + titles[i]; - } - - titles[titles.Length - 1] = " and " + titles[titles.Length - 1]; - - return string.Concat(titles); - } -} diff --git a/src/Snippetica.CodeGeneration/Commands/BasicTypeCommand.cs b/src/Snippetica.CodeGeneration/Commands/BasicTypeCommand.cs index b593cc89..f8a65e86 100644 --- a/src/Snippetica.CodeGeneration/Commands/BasicTypeCommand.cs +++ b/src/Snippetica.CodeGeneration/Commands/BasicTypeCommand.cs @@ -1,6 +1,5 @@ // Copyright (c) Josef Pihrt. All rights reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; using System.Collections.Generic; using System.IO; using System.Text.RegularExpressions; @@ -95,7 +94,7 @@ protected override void Execute(ExecutionContext context, Snippet snippet) string fileName = snippet.GetFileName(); - if (fileName.IndexOf("OfT", StringComparison.Ordinal) != -1) + if (fileName.Contains("OfT")) { fileName = fileName.Replace("OfT", $"Of{Type.Name}"); } diff --git a/src/Snippetica.CodeGeneration/Commands/CommandKind.cs b/src/Snippetica.CodeGeneration/Commands/CommandKind.cs index 79663972..c87b4c01 100644 --- a/src/Snippetica.CodeGeneration/Commands/CommandKind.cs +++ b/src/Snippetica.CodeGeneration/Commands/CommandKind.cs @@ -19,7 +19,6 @@ public enum CommandKind AbstractModifier, AccessModifier, AlternativeShortcut, - XamlProperty, PrefixTitle, SuffixFileName, ShortcutToLowercase, diff --git a/src/Snippetica.CodeGeneration/Commands/TypeCommand.cs b/src/Snippetica.CodeGeneration/Commands/TypeCommand.cs index 5687e4c8..3d65876c 100644 --- a/src/Snippetica.CodeGeneration/Commands/TypeCommand.cs +++ b/src/Snippetica.CodeGeneration/Commands/TypeCommand.cs @@ -1,7 +1,6 @@ // Copyright (c) Josef Pihrt. All rights reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Diagnostics; -using System.IO; using Snippetica.VisualStudio; namespace Snippetica.CodeGeneration.Commands; diff --git a/src/Snippetica.CodeGeneration/Commands/XamlPropertyCommand.cs b/src/Snippetica.CodeGeneration/Commands/XamlPropertyCommand.cs deleted file mode 100644 index e891cf73..00000000 --- a/src/Snippetica.CodeGeneration/Commands/XamlPropertyCommand.cs +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright (c) Josef Pihrt. All rights reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.IO; -using Snippetica.VisualStudio; - -namespace Snippetica.CodeGeneration.Commands; - -public class XamlPropertyCommand : SnippetCommand -{ - public override CommandKind Kind => CommandKind.XamlProperty; - - protected override void Execute(ExecutionContext context, Snippet snippet) - { - snippet.SuffixTitle(" property"); - snippet.SuffixShortcut("py"); - snippet.SuffixDescription(" property"); - snippet.RemoveTag(KnownTags.GenerateXamlProperty); - snippet.RemoveTag(KnownTags.NonUniqueShortcut); - snippet.AddTag(KnownTags.AutoGenerated); - - snippet.Literals.Clear(); - snippet.AddLiteral("property", "Property name", "."); - - string name = snippet.GetFileNameWithoutExtension(); - - snippet.CodeText = $"<{name}$property$>$end$"; - - snippet.SuffixFileName("Property"); - } -} diff --git a/src/Snippetica.CodeGeneration/DirectoryReadmeSettings.cs b/src/Snippetica.CodeGeneration/DirectoryReadmeSettings.cs deleted file mode 100644 index 3f6c5773..00000000 --- a/src/Snippetica.CodeGeneration/DirectoryReadmeSettings.cs +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (c) Josef Pihrt. All rights reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.Collections.Generic; -using Snippetica.VisualStudio; - -namespace Snippetica.CodeGeneration; - -public class DirectoryReadmeSettings -{ - public SnippetEnvironment Environment { get; set; } - - public string DirectoryPath { get; set; } - - public Language Language { get; set; } - - public bool IsDevelopment { get; set; } - - public bool AddQuickReference { get; set; } - - public string Header { get; set; } - - public string QuickReferenceText { get; set; } - - public bool AddLinkToTitle { get; set; } - - public bool GroupShortcuts { get; set; } - - public List Shortcuts { get; } = new(); -} diff --git a/src/Snippetica.CodeGeneration/ProjectReadmeSettings.cs b/src/Snippetica.CodeGeneration/ProjectReadmeSettings.cs deleted file mode 100644 index cefef9ed..00000000 --- a/src/Snippetica.CodeGeneration/ProjectReadmeSettings.cs +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright (c) Josef Pihrt. All rights reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using Snippetica.VisualStudio; - -namespace Snippetica.CodeGeneration; - -public class ProjectReadmeSettings -{ - public SnippetEnvironment Environment { get; set; } - - public string DirectoryPath { get; set; } - - public Language Language { get; set; } - - public bool IsDevelopment { get; set; } - - public string Header { get; set; } -} diff --git a/src/Snippetica.CodeGeneration/SnippetCodeBuilder.cs b/src/Snippetica.CodeGeneration/SnippetCodeBuilder.cs index cc0a848b..54f1b54f 100644 --- a/src/Snippetica.CodeGeneration/SnippetCodeBuilder.cs +++ b/src/Snippetica.CodeGeneration/SnippetCodeBuilder.cs @@ -32,11 +32,6 @@ public void AppendEndPlaceholder() AppendPlaceholder("end"); } - internal void AppendSelectedPlaceholder() - { - AppendPlaceholder("selected"); - } - public void AppendDelimiter() { Append(Delimiter); diff --git a/src/Snippetica.CodeGeneration/SnippetEnvironment.cs b/src/Snippetica.CodeGeneration/SnippetEnvironment.cs index cc70dada..ad1da57f 100644 --- a/src/Snippetica.CodeGeneration/SnippetEnvironment.cs +++ b/src/Snippetica.CodeGeneration/SnippetEnvironment.cs @@ -17,8 +17,6 @@ public abstract class SnippetEnvironment public List Shortcuts { get; } = new(); - public Dictionary LanguageDefinitions { get; } = new(); - public IEnumerable GenerateSnippets( IEnumerable directories, Dictionary languages, @@ -178,35 +176,6 @@ protected virtual bool ShouldGenerateSnippets(SnippetDirectory directory) return IsSupportedLanguage(directory.Language); } - public DirectoryReadmeSettings CreateSnippetsMarkdownSettings(SnippetGeneratorResult result) - { - var settings = new DirectoryReadmeSettings() - { - Environment = this, - IsDevelopment = result.IsDevelopment, - Header = result.DirectoryName, - AddLinkToTitle = true, - AddQuickReference = !result.IsDevelopment && !result.HasTag(KnownTags.NoQuickReference), - Language = result.Language, - DirectoryPath = result.Path, - GroupShortcuts = false, - }; - - if (!settings.IsDevelopment) - settings.Shortcuts.AddRange(Shortcuts); - - return settings; - } - - public ProjectReadmeSettings CreateEnvironmentMarkdownSettings() - { - return new ProjectReadmeSettings() - { - Environment = this, - Header = $"{KnownNames.ProductName} for {Kind.GetTitle()}", - }; - } - protected abstract SnippetGenerator CreateSnippetGenerator(SnippetDirectory directory, Dictionary languages); public abstract bool IsSupportedLanguage(Language language); diff --git a/src/Snippetica.CodeGeneration/SnippetGeneratorResult.cs b/src/Snippetica.CodeGeneration/SnippetGeneratorResult.cs index 6c629990..078e16aa 100644 --- a/src/Snippetica.CodeGeneration/SnippetGeneratorResult.cs +++ b/src/Snippetica.CodeGeneration/SnippetGeneratorResult.cs @@ -1,8 +1,6 @@ // Copyright (c) Josef Pihrt. All rights reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; using System.Collections.Generic; -using System.Linq; using Snippetica.VisualStudio; namespace Snippetica.CodeGeneration; @@ -39,11 +37,6 @@ public SnippetGeneratorResult( public List Tags { get; } = new(); - public bool HasTag(string tag) - { - return Tags.Any(f => f.Equals(tag, StringComparison.Ordinal)); - } - public string DirectoryName { get diff --git a/src/Snippetica.CodeGeneration/VisualStudio/ProjectDocument.cs b/src/Snippetica.CodeGeneration/VisualStudio/ProjectDocument.cs index 8967500a..275c325f 100644 --- a/src/Snippetica.CodeGeneration/VisualStudio/ProjectDocument.cs +++ b/src/Snippetica.CodeGeneration/VisualStudio/ProjectDocument.cs @@ -11,7 +11,6 @@ namespace Snippetica.CodeGeneration.VisualStudio; public class ProjectDocument { public const string CSharpProjectExtension = "csproj"; - public const string VisualBasicProjectExtension = "vbproj"; public ProjectDocument(string filePath) { diff --git a/src/Snippetica.CodeGeneration/XmlSnippetGenerator.cs b/src/Snippetica.CodeGeneration/XmlSnippetGenerator.cs index 84c0dce9..78b2395d 100644 --- a/src/Snippetica.CodeGeneration/XmlSnippetGenerator.cs +++ b/src/Snippetica.CodeGeneration/XmlSnippetGenerator.cs @@ -27,7 +27,6 @@ public static class XmlSnippetGenerator public const string SelfClosingShortcut = "s"; public const string ContentShortcut = "x"; public const string CommentShortcut = "c"; - public const string RegionShortcut = "r"; public static IEnumerable GenerateSnippets(Language language, bool generateHtmlEntities = false) { diff --git a/src/Snippetica.VisualStudio/Comparers/NamespaceComparer.cs b/src/Snippetica.VisualStudio/Comparers/NamespaceComparer.cs index 5f5b582d..0140a5b7 100644 --- a/src/Snippetica.VisualStudio/Comparers/NamespaceComparer.cs +++ b/src/Snippetica.VisualStudio/Comparers/NamespaceComparer.cs @@ -8,8 +8,6 @@ namespace Snippetica.VisualStudio; internal class NamespaceComparer : IComparer { - public static NamespaceComparer Default { get; } = new(placeSystemFirst: false); - public static NamespaceComparer SystemFirst { get; } = new(placeSystemFirst: true); private static readonly Regex _systemUsingRegex = new(@"\A\s*System\s*(\.|\z)"); diff --git a/src/Snippetica.VisualStudio/Serialization/SerializationContext.cs b/src/Snippetica.VisualStudio/Serialization/SerializationContext.cs index a523f62d..1eacdb0c 100644 --- a/src/Snippetica.VisualStudio/Serialization/SerializationContext.cs +++ b/src/Snippetica.VisualStudio/Serialization/SerializationContext.cs @@ -1,7 +1,5 @@ // Copyright (c) Josef Pihrt. All rights reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Snippetica.VisualStudio.Serialization; - namespace Snippetica.VisualStudio.Serialization; /// diff --git a/src/Snippetica.VisualStudio/Serialization/SnippetMapper.cs b/src/Snippetica.VisualStudio/Serialization/SnippetMapper.cs index acd35d2b..bce4a1a2 100644 --- a/src/Snippetica.VisualStudio/Serialization/SnippetMapper.cs +++ b/src/Snippetica.VisualStudio/Serialization/SnippetMapper.cs @@ -4,7 +4,6 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; -using Snippetica.VisualStudio.Serialization; using Snippetica.VisualStudio.Validations; namespace Snippetica.VisualStudio.Serialization; diff --git a/src/Snippetica.VisualStudio/Snippet.cs b/src/Snippetica.VisualStudio/Snippet.cs index 7c03c94d..e0f2340e 100644 --- a/src/Snippetica.VisualStudio/Snippet.cs +++ b/src/Snippetica.VisualStudio/Snippet.cs @@ -4,7 +4,6 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using System.Diagnostics; -using System.IO; namespace Snippetica.VisualStudio; diff --git a/src/Snippetica.VisualStudio/SnippetExtensions.cs b/src/Snippetica.VisualStudio/SnippetExtensions.cs index d2dc8f9a..288bb826 100644 --- a/src/Snippetica.VisualStudio/SnippetExtensions.cs +++ b/src/Snippetica.VisualStudio/SnippetExtensions.cs @@ -33,6 +33,6 @@ internal static bool CodeContainsCDataEnd(this Snippet snippet) if (snippet is null) throw new ArgumentNullException(nameof(snippet)); - return snippet.CodeText.IndexOf("]]>", StringComparison.Ordinal) != -1; + return snippet.CodeText.Contains("]]>"); } }