// 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; namespace ICSharpCode.SharpDevelop.Dom { public interface IProjectContent { void Dispose(); XmlDoc XmlDoc { get; } /// /// Gets if the project content is representing the current version of the assembly. /// This property always returns true for ParseProjectContents but might return false /// for ReflectionProjectContent/CecilProjectContent if the file was changed. /// bool IsUpToDate { get; } ICollection Classes { get; } /// /// Gets the list of namespaces defined in this project content. Does not include namespaces from /// referenced project contents. /// ICollection NamespaceNames { get; } /// /// Gets the list of referenced project contents. /// ICollection ReferencedContents { get; } event EventHandler ReferencedContentsChanged; /// /// Gets the properties of the language this project content was written in. /// LanguageProperties Language { get; } /// /// Gets the default imports of the project content. Can return null. /// IUsing DefaultImports { get; } /// /// Gets the project for this project content. Returns null for reflection project contents. /// The type used for project objects depends on the host application. /// object Project { get; } /// /// Gets a class that allows to conveniently access commonly used types in the system /// namespace. /// SystemTypes SystemTypes { get; } IList GetAssemblyAttributes(); string GetXmlDocumentation(string memberTag); void AddClassToNamespaceList(IClass addClass); void RemoveCompilationUnit(ICompilationUnit oldUnit); void UpdateCompilationUnit(ICompilationUnit oldUnit, ICompilationUnit parserOutput, string fileName); IClass GetClass(string typeName, int typeParameterCount); bool NamespaceExists(string name); List GetNamespaceContents(string nameSpace); List GetAllContents(); IClass GetClass(string typeName, int typeParameterCount, LanguageProperties language, GetClassOptions options); bool NamespaceExists(string name, LanguageProperties language, bool lookInReferences); /// /// Adds the contents of the specified to the . /// /// If true, contents of referenced projects will be added as well (not recursive - just 1 level deep). void AddNamespaceContents(List list, string subNameSpace, LanguageProperties language, bool lookInReferences); /// /// Adds the contents of all namespaces in this project to the . /// /// If true, contents of referenced projects will be added as well (not recursive - just 1 level deep). void AddAllContents(List list, LanguageProperties language, bool lookInReferences); SearchTypeResult SearchType(SearchTypeRequest request); /// /// Gets the position of a member in this project content (not a referenced one). /// /// The full class name in Reflection syntax (always case sensitive, ` for generics) /// Whether to search in referenced project contents. IClass GetClassByReflectionName(string fullMemberName, bool lookInReferences); /// /// Gets the definition position of the class/member. /// /// The entity to get the position from. FilePosition GetPosition(IEntity entity); /// /// Gets whether internals in the project content are visible to the other project content. /// bool InternalsVisibleTo(IProjectContent otherProjectContent); /// /// Gets the name of the assembly. /// string AssemblyName { get; } } [Flags] public enum GetClassOptions { None = 0, /// /// Also look in referenced project contents. /// LookInReferences = 1, /// /// Try if the class is an inner class. /// LookForInnerClass = 2, /// /// Do not return a class with the wrong type parameter count. /// If this flag is not set, GetClass will return a class with the same name but a different /// type parameter count if no exact match is found. /// ExactMatch = 4, /// /// Default = LookInReferences + LookForInnerClass /// Default = LookInReferences | LookForInnerClass } public sealed class SearchTypeRequest { IUsingScope currentUsingScope; ICompilationUnit currentCompilationUnit; public string Name { get; set; } public int TypeParameterCount { get; set; } public IClass CurrentType { get; set; } public int CaretLine { get; set; } public int CaretColumn { get; set; } public ICompilationUnit CurrentCompilationUnit { get { return currentCompilationUnit; } set { if (value == null) throw new ArgumentNullException("CurrentCompilationUnit"); currentCompilationUnit = value; } } public IUsingScope CurrentUsingScope { get { return currentUsingScope; } set { if (value == null) throw new ArgumentNullException("CurrentUsingScope"); currentUsingScope = value; } } public SearchTypeRequest(string name, int typeParameterCount, IClass currentType, int caretLine, int caretColumn) { if (currentType == null) throw new ArgumentNullException("currentType"); this.Name = name; this.TypeParameterCount = typeParameterCount; this.CurrentCompilationUnit = currentType.CompilationUnit; this.CurrentType = currentType != null ? currentType.GetCompoundClass() : null; this.CaretLine = caretLine; this.CaretColumn = caretColumn; this.CurrentUsingScope = currentType.UsingScope; } public SearchTypeRequest(string name, int typeParameterCount, IClass currentType, ICompilationUnit currentCompilationUnit, int caretLine, int caretColumn) { if (currentCompilationUnit == null) throw new ArgumentNullException("currentCompilationUnit"); this.Name = name; this.TypeParameterCount = typeParameterCount; this.CurrentCompilationUnit = currentCompilationUnit; this.CurrentType = currentType != null ? currentType.GetCompoundClass() : null; this.CaretLine = caretLine; this.CaretColumn = caretColumn; this.CurrentUsingScope = (currentType != null) ? currentType.UsingScope : currentCompilationUnit.UsingScope; } } public struct SearchTypeResult { public static readonly SearchTypeResult Empty = default(SearchTypeResult); readonly IReturnType result; readonly IUsing usedUsing; readonly string namespaceResult; public SearchTypeResult(IReturnType result) : this(result, null) {} public SearchTypeResult(IClass c) : this(c != null ? c.DefaultReturnType : null) {} public SearchTypeResult(IReturnType result, IUsing usedUsing) { this.result = result; this.usedUsing = usedUsing; this.namespaceResult = null; } public SearchTypeResult(string namespaceResult, IUsing usedUsing) { this.result = null; this.usedUsing = usedUsing; this.namespaceResult = namespaceResult; } /// /// Gets the result type. /// public IReturnType Result { get { return result; } } /// /// Gets the using that was used for this type lookup. /// public IUsing UsedUsing { get { return usedUsing; } } public string NamespaceResult { get { return namespaceResult; } } } /// /// Used in 'GetNamespaceContents' result to represent a namespace. /// public class NamespaceEntry : ICompletionEntry { public string Name { get; private set; } public NamespaceEntry(string name) { if (name == null) throw new ArgumentNullException("name"); this.Name = name; } public override int GetHashCode() { return Name.GetHashCode(); } public override bool Equals(object obj) { NamespaceEntry e = obj as NamespaceEntry; return e != null && e.Name == this.Name; } public override string ToString() { return Name; } } }