Skip to content

Commit

Permalink
Introduce ISymbol as a common super-interface of IEntity, INamespace,…
Browse files Browse the repository at this point in the history
… IVariable and ITypeParameter.
  • Loading branch information
dgrunwald committed Jun 12, 2013
1 parent 3ca994d commit 5e9edc0
Show file tree
Hide file tree
Showing 18 changed files with 130 additions and 14 deletions.
4 changes: 2 additions & 2 deletions ICSharpCode.NRefactory.CSharp/Resolver/CSharpOperators.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ bool IMember.IsOverridable {
get { return false; }
}

EntityType IEntity.EntityType {
EntityType ISymbol.EntityType {
get { return EntityType.Operator; }
}

Expand Down Expand Up @@ -243,7 +243,7 @@ string INamedElement.FullName {
get { return "operator"; }
}

string INamedElement.Name {
public string Name {
get { return "operator"; }
}

Expand Down
4 changes: 4 additions & 0 deletions ICSharpCode.NRefactory.CSharp/Resolver/ResolveVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3145,6 +3145,10 @@ public SimpleVariable(DomRegion region, IType type, string name)
this.name = name;
}

public EntityType EntityType {
get { return EntityType.Variable; }
}

public string Name {
get { return name; }
}
Expand Down
6 changes: 5 additions & 1 deletion ICSharpCode.NRefactory.CSharp/TypeSystem/CSharpAssembly.cs
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,14 @@ string INamespace.FullName {
get { return fullName; }
}

string INamespace.Name {
public string Name {
get { return name; }
}

EntityType ISymbol.EntityType {
get { return EntityType.Namespace; }
}

INamespace INamespace.ParentNamespace {
get { return parentNamespace; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,14 @@ string INamespace.FullName {
get { return NamespaceDeclaration.BuildQualifiedName(parentNamespace.FullName, name); }
}

string INamespace.Name {
public string Name {
get { return name; }
}

EntityType ISymbol.EntityType {
get { return EntityType.Namespace; }
}

INamespace INamespace.ParentNamespace {
get { return parentNamespace; }
}
Expand Down
1 change: 1 addition & 0 deletions ICSharpCode.NRefactory/ICSharpCode.NRefactory.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@
<Compile Include="TypeSystem\DefaultSolutionSnapshot.cs" />
<Compile Include="TypeSystem\DomRegion.cs" />
<Compile Include="TypeSystem\EntityType.cs" />
<Compile Include="TypeSystem\ISymbol.cs" />
<Compile Include="TypeSystem\TypeParameterSubstitution.cs" />
<Compile Include="TypeSystem\TypeSystemExtensions.cs" />
<Compile Include="TypeSystem\FullTypeName.cs" />
Expand Down
38 changes: 37 additions & 1 deletion ICSharpCode.NRefactory/TypeSystem/EntityType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,51 @@ namespace ICSharpCode.NRefactory.TypeSystem
public enum EntityType : byte
{
None,
/// <seealso cref="ITypeDefinition"/>
TypeDefinition,
/// <seealso cref="IField"/>
Field,
/// <summary>
/// The symbol is a property, but not an indexer.
/// </summary>
/// <seealso cref="IProperty"/>
Property,
/// <summary>
/// The symbol is an indexer, not a regular property.
/// </summary>
/// <seealso cref="IProperty"/>
Indexer,
/// <seealso cref="IEvent"/>
Event,
/// <summary>
/// The symbol is a method which is not an operator/constructor/destructor or accessor.
/// </summary>
/// <seealso cref="IMethod"/>
Method,
/// <summary>
/// The symbol is a user-defined operator.
/// </summary>
/// <seealso cref="IMethod"/>
Operator,
/// <seealso cref="IMethod"/>
Constructor,
/// <seealso cref="IMethod"/>
Destructor,
Accessor
/// <summary>
/// The accessor method for a property getter/setter or event add/remove.
/// </summary>
/// <seealso cref="IMethod"/>
Accessor,
/// <seealso cref="INamespace"/>
Namespace,
/// <summary>
/// The symbol is a variable, but not a parameter.
/// </summary>
/// <seealso cref="IVariable"/>
Variable,
/// <seealso cref="IParameter"/>
Parameter,
/// <seealso cref="ITypeParameter"/>
TypeParameter,
}
}
6 changes: 3 additions & 3 deletions ICSharpCode.NRefactory/TypeSystem/IEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,12 @@ public interface IUnresolvedEntity : INamedElement, IHasAccessibility
/// <summary>
/// Represents a resolved entity.
/// </summary>
public interface IEntity : ICompilationProvider, INamedElement, IHasAccessibility
public interface IEntity : ISymbol, ICompilationProvider, INamedElement, IHasAccessibility
{
/// <summary>
/// Gets the entity type.
/// Gets the short name of the entity.
/// </summary>
EntityType EntityType { get; }
new string Name { get; }

/// <summary>
/// Gets the complete entity region (including header+body)
Expand Down
4 changes: 2 additions & 2 deletions ICSharpCode.NRefactory/TypeSystem/INamespace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
/// <summary>
/// Represents a resolved namespace.
/// </summary>
public interface INamespace : ICompilationProvider
public interface INamespace : ISymbol, ICompilationProvider
{
// No pointer back to unresolved namespace:
// multiple unresolved namespaces (from different assemblies) get
Expand All @@ -44,7 +44,7 @@ public interface INamespace : ICompilationProvider
/// <summary>
/// Gets the short name of this namespace (e.g. "Collections").
/// </summary>
string Name { get; }
new string Name { get; }

/// <summary>
/// Gets the parent namespace.
Expand Down
39 changes: 39 additions & 0 deletions ICSharpCode.NRefactory/TypeSystem/ISymbol.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.

using System;

namespace ICSharpCode.NRefactory.TypeSystem
{
/// <summary>
/// Interface for type system symbols.
/// </summary>
public interface ISymbol
{
/// <summary>
/// This property returns an enum specifying which kind of symbol this is
/// (which derived interfaces of ISymbol are implemented)
/// </summary>
EntityType EntityType { get; }

/// <summary>
/// Gets the short name of the symbol.
/// </summary>
string Name { get; }
}
}
7 changes: 6 additions & 1 deletion ICSharpCode.NRefactory/TypeSystem/ITypeParameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public interface IUnresolvedTypeParameter : INamedElement
/// <summary>
/// Type parameter of a generic class/method.
/// </summary>
public interface ITypeParameter : IType
public interface ITypeParameter : IType, ISymbol
{
/// <summary>
/// Get the type of this type parameter's owner.
Expand All @@ -84,6 +84,11 @@ public interface ITypeParameter : IType
/// </summary>
int Index { get; }

/// <summary>
/// Gets the name of the type parameter.
/// </summary>
new string Name { get; }

/// <summary>
/// Gets the list of attributes declared on this type parameter.
/// </summary>
Expand Down
4 changes: 2 additions & 2 deletions ICSharpCode.NRefactory/TypeSystem/IVariable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ namespace ICSharpCode.NRefactory.TypeSystem
/// <summary>
/// Represents a variable (name/type pair).
/// </summary>
public interface IVariable
public interface IVariable : ISymbol
{
/// <summary>
/// Gets the name of the variable.
/// </summary>
string Name { get; }
new string Name { get; }

/// <summary>
/// Gets the declaration region of the variable.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ protected AbstractTypeParameter(ICompilation compilation, EntityType ownerType,
this.variance = variance;
}

EntityType ISymbol.EntityType {
get { return EntityType.TypeParameter; }
}

public EntityType OwnerType {
get { return ownerType; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ public DefaultParameter(IType type, string name)
this.defaultValue = defaultValue;
}

EntityType ISymbol.EntityType {
get { return EntityType.Parameter; }
}

public IList<IAttribute> Attributes {
get { return attributes; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,11 @@ string INamespace.FullName {
get { return ns.FullName; }
}

string INamespace.Name {
EntityType ISymbol.EntityType {
get { return EntityType.Namespace; }
}

public string Name {
get { return ns.Name; }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ public ResolvedParameterWithDefaultValue(IConstantValue defaultValue, ITypeResol
this.context = context;
}

EntityType ISymbol.EntityType { get { return EntityType.Parameter; } }
public IType Type { get; internal set; }
public string Name { get; internal set; }
public DomRegion Region { get; internal set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ private DummyTypeParameter(EntityType ownerType, int index)
this.index = index;
}

EntityType ISymbol.EntityType {
get { return EntityType.TypeParameter; }
}

public override string Name {
get {
return (ownerType == EntityType.Method ? "!!" : "!") + index;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ public IEnumerable<ITypeDefinition> Types {
}
}

public EntityType EntityType {
get { return EntityType.Namespace; }
}

public ICompilation Compilation {
get { return compilation; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,8 @@ public SpecializedParameter(IParameter originalParameter, IType newType)
this.newType = newType;
}

EntityType ISymbol.EntityType { get { return EntityType.Parameter; } }

public IList<IAttribute> Attributes {
get { return originalParameter.Attributes; }
}
Expand Down

0 comments on commit 5e9edc0

Please sign in to comment.