From 1326917a8d478990d135097198b710f1de78f591 Mon Sep 17 00:00:00 2001 From: DamirAinullin Date: Sat, 18 Jun 2016 23:37:43 +0300 Subject: [PATCH] fixes of obvious code mistakes --- .../SharedProject/DesignPropertyDescriptor.cs | 4 +-- .../SharedProject/Navigation/ModuleId.cs | 2 +- .../Navigation/SourceLocation.cs | 2 +- .../SharedProject/ProjectNode.CopyPaste.cs | 3 +-- Common/Product/SharedProject/ProjectNode.cs | 12 +++------ .../Analysis/JavaScript/SourceLocation.cs | 2 +- .../Nodejs/Debugger/DebugEngine/AD7Thread.cs | 4 +-- Nodejs/Product/Npm/SPI/NpmBinCommand.cs | 2 +- Nodejs/Product/Npm/sqlite/SQLite.cs | 7 ++---- .../Profiling/StandaloneTargetView.cs | 2 +- .../ReferenceGenerator/ReferenceGenerator.cs | 25 ++++++++----------- Nodejs/Tests/NpmTests/NpmSearchTests.cs | 4 +-- 12 files changed, 26 insertions(+), 43 deletions(-) diff --git a/Common/Product/SharedProject/DesignPropertyDescriptor.cs b/Common/Product/SharedProject/DesignPropertyDescriptor.cs index a2cbbd427..be0bf5d41 100644 --- a/Common/Product/SharedProject/DesignPropertyDescriptor.cs +++ b/Common/Product/SharedProject/DesignPropertyDescriptor.cs @@ -98,9 +98,7 @@ public override object GetEditor(Type editorBaseType) { public override TypeConverter Converter { get { if (converter == null) { - if (converter == null) { - converter = property.Converter; - } + converter = property.Converter; } return converter; } diff --git a/Common/Product/SharedProject/Navigation/ModuleId.cs b/Common/Product/SharedProject/Navigation/ModuleId.cs index 6c5fefb26..6c4e7bfc4 100644 --- a/Common/Product/SharedProject/Navigation/ModuleId.cs +++ b/Common/Product/SharedProject/Navigation/ModuleId.cs @@ -47,7 +47,7 @@ public override int GetHashCode() { public override bool Equals(object obj) { ModuleId other = obj as ModuleId; - if (null == obj) { + if (null == other) { return false; } if (!_ownerHierarchy.Equals(other._ownerHierarchy)) { diff --git a/Common/Product/SharedProject/Navigation/SourceLocation.cs b/Common/Product/SharedProject/Navigation/SourceLocation.cs index 6714e5e6c..c8fd610af 100644 --- a/Common/Product/SharedProject/Navigation/SourceLocation.cs +++ b/Common/Product/SharedProject/Navigation/SourceLocation.cs @@ -154,7 +154,7 @@ public int Column { public static int Compare(SourceLocation left, SourceLocation right) { if (left < right) return -1; - if (right > left) + if (left > right) return 1; return 0; diff --git a/Common/Product/SharedProject/ProjectNode.CopyPaste.cs b/Common/Product/SharedProject/ProjectNode.CopyPaste.cs index 58c27ecf6..4ac8a74f1 100644 --- a/Common/Product/SharedProject/ProjectNode.CopyPaste.cs +++ b/Common/Product/SharedProject/ProjectNode.CopyPaste.cs @@ -152,9 +152,8 @@ public int Drop(IOleDataObject pDataObject, uint grfKeyState, uint itemid, ref u int returnValue; try { - DropDataType dropDataType = DropDataType.None; pdwEffect = (uint)QueryDropEffect(grfKeyState); - dropDataType = ProcessSelectionDataObject(pDataObject, targetNode, true, (DropEffect)pdwEffect); + DropDataType dropDataType = ProcessSelectionDataObject(pDataObject, targetNode, true, (DropEffect)pdwEffect); if (dropDataType == DropDataType.None) { pdwEffect = (uint)DropEffect.None; } diff --git a/Common/Product/SharedProject/ProjectNode.cs b/Common/Product/SharedProject/ProjectNode.cs index 1b0e799c9..eb8d110d8 100644 --- a/Common/Product/SharedProject/ProjectNode.cs +++ b/Common/Product/SharedProject/ProjectNode.cs @@ -2678,16 +2678,13 @@ protected int CanOverwriteExistingItem(string originalFileName, string computedN return VSConstants.E_INVALIDARG; } - string message = String.Empty; string title = String.Empty; - OLEMSGICON icon = OLEMSGICON.OLEMSGICON_CRITICAL; - OLEMSGBUTTON buttons = OLEMSGBUTTON.OLEMSGBUTTON_OK; OLEMSGDEFBUTTON defaultButton = OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST; // File already exists in project... message box - message = SR.GetString(inProject ? SR.FileAlreadyInProject : SR.FileAlreadyExists, Path.GetFileName(computedNewFileName)); - icon = OLEMSGICON.OLEMSGICON_QUERY; - buttons = OLEMSGBUTTON.OLEMSGBUTTON_YESNO; + string message = SR.GetString(inProject ? SR.FileAlreadyInProject : SR.FileAlreadyExists, Path.GetFileName(computedNewFileName)); + OLEMSGICON icon = OLEMSGICON.OLEMSGICON_QUERY; + OLEMSGBUTTON buttons = OLEMSGBUTTON.OLEMSGBUTTON_YESNO; int msgboxResult = Utilities.ShowMessageBox(this.Site, title, message, icon, buttons, defaultButton); if (msgboxResult == NativeMethods.IDCANCEL) { return (int)E_CANCEL_FILE_ADD; @@ -4569,9 +4566,8 @@ public virtual int AddComponent(VSADDCOMPOPERATION dwAddCompOperation, uint cCom return VSConstants.E_NOTIMPL; } for (int cCount = 0; cCount < cComponents; cCount++) { - VSCOMPONENTSELECTORDATA selectorData = new VSCOMPONENTSELECTORDATA(); IntPtr ptr = rgpcsdComponents[cCount]; - selectorData = (VSCOMPONENTSELECTORDATA)Marshal.PtrToStructure(ptr, typeof(VSCOMPONENTSELECTORDATA)); + VSCOMPONENTSELECTORDATA selectorData = (VSCOMPONENTSELECTORDATA)Marshal.PtrToStructure(ptr, typeof(VSCOMPONENTSELECTORDATA)); if (null == references.AddReferenceFromSelectorData(selectorData)) { //Skip further proccessing since a reference has to be added pResult[0] = VSADDCOMPRESULT.ADDCOMPRESULT_Failure; diff --git a/Nodejs/Product/Analysis/JavaScript/SourceLocation.cs b/Nodejs/Product/Analysis/JavaScript/SourceLocation.cs index 94b025159..2ccc21ed1 100644 --- a/Nodejs/Product/Analysis/JavaScript/SourceLocation.cs +++ b/Nodejs/Product/Analysis/JavaScript/SourceLocation.cs @@ -161,7 +161,7 @@ public int Column public static int Compare(SourceLocation left, SourceLocation right) { if (left < right) return -1; - if (right > left) return 1; + if (left > right) return 1; return 0; } diff --git a/Nodejs/Product/Nodejs/Debugger/DebugEngine/AD7Thread.cs b/Nodejs/Product/Nodejs/Debugger/DebugEngine/AD7Thread.cs index a1fc390cf..958a51473 100644 --- a/Nodejs/Product/Nodejs/Debugger/DebugEngine/AD7Thread.cs +++ b/Nodejs/Product/Nodejs/Debugger/DebugEngine/AD7Thread.cs @@ -181,12 +181,10 @@ int IDebugThread100.GetFlags(out uint flags) { } int IDebugThread100.GetThreadProperties100(uint dwFields, THREADPROPERTIES100[] props) { - int hRes = VSConstants.S_OK; - // Invoke GetThreadProperties to get the VS7/8/9 properties THREADPROPERTIES[] props90 = new THREADPROPERTIES[1]; enum_THREADPROPERTY_FIELDS dwFields90 = (enum_THREADPROPERTY_FIELDS)(dwFields & 0x3f); - hRes = ((IDebugThread2)this).GetThreadProperties(dwFields90, props90); + int hRes = ((IDebugThread2)this).GetThreadProperties(dwFields90, props90); props[0].bstrLocation = props90[0].bstrLocation; props[0].bstrName = props90[0].bstrName; props[0].bstrPriority = props90[0].bstrPriority; diff --git a/Nodejs/Product/Npm/SPI/NpmBinCommand.cs b/Nodejs/Product/Npm/SPI/NpmBinCommand.cs index 4cd29001d..b846d1e6f 100644 --- a/Nodejs/Product/Npm/SPI/NpmBinCommand.cs +++ b/Nodejs/Product/Npm/SPI/NpmBinCommand.cs @@ -43,7 +43,7 @@ public string BinDirectory { if (null == _binDirectory) { var temp = StandardOutput; if (null != temp) { - temp.Trim(); + temp = temp.Trim(); if (temp.Length > 0) { // The standard output contains an informational // message added by the base command class through diff --git a/Nodejs/Product/Npm/sqlite/SQLite.cs b/Nodejs/Product/Npm/sqlite/SQLite.cs index 4f5aeee4f..2d4274e45 100644 --- a/Nodejs/Product/Npm/sqlite/SQLite.cs +++ b/Nodejs/Product/Npm/sqlite/SQLite.cs @@ -2091,9 +2091,8 @@ public int ExecuteNonQuery () Debug.WriteLine ("Executing: " + this); } - var r = SQLite3.Result.OK; var stmt = Prepare (); - r = SQLite3.Step (stmt); + var r = SQLite3.Step (stmt); Finalize (stmt); if (r == SQLite3.Result.Done) { int rowsAffected = SQLite3.Changes (_conn.Handle); @@ -2400,8 +2399,6 @@ public int ExecuteNonQuery (object[] source) Debug.WriteLine ("Executing: " + CommandText); } - var r = SQLite3.Result.OK; - if (!Initialized) { Statement = Prepare (); Initialized = true; @@ -2413,7 +2410,7 @@ public int ExecuteNonQuery (object[] source) SQLiteCommand.BindParameter (Statement, i + 1, source [i], Connection.StoreDateTimeAsTicks); } } - r = SQLite3.Step (Statement); + var r = SQLite3.Step (Statement); if (r == SQLite3.Result.Done) { int rowsAffected = SQLite3.Changes (Connection.Handle); diff --git a/Nodejs/Product/Profiling/Profiling/StandaloneTargetView.cs b/Nodejs/Product/Profiling/Profiling/StandaloneTargetView.cs index 309d2e9f2..83644819c 100644 --- a/Nodejs/Product/Profiling/Profiling/StandaloneTargetView.cs +++ b/Nodejs/Product/Profiling/Profiling/StandaloneTargetView.cs @@ -152,7 +152,7 @@ void StandaloneTargetView_PropertyChanged(object sender, PropertyChangedEventArg WorkingDirectory.IndexOfAny(Path.GetInvalidPathChars()) == -1 && (Path.IsPathRooted(ScriptPath) || Path.IsPathRooted(WorkingDirectory)) && File.Exists(Path.Combine(WorkingDirectory, ScriptPath)) && - (string.IsNullOrEmpty(WorkingDirectory) || Directory.Exists(WorkingDirectory)) && + (WorkingDirectory == string.Empty || Directory.Exists(WorkingDirectory)) && (File.Exists(InterpreterPath)); } } diff --git a/Nodejs/Product/ReferenceGenerator/ReferenceGenerator.cs b/Nodejs/Product/ReferenceGenerator/ReferenceGenerator.cs index 67f7c4c2c..b28d295bc 100644 --- a/Nodejs/Product/ReferenceGenerator/ReferenceGenerator.cs +++ b/Nodejs/Product/ReferenceGenerator/ReferenceGenerator.cs @@ -15,11 +15,8 @@ //*********************************************************// using System; using System.Collections.Generic; -using System.Diagnostics; using System.IO; -using System.Linq; using System.Text; -using System.Threading.Tasks; using System.Web.Script.Serialization; using System.Xml; using Microsoft.NodejsTools; @@ -190,7 +187,7 @@ private void GenerateModuleWorker(dynamic module, int indentation, string name) case "join": body = ReferenceCode.PathJoinBody; break; } } - GenerateMethod(name, method, indentation + 1, body); + GenerateMethod(method, indentation + 1, body); } } @@ -200,7 +197,7 @@ private void GenerateModuleWorker(dynamic module, int indentation, string name) if (module.ContainsKey("classes")) { foreach (var klass in module["classes"]) { - GenerateClass(name, klass, indentation + 1); + GenerateClass(klass, indentation + 1); } } @@ -210,7 +207,7 @@ private void GenerateModuleWorker(dynamic module, int indentation, string name) GenerateProperties(module["properties"], indentation + 1, specializer); } - _output.AppendFormat("}}", name); + _output.Append("}}"); } private Dictionary> PropertySpecializations = MakePropertySpecializations(); @@ -242,7 +239,7 @@ private static string ProcessPropertySpecialization(string propertyName) { return null; } - private void GenerateClass(string modName, dynamic klass, int indentation) { + private void GenerateClass(dynamic klass, int indentation) { string className = FixClassName(klass["name"]); _output.Append(' ', indentation * 4); _output.AppendFormat("function _{0}() {{", className); @@ -250,7 +247,7 @@ private void GenerateClass(string modName, dynamic klass, int indentation) { if (klass.ContainsKey("methods")) { foreach (var method in klass["methods"]) { - GenerateMethod(modName + "." + className, method, indentation + 1); + GenerateMethod(method, indentation + 1); } } @@ -294,13 +291,13 @@ private void GenerateProperties(dynamic properties, int indentation, FuncBoolean") != -1) { + if (desc.IndexOf("Boolean", StringComparison.Ordinal) != -1) { value = "true"; - } else if (desc.IndexOf("Number") != -1) { + } else if (desc.IndexOf("Number", StringComparison.Ordinal) != -1) { value = "0"; - } else if (desc.IndexOf("Readable Stream") != -1) { + } else if (desc.IndexOf("Readable Stream", StringComparison.Ordinal) != -1) { value = "require('stream').Readable()"; - } else if (desc.IndexOf("Writable Stream") != -1 || textRaw == "process.stderr") { + } else if (desc.IndexOf("Writable Stream", StringComparison.Ordinal) != -1 || textRaw == "process.stderr") { value = "require('stream').Writable()"; } else if (!String.IsNullOrWhiteSpace(textRaw)) { int start, end; @@ -394,7 +391,7 @@ private void GenerateEvents(dynamic events, int indentation) { _output.AppendLine("}"); } - private void GenerateMethod(string fullName, dynamic method, int indentation, string body = null) { + private void GenerateMethod(dynamic method, int indentation, string body = null) { _output.Append(' ', indentation * 4); _output.AppendFormat("this.{0} = function(", method["name"]); var signature = method["signatures"][0]; @@ -475,7 +472,7 @@ private void GenerateMethod(string fullName, dynamic method, int indentation, st _output.AppendLine(body); } else if (method["name"].StartsWith("create") && method["name"].Length > 6) { _output.Append(' ', indentation * 4); - _output.AppendFormat("return new this.{1}();", fullName, method["name"].Substring(6)); + _output.AppendFormat("return new this.{0}();", method["name"].Substring(6)); _output.AppendLine(); } _output.Append(' ', indentation * 4); diff --git a/Nodejs/Tests/NpmTests/NpmSearchTests.cs b/Nodejs/Tests/NpmTests/NpmSearchTests.cs index 3e73d9861..727d13427 100644 --- a/Nodejs/Tests/NpmTests/NpmSearchTests.cs +++ b/Nodejs/Tests/NpmTests/NpmSearchTests.cs @@ -115,9 +115,7 @@ private void CheckPackage( private IList GetTestPackageList( string cachePath, out IDictionary byName) { - IList target = new List(); - - target = new NpmGetCatalogCommand(string.Empty, cachePath, false, RegistryUrl).GetCatalogPackagesAsync(string.Empty, new Uri(RegistryUrl)).GetAwaiter().GetResult().ToList(); + IList target = new NpmGetCatalogCommand(string.Empty, cachePath, false, RegistryUrl).GetCatalogPackagesAsync(string.Empty, new Uri(RegistryUrl)).GetAwaiter().GetResult().ToList(); // Do this after because package names can be split across multiple // lines and therefore may change after the IPackage is initially created.