Browse Source

Implemented TopLevelTypeDefinitionModelCollection.

newNRvisualizers
Daniel Grunwald 13 years ago
parent
commit
925837dee8
  1. 11
      src/Main/Base/Project/Dom/ConcatModelCollection.cs
  2. 2
      src/Main/Base/Project/Dom/IModelCollection.cs
  3. 2
      src/Main/Base/Project/Dom/IModelFactory.cs
  4. 5
      src/Main/Base/Project/Dom/ITypeDefinitionModel.cs
  5. 14
      src/Main/Base/Project/Dom/ITypeDefinitionModelCollection.cs
  6. 3
      src/Main/Base/Project/Dom/KeyedModelCollection.cs
  7. 2
      src/Main/Base/Project/Src/Project/CompilableProject.cs
  8. 8
      src/Main/Base/Test/Dom/CSharpModelTests.cs
  9. 2
      src/Main/SharpDevelop/Dom/ModelFactory.cs
  10. 99
      src/Main/SharpDevelop/Dom/TopLevelTypeDefinitionModelCollection.cs
  11. 42
      src/Main/SharpDevelop/Dom/TypeDefinitionModel.cs

11
src/Main/Base/Project/Dom/ConcatModelCollection.cs

@ -152,16 +152,5 @@ namespace ICSharpCode.SharpDevelop.Dom
{ {
return GetEnumerator(); return GetEnumerator();
} }
public T this[int index] {
get {
int inputIndex = 0;
while (index >= inputs[inputIndex].Count) {
index -= inputs[inputIndex].Count;
inputIndex++;
}
return inputs[inputIndex][index];
}
}
} }
} }

2
src/Main/Base/Project/Dom/IModelCollection.cs

@ -10,7 +10,7 @@ namespace ICSharpCode.SharpDevelop.Dom
/// <summary> /// <summary>
/// A read-only collection that provides change notifications. /// A read-only collection that provides change notifications.
/// </summary> /// </summary>
public interface IModelCollection<out T> : IReadOnlyList<T>, INotifyCollectionChanged public interface IModelCollection<out T> : IReadOnlyCollection<T>, INotifyCollectionChanged
{ {
} }
} }

2
src/Main/Base/Project/Dom/IModelFactory.cs

@ -16,7 +16,7 @@ namespace ICSharpCode.SharpDevelop.Dom
/// <summary> /// <summary>
/// Creates an empty type definition collection that holds the top-level types for a project. /// Creates an empty type definition collection that holds the top-level types for a project.
/// </summary> /// </summary>
IMutableTypeDefinitionModelCollection CreateTopLevelTypeDefinitionCollection(IEntityModelContext context); ITypeDefinitionModelCollection CreateTopLevelTypeDefinitionCollection(IEntityModelContext context);
ITypeDefinitionModel CreateTypeDefinitionModel(IEntityModelContext context, params IUnresolvedTypeDefinition[] parts); ITypeDefinitionModel CreateTypeDefinitionModel(IEntityModelContext context, params IUnresolvedTypeDefinition[] parts);
IMemberModel CreateMemberModel(IEntityModelContext context, IUnresolvedMember member); IMemberModel CreateMemberModel(IEntityModelContext context, IUnresolvedMember member);

5
src/Main/Base/Project/Dom/ITypeDefinitionModel.cs

@ -27,5 +27,10 @@ namespace ICSharpCode.SharpDevelop.Dom
/// Returns null if the type definition could not be resolved. /// Returns null if the type definition could not be resolved.
/// </summary> /// </summary>
new ITypeDefinition Resolve(ISolutionSnapshotWithProjectMapping solutionSnapshot); new ITypeDefinition Resolve(ISolutionSnapshotWithProjectMapping solutionSnapshot);
/// <summary>
/// Retrieves
/// </summary>
ITypeDefinitionModel GetNestedType(string name, int atpc);
} }
} }

14
src/Main/Base/Project/Dom/ITypeDefinitionModelCollection.cs

@ -27,10 +27,7 @@ namespace ICSharpCode.SharpDevelop.Dom
/// Returns null if no such model object exists. /// Returns null if no such model object exists.
/// </summary> /// </summary>
ITypeDefinitionModel this[TopLevelTypeName topLevelTypeName] { get; } ITypeDefinitionModel this[TopLevelTypeName topLevelTypeName] { get; }
}
public interface IMutableTypeDefinitionModelCollection : ITypeDefinitionModelCollection, IList<ITypeDefinitionModel>
{
/// <summary> /// <summary>
/// Updates the collection when the parse information has changed. /// Updates the collection when the parse information has changed.
/// </summary> /// </summary>
@ -54,12 +51,6 @@ namespace ICSharpCode.SharpDevelop.Dom
get { return null; } get { return null; }
} }
ITypeDefinitionModel IReadOnlyList<ITypeDefinitionModel>.this[int index] {
get {
throw new ArgumentOutOfRangeException();
}
}
int IReadOnlyCollection<ITypeDefinitionModel>.Count { int IReadOnlyCollection<ITypeDefinitionModel>.Count {
get { return 0; } get { return 0; }
} }
@ -73,5 +64,10 @@ namespace ICSharpCode.SharpDevelop.Dom
{ {
return Enumerable.Empty<ITypeDefinitionModel>().GetEnumerator(); return Enumerable.Empty<ITypeDefinitionModel>().GetEnumerator();
} }
void ITypeDefinitionModelCollection.Update(IUnresolvedFile oldFile, IUnresolvedFile newFile)
{
throw new NotSupportedException();
}
} }
} }

