diff options
author | Karsten Heimrich <karsten.heimrich@qt.io> | 2022-10-04 10:21:03 +0200 |
---|---|---|
committer | Karsten Heimrich <karsten.heimrich@qt.io> | 2022-10-05 11:52:31 +0000 |
commit | 8a732a67ad148bf797cfdbdc349930b79dd010a9 (patch) | |
tree | 420687ab3536e38b5f787772c7ffcc8118fc3274 | |
parent | 9f2c3c23af6b5e98459024c34823e806a375f40c (diff) |
Fix expression is always 'true' or always 'false'
Change-Id: I95a9f9b4e7512542a7a3de7b61029af4de8832b3
Reviewed-by: Karsten Heimrich <karsten.heimrich@qt.io>
-rw-r--r-- | QtVsTest/MacroServer.cs | 14 | ||||
-rw-r--r-- | QtVsTools.Core/Common/Json/SerializableEnum.cs | 8 | ||||
-rw-r--r-- | QtVsTools.Core/Common/Json/Serializer.cs | 5 | ||||
-rw-r--r-- | QtVsTools.Core/Common/QtVSIPSettingsShared.cs | 2 | ||||
-rw-r--r-- | QtVsTools.Core/HelperFunctions.cs | 15 | ||||
-rw-r--r-- | QtVsTools.Core/QtModules.cs | 11 | ||||
-rw-r--r-- | QtVsTools.Package/Legacy/Translation.cs | 9 | ||||
-rw-r--r-- | QtVsTools.Package/Options/QtVersionsTable.cs | 8 | ||||
-rw-r--r-- | QtVsTools.Package/Package/QtMsBuildConverter.cs | 4 | ||||
-rw-r--r-- | QtVsTools.Package/Package/QtProjectContextMenu.cs | 63 | ||||
-rw-r--r-- | QtVsTools.Package/QtMsBuild/QtProjectBuild.cs | 51 | ||||
-rw-r--r-- | QtVsTools.Package/QtMsBuild/QtProjectTracker.cs | 5 | ||||
-rw-r--r-- | QtVsTools.RegExpr/expression/CharClassSet.cs | 2 | ||||
-rw-r--r-- | QtVsTools.Wizards/ProjectWizard/ConfigPage.xaml.cs | 7 | ||||
-rw-r--r-- | QtVsTools.Wizards/ProjectWizard/ProjectTemplateWizard.cs | 4 |
15 files changed, 86 insertions, 122 deletions
diff --git a/QtVsTest/MacroServer.cs b/QtVsTest/MacroServer.cs index bab0f2b5..1cd3db2d 100644 --- a/QtVsTest/MacroServer.cs +++ b/QtVsTest/MacroServer.cs @@ -69,8 +69,8 @@ namespace QtVsTest.Macros public async Task LoopAsync() { await JoinableTaskFactory.SwitchToMainThreadAsync(Loop.Token); - var DTE = await Package.GetServiceAsync(typeof(DTE)) as DTE2; - var mainWindowHWnd = new IntPtr((long)DTE.MainWindow.HWnd); + var dte = await Package.GetServiceAsync(typeof(DTE)) as DTE2; + var mainWindowHWnd = new IntPtr((long)dte.MainWindow.HWnd); await TaskScheduler.Default; var pipeName = string.Format("QtVSTest_{0}", Process.GetCurrentProcess().Id); @@ -99,7 +99,7 @@ namespace QtVsTest.Macros break; var macro = new Macro( - Package, DTE, mainWindowHWnd, JoinableTaskFactory, Loop.Token); + Package, dte, mainWindowHWnd, JoinableTaskFactory, Loop.Token); await macro.CompileAsync(Encoding.UTF8.GetString(data)); if (macro.AutoRun) await macro.RunAsync(); @@ -121,12 +121,10 @@ namespace QtVsTest.Macros pipe.WaitForPipeDrain(); - if (macro != null && macro.Ok && macro.AutoRun && macro.QuitWhenDone) { + if (macro.Ok && macro.AutoRun && macro.QuitWhenDone) { await JoinableTaskFactory.SwitchToMainThreadAsync(Loop.Token); - if (DTE != null) { - DTE.Solution.Close(false); - DTE.Quit(); - } + dte.Solution.Close(false); + dte.Quit(); await TaskScheduler.Default; Loop.Cancel(); } diff --git a/QtVsTools.Core/Common/Json/SerializableEnum.cs b/QtVsTools.Core/Common/Json/SerializableEnum.cs index c5e563f5..15b67e3f 100644 --- a/QtVsTools.Core/Common/Json/SerializableEnum.cs +++ b/QtVsTools.Core/Common/Json/SerializableEnum.cs @@ -45,11 +45,11 @@ namespace QtVsTools.Json return enumValue.ToString(); var member = type.GetMember(enumValue.ToString()); - if (member == null || member.Length == 0) + if (member.Length == 0) return enumValue.ToString(); var attribs = member[0].GetCustomAttributes(typeof(EnumStringAttribute), false); - if (attribs == null || attribs.Length == 0) + if (attribs.Length == 0) return enumValue.ToString(); if (attribs.FirstOrDefault(x => x is EnumStringAttribute) is EnumStringAttribute a) @@ -65,13 +65,13 @@ namespace QtVsTools.Json return default(TEnum); var members = typeof(TEnum).GetMembers(); - if (members == null || members.Length == 0) + if (members.Length == 0) return default(TEnum); var member = members.Where(x => { var attribs = x.GetCustomAttributes(typeof(EnumStringAttribute), false); - if (attribs == null || attribs.Length == 0) + if (attribs.Length == 0) return false; if (attribs.FirstOrDefault(y => y is EnumStringAttribute) is EnumStringAttribute a) diff --git a/QtVsTools.Core/Common/Json/Serializer.cs b/QtVsTools.Core/Common/Json/Serializer.cs index 7af207e9..fbb2db9e 100644 --- a/QtVsTools.Core/Common/Json/Serializer.cs +++ b/QtVsTools.Core/Common/Json/Serializer.cs @@ -107,9 +107,6 @@ namespace QtVsTools.Json private bool Initialize(Type type) { var settings = new DataContractJsonSerializerSettings(); - if (settings == null) - return false; - settings.DataContractSurrogate = new DataContractSurrogate { Serializer = this }; settings.EmitTypeInformation = EmitTypeInformation.Never; settings.UseSimpleDictionaryFormat = true; @@ -132,7 +129,7 @@ namespace QtVsTools.Json return new JsonData() { Stream = stream }; } catch (Exception exception) { exception.Log(); - if (stream != null && stream.CanRead && stream.Length > 0) + if (stream.CanRead && stream.Length > 0) stream.Dispose(); return null; } diff --git a/QtVsTools.Core/Common/QtVSIPSettingsShared.cs b/QtVsTools.Core/Common/QtVSIPSettingsShared.cs index 7cee13a6..5d1988fc 100644 --- a/QtVsTools.Core/Common/QtVSIPSettingsShared.cs +++ b/QtVsTools.Core/Common/QtVSIPSettingsShared.cs @@ -93,8 +93,6 @@ namespace QtVsTools.Common foreach (VCFileConfiguration config in vcfile?.FileConfigurations as IVCCollection) { tool = new QtCustomBuildTool(config); - if (tool == null) - continue; configName = config.Name.Remove(config.Name.IndexOf('|')); var vcConfig = config.ProjectConfiguration as VCConfiguration; platformName = (vcConfig.Platform as VCPlatform).Name; diff --git a/QtVsTools.Core/HelperFunctions.cs b/QtVsTools.Core/HelperFunctions.cs index 9ccb0822..96460715 100644 --- a/QtVsTools.Core/HelperFunctions.cs +++ b/QtVsTools.Core/HelperFunctions.cs @@ -1412,24 +1412,25 @@ namespace QtVsTools.Core VersionInfo = QtVersionManager.The().GetVersionInfo( QtVersionManager.The().GetDefaultVersion()); } - bool isOS64Bit = System.Environment.Is64BitOperatingSystem; - bool isQt64Bit = VersionInfo.is64Bit(); string vcPath = VCPath; if (vcPath == "") return false; + bool osIs64Bit = System.Environment.Is64BitOperatingSystem; + bool qtIs64Bit = VersionInfo.is64Bit(); + string comspecPath = Environment.GetEnvironmentVariable("COMSPEC"); string vcVarsCmd = ""; string vcVarsArg = ""; - if (isOS64Bit && isQt64Bit) + if (osIs64Bit && qtIs64Bit) vcVarsCmd = Path.Combine(vcPath, @"Auxiliary\Build\vcvars64.bat"); - else if (!isOS64Bit && !isQt64Bit) - vcVarsCmd = Path.Combine(vcPath, @"Auxiliary\Build\vcvars32.bat"); - else if (isOS64Bit && !isQt64Bit) + else if (osIs64Bit /* && !QtIs64Bit */) vcVarsCmd = Path.Combine(vcPath, @"Auxiliary\Build\vcvarsamd64_x86.bat"); - else if (!isOS64Bit && isQt64Bit) + else if (/* !OsIs64Bit && */ qtIs64Bit) vcVarsCmd = Path.Combine(vcPath, @"Auxiliary\Build\vcvarsx86_amd64.bat"); + else /* !OsIs64Bit && !QtIs64Bit */ + vcVarsCmd = Path.Combine(vcPath, @"Auxiliary\Build\vcvars32.bat"); Messages.Print($"vcvars: {vcVarsCmd}"); diff --git a/QtVsTools.Core/QtModules.cs b/QtVsTools.Core/QtModules.cs index 58169b38..37954b97 100644 --- a/QtVsTools.Core/QtModules.cs +++ b/QtVsTools.Core/QtModules.cs @@ -58,25 +58,24 @@ namespace QtVsTools.Core public List<QtModule> GetAvailableModules(uint major) { - if (major < 6) { + switch (major) { + case var _ when major < 6: if (qt5list == null) { qt5list = new List<QtModule>(qt5modules.Count); foreach (var entry in qt5modules) qt5list.Add(entry.Value); } return qt5list; - } - if (major == 6) { + case var _ when major == 6: if (qt6list == null) { qt6list = new List<QtModule>(qt6modules.Count); foreach (var entry in qt6modules) qt6list.Add(entry.Value); } return qt6list; - } - if (major > 6) + default: throw new QtVSException("Unsupported Qt version."); - return null; + } } private QtModules() diff --git a/QtVsTools.Package/Legacy/Translation.cs b/QtVsTools.Package/Legacy/Translation.cs index f213ed36..c1757fd2 100644 --- a/QtVsTools.Package/Legacy/Translation.cs +++ b/QtVsTools.Package/Legacy/Translation.cs @@ -52,10 +52,11 @@ namespace QtVsTools.Legacy } if (tsFiles == null) { - tsFiles = (qtProject.VCProject - .GetFilesEndingWith(".ts") as IVCCollection) - .Cast<VCFile>() - .Select(vcFile => vcFile.RelativePath); + if (qtProject.VCProject.GetFilesEndingWith(".ts") is IVCCollection collection) { + tsFiles = collection + .Cast<VCFile>() + .Select(vcFile => vcFile.RelativePath); + } } if (tsFiles != null) { diff --git a/QtVsTools.Package/Options/QtVersionsTable.cs b/QtVsTools.Package/Options/QtVersionsTable.cs index 43a6b568..da1c8fbc 100644 --- a/QtVsTools.Package/Options/QtVersionsTable.cs +++ b/QtVsTools.Package/Options/QtVersionsTable.cs @@ -531,13 +531,9 @@ namespace QtVsTools.Options static object GetBinding(FrameworkElement control) { - if (control == null - || control.BindingGroup == null - || control.BindingGroup.Items == null - || control.BindingGroup.Items.Count == 0) { + if (control?.BindingGroup == null) return null; - } - return control.BindingGroup.Items[0]; + return control.BindingGroup.Items.Count == 0 ? null : control.BindingGroup.Items[0]; } static DataGridCell FindContainingCell(DependencyObject control) diff --git a/QtVsTools.Package/Package/QtMsBuildConverter.cs b/QtVsTools.Package/Package/QtMsBuildConverter.cs index fd4e5f76..6406c6db 100644 --- a/QtVsTools.Package/Package/QtMsBuildConverter.cs +++ b/QtVsTools.Package/Package/QtMsBuildConverter.cs @@ -110,8 +110,10 @@ namespace QtVsTools projCount + 1, projectPaths.Count, Path.GetFileNameWithoutExtension(projectPath)), projectPaths.Count, projCount); - if (waitDialog.Canceled) + if (waitDialog.Canceled) { + canceled = true; break; + } } if (!ConvertProject(projectPath)) { if (waitDialog != null) diff --git a/QtVsTools.Package/Package/QtProjectContextMenu.cs b/QtVsTools.Package/Package/QtProjectContextMenu.cs index f77ff62a..bc86c4fe 100644 --- a/QtVsTools.Package/Package/QtProjectContextMenu.cs +++ b/QtVsTools.Package/Package/QtProjectContextMenu.cs @@ -162,13 +162,14 @@ namespace QtVsTools var project = HelperFunctions.GetSelectedProject(QtVsToolsPackage.Instance.Dte); var isQtProject = HelperFunctions.IsVsToolsProject(project); var isQMakeProject = HelperFunctions.IsQtProject(project); - var isQtMsBuildEnabled = QtProject.IsQtMsBuildEnabled(project); - if (!isQtProject && !isQMakeProject) { command.Enabled = command.Visible = false; return; } + var isQtMsBuildEnabled = QtProject.IsQtMsBuildEnabled(project); + + var status = vsCommandStatus.vsCommandStatusSupported; switch ((CommandId)command.CommandID.ID) { case CommandId.ImportPriFileProjectId: case CommandId.ExportPriFileProjectId: @@ -182,50 +183,32 @@ namespace QtVsTools command.Visible = true; command.Enabled = Translation.ToolsAvailable(project); break; - case CommandId.QtProjectSettingsProjectId: { - var status = vsCommandStatus.vsCommandStatusSupported; - if (project != null) { - if (isQtProject) - status |= vsCommandStatus.vsCommandStatusEnabled; - else if (isQMakeProject) - status |= vsCommandStatus.vsCommandStatusInvisible; - } - command.Enabled = ((status & vsCommandStatus.vsCommandStatusEnabled) != 0); - command.Visible = ((status & vsCommandStatus.vsCommandStatusInvisible) == 0); - } + case CommandId.QtProjectSettingsProjectId: + if (isQtProject) + status |= vsCommandStatus.vsCommandStatusEnabled; + else + status |= vsCommandStatus.vsCommandStatusInvisible; + command.Enabled = ((status & vsCommandStatus.vsCommandStatusEnabled) != 0); + command.Visible = ((status & vsCommandStatus.vsCommandStatusInvisible) == 0); break; - case CommandId.ChangeProjectQtVersionProjectId: { - var status = vsCommandStatus.vsCommandStatusSupported; - if ((project == null) || isQtProject) - status |= vsCommandStatus.vsCommandStatusInvisible; - else if (isQMakeProject) - status |= vsCommandStatus.vsCommandStatusEnabled; - else - status |= vsCommandStatus.vsCommandStatusInvisible; - command.Enabled = ((status & vsCommandStatus.vsCommandStatusEnabled) != 0); - command.Visible = ((status & vsCommandStatus.vsCommandStatusInvisible) == 0); - } + case CommandId.ChangeProjectQtVersionProjectId: + if (isQMakeProject) + status |= vsCommandStatus.vsCommandStatusEnabled; + else + status |= vsCommandStatus.vsCommandStatusInvisible; + command.Enabled = ((status & vsCommandStatus.vsCommandStatusEnabled) != 0); + command.Visible = ((status & vsCommandStatus.vsCommandStatusInvisible) == 0); break; - case CommandId.ProjectConvertToQtMsBuild: { - if (project == null || (!isQtProject && !isQMakeProject)) { - command.Visible = false; - command.Enabled = false; - } else if (isQtMsBuildEnabled) { - command.Visible = true; - command.Enabled = false; - } else { - command.Visible = true; - command.Enabled = true; - } - } + case CommandId.ProjectConvertToQtMsBuild: + command.Visible = true; + command.Enabled = !isQtMsBuildEnabled; break; - case CommandId.ProjectRefreshIntelliSense: { - command.Visible = command.Enabled = isQtMsBuildEnabled; - } + case CommandId.ProjectRefreshIntelliSense: + command.Visible = command.Enabled = isQtMsBuildEnabled; break; } - if (project != null && isQtProject) { + if (isQtProject) { int projectVersion = QtProject.GetFormatVersion(project); switch ((CommandId)command.CommandID.ID) { case CommandId.ChangeProjectQtVersionProjectId: diff --git a/QtVsTools.Package/QtMsBuild/QtProjectBuild.cs b/QtVsTools.Package/QtMsBuild/QtProjectBuild.cs index 2cff5c70..5a1cb296 100644 --- a/QtVsTools.Package/QtMsBuild/QtProjectBuild.cs +++ b/QtVsTools.Package/QtMsBuild/QtProjectBuild.cs @@ -320,45 +320,40 @@ namespace QtVsTools.QtMsBuild if (QtVsToolsPackage.Instance.Options.BuildDebugInformation) { string resMsg; StringBuilder resInfo = new StringBuilder(); - if (result?.OverallResult == BuildResultCode.Success) { + if (result.OverallResult == BuildResultCode.Success) { resMsg = "Build ok"; } else { resMsg = "Build FAIL"; - if (result == null) { - resInfo.AppendLine("####### Build returned 'null'"); - } else { - resInfo.AppendLine("####### Build returned 'Failure' code"); - if (result.ResultsByTarget != null) { - foreach (var tr in result.ResultsByTarget) { - var res = tr.Value; - if (res.ResultCode != TargetResultCode.Failure) - continue; - resInfo.AppendFormat("### Target '{0}' FAIL\r\n", tr.Key); - if (res.Items != null && res.Items.Length > 0) { - resInfo.AppendFormat( - "Items: {0}\r\n", string.Join(", ", res.Items - .Select(it => it.ItemSpec))); - } - var e = tr.Value?.Exception; - if (e != null) { - resInfo.AppendFormat( - "Exception: {0}\r\nStacktrace:\r\n{1}\r\n", - e.Message, e.StackTrace); - } + resInfo.AppendLine("####### Build returned 'Failure' code"); + if (result.ResultsByTarget != null) { + foreach (var tr in result.ResultsByTarget) { + var res = tr.Value; + if (res.ResultCode != TargetResultCode.Failure) + continue; + resInfo.AppendFormat("### Target '{0}' FAIL\r\n", tr.Key); + if (res.Items != null && res.Items.Length > 0) { + resInfo.AppendFormat( + "Items: {0}\r\n", string.Join(", ", res.Items + .Select(it => it.ItemSpec))); + } + var e = tr.Value?.Exception; + if (e != null) { + resInfo.AppendFormat( + "Exception: {0}\r\nStacktrace:\r\n{1}\r\n", + e.Message, e.StackTrace); } } } } Messages.Print(string.Format( - "{0:HH:mm:ss.FFF} QtProjectBuild({1}): [{2}] {3}\r\n{4}", - DateTime.Now, Thread.CurrentThread.ManagedThreadId, - ConfiguredProject.ProjectConfiguration.Name, - resMsg, resInfo.ToString())); + "{0:HH:mm:ss.FFF} QtProjectBuild({1}): [{2}] {3}\r\n{4}", + DateTime.Now, Thread.CurrentThread.ManagedThreadId, + ConfiguredProject.ProjectConfiguration.Name, + resMsg, resInfo.ToString())); } bool ok = false; - if (result == null - || result.ResultsByTarget == null + if (result.ResultsByTarget == null || result.OverallResult != BuildResultCode.Success) { Messages.Print(string.Format("{0}: background build FAILED!", Path.GetFileName(UnconfiguredProject.FullPath))); diff --git a/QtVsTools.Package/QtMsBuild/QtProjectTracker.cs b/QtVsTools.Package/QtMsBuild/QtProjectTracker.cs index 7ac8ed28..06a42665 100644 --- a/QtVsTools.Package/QtMsBuild/QtProjectTracker.cs +++ b/QtVsTools.Package/QtMsBuild/QtProjectTracker.cs @@ -168,10 +168,9 @@ namespace QtVsTools.QtMsBuild UpdateInitStatus(p += 10); UnconfiguredProject = context.UnconfiguredProject; - if (UnconfiguredProject == null - || UnconfiguredProject.ProjectService == null - || UnconfiguredProject.ProjectService.Services == null) + if (UnconfiguredProject?.ProjectService.Services == null) return; + await TaskScheduler.Default; UpdateInitStatus(p += 10); diff --git a/QtVsTools.RegExpr/expression/CharClassSet.cs b/QtVsTools.RegExpr/expression/CharClassSet.cs index 006e103e..3b7d4371 100644 --- a/QtVsTools.RegExpr/expression/CharClassSet.cs +++ b/QtVsTools.RegExpr/expression/CharClassSet.cs @@ -248,7 +248,7 @@ namespace QtVsTools.SyntaxAnalysis while (stack.Any()) { var context = stack.Pop(); expr = context.Expr; - if (context == null || expr == null) { + if (expr == null) { continue; } else if (context.Children == null) { context.Children = new Queue<Expr>(); diff --git a/QtVsTools.Wizards/ProjectWizard/ConfigPage.xaml.cs b/QtVsTools.Wizards/ProjectWizard/ConfigPage.xaml.cs index b46370d2..511aa3fd 100644 --- a/QtVsTools.Wizards/ProjectWizard/ConfigPage.xaml.cs +++ b/QtVsTools.Wizards/ProjectWizard/ConfigPage.xaml.cs @@ -456,12 +456,9 @@ namespace QtVsTools.Wizards.ProjectWizard static object GetBinding(FrameworkElement control) { - if (control.BindingGroup == null - || control.BindingGroup.Items == null - || control.BindingGroup.Items.Count == 0) { + if (control?.BindingGroup == null) return null; - } - return control.BindingGroup.Items[0]; + return control.BindingGroup.Items.Count == 0 ? null : control.BindingGroup.Items[0]; } static FrameworkElement FindAncestor(FrameworkElement control, string name) diff --git a/QtVsTools.Wizards/ProjectWizard/ProjectTemplateWizard.cs b/QtVsTools.Wizards/ProjectWizard/ProjectTemplateWizard.cs index d0a576bc..5691b18d 100644 --- a/QtVsTools.Wizards/ProjectWizard/ProjectTemplateWizard.cs +++ b/QtVsTools.Wizards/ProjectWizard/ProjectTemplateWizard.cs @@ -322,9 +322,7 @@ namespace QtVsTools.Wizards.ProjectWizard if (string.IsNullOrEmpty(wizConfig.QtVersionPath)) return string.Empty; string[] linuxPaths = wizConfig.QtVersionPath.Split(':'); - if (linuxPaths == null || linuxPaths.Length <= 2) - return string.Empty; - return linuxPaths[2]; + return linuxPaths.Length <= 2 ? string.Empty : linuxPaths[2]; } protected virtual void Expand() |