Browse Source

Implemented ITypeDefinitionModel.NestedTypes.

newNRvisualizers
Daniel Grunwald 13 years ago
parent
commit
05c08b91b3
  1. 2
      src/Main/Base/Project/Util/CustomThreadPoolTaskScheduler.cs
  2. 12
      src/Main/SharpDevelop/Dom/MemberModel.cs
  3. 114
      src/Main/SharpDevelop/Dom/NestedTypeDefinitionModelCollection.cs
  4. 1
      src/Main/SharpDevelop/Dom/TopLevelTypeDefinitionModelCollection.cs
  5. 23
      src/Main/SharpDevelop/Dom/TypeDefinitionModel.cs
  6. 1
      src/Main/SharpDevelop/SharpDevelop.csproj

2
src/Main/Base/Project/Util/CustomThreadPoolTaskScheduler.cs

@ -36,7 +36,7 @@ namespace ICSharpCode.SharpDevelop @@ -36,7 +36,7 @@ namespace ICSharpCode.SharpDevelop
protected virtual void StartThread(ThreadStart start)
{
var t = new Thread(RunThread);
var t = new Thread(start);
t.IsBackground = true;
t.Start();
}

12
src/Main/SharpDevelop/Dom/MemberModel.cs

@ -66,18 +66,6 @@ namespace ICSharpCode.SharpDevelop.Dom @@ -66,18 +66,6 @@ namespace ICSharpCode.SharpDevelop.Dom
get { return member.Name; }
}
/// <summary>
/// Gets the full type name of the type that declares this member.
/// </summary>
public FullTypeName DeclaringTypeName {
get {
if (member.DeclaringTypeDefinition != null)
return member.DeclaringTypeDefinition.FullTypeName;
else
return new TopLevelTypeName(string.Empty, string.Empty);
}
}
#region Resolve
public IMember Resolve()
{

114
src/Main/SharpDevelop/Dom/NestedTypeDefinitionModelCollection.cs

@ -0,0 +1,114 @@ @@ -0,0 +1,114 @@
// 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.Generic;
using System.Collections.Specialized;
using ICSharpCode.NRefactory.TypeSystem;
namespace ICSharpCode.SharpDevelop.Dom
{
sealed class NestedTypeDefinitionModelCollection : IModelCollection<ITypeDefinitionModel>
{
readonly IEntityModelContext context;
List<TypeDefinitionModel> list = new List<TypeDefinitionModel>();
public NestedTypeDefinitionModelCollection(IEntityModelContext context)
{
this.context = context;
}
public event NotifyCollectionChangedEventHandler CollectionChanged;
public IEnumerator<ITypeDefinitionModel> GetEnumerator()
{
return list.GetEnumerator();
}
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
return list.GetEnumerator();
}
public int Count {
get { return list.Count; }
}
public TypeDefinitionModel FindModel(string name, int tpc)
{
foreach (var typeDef in list) {
if (typeDef.Name == name && typeDef.FullTypeName.TypeParameterCount == tpc)
return typeDef;
}
return null;
}
public void Update(IList<IUnresolvedTypeDefinition> oldTypes, IList<IUnresolvedTypeDefinition> newTypes)
{
List<ITypeDefinitionModel> oldModels = null;
List<ITypeDefinitionModel> newModels = null;
bool[] oldTypeDefHandled = null;
if (oldTypes != null) {
oldTypeDefHandled = new bool[oldTypes.Count];
}
if (newTypes != null) {
foreach (var newPart in newTypes) {
TypeDefinitionModel model = FindModel(newPart.Name, newPart.TypeParameters.Count);
if (model != null) {
// Existing type changed
// Find a matching old part:
IUnresolvedTypeDefinition oldPart = null;
if (oldTypes != null) {
for (int i = 0; i < oldTypeDefHandled.Length; i++) {
if (oldTypeDefHandled[i])
continue;
if (oldTypes[i].Name == newPart.Name && oldTypes[i].TypeParameters.Count == newPart.TypeParameters.Count) {
oldTypeDefHandled[i] = true;
oldPart = oldTypes[i];
break;
}
}
}
model.Update(oldPart, newPart);
} else {
// New type added
model = new TypeDefinitionModel(context, newPart);
list.Add(model);
if (newModels == null)
newModels = new List<ITypeDefinitionModel>();
newModels.Add(model);
}
}
}
// Remove all old parts that weren't updated:
if (oldTypes != null) {
for (int i = 0; i < oldTypeDefHandled.Length; i++) {
if (!oldTypeDefHandled[i]) {
IUnresolvedTypeDefinition oldPart = oldTypes[i];
TypeDefinitionModel model = FindModel(oldPart.Name, oldPart.TypeParameters.Count);
if (model != null) {
// Remove the part from the model
if (model.Parts.Count > 1) {
model.Update(oldPart, null);
} else {
list.Remove(model);
if (oldModels == null)
oldModels = new List<ITypeDefinitionModel>();
oldModels.Add(model);
}
}
}
}
}
// Raise the event if necessary:
if (CollectionChanged != null) {
if (oldModels != null && newModels != null)
CollectionChanged(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Replace, newModels, oldModels));
else if (oldModels != null)
CollectionChanged(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, oldModels));
else if (newModels != null)
CollectionChanged(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, newModels));
}
}
}
}