3
src/Main/Base/Project/Dom/KeyedModelCollection.cs

@ -12,6 +12,9 @@ namespace ICSharpCode.SharpDevelop.Dom
/// </summary> /// </summary>
public abstract class KeyedModelCollection<TKey, TItem> : KeyedCollection<TKey, TItem>, IModelCollection<TItem> public abstract class KeyedModelCollection<TKey, TItem> : KeyedCollection<TKey, TItem>, IModelCollection<TItem>
{ {
// TODO: do we still need this class? maybe we should remove it?
// It's less useful than I initially thought because the indexer throws exceptions and there's no TryGetValue
protected override void ClearItems() protected override void ClearItems()
{ {
base.ClearItems(); base.ClearItems();

2
src/Main/Base/Project/Src/Project/CompilableProject.cs

@ -346,7 +346,7 @@ namespace ICSharpCode.SharpDevelop.Project
#region Type System #region Type System
volatile ProjectContentContainer projectContentContainer; volatile ProjectContentContainer projectContentContainer;
IMutableTypeDefinitionModelCollection typeDefinitionModels; ITypeDefinitionModelCollection typeDefinitionModels;
protected void InitializeProjectContent(IProjectContent initialProjectContent) protected void InitializeProjectContent(IProjectContent initialProjectContent)
{ {

8
src/Main/Base/Test/Dom/CSharpModelTests.cs

@ -77,6 +77,14 @@ namespace ICSharpCode.SharpDevelop.Dom
public void EmptyProject() public void EmptyProject()
{ {
Assert.AreEqual(0, topLevelTypeModels.Count); Assert.AreEqual(0, topLevelTypeModels.Count);
Assert.IsNull(topLevelTypeModels[new TopLevelTypeName("A")]);
}
[Test]
public void AddSimpleClass()
{
AddCodeFile("test.cs", @"class SimpleClass {}");
Assert.AreEqual(1, topLevelTypeModels.Count);
} }
} }
} }

2
src/Main/SharpDevelop/Dom/ModelFactory.cs

@ -8,7 +8,7 @@ namespace ICSharpCode.SharpDevelop.Dom
{ {
sealed class ModelFactory : IModelFactory sealed class ModelFactory : IModelFactory
{ {
public IMutableTypeDefinitionModelCollection CreateTopLevelTypeDefinitionCollection(IEntityModelContext context) public ITypeDefinitionModelCollection CreateTopLevelTypeDefinitionCollection(IEntityModelContext context)
{ {
return new TopLevelTypeDefinitionModelCollection(context); return new TopLevelTypeDefinitionModelCollection(context);
} }

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

@ -13,9 +13,11 @@ namespace ICSharpCode.SharpDevelop.Dom
/// <summary> /// <summary>
/// A TypeDefinitionModel-collection that holds models for all top-level types in a project content. /// A TypeDefinitionModel-collection that holds models for all top-level types in a project content.
/// </summary> /// </summary>
sealed class TopLevelTypeDefinitionModelCollection : KeyedModelCollection<TopLevelTypeName, ITypeDefinitionModel>, IMutableTypeDefinitionModelCollection sealed class TopLevelTypeDefinitionModelCollection : ITypeDefinitionModelCollection
{ {
readonly IEntityModelContext context; readonly IEntityModelContext context;
Dictionary<TopLevelTypeName, TypeDefinitionModel> dict = new Dictionary<TopLevelTypeName, TypeDefinitionModel>();
public event NotifyCollectionChangedEventHandler CollectionChanged;
public TopLevelTypeDefinitionModelCollection(IEntityModelContext context) public TopLevelTypeDefinitionModelCollection(IEntityModelContext context)
{ {
@ -24,11 +26,27 @@ namespace ICSharpCode.SharpDevelop.Dom
this.context = context; this.context = context;
} }
public int Count {
get { return dict.Count; }
}
public ITypeDefinitionModel this[TopLevelTypeName topLevelName] {
get {
TypeDefinitionModel model;
if (dict.TryGetValue(topLevelName, out model))
return model;
else
return null;
}
}
public ITypeDefinitionModel this[FullTypeName fullTypeName] { public ITypeDefinitionModel this[FullTypeName fullTypeName] {
get { get {
ITypeDefinitionModel model = base[fullTypeName.TopLevelTypeName]; ITypeDefinitionModel model = this[fullTypeName.TopLevelTypeName];
for (int i = 0; i < fullTypeName.NestingLevel; i++) { for (int i = 0; i < fullTypeName.NestingLevel; i++) {
throw new NotImplementedException(); string name = fullTypeName.GetNestedTypeName(i);
int atpc = fullTypeName.GetNestedTypeAdditionalTypeParameterCount(i);
model = model.GetNestedType(name, atpc);
} }
return model; return model;
} }
@ -39,15 +57,82 @@ namespace ICSharpCode.SharpDevelop.Dom
/// </summary> /// </summary>
public void Update(IUnresolvedFile oldFile, IUnresolvedFile newFile) public void Update(IUnresolvedFile oldFile, IUnresolvedFile newFile)
{ {
List<ITypeDefinitionModel> oldModels = null;
List<ITypeDefinitionModel> newModels = null;
bool[] oldTypeDefHandled = null;
if (oldFile != null) { if (oldFile != null) {
oldTypeDefHandled = new bool[oldFile.TopLevelTypeDefinitions.Count];
}
if (newFile != null) {
foreach (var newPart in newFile.TopLevelTypeDefinitions) {
FullTypeName newFullTypeName = newPart.FullTypeName;
TypeDefinitionModel model;
if (dict.TryGetValue(newFullTypeName.TopLevelTypeName, out model)) {
// Existing type changed
// Find a matching old part:
IUnresolvedTypeDefinition oldPart = null;
if (oldFile != null) {
for (int i = 0; i < oldTypeDefHandled.Length; i++) {
if (oldTypeDefHandled[i])
continue;
if (oldFile.TopLevelTypeDefinitions[i].FullTypeName == newFullTypeName) {
oldTypeDefHandled[i] = true;
oldPart = oldFile.TopLevelTypeDefinitions[i];
break;
}
}
}
model.Update(oldPart, newPart);
} else {
// New type added
model = new TypeDefinitionModel(context, newPart);
dict.Add(newFullTypeName.TopLevelTypeName, model);
if (newModels == null)
newModels = new List<ITypeDefinitionModel>();
newModels.Add(model);
} }
throw new NotImplementedException(); }
}
// Remove all old parts that weren't updated:
if (oldFile != null) {
for (int i = 0; i < oldTypeDefHandled.Length; i++) {
if (!oldTypeDefHandled[i]) {
IUnresolvedTypeDefinition oldPart = oldFile.TopLevelTypeDefinitions[i];
TopLevelTypeName topLevelTypeName = oldPart.FullTypeName.TopLevelTypeName;
TypeDefinitionModel model;
if (dict.TryGetValue(topLevelTypeName, out model)) {
// Remove the part from the model
if (model.Parts.Count > 1) {
model.Update(oldPart, null);
} else {
dict.Remove(topLevelTypeName);
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));
}
}
IEnumerator<ITypeDefinitionModel> IEnumerable<ITypeDefinitionModel>.GetEnumerator()
{
return dict.Values.GetEnumerator();
} }
protected override TopLevelTypeName GetKeyForItem(ITypeDefinitionModel item) IEnumerator IEnumerable.GetEnumerator()
{ {
return item.FullTypeName.TopLevelTypeName; return dict.Values.GetEnumerator();
} }
} }
} }

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

@ -49,24 +49,9 @@ namespace ICSharpCode.SharpDevelop.Dom
parts[0] = primaryPart; parts[0] = primaryPart;
} }
/* public IReadOnlyList<IUnresolvedTypeDefinition> Parts {
/// <summary> get { return parts; }
/// Updates the type definition model by removing the old parts and adding the new ones.
/// </summary>
public void Update(IReadOnlyList<IUnresolvedTypeDefinition> removedParts, IReadOnlyList<IUnresolvedTypeDefinition> newParts)
{
SD.MainThread.VerifyAccess();
if (removedParts != null)
foreach (var p in removedParts)
parts.Remove(p);
if (newParts != null)
parts.AddRange(newParts);
MemberModelCollection members;
if (membersWeakReference.TryGetTarget(out members)) {
members.Update(parts);
} }
}*/
public IProject ParentProject { public IProject ParentProject {
get { return context.Project; } get { return context.Project; }
@ -221,17 +206,6 @@ namespace ICSharpCode.SharpDevelop.Dom
{ {
return GetEnumerator(); return GetEnumerator();
} }
public MemberModel this[int index] {
get {
int inputIndex = 0;
while (index >= lists[inputIndex].Count) {
index -= lists[inputIndex].Count;
inputIndex++;
}
return lists[inputIndex][index];
}
}
} }
WeakReference<MemberCollection> membersWeakReference = new WeakReference<MemberCollection>(null); WeakReference<MemberCollection> membersWeakReference = new WeakReference<MemberCollection>(null);
@ -255,10 +229,22 @@ namespace ICSharpCode.SharpDevelop.Dom
} }
#endregion #endregion
#region Nested Types collection
public IModelCollection<ITypeDefinitionModel> NestedTypes { public IModelCollection<ITypeDefinitionModel> NestedTypes {
get { get {
throw new NotImplementedException(); throw new NotImplementedException();
} }
} }
public ITypeDefinitionModel GetNestedType(string name, int atpc)
{
throw new NotImplementedException();
}
#endregion
public void Update(IUnresolvedTypeDefinition oldPart, IUnresolvedTypeDefinition newPart)
{
throw new NotImplementedException();
}
} }
} }

Loading…
Cancel
Save