Browse Source

Add IsPartial flag to indicate class is partial in NRefactory type system.

A single C# class with the partial keyword but without any other parts
can now be identified.
pull/375/head
Matt Ward 12 years ago
parent
commit
4172305544
  1. 1
      src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/TypeSystem/TypeSystemConvertVisitor.cs
  2. 4
      src/Libraries/NRefactory/ICSharpCode.NRefactory.Cecil/CecilLoader.cs
  3. 11
      src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Parser/TypeSystemConvertVisitorTests.cs
  4. 5
      src/Libraries/NRefactory/ICSharpCode.NRefactory/TypeSystem/ITypeDefinition.cs
  5. 2
      src/Libraries/NRefactory/ICSharpCode.NRefactory/TypeSystem/Implementation/AbstractUnresolvedEntity.cs
  6. 4
      src/Libraries/NRefactory/ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultUnresolvedMethod.cs
  7. 8
      src/Libraries/NRefactory/ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultUnresolvedTypeDefinition.cs

1
src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/TypeSystem/TypeSystemConvertVisitor.cs

@ -827,6 +827,7 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem @@ -827,6 +827,7 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem
td.IsAbstract = (modifiers & (Modifiers.Abstract | Modifiers.Static)) != 0;
td.IsSealed = (modifiers & (Modifiers.Sealed | Modifiers.Static)) != 0;
td.IsShadowing = (modifiers & Modifiers.New) != 0;
td.IsPartial = (modifiers & Modifiers.Partial) != 0;
}
static void ApplyModifiers(AbstractUnresolvedMember m, Modifiers modifiers)

4
src/Libraries/NRefactory/ICSharpCode.NRefactory.Cecil/CecilLoader.cs

@ -1272,6 +1272,10 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -1272,6 +1272,10 @@ namespace ICSharpCode.NRefactory.TypeSystem
// FlagHasNoExtensionMethods is unused in LazyCecilTypeDefinition
}
public bool IsPartial {
get { return false; }
}
public override object Clone()
{
throw new NotSupportedException();

11
src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Parser/TypeSystemConvertVisitorTests.cs

@ -115,6 +115,17 @@ namespace ICSharpCode.NRefactory.CSharp.Parser @@ -115,6 +115,17 @@ namespace ICSharpCode.NRefactory.CSharp.Parser
Assert.That(type.Attributes.Select(a => a.AttributeType.FullName).ToList(), Is.EqualTo(new[] { "My3Attribute" }));
}
[Test]
public void PartialClassWithSinglePart()
{
var syntaxTree = SyntaxTree.Parse("partial class Test {}");
syntaxTree.FileName = "a.cs";
var content = CreateContent(syntaxTree.ToTypeSystem());
var typeDef = content.CreateCompilation().MainAssembly.GetTypeDefinition("", "Test");
Assert.AreEqual(1, typeDef.Parts.Count);
var part = typeDef.Parts.Single();
Assert.IsTrue(part.IsPartial);
}
}
[TestFixture]

5
src/Libraries/NRefactory/ICSharpCode.NRefactory/TypeSystem/ITypeDefinition.cs

@ -49,6 +49,11 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -49,6 +49,11 @@ namespace ICSharpCode.NRefactory.TypeSystem
/// </summary>
bool? HasExtensionMethods { get; }
/// <summary>
/// Returns whether this type is partial.
/// </summary>
bool IsPartial { get; }
/// <summary>
/// Gets whether this unresolved type definition causes the addition of a default constructor
/// if no other constructor is present.

2
src/Libraries/NRefactory/ICSharpCode.NRefactory/TypeSystem/Implementation/AbstractUnresolvedEntity.cs

@ -64,7 +64,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -64,7 +64,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
internal const ushort FlagFieldIsFixedSize = 0x4000;
// flags for DefaultMethod:
internal const ushort FlagExtensionMethod = 0x1000;
internal const ushort FlagPartialMethod = 0x2000;
internal const ushort FlagPartial = 0x2000;
internal const ushort FlagHasBody = 0x4000;
internal const ushort FlagAsyncMethod = 0x8000;

4
src/Libraries/NRefactory/ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultUnresolvedMethod.cs

@ -115,10 +115,10 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -115,10 +115,10 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
}
public bool IsPartial {
get { return flags[FlagPartialMethod]; }
get { return flags[FlagPartial]; }
set {
ThrowIfFrozen();
flags[FlagPartialMethod] = value;
flags[FlagPartial] = value;
}
}

8
src/Libraries/NRefactory/ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultUnresolvedTypeDefinition.cs

@ -130,6 +130,14 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -130,6 +130,14 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
}
}
public bool IsPartial {
get { return flags[FlagPartial]; }
set {
ThrowIfFrozen();
flags[FlagPartial] = value;
}
}
public override string Namespace {
get { return namespaceName; }
set {

Loading…
Cancel
Save