public override void Accept(AnalyzerBase analyzer) { foreach (var exception in DocumentedExceptions) { exception.Accept(analyzer); } }
public void CanHandleMultipleNumberReplacements() { var gridProfile = new Profile { Name = "GridTestProfile", ClassGrouping = "Grid", FallbackOutput = "<TextBlock Text=\"FALLBACK_$name$\" />", SubPropertyOutput = "<TextBlock Text=\"SUBPROP_$name$\" />", Mappings = new ObservableCollection <Mapping> { new Mapping { Type = StringPropertyName, NameContains = "", Output = "<TextBlock Text=\"$name$\" Grid.Row=\"$incint$\" /><TextBlock Text=\"$name$\" Grid.Row=\"$incint$\" />", IfReadOnly = false, }, }, }; var result = AnalyzerBase.GetPropertyOutput(gridProfile, StringPropertyName, "MyProperty", false, UnusedIndentValue); var expected = "<TextBlock Text=\"MyProperty\" Grid.Row=\"1\" />" + Environment.NewLine + "<TextBlock Text=\"MyProperty\" Grid.Row=\"2\" />"; StringAssert.AreEqual(expected, result); }
public void SpecificGenericsMatchBeforeWildCard() { var wildcardGenericsProfile = new Profile { Name = "wildcardGenericsProfile", ClassGrouping = "Grid", FallbackOutput = "<Fallback />", Mappings = new ObservableCollection <Mapping> { new Mapping { Type = "List<T>", NameContains = "", Output = "<Wildcard />", IfReadOnly = false, }, new Mapping { Type = "List<string>", NameContains = "", Output = "<ListOfStrings />", IfReadOnly = false, }, }, }; var result = AnalyzerBase.GetPropertyOutput(wildcardGenericsProfile, "List<string>", "MyProperty", isReadOnly: false, indent: UnusedIndentValue); Assert.AreEqual("<ListOfStrings />", result); }
public DataBindingBackgroundHelper(AnalyzerBase analyzer, TreeItem treeItem, AnalyzerContext context, Action doneAction) { _context = context; _analyzer = analyzer; _treeItem = treeItem; _doneAction = doneAction; }
public void AddMiddleCell(Cell cell) { cells.Add(cell); NullMiddle(cell); analyzer = GetAnalyzer(); SetEstimate(); }
/// <summary>Called to test a C# codefix when applied on the inputted string as a source.</summary> /// <param name="oldSource">A class in the form of a string before the CodeFix was applied to it.</param> /// <param name="newSource">A class in the form of a string after the CodeFix was applied to it.</param> /// <param name="codeFixIndex">Index determining which codefix to apply if there are multiple.</param> /// <param name="allowNewCompilerDiagnostics">A bool controlling whether or not the test will fail if the CodeFix introduces other warnings after being applied.</param> protected void VerifyCodeFix(string oldSource, string newSource, int?codeFixIndex = null, bool allowNewCompilerDiagnostics = false) { AnalyzerBase analyzer = this.GetDiagnosticAnalyzer(); CodeFixProvider codeFixProvider = this.GetCodeFixProvider(); this.VerifyFix(analyzer, codeFixProvider, oldSource, newSource, codeFixIndex, allowNewCompilerDiagnostics); }
public void RecordInfo(string message) { if (AnalyzerBase.GetSettings().ExtendedOutputEnabled) { RxtOutputPane.Instance.Write(TimeStampMessage(message)); } }
private async void MenuItem_BeforeQueryStatus(object sender, EventArgs e) { try { if (sender is OleMenuCommand menuCmd) { bool showCommandButton = false; var settings = AnalyzerBase.GetSettings(); if (settings.IsActiveProfileSet) { var profile = settings.GetActiveProfile(); var dte = await Instance.ServiceProvider.GetServiceAsync(typeof(DTE)) as DTE; var logic = new SetDataContextCommandLogic(profile, this.Logger, new VisualStudioAbstraction(this.Logger, this.ServiceProvider, dte)); showCommandButton = logic.ShouldEnableCommand(); } menuCmd.Visible = menuCmd.Enabled = showCommandButton; } } catch (Exception exc) { this.Logger.RecordException(exc); throw; // Remove for launch. see issue #90 } }
/// <summary>Runs the analyzer against all defined elements. </summary> /// <param name="analyzer">The analyzer. </param> public override void Accept(AnalyzerBase analyzer) { foreach (var thrownExceptionModel in ThrownExceptions) { thrownExceptionModel.Accept(analyzer); } }
private void MenuItem_BeforeQueryStatus(object sender, EventArgs e) { try { if (sender is OleMenuCommand menuCmd) { menuCmd.Visible = menuCmd.Enabled = false; if (!this.IsSingleProjectItemSelection(out var hierarchy, out var itemid)) { this.SelectedFileName = null; return; } ((IVsProject)hierarchy).GetMkDocument(itemid, out var itemFullPath); var transformFileInfo = new FileInfo(itemFullPath); // Save the name of the selected file so we whave it when the command is executed this.SelectedFileName = transformFileInfo.FullName; if (transformFileInfo.Name.EndsWith(".cs") || transformFileInfo.Name.EndsWith(".vb")) { if (AnalyzerBase.GetSettings().IsActiveProfileSet) { menuCmd.Visible = menuCmd.Enabled = true; } } } } catch (Exception exc) { this.Logger.RecordException(exc); throw; } }
/// <summary>Analyzes the object and its children. </summary> /// <param name="analyzer">The analyzer base. </param> public override void Accept(AnalyzerBase analyzer) { base.Accept(analyzer); foreach (var catchClauseModel in CatchClauses) { catchClauseModel.Accept(analyzer); } }
public void GetSelectionPropertiesName_Two() { var result = AnalyzerBase.GetSelectionPropertiesName(new List <string> { "one", "two" }); Assert.IsTrue(result.Equals("one and two")); }
public void GetSelectionPropertiesName_Five() { var result = AnalyzerBase.GetSelectionPropertiesName(new List <string> { "one", "two", "three", "four", "five" }); Assert.IsTrue(result.Equals("one, two and 3 other properties")); }
public void RecordInfo(string message) { ThreadHelper.ThrowIfNotOnUIThread(); if (AnalyzerBase.GetSettings().ExtendedOutputEnabled) { RxtOutputPane.Instance.Write(TimeStampMessage(message)); } }
public override void Accept(AnalyzerBase analyzer) { if (DocumentationBlock != null) { DocumentationBlock.Accept(analyzer); } base.Accept(analyzer); }
public override void Accept(AnalyzerBase analyzer) { foreach (var accessor in Accessors) { accessor.Accept(analyzer); } base.Accept(analyzer); }
/// <summary>Analyzes the object and its children. </summary> /// <param name="analyzer">The analyzer. </param> public override void Accept(AnalyzerBase analyzer) { foreach (var accessorDeclarationModel in Accessors) { accessorDeclarationModel.Accept(analyzer); } base.Accept(analyzer); }
protected override AnalyzerBase GetDiagnosticAnalyzer() { if (this.analyzer == null) { this.analyzer = new ElementsMustBeDocumented(); } return(this.analyzer); }
protected DiagnosticResult CreateDiagnosticResult(string message, params DiagnosticResultLocation[] locations) { AnalyzerBase analyzer = this.GetDiagnosticAnalyzer(); return(new DiagnosticResult { Id = analyzer.Id, Message = message, Locations = locations, Severity = analyzer.DefaultSeverity }); }
/// <summary>Analyzes the object and its children. </summary> /// <param name="analyzer">The analyzer. </param> public override void Accept(AnalyzerBase analyzer) { foreach (var tryStatement in TryStatements) { tryStatement.Accept(analyzer); } foreach (var thrownException in ThrownExceptions) { thrownException.Accept(analyzer); } }
public void RecordError(string message) { // Activate the pane (bring to front) so errors are obvious if (AnalyzerBase.GetSettings().ExtendedOutputEnabled) { RxtOutputPane.Instance.Write(TimeStampMessage(message)); RxtOutputPane.Instance.Activate(); } else { GeneralOutputPane.Instance.Write(TimeStampMessage(message)); GeneralOutputPane.Instance.Activate(); } }
static TelegramBotAnalyzers() { // When compiling the project that uses this analyzer, the Microsoft.CodeAnalysis.Workspaces assembly is not loaded. // All this try-catch and null checking nonsense is here to remove the warning one would get when compiling try { DiagnosticConfig.DefaultCategory = "Telegram.Bot"; Manager = new AnalyzerBase(); } catch (FileNotFoundException exception) when(exception.FileName.Contains("Microsoft.CodeAnalysis.Workspaces")) { } }
private async void Execute(object sender, EventArgs e) { try { ThreadHelper.ThrowIfNotOnUIThread(); this.Logger?.RecordFeatureUsage(nameof(CreateViewCommand)); this.Logger?.RecordInfo(StringRes.Info_AttemptingToCreateView); var dte = await this.ServiceProvider.GetServiceAsync(typeof(DTE)) as DTE; var componentModel = await this.ServiceProvider.GetServiceAsync(typeof(SComponentModel)) as IComponentModel; var profile = AnalyzerBase.GetSettings().GetActiveProfile(); var logic = new CreateViewCommandLogic(profile, this.Logger, new VisualStudioAbstraction(dte, componentModel)); await logic.ExecuteAsync(this.SelectedFileName); if (logic.CreateView) { if (!Directory.Exists(logic.ViewFolder)) { Directory.CreateDirectory(logic.ViewFolder); } File.WriteAllText(logic.XamlFileName, logic.XamlFileContents, Encoding.UTF8); File.WriteAllText(logic.CodeFileName, logic.CodeFileContents, Encoding.UTF8); // add files to project (rely on VS to nest them) logic.ViewProject.Project.ProjectItems.AddFromFile(logic.XamlFileName); logic.ViewProject.Project.ProjectItems.AddFromFile(logic.CodeFileName); // Open the newly created view dte?.ItemOperations.OpenFile(logic.XamlFileName, EnvDTE.Constants.vsViewKindDesigner); this.Logger?.RecordInfo(StringRes.Info_CreatedView.WithParams(logic.XamlFileName)); } else { this.Logger?.RecordInfo(StringRes.Info_NoViewCreated); } } catch (Exception exc) { this.Logger?.RecordException(exc); throw; } }
public void CorrectlySplitCamelCasePropertyNames() { var profile = TestProfile.CreateEmpty(); profile.Mappings.Add(new Mapping { Type = "string", IfReadOnly = false, NameContains = string.Empty, Output = "$namewithspaces$", }); var result = AnalyzerBase.GetPropertyOutput(profile, "string", "MyProperty", isReadOnly: false, indent: UnusedIndentValue); Assert.AreEqual("My Property", result); }
public async Task <AnalyzerOutput> GetXamlAsync(IAsyncServiceProvider serviceProvider) { AnalyzerOutput result = null; if (AnalyzerBase.GetSettings().Profiles.Any()) { var dte = await serviceProvider.GetServiceAsync(typeof(EnvDTE.DTE)) as EnvDTE.DTE; var activeDocument = dte.ActiveDocument; var textView = await GetTextViewAsync(serviceProvider); var selection = textView.Selection; bool isSelection = selection.Start.Position != selection.End.Position; var caretPosition = textView.Caret.Position.BufferPosition; var document = caretPosition.Snapshot.GetOpenDocumentInCurrentContextWithChanges(); var semanticModel = await document.GetSemanticModelAsync(); var vs = new VisualStudioAbstraction(this.Logger, this.ServiceProvider, dte); var xamlIndent = await vs.GetXamlIndentAsync(); IDocumentAnalyzer analyzer = null; if (activeDocument.Language == "CSharp") { analyzer = new CSharpAnalyzer(this.Logger); } else if (activeDocument.Language == "Basic") { analyzer = new VisualBasicAnalyzer(this.Logger); } result = isSelection ? analyzer?.GetSelectionOutput(await document.GetSyntaxRootAsync(), semanticModel, selection.Start.Position, selection.End.Position, xamlIndent) : analyzer?.GetSingleItemOutput(await document.GetSyntaxRootAsync(), semanticModel, caretPosition.Position, xamlIndent); } else { await ShowStatusBarMessageAsync(serviceProvider, StringRes.UI_NoXamlCopiedNoProfilesConfigured); } return(result); }
public AnalyzerOutput GetXaml(IAsyncServiceProvider serviceProvider) { AnalyzerOutput result = null; if (AnalyzerBase.GetSettings().Profiles.Any()) { var dte = (EnvDTE.DTE)serviceProvider.GetServiceAsync(typeof(EnvDTE.DTE)).Result; var activeDocument = dte.ActiveDocument; var textView = GetTextView(serviceProvider); var selection = textView.Selection; bool isSelection = selection.Start.Position != selection.End.Position; var caretPosition = textView.Caret.Position.BufferPosition; var document = caretPosition.Snapshot.GetOpenDocumentInCurrentContextWithChanges(); var semanticModel = document.GetSemanticModelAsync().Result; IDocumentAnalyzer analyzer = null; if (activeDocument.Language == "CSharp") { analyzer = new CSharpAnalyzer(this.Logger); } else if (activeDocument.Language == "Basic") { analyzer = new VisualBasicAnalyzer(this.Logger); } result = isSelection ? analyzer?.GetSelectionOutput(document.GetSyntaxRootAsync().Result, semanticModel, selection.Start.Position, selection.End.Position) : analyzer?.GetSingleItemOutput(document.GetSyntaxRootAsync().Result, semanticModel, caretPosition.Position); } else { ShowStatusBarMessage(serviceProvider, "No XAML copied. No profiles configured."); } return(result); }
private void MenuItem_BeforeQueryStatus(object sender, EventArgs e) { try { if (sender is OleMenuCommand menuCmd) { menuCmd.Visible = menuCmd.Enabled = false; if (!AnalyzerBase.GetSettings().IsActiveProfileSet) { menuCmd.Visible = menuCmd.Enabled = true; } } } catch (Exception exc) { this.Logger.RecordException(exc); throw; } }
public DragDropPointerEffects HandleDataDropped(DragDropInfo dragDropInfo) { var position = dragDropInfo.VirtualBufferPosition.Position; var insertLineLength = this.view.GetTextViewLineContainingBufferPosition(position).Length; ThreadHelper.JoinableTaskFactory.Run(async() => { var profile = AnalyzerBase.GetSettings().GetActiveProfile(); var logic = new DropHandlerLogic(profile, this.logger, this.vs, this.fileSystem); var textOutput = await logic.ExecuteAsync(this.draggedFilename, insertLineLength); if (!string.IsNullOrEmpty(textOutput)) { this.view.TextBuffer.Insert(position.Position, textOutput); } }); return(DragDropPointerEffects.Copy); }
public void WriteablePropertiesMatchFallbackIfOnlySpecificReadOnlyDefined() { var readonlyProfile = new Profile { Name = "readonlyProfile", ClassGrouping = "Grid", FallbackOutput = "<Fallback />", Mappings = new ObservableCollection <Mapping> { new Mapping { Type = StringPropertyName, NameContains = "", Output = "<ReadOnly />", IfReadOnly = true, }, }, }; var result = AnalyzerBase.GetPropertyOutput(readonlyProfile, StringPropertyName, "MyProperty", isReadOnly: false, indent: UnusedIndentValue); Assert.AreEqual("<Fallback />", result); }
public void ReadOnlyPropertiesMatchNotReadOnlyRatherThanFallback() { var readonlyProfile = new Profile { Name = "readonlyProfile", ClassGrouping = "Grid", FallbackOutput = "<Fallback />", Mappings = new ObservableCollection <Mapping> { new Mapping { Type = StringPropertyName, NameContains = "", Output = "<ReadAndWrite />", IfReadOnly = false, }, }, }; var result = AnalyzerBase.GetPropertyOutput(readonlyProfile, StringPropertyName, "MyProperty", isReadOnly: true); Assert.AreEqual("<ReadAndWrite />", result); }