diff options
author | Mike Krüger <mkrueger@xamarin.com> | 2011-12-01 11:23:02 +0400 |
---|---|---|
committer | Mike Krüger <mkrueger@xamarin.com> | 2011-12-01 11:23:02 +0400 |
commit | c1c3e6cd7921e158bf5826b6cf7a08e1967e19e1 (patch) | |
tree | 5b271e1130c0ae00e6467617a82ad274a08495ce /main/contrib | |
parent | e397f88ca1002c52701ab2b95db44106a8df8f9f (diff) |
[Refactoring] Track API changes.
Diffstat (limited to 'main/contrib')
5 files changed, 90 insertions, 68 deletions
diff --git a/main/contrib/ICSharpCode.NRefactory.CSharp/Resolver/CSharpOperators.cs b/main/contrib/ICSharpCode.NRefactory.CSharp/Resolver/CSharpOperators.cs index 768639a108..1d6a53efd0 100644 --- a/main/contrib/ICSharpCode.NRefactory.CSharp/Resolver/CSharpOperators.cs +++ b/main/contrib/ICSharpCode.NRefactory.CSharp/Resolver/CSharpOperators.cs @@ -143,15 +143,15 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver get { return false; } } - EntityType IEntity.EntityType { + EntityType IBaseEntity.EntityType { get { return EntityType.Operator; } } - DomRegion IEntity.Region { + DomRegion IBaseEntity.Region { get { return DomRegion.Empty; } } - DomRegion IEntity.BodyRegion { + DomRegion IBaseEntity.BodyRegion { get { return DomRegion.Empty; } } @@ -167,23 +167,23 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver get { return Accessibility.Public; } } - bool IEntity.IsStatic { + bool IBaseEntity.IsStatic { get { return true; } } - bool IEntity.IsAbstract { + bool IBaseEntity.IsAbstract { get { return false; } } - bool IEntity.IsSealed { + bool IBaseEntity.IsSealed { get { return false; } } - bool IEntity.IsShadowing { + bool IBaseEntity.IsShadowing { get { return false; } } - bool IEntity.IsSynthetic { + bool IBaseEntity.IsSynthetic { get { return true; } } diff --git a/main/contrib/ICSharpCode.NRefactory.CSharp/TypeSystem/CSharpParsedFile.cs b/main/contrib/ICSharpCode.NRefactory.CSharp/TypeSystem/CSharpParsedFile.cs index bd3ec9f677..d4e99fcbc4 100644 --- a/main/contrib/ICSharpCode.NRefactory.CSharp/TypeSystem/CSharpParsedFile.cs +++ b/main/contrib/ICSharpCode.NRefactory.CSharp/TypeSystem/CSharpParsedFile.cs @@ -20,6 +20,7 @@ using System; using System.Collections.Generic; using ICSharpCode.NRefactory.TypeSystem; using ICSharpCode.NRefactory.TypeSystem.Implementation; +using System.Linq; namespace ICSharpCode.NRefactory.CSharp.TypeSystem { @@ -104,6 +105,28 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem } return rootUsingScope; } + + public CSharpTypeResolveContext GetTypeResolveContext (ICompilation compilation, TextLocation loc) + { + var rctx = new CSharpTypeResolveContext (compilation.MainAssembly); + rctx = rctx.WithUsingScope (GetUsingScope (loc).Resolve (compilation)); + var curDef = GetInnermostTypeDefinition (loc); + if (curDef != null) { + var resolvedDef = curDef.Resolve (rctx).GetDefinition (); + rctx = rctx.WithCurrentTypeDefinition (resolvedDef); + + var curMember = resolvedDef.Members.FirstOrDefault (m => m.Region.Begin <= loc && loc < m.BodyRegion.End); + if (curMember != null) + rctx = rctx.WithCurrentMember (curMember); + } + + return rctx; + } + + public ICSharpCode.NRefactory.CSharp.Resolver.CSharpResolver GetResolver (ICompilation compilation, TextLocation loc) + { + return new ICSharpCode.NRefactory.CSharp.Resolver.CSharpResolver (GetTypeResolveContext (compilation, loc)); + } public IUnresolvedTypeDefinition GetTopLevelTypeDefinition(TextLocation location) { diff --git a/main/contrib/ICSharpCode.NRefactory/TypeSystem/ExtensionMethods.cs b/main/contrib/ICSharpCode.NRefactory/TypeSystem/ExtensionMethods.cs index 27e4016cdb..06f2de9aac 100644 --- a/main/contrib/ICSharpCode.NRefactory/TypeSystem/ExtensionMethods.cs +++ b/main/contrib/ICSharpCode.NRefactory/TypeSystem/ExtensionMethods.cs @@ -262,5 +262,26 @@ namespace ICSharpCode.NRefactory.TypeSystem return new ProjectedList<ITypeResolveContext, IConstantValue, ResolveResult>(context, constantValues, (c, t) => t.Resolve(c)); } #endregion + + #region GetSubTypeDefinitions + public static IEnumerable<ITypeDefinition> GetSubTypeDefinitions (this IType baseType) + { + var def = baseType.GetDefinition (); + if (def == null) + return Enumerable.Empty<ITypeDefinition> (); + return def.GetSubTypeDefinitions (); + } + + /// <summary> + /// Gets all sub type definitions defined in a context. + /// </summary> + public static IEnumerable<ITypeDefinition> GetSubTypeDefinitions (this ITypeDefinition baseType) + { + foreach (var contextType in baseType.Compilation.GetAllTypeDefinitions ()) { + if (contextType.IsDerivedFrom (baseType)) + yield return contextType; + } + } + #endregion } } diff --git a/main/contrib/ICSharpCode.NRefactory/TypeSystem/IEntity.cs b/main/contrib/ICSharpCode.NRefactory/TypeSystem/IEntity.cs index 4426beef3c..135e8c55d7 100644 --- a/main/contrib/ICSharpCode.NRefactory/TypeSystem/IEntity.cs +++ b/main/contrib/ICSharpCode.NRefactory/TypeSystem/IEntity.cs @@ -22,10 +22,7 @@ using System.Diagnostics.Contracts; namespace ICSharpCode.NRefactory.TypeSystem { - /// <summary> - /// Represents an unresolved entity. - /// </summary> - public interface IUnresolvedEntity : INamedElement, IHasAccessibility + public interface IBaseEntity : INamedElement, IHasAccessibility { /// <summary> /// Gets the entity type. @@ -42,25 +39,7 @@ namespace ICSharpCode.NRefactory.TypeSystem /// </summary> DomRegion BodyRegion { get; } - /// <summary> - /// Gets the declaring class. - /// For members, this is the class that contains the member. - /// For nested classes, this is the outer class. For top-level entities, this property returns null. - /// </summary> - IUnresolvedTypeDefinition DeclaringTypeDefinition { get; } - - /// <summary> - /// Gets the parsed file in which this entity is defined. - /// Returns null if this entity wasn't parsed from source code (e.g. loaded from a .dll with CecilLoader). - /// </summary> - IParsedFile ParsedFile { get; } - - /// <summary> - /// Gets the attributes on this entity. - /// </summary> - IList<IUnresolvedAttribute> Attributes { get; } - - /// <summary> + /// <summary> /// Gets whether this entity is static. /// Returns true if either the 'static' or the 'const' modifier is set. /// </summary> @@ -90,25 +69,34 @@ namespace ICSharpCode.NRefactory.TypeSystem } /// <summary> - /// Represents a resolved entity. + /// Represents an unresolved entity. /// </summary> - public interface IEntity : IResolved, INamedElement, IHasAccessibility + public interface IUnresolvedEntity : IBaseEntity { /// <summary> - /// Gets the entity type. + /// Gets the declaring class. + /// For members, this is the class that contains the member. + /// For nested classes, this is the outer class. For top-level entities, this property returns null. /// </summary> - EntityType EntityType { get; } + IUnresolvedTypeDefinition DeclaringTypeDefinition { get; } /// <summary> - /// Gets the complete entity region (including header+body) + /// Gets the parsed file in which this entity is defined. + /// Returns null if this entity wasn't parsed from source code (e.g. loaded from a .dll with CecilLoader). /// </summary> - DomRegion Region { get; } + IParsedFile ParsedFile { get; } /// <summary> - /// Gets the entity body region. + /// Gets the attributes on this entity. /// </summary> - DomRegion BodyRegion { get; } - + IList<IUnresolvedAttribute> Attributes { get; } + } + + /// <summary> + /// Represents a resolved entity. + /// </summary> + public interface IEntity : IBaseEntity, IResolved + { /// <summary> /// Gets the declaring class. /// For members, this is the class that contains the member. @@ -138,33 +126,5 @@ namespace ICSharpCode.NRefactory.TypeSystem /// Gets the documentation for this entity. /// </summary> string Documentation { get; } - - /// <summary> - /// Gets whether this entity is static. - /// Returns true if either the 'static' or the 'const' modifier is set. - /// </summary> - bool IsStatic { get; } - - /// <summary> - /// Returns whether this entity is abstract. - /// </summary> - /// <remarks>Static classes also count as abstract classes.</remarks> - bool IsAbstract { get; } - - /// <summary> - /// Returns whether this entity is sealed. - /// </summary> - /// <remarks>Static classes also count as sealed classes.</remarks> - bool IsSealed { get; } - - /// <summary> - /// Gets whether this member is declared to be shadowing another member with the same name. - /// </summary> - bool IsShadowing { get; } - - /// <summary> - /// Gets whether this member is generated by a macro/compiler feature. - /// </summary> - bool IsSynthetic { get; } } } diff --git a/main/contrib/ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultUnresolvedTypeDefinition.cs b/main/contrib/ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultUnresolvedTypeDefinition.cs index ffd05d62cc..e7acbe4d04 100644 --- a/main/contrib/ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultUnresolvedTypeDefinition.cs +++ b/main/contrib/ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultUnresolvedTypeDefinition.cs @@ -40,6 +40,24 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation this.EntityType = EntityType.TypeDefinition; } + public DefaultUnresolvedTypeDefinition(string fullName) + { + string namespaceName; + string name; + int idx = fullName.LastIndexOf ('.'); + if (idx > 0) { + namespaceName = fullName.Substring (0, idx); + name = fullName.Substring (idx); + } else { + namespaceName = ""; + name = fullName; + } + + this.EntityType = EntityType.TypeDefinition; + this.namespaceName = namespaceName; + this.Name = name; + } + public DefaultUnresolvedTypeDefinition(string namespaceName, string name) { this.EntityType = EntityType.TypeDefinition; |