1
src/Main/SharpDevelop/Dom/TopLevelTypeDefinitionModelCollection.cs

@ -3,7 +3,6 @@ @@ -3,7 +3,6 @@
using System;
using System.Collections;
using System.Collections.ObjectModel;
using System.Collections.Generic;
using System.Collections.Specialized;
using ICSharpCode.NRefactory.TypeSystem;

23
src/Main/SharpDevelop/Dom/TypeDefinitionModel.cs

@ -6,7 +6,6 @@ using System.Collections; @@ -6,7 +6,6 @@ using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using ICSharpCode.NRefactory.TypeSystem;
using ICSharpCode.SharpDevelop.Parser;
@ -218,15 +217,30 @@ namespace ICSharpCode.SharpDevelop.Dom @@ -218,15 +217,30 @@ namespace ICSharpCode.SharpDevelop.Dom
#endregion
#region Nested Types collection
NestedTypeDefinitionModelCollection nestedTypes;
public IModelCollection<ITypeDefinitionModel> NestedTypes {
get {
throw new NotImplementedException();
if (nestedTypes == null) {
nestedTypes = new NestedTypeDefinitionModelCollection(context);
foreach (var part in parts) {
nestedTypes.Update(null, part.NestedTypes);
}
}
return nestedTypes;
}
}
public ITypeDefinitionModel GetNestedType(string name, int atpc)
{
throw new NotImplementedException();
foreach (var nestedType in this.NestedTypes) {
if (nestedType.Name == name) {
var nestedTypeFullName = nestedType.FullTypeName;
if (nestedTypeFullName.GetNestedTypeAdditionalTypeParameterCount(nestedTypeFullName.NestingLevel - 1) == atpc)
return nestedType;
}
}
return null;
}
#endregion
@ -264,6 +278,9 @@ namespace ICSharpCode.SharpDevelop.Dom @@ -264,6 +278,9 @@ namespace ICSharpCode.SharpDevelop.Dom
members.UpdatePart(partIndex, newPart);
}
}
if (nestedTypes != null) {
nestedTypes.Update(oldPart != null ? oldPart.NestedTypes : null, newPart != null ? newPart.NestedTypes : null);
}
}
#endregion
}

1
src/Main/SharpDevelop/SharpDevelop.csproj

@ -83,6 +83,7 @@ @@ -83,6 +83,7 @@
<ItemGroup>
<Compile Include="Dom\ModelFactory.cs" />
<Compile Include="Dom\MemberModel.cs" />
<Compile Include="Dom\NestedTypeDefinitionModelCollection.cs" />
<Compile Include="Dom\TopLevelTypeDefinitionModelCollection.cs" />
<Compile Include="Dom\TreeNodeFactoryService.cs" />
<Compile Include="Dom\TypeDefinitionModel.cs" />

Loading…
Cancel
Save