diff --git a/src/AddIns/BackendBindings/Boo/BooBinding/Project/PostBuildEvent.proj b/src/AddIns/BackendBindings/Boo/BooBinding/Project/PostBuildEvent.proj index 1fe7b06954..e508de3598 100644 --- a/src/AddIns/BackendBindings/Boo/BooBinding/Project/PostBuildEvent.proj +++ b/src/AddIns/BackendBindings/Boo/BooBinding/Project/PostBuildEvent.proj @@ -1,13 +1,13 @@ - - $(PrepareForRunDependsOn);MyPostBuildTarget - - - - - - - - - + + $(PrepareForRunDependsOn);MyPostBuildTarget + + + + + + + + + diff --git a/src/AddIns/BackendBindings/Boo/BooBinding/Project/Src/CodeCompletion/ConvertVisitor.cs b/src/AddIns/BackendBindings/Boo/BooBinding/Project/Src/CodeCompletion/ConvertVisitor.cs index e2e4d334be..6b15d670c8 100644 --- a/src/AddIns/BackendBindings/Boo/BooBinding/Project/Src/CodeCompletion/ConvertVisitor.cs +++ b/src/AddIns/BackendBindings/Boo/BooBinding/Project/Src/CodeCompletion/ConvertVisitor.cs @@ -165,7 +165,7 @@ namespace Grunwald.BooBinding.CodeCompletion c.Attributes = DefaultAttribute.EmptyAttributeList; } else { foreach (AST.Attribute a in node.Attributes) { - c.Attributes.Add(new DefaultAttribute(a.Name)); + c.Attributes.Add(new DefaultAttribute(new AttributeReturnType(a.Name))); } } c.Documentation = node.Documentation; diff --git a/src/AddIns/BackendBindings/VBNetBinding/Project/Src/MyNamespaceBuilder.cs b/src/AddIns/BackendBindings/VBNetBinding/Project/Src/MyNamespaceBuilder.cs index cf52600e0e..588500d9d1 100644 --- a/src/AddIns/BackendBindings/VBNetBinding/Project/Src/MyNamespaceBuilder.cs +++ b/src/AddIns/BackendBindings/VBNetBinding/Project/Src/MyNamespaceBuilder.cs @@ -40,7 +40,7 @@ namespace VBNetBinding DefaultClass c = new DefaultClass(cu, ns + ".MyProject"); c.ClassType = ClassType.Module; c.Modifiers = ModifierEnum.Internal | ModifierEnum.Partial | ModifierEnum.Sealed | ModifierEnum.Synthetic; - c.Attributes.Add(new DefaultAttribute("Microsoft.VisualBasic.HideModuleNameAttribute")); + c.Attributes.Add(new DefaultAttribute(CreateTypeRef(cu, "Microsoft.VisualBasic.HideModuleNameAttribute"))); // we need to use GetClassReturnType instead of DefaultReturnType because we need // a reference to the compound class. @@ -71,22 +71,22 @@ namespace VBNetBinding DefaultClass c = new DefaultClass(cu, ns + ".MyApplication"); c.ClassType = ClassType.Class; c.Modifiers = ModifierEnum.Internal | ModifierEnum.Sealed | ModifierEnum.Partial | ModifierEnum.Synthetic; - c.Attributes.Add(new DefaultAttribute("Microsoft.VisualBasic.HideModuleNameAttribute")); + c.Attributes.Add(new DefaultAttribute(CreateTypeRef(cu, "Microsoft.VisualBasic.HideModuleNameAttribute"))); switch (project.OutputType) { case OutputType.WinExe: - c.BaseTypes.Add(CreateBaseType(cu, "Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase")); + c.BaseTypes.Add(CreateTypeRef(cu, "Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase")); break; case OutputType.Exe: - c.BaseTypes.Add(CreateBaseType(cu, "Microsoft.VisualBasic.ApplicationServices.ConsoleApplicationBase")); + c.BaseTypes.Add(CreateTypeRef(cu, "Microsoft.VisualBasic.ApplicationServices.ConsoleApplicationBase")); break; default: - c.BaseTypes.Add(CreateBaseType(cu, "Microsoft.VisualBasic.ApplicationServices.ApplicationBase")); + c.BaseTypes.Add(CreateTypeRef(cu, "Microsoft.VisualBasic.ApplicationServices.ApplicationBase")); break; } return c; } - static IReturnType CreateBaseType(ICompilationUnit cu, string fullName) + static IReturnType CreateTypeRef(ICompilationUnit cu, string fullName) { return new GetClassReturnType(cu.ProjectContent, fullName, 0); } @@ -96,8 +96,8 @@ namespace VBNetBinding DefaultClass c = new DefaultClass(cu, ns + ".MyComputer"); c.ClassType = ClassType.Class; c.Modifiers = ModifierEnum.Internal | ModifierEnum.Sealed | ModifierEnum.Partial | ModifierEnum.Synthetic; - c.Attributes.Add(new DefaultAttribute("Microsoft.VisualBasic.HideModuleNameAttribute")); - c.BaseTypes.Add(CreateBaseType(cu, "Microsoft.VisualBasic.Devices.Computer")); + c.Attributes.Add(new DefaultAttribute(CreateTypeRef(cu, "Microsoft.VisualBasic.HideModuleNameAttribute"))); + c.BaseTypes.Add(CreateTypeRef(cu, "Microsoft.VisualBasic.Devices.Computer")); return c; } @@ -106,7 +106,7 @@ namespace VBNetBinding DefaultClass c = new MyFormsClass(cu, ns + ".MyForms"); c.ClassType = ClassType.Class; c.Modifiers = ModifierEnum.Internal | ModifierEnum.Sealed | ModifierEnum.Synthetic; - c.Attributes.Add(new DefaultAttribute("Microsoft.VisualBasic.HideModuleNameAttribute")); + c.Attributes.Add(new DefaultAttribute(CreateTypeRef(cu, "Microsoft.VisualBasic.HideModuleNameAttribute"))); return c; } diff --git a/src/AddIns/BackendBindings/WixBinding/Project/PostBuildEvent.proj b/src/AddIns/BackendBindings/WixBinding/Project/PostBuildEvent.proj deleted file mode 100644 index 06ca69151d..0000000000 --- a/src/AddIns/BackendBindings/WixBinding/Project/PostBuildEvent.proj +++ /dev/null @@ -1,11 +0,0 @@ - - - $(PrepareForRunDependsOn);MyPostBuildTarget - - - - - - diff --git a/src/AddIns/BackendBindings/WixBinding/Project/WixBinding.addin b/src/AddIns/BackendBindings/WixBinding/Project/WixBinding.addin index 937947ee83..3904f5b4d7 100644 --- a/src/AddIns/BackendBindings/WixBinding/Project/WixBinding.addin +++ b/src/AddIns/BackendBindings/WixBinding/Project/WixBinding.addin @@ -6,13 +6,12 @@ - + + - - diff --git a/src/AddIns/BackendBindings/WixBinding/Project/WixBinding.csproj b/src/AddIns/BackendBindings/WixBinding/Project/WixBinding.csproj index 621d4dae5f..9548193430 100644 --- a/src/AddIns/BackendBindings/WixBinding/Project/WixBinding.csproj +++ b/src/AddIns/BackendBindings/WixBinding/Project/WixBinding.csproj @@ -221,7 +221,6 @@ ICSharpCode.TextEditor False - {7D7E92DF-ACEB-4B69-92C8-8AC7A703CD57} FormsDesigner @@ -249,11 +248,6 @@ ICSharpCode.SharpDevelop.Dom False - - {6B717BD1-CD5E-498C-A42E-9E6A4584DC48} - XmlEditor - False - {8035765F-D51F-4A0C-A746-2FD100E19419} @@ -261,6 +255,12 @@ False + + + {6B717BD1-CD5E-498C-A42E-9E6A4584DC48} + XmlEditor + False + + - \ No newline at end of file diff --git a/src/AddIns/BackendBindings/XamlBinding/Project/Configuration/AssemblyInfo.cs b/src/AddIns/BackendBindings/XamlBinding/Project/Configuration/AssemblyInfo.cs new file mode 100644 index 0000000000..c2fa172629 --- /dev/null +++ b/src/AddIns/BackendBindings/XamlBinding/Project/Configuration/AssemblyInfo.cs @@ -0,0 +1,20 @@ +// +// +// +// +// $Revision$ +// + +using System.Reflection; + +// Information about this assembly is defined by the following +// attributes. +// +// change them to the information which is associated with the assembly +// you compile. + +[assembly: AssemblyTitle("XamlBinding")] +[assembly: AssemblyDescription("Provides XAML integration in code-completion")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] diff --git a/src/AddIns/BackendBindings/XamlBinding/Project/Src/XamlClassReturnType.cs b/src/AddIns/BackendBindings/XamlBinding/Project/Src/XamlClassReturnType.cs new file mode 100644 index 0000000000..1cfc23e876 --- /dev/null +++ b/src/AddIns/BackendBindings/XamlBinding/Project/Src/XamlClassReturnType.cs @@ -0,0 +1,42 @@ +// +// +// +// +// $Revision$ +// + +using System; +using ICSharpCode.SharpDevelop.Dom; + +namespace XamlBinding +{ + /// + /// Description of XamlClassReturnType. + /// + public class XamlClassReturnType : ProxyReturnType + { + XamlCompilationUnit compilationUnit; + string xmlNamespace; + string className; + + public XamlClassReturnType(XamlCompilationUnit compilationUnit, string xmlNamespace, string className) + { + if (compilationUnit == null) + throw new ArgumentNullException("compilationUnit"); + + this.compilationUnit = compilationUnit; + this.xmlNamespace = xmlNamespace ?? ""; + this.className = className ?? ""; + } + + public override IReturnType BaseType { + get { + return compilationUnit.FindType(xmlNamespace, className); + } + } + + public override string Name { + get { return className; } + } + } +} diff --git a/src/AddIns/BackendBindings/XamlBinding/Project/Src/XamlCompilationUnit.cs b/src/AddIns/BackendBindings/XamlBinding/Project/Src/XamlCompilationUnit.cs new file mode 100644 index 0000000000..96e7f1c4ec --- /dev/null +++ b/src/AddIns/BackendBindings/XamlBinding/Project/Src/XamlCompilationUnit.cs @@ -0,0 +1,77 @@ +// +// +// +// +// $Revision$ +// + +using System; +using ICSharpCode.SharpDevelop.Dom; + +namespace XamlBinding +{ + /// + /// Description of XamlCompilationUnit. + /// + public class XamlCompilationUnit : DefaultCompilationUnit + { + public XamlCompilationUnit(IProjectContent projectContent) : base(projectContent) + { + } + + public IReturnType CreateType(string xmlNamespace, string className) + { + if (xmlNamespace.StartsWith("clr-namespace:")) { + return CreateClrNamespaceType(xmlNamespace, className); + } else { + return new XamlClassReturnType(this, xmlNamespace, className); + } + } + + IReturnType CreateClrNamespaceType(string xmlNamespace, string className) + { + string namespaceName = xmlNamespace.Substring("clr-namespace:".Length); + int pos = namespaceName.IndexOf(';'); + if (pos >= 0) { + // we expect that the target type is also a reference of the project, so we + // can ignore the assembly part after the ; + namespaceName = namespaceName.Substring(0, pos); + } + return new GetClassReturnType(this.ProjectContent, namespaceName + "." + className, 0); + } + + public IReturnType FindType(string xmlNamespace, string className) + { + if (xmlNamespace.StartsWith("clr-namespace:")) { + return CreateClrNamespaceType(xmlNamespace, className); + } else { + IReturnType type = FindTypeInAssembly(this.ProjectContent, xmlNamespace, className); + if (type != null) + return type; + foreach (IProjectContent p in this.ProjectContent.ReferencedContents) { + type = FindTypeInAssembly(this.ProjectContent, xmlNamespace, className); + if (type != null) + return type; + } + return null; + } + } + + static IReturnType FindTypeInAssembly(IProjectContent projectContent, string xmlNamespace, string className) + { + foreach (IAttribute att in projectContent.GetAssemblyAttributes()) { + if (att.PositionalArguments.Count == 2 + && att.AttributeType.FullyQualifiedName == "System.Windows.Markup.XmlnsDefinitionAttribute") + { + string namespaceName = att.PositionalArguments[1] as string; + if (xmlNamespace.Equals(att.PositionalArguments[0]) && namespaceName != null) { + IClass c = projectContent.GetClass(namespaceName + "." + className, 0, LanguageProperties.CSharp, false); + if (c != null) + return c.DefaultReturnType; + } + } + } + return null; + } + } +} diff --git a/src/AddIns/BackendBindings/XamlBinding/Project/Src/XamlParser.cs b/src/AddIns/BackendBindings/XamlBinding/Project/Src/XamlParser.cs new file mode 100644 index 0000000000..a2d82d66a5 --- /dev/null +++ b/src/AddIns/BackendBindings/XamlBinding/Project/Src/XamlParser.cs @@ -0,0 +1,130 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.Diagnostics; +using System.IO; +using System.Xml; +using ICSharpCode.Core; +using ICSharpCode.SharpDevelop.Dom; + +namespace XamlBinding +{ + /// + /// Parses xaml files to partial classes for the Dom. + /// + public class XamlParser : IParser + { + string[] lexerTags; + + public string[] LexerTags { + get { + return lexerTags; + } + set { + lexerTags = value; + } + } + + public LanguageProperties Language { + get { + return LanguageProperties.CSharp; + } + } + + public bool CanParse(string fileName) + { + return Path.GetExtension(fileName).Equals(".xaml", StringComparison.OrdinalIgnoreCase); + } + + public bool CanParse(ICSharpCode.SharpDevelop.Project.IProject project) + { + return false; + } + + const string XamlNamespace = "http://schemas.microsoft.com/winfx/2006/xaml"; + + public ICompilationUnit Parse(IProjectContent projectContent, string fileName, string fileContent) + { + XamlCompilationUnit cu = new XamlCompilationUnit(projectContent); + try { + using (XmlTextReader r = new XmlTextReader(new StringReader(fileContent))) { + r.Read(); + r.MoveToContent(); + DomRegion classStart = new DomRegion(r.LineNumber, r.LinePosition); + string className = r.GetAttribute("Class", XamlNamespace); + if (string.IsNullOrEmpty(className)) { + LoggingService.Debug("XamlParser: returning empty cu because root element has no Class attribute"); + } else { + DefaultClass c = new DefaultClass(cu, className); + c.Modifiers = ModifierEnum.Partial; + c.Region = classStart; + c.BaseTypes.Add(TypeFromXmlNode(cu, r)); + cu.Classes.Add(c); + + DefaultMethod initializeComponent = new DefaultMethod( + "InitializeComponent", + projectContent.SystemTypes.Void, + ModifierEnum.Public | ModifierEnum.Synthetic, + classStart, DomRegion.Empty, + c); + c.Methods.Add(initializeComponent); + + ParseXamlElement(cu, c, r); + if (r.NodeType == XmlNodeType.EndElement) { + r.Read(); + c.Region = new DomRegion(classStart.BeginLine, classStart.BeginColumn, r.LineNumber, r.LinePosition); + } + } + } + } catch (XmlException ex) { + LoggingService.Debug("XamlParser exception: " + ex.ToString()); + cu.ErrorsDuringCompile = true; + } + return cu; + } + + IReturnType TypeFromXmlNode(XamlCompilationUnit cu, XmlReader r) + { + return cu.CreateType(r.NamespaceURI, r.Name); + } + + void ParseXamlElement(XamlCompilationUnit cu, DefaultClass c, XmlTextReader r) + { + Debug.Assert(r.NodeType == XmlNodeType.Element); + string name = r.GetAttribute("Name", XamlNamespace) ?? r.GetAttribute("Name"); + if (!string.IsNullOrEmpty(name)) { + DefaultField field = new DefaultField( + TypeFromXmlNode(cu, r), + name, + ModifierEnum.Internal, + new DomRegion(r.LineNumber, r.LinePosition), + c); + c.Fields.Add(field); + } + + if (r.IsEmptyElement) + return; + do { + r.Read(); + if (r.NodeType == XmlNodeType.Element) { + ParseXamlElement(cu, c, r); + } + } while (r.NodeType != XmlNodeType.EndElement); + } + + public IExpressionFinder CreateExpressionFinder(string fileName) + { + throw new NotImplementedException(); + } + + public IResolver CreateResolver() + { + throw new NotImplementedException(); + } + } +} diff --git a/src/AddIns/BackendBindings/XamlBinding/Project/XamlBinding.addin b/src/AddIns/BackendBindings/XamlBinding/Project/XamlBinding.addin new file mode 100644 index 0000000000..bab5b263cc --- /dev/null +++ b/src/AddIns/BackendBindings/XamlBinding/Project/XamlBinding.addin @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/AddIns/BackendBindings/XamlBinding/Project/XamlBinding.csproj b/src/AddIns/BackendBindings/XamlBinding/Project/XamlBinding.csproj new file mode 100644 index 0000000000..3c1ff599df --- /dev/null +++ b/src/AddIns/BackendBindings/XamlBinding/Project/XamlBinding.csproj @@ -0,0 +1,79 @@ + + + {7C96B65D-28A5-4F28-A35B-8D83CE831EE8} + Debug + AnyCPU + Library + XamlBinding + XamlBinding + ..\..\..\..\..\AddIns\AddIns\BackendBindings\XamlBinding + False + False + 4 + false + + + true + Full + True + DEBUG;TRACE + False + + + False + None + False + TRACE + + + False + Auto + 4194304 + AnyCPU + 4096 + + + + + + + + + + + Always + + + Configuration\GlobalAssemblyInfo.cs + + + + + + + {2D18BE89-D210-49EB-A9DD-2246FBB3DF6D} + ICSharpCode.TextEditor + False + + + {3A9AE6AA-BC07-4A2F-972C-581E3AE2F195} + NRefactory + False + + + {2748AD25-9C63-4E12-877B-4DCE96FBED54} + ICSharpCode.SharpDevelop + False + + + {35CEF10F-2D4C-45F2-9DD1-161E0FEC583C} + ICSharpCode.Core + False + + + {924EE450-603D-49C1-A8E5-4AFAA31CE6F3} + ICSharpCode.SharpDevelop.Dom + False + + + \ No newline at end of file diff --git a/src/AddIns/DisplayBindings/FormsDesigner/Project/PostBuildEvent.proj b/src/AddIns/DisplayBindings/FormsDesigner/Project/PostBuildEvent.proj index c1acc58a95..6fdd106a55 100644 --- a/src/AddIns/DisplayBindings/FormsDesigner/Project/PostBuildEvent.proj +++ b/src/AddIns/DisplayBindings/FormsDesigner/Project/PostBuildEvent.proj @@ -1,11 +1,13 @@ - - $(PrepareForRunDependsOn);MyPostBuildTarget - - - - - - - + + $(PrepareForRunDependsOn);MyPostBuildTarget + + + + + + + + + diff --git a/src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Gui/CustomComponentsSideTab.cs b/src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Gui/CustomComponentsSideTab.cs index 13a693a0aa..1bf594584b 100644 --- a/src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Gui/CustomComponentsSideTab.cs +++ b/src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Gui/CustomComponentsSideTab.cs @@ -101,11 +101,15 @@ namespace ICSharpCode.FormsDesigner.Gui goto isDesignComponent; } foreach (IAttribute attr in subClass.Attributes) { - if (attr.Name == "DesignTimeVisibleAttribute" - || attr.Name == "System.ComponentModel.DesignTimeVisibleAttribute") + if (attr.AttributeType.FullyQualifiedName == "System.ComponentModel.DesignTimeVisibleAttribute") { - // TODO: Check value of attribute (make IAttribute store at least simple values like bool's and typeof's) - goto isDesignComponent; + if (attr.PositionalArguments.Count == 1 && attr.PositionalArguments[0] is bool) { + if ((bool)attr.PositionalArguments[0]) { + goto isDesignComponent; + } + } else { + goto isDesignComponent; + } } } } diff --git a/src/AddIns/DisplayBindings/XmlEditor/Project/PostBuildEvent.proj b/src/AddIns/DisplayBindings/XmlEditor/Project/PostBuildEvent.proj new file mode 100644 index 0000000000..656932139c --- /dev/null +++ b/src/AddIns/DisplayBindings/XmlEditor/Project/PostBuildEvent.proj @@ -0,0 +1,13 @@ + + + $(PrepareForRunDependsOn);MyPostBuildTarget + + + + + + + + + + diff --git a/src/AddIns/DisplayBindings/XmlEditor/Project/XmlEditor.addin b/src/AddIns/DisplayBindings/XmlEditor/Project/XmlEditor.addin index af1cff1745..1c8204c614 100644 --- a/src/AddIns/DisplayBindings/XmlEditor/Project/XmlEditor.addin +++ b/src/AddIns/DisplayBindings/XmlEditor/Project/XmlEditor.addin @@ -25,14 +25,14 @@ diff --git a/src/AddIns/DisplayBindings/XmlEditor/Project/XmlEditor.csproj b/src/AddIns/DisplayBindings/XmlEditor/Project/XmlEditor.csproj index f6b9af441b..6d4bb856e5 100644 --- a/src/AddIns/DisplayBindings/XmlEditor/Project/XmlEditor.csproj +++ b/src/AddIns/DisplayBindings/XmlEditor/Project/XmlEditor.csproj @@ -106,8 +106,9 @@ + - Always + Never @@ -167,4 +168,5 @@ + \ No newline at end of file diff --git a/src/AddIns/Misc/CodeCoverage/Project/CodeCoverage.addin b/src/AddIns/Misc/CodeCoverage/Project/CodeCoverage.addin index 4a8e7832c3..1310ec7033 100644 --- a/src/AddIns/Misc/CodeCoverage/Project/CodeCoverage.addin +++ b/src/AddIns/Misc/CodeCoverage/Project/CodeCoverage.addin @@ -5,12 +5,10 @@ - + - - diff --git a/src/AddIns/Misc/CodeCoverage/Project/CodeCoverage.csproj b/src/AddIns/Misc/CodeCoverage/Project/CodeCoverage.csproj index ecd378e215..2d65ee098e 100644 --- a/src/AddIns/Misc/CodeCoverage/Project/CodeCoverage.csproj +++ b/src/AddIns/Misc/CodeCoverage/Project/CodeCoverage.csproj @@ -99,7 +99,6 @@ ICSharpCode.TextEditor False - {1F261725-6318-4434-A1B1-6C70CE4CD324} UnitTesting @@ -112,5 +111,4 @@ - \ No newline at end of file diff --git a/src/AddIns/Misc/CodeCoverage/Project/PostBuildEvent.proj b/src/AddIns/Misc/CodeCoverage/Project/PostBuildEvent.proj deleted file mode 100644 index 84236543e4..0000000000 --- a/src/AddIns/Misc/CodeCoverage/Project/PostBuildEvent.proj +++ /dev/null @@ -1,11 +0,0 @@ - - - $(PrepareForRunDependsOn);MyPostBuildTarget - - - - - - diff --git a/src/AddIns/Misc/UnitTesting/PostBuildEvent.proj b/src/AddIns/Misc/UnitTesting/PostBuildEvent.proj new file mode 100644 index 0000000000..656932139c --- /dev/null +++ b/src/AddIns/Misc/UnitTesting/PostBuildEvent.proj @@ -0,0 +1,13 @@ + + + $(PrepareForRunDependsOn);MyPostBuildTarget + + + + + + + + + + diff --git a/src/AddIns/Misc/UnitTesting/Src/TestClass.cs b/src/AddIns/Misc/UnitTesting/Src/TestClass.cs index 74913b0c48..12629fdfdd 100644 --- a/src/AddIns/Misc/UnitTesting/Src/TestClass.cs +++ b/src/AddIns/Misc/UnitTesting/Src/TestClass.cs @@ -53,7 +53,7 @@ namespace ICSharpCode.UnitTesting if (nameComparer != null) { TestAttributeName testAttributeName = new TestAttributeName("TestFixture", nameComparer); foreach (IAttribute attribute in c.Attributes) { - if (testAttributeName.IsEqual(attribute.Name)) { + if (testAttributeName.IsEqual(attribute.AttributeType.FullyQualifiedName)) { return true; } } diff --git a/src/AddIns/Misc/UnitTesting/Src/TestMethod.cs b/src/AddIns/Misc/UnitTesting/Src/TestMethod.cs index ab41945969..f2c8e191c1 100644 --- a/src/AddIns/Misc/UnitTesting/Src/TestMethod.cs +++ b/src/AddIns/Misc/UnitTesting/Src/TestMethod.cs @@ -114,7 +114,7 @@ namespace ICSharpCode.UnitTesting if (nameComparer != null) { TestAttributeName testAttribute = new TestAttributeName("Test", nameComparer); foreach (IAttribute attribute in member.Attributes) { - if (testAttribute.IsEqual(attribute.Name)) { + if (testAttribute.IsEqual(attribute.AttributeType.FullyQualifiedName)) { IMethod method = (IMethod)member; if (method.Parameters.Count == 0) { return true; diff --git a/src/AddIns/Misc/UnitTesting/UnitTesting.csproj b/src/AddIns/Misc/UnitTesting/UnitTesting.csproj index fcc24f6311..cdbdbe55b1 100644 --- a/src/AddIns/Misc/UnitTesting/UnitTesting.csproj +++ b/src/AddIns/Misc/UnitTesting/UnitTesting.csproj @@ -54,8 +54,9 @@ + - Always + Never @@ -123,4 +124,5 @@ + \ No newline at end of file diff --git a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/TextArea.cs b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/TextArea.cs index 44ffd84c05..9e7e278e8c 100644 --- a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/TextArea.cs +++ b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/TextArea.cs @@ -275,12 +275,6 @@ namespace ICSharpCode.TextEditor Caret.Position = textView.GetLogicalColumn(Caret.Line, Caret.DesiredColumn + (int)(VirtualTop.X * textView.WideSpaceWidth)); } - [Obsolete("Use the parameterless version")] - public void SetCaretToDesiredColumn(int caretLine) - { - Caret.Position = textView.GetLogicalColumn(Caret.Line, Caret.DesiredColumn + (int)(VirtualTop.X * textView.WideSpaceWidth)); - } - public void OptionsChanged() { UpdateMatchingBracket(); diff --git a/src/Main/Core/Project/Src/AddInTree/AddIn/AddIn.cs b/src/Main/Core/Project/Src/AddInTree/AddIn/AddIn.cs index c05c1f24ee..1c6823a9f4 100644 --- a/src/Main/Core/Project/Src/AddInTree/AddIn/AddIn.cs +++ b/src/Main/Core/Project/Src/AddInTree/AddIn/AddIn.cs @@ -29,6 +29,7 @@ namespace ICSharpCode.Core public object CreateObject(string className) { + LoadDependencies(); foreach (Runtime runtime in runtimes) { object o = runtime.CreateInstance(className); if (o != null) { @@ -44,6 +45,37 @@ namespace ICSharpCode.Core return null; } + public void LoadRuntimeAssemblies() + { + LoadDependencies(); + foreach (Runtime runtime in runtimes) { + runtime.Load(); + } + } + + bool dependenciesLoaded; + + void LoadDependencies() + { + if (!dependenciesLoaded) { + dependenciesLoaded = true; + foreach (AddInReference r in manifest.Dependencies) { + if (r.RequirePreload) { + bool found = false; + foreach (AddIn addIn in AddInTree.AddIns) { + if (addIn.Manifest.Identities.ContainsKey(r.Name)) { + found = true; + addIn.LoadRuntimeAssemblies(); + } + } + if (!found) { + throw new AddInLoadException("Cannot load run-time dependency for " + r.ToString()); + } + } + } + } + } + public override string ToString() { return "[AddIn: " + Name + "]"; diff --git a/src/Main/Core/Project/Src/AddInTree/AddIn/AddInReference.cs b/src/Main/Core/Project/Src/AddInTree/AddIn/AddInReference.cs index 3cb4e668b7..1a056b42c4 100644 --- a/src/Main/Core/Project/Src/AddInTree/AddIn/AddInReference.cs +++ b/src/Main/Core/Project/Src/AddInTree/AddIn/AddInReference.cs @@ -20,6 +20,7 @@ namespace ICSharpCode.Core string name; Version minimumVersion; Version maximumVersion; + bool requirePreload; public Version MinimumVersion { get { @@ -33,6 +34,11 @@ namespace ICSharpCode.Core } } + public bool RequirePreload { + get { return requirePreload; } + } + + public string Name { get { return name; @@ -92,16 +98,8 @@ namespace ICSharpCode.Core } else { reference.maximumVersion = reference.minimumVersion = ParseVersion(version, hintPath); } - - if (reference.Name == "SharpDevelop") { - // HACK: SD 2.1 AddIns work with SharpDevelop 2.2 - // Because some 2.1 AddIns restrict themselves to SD 2.1, we extend the - // supported SD range. - if (reference.maximumVersion == new Version("2.1")) { - reference.maximumVersion = new Version("2.2"); - } - } } + reference.requirePreload = string.Equals(properties["requirePreload"], "true", StringComparison.OrdinalIgnoreCase); return reference; } diff --git a/src/Main/Core/Project/Src/AddInTree/AddIn/Runtime.cs b/src/Main/Core/Project/Src/AddInTree/AddIn/Runtime.cs index ab9cdaf553..c88f21b3bb 100644 --- a/src/Main/Core/Project/Src/AddInTree/AddIn/Runtime.cs +++ b/src/Main/Core/Project/Src/AddInTree/AddIn/Runtime.cs @@ -47,46 +47,54 @@ namespace ICSharpCode.Core } } - public Assembly LoadedAssembly { - get { - if (!isAssemblyLoaded) { - LoggingService.Info("Loading addin " + assembly); + /// + /// Force loading the runtime assembly now. + /// + public void Load() + { + if (!isAssemblyLoaded) { + LoggingService.Info("Loading addin " + assembly); - isAssemblyLoaded = true; + isAssemblyLoaded = true; - try { - if (assembly[0] == ':') { - loadedAssembly = System.Reflection.Assembly.Load(assembly.Substring(1)); - } else if (assembly[0] == '$') { - int pos = assembly.IndexOf('/'); - if (pos < 0) - throw new ApplicationException("Expected '/' in path beginning with '$'!"); - string referencedAddIn = assembly.Substring(1, pos - 1); - foreach (AddIn addIn in AddInTree.AddIns) { - if (addIn.Enabled && addIn.Manifest.Identities.ContainsKey(referencedAddIn)) { - string assemblyFile = Path.Combine(Path.GetDirectoryName(addIn.FileName), - assembly.Substring(pos + 1)); - loadedAssembly = System.Reflection.Assembly.LoadFrom(assemblyFile); - break; - } - } - if (loadedAssembly == null) { - throw new FileNotFoundException("Could not find referenced AddIn " + referencedAddIn); + try { + if (assembly[0] == ':') { + loadedAssembly = System.Reflection.Assembly.Load(assembly.Substring(1)); + } else if (assembly[0] == '$') { + int pos = assembly.IndexOf('/'); + if (pos < 0) + throw new ApplicationException("Expected '/' in path beginning with '$'!"); + string referencedAddIn = assembly.Substring(1, pos - 1); + foreach (AddIn addIn in AddInTree.AddIns) { + if (addIn.Enabled && addIn.Manifest.Identities.ContainsKey(referencedAddIn)) { + string assemblyFile = Path.Combine(Path.GetDirectoryName(addIn.FileName), + assembly.Substring(pos + 1)); + loadedAssembly = System.Reflection.Assembly.LoadFrom(assemblyFile); + break; } - } else { - loadedAssembly = System.Reflection.Assembly.LoadFrom(Path.Combine(hintPath, assembly)); } - - #if DEBUG - // preload assembly to provoke FileLoadException if dependencies are missing - loadedAssembly.GetExportedTypes(); - #endif - } catch (FileNotFoundException ex) { - MessageService.ShowError("The addin '" + assembly + "' could not be loaded:\n" + ex.ToString()); - } catch (FileLoadException ex) { - MessageService.ShowError("The addin '" + assembly + "' could not be loaded:\n" + ex.ToString()); + if (loadedAssembly == null) { + throw new FileNotFoundException("Could not find referenced AddIn " + referencedAddIn); + } + } else { + loadedAssembly = System.Reflection.Assembly.LoadFrom(Path.Combine(hintPath, assembly)); } + + #if DEBUG + // preload assembly to provoke FileLoadException if dependencies are missing + loadedAssembly.GetExportedTypes(); + #endif + } catch (FileNotFoundException ex) { + MessageService.ShowError("The addin '" + assembly + "' could not be loaded:\n" + ex.ToString()); + } catch (FileLoadException ex) { + MessageService.ShowError("The addin '" + assembly + "' could not be loaded:\n" + ex.ToString()); } + } + } + + public Assembly LoadedAssembly { + get { + Load(); // load the assembly, if not already done return loadedAssembly; } } diff --git a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/ICSharpCode.SharpDevelop.Dom.csproj b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/ICSharpCode.SharpDevelop.Dom.csproj index 305f9f02eb..3b312fbf13 100644 --- a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/ICSharpCode.SharpDevelop.Dom.csproj +++ b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/ICSharpCode.SharpDevelop.Dom.csproj @@ -62,6 +62,7 @@ + diff --git a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/CecilReader.cs b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/CecilReader.cs index 4a84570cf8..ce23e3204f 100644 --- a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/CecilReader.cs +++ b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/CecilReader.cs @@ -6,6 +6,7 @@ // using System; +using System.Collections; using System.Collections.Generic; using System.IO; @@ -36,8 +37,13 @@ namespace ICSharpCode.SharpDevelop.Dom static void AddAttributes(IProjectContent pc, IList list, CustomAttributeCollection attributes) { foreach (CustomAttribute att in attributes) { - DefaultAttribute a = new DefaultAttribute(att.Constructor.DeclaringType.FullName); - // TODO: add only attributes marked "important", and include attribute arguments + DefaultAttribute a = new DefaultAttribute(CreateType(pc, null, att.Constructor.DeclaringType)); + foreach (object o in att.ConstructorParameters) { + a.PositionalArguments.Add(o); + } + foreach (DictionaryEntry entry in att.Properties) { + a.NamedArguments.Add(entry.Key.ToString(), entry.Value); + } list.Add(a); } } @@ -127,6 +133,7 @@ namespace ICSharpCode.SharpDevelop.Dom AssemblyDefinition assembly, ProjectContentRegistry registry) : base(fullName, fileName, referencedAssemblies, registry) { + AddAttributes(this, this.AssemblyCompilationUnit.Attributes, assembly.CustomAttributes); foreach (ModuleDefinition module in assembly.Modules) { AddTypes(module.Types); } diff --git a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/CtrlSpaceResolveHelper.cs b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/CtrlSpaceResolveHelper.cs index 686b4e4d4b..4fb9034d17 100644 --- a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/CtrlSpaceResolveHelper.cs +++ b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/CtrlSpaceResolveHelper.cs @@ -152,12 +152,6 @@ namespace ICSharpCode.SharpDevelop.Dom } } - [Obsolete()] - public static ResolveResult GetResultFromDeclarationLine(IClass callingClass, IMethodOrProperty callingMember, int caretLine, int caretColumn, string expression) - { - return GetResultFromDeclarationLine(callingClass, callingMember, caretLine, caretColumn, new ExpressionResult(expression)); - } - public static ResolveResult GetResultFromDeclarationLine(IClass callingClass, IMethodOrProperty callingMember, int caretLine, int caretColumn, ExpressionResult expressionResult) { string expression = expressionResult.Expression; diff --git a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/AttributeReturnType.cs b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/AttributeReturnType.cs new file mode 100644 index 0000000000..dcea853eb7 --- /dev/null +++ b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/AttributeReturnType.cs @@ -0,0 +1,32 @@ +// +// +// +// +// $Revision$ +// + +using System; + +namespace ICSharpCode.SharpDevelop.Dom +{ + /// + /// Description of AttributeReturnType. + /// + public class AttributeReturnType : ProxyReturnType + { + string name; + + public AttributeReturnType(string name) + { + this.name = name; + } + + public override string Name { + get { return name; } + } + + public override IReturnType BaseType { + get { return null; } + } + } +} diff --git a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/DefaultAttribute.cs b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/DefaultAttribute.cs index 7af148071f..2aa73c933f 100644 --- a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/DefaultAttribute.cs +++ b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/DefaultAttribute.cs @@ -14,65 +14,45 @@ namespace ICSharpCode.SharpDevelop.Dom { public static readonly IList EmptyAttributeList = new List().AsReadOnly(); - string name; - List positionalArguments; - SortedList namedArguments; + IReturnType attributeType; + IList positionalArguments; + IDictionary namedArguments; AttributeTarget attributeTarget; - public DefaultAttribute(string name) : this(name, AttributeTarget.None) {} + public DefaultAttribute(IReturnType attributeType) : this(attributeType, AttributeTarget.None) {} - public DefaultAttribute(string name, AttributeTarget attributeTarget) + public DefaultAttribute(IReturnType attributeType, AttributeTarget attributeTarget) + : this(attributeType, attributeTarget, null, null) { - this.name = name; - this.attributeTarget = attributeTarget; - this.positionalArguments = new List(); - this.namedArguments = new SortedList(); } - public DefaultAttribute(string name, AttributeTarget attributeTarget, List positionalArguments, SortedList namedArguments) + public DefaultAttribute(IReturnType attributeType, AttributeTarget attributeTarget, IList positionalArguments, IDictionary namedArguments) { - this.name = name; + if (attributeType == null) + throw new ArgumentNullException("attributeType"); + this.attributeType = attributeType; this.attributeTarget = attributeTarget; - this.positionalArguments = positionalArguments; - this.namedArguments = namedArguments; - } - - public string Name { - get { - return name; - } - set { - name = value; - } + this.positionalArguments = positionalArguments ?? new List(); + this.namedArguments = namedArguments ?? new SortedList(); } - public AttributeTarget AttributeTarget { - get { - return attributeTarget; - } - set { - attributeTarget = value; - } - } - public List PositionalArguments { - get { - return positionalArguments; - } + public IReturnType AttributeType { + get { return attributeType; } + set { attributeType = value; } } - public SortedList NamedArguments { - get { - return namedArguments; - } + public AttributeTarget AttributeTarget { + get { return attributeTarget; } + set { attributeTarget = value; } } - public virtual int CompareTo(IAttribute value) { - return Name.CompareTo(value.Name); + public IList PositionalArguments { + get { return positionalArguments; } } - int IComparable.CompareTo(object value) { - return CompareTo((IAttribute)value); + public IDictionary NamedArguments { + get { return namedArguments; } } } } diff --git a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Interfaces/IAttribute.cs b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Interfaces/IAttribute.cs index 4544a06f2d..8efe9969a9 100644 --- a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Interfaces/IAttribute.cs +++ b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Interfaces/IAttribute.cs @@ -6,16 +6,25 @@ // using System; +using System.Collections.Generic; namespace ICSharpCode.SharpDevelop.Dom { - public interface IAttribute : IComparable + public interface IAttribute { AttributeTarget AttributeTarget { get; } - string Name { + IReturnType AttributeType { + get; + } + + IList PositionalArguments { + get; + } + + IDictionary NamedArguments { get; } } @@ -33,16 +42,4 @@ namespace ICSharpCode.SharpDevelop.Dom Return, Type } - - public struct AttributeArgument - { - public readonly IReturnType Type; - public readonly object Value; - - public AttributeArgument(IReturnType type, object value) - { - this.Type = type; - this.Value = value; - } - } } diff --git a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/LanguageProperties.cs b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/LanguageProperties.cs index 5f75bdf2ef..e1827abfc7 100644 --- a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/LanguageProperties.cs +++ b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/LanguageProperties.cs @@ -332,13 +332,7 @@ namespace ICSharpCode.SharpDevelop.Dom public override bool ShowInNamespaceCompletion(IClass c) { foreach (IAttribute attr in c.Attributes) { - if (NameComparer.Equals(attr.Name, "Microsoft.VisualBasic.HideModuleNameAttribute")) - return false; - if (NameComparer.Equals(attr.Name, "HideModuleNameAttribute")) - return false; - if (NameComparer.Equals(attr.Name, "Microsoft.VisualBasic.HideModuleName")) - return false; - if (NameComparer.Equals(attr.Name, "HideModuleName")) + if (attr.AttributeType.FullyQualifiedName == "Microsoft.VisualBasic.HideModuleNameAttribute") return false; } return base.ShowInNamespaceCompletion(c); diff --git a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/NRefactoryResolver/NRefactoryASTConvertVisitor.cs b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/NRefactoryResolver/NRefactoryASTConvertVisitor.cs index 61e372f9cd..94ec558a66 100644 --- a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/NRefactoryResolver/NRefactoryASTConvertVisitor.cs +++ b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/NRefactoryResolver/NRefactoryASTConvertVisitor.cs @@ -240,7 +240,7 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver } foreach (AST.Attribute attribute in section.Attributes) { - result.Add(new DefaultAttribute(attribute.Name, target)); + result.Add(new DefaultAttribute(new AttributeReturnType(attribute.Name), target)); } } return result; diff --git a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/ProjectContent/DefaultProjectContent.cs b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/ProjectContent/DefaultProjectContent.cs index bfa0e61d8a..fd09b0e420 100644 --- a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/ProjectContent/DefaultProjectContent.cs +++ b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/ProjectContent/DefaultProjectContent.cs @@ -448,6 +448,15 @@ namespace ICSharpCode.SharpDevelop.Dom RemoveEmptyNamespace(parent); // remove parent if also empty } + List assemblyAttributes = new List(); + + public virtual IList GetAssemblyAttributes() + { + lock (namespaces) { + return assemblyAttributes.ToArray(); + } + } + public void RemoveCompilationUnit(ICompilationUnit unit) { lock (namespaces) { diff --git a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/ProjectContent/IProjectContent.cs b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/ProjectContent/IProjectContent.cs index 5fc1bc3633..3eb0698302 100644 --- a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/ProjectContent/IProjectContent.cs +++ b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/ProjectContent/IProjectContent.cs @@ -70,6 +70,8 @@ namespace ICSharpCode.SharpDevelop.Dom get; } + IList GetAssemblyAttributes(); + string GetXmlDocumentation(string memberTag); void AddClassToNamespaceList(IClass addClass); diff --git a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/ProjectContent/ReflectionProjectContent.cs b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/ProjectContent/ReflectionProjectContent.cs index 22c225279a..1e99a45248 100644 --- a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/ProjectContent/ReflectionProjectContent.cs +++ b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/ProjectContent/ReflectionProjectContent.cs @@ -46,6 +46,11 @@ namespace ICSharpCode.SharpDevelop.Dom get { return assemblyCompilationUnit; } } + public override IList GetAssemblyAttributes() + { + return assemblyCompilationUnit.Attributes; + } + DateTime assemblyFileLastWriteTime; /// @@ -80,6 +85,7 @@ namespace ICSharpCode.SharpDevelop.Dom AddClassToNamespaceListInternal(new ReflectionClass(assemblyCompilationUnit, type, name, null)); } } + ReflectionClass.AddAttributes(this, assemblyCompilationUnit.Attributes, CustomAttributeData.GetCustomAttributes(assembly)); InitializeSpecialClasses(); } diff --git a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Refactoring/CodeGenerator.cs b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Refactoring/CodeGenerator.cs index 88fb0df7a3..6df31aa531 100644 --- a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Refactoring/CodeGenerator.cs +++ b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Refactoring/CodeGenerator.cs @@ -140,7 +140,7 @@ namespace ICSharpCode.SharpDevelop.Dom.Refactoring { AttributeSection sec = new AttributeSection(null, null); foreach (IAttribute att in attributes) { - sec.Attributes.Add(new ICSharpCode.NRefactory.Ast.Attribute(att.Name, null, null)); + sec.Attributes.Add(new ICSharpCode.NRefactory.Ast.Attribute(ConvertType(att.AttributeType, targetContext).Type, null, null)); } List resultList = new List(1); if (sec.Attributes.Count > 0) diff --git a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/ReflectionLayer/DomPersistence.cs b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/ReflectionLayer/DomPersistence.cs index 471c85dffb..314e8673c2 100644 --- a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/ReflectionLayer/DomPersistence.cs +++ b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/ReflectionLayer/DomPersistence.cs @@ -20,7 +20,7 @@ namespace ICSharpCode.SharpDevelop.Dom { public const long FileMagic = 0x11635233ED2F428C; public const long IndexFileMagic = 0x11635233ED2F427D; - public const short FileVersion = 11; + public const short FileVersion = 12; ProjectContentRegistry registry; string cacheDirectory; @@ -297,6 +297,7 @@ namespace ICSharpCode.SharpDevelop.Dom void WriteClasses() { ICollection classes = pc.Classes; + IList assemblyAttributes = pc.GetAssemblyAttributes(); classIndices.Clear(); stringDict.Clear(); @@ -309,6 +310,7 @@ namespace ICSharpCode.SharpDevelop.Dom List externalTypes = new List(); List stringList = new List(); CreateExternalTypeList(externalTypes, stringList, classes.Count, classes); + AddStringsAndExternalTypesFromAttributes(stringList, externalTypes, classes.Count, assemblyAttributes); writer.Write(classes.Count); writer.Write(externalTypes.Count); @@ -323,6 +325,7 @@ namespace ICSharpCode.SharpDevelop.Dom foreach (string text in stringList) { writer.Write(text); } + WriteAttributes(assemblyAttributes); foreach (IClass c in classes) { WriteClass(c); // BinaryReader easily reads junk data when the file does not have the @@ -350,6 +353,7 @@ namespace ICSharpCode.SharpDevelop.Dom for (int i = 0; i < stringArray.Length; i++) { stringArray[i] = reader.ReadString(); } + ReadAttributes(pc.AssemblyCompilationUnit); for (int i = 0; i < classes.Length; i++) { ReadClass(classes[i]); pc.AddClassToNamespaceList(classes[i]); @@ -485,7 +489,7 @@ namespace ICSharpCode.SharpDevelop.Dom { foreach (IClass c in classes) { CreateExternalTypeList(externalTypes, stringList, classCount, c.InnerClasses); - AddStrings(stringList, c.Attributes); + AddStringsAndExternalTypesFromAttributes(stringList, externalTypes, classCount, c.Attributes); foreach (IReturnType returnType in c.BaseTypes) { AddExternalType(returnType, externalTypes, classCount); } @@ -505,7 +509,7 @@ namespace ICSharpCode.SharpDevelop.Dom CreateExternalTypeListMember(externalTypes, stringList, classCount, p); foreach (IParameter parameter in p.Parameters) { AddString(stringList, parameter.Name); - AddStrings(stringList, parameter.Attributes); + AddStringsAndExternalTypesFromAttributes(stringList, externalTypes, classCount, parameter.Attributes); AddExternalType(parameter.ReturnType, externalTypes, classCount); } } @@ -513,7 +517,7 @@ namespace ICSharpCode.SharpDevelop.Dom CreateExternalTypeListMember(externalTypes, stringList, classCount, m); foreach (IParameter parameter in m.Parameters) { AddString(stringList, parameter.Name); - AddStrings(stringList, parameter.Attributes); + AddStringsAndExternalTypesFromAttributes(stringList, externalTypes, classCount, parameter.Attributes); AddExternalType(parameter.ReturnType, externalTypes, classCount); } foreach (ITypeParameter tp in m.TypeParameters) { @@ -531,7 +535,7 @@ namespace ICSharpCode.SharpDevelop.Dom IMember member) { AddString(stringList, member.Name); - AddStrings(stringList, member.Attributes); + AddStringsAndExternalTypesFromAttributes(stringList, externalTypes, classCount, member.Attributes); foreach (ExplicitInterfaceImplementation eii in member.InterfaceImplementations) { AddString(stringList, eii.MemberName); AddExternalType(eii.InterfaceReference, externalTypes, classCount); @@ -689,20 +693,44 @@ namespace ICSharpCode.SharpDevelop.Dom #endregion #region Write/Read attributes + void AddStringsAndExternalTypesFromAttributes(List stringList, + List externalTypes, int classCount, + IList attributes) + { + foreach (IAttribute a in attributes) { + AddExternalType(a.AttributeType, externalTypes, classCount); + foreach (object o in a.PositionalArguments) { + AddStringsAndExternalTypesFromAttributeArgument(stringList, attributes, externalTypes, classCount, o); + } + foreach (KeyValuePair pair in a.NamedArguments) { + AddString(stringList, pair.Key); + AddStringsAndExternalTypesFromAttributeArgument(stringList, attributes, externalTypes, classCount, pair.Value); + } + } + } + void WriteAttributes(IList attributes) { writer.Write((ushort)attributes.Count); foreach (IAttribute a in attributes) { - WriteString(a.Name); + WriteType(a.AttributeType); writer.Write((byte)a.AttributeTarget); + writer.Write((byte)a.PositionalArguments.Count); + foreach (object o in a.PositionalArguments) { + WriteAttributeArgument(o); + } + writer.Write((byte)a.NamedArguments.Count); + foreach (KeyValuePair pair in a.NamedArguments) { + WriteString(pair.Key); + WriteAttributeArgument(pair.Value); + } } } - void AddStrings(List stringList, IList attributes) + void ReadAttributes(ICompilationUnit cu) { - foreach (IAttribute a in attributes) { - AddString(stringList, a.Name); - } + int count = reader.ReadUInt16(); + ReadAttributes(cu.Attributes, count); } void ReadAttributes(DefaultParameter parameter) @@ -728,8 +756,80 @@ namespace ICSharpCode.SharpDevelop.Dom void ReadAttributes(IList attributes, int count) { for (int i = 0; i < count; i++) { - string name = ReadString(); - attributes.Add(new DefaultAttribute(name, (AttributeTarget)reader.ReadByte())); + IReturnType type = ReadType(); + DefaultAttribute attr = new DefaultAttribute(type, (AttributeTarget)reader.ReadByte()); + int posArgCount = reader.ReadByte(); + for (int j = 0; j < posArgCount; j++) { + attr.PositionalArguments.Add(ReadAttributeArgument()); + } + int namedArgCount = reader.ReadByte(); + for (int j = 0; j < namedArgCount; j++) { + attr.NamedArguments.Add(ReadString(), ReadAttributeArgument()); + } + attributes.Add(attr); + } + } + #endregion + + #region Write/Read attribute arguments + void AddStringsAndExternalTypesFromAttributeArgument(List stringList, IList attributes, + List externalTypes, int classCount, + object value) + { + if (value is string) { + AddString(stringList, (string)value); + } else if (value is IReturnType) { + AddExternalType((IReturnType)value, externalTypes, classCount); + } + } + + enum AttributeType : byte + { + Null, + String, + Type, + Int32, + Bool + } + + void WriteAttributeArgument(object o) + { + if (o == null) { + writer.Write((byte)AttributeType.Null); + } else if (o is string) { + writer.Write((byte)AttributeType.String); + WriteString((string)o); + } else if (o is IReturnType) { + writer.Write((byte)AttributeType.Type); + WriteType((IReturnType)o); + } else if (o is int) { + writer.Write((byte)AttributeType.Int32); + writer.Write((int)o); + } else if (o is bool) { + writer.Write((byte)AttributeType.Bool); + writer.Write((bool)o); + } else { + writer.Write((byte)AttributeType.Null); + LoggingService.Warn("Cannot write attribute arguments of type " + o.GetType()); + } + } + + object ReadAttributeArgument() + { + byte type = reader.ReadByte(); + switch ((AttributeType)type) { + case AttributeType.Null: + return null; + case AttributeType.String: + return ReadString(); + case AttributeType.Type: + return ReadType(); + case AttributeType.Int32: + return reader.ReadInt32(); + case AttributeType.Bool: + return reader.ReadBoolean(); + default: + throw new NotSupportedException("Invalid attribute argument type code " + type); } } #endregion diff --git a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/ReflectionLayer/ReflectionClass.cs b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/ReflectionLayer/ReflectionClass.cs index dcf7afda77..2efbd5bdb1 100644 --- a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/ReflectionLayer/ReflectionClass.cs +++ b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/ReflectionLayer/ReflectionClass.cs @@ -65,24 +65,31 @@ namespace ICSharpCode.SharpDevelop.Dom.ReflectionLayer internal static void AddAttributes(IProjectContent pc, IList list, IList attributes) { foreach (CustomAttributeData att in attributes) { - DefaultAttribute a = new DefaultAttribute(att.Constructor.DeclaringType.FullName); + DefaultAttribute a = new DefaultAttribute(ReflectionReturnType.Create(pc, null, att.Constructor.DeclaringType, false)); foreach (CustomAttributeTypedArgument arg in att.ConstructorArguments) { - IReturnType type = ReflectionReturnType.Create(pc, null, arg.ArgumentType, false); - a.PositionalArguments.Add(new AttributeArgument(type, arg.Value)); + a.PositionalArguments.Add(ReplaceTypeByIReturnType(pc, arg.Value)); } foreach (CustomAttributeNamedArgument arg in att.NamedArguments) { - IReturnType type = ReflectionReturnType.Create(pc, null, arg.TypedValue.ArgumentType, false); - a.NamedArguments.Add(arg.MemberInfo.Name, new AttributeArgument(type, arg.TypedValue.Value)); + a.NamedArguments.Add(arg.MemberInfo.Name, ReplaceTypeByIReturnType(pc, arg.TypedValue.Value)); } list.Add(a); } } + static object ReplaceTypeByIReturnType(IProjectContent pc, object val) + { + if (val is Type) { + return ReflectionReturnType.Create(pc, null, (Type)val, false); + } else { + return val; + } + } + internal static void ApplySpecialsFromAttributes(DefaultClass c) { foreach (IAttribute att in c.Attributes) { - if (att.Name == "Microsoft.VisualBasic.CompilerServices.StandardModuleAttribute" - || att.Name == "System.Runtime.CompilerServices.CompilerGlobalScopeAttribute") + if (att.AttributeType.FullyQualifiedName == "Microsoft.VisualBasic.CompilerServices.StandardModuleAttribute" + || att.AttributeType.FullyQualifiedName == "System.Runtime.CompilerServices.CompilerGlobalScopeAttribute") { c.ClassType = ClassType.Module; break; diff --git a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/ReflectionLayer/ReflectionMethod.cs b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/ReflectionLayer/ReflectionMethod.cs index 0bb58e0b17..9b0e261629 100644 --- a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/ReflectionLayer/ReflectionMethod.cs +++ b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/ReflectionLayer/ReflectionMethod.cs @@ -16,7 +16,7 @@ namespace ICSharpCode.SharpDevelop.Dom.ReflectionLayer { if (m.IsStatic) { foreach (IAttribute a in m.Attributes) { - string attributeName = a.Name; + string attributeName = a.AttributeType.FullyQualifiedName; if (attributeName == "System.Runtime.CompilerServices.ExtensionAttribute" || attributeName == "Boo.Lang.ExtensionAttribute") { diff --git a/src/SharpDevelop.sln b/src/SharpDevelop.sln index e0f5f156fb..ec390327f8 100644 --- a/src/SharpDevelop.sln +++ b/src/SharpDevelop.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 9.00 # Visual Studio 2005 -# SharpDevelop 3.0.0.2456 +# SharpDevelop 2.2.0.2560 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "AddIns", "AddIns", "{14A277EE-7DF1-4529-B639-7D1EF334C1C5}" ProjectSection(SolutionItems) = postProject EndProjectSection @@ -46,6 +46,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Backends", "Backends", "{FE ProjectSection(SolutionItems) = postProject EndProjectSection EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XamlBinding", "AddIns\BackendBindings\XamlBinding\Project\XamlBinding.csproj", "{7C96B65D-28A5-4F28-A35B-8D83CE831EE8}" +EndProject Project("{A33008B1-5DAC-44D5-9060-242E3B6E38F2}") = "Boo.InterpreterAddIn", "AddIns\BackendBindings\Boo\Boo.InterpreterAddIn\Project\Boo.InterpreterAddIn.booproj", "{928E34B2-5E46-4A4D-8E4D-2CA2CCDB905A}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WixBinding", "AddIns\BackendBindings\WixBinding\Project\WixBinding.csproj", "{e1b288a2-08ee-4318-8bbb-8ab72c69e33e}" @@ -462,6 +464,10 @@ Global {87C0E3D9-0DFD-4F6D-8E38-408AAF73F4EE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {87C0E3D9-0DFD-4F6D-8E38-408AAF73F4EE}.Release|Any CPU.Build.0 = Release|Any CPU {87C0E3D9-0DFD-4F6D-8E38-408AAF73F4EE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7C96B65D-28A5-4F28-A35B-8D83CE831EE8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7C96B65D-28A5-4F28-A35B-8D83CE831EE8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7C96B65D-28A5-4F28-A35B-8D83CE831EE8}.Release|Any CPU.Build.0 = Release|Any CPU + {7C96B65D-28A5-4F28-A35B-8D83CE831EE8}.Release|Any CPU.ActiveCfg = Release|Any CPU EndGlobalSection GlobalSection(NestedProjects) = preSolution {CE5B42B7-6E8C-4385-9E97-F4023FC16BF2} = {14A277EE-7DF1-4529-B639-7D1EF334C1C5} @@ -488,6 +494,7 @@ Global {DBCF20A1-BA13-4582-BFA9-74DE4D987B73} = {FEB825FA-4AD8-425D-8E4A-B5A18EE1B81C} {e1b288a2-08ee-4318-8bbb-8ab72c69e33e} = {FEB825FA-4AD8-425D-8E4A-B5A18EE1B81C} {928E34B2-5E46-4A4D-8E4D-2CA2CCDB905A} = {FEB825FA-4AD8-425D-8E4A-B5A18EE1B81C} + {7C96B65D-28A5-4F28-A35B-8D83CE831EE8} = {FEB825FA-4AD8-425D-8E4A-B5A18EE1B81C} {4B8F0F98-8BE1-402B-AA8B-C8D548577B38} = {CE5B42B7-6E8C-4385-9E97-F4023FC16BF2} {7D5C266F-D6FF-4D14-B315-0C0FC6C4EF51} = {CE5B42B7-6E8C-4385-9E97-F4023FC16BF2} {64A3E5E6-90BF-47F6-94DF-68C94B62C817} = {CE5B42B7-6E8C-4385-9E97-F4023FC16BF2}