From ee2a4e29cb15e4b26123b84aad84876dc69008c9 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Thu, 23 Jul 2009 16:28:19 +0000 Subject: [PATCH] Fixed code analysis AddIn (fixed support for custom MSBuild loggers, ported SuppressMessageCommand to ITextEditor). git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@4523 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../Src/SuppressMessageCommand.cs | 7 ++- .../Project/Gui/SearchResultNode.cs | 2 +- .../Document/OffsetChangeMap.cs | 48 +++++++++++++++++-- .../Highlighting/HighlightedInlineBuilder.cs | 4 +- .../Rendering/VisualLine.cs | 2 + .../ICSharpCode.AvalonEdit/Utils/ThrowUtil.cs | 3 +- .../Project/MSBuildEngine/MSBuildEngine.cs | 14 ++++-- .../Implementations/SearchClassReturnType.cs | 2 +- .../Src/log4netLoggingService.cs | 11 +++-- 9 files changed, 71 insertions(+), 22 deletions(-) diff --git a/src/AddIns/Misc/CodeAnalysis/Src/SuppressMessageCommand.cs b/src/AddIns/Misc/CodeAnalysis/Src/SuppressMessageCommand.cs index a2c19200c7..c1705c5ca6 100644 --- a/src/AddIns/Misc/CodeAnalysis/Src/SuppressMessageCommand.cs +++ b/src/AddIns/Misc/CodeAnalysis/Src/SuppressMessageCommand.cs @@ -42,10 +42,10 @@ namespace ICSharpCode.CodeAnalysis if (p.CompilationUnit == null || p.FileName == null || p.Line <= 0) continue; IViewContent viewContent = FileService.OpenFile(p.FileName); - ITextEditorControlProvider provider = viewContent as ITextEditorControlProvider; + ITextEditorProvider provider = viewContent as ITextEditorProvider; if (provider == null) continue; - IDocument document = new TextEditorDocument(provider.TextEditorControl.Document); + IDocument document = provider.TextEditor.Document; if (p.Line >= document.TotalNumberOfLines) continue; IDocumentLine line = document.GetLine(p.Line); @@ -60,8 +60,7 @@ namespace ICSharpCode.CodeAnalysis string code = codegen.GenerateCode(CreateSuppressAttribute(p.CompilationUnit, tag), indentation.ToString()); if (!code.EndsWith("\n")) code += Environment.NewLine; document.Insert(line.Offset, code); - provider.TextEditorControl.ActiveTextAreaControl.Caret.Line = p.Line - 1; - provider.TextEditorControl.ActiveTextAreaControl.ScrollToCaret(); + provider.TextEditor.JumpTo(p.Line, p.Column); TaskService.Remove(t); ParserService.ParseViewContent(viewContent); } diff --git a/src/AddIns/Misc/SearchAndReplace/Project/Gui/SearchResultNode.cs b/src/AddIns/Misc/SearchAndReplace/Project/Gui/SearchResultNode.cs index 38eb9c5d1a..80d3e36d4f 100644 --- a/src/AddIns/Misc/SearchAndReplace/Project/Gui/SearchResultNode.cs +++ b/src/AddIns/Misc/SearchAndReplace/Project/Gui/SearchResultNode.cs @@ -96,7 +96,7 @@ namespace SearchAndReplace if (displayText != null) { textBlock.Inlines.Add(displayText); } else if (inlineBuilder != null) { - textBlock.Inlines.AddRange(inlineBuilder.CreateInlines()); + textBlock.Inlines.AddRange(inlineBuilder.CreateRuns()); } if (showFileName) { diff --git a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Document/OffsetChangeMap.cs b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Document/OffsetChangeMap.cs index 09d815c2c7..3b73bb2160 100644 --- a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Document/OffsetChangeMap.cs +++ b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Document/OffsetChangeMap.cs @@ -5,10 +5,12 @@ // $Revision$ // -using ICSharpCode.AvalonEdit.Utils; using System; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.Diagnostics.CodeAnalysis; + +using ICSharpCode.AvalonEdit.Utils; namespace ICSharpCode.AvalonEdit.Document { @@ -59,11 +61,15 @@ namespace ICSharpCode.AvalonEdit.Document /// Describes a series of offset changes. /// [Serializable] + [SuppressMessage("Microsoft.Naming", "CA1710:IdentifiersShouldHaveCorrectSuffix", + Justification="It's a mapping old offsets -> new offsets")] public sealed class OffsetChangeMap : Collection { /// /// Immutable OffsetChangeMap that is empty. /// + [SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", + Justification="The Empty instance is immutable")] public static readonly OffsetChangeMap Empty = new OffsetChangeMap(Utils.Empty.ReadOnlyCollection); /// @@ -138,7 +144,7 @@ namespace ICSharpCode.AvalonEdit.Document /// This represents the offset of a document change (either insertion or removal, not both at once). /// [Serializable] - public struct OffsetChangeMapEntry + public struct OffsetChangeMapEntry : IEquatable { readonly int offset; readonly int removalLength; @@ -155,7 +161,7 @@ namespace ICSharpCode.AvalonEdit.Document /// The number of characters removed. /// Returns 0 if this entry represents an insertion. /// - public int RemovalLength { + public int RemovalLength { get { return removalLength; } } @@ -206,5 +212,41 @@ namespace ICSharpCode.AvalonEdit.Document this.removalLength = removalLength; this.insertionLength = insertionLength; } + + /// + public override int GetHashCode() + { + unchecked { + return offset + 3559 * insertionLength + 3571 * removalLength; + } + } + + /// + public override bool Equals(object obj) + { + return obj is OffsetChangeMapEntry && this.Equals((OffsetChangeMapEntry)obj); + } + + /// + public bool Equals(OffsetChangeMapEntry other) + { + return offset == other.offset && insertionLength == other.insertionLength && removalLength == other.removalLength; + } + + /// + /// Tests the two entries for equality. + /// + public static bool operator ==(OffsetChangeMapEntry left, OffsetChangeMapEntry right) + { + return left.Equals(right); + } + + /// + /// Tests the two entries for inequality. + /// + public static bool operator !=(OffsetChangeMapEntry left, OffsetChangeMapEntry right) + { + return !left.Equals(right); + } } } diff --git a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/HighlightedInlineBuilder.cs b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/HighlightedInlineBuilder.cs index 76b18bac6a..13e312b883 100644 --- a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/HighlightedInlineBuilder.cs +++ b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/HighlightedInlineBuilder.cs @@ -52,7 +52,7 @@ namespace ICSharpCode.AvalonEdit.Highlighting int GetIndexForOffset(int offset) { if (offset < 0 || offset > text.Length) - throw new ArgumentOutOfRangeException(); + throw new ArgumentOutOfRangeException("offset"); int index = stateChangeOffsets.BinarySearch(offset); if (index < 0) { index = ~index; @@ -152,7 +152,7 @@ namespace ICSharpCode.AvalonEdit.Highlighting /// /// Creates WPF Run instances that can be used for TextBlock.Inlines. /// - public Run[] CreateInlines() + public Run[] CreateRuns() { Run[] runs = new Run[stateChanges.Count]; for (int i = 0; i < runs.Length; i++) { diff --git a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Rendering/VisualLine.cs b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Rendering/VisualLine.cs index 44f5a6124b..915752c838 100644 --- a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Rendering/VisualLine.cs +++ b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Rendering/VisualLine.cs @@ -384,6 +384,8 @@ namespace ICSharpCode.AvalonEdit.Rendering return mode == CaretPositioningMode.Normal; } + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", MessageId = "mode", + Justification = "make method consistent with HasImplicitStopAtLineStart; might depend on mode in the future")] static bool HasImplicitStopAtLineEnd(CaretPositioningMode mode) { return true; diff --git a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Utils/ThrowUtil.cs b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Utils/ThrowUtil.cs index 4ff4f4de14..fb366b32ef 100644 --- a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Utils/ThrowUtil.cs +++ b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Utils/ThrowUtil.cs @@ -6,6 +6,7 @@ // using System; +using System.Globalization; namespace ICSharpCode.AvalonEdit.Utils { @@ -42,7 +43,7 @@ namespace ICSharpCode.AvalonEdit.Utils public static int CheckInRangeInclusive(int val, string parameterName, int lower, int upper) { if (val < lower || val > upper) - throw new ArgumentOutOfRangeException(parameterName, val, "Expected: " + lower.ToString() + " <= " + parameterName + " <= " + upper.ToString()); + throw new ArgumentOutOfRangeException(parameterName, val, "Expected: " + lower.ToString(CultureInfo.InvariantCulture) + " <= " + parameterName + " <= " + upper.ToString(CultureInfo.InvariantCulture)); return val; } diff --git a/src/Main/Base/Project/Src/Project/MSBuildEngine/MSBuildEngine.cs b/src/Main/Base/Project/Src/Project/MSBuildEngine/MSBuildEngine.cs index 6e6dd9d5d0..8be8bddad6 100644 --- a/src/Main/Base/Project/Src/Project/MSBuildEngine/MSBuildEngine.cs +++ b/src/Main/Base/Project/Src/Project/MSBuildEngine/MSBuildEngine.cs @@ -187,6 +187,14 @@ namespace ICSharpCode.SharpDevelop.Project InterestingTasks.AddRange(MSBuildEngine.CompileTaskNames); + List loggers = new List { + new SharpDevelopLogger(this), + //new BuildLogFileLogger(fileName + ".log", LoggerVerbosity.Diagnostic) + }; + foreach (IMSBuildAdditionalLogger loggerProvider in MSBuildEngine.AdditionalMSBuildLoggers) { + loggers.Add(loggerProvider.CreateLogger(this)); + } + // Get ParallelMSBuildManager (or create a new one if one doesn't exist already). // The serviceContainer will automatically dispose it after the build has completed. ParallelMSBuildManager manager = (ParallelMSBuildManager)serviceContainer.GetOrCreateService( @@ -226,10 +234,6 @@ namespace ICSharpCode.SharpDevelop.Project string fileName = project.FileName; string[] targets = { options.Target.TargetName }; BuildRequestData requestData = new BuildRequestData(fileName, globalProperties, null, targets, new HostServices()); - ILogger[] loggers = { - new SharpDevelopLogger(this), - //new BuildLogFileLogger(fileName + ".log", LoggerVerbosity.Diagnostic) - }; manager.StartBuild(requestData, loggers, OnComplete); } @@ -285,7 +289,7 @@ namespace ICSharpCode.SharpDevelop.Project buildInProcess = true; } LoggingService.Info("Start job (buildInProcess=" + buildInProcess + "): " + job.ToString()); - */ + */ static string EnsureBackslash(string path) { diff --git a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/SearchClassReturnType.cs b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/SearchClassReturnType.cs index 765c10a37d..5b14c648a2 100644 --- a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/SearchClassReturnType.cs +++ b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/SearchClassReturnType.cs @@ -13,7 +13,7 @@ namespace ICSharpCode.SharpDevelop.Dom { /// /// The SearchClassReturnType is used when only a part of the class name is known and the - /// type can only be resolved on demand (the ConvertVisitor uses SearchClassReturnType's). + /// type can only be resolved on demand (the ConvertVisitor uses SearchClassReturnTypes). /// public sealed class SearchClassReturnType : ProxyReturnType { diff --git a/src/Main/ICSharpCode.SharpDevelop.Sda/Src/log4netLoggingService.cs b/src/Main/ICSharpCode.SharpDevelop.Sda/Src/log4netLoggingService.cs index 1e5a20e978..b1b85157c8 100644 --- a/src/Main/ICSharpCode.SharpDevelop.Sda/Src/log4netLoggingService.cs +++ b/src/Main/ICSharpCode.SharpDevelop.Sda/Src/log4netLoggingService.cs @@ -6,6 +6,7 @@ // using System; +using System.Globalization; using System.IO; using ICSharpCode.Core.Services; using log4net; @@ -30,7 +31,7 @@ namespace ICSharpCode.SharpDevelop.Sda public void DebugFormatted(string format, params object[] args) { - log.DebugFormat(format, args); + log.DebugFormat(CultureInfo.InvariantCulture, format, args); } public void Info(object message) @@ -40,7 +41,7 @@ namespace ICSharpCode.SharpDevelop.Sda public void InfoFormatted(string format, params object[] args) { - log.InfoFormat(format, args); + log.InfoFormat(CultureInfo.InvariantCulture, format, args); } public void Warn(object message) @@ -55,7 +56,7 @@ namespace ICSharpCode.SharpDevelop.Sda public void WarnFormatted(string format, params object[] args) { - log.WarnFormat(format, args); + log.WarnFormat(CultureInfo.InvariantCulture, format, args); } public void Error(object message) @@ -70,7 +71,7 @@ namespace ICSharpCode.SharpDevelop.Sda public void ErrorFormatted(string format, params object[] args) { - log.ErrorFormat(format, args); + log.ErrorFormat(CultureInfo.InvariantCulture, format, args); } public void Fatal(object message) @@ -85,7 +86,7 @@ namespace ICSharpCode.SharpDevelop.Sda public void FatalFormatted(string format, params object[] args) { - log.FatalFormat(format, args); + log.FatalFormat(CultureInfo.InvariantCulture, format, args); } public bool IsDebugEnabled {