Browse Source

Add DefaultMethod implementation.

newNRvisualizers
Daniel Grunwald 15 years ago
parent
commit
d9ca020033
  1. 4
      ICSharpCode.NRefactory.Tests/TypeSystem/CecilLoaderTests.cs
  2. 13
      ICSharpCode.NRefactory.Tests/TypeSystem/TypeSystemTests.cs
  3. 2
      ICSharpCode.NRefactory/ICSharpCode.NRefactory.csproj
  4. 197
      ICSharpCode.NRefactory/TypeSystem/CecilLoader.cs
  5. 1
      ICSharpCode.NRefactory/TypeSystem/ClassType.cs
  6. 3
      ICSharpCode.NRefactory/TypeSystem/EntityType.cs
  7. 248
      ICSharpCode.NRefactory/TypeSystem/Implementation/AbstractMember.cs
  8. 4
      ICSharpCode.NRefactory/TypeSystem/Implementation/BitVector16.cs
  9. 10
      ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultExplicitInterfaceImplementation.cs
  10. 77
      ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultMethod.cs
  11. 5
      ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultTypeDefinition.cs
  12. 2
      ICSharpCode.NRefactory/TypeSystem/Implementation/GetClassTypeReference.cs
  13. 14
      ICSharpCode.NRefactory/TypeSystem/Implementation/MultiTypeResolveContext.cs

4
ICSharpCode.NRefactory.Tests/TypeSystem/CecilLoaderTests.cs

@ -13,7 +13,9 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -13,7 +13,9 @@ namespace ICSharpCode.NRefactory.TypeSystem
[TestFixtureSetUp]
public void SetUp()
{
testCasePC = CecilLoader.LoadAssemblyFile(typeof(TestCase.SimplePublicClass).Assembly.Location);
// use "IncludeInternalMembers" so that Cecil results match C# parser results
CecilLoader loader = new CecilLoader() { IncludeInternalMembers = true };
testCasePC = loader.LoadAssemblyFile(typeof(TestCase.SimplePublicClass).Assembly.Location);
}
}
}

13
ICSharpCode.NRefactory.Tests/TypeSystem/TypeSystemTests.cs

@ -2,6 +2,7 @@ @@ -2,6 +2,7 @@
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
using System;
using System.Linq;
using ICSharpCode.NRefactory.TypeSystem.TestCase;
using NUnit.Framework;
@ -30,5 +31,17 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -30,5 +31,17 @@ namespace ICSharpCode.NRefactory.TypeSystem
Assert.IsFalse(c.IsStatic);
Assert.IsFalse(c.IsShadowing);
}
[Test]
public void SimplePublicClassMethodTest()
{
ITypeDefinition c = testCasePC.GetClass(typeof(SimplePublicClass).FullName, 0, StringComparer.Ordinal);
Assert.AreEqual(2, c.Methods.Count);
IMethod method = c.Methods.Single(m => m.Name == "Method");
Assert.AreEqual(typeof(SimplePublicClass).FullName + ".Method", method.FullName);
Assert.AreSame(c, method.DeclaringType);
}
}
}

2
ICSharpCode.NRefactory/ICSharpCode.NRefactory.csproj

@ -156,12 +156,14 @@ @@ -156,12 +156,14 @@
<Compile Include="TypeSystem\IMember.cs" />
<Compile Include="TypeSystem\IMethod.cs" />
<Compile Include="TypeSystem\Implementation\AbstractFreezable.cs" />
<Compile Include="TypeSystem\Implementation\AbstractMember.cs" />
<Compile Include="TypeSystem\Implementation\AbstractType.cs" />
<Compile Include="TypeSystem\Implementation\AbstractTypeReference.cs" />
<Compile Include="TypeSystem\Implementation\ArrayType.cs" />
<Compile Include="TypeSystem\Implementation\BitVector16.cs" />
<Compile Include="TypeSystem\Implementation\ConstructedType.cs" />
<Compile Include="TypeSystem\Implementation\DefaultExplicitInterfaceImplementation.cs" />
<Compile Include="TypeSystem\Implementation\DefaultMethod.cs" />
<Compile Include="TypeSystem\Implementation\DefaultParameter.cs" />
<Compile Include="TypeSystem\Implementation\DynamicType.cs" />
<Compile Include="TypeSystem\Implementation\GetClassTypeReference.cs" />

