From 77a30c4a1abd6c94ec9bba616364cd373293ac93 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Sat, 15 Jun 2013 16:34:14 +0200 Subject: [PATCH] [WIP] PackageManagement.EnvDTE --- .../Project/PackageManagement.csproj | 13 +- .../Project/Src/EnvDTE/CodeAttribute.cs | 141 +++++----- .../Project/Src/EnvDTE/CodeAttribute2.cs | 61 +++-- .../Src/EnvDTE/CodeAttributeArgument.cs | 85 +++--- .../Src/EnvDTE/CodeAttributeArguments.cs | 37 --- .../Project/Src/EnvDTE/CodeAttributes.cs | 41 --- .../Project/Src/EnvDTE/CodeClass.cs | 90 ++++--- .../Project/Src/EnvDTE/CodeElement.cs | 45 +++- .../Src/EnvDTE/CodeElementsInNamespace.cs | 65 ----- .../Project/Src/EnvDTE/CodeElementsList.cs | 79 +++++- .../Project/Src/EnvDTE/CodeModelContext.cs | 14 + .../Project/Src/EnvDTE/CodeNamespace.cs | 87 +++--- .../Project/Src/EnvDTE/CodeType.cs | 248 +++++++++++------- .../Project/Src/EnvDTE/CodeTypeBaseTypes.cs | 28 -- .../Project/Src/EnvDTE/CodeTypeMembers.cs | 46 ---- .../Project/Src/EnvDTE/CodeVariable.cs | 9 +- .../Src/EnvDTE/FileCodeModelCodeNamespace.cs | 2 - .../FileCodeModelCodeNamespaceMembers.cs | 21 -- .../Project/Src/EnvDTE/IClassExtensions.cs | 43 --- .../Project/Src/EnvDTE/ProjectItem.cs | 5 + .../Project/Src/EnvDTE/TextPoint.cs | 8 +- .../Project/Src/IProjectContentExtensions.cs | 10 + src/Main/Base/Project/Dom/IEntityModel.cs | 23 +- src/Main/Base/Project/Dom/INamespaceModel.cs | 19 ++ src/Main/Base/Project/Dom/ISymbolModel.cs | 38 +++ .../Base/Project/Dom/ITypeDefinitionModel.cs | 4 + .../Base/Project/Dom/ModelCollectionLinq.cs | 7 + .../Project/ICSharpCode.SharpDevelop.csproj | 2 + .../SharpDevelop/Dom/TypeDefinitionModel.cs | 13 + 29 files changed, 635 insertions(+), 649 deletions(-) delete mode 100644 src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeAttributeArguments.cs delete mode 100644 src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeAttributes.cs delete mode 100644 src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeElementsInNamespace.cs create mode 100644 src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeModelContext.cs delete mode 100644 src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeTypeBaseTypes.cs delete mode 100644 src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeTypeMembers.cs delete mode 100644 src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/FileCodeModelCodeNamespaceMembers.cs delete mode 100644 src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/IClassExtensions.cs create mode 100644 src/Main/Base/Project/Dom/INamespaceModel.cs create mode 100644 src/Main/Base/Project/Dom/ISymbolModel.cs diff --git a/src/AddIns/Misc/PackageManagement/Project/PackageManagement.csproj b/src/AddIns/Misc/PackageManagement/Project/PackageManagement.csproj index 8292a65b29..6d8fad1207 100644 --- a/src/AddIns/Misc/PackageManagement/Project/PackageManagement.csproj +++ b/src/AddIns/Misc/PackageManagement/Project/PackageManagement.csproj @@ -92,13 +92,10 @@ - - - @@ -106,6 +103,7 @@ + @@ -116,8 +114,6 @@ - - @@ -129,10 +125,8 @@ - - @@ -500,6 +494,11 @@ ICSharpCode.AvalonEdit False + + {53DCA265-3C3C-42F9-B647-F72BA678122B} + ICSharpCode.NRefactory.CSharp + False + {3B2A5653-EC97-4001-BB9B-D90F1AF2C371} ICSharpCode.NRefactory diff --git a/src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeAttribute.cs b/src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeAttribute.cs index cad99a157c..a3a6a622eb 100644 --- a/src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeAttribute.cs +++ b/src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeAttribute.cs @@ -1,72 +1,69 @@ -//// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -//// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) -// -//using System; -//using System.Linq; -//using ICSharpCode.SharpDevelop.Dom; -// -//namespace ICSharpCode.PackageManagement.EnvDTE -//{ -// public class CodeAttribute : CodeElement, global::EnvDTE.CodeAttribute -// { -// IAttribute attribute; -// static readonly string AttributeEndName = "Attribute"; -// -// public CodeAttribute() -// { -// } -// -// public CodeAttribute(IAttribute attribute) -// { -// this.attribute = attribute; -// } -// -// public override global::EnvDTE.vsCMElement Kind { -// get { return global::EnvDTE.vsCMElement.vsCMElementAttribute; } -// } -// -// public override string Name { -// get { return GetShortName(); } -// } -// -// string GetShortName() -// { -// return GetShortName(attribute.AttributeType.Name); -// } -// -// string GetShortName(string name) -// { -// if (name.EndsWith(AttributeEndName)) { -// return name.Substring(0, name.Length - AttributeEndName.Length); -// } -// return name; -// } -// -// public virtual string FullName { -// get { return attribute.AttributeType.FullyQualifiedName; } -// } -// -// public virtual string Value { -// get { return GetValue(); } -// set { } -// } -// -// string GetValue() -// { -// return String.Join(", ", GetArgumentValues()); -// } -// -// string[] GetArgumentValues() -// { -// return attribute -// .PositionalArguments -// .Select(arg => GetArgumentValue(arg)) -// .ToArray(); -// } -// -// string GetArgumentValue(object argument) -// { -// return new CodeAttributeArgument(String.Empty, argument).Value; -// } -// } -//} +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; +using System.Linq; +using ICSharpCode.NRefactory.Semantics; +using ICSharpCode.NRefactory.TypeSystem; +using ICSharpCode.SharpDevelop.Dom; + +namespace ICSharpCode.PackageManagement.EnvDTE +{ + public class CodeAttribute : CodeElement, global::EnvDTE.CodeAttribute + { + protected readonly IAttribute attribute; + const string AttributeEndName = "Attribute"; + + public CodeAttribute() + { + } + + public CodeAttribute(IAttribute attribute) + { + this.attribute = attribute; + } + + public override global::EnvDTE.vsCMElement Kind { + get { return global::EnvDTE.vsCMElement.vsCMElementAttribute; } + } + + public override string Name { + get { return GetShortName(attribute.AttributeType.Name); } + } + + string GetShortName(string name) + { + if (name.EndsWith(AttributeEndName)) { + return name.Substring(0, name.Length - AttributeEndName.Length); + } + return name; + } + + public virtual string FullName { + get { return attribute.AttributeType.FullName; } + } + + public virtual string Value { + get { return GetValue(); } + set { } + } + + string GetValue() + { + return String.Join(", ", GetArgumentValues()); + } + + string[] GetArgumentValues() + { + return attribute + .PositionalArguments + .Select(arg => GetArgumentValue(arg)) + .ToArray(); + } + + string GetArgumentValue(ResolveResult argument) + { + return new CodeAttributeArgument(String.Empty, argument).Value; + } + } +} diff --git a/src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeAttribute2.cs b/src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeAttribute2.cs index f082e020cc..f7a3583611 100644 --- a/src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeAttribute2.cs +++ b/src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeAttribute2.cs @@ -1,27 +1,34 @@ -//// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -//// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) -// -//using System; -//using ICSharpCode.SharpDevelop.Dom; -// -//namespace ICSharpCode.PackageManagement.EnvDTE -//{ -// public class CodeAttribute2 : CodeAttribute, global::EnvDTE.CodeAttribute2 -// { -// IAttribute attribute; -// -// public CodeAttribute2() -// { -// } -// -// public CodeAttribute2(IAttribute attribute) -// : base(attribute) -// { -// this.attribute = attribute; -// } -// -// public virtual global::EnvDTE.CodeElements Arguments { -// get { return new CodeAttributeArguments(attribute); } -// } -// } -//} +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; +using ICSharpCode.NRefactory.TypeSystem; +using ICSharpCode.SharpDevelop.Dom; + +namespace ICSharpCode.PackageManagement.EnvDTE +{ + public class CodeAttribute2 : CodeAttribute, global::EnvDTE.CodeAttribute2 + { + public CodeAttribute2() + { + } + + public CodeAttribute2(IAttribute attribute) + : base(attribute) + { + } + + public virtual global::EnvDTE.CodeElements Arguments { + get { + var list = new CodeElementsList(); + foreach (var arg in attribute.PositionalArguments) { + list.Add(new CodeAttributeArgument(string.Empty, arg)); + } + foreach (var arg in attribute.NamedArguments) { + list.Add(new CodeAttributeArgument(arg.Key.Name, arg.Value)); + } + return list; + } + } + } +} diff --git a/src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeAttributeArgument.cs b/src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeAttributeArgument.cs index d51d775eb3..1e8a7d0dfb 100644 --- a/src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeAttributeArgument.cs +++ b/src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeAttributeArgument.cs @@ -1,39 +1,46 @@ -//// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -//// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) -// -//using System; -// -//namespace ICSharpCode.PackageManagement.EnvDTE -//{ -// public class CodeAttributeArgument : CodeElement, global::EnvDTE.CodeAttributeArgument -// { -// string name; -// string value; -// -// public CodeAttributeArgument() -// { -// } -// -// public CodeAttributeArgument(string name, object value) -// { -// this.name = name; -// this.value = GetValue(value); -// } -// -// string GetValue(object value) -// { -// if (value is string) { -// return String.Format("\"{0}\"", value); -// } -// return value.ToString(); -// } -// -// public override string Name { -// get { return name; } -// } -// -// public virtual string Value { -// get { return value; } -// } -// } -//} +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; +using ICSharpCode.NRefactory.CSharp.Refactoring; +using ICSharpCode.NRefactory.Semantics; + +namespace ICSharpCode.PackageManagement.EnvDTE +{ + public class CodeAttributeArgument : CodeElement, global::EnvDTE.CodeAttributeArgument + { + string name; + string value; + + public CodeAttributeArgument() + { + } + + public CodeAttributeArgument(string name, string value) + { + this.name = name; + this.value = value; + } + + public CodeAttributeArgument(string name, ResolveResult value) + { + this.name = name; + this.value = GetValue(value); + } + + string GetValue(ResolveResult value) + { + var astBuilder = new TypeSystemAstBuilder(); + var ast = astBuilder.ConvertConstantValue(value); + return ast.ToString(); + } + + public override string Name { + get { return name; } + } + + public virtual string Value { + get { return value; } + } + } +} diff --git a/src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeAttributeArguments.cs b/src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeAttributeArguments.cs deleted file mode 100644 index ee2f43f13f..0000000000 --- a/src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeAttributeArguments.cs +++ /dev/null @@ -1,37 +0,0 @@ -//// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -//// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) -// -//using System; -//using System.Collections; -//using System.Collections.Generic; -//using System.Linq; -//using ICSharpCode.SharpDevelop.Dom; -// -//namespace ICSharpCode.PackageManagement.EnvDTE -//{ -// public class CodeAttributeArguments : CodeElementsList -// { -// IAttribute attribute; -// -// public CodeAttributeArguments(IAttribute attribute) -// { -// this.attribute = attribute; -// AddCodeElements(); -// } -// -// void AddCodeElements() -// { -// foreach (object arg in attribute.PositionalArguments) { -// AddAttributeArgument(String.Empty, arg); -// } -// foreach (KeyValuePair namedArg in attribute.NamedArguments) { -// AddAttributeArgument(namedArg.Key, namedArg.Value); -// } -// } -// -// void AddAttributeArgument(string name, object value) -// { -// AddCodeElement(new CodeAttributeArgument(name, value)); -// } -// } -//} diff --git a/src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeAttributes.cs b/src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeAttributes.cs deleted file mode 100644 index 56a231ed6d..0000000000 --- a/src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeAttributes.cs +++ /dev/null @@ -1,41 +0,0 @@ -//// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -//// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) -// -//using System; -//using System.Collections; -//using System.Collections.Generic; -//using System.Linq; -//using ICSharpCode.SharpDevelop.Dom; -// -//namespace ICSharpCode.PackageManagement.EnvDTE -//{ -// public class CodeAttributes : CodeElementsList -// { -// public CodeAttributes(IEntity entity) -// : this(entity.Attributes) -// { -// } -// -// public CodeAttributes(IParameter parameter) -// : this(parameter.Attributes) -// { -// } -// -// public CodeAttributes(IEnumerable attributes) -// { -// AddAttributes(attributes); -// } -// -// void AddAttributes(IEnumerable attributes) -// { -// foreach (IAttribute attribute in attributes) { -// AddAttribute(attribute); -// } -// } -// -// void AddAttribute(IAttribute attribute) -// { -// AddCodeElement(new CodeAttribute2(attribute)); -// } -// } -//} diff --git a/src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeClass.cs b/src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeClass.cs index 33cdbf851c..4c4d951026 100644 --- a/src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeClass.cs +++ b/src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeClass.cs @@ -1,34 +1,56 @@ -//// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -//// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) -// -//using System; -//using ICSharpCode.SharpDevelop.Dom; -// -//namespace ICSharpCode.PackageManagement.EnvDTE -//{ -// public class CodeClass : CodeType, global::EnvDTE.CodeClass -// { -// public CodeClass(IProjectContent projectContent, IClass c) -// : base(projectContent, c) -// { -// } -// -// public CodeClass() -// { -// } -// -// public override global::EnvDTE.vsCMElement Kind { -// get { return global::EnvDTE.vsCMElement.vsCMElementClass; } -// } -// -// public virtual global::EnvDTE.CodeElements ImplementedInterfaces { -// get { return new ImplementedInterfacesOnClass(ProjectContent, Class); } -// } -// -// public virtual global::EnvDTE.CodeVariable AddVariable(string name, object type, object Position = null, global::EnvDTE.vsCMAccess Access = global::EnvDTE.vsCMAccess.vsCMAccessPublic, object Location = null) -// { -// var codeGenerator = new ClassCodeGenerator(Class); -// return codeGenerator.AddPublicVariable(name, (string)type); -// } -// } -//} +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; +using System.Linq; +using ICSharpCode.NRefactory.TypeSystem; +using ICSharpCode.SharpDevelop.Dom; +using ICSharpCode.SharpDevelop.Project; + +namespace ICSharpCode.PackageManagement.EnvDTE +{ + public class CodeClass : CodeType, global::EnvDTE.CodeClass + { + public CodeClass(CodeModelContext context, ITypeDefinitionModel typeModel) + : base(context, typeModel) + { + } + + public CodeClass() + { + } + + public override global::EnvDTE.vsCMElement Kind { + get { return global::EnvDTE.vsCMElement.vsCMElementClass; } + } + + public virtual global::EnvDTE.CodeElements ImplementedInterfaces { + get { + var list = new CodeElementsList(); + var td = typeModel.Resolve(); + if (td != null) { + foreach (var baseType in td.GetAllBaseTypes().Where(t => t.Kind == TypeKind.Interface)) { + CodeType element = Create(context, baseType); + if (element != null) + list.Add(element); + } + } + return list; + } + } + + public virtual global::EnvDTE.CodeVariable AddVariable(string name, object type, object Position = null, global::EnvDTE.vsCMAccess Access = global::EnvDTE.vsCMAccess.vsCMAccessPublic, object Location = null) + { + var fieldTypeName = new FullTypeName((string)type); + var td = typeModel.Resolve(); + if (td == null) + return null; + IType fieldType = td.Compilation.FindType(fieldTypeName); + IFieldModel field = typeModel.AddField(Access.ToAccessibility(), fieldType, name); + if (field != null) + return new CodeVariable(context, field); + else + return null; + } + } +} diff --git a/src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeElement.cs b/src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeElement.cs index 016324c25e..efa0281f6d 100644 --- a/src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeElement.cs +++ b/src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeElement.cs @@ -11,20 +11,46 @@ namespace ICSharpCode.PackageManagement.EnvDTE public class CodeElement : global::EnvDTE.CodeElementBase, global::EnvDTE.CodeElement { DTE dte; - IEntityModel entityModel; + protected readonly CodeModelContext context; + readonly ISymbolModel symbolModel; public CodeElement() { } - public CodeElement(IEntityModel entityModel) + public CodeElement(CodeModelContext context, ISymbolModel symbolModel) { - this.entityModel = entityModel; - this.Language = entityModel.ParentProject.GetCodeModelLanguage(); + this.context = context; + this.symbolModel = symbolModel; + if (symbolModel.ParentProject != null) + this.Language = symbolModel.ParentProject.GetCodeModelLanguage(); + } + + public static CodeElement CreateMember(CodeModelContext context, IMemberModel m) + { + switch (m.SymbolKind) { + case SymbolKind.Field: +// return new CodeVariable(m); + throw new NotImplementedException(); + case SymbolKind.Property: + case SymbolKind.Indexer: +// return new CodeProperty2(m); + throw new NotImplementedException(); + case SymbolKind.Event: + return null; // events are not supported in EnvDTE? + case SymbolKind.Method: + case SymbolKind.Operator: + case SymbolKind.Constructor: + case SymbolKind.Destructor: +// return new CodeFunction2(m); + throw new NotImplementedException(); + default: + throw new NotSupportedException("Invalid value for SymbolKind"); + } } public virtual string Name { - get { return entityModel.Name; } + get { return symbolModel.Name; } } public virtual string Language { get; protected set; } @@ -40,7 +66,14 @@ namespace ICSharpCode.PackageManagement.EnvDTE return null; } - public virtual global::EnvDTE.vsCMInfoLocation InfoLocation { get; protected set; } + public virtual global::EnvDTE.vsCMInfoLocation InfoLocation { + get { + if (symbolModel != null && symbolModel.ParentProject == context) + return global::EnvDTE.vsCMInfoLocation.vsCMInfoLocationProject; + else + return global::EnvDTE.vsCMInfoLocation.vsCMInfoLocationExternal; + } + } public virtual global::EnvDTE.DTE DTE { get { diff --git a/src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeElementsInNamespace.cs b/src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeElementsInNamespace.cs deleted file mode 100644 index 2e5152cacc..0000000000 --- a/src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeElementsInNamespace.cs +++ /dev/null @@ -1,65 +0,0 @@ -//// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -//// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) -// -//using System; -//using System.Collections; -//using System.Collections.Generic; -//using System.Linq; -// -//using ICSharpCode.SharpDevelop.Dom; -// -//namespace ICSharpCode.PackageManagement.EnvDTE -//{ -// public class CodeElementsInNamespace : CodeElementsList -// { -// IProjectContent projectContent; -// NamespaceName namespaceName; -// -// public CodeElementsInNamespace(IProjectContent projectContent, string qualifiedNamespaceName) -// : this(projectContent, new NamespaceName(qualifiedNamespaceName)) -// { -// } -// -// public CodeElementsInNamespace(IProjectContent projectContent, NamespaceName namespaceName) -// { -// this.projectContent = projectContent; -// this.namespaceName = namespaceName; -// GetCodeElements(); -// } -// -// void GetCodeElements() -// { -// foreach (ICompletionEntry entry in projectContent.GetNamespaceContents(namespaceName.QualifiedName)) { -// AddCodeElement(entry); -// } -// } -// -// void AddCodeElement(ICompletionEntry entry) -// { -// var namespaceEntry = entry as NamespaceEntry; -// var classEntry = entry as IClass; -// if (namespaceEntry != null) { -// AddCodeNamespace(namespaceEntry); -// } else if (classEntry != null) { -// AddCodeClass(classEntry); -// } -// } -// -// void AddCodeNamespace(NamespaceEntry namespaceEntry) -// { -// if (!String.IsNullOrEmpty(namespaceEntry.Name)) { -// NamespaceName childNamespaceName = namespaceName.CreateChildNamespaceName(namespaceEntry.Name); -// AddCodeElement(new CodeNamespace(projectContent, childNamespaceName)); -// } -// } -// -// void AddCodeClass(IClass c) -// { -// if (c.ClassType == ClassType.Interface) { -// AddCodeElement(new CodeInterface(projectContent, c)); -// } else { -// AddCodeElement(new CodeClass2(projectContent, c)); -// } -// } -// } -//} diff --git a/src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeElementsList.cs b/src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeElementsList.cs index 37224dd41e..cf0bd0be5b 100644 --- a/src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeElementsList.cs +++ b/src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeElementsList.cs @@ -5,22 +5,20 @@ using System; using System.Collections; using System.Collections.Generic; using System.Linq; +using ICSharpCode.SharpDevelop.Dom; namespace ICSharpCode.PackageManagement.EnvDTE { - public class CodeElementsList : MarshalByRefObject, global::EnvDTE.CodeElements + public class CodeElementsList : MarshalByRefObject, global::EnvDTE.CodeElements, IList + where T : global::EnvDTE.CodeElement { - List elements = new List(); + List elements = new List(); public CodeElementsList() { } - protected virtual void AddCodeElement(CodeElement element) - { - elements.Add(element); - } - + #region EnvDTE.CodeElements implementation public int Count { get { return elements.Count; } } @@ -30,22 +28,79 @@ namespace ICSharpCode.PackageManagement.EnvDTE return elements.GetEnumerator(); } - public global::EnvDTE.CodeElement Item(object index) + global::EnvDTE.CodeElement global::EnvDTE.CodeElements.Item(object index) { if (index is int) { - return Item((int)index); + return GetItem((int)index); } - return Item((string)index); + return GetItem((string)index); } - global::EnvDTE.CodeElement Item(int index) + global::EnvDTE.CodeElement GetItem(int index) { return elements[index - 1]; } - global::EnvDTE.CodeElement Item(string name) + global::EnvDTE.CodeElement GetItem(string name) { return elements.Single(item => item.Name == name); } + #endregion + + #region IList + public T this[int index] { + get { return elements[index]; } + set { elements[index] = value; } + } + + bool ICollection.IsReadOnly { + get { return false; } + } + + public int IndexOf(T item) + { + return elements.IndexOf(item); + } + + public void Insert(int index, T item) + { + elements.Insert(index, item); + } + + public void RemoveAt(int index) + { + elements.RemoveAt(index); + } + + public void Add(T item) + { + elements.Add(item); + } + + public void Clear() + { + elements.Clear(); + } + + public bool Contains(T item) + { + return elements.Contains(item); + } + + public void CopyTo(T[] array, int arrayIndex) + { + elements.CopyTo(array, arrayIndex); + } + + public bool Remove(T item) + { + return elements.Remove(item); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return elements.GetEnumerator(); + } + #endregion } } diff --git a/src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeModelContext.cs b/src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeModelContext.cs new file mode 100644 index 0000000000..d1851d6ef6 --- /dev/null +++ b/src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeModelContext.cs @@ -0,0 +1,14 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; +using ICSharpCode.SharpDevelop.Project; + +namespace ICSharpCode.PackageManagement.EnvDTE +{ + public class CodeModelContext + { + public IProject CurrentProject { get; set; } + public IDocumentLoader DocumentLoader { get; set; } + } +} diff --git a/src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeNamespace.cs b/src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeNamespace.cs index 4088878680..3df9d60d04 100644 --- a/src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeNamespace.cs +++ b/src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeNamespace.cs @@ -1,47 +1,40 @@ -//// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -//// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) -// -//using System; -//using ICSharpCode.SharpDevelop.Dom; -// -//namespace ICSharpCode.PackageManagement.EnvDTE -//{ -// public class CodeNamespace : CodeElement, global::EnvDTE.CodeNamespace -// { -// NamespaceName namespaceName; -// IProjectContent projectContent; -// -// public CodeNamespace(IProjectContent projectContent, string qualifiedName) -// : this(projectContent, new NamespaceName(qualifiedName)) -// { -// } -// -// public CodeNamespace(IProjectContent projectContent, NamespaceName namespaceName) -// { -// this.projectContent = projectContent; -// this.namespaceName = namespaceName; -// this.InfoLocation = global::EnvDTE.vsCMInfoLocation.vsCMInfoLocationExternal; -// this.Language = projectContent.GetCodeModelLanguage(); -// } -// -// public override global::EnvDTE.vsCMElement Kind { -// get { return global::EnvDTE.vsCMElement.vsCMElementNamespace; } -// } -// -// internal NamespaceName NamespaceName { -// get { return namespaceName; } -// } -// -// public string FullName { -// get { return namespaceName.QualifiedName; } -// } -// -// public override string Name { -// get { return namespaceName.LastPart; } -// } -// -// public virtual global::EnvDTE.CodeElements Members { -// get { return new CodeElementsInNamespace(projectContent, namespaceName); } -// } -// } -//} +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; +using System.Collections.Generic; +using ICSharpCode.SharpDevelop.Dom; + +namespace ICSharpCode.PackageManagement.EnvDTE +{ + public class CodeNamespace : CodeElement, global::EnvDTE.CodeNamespace + { + readonly INamespaceModel model; + + public CodeNamespace(CodeModelContext context, INamespaceModel model) + : base(context, model) + { + this.model = model; + } + + public override global::EnvDTE.vsCMElement Kind { + get { return global::EnvDTE.vsCMElement.vsCMElementNamespace; } + } + + public override global::EnvDTE.vsCMInfoLocation InfoLocation { + get { return global::EnvDTE.vsCMInfoLocation.vsCMInfoLocationExternal; } + } + + public string FullName { + get { return model.FullName; } + } + + public virtual global::EnvDTE.CodeElements Members { + get { + IModelCollection namespaceMembers = model.ChildNamespaces.Select(ns => new CodeNamespace(context, ns)); + IModelCollection typeMembers = model.Types.Select(td => CodeType.Create(context, td)); + return namespaceMembers.Concat(typeMembers).AsCodeElements(); + } + } + } +} diff --git a/src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeType.cs b/src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeType.cs index 3042d5a234..db7d340e39 100644 --- a/src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeType.cs +++ b/src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeType.cs @@ -1,91 +1,157 @@ -//// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -//// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) -// -//using System; -//using System.Linq; -//using ICSharpCode.SharpDevelop.Dom; -//using ICSharpCode.SharpDevelop.Project; -// -//namespace ICSharpCode.PackageManagement.EnvDTE -//{ -// public class CodeType : CodeElement, global::EnvDTE.CodeType -// { -// CodeTypeMembers members; -// -// /// -// /// Note that projectContent may be different to the IClass.ProjectContent since the class -// /// is retrieved from the namespace contents and could belong to a separate project or -// /// referenced assembly. -// /// -// public CodeType(IProjectContent projectContent, IClass c) -// : base(c) -// { -// this.Class = c; -// this.ProjectContent = projectContent; -// InfoLocation = GetInfoLocation(projectContent, c); -// } -// -// global::EnvDTE.vsCMInfoLocation GetInfoLocation(IProjectContent projectContent, IClass c) -// { -// if (projectContent.Project == c.ProjectContent.Project) { -// return global::EnvDTE.vsCMInfoLocation.vsCMInfoLocationProject; -// } -// return global::EnvDTE.vsCMInfoLocation.vsCMInfoLocationExternal; -// } -// -// public CodeType() -// { -// } -// -// protected IClass Class { get; private set; } -// protected IProjectContent ProjectContent { get; private set; } -// -// public virtual global::EnvDTE.vsCMAccess Access { -// get { return GetAccess(); } -// set { } -// } -// -// public virtual string FullName { -// get { return Class.FullyQualifiedName; } -// } -// -// public virtual global::EnvDTE.CodeElements Members { -// get { -// if (members == null) { -// members = new CodeTypeMembers(ProjectContent, Class); -// } -// return members; -// } -// } -// -// public virtual global::EnvDTE.CodeElements Bases { -// get { return new CodeTypeBaseTypes(ProjectContent, Class); } -// } -// -// public virtual global::EnvDTE.CodeElements Attributes { -// get { return new CodeAttributes(Class); } -// } -// -// public virtual global::EnvDTE.CodeNamespace Namespace { -// get { return new FileCodeModelCodeNamespace(ProjectContent, Class.Namespace); } -// } -// -// public virtual global::EnvDTE.ProjectItem ProjectItem { -// get { -// if (ProjectContent.Project != null) { -// return new ProjectItem(ProjectContent, Class); -// } -// return null; -// } -// } -// -// /// -// /// Returns true if the current type matches the fully qualified name or any of its -// /// base types are a match. -// /// -// protected override bool GetIsDerivedFrom(string fullName) -// { -// return Class.IsDerivedFrom(fullName); -// } -// } -//} +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +using ICSharpCode.NRefactory.TypeSystem; +using ICSharpCode.SharpDevelop; +using ICSharpCode.SharpDevelop.Dom; +using ICSharpCode.SharpDevelop.Project; + +namespace ICSharpCode.PackageManagement.EnvDTE +{ + public class CodeType : CodeElement, global::EnvDTE.CodeType + { + protected readonly ITypeDefinitionModel typeModel; + CodeElementsList members; + + public static CodeType Create(CodeModelContext context, IType type) + { + var typeDef = type.GetDefinition(); + if (typeDef != null) { + var typeModel = typeDef.GetModel(); + if (typeModel != null) + return Create(context, typeModel); + } + return null; + } + + public static CodeType Create(CodeModelContext context, ITypeDefinitionModel typeModel) + { + switch (typeModel.TypeKind) { + case TypeKind.Class: + case TypeKind.Module: + goto default; + case TypeKind.Interface: + goto default; + case TypeKind.Struct: + case TypeKind.Void: + goto default; + case TypeKind.Delegate: + goto default; + case TypeKind.Enum: + goto default; + default: + return new CodeType(context, typeModel); + } + } + + /// + /// Note that projectContent may be different to the IClass.ProjectContent since the class + /// is retrieved from the namespace contents and could belong to a separate project or + /// referenced assembly. + /// + public CodeType(CodeModelContext context, ITypeDefinitionModel typeModel) + : base(context, typeModel) + { + this.typeModel = typeModel; + } + + public CodeType() + { + } + + public virtual global::EnvDTE.vsCMAccess Access { + get { return typeModel.Accessibility.ToAccess(); } + set { typeModel.Accessibility = value.ToAccessibility(); } + } + + public virtual string FullName { + get { + var fullTypeName = typeModel.FullTypeName; + StringBuilder b = new StringBuilder(); + if (!string.IsNullOrEmpty(fullTypeName.TopLevelTypeName.Namespace)) { + b.Append(fullTypeName.TopLevelTypeName.Namespace); + b.Append('.'); + } + b.Append(fullTypeName.TopLevelTypeName.Name); + for (int i = 0; i < fullTypeName.NestingLevel; i++) { + b.Append('.'); + b.Append(fullTypeName.GetNestedTypeName(i)); + } + return b.ToString(); + } + } + + public virtual global::EnvDTE.CodeElements Members { + get { + if (members == null) { + members = typeModel.Members.Select(m => CreateMember(context, m)).AsCodeElements(); + } + return members; + } + } + + public virtual global::EnvDTE.CodeElements Bases { + get { + var list = new CodeElementsList(); + var td = typeModel.Resolve(); + if (td != null) { + IEnumerable baseTypes; + if (td.Kind == TypeKind.Interface) + baseTypes = td.DirectBaseTypes; + else + baseTypes = td.DirectBaseTypes.Where(t => t.Kind != TypeKind.Interface); + foreach (var baseType in baseTypes) { + CodeType element = Create(context, baseType); + if (element != null) + list.Add(element); + } + } + return list; + } + } + + public virtual global::EnvDTE.CodeElements Attributes { + get { + var list = new CodeElementsList(); + var td = typeModel.Resolve(); + if (td != null) { + foreach (var attr in td.Attributes) { + list.Add(new CodeAttribute2(attr)); + } + } + return list; + } + } + + public virtual global::EnvDTE.CodeNamespace Namespace { + get { + throw new NotImplementedException(); +// return new FileCodeModelCodeNamespace(currentProject, typeModel.Namespace); + } + } + + public virtual global::EnvDTE.ProjectItem ProjectItem { + get { + if (context.CurrentProject != null) { + return EnvDTE.ProjectItem.FindByEntity(context.CurrentProject, typeModel); + } + return null; + } + } + + /// + /// Returns true if the current type matches the fully qualified name or any of its + /// base types are a match. + /// + protected override bool GetIsDerivedFrom(string fullName) + { + var td = typeModel.Resolve(); + return td != null && td.GetAllBaseTypeDefinitions().Any(b => b.FullName == fullName); + } + } +} diff --git a/src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeTypeBaseTypes.cs b/src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeTypeBaseTypes.cs deleted file mode 100644 index eb5df445c1..0000000000 --- a/src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeTypeBaseTypes.cs +++ /dev/null @@ -1,28 +0,0 @@ -//// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -//// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) -// -//using System; -//using ICSharpCode.SharpDevelop.Dom; -// -//namespace ICSharpCode.PackageManagement.EnvDTE -//{ -// public class CodeTypeBaseTypes : CodeElementsList -// { -// IProjectContent projectContent; -// IClass c; -// -// public CodeTypeBaseTypes(IProjectContent projectContent, IClass c) -// { -// this.projectContent = projectContent; -// this.c = c; -// AddBaseTypes(); -// } -// -// void AddBaseTypes() -// { -// if (c.BaseType != null) { -// AddCodeElement(CodeClass2.CreateFromBaseType(projectContent, c.BaseType)); -// } -// } -// } -//} diff --git a/src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeTypeMembers.cs b/src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeTypeMembers.cs deleted file mode 100644 index dc170ae809..0000000000 --- a/src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeTypeMembers.cs +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) - -using System; -using ICSharpCode.NRefactory.TypeSystem; -using ICSharpCode.SharpDevelop.Dom; - -namespace ICSharpCode.PackageManagement.EnvDTE -{ - public class CodeTypeMembers : CodeElementsList - { - public CodeTypeMembers(IModelCollection members) - { - foreach (var m in members) { - var e = CreateMember(m); - if (e != null) - base.AddCodeElement(e); - } - // TODO track collection changes - //members.CollectionChanged += members_CollectionChanged; - } - - CodeElement CreateMember(IMemberModel m) - { - switch (m.SymbolKind) { - case SymbolKind.Field: -// return new CodeVariable(m); - throw new NotImplementedException(); - case SymbolKind.Property: - case SymbolKind.Indexer: -// return new CodeProperty2(m); - throw new NotImplementedException(); - case SymbolKind.Event: - return null; // events are not supported in EnvDTE? - case SymbolKind.Method: - case SymbolKind.Operator: - case SymbolKind.Constructor: - case SymbolKind.Destructor: -// return new CodeFunction2(m); - throw new NotImplementedException(); - default: - throw new NotSupportedException("Invalid value for SymbolKind"); - } - } - } -} diff --git a/src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeVariable.cs b/src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeVariable.cs index 17772d6a25..0377696b66 100644 --- a/src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeVariable.cs +++ b/src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeVariable.cs @@ -9,16 +9,15 @@ namespace ICSharpCode.PackageManagement.EnvDTE public class CodeVariable : CodeElement, global::EnvDTE.CodeVariable { readonly IFieldModel field; - readonly IDocumentLoader documentLoader; public CodeVariable() { } - public CodeVariable(IFieldModel field, IDocumentLoader documentLoader) + public CodeVariable(CodeModelContext context, IFieldModel field) + : base(context, field) { this.field = field; - this.documentLoader = documentLoader; } public override global::EnvDTE.vsCMElement Kind { @@ -32,12 +31,12 @@ namespace ICSharpCode.PackageManagement.EnvDTE public override global::EnvDTE.TextPoint GetStartPoint() { - return TextPoint.CreateStartPoint(field.Region, documentLoader); + return TextPoint.CreateStartPoint(context, field.Region); } public override global::EnvDTE.TextPoint GetEndPoint() { - return TextPoint.CreateEndPoint(field.Region, documentLoader); + return TextPoint.CreateEndPoint(context, field.Region); } } } diff --git a/src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/FileCodeModelCodeNamespace.cs b/src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/FileCodeModelCodeNamespace.cs index dab67dcd99..4ef3937761 100644 --- a/src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/FileCodeModelCodeNamespace.cs +++ b/src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/FileCodeModelCodeNamespace.cs @@ -15,8 +15,6 @@ // /// // public class FileCodeModelCodeNamespace : CodeNamespace // { -// FileCodeModelCodeNamespaceMembers members = new FileCodeModelCodeNamespaceMembers(); -// // public FileCodeModelCodeNamespace(IProjectContent projectContent, string namespaceName) // : base(projectContent, namespaceName) // { diff --git a/src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/FileCodeModelCodeNamespaceMembers.cs b/src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/FileCodeModelCodeNamespaceMembers.cs deleted file mode 100644 index 2890104739..0000000000 --- a/src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/FileCodeModelCodeNamespaceMembers.cs +++ /dev/null @@ -1,21 +0,0 @@ -//// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -//// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) -// -//using System; -//using ICSharpCode.SharpDevelop.Dom; -// -//namespace ICSharpCode.PackageManagement.EnvDTE -//{ -// public class FileCodeModelCodeNamespaceMembers : CodeElementsList -// { -// public FileCodeModelCodeNamespaceMembers() -// { -// } -// -// public void AddClass(IProjectContent projectContent, IClass c) -// { -// var codeClass = new CodeClass2(projectContent, c); -// AddCodeElement(codeClass); -// } -// } -//} diff --git a/src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/IClassExtensions.cs b/src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/IClassExtensions.cs deleted file mode 100644 index 35d5181af9..0000000000 --- a/src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/IClassExtensions.cs +++ /dev/null @@ -1,43 +0,0 @@ -//// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -//// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) -// -//using System; -//using System.Linq; -//using ICSharpCode.SharpDevelop.Dom; -// -//namespace ICSharpCode.PackageManagement.EnvDTE -//{ -// public static class IClassExtensions -// { -// /// -// /// Returns true if the class fully qualified name matches the name or -// /// any class in the inheritance tree matches the name. -// /// -// public static bool IsDerivedFrom(this IClass c, string typeName) -// { -// if (c.FullyQualifiedName == typeName) { -// return true; -// } -// -// if (TypeNameMatchesBaseType(c.BaseType, typeName)) { -// return true; -// } -// -// return IsTypeInClassInheritanceTree(c, typeName); -// } -// -// static bool TypeNameMatchesBaseType(IReturnType baseType, string typeName) -// { -// return -// (baseType != null) && -// (baseType.FullyQualifiedName == typeName); -// } -// -// static bool IsTypeInClassInheritanceTree(IClass c, string typeName) -// { -// return c -// .ClassInheritanceTreeClassesOnly -// .Any(inheritedClass => inheritedClass.FullyQualifiedName == typeName); -// } -// } -//} diff --git a/src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/ProjectItem.cs b/src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/ProjectItem.cs index 2110a0f7ec..4873041576 100644 --- a/src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/ProjectItem.cs +++ b/src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/ProjectItem.cs @@ -39,6 +39,11 @@ namespace ICSharpCode.PackageManagement.EnvDTE return new FileProjectItems(this); } + internal static ProjectItem FindByEntity(IProject project, IEntityModel entity) + { + throw new NotImplementedException(); + } + // internal ProjectItem(MSBuildBasedProject project, IClass c) // : this(new Project(project), project.FindFile(c.CompilationUnit.FileName)) // { diff --git a/src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/TextPoint.cs b/src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/TextPoint.cs index dccef8e8de..d6f5c3cadf 100644 --- a/src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/TextPoint.cs +++ b/src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/TextPoint.cs @@ -34,14 +34,14 @@ namespace ICSharpCode.PackageManagement.EnvDTE return new EditPoint(fileName, location, documentLoader); } - internal static TextPoint CreateStartPoint(DomRegion region, IDocumentLoader documentLoader) + internal static TextPoint CreateStartPoint(CodeModelContext context, DomRegion region) { - return new TextPoint(region.FileName, region.Begin, documentLoader); + return new TextPoint(region.FileName, region.Begin, context.DocumentLoader); } - internal static TextPoint CreateEndPoint(DomRegion region, IDocumentLoader documentLoader) + internal static TextPoint CreateEndPoint(CodeModelContext context, DomRegion region) { - return new TextPoint(region.FileName, region.End, documentLoader); + return new TextPoint(region.FileName, region.End, context.DocumentLoader); } } } diff --git a/src/AddIns/Misc/PackageManagement/Project/Src/IProjectContentExtensions.cs b/src/AddIns/Misc/PackageManagement/Project/Src/IProjectContentExtensions.cs index 840293d7d4..ad898061a2 100644 --- a/src/AddIns/Misc/PackageManagement/Project/Src/IProjectContentExtensions.cs +++ b/src/AddIns/Misc/PackageManagement/Project/Src/IProjectContentExtensions.cs @@ -39,5 +39,15 @@ namespace ICSharpCode.PackageManagement throw new Exception("Invalid value for vsCMAccess"); } } + + public static CodeElementsList AsCodeElements(this IModelCollection input) + where T : global::EnvDTE.CodeElement + { + var list = new CodeElementsList(); + // TODO: react to changes + foreach (var element in input) + list.Add(element); + return list; + } } } diff --git a/src/Main/Base/Project/Dom/IEntityModel.cs b/src/Main/Base/Project/Dom/IEntityModel.cs index 2ee42e005f..966186e846 100644 --- a/src/Main/Base/Project/Dom/IEntityModel.cs +++ b/src/Main/Base/Project/Dom/IEntityModel.cs @@ -12,34 +12,13 @@ namespace ICSharpCode.SharpDevelop.Dom /// /// An NRefactory entity as a model. /// - public interface IEntityModel : INotifyPropertyChanged + public interface IEntityModel : ISymbolModel { - /// - /// Gets the name of the entity. - /// - string Name { get; } - - /// - /// Gets the symbol kind of the entity. - /// - SymbolKind SymbolKind { get; } - /// /// Gets/sets the accessibility of the entity. /// Accessibility Accessibility { get; set; } - /// - /// Gets the parent project that contains this entity. - /// May return null if the entity is not part of a project. - /// - IProject ParentProject { get; } - - /// - /// Gets the region where this entity is defined. - /// - DomRegion Region { get; } - /// /// Resolves the entity in the current solution snapshot. /// Returns null if the entity could not be resolved. diff --git a/src/Main/Base/Project/Dom/INamespaceModel.cs b/src/Main/Base/Project/Dom/INamespaceModel.cs new file mode 100644 index 0000000000..3e56bd5896 --- /dev/null +++ b/src/Main/Base/Project/Dom/INamespaceModel.cs @@ -0,0 +1,19 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; + +namespace ICSharpCode.SharpDevelop.Dom +{ + /// + /// Represents a namespace within a single project. + /// + public interface INamespaceModel : ISymbolModel + { + string FullName { get; } + + INamespaceModel ParentNamespace { get; } + IModelCollection ChildNamespaces { get; } + IModelCollection Types { get; } + } +} diff --git a/src/Main/Base/Project/Dom/ISymbolModel.cs b/src/Main/Base/Project/Dom/ISymbolModel.cs new file mode 100644 index 0000000000..f4ddd0a803 --- /dev/null +++ b/src/Main/Base/Project/Dom/ISymbolModel.cs @@ -0,0 +1,38 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; +using System.ComponentModel; +using ICSharpCode.NRefactory.TypeSystem; +using ICSharpCode.SharpDevelop.Parser; +using ICSharpCode.SharpDevelop.Project; + +namespace ICSharpCode.SharpDevelop.Dom +{ + /// + /// An NRefactory symbol as a model. + /// + public interface ISymbolModel : INotifyPropertyChanged + { + /// + /// Gets the name of the entity. + /// + string Name { get; } + + /// + /// Gets the symbol kind of the entity. + /// + SymbolKind SymbolKind { get; } + + /// + /// Gets the parent project that contains this entity. + /// May return null if the entity is not part of a project. + /// + IProject ParentProject { get; } + + /// + /// Gets the region where this entity is defined. + /// + DomRegion Region { get; } + } +} diff --git a/src/Main/Base/Project/Dom/ITypeDefinitionModel.cs b/src/Main/Base/Project/Dom/ITypeDefinitionModel.cs index 8288f6b3e0..cefa5e1fdf 100644 --- a/src/Main/Base/Project/Dom/ITypeDefinitionModel.cs +++ b/src/Main/Base/Project/Dom/ITypeDefinitionModel.cs @@ -13,6 +13,8 @@ namespace ICSharpCode.SharpDevelop.Dom public interface ITypeDefinitionModel : IEntityModel { FullTypeName FullTypeName { get; } + string Namespace { get; } + TypeKind TypeKind { get; } IModelCollection NestedTypes { get; } IModelCollection Members { get; } @@ -38,5 +40,7 @@ namespace ICSharpCode.SharpDevelop.Dom /// Either oldPart or newPart may be null when adding/removed a part. /// void Update(IUnresolvedTypeDefinition oldPart, IUnresolvedTypeDefinition newPart); + + IFieldModel AddField(Accessibility accessiblity, IType type, string name); } } diff --git a/src/Main/Base/Project/Dom/ModelCollectionLinq.cs b/src/Main/Base/Project/Dom/ModelCollectionLinq.cs index 13766c567d..fe5a9bf3e5 100644 --- a/src/Main/Base/Project/Dom/ModelCollectionLinq.cs +++ b/src/Main/Base/Project/Dom/ModelCollectionLinq.cs @@ -30,6 +30,13 @@ namespace ICSharpCode.SharpDevelop.Dom } #endregion + #region Concat + public static IModelCollection Concat(this IModelCollection input1, IModelCollection input2) + { + return new ImmutableModelCollection>(new [] { input1, input2 }).SelectMany(c => c); + } + #endregion + #region Where public static IModelCollection Where(this IModelCollection source, Func predicate) { diff --git a/src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj b/src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj index 8bdfb532a7..94d71d21f3 100644 --- a/src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj +++ b/src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj @@ -90,7 +90,9 @@ + + diff --git a/src/Main/SharpDevelop/Dom/TypeDefinitionModel.cs b/src/Main/SharpDevelop/Dom/TypeDefinitionModel.cs index 9fe6786f8d..6cb205ae92 100644 --- a/src/Main/SharpDevelop/Dom/TypeDefinitionModel.cs +++ b/src/Main/SharpDevelop/Dom/TypeDefinitionModel.cs @@ -46,6 +46,10 @@ namespace ICSharpCode.SharpDevelop.Dom get { return SymbolKind.TypeDefinition; } } + public TypeKind TypeKind { + get { return parts[0].Kind; } + } + public Accessibility Accessibility { get { var td = Resolve(); @@ -71,6 +75,10 @@ namespace ICSharpCode.SharpDevelop.Dom get { return fullTypeName.Name; } } + public string Namespace { + get { return fullTypeName.TopLevelTypeName.Namespace; } + } + #region Resolve public ITypeDefinition Resolve() { @@ -307,5 +315,10 @@ namespace ICSharpCode.SharpDevelop.Dom } } #endregion + + public IFieldModel AddField(Accessibility accessiblity, IType type, string name) + { + throw new NotImplementedException(); + } } }