public void DoCoolStuff_2ValidFolders_ShouldRename2Folders() { RenameHelper r = new RenameHelper("C:\test", "NewValue", ds, fs, o); r.DoCoolStuff(); Assert.IsTrue(r.FolderRenameCounter == 2,"Incorrect number of folders renamed"); }
private async Task <Solution> RenameAsync(Document document, SyntaxToken identifier, SyntaxNode root, Diagnostic diagnostic, CancellationToken cancellationToken) { var convention = diagnostic.Properties["convention"]; var newIdentifier = identifier.WithConvention((NamingConvention)Enum.Parse(typeof(NamingConvention), convention)); return(await RenameHelper.RenameSymbolAsync(document, root, identifier, newIdentifier.Text, cancellationToken)); }
private async Task <Solution> RemoveTestSuffixAsync(Document document, SyntaxNode root, MethodDeclarationSyntax methodDeclaration, CancellationToken cancellationToken) { var newMethodName = methodDeclaration.Identifier.Text.Remove(methodDeclaration.Identifier.Text.Length - 4); return(await RenameHelper.RenameSymbolAsync(document, root, methodDeclaration.Identifier, newMethodName, cancellationToken)); }
/// <inheritdoc/> public override async Task RegisterCodeFixesAsync(CodeFixContext context) { var document = context.Document; var root = await document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false); foreach (var diagnostic in context.Diagnostics) { var token = root.FindToken(diagnostic.Location.SourceSpan.Start); if (!string.IsNullOrEmpty(token.ValueText)) { var newName = token.ValueText.TrimStart('_'); // only offer a codefix if the name does not consist of only underscores. if (!string.IsNullOrEmpty(newName)) { newName = char.ToLower(newName[0]) + newName.Substring(1); context.RegisterCodeFix( CodeAction.Create( string.Format(NamingResources.RenameToCodeFix, newName), cancellationToken => RenameHelper.RenameSymbolAsync(document, root, token, newName, cancellationToken), nameof(RenameToLowerCaseCodeFixProvider)), diagnostic); } } } }
private async Task RenameSymbol() { var host = MainViewModel.RoslynHost; var document = host.GetDocument(DocumentId); var symbol = await RenameHelper.GetRenameSymbol(document, _getSelection().Start).ConfigureAwait(true); if (symbol == null) { return; } var dialog = _serviceLocator.GetInstance <IRenameSymbolDialog>(); dialog.Initialize(symbol.Name); dialog.Show(); if (dialog.ShouldRename) { var newSolution = await Renamer.RenameSymbolAsync(document.Project.Solution, symbol, dialog.SymbolName, null).ConfigureAwait(true); var newDocument = newSolution.GetDocument(DocumentId); // TODO: possibly update entire solution host.UpdateDocument(newDocument); } OnEditorFocus(); }
/// <inheritdoc/> public override async Task RegisterCodeFixesAsync(CodeFixContext context) { var document = context.Document; var root = await document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false); foreach (var diagnostic in context.Diagnostics) { var token = root.FindToken(diagnostic.Location.SourceSpan.Start); if (!string.IsNullOrEmpty(token.ValueText)) { var newName = token.ValueText.TrimStart(new[] { '_' }); if (string.IsNullOrEmpty(newName)) { // The variable consisted of only underscores. In this case we cannot // generate a valid variable name and thus will not offer a code fix. continue; } context.RegisterCodeFix( CodeAction.Create( string.Format(NamingResources.RenameToCodeFix, newName), cancellationToken => RenameHelper.RenameSymbolAsync(document, root, token, newName, cancellationToken), nameof(SA1309CodeFixProvider)), diagnostic); } } }
public void Run() { if (_companyNamePlaceHolder != null) { if (_companyName != null) { RenameHelper.RenameAll(_entries, _companyNamePlaceHolder, _companyName); RenameHelper.RenameAll(_entries, _companyNamePlaceHolder.ToCamelCase(), _companyName.ToCamelCase()); RenameHelper.RenameAll(_entries, _companyNamePlaceHolder.ToKebabCase(), _companyName.ToKebabCase()); RenameHelper.RenameAll(_entries, _companyNamePlaceHolder.ToLowerInvariant(), _companyName.ToLowerInvariant()); } else { RenameHelper.RenameAll(_entries, _companyNamePlaceHolder + "." + _projectNamePlaceHolder, _projectNamePlaceHolder); RenameHelper.RenameAll(_entries, _companyNamePlaceHolder.ToCamelCase() + "." + _projectNamePlaceHolder.ToCamelCase(), _projectNamePlaceHolder.ToCamelCase()); RenameHelper.RenameAll(_entries, _companyNamePlaceHolder.ToLowerInvariant() + "." + _projectNamePlaceHolder.ToLowerInvariant(), _projectNamePlaceHolder.ToLowerInvariant()); RenameHelper.RenameAll(_entries, _companyNamePlaceHolder.ToKebabCase() + "/" + _projectNamePlaceHolder.ToKebabCase(), _projectNamePlaceHolder.ToKebabCase()); } } RenameHelper.RenameAll(_entries, _projectNamePlaceHolder, _projectName); RenameHelper.RenameAll(_entries, _projectNamePlaceHolder.ToCamelCase(), _projectName.ToCamelCase()); RenameHelper.RenameAll(_entries, _projectNamePlaceHolder.ToKebabCase(), _projectName.ToKebabCase()); RenameHelper.RenameAll(_entries, _projectNamePlaceHolder.ToLowerInvariant(), _projectName.ToLowerInvariant()); RenameHelper.RenameAll(_entries, _projectNamePlaceHolder.ToSnakeCase().ToUpper(), _projectName.ToSnakeCase().ToUpper()); }
internal static void RenameSelectedNode(this IRenamerContextMenu item, TextViewContext context, Action <TextViewContext> action) { var treeView = context.TreeView; var activeHandler = BaseContextMenu.ILSpyPackage.ActiveHandler; if (treeView == null || activeHandler == null) { return; } var targetObject = activeHandler.TargetObject; if (targetObject == null) { return; } var instance = MainWindow.Instance; var oldNode = treeView.SelectedItem as ILSpyTreeNode; var path = MainWindow.GetPathForNode(oldNode); var oldName = RenameHelper.GetName(targetObject); action(context); var newNode = item.FindRenamedNode(oldNode, path, oldName, targetObject); if (newNode == null) { return; } instance.SelectNode(newNode); newNode.IsExpanded = oldNode != null && oldNode.IsExpanded; }
public void DoCoolStuff_5ValidFiles_ShouldRename5Files() { RenameHelper r = new RenameHelper("C:\test", "NewValue", ds, fs, o); r.DoCoolStuff(); Assert.IsTrue(r.FileRenameCounter == 5,"Incorrect number of files renamed"); }
public void DoCoolStuff_5ValidFiles_ShouldCallMove5Times() { RenameHelper r = new RenameHelper("C:\test", "NewValue", ds, fs, o); r.DoCoolStuff(); Assert.IsTrue(fileMoveCounter == 5,"Move called incorrect amount of times"); }
/// <inheritdoc/> public override async Task RegisterCodeFixesAsync(CodeFixContext context) { var document = context.Document; var root = await document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false); foreach (var diagnostic in context.Diagnostics) { var token = root.FindToken(diagnostic.Location.SourceSpan.Start); if (!string.IsNullOrEmpty(token.ValueText)) { var newName = token.ValueText.TrimStart(new[] { '_' }); if (!SyntaxFacts.IsValidIdentifier(newName)) { // The proposed name was not legal, so no code fix will be offered. continue; } context.RegisterCodeFix( CodeAction.Create( string.Format(NamingResources.RenameToCodeFix, newName), cancellationToken => RenameHelper.RenameSymbolAsync(document, root, token, newName, cancellationToken), nameof(SA1309CodeFixProvider)), diagnostic); } } }
public void DoCoolStuff_2ValidFolders_ShouldCallFolderMoveTwice() { RenameHelper r = new RenameHelper("C:\test", "NewValue", ds, fs, o); r.DoCoolStuff(); Assert.IsTrue(folderMoveCounter == 2,"Move called incorrect amount of times"); }
public override void Execute(ProjectBuildContext context) { context .GetFile("/aspnet-core/MyCompanyName.MyProjectName.sln") .ReplaceText(_oldProjectName, _newProjectName); RenameHelper.RenameAll(context.Files, _oldProjectName, _newProjectName); }
private async Task <Solution> RemoveSuffixAsync(Document document, MethodDeclarationSyntax methodDeclaration, SyntaxNode root, CancellationToken cancellationToken) { var origMethodName = methodDeclaration.Identifier.Text; var newMethodName = origMethodName.Substring(0, origMethodName.Length - "Async".Length); return(await RenameHelper.RenameSymbolAsync(document, root, methodDeclaration.Identifier, newMethodName, cancellationToken)); }
SharpTreeNode IRenamerContextMenu.FindRenamedNode(ILSpyTreeNode oldNode, string[] path, string oldName, object targetObject) { var newName = RenameHelper.GetName(targetObject); RenamePath(oldNode, path, oldName, newName); return(MainWindow.Instance.FindNodeByPath(path, true)); }
internal static void HandleSelectedNodeRenaming(TextViewContext context, Action <TextViewContext> action) { var treeView = context.TreeView; var activeHandler = ILSpyPackage.ActiveHandler; if (treeView == null || activeHandler == null) { return; } var targetObject = activeHandler.TargetObject; if (targetObject == null) { return; } var instance = MainWindow.Instance; var oldNode = treeView.SelectedItem as ILSpyTreeNode; var path = instance.GetPathForNode(oldNode); var oldName = RenameHelper.GetName(targetObject); action(context); // After renaming an assembly, ILSpy is still using the filename to display node text, even if assembly name changed if (!(oldNode is AssemblyTreeNode)) { var newName = RenameHelper.GetName(targetObject); RenamePath(oldNode, path, oldName, newName); } // Update path to reflect new name var newNode = instance.FindNodeByPath(path, true); if (newNode == null) { return; } // Hack, so we have to change the shortname, without changing the filename, so that the user can reload the previous state var adef = targetObject as AssemblyDefinition; if (newNode is AssemblyTreeNode && adef != null) { var la = (newNode as AssemblyTreeNode).LoadedAssembly; var pInfo = la.GetType().GetField("shortName", BindingFlags.Instance | BindingFlags.NonPublic); if (pInfo != null) { pInfo.SetValue(la, adef.Name.Name); newNode.RaisePropertyChanged("Text"); } } instance.SelectNode(newNode); newNode.IsExpanded = oldNode != null && oldNode.IsExpanded; }
/// <inheritdoc/> public override async Task RegisterCodeFixesAsync(CodeFixContext context) { var document = context.Document; var root = await document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false); foreach (var diagnostic in context.Diagnostics) { var token = root.FindToken(diagnostic.Location.SourceSpan.Start); var newName = char.ToUpper(token.ValueText[0]) + token.ValueText.Substring(1); var memberSyntax = this.GetParentTypeDeclaration(token); if (memberSyntax is NamespaceDeclarationSyntax) { // namespaces are not symbols. So we are just renaming the namespace Func <CancellationToken, Task <Document> > renameNamespace = cancellationToken => { IdentifierNameSyntax identifierSyntax = (IdentifierNameSyntax)token.Parent; var newIdentifierSyntac = identifierSyntax.WithIdentifier(SyntaxFactory.Identifier(newName)); var newRoot = root.ReplaceNode(identifierSyntax, newIdentifierSyntac); return(Task.FromResult(context.Document.WithSyntaxRoot(newRoot))); }; context.RegisterCodeFix( CodeAction.Create( string.Format(NamingResources.RenameToCodeFix, newName), renameNamespace, nameof(RenameToUpperCaseCodeFixProvider) + "_" + diagnostic.Id), diagnostic); } else if (memberSyntax != null) { SemanticModel semanticModel = await document.GetSemanticModelAsync(context.CancellationToken).ConfigureAwait(false); var typeDeclarationSymbol = semanticModel.GetDeclaredSymbol(memberSyntax); if (typeDeclarationSymbol == null) { continue; } if (!this.IsValidNewMemberName(typeDeclarationSymbol, newName)) { newName = newName + Suffix; } context.RegisterCodeFix( CodeAction.Create( string.Format(NamingResources.RenameToCodeFix, newName), cancellationToken => RenameHelper.RenameSymbolAsync(document, root, token, newName, cancellationToken), nameof(RenameToUpperCaseCodeFixProvider) + "_" + diagnostic.Id), diagnostic); } } }
public override async Task RegisterCodeFixesAsync(CodeFixContext context) { var document = context.Document; var root = await document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false); foreach (var diagnostic in context.Diagnostics) { var token = root.FindToken(diagnostic.Location.SourceSpan.Start); if (string.IsNullOrEmpty(token.ValueText)) { continue; } var originalName = token.ValueText; var baseName = originalName.TrimStart('_'); if (baseName.Length == 0) { // only offer a code fix if the name does not consist of only underscores. continue; } baseName = char.ToLower(baseName[0]) + baseName.Substring(1); int underscoreCount = originalName.Length - baseName.Length; var memberSyntax = RenameHelper.GetParentDeclaration(token); SemanticModel semanticModel = await document.GetSemanticModelAsync(context.CancellationToken).ConfigureAwait(false); var declaredSymbol = semanticModel.GetDeclaredSymbol(memberSyntax); if (declaredSymbol == null) { continue; } // preserve the underscores, but only for fields. var prefix = declaredSymbol.Kind == SymbolKind.Field ? originalName.Substring(0, underscoreCount) : string.Empty; var newName = prefix + baseName; int index = 0; while (!await RenameHelper.IsValidNewMemberNameAsync(semanticModel, declaredSymbol, newName, context.CancellationToken).ConfigureAwait(false)) { index++; newName = prefix + baseName + index; } context.RegisterCodeFix( CodeAction.Create( string.Format(NamingResources.RenameToCodeFix, newName), cancellationToken => RenameHelper.RenameSymbolAsync(document, root, token, newName, cancellationToken), nameof(RenameToLowerCaseCodeFixProvider) + "_" + underscoreCount + "_" + index), diagnostic); } }
protected override async Task <int> OnExecuteAsync(CommandLineApplication app) { Identifier = Identifier.ToLower(); if (Name.IsNullOrWhiteSpace()) { var defaultName = string.Empty; var promptText = string.Empty; switch (Identifier) { case "console": defaultName = Consts.DefaultConsoleName; promptText = Consts.Descriptions.New.NameConsolePrompt; break; case "module": defaultName = Consts.DefaultModuleName; promptText = Consts.Descriptions.New.NameModulePrompt; break; default: break; } Name = Prompt.GetString(promptText, defaultValue: defaultName); } var tplFinder = new TemplateFinder(TemplateName); var tplFilePath = await tplFinder.Fetch(); var projectFolder = Path.Combine(Directory.GetCurrentDirectory(), $".{Path.DirectorySeparatorChar}src{Path.DirectorySeparatorChar}{Name}"); if (!Directory.Exists(projectFolder)) { Directory.CreateDirectory(projectFolder); } ExtractHelper.ExtractZipFile(tplFilePath, projectFolder, Identifier); if (Identifier == "module") { Placeholder = $"{Placeholder}.{DefaultModuleNamePlaceholder}"; } RenameHelper.RenameFolders(projectFolder, Placeholder, Name, false, null); return(0); }
/// <inheritdoc/> public override async Task RegisterCodeFixesAsync(CodeFixContext context) { var document = context.Document; var root = await document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false); foreach (var diagnostic in context.Diagnostics) { var token = root.FindToken(diagnostic.Location.SourceSpan.Start); var numberOfCharsToRemove = 0; // If a variable contains multiple prefixes that would result in this diagnostic, // we detect that and remove all of the bad prefixes such that after // the fix is applied there are no more violations of this rule. for (int i = 0; i < token.ValueText.Length; i += 2) { if (string.Compare("m_", 0, token.ValueText, i, 2, StringComparison.Ordinal) == 0 || string.Compare("s_", 0, token.ValueText, i, 2, StringComparison.Ordinal) == 0 || string.Compare("t_", 0, token.ValueText, i, 2, StringComparison.Ordinal) == 0) { numberOfCharsToRemove += 2; continue; } break; } if (numberOfCharsToRemove == 0) { continue; } // The prefix is the full variable name. In this case we cannot generate a valid variable name and thus will not offer a code fix. if (token.ValueText.Length == numberOfCharsToRemove) { continue; } var newName = token.ValueText.Substring(numberOfCharsToRemove); context.RegisterCodeFix( CodeAction.Create( string.Format(NamingResources.RenameToCodeFix, newName), cancellationToken => RenameHelper.RenameSymbolAsync(document, root, token, newName, cancellationToken), nameof(SA1308CodeFixProvider)), diagnostic); } }
/// <inheritdoc/> public override async Task RegisterCodeFixesAsync(CodeFixContext context) { var document = context.Document; var root = await document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false); foreach (var diagnostic in context.Diagnostics) { var token = root.FindToken(diagnostic.Location.SourceSpan.Start); var newName = "I" + token.ValueText; context.RegisterCodeFix( CodeAction.Create( string.Format(NamingResources.RenameToCodeFix, newName), cancellationToken => RenameHelper.RenameSymbolAsync(document, root, token, newName, cancellationToken), nameof(SA1302CodeFixProvider)), diagnostic); } }
private static async Task <Solution> CreateChangedSolutionAsync(Document document, Diagnostic diagnostic, CancellationToken cancellationToken) { var root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false); var token = root.FindToken(diagnostic.Location.SourceSpan.Start); var baseName = "T" + token.ValueText; var index = 0; var newName = baseName; var semanticModel = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false); var declaredSymbol = semanticModel.GetDeclaredSymbol(token.Parent, cancellationToken); while (!await RenameHelper.IsValidNewMemberNameAsync(semanticModel, declaredSymbol, newName, cancellationToken).ConfigureAwait(false)) { index++; newName = baseName + index; } return(await RenameHelper.RenameSymbolAsync(document, root, token, newName, cancellationToken).ConfigureAwait(false)); }
/// <inheritdoc/> public override async Task RegisterCodeFixesAsync(CodeFixContext context) { var document = context.Document; var root = await document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false); foreach (var diagnostic in context.Diagnostics) { if (!diagnostic.Id.Equals(UseAsyncSuffixAnalyzer.DiagnosticId)) { continue; } var token = root.FindToken(diagnostic.Location.SourceSpan.Start); var newName = token.ValueText + "Async"; context.RegisterCodeFix( CodeAction.Create( $"Rename method to '{newName}'", cancellationToken => RenameHelper.RenameSymbolAsync(document, root, token, newName, cancellationToken), nameof(UseAsyncSuffixCodeFixProvider)), diagnostic); } }
KeyValuePair <RenameResult, string>?RenameIdentifierOfContainerNode(SyntaxNode containerNode, SyntaxToken identifierToRename, string newVarName) { RenameResult result = null; var currentName = identifierToRename.ValueText; var selectedName = currentName; if (string.Compare(newVarName, currentName, false) == 0) { return(null); } if (ValidateNewName(newVarName) == false) { return(null); } var identifierDeclarationNode = identifierToRename.Parent; var identifierSymbol = _semanticModel.GetDeclaredSymbol(identifierDeclarationNode); var validateNameResult = RenameHelper.IsValidNewMemberNameAsync(_semanticModel, identifierSymbol, newVarName).Result; if (validateNameResult == false) { return(null); } result = RenameSymbol(WorkingDocument, WorkingDocument.GetSyntaxRootAsync().Result, containerNode, identifierDeclarationNode, newVarName); if (result != null) { selectedName = newVarName; } return(new KeyValuePair <RenameResult, string>(result, selectedName)); }
public override async Task RegisterCodeFixesAsync(CodeFixContext context) { var document = context.Document; var root = await document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false); foreach (var diagnostic in context.Diagnostics) { var token = root.FindToken(diagnostic.Location.SourceSpan.Start); var tokenText = token.ValueText.TrimStart('_'); var baseName = char.ToUpper(tokenText[0]) + tokenText.Substring(1); var newName = baseName; var memberSyntax = RenameHelper.GetParentDeclaration(token); if (BaseNamespaceDeclarationSyntaxWrapper.IsInstance(memberSyntax)) { // namespaces are not symbols. So we are just renaming the namespace Task <Document> RenameNamespace(CancellationToken cancellationToken) { IdentifierNameSyntax identifierSyntax = (IdentifierNameSyntax)token.Parent; var newIdentifierSyntax = identifierSyntax.WithIdentifier(SyntaxFactory.Identifier(newName)); var newRoot = root.ReplaceNode(identifierSyntax, newIdentifierSyntax); return(Task.FromResult(context.Document.WithSyntaxRoot(newRoot))); } context.RegisterCodeFix( CodeAction.Create( string.Format(NamingResources.RenameToCodeFix, newName), (Func <CancellationToken, Task <Document> >)RenameNamespace, nameof(RenameToUpperCaseCodeFixProvider) + "_" + diagnostic.Id), diagnostic); } else if (memberSyntax != null) { SemanticModel semanticModel = await document.GetSemanticModelAsync(context.CancellationToken).ConfigureAwait(false); var declaredSymbol = semanticModel.GetDeclaredSymbol(memberSyntax); if (declaredSymbol == null) { continue; } bool usedSuffix = false; if (declaredSymbol.Kind == SymbolKind.Field && declaredSymbol.ContainingType?.TypeKind != TypeKind.Enum && !await RenameHelper.IsValidNewMemberNameAsync(semanticModel, declaredSymbol, newName, context.CancellationToken).ConfigureAwait(false)) { usedSuffix = true; newName += Suffix; } int index = 0; while (!await RenameHelper.IsValidNewMemberNameAsync(semanticModel, declaredSymbol, newName, context.CancellationToken).ConfigureAwait(false)) { usedSuffix = false; index++; newName = baseName + index; } context.RegisterCodeFix( CodeAction.Create( string.Format(NamingResources.RenameToCodeFix, newName), cancellationToken => RenameHelper.RenameSymbolAsync(document, root, token, newName, cancellationToken), nameof(RenameToUpperCaseCodeFixProvider) + "_" + diagnostic.Id + "_" + usedSuffix + "_" + index), diagnostic); } } }
protected override async Task <int> OnExecuteAsync(CommandLineApplication app) { if (!Mpa) { //switch to personball/module-zero-core-template to reduce size of project template zip file if (TemplateName == Consts.DefaultProjectTemplateName) { TemplateName = Consts.DefaultProjectTemplateForSPA; } if (string.IsNullOrWhiteSpace(SpaType)) { SpaType = Prompt.GetString(Consts.Descriptions.Init.SpaTypeDescription, defaultValue: "vue"); SpaType = SpaType.ToLower(); if ("vue,ng,react".IndexOf(SpaType) == -1) { SpaType = "vue"; } } } Console.WriteLine($"TemplateName\t:{TemplateName}"); Console.WriteLine($"Placeholder\t:{Placeholder}"); Console.WriteLine($"ProjectName\t:{ProjectName}"); Console.WriteLine($"MPA\t\t:{Mpa}"); Console.WriteLine($"SpaType\t\t:{SpaType}"); Console.WriteLine($"RenameBackup\t:{RenameBackup}"); //Create Target folder var projectFolder = Path.Combine(Directory.GetCurrentDirectory(), ProjectName); if (!Directory.Exists(projectFolder)) { Directory.CreateDirectory(projectFolder); } var tplFinder = new TemplateFinder(TemplateName); var tplFilePath = await tplFinder.Fetch(); ExtractHelper.ExtractZipFile(tplFilePath, projectFolder); var excludeFolders = new List <string>(); InitExcludedFolders.ForEach(s => { excludeFolders.Add(s); }); if (!Mpa) { excludeFolders.Add($"./aspnet-core/src/{Placeholder}.Web.Mvc"); //TODO@personball remove web.mvc entry in vs solution file(sln). switch (SpaType.ToLower()) { case "ng": excludeFolders.Remove("./angular"); break; case "react": excludeFolders.Remove("./reactjs"); break; case "vue": default: excludeFolders.Remove("./vue"); break; } } // Placeholder as AbpCompanyName.AbpProjectName // ProjectName as CompanyName.ProjectName or just ProjectName RenameHelper.RenameFolders(projectFolder, Placeholder, ProjectName, RenameBackup, excludeFolders); Console.WriteLine("Init Completed!"); return(0); }
/// <inheritdoc/> public override async Task RegisterCodeFixesAsync(CodeFixContext context) { var document = context.Document; var root = await document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false); foreach (var diagnostic in context.Diagnostics) { if (!diagnostic.Id.Equals(SA1310FieldNamesMustNotContainUnderscore.DiagnosticId)) { continue; } var token = root.FindToken(diagnostic.Location.SourceSpan.Start); string currentName = token.ValueText; string proposedName = BuildProposedName(currentName); if (proposedName != currentName) { context.RegisterCodeFix(CodeAction.Create(string.Format(NamingResources.RenameToCodeFix, proposedName), cancellationToken => RenameHelper.RenameSymbolAsync(document, root, token, proposedName, cancellationToken), equivalenceKey: nameof(SA1310CodeFixProvider)), diagnostic); } } }
public DialogResult ShowDialog(object item) { Item = item; ItemName.Text = RenameHelper.GetName(item); return(ShowDialog()); }
private void Ok_Click(object sender, EventArgs e) { RenameHelper.Rename(Item, ItemName.Text); }
/// <inheritdoc/> public override async Task RegisterCodeFixesAsync(CodeFixContext context) { foreach (var diagnostic in context.Diagnostics) { if (!diagnostic.Id.Equals(SA1307AccessibleFieldsMustBeginWithUpperCaseLetter.DiagnosticId)) { continue; } var document = context.Document; var root = await document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false); var token = root.FindToken(diagnostic.Location.SourceSpan.Start); if (token.IsMissing) { continue; } if (!string.IsNullOrEmpty(token.ValueText)) { var newName = char.ToUpper(token.ValueText[0]) + token.ValueText.Substring(1); context.RegisterCodeFix(CodeAction.Create($"Rename field to '{newName}'", cancellationToken => RenameHelper.RenameSymbolAsync(document, root, token, newName, cancellationToken)), diagnostic); } } }
/// <inheritdoc/> public override async Task RegisterCodeFixesAsync(CodeFixContext context) { var document = context.Document; var root = await document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false); foreach (var diagnostic in context.Diagnostics) { if (!diagnostic.Id.Equals(SA1309FieldNamesMustNotBeginWithUnderscore.DiagnosticId)) { continue; } var token = root.FindToken(diagnostic.Location.SourceSpan.Start); if (token.IsMissing) { continue; } if (!string.IsNullOrEmpty(token.ValueText)) { var newName = token.ValueText.TrimStart(new[] { '_' }); if (string.IsNullOrEmpty(newName)) { // The variable consisted of only underscores. In this case we cannot // generate a valid variable name and thus will not offer a code fix. continue; } context.RegisterCodeFix(CodeAction.Create($"Rename field to '{newName}'", cancellationToken => RenameHelper.RenameSymbolAsync(document, root, token, newName, cancellationToken)), diagnostic); } } }
public FileRenameControl() { InitializeComponent(); FileResults = new ObservableCollection <VM_VideoLocal_Renamed>(); ViewFiles = CollectionViewSource.GetDefaultView(FileResults); RenameTags = new ObservableCollection <RenameTag>(); foreach (RenameTag tag in RenameHelper.GetAllTags()) { RenameTags.Add(tag); } ViewTags = CollectionViewSource.GetDefaultView(RenameTags); cboTagType.SelectedIndex = 0; RenameTests = new ObservableCollection <RenameTest>(); foreach (RenameTest test in RenameHelper.GetAllTests()) { RenameTests.Add(test); } ViewTests = CollectionViewSource.GetDefaultView(RenameTests); cboTestType.SelectedIndex = 0; RenameScripts = new ObservableCollection <VM_RenameScript>(); //ViewScripts = CollectionViewSource.GetDefaultView(RenameScripts); /*string testScript = "IF A(69),A(1),A(2) DO FAIL" + Environment.NewLine + //Do not rename file if it is Naruto * //// Group Name * "DO ADD '[%grp] '" + Environment.NewLine + //sub group name short * //// Anime Name * "IF I(eng) DO ADD '%eng - '" + Environment.NewLine + // if the anime has an official/main title english add it to the string * "IF I(ann);I(!eng) DO ADD '%ann - '" + Environment.NewLine + //If the anime has a romaji title but not an english title add the romaji anime title * //// Episode Number * "DO ADD '%enr - '" + Environment.NewLine + //Add the base, same for all files * //// FILE Version * "IF F(!1) DO ADD ' [v%ver]'" + Environment.NewLine + //If the episode has an english title add to string * //// Episode Title * "IF I(epr) DO ADD '%epr'" + Environment.NewLine + //If the episode has an english title add to string * "IF I(epn);I(!epr) DO ADD '%epn'" + Environment.NewLine + //If the episode has an romaji title but not an english title add the romaji episode title * //// Codecs * "DO ADD ' [%vid/%aud]'" + Environment.NewLine + * //// video depth * "IF Z(10) DO ADD '[%bitbit]'" + Environment.NewLine + * //// Blu-ray and DVD * "IF R(Blu-ray),R(DVD) DO ADD '[%src]'" + Environment.NewLine + * //// CRC * "DO ADD '[%CRC]'" + Environment.NewLine; * * * * txtRenameScript.Text = testScript;*/ btnLoadFiles.Click += new RoutedEventHandler(btnLoadFiles_Click); btnPreviewFiles.Click += new RoutedEventHandler(btnPreviewFiles_Click); btnRenameFiles.Click += new RoutedEventHandler(btnRenameFiles_Click); btnPreviewStop.Click += new RoutedEventHandler(btnPreviewStop_Click); btnClearList.Click += new RoutedEventHandler(btnClearList_Click); btnAddTag.Click += new RoutedEventHandler(btnAddTag_Click); btnAddTest.Click += new RoutedEventHandler(btnAddTest_Click); btnNewScript.Click += new RoutedEventHandler(btnNewScript_Click); btnSaveScript.Click += new RoutedEventHandler(btnSaveScript_Click); btnDeleteScript.Click += new RoutedEventHandler(btnDeleteScript_Click); Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(AppSettings.Culture); cboLoadType.Items.Clear(); cboLoadType.Items.Add(Shoko.Commons.Properties.Resources.Rename_Random); cboLoadType.Items.Add(Shoko.Commons.Properties.Resources.Rename_Series); cboLoadType.Items.Add(Shoko.Commons.Properties.Resources.Rename_All); cboLoadType.SelectedIndex = 0; cboLoadType.SelectionChanged += new SelectionChangedEventHandler(cboLoadType_SelectionChanged); cboFilterType.Items.Clear(); cboFilterType.Items.Add(Shoko.Commons.Properties.Resources.Random_All); cboFilterType.Items.Add(Shoko.Commons.Properties.Resources.Rename_Failed); cboFilterType.Items.Add(Shoko.Commons.Properties.Resources.Rename_Passed); cboFilterType.SelectionChanged += new SelectionChangedEventHandler(cboFilterType_SelectionChanged); cboFilterType.SelectedIndex = 0; cboScript.SelectionChanged += new SelectionChangedEventHandler(cboScript_SelectionChanged); previewWorker.DoWork += new DoWorkEventHandler(previewWorker_DoWork); previewWorker.WorkerSupportsCancellation = true; previewWorker.WorkerReportsProgress = true; previewWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(previewWorker_RunWorkerCompleted); previewWorker.ProgressChanged += new ProgressChangedEventHandler(previewWorker_ProgressChanged); renameWorker.DoWork += new DoWorkEventHandler(renameWorker_DoWork); renameWorker.WorkerSupportsCancellation = true; renameWorker.WorkerReportsProgress = true; renameWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(renameWorker_RunWorkerCompleted); renameWorker.ProgressChanged += new ProgressChangedEventHandler(renameWorker_ProgressChanged); txtRenameScript.LostFocus += new RoutedEventHandler(txtRenameScript_LostFocus); ViewTags.SortDescriptions.Add(new SortDescription("Name", ListSortDirection.Ascending)); ViewTests.SortDescriptions.Add(new SortDescription("Name", ListSortDirection.Ascending)); //ViewScripts.SortDescriptions.Add(new SortDescription("ScriptName", ListSortDirection.Ascending)); }
private async Task <Solution> AddSuffixAsync(Document document, MethodDeclarationSyntax methodDeclaration, SyntaxNode root, CancellationToken cancellationToken) { return(await RenameHelper.RenameSymbolAsync(document, root, methodDeclaration.Identifier, methodDeclaration.Identifier.Text + "Async", cancellationToken)); }
/// <inheritdoc/> public override async Task RegisterCodeFixesAsync(CodeFixContext context) { var document = context.Document; var root = await document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false); foreach (var diagnostic in context.Diagnostics) { if (!diagnostic.Id.Equals(SX1309FieldNamesMustBeginWithUnderscore.DiagnosticId) && !diagnostic.Id.Equals(SX1309SStaticFieldNamesMustBeginWithUnderscore.DiagnosticId)) { continue; } var token = root.FindToken(diagnostic.Location.SourceSpan.Start); if (token.IsMissing) { continue; } if (!string.IsNullOrEmpty(token.ValueText)) { string newName = '_' + token.ValueText; context.RegisterCodeFix(CodeAction.Create(string.Format(NamingResources.RenameToCodeFix, newName), cancellationToken => RenameHelper.RenameSymbolAsync(document, root, token, newName, cancellationToken), equivalenceKey: nameof(SX1309CodeFixProvider)), diagnostic); } } }