197
ICSharpCode.NRefactory/TypeSystem/CecilLoader.cs

@ -4,43 +4,66 @@ @@ -4,43 +4,66 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics.Contracts;
using System.Text;
using ICSharpCode.NRefactory.TypeSystem.Implementation;
using Mono.Cecil;
namespace ICSharpCode.NRefactory.TypeSystem
{
/// <summary>
/// Static methods for loading an IProjectContent from an already compiled assembly.
/// Allows loading an IProjectContent from an already compiled assembly.
/// </summary>
public static class CecilLoader
/// <remarks>Instance methods are not thread-safe; you need to create multiple instances of CecilLoader
/// if you want to load multiple project contents in parallel.</remarks>
public class CecilLoader
{
#region Options
/// <summary>
/// Gets/Sets the early bind context.
/// This context is used to pre-resolve type references - setting this property will cause the CecilLoader
/// to directly reference the resolved types, and create links (<see cref="GetClassTypeReference"/>) to types
/// that could not be resolved.
/// </summary>
public ITypeResolveContext EarlyBindContext { get; set; }
/// <summary>
/// Specifies whether to include internal members. The default is false.
/// </summary>
public bool IncludeInternalMembers { get; set; }
#endregion
#region Load From AssemblyDefinition
public static IProjectContent LoadAssembly(AssemblyDefinition assemblyDefinition)
public IProjectContent LoadAssembly(AssemblyDefinition assemblyDefinition)
{
if (assemblyDefinition == null)
throw new ArgumentNullException("assemblyDefinition");
List<IAttribute> assemblyAttributes = new List<IAttribute>();
ReadAttributes(assemblyDefinition, assemblyAttributes, earlyBindContext: null);
TypeStorage typeStorage = new TypeStorage();
CecilProjectContent pc = new CecilProjectContent(typeStorage, assemblyDefinition.Name.FullName, assemblyAttributes.AsReadOnly());
List<CecilTypeDefinition> types = new List<CecilTypeDefinition>();
foreach (ModuleDefinition module in assemblyDefinition.Modules) {
foreach (TypeDefinition td in module.Types) {
if ((td.Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.Public) {
string name = td.FullName;
if (name.Length == 0 || name[0] == '<')
continue;
types.Add(new CecilTypeDefinition(pc, td));
ITypeResolveContext oldEarlyBindContext = this.EarlyBindContext;
try {
List<IAttribute> assemblyAttributes = new List<IAttribute>();
ReadAttributes(assemblyDefinition, assemblyAttributes);
TypeStorage typeStorage = new TypeStorage();
CecilProjectContent pc = new CecilProjectContent(typeStorage, assemblyDefinition.Name.FullName, assemblyAttributes.AsReadOnly());
this.EarlyBindContext = MultiTypeResolveContext.Combine(pc, this.EarlyBindContext);
List<CecilTypeDefinition> types = new List<CecilTypeDefinition>();
foreach (ModuleDefinition module in assemblyDefinition.Modules) {
foreach (TypeDefinition td in module.Types) {
if (this.IncludeInternalMembers || (td.Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.Public) {
string name = td.FullName;
if (name.Length == 0 || name[0] == '<')
continue;
types.Add(new CecilTypeDefinition(pc, td));
}
}
}
foreach (CecilTypeDefinition c in types) {
c.Init(this);
typeStorage.UpdateType(c);
}
return pc;
} finally {
this.EarlyBindContext = oldEarlyBindContext;
}
foreach (CecilTypeDefinition c in types) {
c.Init(pc);
typeStorage.UpdateType(c);
}
return pc;
}
/// <summary>
@ -49,14 +72,14 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -49,14 +72,14 @@ namespace ICSharpCode.NRefactory.TypeSystem
/// <param name="typeDefinition">The Cecil TypeDefinition.</param>
/// <param name="projectContent">The project content used as parent for the new type.</param>
/// <returns>ITypeDefinition representing the Cecil type.</returns>
public static ITypeDefinition LoadType(TypeDefinition typeDefinition, IProjectContent projectContent)
public ITypeDefinition LoadType(TypeDefinition typeDefinition, IProjectContent projectContent)
{
if (typeDefinition == null)
throw new ArgumentNullException("typeDefinition");
if (projectContent == null)
throw new ArgumentNullException("projectContent");
var c = new CecilTypeDefinition(projectContent, typeDefinition);
c.Init(null);
c.Init(this);
return c;
}
#endregion
@ -96,11 +119,12 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -96,11 +119,12 @@ namespace ICSharpCode.NRefactory.TypeSystem
#endregion
#region Load Assembly From Disk
public static IProjectContent LoadAssemblyFile(string fileName)
public IProjectContent LoadAssemblyFile(string fileName)
{
if (fileName == null)
throw new ArgumentNullException("fileName");
AssemblyDefinition asm = AssemblyDefinition.ReadAssembly(fileName, new ReaderParameters { AssemblyResolver = new DummyAssemblyResolver() });
var param = new ReaderParameters { AssemblyResolver = new DummyAssemblyResolver() };
AssemblyDefinition asm = AssemblyDefinition.ReadAssembly(fileName, param);
return LoadAssembly(asm);
}
@ -129,22 +153,18 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -129,22 +153,18 @@ namespace ICSharpCode.NRefactory.TypeSystem
/// This is used to support the 'dynamic' type.</param>
/// <param name="entity">The entity that owns this type reference.
/// Used for generic type references.</param>
/// <param name="earlyBindContext">Early binding context - used to pre-resolve
/// type references where possible.</param>
public static ITypeReference ReadTypeReference(
public ITypeReference ReadTypeReference(
TypeReference type,
ICustomAttributeProvider typeAttributes = null,
IEntity entity = null,
ITypeResolveContext earlyBindContext = null)
IEntity entity = null)
{
int typeIndex = 0;
return CreateType(type, entity, earlyBindContext, typeAttributes, ref typeIndex);
return CreateType(type, entity, typeAttributes, ref typeIndex);
}
static ITypeReference CreateType(
ITypeReference CreateType(
TypeReference type,
IEntity entity ,
ITypeResolveContext earlyBindContext,
ICustomAttributeProvider typeAttributes, ref int typeIndex)
{
while (type is OptionalModifierType || type is RequiredModifierType) {
@ -162,7 +182,6 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -162,7 +182,6 @@ namespace ICSharpCode.NRefactory.TypeSystem
CreateType(
(type as Mono.Cecil.PointerType).ElementType,
entity,
earlyBindContext,
typeAttributes, ref typeIndex));
} else if (type is Mono.Cecil.ArrayType) {
typeIndex++;
@ -170,7 +189,6 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -170,7 +189,6 @@ namespace ICSharpCode.NRefactory.TypeSystem
CreateType(
(type as Mono.Cecil.ArrayType).ElementType,
entity,
earlyBindContext,
typeAttributes, ref typeIndex),
(type as Mono.Cecil.ArrayType).Rank);
} else if (type is GenericInstanceType) {
@ -209,7 +227,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -209,7 +227,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
if (name.IndexOf('/') > 0) {
string[] nameparts = name.Split('/');
ITypeReference typeRef = GetSimpleType(nameparts[0], earlyBindContext);
ITypeReference typeRef = GetSimpleType(nameparts[0]);
for (int i = 1; i < nameparts.Length; i++) {
int partTypeParameterCount;
string namepart = SplitTypeParameterCountFromReflectionName(nameparts[i], out partTypeParameterCount);
@ -219,15 +237,20 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -219,15 +237,20 @@ namespace ICSharpCode.NRefactory.TypeSystem
} else if (name == "System.Object" && HasDynamicAttribute(typeAttributes, typeIndex)) {
return SharedTypes.Dynamic;
} else {
return GetSimpleType(name, earlyBindContext);
return GetSimpleType(name);
}
}
}
static ITypeReference GetSimpleType(string reflectionName, ITypeResolveContext earlyBindContext)
/// <summary>
/// Gets a type reference for a reflection name.
/// This method does not handle nested types -- it can be only used with top-level types.
/// </summary>
ITypeReference GetSimpleType(string reflectionName)
{
int typeParameterCount;
string name = SplitTypeParameterCountFromReflectionName(reflectionName, out typeParameterCount);
var earlyBindContext = this.EarlyBindContext;
if (earlyBindContext != null) {
IType c = earlyBindContext.GetClass(name, typeParameterCount, StringComparer.Ordinal);
if (c != null)
@ -280,27 +303,34 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -280,27 +303,34 @@ namespace ICSharpCode.NRefactory.TypeSystem
#endregion
#region Read Attributes
static void ReadAttributes(ICustomAttributeProvider attributeProvider, IList<IAttribute> outputList, ITypeResolveContext earlyBindContext)
void ReadAttributes(ICustomAttributeProvider attributeProvider, IList<IAttribute> outputList)
{
foreach (var cecilAttribute in attributeProvider.CustomAttributes) {
outputList.Add(new CecilAttribute(cecilAttribute, earlyBindContext));
outputList.Add(ReadAttribute(cecilAttribute));
}
}
public IAttribute ReadAttribute(CustomAttribute cecilAttribute)
{
if (cecilAttribute == null)
throw new ArgumentNullException("cecilAttribute");
return new CecilAttribute(cecilAttribute, this);
}
sealed class CecilAttribute : Immutable, IAttribute
{
readonly ITypeReference attributeType;
readonly IList<IConstantValue> positionalArguments;
readonly IList<KeyValuePair<string, IConstantValue>> namedArguments;
public CecilAttribute(CustomAttribute ca, ITypeResolveContext earlyBindContext)
public CecilAttribute(CustomAttribute ca, CecilLoader loader)
{
this.attributeType = ReadTypeReference(ca.AttributeType, earlyBindContext: earlyBindContext);
this.attributeType = loader.ReadTypeReference(ca.AttributeType);
try {
if (ca.HasConstructorArguments) {
var posArgs = new List<IConstantValue>();
foreach (var arg in ca.ConstructorArguments) {
posArgs.Add(ReadConstantValue(arg, earlyBindContext));
posArgs.Add(loader.ReadConstantValue(arg));
}
this.positionalArguments = posArgs.AsReadOnly();
} else {
@ -313,10 +343,10 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -313,10 +343,10 @@ namespace ICSharpCode.NRefactory.TypeSystem
if (ca.HasFields || ca.HasProperties) {
var namedArgs = new List<KeyValuePair<string, IConstantValue>>();
foreach (var arg in ca.Fields) {
namedArgs.Add(new KeyValuePair<string, IConstantValue>(arg.Name, ReadConstantValue(arg.Argument, earlyBindContext)));
namedArgs.Add(new KeyValuePair<string, IConstantValue>(arg.Name, loader.ReadConstantValue(arg.Argument)));
}
foreach (var arg in ca.Properties) {
namedArgs.Add(new KeyValuePair<string, IConstantValue>(arg.Name, ReadConstantValue(arg.Argument, earlyBindContext)));
namedArgs.Add(new KeyValuePair<string, IConstantValue>(arg.Name, loader.ReadConstantValue(arg.Argument)));
}
this.namedArguments = namedArgs.AsReadOnly();
} else {
@ -346,19 +376,19 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -346,19 +376,19 @@ namespace ICSharpCode.NRefactory.TypeSystem
#endregion
#region Read Constant Value
static IConstantValue ReadConstantValue(CustomAttributeArgument arg, ITypeResolveContext earlyBindContext)
public IConstantValue ReadConstantValue(CustomAttributeArgument arg)
{
ITypeReference type = ReadTypeReference(arg.Type, earlyBindContext: earlyBindContext);
ITypeReference type = ReadTypeReference(arg.Type);
object value = arg.Value;
TypeReference valueType = value as TypeReference;
if (valueType != null)
value = ReadTypeReference(valueType, earlyBindContext: earlyBindContext);
value = ReadTypeReference(valueType);
return new SimpleConstantValue(type, value);
}
#endregion
#region Read Type Definition
class CecilTypeDefinition : DefaultTypeDefinition
sealed class CecilTypeDefinition : DefaultTypeDefinition
{
TypeDefinition typeDefinition;
@ -374,9 +404,8 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -374,9 +404,8 @@ namespace ICSharpCode.NRefactory.TypeSystem
this.typeDefinition = typeDefinition;
}
public void Init(ITypeResolveContext earlyBindContext)
public void Init(CecilLoader loader)
{
InitNestedTypes(earlyBindContext);
InitModifiers();
if (typeDefinition.HasGenericParameters) {
@ -390,33 +419,36 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -390,33 +419,36 @@ namespace ICSharpCode.NRefactory.TypeSystem
}*/
}
InitNestedTypes(loader); // nested types can be initialized only after generic parameters were created
if (typeDefinition.HasCustomAttributes) {
ReadAttributes(typeDefinition, this.Attributes, earlyBindContext);
loader.ReadAttributes(typeDefinition, this.Attributes);
}
// set base classes
if (typeDefinition.BaseType != null) {
BaseTypes.Add(ReadTypeReference(typeDefinition.BaseType, entity: this, earlyBindContext: earlyBindContext));
BaseTypes.Add(loader.ReadTypeReference(typeDefinition.BaseType, entity: this));
}
if (typeDefinition.HasInterfaces) {
foreach (TypeReference iface in typeDefinition.Interfaces) {
BaseTypes.Add(ReadTypeReference(iface, entity: this, earlyBindContext: earlyBindContext));
BaseTypes.Add(loader.ReadTypeReference(iface, entity: this));
}
}
InitMembers(earlyBindContext);
InitMembers(loader);
this.typeDefinition = null;
Freeze(); // freeze after initialization
}
void InitNestedTypes(ITypeResolveContext earlyBindContext)
void InitNestedTypes(CecilLoader loader)
{
if (!typeDefinition.HasNestedTypes)
return;
foreach (TypeDefinition nestedType in typeDefinition.NestedTypes) {
TypeAttributes visibility = nestedType.Attributes & TypeAttributes.VisibilityMask;
if (visibility == TypeAttributes.NestedPublic
if (loader.IncludeInternalMembers
|| visibility == TypeAttributes.NestedPublic
|| visibility == TypeAttributes.NestedFamily
|| visibility == TypeAttributes.NestedFamORAssem)
{
@ -431,7 +463,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -431,7 +463,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
}
}
foreach (CecilTypeDefinition innerClass in this.InnerClasses) {
innerClass.Init(earlyBindContext);
innerClass.Init(loader);
}
}
@ -454,15 +486,30 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -454,15 +486,30 @@ namespace ICSharpCode.NRefactory.TypeSystem
}
this.IsSealed = td.IsSealed;
this.IsAbstract = td.IsAbstract;
if ((td.Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NestedPublic) {
this.Accessibility = Accessibility.Public;
} else if ((td.Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NestedFamily) {
this.Accessibility = Accessibility.Protected;
} else if ((td.Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NestedFamORAssem) {
// we don't care about the 'OrAssem' part because it's an external assembly
this.Accessibility = Accessibility.Protected;
} else {
this.Accessibility = Accessibility.Public;
switch (td.Attributes & TypeAttributes.VisibilityMask) {
case TypeAttributes.NotPublic:
case TypeAttributes.NestedAssembly:
this.Accessibility = Accessibility.Internal;
break;
case TypeAttributes.Public:
case TypeAttributes.NestedPublic:
this.Accessibility = Accessibility.Public;
break;
case TypeAttributes.NestedPrivate:
this.Accessibility = Accessibility.Private;
break;
case TypeAttributes.NestedFamily:
this.Accessibility = Accessibility.Protected;
break;
case TypeAttributes.NestedFamANDAssem:
this.Accessibility = Accessibility.ProtectedAndInternal;
break;
case TypeAttributes.NestedFamORAssem:
this.Accessibility = Accessibility.ProtectedOrInternal;
break;
case TypeAttributes.LayoutMask:
this.Accessibility = Accessibility;
break;
}
}
@ -489,11 +536,21 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -489,11 +536,21 @@ namespace ICSharpCode.NRefactory.TypeSystem
return false;
}
void InitMembers(ITypeResolveContext earlyBindContext)
void InitMembers(CecilLoader loader)
{
//throw new NotImplementedException();
if (typeDefinition.HasMethods) {
foreach (MethodDefinition method in typeDefinition.Methods) {
this.Methods.Add(loader.ReadMethod(method, this));
}
}
}
}
#endregion
IMethod ReadMethod(MethodDefinition method, ITypeDefinition parentType)
{
DefaultMethod m = new DefaultMethod(parentType, method.Name);
return m;
}
}
}

1
ICSharpCode.NRefactory/TypeSystem/ClassType.cs

@ -2,7 +2,6 @@ @@ -2,7 +2,6 @@
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
using System;
using System.Collections.Generic;
namespace ICSharpCode.NRefactory.TypeSystem
{

3
ICSharpCode.NRefactory/TypeSystem/EntityType.cs

@ -2,11 +2,10 @@ @@ -2,11 +2,10 @@
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
using System;
using System.Collections.Generic;
namespace ICSharpCode.NRefactory.TypeSystem
{
public enum EntityType
public enum EntityType : byte
{
TypeDefinition,
Field,

248
ICSharpCode.NRefactory/TypeSystem/Implementation/AbstractMember.cs

@ -0,0 +1,248 @@ @@ -0,0 +1,248 @@
// Copyright (c) 2010 AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
using System;
using System.Collections.Generic;
namespace ICSharpCode.NRefactory.TypeSystem.Implementation
{
/// <summary>
/// Base class for <see cref="IMember"/> implementations.
/// </summary>
public abstract class AbstractMember : AbstractFreezable, IMember
{
ITypeDefinition declaringTypeDefinition;
ITypeReference returnType = SharedTypes.UnknownType;
IList<IAttribute> attributes;
IList<IExplicitInterfaceImplementation> interfaceImplementations;
DomRegion region;
DomRegion bodyRegion;
string name;
// 1 byte per enum + 2 bytes for flags
Accessibility accessibility;
EntityType entityType;
protected BitVector16 flags;
const ushort FlagSealed = 0x0001;
const ushort FlagAbstract = 0x0002;
const ushort FlagShadowing = 0x0004;
const ushort FlagSynthetic = 0x0008;
const ushort FlagVirtual = 0x0010;
const ushort FlagOverride = 0x0020;
const ushort FlagStatic = 0x0040;
// Flags of form 0xY000 are reserved for use in derived classes (DefaultMethod etc.)
protected override void FreezeInternal()
{
attributes = FreezeList(attributes);
interfaceImplementations = FreezeList(interfaceImplementations);
base.FreezeInternal();
}
protected AbstractMember(ITypeDefinition declaringTypeDefinition, string name, EntityType entityType)
{
if (declaringTypeDefinition == null)
throw new ArgumentNullException("declaringTypeDefinition");
if (name == null)
throw new ArgumentNullException("name");
this.declaringTypeDefinition = declaringTypeDefinition;
this.entityType = entityType;
this.name = name;
}
/* do we really need copy constructor (for specialized members?)
protected AbstractMember(IMember member)
{
if (member == null)
throw new ArgumentNullException("member");
this.declaringTypeDefinition = member.DeclaringTypeDefinition;
this.returnType = member.ReturnType;
this.attributes = CopyList(member.Attributes);
this.interfaceImplementations = CopyList(member.InterfaceImplementations);
this.region = member.Region;
this.bodyRegion = member.BodyRegion;
this.name = member.Name;
this.accessibility = member.Accessibility;
this.IsSealed = member.IsSealed;
this.IsAbstract = member.IsAbstract;
this.IsShadowing = member.IsShadowing;
this.IsSynthetic = member.IsSynthetic;
this.IsVirtual = member.IsVirtual;
this.IsOverride = member.IsOverride;
this.IsStatic = member.IsStatic;
}
static IList<T> CopyList<T>(IList<T> inputList)
{
if (inputList.Count == 0)
return null;
else
return new List<T>(inputList);
}
*/
public ITypeDefinition DeclaringTypeDefinition {
get { return declaringTypeDefinition; }
}
public virtual IType DeclaringType {
get { return declaringTypeDefinition; }
}
public virtual IMember GenericMember {
get { return null; }
}
public ITypeReference ReturnType {
get { return returnType; }
set {
CheckBeforeMutation();
if (value == null)
throw new ArgumentNullException();
returnType = value;
}
}
public IList<IExplicitInterfaceImplementation> InterfaceImplementations {
get {
if (interfaceImplementations == null)
interfaceImplementations = new List<IExplicitInterfaceImplementation>();
return interfaceImplementations;
}
}
public bool IsVirtual {
get { return flags[FlagVirtual]; }
set {
CheckBeforeMutation();
flags[FlagVirtual] = value;
}
}
public bool IsOverride {
get { return flags[FlagOverride]; }
set {
CheckBeforeMutation();
flags[FlagOverride] = value;
}
}
public bool IsOverridable {
get {
return (IsVirtual || IsOverride) && !IsSealed;
}
}
public EntityType EntityType {
get { return entityType; }
set {
CheckBeforeMutation();
entityType = value;
}
}
public DomRegion Region {
get { return region; }
set {
CheckBeforeMutation();
region = value;
}
}
public DomRegion BodyRegion {
get { return bodyRegion; }
set {
CheckBeforeMutation();
bodyRegion = value;
}
}
public IList<IAttribute> Attributes {
get {
if (attributes == null)
attributes = new List<IAttribute>();
return attributes;
}
}
public virtual string Documentation {
get { return null; }
}
public Accessibility Accessibility {
get { return accessibility; }
set {
CheckBeforeMutation();
accessibility = value;
}
}
public bool IsStatic {
get { return flags[FlagStatic]; }
set {
CheckBeforeMutation();
flags[FlagStatic] = value;
}
}
public bool IsAbstract {
get { return flags[FlagAbstract]; }
set {
CheckBeforeMutation();
flags[FlagAbstract] = value;
}
}
public bool IsSealed {
get { return flags[FlagSealed]; }
set {
CheckBeforeMutation();
flags[FlagSealed] = value;
}
}
public bool IsShadowing {
get { return flags[FlagShadowing]; }
set {
CheckBeforeMutation();
flags[FlagShadowing] = value;
}
}
public bool IsSynthetic {
get { return flags[FlagSynthetic]; }
set {
CheckBeforeMutation();
flags[FlagSynthetic] = value;
}
}
public IProjectContent ProjectContent {
get { return declaringTypeDefinition.ProjectContent; }
}
public string Name {
get { return name; }
set {
CheckBeforeMutation();
if (value == null)
throw new ArgumentNullException();
name = value;
}
}
public virtual string FullName {
get {
return this.DeclaringType.FullName + "." + this.Name;
}
}
public string Namespace {
get { return declaringTypeDefinition.Namespace; }
}
public virtual string DotNetName {
get { return this.DeclaringType.DotNetName + "." + this.Name; }
}
}
}

4
ICSharpCode.NRefactory/TypeSystem/Implementation/BitVector16.cs

@ -43,12 +43,12 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -43,12 +43,12 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
public static bool operator ==(BitVector16 left, BitVector16 right)
{
return left.Equals(right);
return left.data == right.data;
}
public static bool operator !=(BitVector16 left, BitVector16 right)
{
return !left.Equals(right);
return left.data != right.data;
}
#endregion
}

10
ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultExplicitInterfaceImplementation.cs

@ -8,7 +8,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -8,7 +8,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
/// <summary>
/// Default implementation for IExplicitInterfaceImplementation.
/// </summary>
public sealed class DefaultExplicitInterfaceImplementation : IExplicitInterfaceImplementation
public sealed class DefaultExplicitInterfaceImplementation : Immutable, IExplicitInterfaceImplementation
{
public ITypeReference InterfaceType { get; private set; }
public string MemberName { get; private set; }
@ -22,13 +22,5 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -22,13 +22,5 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
this.InterfaceType = interfaceType;
this.MemberName = memberName;
}
bool IFreezable.IsFrozen {
get { return true; }
}
void IFreezable.Freeze()
{
}
}
}

77
ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultMethod.cs

@ -0,0 +1,77 @@ @@ -0,0 +1,77 @@
// Copyright (c) 2010 AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
using System;
using System.Collections.Generic;
namespace ICSharpCode.NRefactory.TypeSystem.Implementation
{
/// <summary>
/// Default implementation of <see cref="IMethod" /> interface.
/// </summary>
public class DefaultMethod : AbstractMember, IMethod
{
IList<IAttribute> returnTypeAttributes;
IList<ITypeParameter> typeParameters;
IList<IParameter> parameters;
const ushort FlagExtensionMethod = 0x1000;
protected override void FreezeInternal()
{
returnTypeAttributes = FreezeList(returnTypeAttributes);
typeParameters = FreezeList(typeParameters);
parameters = FreezeList(parameters);
base.FreezeInternal();
}
public DefaultMethod(ITypeDefinition declaringTypeDefinition, string name)
: base(declaringTypeDefinition, name, EntityType.Method)
{
}
public IList<IAttribute> ReturnTypeAttributes {
get {
if (returnTypeAttributes == null)
returnTypeAttributes = new List<IAttribute>();
return returnTypeAttributes;
}
}
public IList<ITypeParameter> TypeParameters {
get {
if (typeParameters == null)
typeParameters = new List<ITypeParameter>();
return typeParameters;
}
}
public bool IsExtensionMethod {
get { return flags[FlagExtensionMethod]; }
set {
CheckBeforeMutation();
flags[FlagExtensionMethod] = value;
}
}
public bool IsConstructor {
get { return this.EntityType == EntityType.Constructor; }
}
public bool IsDestructor {
get { return this.EntityType == EntityType.Destructor; }
}
public bool IsOperator {
get { return this.EntityType == EntityType.Operator; }
}
public IList<IParameter> Parameters {
get {
if (parameters == null)
parameters = new List<IParameter>();
return parameters;
}
}
}
}

5
ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultTypeDefinition.cs

@ -3,10 +3,9 @@ @@ -3,10 +3,9 @@
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Diagnostics.Contracts;
using System.Globalization;
using System.Linq;
using System.Diagnostics.Contracts;
namespace ICSharpCode.NRefactory.TypeSystem.Implementation
{
@ -327,6 +326,8 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -327,6 +326,8 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
public IType Resolve(ITypeResolveContext context)
{
if (context == null)
throw new ArgumentNullException("context");
return this;
}

2
ICSharpCode.NRefactory/TypeSystem/Implementation/GetClassTypeReference.cs

@ -23,6 +23,8 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -23,6 +23,8 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
public override IType Resolve(ITypeResolveContext context)
{
if (context == null)
throw new ArgumentNullException("context");
return context.GetClass(fullTypeName, typeParameterCount, StringComparer.Ordinal);
}

14
ICSharpCode.NRefactory/TypeSystem/Implementation/MultiTypeResolveContext.cs

@ -12,6 +12,20 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -12,6 +12,20 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
/// </summary>
public class MultiTypeResolveContext : ITypeResolveContext
{
/// <summary>
/// Creates a <see cref="MultiTypeResolveContext"/> that combines the given resolve contexts.
/// If one of the input parameters is null, the other input parameter is returned directly.
/// If both input parameters are null, the function returns null.
/// </summary>
public static ITypeResolveContext Combine(ITypeResolveContext a, ITypeResolveContext b)
{
if (a == null)
return b;
if (b == null)
return a;
return new MultiTypeResolveContext(new [] { a, b });
}
readonly ITypeResolveContext[] contexts;
/// <summary>

Loading…
Cancel
Save