Skip to content

Commit 62dd840

Browse files
committed
Updates to support partial methods and nested types in containers. Bug fix for get model[T] to show up correctly. Remove obsolete flag from container methods for passing the target document.
1 parent e148c40 commit 62dd840

File tree

18 files changed

+1315
-35
lines changed

18 files changed

+1315
-35
lines changed

src/CodeFactoryVisualStudio/CodeFactory.DotNet/CSharp/CsClass.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,13 @@ public abstract class CsClass:CsContainer,ICsClass
3030
/// <param name="loadedFromSource">Flag that determines if the model was loaded from source code or from an existing library.</param>
3131
/// <param name="language">The target language the model was generated from.</param>
3232
/// <param name="members">The members assigned to this container.</param>
33+
/// <param name="isNested">Flag that determines if the container type is nested in another type definition.</param>
34+
/// <param name="nestedType">Enumeration of the type of nesting the container is.</param>
35+
/// <param name="nestedModels">List of nested models assigned to this container. This is an optional parameter and can be null</param>
3336
/// <param name="baseClass">The class model that is base class of this class.</param>
3437
/// <param name="sourceDocument">The source document that was used to build this model. This is optional parameter and can be null.</param>
3538
/// <param name="modelStore">Optional the lookup storage for models created during the compile or lookup of the model.</param>
36-
/// <param name="modelErrors">Optional the error that occured while creating the model.</param>
39+
/// <param name="modelErrors">Optional the error that occurred while creating the model.</param>
3740
/// <param name="attributes">List of the attributes assigned to this model.</param>
3841
/// <param name="isGeneric">Flag that determines if the container is a generic definition.</param>
3942
/// <param name="hasStrongTypesInGenerics">Flag that determines if the generics use strong type definitions.</param>
@@ -56,13 +59,13 @@ protected CsClass(bool isLoaded, bool hasErrors, bool loadedFromSource, SourceCo
5659
IReadOnlyList<CsAttribute> attributes, bool isGeneric, bool hasStrongTypesInGenerics,
5760
IReadOnlyList<CsGenericParameter> genericParameters, IReadOnlyList<CsType> genericTypes, string modelSourceFile, IReadOnlyList<string> sourceFiles,
5861
bool hasDocumentation, string documentation, string lookupPath, string name, string ns, string parentPath,
59-
CsSecurity security, IReadOnlyList<CsInterface> inheritedInterfaces, IReadOnlyList<CsMember> members,
60-
bool isStatic, bool isAbstract, bool isSealed, CsClass baseClass, string sourceDocument = null,
62+
CsSecurity security, IReadOnlyList<CsInterface> inheritedInterfaces, IReadOnlyList<CsMember> members,bool isNested, CsNestedType nestedType,
63+
bool isStatic, bool isAbstract, bool isSealed, CsClass baseClass,IReadOnlyList<ICsNestedModel> nestedModels, string sourceDocument = null,
6164
ModelStore<ICsModel> modelStore = null, IReadOnlyList<ModelLoadException> modelErrors = null)
6265
: base(isLoaded, hasErrors, loadedFromSource, language, CsModelType.Class, attributes,
6366
isGeneric, hasStrongTypesInGenerics, genericParameters, genericTypes, modelSourceFile, sourceFiles, hasDocumentation,
6467
documentation, lookupPath, name, ns, parentPath, CsContainerType.Class, security, inheritedInterfaces,
65-
members, sourceDocument, modelStore, modelErrors)
68+
members,isNested,nestedType,nestedModels, sourceDocument, modelStore, modelErrors)
6669
{
6770
_isStatic = isStatic;
6871
_isAbstract = isAbstract;

src/CodeFactoryVisualStudio/CodeFactory.DotNet/CSharp/CsContainer.cs

Lines changed: 85 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace CodeFactory.DotNet.CSharp
1616
/// <summary>
1717
/// Data model that implements the base implement for all models that support members.
1818
/// </summary>
19-
public abstract class CsContainer:CsModel,ICsContainer
19+
public abstract class CsContainer:CsModel,ICsContainer,ICsNestedModel
2020
{
2121
#region Property backing fields
2222
private readonly IReadOnlyList<CsAttribute> _attributes;
@@ -35,6 +35,10 @@ public abstract class CsContainer:CsModel,ICsContainer
3535
private readonly CsSecurity _security;
3636
private readonly IReadOnlyList<CsInterface> _inheritedInterfaces;
3737
private readonly IReadOnlyList<CsMember> _members;
38+
private readonly bool _isNested;
39+
private readonly CsNestedType _nestedType;
40+
private readonly IReadOnlyList<ICsNestedModel> _nestedModels;
41+
3842
#endregion
3943

4044
/// <summary>
@@ -46,9 +50,12 @@ public abstract class CsContainer:CsModel,ICsContainer
4650
/// <param name="language">The target language the model was generated from.</param>
4751
/// <param name="modelType">The type of code model created.</param>
4852
/// <param name="members">The members assigned to this container.</param>
53+
/// <param name="isNested">Flag that determines if the container type is nested in another type definition.</param>
54+
/// <param name="nestedType">Enumeration of the type of nesting the container is.</param>
55+
/// <param name="nestedModels">List of nested models assigned to this container. This is an optional parameter and can be null</param>
4956
/// <param name="sourceDocument">The source document that was used to build this model. This is optional parameter and can be null.</param>
5057
/// <param name="modelStore">Optional the lookup storage for models created during the compile or lookup of the model.</param>
51-
/// <param name="modelErrors">Optional the error that occured while creating the model.</param>
58+
/// <param name="modelErrors">Optional the error that occurred while creating the model.</param>
5259
/// <param name="attributes">List of the attributes assigned to this model.</param>
5360
/// <param name="isGeneric">Flag that determines if the container is a generic definition.</param>
5461
/// <param name="hasStrongTypesInGenerics">Flag that determines if the generics use strong type definitions.</param>
@@ -70,8 +77,9 @@ protected CsContainer(bool isLoaded, bool hasErrors, bool loadedFromSource, Sour
7077
IReadOnlyList<CsGenericParameter> genericParameters, IReadOnlyList<CsType> genericTypes, string modelSourceFile,
7178
IReadOnlyList<string> sourceFiles, bool hasDocumentation, string documentation, string lookupPath,
7279
string name, string ns, string parentPath, CsContainerType containerType, CsSecurity security,
73-
IReadOnlyList<CsInterface> inheritedInterfaces, IReadOnlyList<CsMember> members,
74-
string sourceDocument = null, ModelStore<ICsModel> modelStore = null, IReadOnlyList<ModelLoadException> modelErrors = null)
80+
IReadOnlyList<CsInterface> inheritedInterfaces, IReadOnlyList<CsMember> members, bool isNested, CsNestedType nestedType, IReadOnlyList<ICsNestedModel> nestedModels = null,
81+
82+
string sourceDocument = null, ModelStore<ICsModel> modelStore = null, IReadOnlyList<ModelLoadException> modelErrors = null)
7583
: base(isLoaded, hasErrors, loadedFromSource, language, modelType, sourceDocument, modelStore, modelErrors)
7684
{
7785
_attributes = attributes ?? ImmutableList<CsAttribute>.Empty;
@@ -91,6 +99,9 @@ protected CsContainer(bool isLoaded, bool hasErrors, bool loadedFromSource, Sour
9199
_security = security;
92100
_inheritedInterfaces = inheritedInterfaces ?? ImmutableList<CsInterface>.Empty;
93101
_members = members ?? ImmutableList<CsMember>.Empty;
102+
_isNested = isNested;
103+
_nestedType = nestedType;
104+
_nestedModels = nestedModels ?? ImmutableList<ICsNestedModel>.Empty;
94105
}
95106

96107
/// <summary>
@@ -214,7 +225,7 @@ protected CsContainer(bool isLoaded, bool hasErrors, bool loadedFromSource, Sour
214225
/// List of the methods that are implemented in this container.
215226
/// </summary>
216227
public IReadOnlyList<CsMethod> Methods => _members.Where(m => m.MemberType == CsMemberType.Method)
217-
.Cast<CsMethod>().Where(m => m.MethodType == CsMethodType.Member)
228+
.Cast<CsMethod>().Where(m => m.MethodType == CsMethodType.Member | m.MethodType == CsMethodType.PartialImplementation | m.MethodType == CsMethodType.PartialDefinition)
218229
.ToImmutableList() ?? ImmutableList<CsMethod>.Empty;
219230

220231
/// <summary>
@@ -230,6 +241,60 @@ protected CsContainer(bool isLoaded, bool hasErrors, bool loadedFromSource, Sour
230241
public IReadOnlyList<CsEvent> Events => _members.Where(m => m.MemberType == CsMemberType.Event).Cast<CsEvent>()
231242
.ToImmutableList() ?? ImmutableList<CsEvent>.Empty;
232243

244+
/// <summary>
245+
/// Models that are nested in the implementation of this container.
246+
/// </summary>
247+
public IReadOnlyList<ICsNestedModel> NestedModels => _nestedModels;
248+
249+
/// <summary>
250+
/// Classes that are nested in this container.
251+
/// </summary>
252+
public IReadOnlyList<CsClass> NestedClasses =>
253+
_nestedModels.Where(n => n.NestedType == CsNestedType.Class).Cast<CsClass>().ToImmutableList();
254+
255+
/// <summary>
256+
/// Interfaces that are nested in this container.
257+
/// </summary>
258+
public IReadOnlyList<CsInterface> NestedInterfaces =>
259+
_nestedModels.Where(n => n.NestedType == CsNestedType.Interface).Cast<CsInterface>().ToImmutableList();
260+
261+
/// <summary>
262+
/// Structures that are nested in this container.
263+
/// </summary>
264+
public IReadOnlyList<CsStructure> NestedStructures =>
265+
_nestedModels.Where(n => n.NestedType == CsNestedType.Structure).Cast<CsStructure>().ToImmutableList();
266+
267+
/// <summary>
268+
/// Enums that are nested in this container.
269+
/// </summary>
270+
public IReadOnlyList<CsEnum> NestedEnums =>
271+
_nestedModels.Where(n => n.NestedType == CsNestedType.Enum).Cast<CsEnum>().ToImmutableList();
272+
273+
/// <summary>
274+
/// Models that are nested in the implementation of this container.
275+
/// </summary>
276+
IReadOnlyList<IDotNetNestedModel> IDotNetContainer.NestedModels => NestedModels;
277+
278+
/// <summary>
279+
/// Classes that are nested in this container.
280+
/// </summary>
281+
IReadOnlyList<IDotNetClass> IDotNetContainer.NestedClasses => NestedClasses;
282+
283+
/// <summary>
284+
/// Interfaces that are nested in this container.
285+
/// </summary>
286+
IReadOnlyList<IDotNetInterface> IDotNetContainer.NestedInterfaces => NestedInterfaces;
287+
288+
/// <summary>
289+
/// Structures that are nested in this container.
290+
/// </summary>
291+
IReadOnlyList<IDotNetStructure> IDotNetContainer.NestedStructures => NestedStructures;
292+
293+
/// <summary>
294+
/// Enums that are nested in this container.
295+
/// </summary>
296+
IReadOnlyList<IDotNetEnum> IDotNetContainer.NestedEnums => NestedEnums;
297+
233298
/// <summary>
234299
/// The source code syntax that is stored in the body of the container model. This will be null if the container was not loaded from source code.
235300
/// </summary>
@@ -430,5 +495,20 @@ protected CsContainer(bool isLoaded, bool hasErrors, bool loadedFromSource, Sour
430495

431496
/// <inheritdoc/>
432497
public string ModelSourceFile => _modelSourceFile;
498+
499+
/// <summary>
500+
/// Identifies the type of model that has been nested.
501+
/// </summary>
502+
DotNetNestedType IDotNetNestedModel.NestedType => (DotNetNestedType) _nestedType ;
503+
504+
/// <summary>
505+
/// Identifies the type of model that has been nested.
506+
/// </summary>
507+
public CsNestedType NestedType => _nestedType;
508+
509+
/// <summary>
510+
/// Flag that determines if this model is nested in a parent model.
511+
/// </summary>
512+
public bool IsNested { get; }
433513
}
434514
}

src/CodeFactoryVisualStudio/CodeFactory.DotNet/CSharp/CsDelegate.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -324,12 +324,12 @@ protected CsDelegate(bool isLoaded, bool hasErrors, bool loadedFromSource, Sourc
324324
public abstract Task<CsSource> ReplaceAsync(string sourceCode);
325325

326326

327-
/// <summary>
328-
/// Gets a <see cref="ICsModel"/> from the currently loaded source code.
329-
/// </summary>
330-
/// <param name="lookupPath">The fully qualified path to the model to be loaded.</param>
331-
/// <returns>The loaded model or null if the model could not be found.</returns>
332-
public CsModel GetModel(string lookupPath) => LookupModel(lookupPath);
327+
///// <summary>
328+
///// Gets a <see cref="ICsModel"/> from the currently loaded source code.
329+
///// </summary>
330+
///// <param name="lookupPath">The fully qualified path to the model to be loaded.</param>
331+
///// <returns>The loaded model or null if the model could not be found.</returns>
332+
//public CsModel GetModel(string lookupPath) => LookupModel(lookupPath);
333333

334334
/// <inheritdoc/>
335335
public abstract Task<CsSource> AddBeforeAsync(string sourceCode, bool ignoreLeadingModelsAndDocs);

src/CodeFactoryVisualStudio/CodeFactory.DotNet/CSharp/CsEnum.cs

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ public abstract class CsEnum:CsModel,ICsEnum
2929
private readonly string _ns;
3030
private readonly CsSecurity _security;
3131
private readonly IReadOnlyList<CsEnumValue> _values;
32+
private readonly bool _isNested;
33+
private readonly CsNestedType _nestedType;
34+
3235
#endregion
3336

3437
/// <summary>
@@ -39,9 +42,11 @@ public abstract class CsEnum:CsModel,ICsEnum
3942
/// <param name="loadedFromSource">Flag that determines if the model was loaded from source code or from an existing library.</param>
4043
/// <param name="language">The target language the model was generated from.</param>
4144
/// <param name="values">The enumeration values assigned to this enumeration.</param>
45+
/// <param name="isNested">Flag that determines if the container type is nested in another type definition.</param>
46+
/// <param name="nestedType">Enumeration of the type of nesting the container is.</param>
4247
/// <param name="sourceDocument">The source document that was used to build this model. This is optional parameter and can be null.</param>
4348
/// <param name="modelStore">Optional the lookup storage for models created during the compile or lookup of the model.</param>
44-
/// <param name="modelErrors">Optional the error that occured while creating the model.</param>
49+
/// <param name="modelErrors">Optional the error that occurred while creating the model.</param>
4550
/// <param name="attributes">List of the attributes assigned to this model.</param>
4651
/// <param name="sourceFiles">List of the fully qualified paths to the source code files this model is defined in.</param>
4752
/// <param name="hasDocumentation">Flag that determines if the model has XML documentation assigned to it.</param>
@@ -54,7 +59,7 @@ public abstract class CsEnum:CsModel,ICsEnum
5459
/// <param name="security">The security scope assigned to this model.</param>
5560
protected CsEnum(bool isLoaded, bool hasErrors, bool loadedFromSource, SourceCodeType language,
5661
IReadOnlyList<CsAttribute> attributes, string parentPath, bool hasDocumentation, string documentation, string lookupPath,string modelSourceFile,
57-
IReadOnlyList<string> sourceFiles, string name, string ns, CsSecurity security, IReadOnlyList<CsEnumValue> values,
62+
IReadOnlyList<string> sourceFiles, string name, string ns, CsSecurity security, IReadOnlyList<CsEnumValue> values, bool isNested,CsNestedType nestedType,
5863
string sourceDocument = null, ModelStore<ICsModel> modelStore = null, IReadOnlyList<ModelLoadException> modelErrors = null): base(isLoaded, hasErrors, loadedFromSource, language, CsModelType.Enum, sourceDocument, modelStore, modelErrors)
5964
{
6065
_attributes = attributes ?? ImmutableList<CsAttribute>.Empty;
@@ -68,6 +73,9 @@ protected CsEnum(bool isLoaded, bool hasErrors, bool loadedFromSource, SourceCod
6873
_ns = ns;
6974
_security = security;
7075
_values = values ?? ImmutableList<CsEnumValue>.Empty;
76+
_isNested = isNested;
77+
_nestedType = nestedType;
78+
7179
}
7280

7381
/// <summary>
@@ -272,7 +280,6 @@ protected CsEnum(bool isLoaded, bool hasErrors, bool loadedFromSource, SourceCod
272280
/// <inheritdoc/>
273281
public abstract Task<CsSource> AddBeforeAsync(string sourceCode, bool ignoreLeadingModelsAndDocs);
274282

275-
276283
/// <summary>
277284
/// The security scope assigned to the enumeration.
278285
/// </summary>
@@ -290,5 +297,20 @@ protected CsEnum(bool isLoaded, bool hasErrors, bool loadedFromSource, SourceCod
290297

291298
/// <inheritdoc/>
292299
public string ModelSourceFile => _modelSourceFile;
300+
301+
/// <summary>
302+
/// Identifies the type of model that has been nested.
303+
/// </summary>
304+
DotNetNestedType IDotNetNestedModel.NestedType => (DotNetNestedType)_nestedType;
305+
306+
/// <summary>
307+
/// Identifies the type of model that has been nested.
308+
/// </summary>
309+
public CsNestedType NestedType => _nestedType;
310+
311+
/// <summary>
312+
/// Flag that determines if this model is nested in a parent model.
313+
/// </summary>
314+
public bool IsNested => _isNested;
293315
}
294316
}

src/CodeFactoryVisualStudio/CodeFactory.DotNet/CSharp/CsInterface.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ public abstract class CsInterface:CsContainer,ICsInterface
2121
/// <param name="loadedFromSource">Flag that determines if the model was loaded from source code or from an existing library.</param>
2222
/// <param name="language">The target language the model was generated from.</param>
2323
/// <param name="members">The members assigned to this container.</param>
24+
/// <param name="isNested">Flag that determines if the container type is nested in another type definition.</param>
25+
/// <param name="nestedType">Enumeration of the type of nesting the container is.</param>
26+
/// <param name="nestedModels">List of nested models assigned to this container. This is an optional parameter and can be null</param>
2427
/// <param name="sourceDocument">The source document that was used to build this model. This is optional parameter and can be null.</param>
2528
/// <param name="modelStore">Optional the lookup storage for models created during the compile or lookup of the model.</param>
2629
/// <param name="modelErrors">Optional the error that occured while creating the model.</param>
@@ -45,11 +48,11 @@ protected CsInterface(bool isLoaded, bool hasErrors, bool loadedFromSource, Sour
4548
IReadOnlyList<CsType> genericTypes, string modelSourceFile, IReadOnlyList<string> sourceFiles, bool hasDocumentation,
4649
string documentation, string lookupPath, string name, string ns, string parentPath,
4750
CsSecurity security, IReadOnlyList<CsInterface> inheritedInterfaces,
48-
IReadOnlyList<CsMember> members, string sourceDocument = null, ModelStore<ICsModel> modelStore = null, IReadOnlyList<ModelLoadException> modelErrors = null)
51+
IReadOnlyList<CsMember> members, bool isNested,CsNestedType nestedType, IReadOnlyList<ICsNestedModel> nestedModels = null, string sourceDocument = null, ModelStore<ICsModel> modelStore = null, IReadOnlyList<ModelLoadException> modelErrors = null)
4952
: base(isLoaded, hasErrors, loadedFromSource, language, CsModelType.Interface,attributes,
5053
isGeneric, hasStrongTypesInGenerics, genericParameters, genericTypes,modelSourceFile, sourceFiles, hasDocumentation,
5154
documentation, lookupPath, name, ns, parentPath, CsContainerType.Interface, security, inheritedInterfaces,
52-
members, sourceDocument, modelStore, modelErrors)
55+
members,isNested,nestedType,nestedModels, sourceDocument, modelStore, modelErrors)
5356
{
5457
//Intentionally blank
5558
}

src/CodeFactoryVisualStudio/CodeFactory.DotNet/CSharp/CsMethodType.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,16 @@ public enum CsMethodType
6060
/// </summary>
6161
Remove = DotNetMethodType.Remove,
6262

63+
/// <summary>
64+
/// This method is the definition for a partial method.
65+
/// </summary>
66+
PartialDefinition = DotNetMethodType.PartialDefinition,
67+
68+
/// <summary>
69+
/// This method is the implementation for a partial method.
70+
/// </summary>
71+
PartialImplementation = DotNetMethodType.PartialImplementation,
72+
6373
/// <summary>
6474
/// The type of method is unknown
6575
/// </summary>

0 commit comments

Comments
 (0)