From 20cbe026317bacb17542ac2300aee1500469e92e Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Sat, 10 Feb 2007 17:23:16 +0000 Subject: [PATCH] Fixed SD2-1276: Duplicated code when converting single VB.NET If-Then line into multiple lines Use AddInTree to let AddIns register additional MSBuild properties. git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/2.1@2380 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../Boo/BooBinding/Project/BooBinding.addin | 14 ++++++++--- .../Boo/BooBinding/Project/Src/BooProject.cs | 6 ----- .../VBNetFormattingStrategy.cs | 2 +- .../Src/Project/MSBuildBasedProject.cs | 25 ++++++++++++++++--- .../Base/Project/Src/Project/MSBuildEngine.cs | 23 ++++------------- .../Implementations/ConstructedReturnType.cs | 10 +++++--- 6 files changed, 46 insertions(+), 34 deletions(-) diff --git a/src/AddIns/BackendBindings/Boo/BooBinding/Project/BooBinding.addin b/src/AddIns/BackendBindings/Boo/BooBinding/Project/BooBinding.addin index d8e8f76493..6efac20361 100644 --- a/src/AddIns/BackendBindings/Boo/BooBinding/Project/BooBinding.addin +++ b/src/AddIns/BackendBindings/Boo/BooBinding/Project/BooBinding.addin @@ -15,6 +15,7 @@ + - + + + - + + + + + + - + diff --git a/src/AddIns/BackendBindings/Boo/BooBinding/Project/Src/BooProject.cs b/src/AddIns/BackendBindings/Boo/BooBinding/Project/Src/BooProject.cs index 19973e98ea..9d761be105 100644 --- a/src/AddIns/BackendBindings/Boo/BooBinding/Project/Src/BooProject.cs +++ b/src/AddIns/BackendBindings/Boo/BooBinding/Project/Src/BooProject.cs @@ -18,17 +18,11 @@ namespace Grunwald.BooBinding { public class BooProject : CompilableProject { - static bool initialized = false; public static readonly string BooBinPath = Path.GetDirectoryName(typeof(BooProject).Assembly.Location); void Init() { reparseCodeSensitiveProperties.Add("Ducky"); - - if (!initialized) { - initialized = true; - MSBuildEngine.MSBuildProperties.Add("BooBinPath", BooBinPath); - } } public override string Language { diff --git a/src/AddIns/BackendBindings/VBNetBinding/Project/Src/FormattingStrategy/VBNetFormattingStrategy.cs b/src/AddIns/BackendBindings/VBNetBinding/Project/Src/FormattingStrategy/VBNetFormattingStrategy.cs index 4d64ad0ff8..9a74d5a9ff 100644 --- a/src/AddIns/BackendBindings/VBNetBinding/Project/Src/FormattingStrategy/VBNetFormattingStrategy.cs +++ b/src/AddIns/BackendBindings/VBNetBinding/Project/Src/FormattingStrategy/VBNetFormattingStrategy.cs @@ -351,7 +351,7 @@ namespace VBNetBinding.FormattingStrategy if (Regex.IsMatch(texttoreplace.Trim(), statement.StartRegex, RegexOptions.IgnoreCase)) { string indentation = GetIndentation(textArea, lineNr - 1); if (isEndStatementNeeded(textArea, ref statement, lineNr)) { - textArea.Document.Insert(textArea.Caret.Offset, terminator + indentation + statement.EndStatement); + textArea.Document.Replace(curLine.Offset, curLine.Length, terminator + indentation + statement.EndStatement); ++undoCount; } for (int i = 0; i < statement.IndentPlus; i++) { diff --git a/src/Main/Base/Project/Src/Project/MSBuildBasedProject.cs b/src/Main/Base/Project/Src/Project/MSBuildBasedProject.cs index dec810b845..572ef20134 100644 --- a/src/Main/Base/Project/Src/Project/MSBuildBasedProject.cs +++ b/src/Main/Base/Project/Src/Project/MSBuildBasedProject.cs @@ -820,9 +820,28 @@ namespace ICSharpCode.SharpDevelop.Project internal static void InitializeMSBuildProject(MSBuild.Project project) { - project.GlobalProperties.SetProperty("BuildingInsideVisualStudio", "true"); - foreach (KeyValuePair pair in MSBuildEngine.MSBuildProperties) { - project.GlobalProperties.SetProperty(pair.Key, pair.Value, true); + InitializeMSBuildProjectProperties(project.GlobalProperties); + } + + /// + /// Set compilation properties (MSBuildProperties and AddInTree/AdditionalPropertiesPath). + /// + internal static void InitializeMSBuildProjectProperties(MSBuild.BuildPropertyGroup propertyGroup) + { + foreach (KeyValuePair entry in MSBuildEngine.MSBuildProperties) { + propertyGroup.SetProperty(entry.Key, entry.Value); + } + // re-load these properties from AddInTree every time because "text" might contain + // SharpDevelop properties resolved by the StringParser (e.g. ${property:FxCopPath}) + AddInTreeNode node = AddInTree.GetTreeNode(MSBuildEngine.AdditionalPropertiesPath, false); + if (node != null) { + foreach (Codon codon in node.Codons) { + object item = codon.BuildItem(null, new System.Collections.ArrayList()); + if (item != null) { + bool escapeValue = !codon.Properties.Get("text", "").Contains("$("); + propertyGroup.SetProperty(codon.Id, item.ToString(), escapeValue); + } + } } } diff --git a/src/Main/Base/Project/Src/Project/MSBuildEngine.cs b/src/Main/Base/Project/Src/Project/MSBuildEngine.cs index e348149586..252b22e865 100644 --- a/src/Main/Base/Project/Src/Project/MSBuildEngine.cs +++ b/src/Main/Base/Project/Src/Project/MSBuildEngine.cs @@ -30,7 +30,7 @@ namespace ICSharpCode.SharpDevelop.Project const string CompileTaskNamesPath = "/SharpDevelop/MSBuildEngine/CompileTaskNames"; const string AdditionalTargetFilesPath = "/SharpDevelop/MSBuildEngine/AdditionalTargetFiles"; const string AdditionalLoggersPath = "/SharpDevelop/MSBuildEngine/AdditionalLoggers"; - const string AdditionalPropertiesPath = "/SharpDevelop/MSBuildEngine/AdditionalProperties"; + internal const string AdditionalPropertiesPath = "/SharpDevelop/MSBuildEngine/AdditionalProperties"; /// /// Gets a list of the task names that cause a "Compiling ..." log message. @@ -69,6 +69,7 @@ namespace ICSharpCode.SharpDevelop.Project MSBuildProperties = new SortedList(); MSBuildProperties.Add("SharpDevelopBinPath", Path.GetDirectoryName(typeof(MSBuildEngine).Assembly.Location)); + MSBuildProperties.Add("BuildingInsideVisualStudio", "true"); } #region Properties @@ -373,21 +374,9 @@ namespace ICSharpCode.SharpDevelop.Project internal Engine CreateEngine() { Engine engine = MSBuildInternals.CreateEngine(); - foreach (KeyValuePair entry in MSBuildProperties) { - engine.GlobalProperties.SetProperty(entry.Key, entry.Value); - } - // re-load these properties from AddInTree every time because "text" might contain - // SharpDevelop properties resolved by the StringParser (e.g. ${property:FxCopPath}) - AddInTreeNode node = AddInTree.GetTreeNode(AdditionalPropertiesPath, false); - if (node != null) { - foreach (Codon codon in node.Codons) { - object item = codon.BuildItem(null, new System.Collections.ArrayList()); - if (item != null) { - bool escapeValue = !codon.Properties.Get("text", "").Contains("$("); - engine.GlobalProperties.SetProperty(codon.Id, item.ToString(), escapeValue); - } - } - } + + MSBuildBasedProject.InitializeMSBuildProjectProperties(engine.GlobalProperties); + if (options.AdditionalProperties != null) { foreach (KeyValuePair entry in options.AdditionalProperties) { engine.GlobalProperties.SetProperty(entry.Key, entry.Value); @@ -398,8 +387,6 @@ namespace ICSharpCode.SharpDevelop.Project engine.GlobalProperties.SetProperty("SolutionFileName", Path.GetFileName(solution.FileName)); engine.GlobalProperties.SetProperty("SolutionPath", solution.FileName); - engine.GlobalProperties.SetProperty("BuildingInsideVisualStudio", "true"); - return engine; } diff --git a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/ConstructedReturnType.cs b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/ConstructedReturnType.cs index 8adc0384bf..ac9a14d008 100644 --- a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/ConstructedReturnType.cs +++ b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/ConstructedReturnType.cs @@ -72,17 +72,21 @@ namespace ICSharpCode.SharpDevelop.Dom } } + /// + /// Gets if is/contains a generic return type referring to a class type parameter. + /// bool CheckReturnType(IReturnType t) { + if (t == null) { + return false; + } if (t.IsGenericReturnType) { return t.CastToGenericReturnType().TypeParameter.Method == null; } else if (t.IsArrayReturnType) { return CheckReturnType(t.CastToArrayReturnType().ArrayElementType); } else if (t.IsConstructedReturnType) { foreach (IReturnType para in t.CastToConstructedReturnType().TypeArguments) { - if (para != null) { - if (CheckReturnType(para)) return true; - } + if (CheckReturnType(para)) return true; } return false; } else {