Skip to content
Browse files

Factory move stage 2 complete

  • Loading branch information...
1 parent e1f76ab commit f227e60ec3cd3e734f12d97e547fd6c915e922a4 @KathleenDollard committed
Showing with 184 additions and 1,016 deletions.
  1. +6 −0 RoslynDom.sln
  2. +5 −5 {RoslynDomCSharpFactories/StructureFactories → RoslynDom/Factories}/RDomAccessor.cs
  3. +8 −8 {RoslynDomCSharpFactories/StructureFactories → RoslynDom/Factories}/RDomClass.cs
  4. +7 −8 {RoslynDomCSharpFactories/StructureFactories → RoslynDom/Factories}/RDomEnum.cs
  5. +4 −4 {RoslynDomCSharpFactories/StructureFactories → RoslynDom/Factories}/RDomField.cs
  6. +10 −8 {RoslynDomCSharpFactories/StructureFactories → RoslynDom/Factories}/RDomInterface.cs
  7. +5 −5 {RoslynDomCSharpFactories/StructureFactories → RoslynDom/Factories}/RDomMethod.cs
  8. +7 −6 {RoslynDomCSharpFactories/StructureFactories → RoslynDom/Factories}/RDomNamespace.cs
  9. +47 −0 RoslynDom/Factories/RDomParameter.cs
  10. +8 −8 {RoslynDomCSharpFactories/StructureFactories → RoslynDom/Factories}/RDomProperty.cs
  11. +3 −2 {RoslynDomCSharpFactories/StructureFactories → RoslynDom/Factories}/RDomReferencedType.cs
  12. +6 −5 {RoslynDomCSharpFactories/StructureFactories → RoslynDom/Factories}/RDomRoot.cs
  13. +9 −10 {RoslynDomCSharpFactories/StructureFactories → RoslynDom/Factories}/RDomStructure.cs
  14. +3 −3 {RoslynDomCSharpFactories/StructureFactories → RoslynDom/Factories}/RDomUsing.cs
  15. +4 −6 ...CSharpFactories/StatementFactories → RoslynDom/FactoriesForStatements}/RDomAssignmentStatement.cs
  16. +4 −5 ...ynDomCSharpFactories/StatementFactories → RoslynDom/FactoriesForStatements}/RDomBlockStatement.cs
  17. +6 −7 ...SharpFactories/StatementFactories → RoslynDom/FactoriesForStatements}/RDomDeclarationStatement.cs
  18. +8 −10 {RoslynDomCSharpFactories/StatementFactories → RoslynDom/FactoriesForStatements}/RDomIfStatement.cs
  19. +4 −6 ...CSharpFactories/StatementFactories → RoslynDom/FactoriesForStatements}/RDomInvocationStatement.cs
  20. +5 −5 ...nDomCSharpFactories/StatementFactories → RoslynDom/FactoriesForStatements}/RDomReturnStatement.cs
  21. +0 −15 RoslynDom/Implementations/RDomAccessor.cs
  22. +0 −64 RoslynDom/Implementations/RDomClass.cs
  23. +1 −62 RoslynDom/Implementations/RDomEnum.cs
  24. +0 −45 RoslynDom/Implementations/RDomField.cs
  25. +1 −62 RoslynDom/Implementations/RDomInterface.cs
  26. +0 −54 RoslynDom/Implementations/RDomMethod.cs
  27. +0 −38 RoslynDom/Implementations/RDomNamespace.cs
  28. +0 −38 RoslynDom/Implementations/RDomParameter.cs
  29. +0 −51 RoslynDom/Implementations/RDomProperty.cs
  30. +0 −17 RoslynDom/Implementations/RDomReferencedType.cs
  31. +1 −32 RoslynDom/Implementations/RDomRoot.cs
  32. +1 −62 RoslynDom/Implementations/RDomStructure.cs
  33. +1 −19 RoslynDom/Implementations/RDomUsing.cs
  34. +19 −0 RoslynDom/RoslynDom.csproj
  35. +0 −38 RoslynDom/StatementImplementations/RDomAssignmentStatement.cs
  36. +0 −26 RoslynDom/StatementImplementations/RDomBlockStatement.cs
  37. +1 −65 RoslynDom/StatementImplementations/RDomDeclarationStatement.cs
  38. +0 −144 RoslynDom/StatementImplementations/RDomIfStatement.cs
  39. +0 −30 RoslynDom/StatementImplementations/RDomInvocationStatement.cs
  40. +0 −25 RoslynDom/StatementImplementations/RDomReturnStatement.cs
  41. +0 −18 RoslynDomCSharpFactories/RoslynDomCSharpFactories.csproj
View
6 RoslynDom.sln
@@ -17,6 +17,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RoslynDomExampleTests", "Ro
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RoslynDomRDomCommon", "RoslynDomRDomCommon\RoslynDomRDomCommon.csproj", "{1E5B8601-B717-471D-A9EE-0C03D15491A5}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RoslynDomCSharpFactories", "RoslynDomCSharpFactories\RoslynDomCSharpFactories.csproj", "{8AE6F765-35A1-492F-84A1-86807155AA2C}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -51,6 +53,10 @@ Global
{1E5B8601-B717-471D-A9EE-0C03D15491A5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1E5B8601-B717-471D-A9EE-0C03D15491A5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1E5B8601-B717-471D-A9EE-0C03D15491A5}.Release|Any CPU.Build.0 = Release|Any CPU
+ {8AE6F765-35A1-492F-84A1-86807155AA2C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {8AE6F765-35A1-492F-84A1-86807155AA2C}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {8AE6F765-35A1-492F-84A1-86807155AA2C}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {8AE6F765-35A1-492F-84A1-86807155AA2C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
View
10 ...tories/StructureFactories/RDomAccessor.cs → RoslynDom/Factories/RDomAccessor.cs
@@ -5,21 +5,21 @@
using Microsoft.CodeAnalysis.CSharp.Syntax;
using RoslynDom.Common;
-namespace RoslynDom.CSharpFactories
+namespace RoslynDom
{
public class RDomPropertyAccessorMiscFactory
- : RDomMiscFactory<IAccessor, AccessorDeclarationSyntax>
+ : RDomMiscFactory<RDomPropertyAccessor, AccessorDeclarationSyntax>
{
- public override void InitializeItem(IAccessor newItem, AccessorDeclarationSyntax syntax)
+ public override void InitializeItem(RDomPropertyAccessor newItem, AccessorDeclarationSyntax syntax)
{
newItem.AccessModifier = (AccessModifier)newItem.Symbol.DeclaredAccessibility;
if (syntax.Body != null)
{
- var statements = ListUtilities.MakeList(syntax, x => x.Body.Statements, x => RDomFactoryHelper.StatementFactoryHelper.MakeItem(x));
+ var statements = ListUtilities.MakeList(syntax, x => x.Body.Statements, x => RDomFactoryHelper.GetHelper<IStatement>().MakeItem(x));
foreach (var statement in statements)
{ newItem.AddStatement(statement); }
}
}
}
- }
+}
View
16 ...Factories/StructureFactories/RDomClass.cs → RoslynDom/Factories/RDomClass.cs
@@ -6,18 +6,18 @@
using Microsoft.CodeAnalysis.CSharp.Syntax;
using RoslynDom.Common;
-namespace RoslynDom.CSharpFactories
+namespace RoslynDom
{
internal static class RDomClassFactoryHelper
{
- public static void InitializeItem(IClass newItem, ClassDeclarationSyntax syntax)
+ public static void InitializeItem(RDomClass newItem, ClassDeclarationSyntax syntax)
{
newItem.Name = newItem.TypedSymbol.Name;
newItem.AccessModifier = (AccessModifier)newItem.Symbol.DeclaredAccessibility;
var newTypeParameters = newItem.TypedSymbol.TypeParametersFrom();
foreach (var typeParameter in newTypeParameters)
{ newItem.AddOrMoveTypeParameter(typeParameter); }
- var members = ListUtilities.MakeList(syntax, x => x.Members, x => RDomFactoryHelper.TypeMemberFactoryHelper.MakeItem(x));
+ var members = ListUtilities.MakeList(newItem.TypedSyntax, x => x.Members, x => RDomFactoryHelper.GetHelper<ITypeMember>().MakeItem(x));
foreach (var member in members)
{ newItem.AddOrMoveMember(member); }
newItem.BaseType = new RDomReferencedType(newItem.TypedSymbol.DeclaringSyntaxReferences, newItem.TypedSymbol.BaseType);
@@ -26,7 +26,7 @@ public static void InitializeItem(IClass newItem, ClassDeclarationSyntax syntax)
newItem.IsStatic = newItem.Symbol.IsStatic;
}
- public static IEnumerable<SyntaxNode> BuildSyntax(IClass item)
+ public static IEnumerable<SyntaxNode> BuildSyntax(RDomClass item)
{
var modifiers = item.BuildModfierSyntax();
var identifier = SyntaxFactory.Identifier(item.Name);
@@ -45,9 +45,9 @@ public static IEnumerable<SyntaxNode> BuildSyntax(IClass item)
}
}
public class RDomClassTypeMemberFactory
- : RDomTypeMemberFactory<IClass, ClassDeclarationSyntax>
+ : RDomTypeMemberFactory<RDomClass, ClassDeclarationSyntax>
{
- public override void InitializeItem(IClass newItem, ClassDeclarationSyntax syntax)
+ public override void InitializeItem(RDomClass newItem, ClassDeclarationSyntax syntax)
{
RDomClassFactoryHelper.InitializeItem(newItem, syntax);
}
@@ -58,9 +58,9 @@ public override IEnumerable<SyntaxNode> BuildSyntax(ITypeMember item)
}
public class RDomClassStemMemberFactory
- : RDomStemMemberFactory<IClass, ClassDeclarationSyntax>
+ : RDomStemMemberFactory<RDomClass, ClassDeclarationSyntax>
{
- public override void InitializeItem(IClass newItem, ClassDeclarationSyntax syntax)
+ public override void InitializeItem(RDomClass newItem, ClassDeclarationSyntax syntax)
{
RDomClassFactoryHelper.InitializeItem(newItem, syntax);
}
View
15 ...pFactories/StructureFactories/RDomEnum.cs → RoslynDom/Factories/RDomEnum.cs
@@ -6,11 +6,11 @@
using RoslynDom.Common;
using System.Linq;
-namespace RoslynDom.CSharpFactories
+namespace RoslynDom
{
internal static class RDomEnumFactoryHelper
{
- public static void InitializeItem(IEnum newItem, EnumDeclarationSyntax syntax)
+ public static void InitializeItem(RDomEnum newItem, EnumDeclarationSyntax syntax)
{
newItem.Name = newItem.TypedSymbol.Name;
newItem.AccessModifier = (AccessModifier)newItem.Symbol.DeclaredAccessibility;
@@ -22,7 +22,7 @@ public static void InitializeItem(IEnum newItem, EnumDeclarationSyntax syntax)
}
}
- public static IEnumerable<SyntaxNode> BuildSyntax(IEnum item)
+ public static IEnumerable<SyntaxNode> BuildSyntax(RDomEnum item)
{
var modifiers = item.BuildModfierSyntax();
var identifier = SyntaxFactory.Identifier(item.Name);
@@ -41,9 +41,9 @@ public static IEnumerable<SyntaxNode> BuildSyntax(IEnum item)
}
public class RDomEnumTypeMemberFactory
- : RDomTypeMemberFactory<IEnum, EnumDeclarationSyntax>
+ : RDomTypeMemberFactory<RDomEnum, EnumDeclarationSyntax>
{
- public override void InitializeItem(IEnum newItem, EnumDeclarationSyntax syntax)
+ public override void InitializeItem(RDomEnum newItem, EnumDeclarationSyntax syntax)
{
RDomEnumFactoryHelper.InitializeItem(newItem, syntax);
}
@@ -56,9 +56,9 @@ public override IEnumerable<SyntaxNode> BuildSyntax(ITypeMember item)
public class RDomEnumStemMemberFactory
- : RDomStemMemberFactory<IEnum, EnumDeclarationSyntax>
+ : RDomStemMemberFactory<RDomEnum, EnumDeclarationSyntax>
{
- public override void InitializeItem(IEnum newItem, EnumDeclarationSyntax syntax)
+ public override void InitializeItem(RDomEnum newItem, EnumDeclarationSyntax syntax)
{
RDomEnumFactoryHelper.InitializeItem(newItem, syntax);
}
@@ -68,5 +68,4 @@ public override IEnumerable<SyntaxNode> BuildSyntax(IStemMember item)
}
}
-
}
View
8 ...Factories/StructureFactories/RDomField.cs → RoslynDom/Factories/RDomField.cs
@@ -5,12 +5,12 @@
using Microsoft.CodeAnalysis.CSharp.Syntax;
using RoslynDom.Common;
-namespace RoslynDom.CSharpFactories
+namespace RoslynDom
{
public class RDomFieldTypeMemberFactory
- : RDomTypeMemberFactory<IField, FieldDeclarationSyntax>
+ : RDomTypeMemberFactory<RDomField, FieldDeclarationSyntax>
{
- public override void InitializeItem(IField newItem, FieldDeclarationSyntax syntax)
+ public override void InitializeItem(RDomField newItem, FieldDeclarationSyntax syntax)
{
newItem.Name = newItem.TypedSymbol.Name;
newItem.AccessModifier = (AccessModifier)newItem.Symbol.DeclaredAccessibility;
@@ -51,5 +51,5 @@ public override IEnumerable<SyntaxNode> BuildSyntax(ITypeMember item)
}
}
-
+
}
View
18 ...ories/StructureFactories/RDomInterface.cs → RoslynDom/Factories/RDomInterface.cs
@@ -6,23 +6,23 @@
using RoslynDom.Common;
using System.Linq;
-namespace RoslynDom.CSharpFactories
+namespace RoslynDom
{
internal static class RDomInterfaceFactoryHelper
{
- public static void InitializeItem(IInterface newItem, InterfaceDeclarationSyntax syntax)
+ public static void InitializeItem(RDomInterface newItem, InterfaceDeclarationSyntax syntax)
{
newItem.Name = newItem.TypedSymbol.Name;
newItem.AccessModifier = (AccessModifier)newItem.Symbol.DeclaredAccessibility;
var newTypeParameters = newItem.TypedSymbol.TypeParametersFrom();
foreach (var typeParameter in newTypeParameters)
{ newItem.AddOrMoveTypeParameter(typeParameter); }
- var members = ListUtilities.MakeList(syntax, x => x.Members, x => RDomFactoryHelper.TypeMemberFactoryHelper.MakeItem(x));
+ var members = ListUtilities.MakeList(newItem.TypedSyntax, x => x.Members, x => RDomFactoryHelper.GetHelper<ITypeMember>().MakeItem(x));
foreach (var member in members)
{ newItem.AddOrMoveMember(member); }
}
- public static IEnumerable<SyntaxNode> BuildSyntax(IInterface item)
+ public static IEnumerable<SyntaxNode> BuildSyntax(RDomInterface item)
{
var modifiers = item.BuildModfierSyntax();
var identifier = SyntaxFactory.Identifier(item.Name);
@@ -41,9 +41,9 @@ public static IEnumerable<SyntaxNode> BuildSyntax(IInterface item)
}
public class RDomInterfaceTypeMemberFactory
- : RDomTypeMemberFactory<IInterface, InterfaceDeclarationSyntax>
+ : RDomTypeMemberFactory<RDomInterface, InterfaceDeclarationSyntax>
{
- public override void InitializeItem(IInterface newItem, InterfaceDeclarationSyntax syntax)
+ public override void InitializeItem(RDomInterface newItem, InterfaceDeclarationSyntax syntax)
{
RDomInterfaceFactoryHelper.InitializeItem(newItem, syntax);
}
@@ -55,9 +55,9 @@ public override IEnumerable<SyntaxNode> BuildSyntax(ITypeMember item)
public class RDomInterfaceStemMemberFactory
- : RDomStemMemberFactory<IInterface, InterfaceDeclarationSyntax>
+ : RDomStemMemberFactory<RDomInterface, InterfaceDeclarationSyntax>
{
- public override void InitializeItem(IInterface newItem, InterfaceDeclarationSyntax syntax)
+ public override void InitializeItem(RDomInterface newItem, InterfaceDeclarationSyntax syntax)
{
RDomInterfaceFactoryHelper.InitializeItem(newItem, syntax);
}
@@ -67,4 +67,6 @@ public override IEnumerable<SyntaxNode> BuildSyntax(IStemMember item)
}
}
+
+
}
View
10 ...actories/StructureFactories/RDomMethod.cs → RoslynDom/Factories/RDomMethod.cs
@@ -5,12 +5,12 @@
using Microsoft.CodeAnalysis.CSharp.Syntax;
using RoslynDom.Common;
-namespace RoslynDom.CSharpFactories
+namespace RoslynDom
{
public class RDomMethodTypeMemberFactory
- : RDomTypeMemberFactory<IMethod, MethodDeclarationSyntax>
+ : RDomTypeMemberFactory<RDomMethod, MethodDeclarationSyntax>
{
- public override void InitializeItem(IMethod newItem, MethodDeclarationSyntax rawItem)
+ public override void InitializeItem(RDomMethod newItem, MethodDeclarationSyntax rawItem)
{
newItem.Name = newItem.TypedSymbol.Name;
var typeParameters = newItem.TypedSymbol.TypeParametersFrom();
@@ -25,12 +25,12 @@ public override void InitializeItem(IMethod newItem, MethodDeclarationSyntax raw
newItem.IsSealed = newItem.Symbol.IsSealed;
newItem.IsStatic = newItem.Symbol.IsStatic;
newItem.IsExtensionMethod = newItem.TypedSymbol.IsExtensionMethod;
- var parameters = ListUtilities.MakeList(rawItem, x => x.ParameterList.Parameters, x => RDomFactoryHelper.MiscFactoryHelper.MakeItem(x));
+ var parameters = ListUtilities.MakeList(rawItem, x => x.ParameterList.Parameters, x => RDomFactoryHelper.GetHelper<IMisc>().MakeItem(x));
foreach (var parameter in parameters)
{ newItem.AddParameter((IParameter)parameter); }
if (rawItem.Body != null)
{
- var statements = ListUtilities.MakeList(rawItem, x => x.Body.Statements, x => RDomFactoryHelper.StatementFactoryHelper.MakeItem(x));
+ var statements = ListUtilities.MakeList(rawItem, x => x.Body.Statements, x => RDomFactoryHelper.GetHelper<IStatement>().MakeItem(x));
foreach (var statement in statements)
{ newItem.AddStatement(statement); }
}
View
13 ...ories/StructureFactories/RDomNamespace.cs → RoslynDom/Factories/RDomNamespace.cs
@@ -6,20 +6,20 @@
using Microsoft.CodeAnalysis.CSharp.Syntax;
using RoslynDom.Common;
-namespace RoslynDom.CSharpFactories
+namespace RoslynDom
{
public class RDomNamespaceStemMemberFactory
- : RDomStemMemberFactory<INamespace, NamespaceDeclarationSyntax>
+ : RDomStemMemberFactory<RDomNamespace, NamespaceDeclarationSyntax>
{
- public override void InitializeItem(INamespace newItem, NamespaceDeclarationSyntax syntax)
+ public override void InitializeItem(RDomNamespace newItem, NamespaceDeclarationSyntax syntax)
{
// Qualified name unbundles namespaces, and if it's defined together, we want it together here.
// Thus, this replaces hte base Initialize name with the correct one
- newItem.Name = syntax.NameFrom();
+ newItem.Name = newItem.TypedSyntax.NameFrom();
if (newItem.Name.StartsWith("@")) { newItem.Name = newItem.Name.Substring(1); }
- var members = ListUtilities.MakeList(syntax, x => x.Members, x => RDomFactoryHelper.StemMemberFactoryHelper.MakeItem(x));
- var usings = ListUtilities.MakeList(syntax, x => x.Usings, x => RDomFactoryHelper.StemMemberFactoryHelper.MakeItem(x));
+ var members = ListUtilities.MakeList(newItem.TypedSyntax, x => x.Members, x => RDomFactoryHelper.GetHelper<IStemMember>().MakeItem(x));
+ var usings = ListUtilities.MakeList(newItem.TypedSyntax, x => x.Usings, x => RDomFactoryHelper.GetHelper<IStemMember>().MakeItem(x));
foreach (var member in members)
{ newItem.AddOrMoveStemMember(member); }
foreach (var member in usings)
@@ -45,4 +45,5 @@ public override IEnumerable<SyntaxNode> BuildSyntax(IStemMember item)
}
}
+
}
View
47 RoslynDom/Factories/RDomParameter.cs
@@ -0,0 +1,47 @@
+using System.Collections.Generic;
+using Microsoft.CodeAnalysis;
+using Microsoft.CodeAnalysis.CSharp;
+using Microsoft.CodeAnalysis.CSharp.Syntax;
+using RoslynDom.Common;
+using System.Linq;
+
+namespace RoslynDom
+{
+ public class RDomParameterMiscFactory
+ : RDomMiscFactory<RDomParameter, ParameterSyntax>
+ {
+ public override void InitializeItem(RDomParameter newItem, ParameterSyntax syntax)
+ {
+ newItem.Name = newItem.TypedSymbol.Name;
+ newItem.Type = new RDomReferencedType(newItem.TypedSymbol.DeclaringSyntaxReferences, newItem.TypedSymbol.Type);
+ newItem.IsOut = newItem.TypedSymbol.RefKind == RefKind.Out;
+ newItem.IsRef = newItem.TypedSymbol.RefKind == RefKind.Ref;
+ newItem.IsParamArray = newItem.TypedSymbol.IsParams;
+ newItem.IsOptional = newItem.TypedSymbol.IsOptional;
+ newItem.Ordinal = newItem.TypedSymbol.Ordinal;
+ }
+
+ public override IEnumerable<SyntaxNode> BuildSyntax(IMisc item)
+ {
+ var nameSyntax = SyntaxFactory.Identifier(item.Name);
+ var itemAsT = item as IParameter;
+ var syntaxType = (TypeSyntax)(RDomFactory.BuildSyntax(itemAsT.Type));
+
+ var node = SyntaxFactory.Parameter(nameSyntax)
+ .WithType(syntaxType);
+
+ var attributes = BuildSyntaxExtensions.BuildAttributeListSyntax(itemAsT.Attributes);
+ if (attributes.Any()) { node = node.WithAttributeLists(attributes); }
+
+ var modifiers = SyntaxFactory.TokenList();
+ if (itemAsT.IsOut) { modifiers = modifiers.Add(SyntaxFactory.Token(SyntaxKind.OutKeyword)); }
+ if (itemAsT.IsRef) { modifiers = modifiers.Add(SyntaxFactory.Token(SyntaxKind.RefKeyword)); }
+ if (itemAsT.IsParamArray) { modifiers = modifiers.Add(SyntaxFactory.Token(SyntaxKind.ParamsKeyword)); }
+ if (itemAsT.IsRef) { modifiers = modifiers.Add(SyntaxFactory.Token(SyntaxKind.RefKeyword)); }
+ if (modifiers.Any()) { node = node.WithModifiers(modifiers); }
+ return new SyntaxNode[] { node.NormalizeWhitespace() };
+
+ }
+ }
+
+}
View
16 ...tories/StructureFactories/RDomProperty.cs → RoslynDom/Factories/RDomProperty.cs
@@ -6,12 +6,12 @@
using Microsoft.CodeAnalysis.CSharp.Syntax;
using RoslynDom.Common;
-namespace RoslynDom.CSharpFactories
+namespace RoslynDom
{
public class RDomPropertyTypeMemberFactory
- : RDomTypeMemberFactory<IProperty, PropertyDeclarationSyntax>
+ : RDomTypeMemberFactory<RDomProperty, PropertyDeclarationSyntax>
{
- public override void InitializeItem(IProperty newItem, PropertyDeclarationSyntax syntax)
+ public override void InitializeItem(RDomProperty newItem, PropertyDeclarationSyntax syntax)
{
newItem.Name = newItem.TypedSymbol.Name;
newItem.AccessModifier = (AccessModifier)newItem.Symbol.DeclaredAccessibility;
@@ -27,12 +27,12 @@ public override void InitializeItem(IProperty newItem, PropertyDeclarationSyntax
if (propSymbol == null) throw new InvalidOperationException();
newItem.CanGet = (!propSymbol.IsWriteOnly); // or check whether getAccessor is null
newItem.CanSet = (!propSymbol.IsReadOnly); // or check whether setAccessor is null
- var getAccessorSyntax = syntax.AccessorList.Accessors.Where(x => x.CSharpKind() == SyntaxKind.GetAccessorDeclaration).FirstOrDefault();
- var setAccessorSyntax = syntax.AccessorList.Accessors.Where(x => x.CSharpKind() == SyntaxKind.SetAccessorDeclaration).FirstOrDefault();
+ var getAccessorSyntax = newItem.TypedSyntax.AccessorList.Accessors.Where(x => x.CSharpKind() == SyntaxKind.GetAccessorDeclaration).FirstOrDefault();
+ var setAccessorSyntax = newItem.TypedSyntax.AccessorList.Accessors.Where(x => x.CSharpKind() == SyntaxKind.SetAccessorDeclaration).FirstOrDefault();
if (getAccessorSyntax != null)
- { newItem.GetAccessor = (IAccessor)(RDomFactoryHelper.MiscFactoryHelper.MakeItem(getAccessorSyntax).FirstOrDefault()); }
+ { newItem.GetAccessor = (IAccessor)(RDomFactoryHelper.GetHelper<IMisc>().MakeItem(getAccessorSyntax).FirstOrDefault()); }
if (setAccessorSyntax != null)
- { newItem.SetAccessor = (IAccessor)(RDomFactoryHelper.MiscFactoryHelper.MakeItem(setAccessorSyntax).FirstOrDefault()); }
+ { newItem.SetAccessor = (IAccessor)(RDomFactoryHelper.GetHelper<IMisc>().MakeItem(setAccessorSyntax).FirstOrDefault()); }
}
public override IEnumerable<SyntaxNode> BuildSyntax(ITypeMember item)
@@ -59,4 +59,4 @@ public override IEnumerable<SyntaxNode> BuildSyntax(ITypeMember item)
}
}
- }
+}
View
5 .../StructureFactories/RDomReferencedType.cs → RoslynDom/Factories/RDomReferencedType.cs
@@ -6,10 +6,10 @@
using Microsoft.CodeAnalysis.CSharp.Syntax;
using RoslynDom.Common;
-namespace RoslynDom.CSharpFactories
+namespace RoslynDom
{
public class RDomReferencedTypeMiscFactory
- : RDomMiscFactory<IReferencedType, FieldDeclarationSyntax>
+ : RDomMiscFactory<RDomReferencedType, FieldDeclarationSyntax>
{
// I'm still evolving how types are handled.
public override IEnumerable<SyntaxNode> BuildSyntax(IMisc item)
@@ -24,4 +24,5 @@ public override IEnumerable<IMisc> CreateFrom(SyntaxNode syntaxNode)
throw new NotImplementedException();
}
}
+
}
View
11 ...pFactories/StructureFactories/RDomRoot.cs → RoslynDom/Factories/RDomRoot.cs
@@ -5,16 +5,16 @@
using Microsoft.CodeAnalysis.CSharp.Syntax;
using RoslynDom.Common;
-namespace RoslynDom.CSharpFactories
+namespace RoslynDom
{
public class RDomRootFactory
- : RDomRootContainerFactory<IRoot, CompilationUnitSyntax>
+ : RDomRootContainerFactory<RDomRoot, CompilationUnitSyntax>
{
- public override void InitializeItem(IRoot newItem, CompilationUnitSyntax syntax)
+ public override void InitializeItem(RDomRoot newItem, CompilationUnitSyntax syntax)
{
newItem.Name = "Root";
- var members = ListUtilities.MakeList(syntax, x => x.Members, x => RDomFactoryHelper.StemMemberFactoryHelper.MakeItem(x));
- var usings = ListUtilities.MakeList(syntax, x => x.Usings, x => RDomFactoryHelper.StemMemberFactoryHelper.MakeItem(x));
+ var members = ListUtilities.MakeList(newItem.TypedSyntax, x => x.Members, x => RDomFactoryHelper.GetHelper<IStemMember >().MakeItem(x));
+ var usings = ListUtilities.MakeList(newItem.TypedSyntax, x => x.Usings, x => RDomFactoryHelper.GetHelper<IStemMember>().MakeItem(x));
foreach (var member in members)
{ newItem.AddOrMoveStemMember(member); }
foreach (var member in usings)
@@ -37,4 +37,5 @@ public override IEnumerable<SyntaxNode> BuildSyntax(IRoot item)
}
}
+
}
View
19 ...ories/StructureFactories/RDomStructure.cs → RoslynDom/Factories/RDomStructure.cs
@@ -6,23 +6,23 @@
using Microsoft.CodeAnalysis.CSharp.Syntax;
using RoslynDom.Common;
-namespace RoslynDom.CSharpFactories
+namespace RoslynDom
{
internal static class RDomStructureFactoryHelper
{
- public static void InitializeItem(IStructure newItem, StructDeclarationSyntax syntax)
+ public static void InitializeItem(RDomStructure newItem, StructDeclarationSyntax syntax)
{
newItem.Name = newItem.TypedSymbol.Name;
newItem.AccessModifier = (AccessModifier)newItem.Symbol.DeclaredAccessibility;
var newTypeParameters = newItem.TypedSymbol.TypeParametersFrom();
foreach (var typeParameter in newTypeParameters)
{ newItem.AddOrMoveTypeParameter(typeParameter); }
- var members = ListUtilities.MakeList(syntax, x => x.Members, x => RDomFactoryHelper.TypeMemberFactoryHelper.MakeItem(x));
+ var members = ListUtilities.MakeList(newItem.TypedSyntax, x => x.Members, x => RDomFactoryHelper.GetHelper<ITypeMember>().MakeItem(x));
foreach (var member in members)
{ newItem.AddOrMoveMember(member); }
}
- public static IEnumerable<SyntaxNode> BuildSyntax(IStructure item)
+ public static IEnumerable<SyntaxNode> BuildSyntax(RDomStructure item)
{
// This is identical to Class, but didn't work out reuse here
var modifiers = item.BuildModfierSyntax();
@@ -41,9 +41,9 @@ public static IEnumerable<SyntaxNode> BuildSyntax(IStructure item)
}
}
public class RDomStructureTypeMemberFactory
- : RDomTypeMemberFactory<IStructure, StructDeclarationSyntax>
+ : RDomTypeMemberFactory<RDomStructure, StructDeclarationSyntax>
{
- public override void InitializeItem(IStructure newItem, StructDeclarationSyntax syntax)
+ public override void InitializeItem(RDomStructure newItem, StructDeclarationSyntax syntax)
{
RDomStructureFactoryHelper.InitializeItem(newItem, syntax);
}
@@ -55,9 +55,9 @@ public override IEnumerable<SyntaxNode> BuildSyntax(ITypeMember item)
public class RDomStructureStemMemberFactory
- : RDomStemMemberFactory<IStructure, StructDeclarationSyntax>
+ : RDomStemMemberFactory<RDomStructure, StructDeclarationSyntax>
{
- public override void InitializeItem(IStructure newItem, StructDeclarationSyntax syntax)
+ public override void InitializeItem(RDomStructure newItem, StructDeclarationSyntax syntax)
{
RDomStructureFactoryHelper.InitializeItem(newItem, syntax);
}
@@ -67,6 +67,5 @@ public override IEnumerable<SyntaxNode> BuildSyntax(IStemMember item)
return RDomStructureFactoryHelper.BuildSyntax((RDomStructure)item);
}
}
-
-
+
}
View
6 ...Factories/StructureFactories/RDomUsing.cs → RoslynDom/Factories/RDomUsing.cs
@@ -4,12 +4,12 @@
using Microsoft.CodeAnalysis.CSharp.Syntax;
using RoslynDom.Common;
-namespace RoslynDom.CSharpFactories
+namespace RoslynDom
{
public class RDomUsingStemMemberFactory
- : RDomStemMemberFactory<IUsing, UsingDirectiveSyntax>
+ : RDomStemMemberFactory<RDomUsing, UsingDirectiveSyntax>
{
- public override void InitializeItem(IUsing newItem, UsingDirectiveSyntax syntax)
+ public override void InitializeItem(RDomUsing newItem, UsingDirectiveSyntax syntax)
{
newItem. Name = syntax.Name.NameFrom();
}
View
10 ...ementFactories/RDomAssignmentStatement.cs → ...sForStatements/RDomAssignmentStatement.cs
@@ -6,12 +6,12 @@
using Microsoft.CodeAnalysis.CSharp.Syntax;
using RoslynDom.Common;
-namespace RoslynDom.CSharpFactories
+namespace RoslynDom
{
public class RDomAssignmentStatementFactory
- : RDomStatementFactory<IAssignmentStatement, ExpressionStatementSyntax>
+ : RDomStatementFactory<RDomAssignmentStatement, ExpressionStatementSyntax>
{
- public override void InitializeItem(IAssignmentStatement newItem, ExpressionStatementSyntax syntax)
+ public override void InitializeItem(RDomAssignmentStatement newItem, ExpressionStatementSyntax syntax)
{
var binary = syntax.Expression as BinaryExpressionSyntax;
if (binary == null) throw new InvalidOperationException();
@@ -24,7 +24,7 @@ public override void InitializeItem(IAssignmentStatement newItem, ExpressionStat
var expression = right as ExpressionSyntax;
if (expression == null) throw new InvalidOperationException();
newItem.Name = identifier.ToString();
- newItem.Expression = RDomFactoryHelper.ExpressionFactoryHelper.MakeItem(expression).FirstOrDefault();
+ newItem.Expression = RDomFactoryHelper.GetHelper<IExpression>().MakeItem(expression).FirstOrDefault();
}
public override IEnumerable<SyntaxNode> BuildSyntax(IStatement item)
{
@@ -44,6 +44,4 @@ public override bool CanCreateFrom(SyntaxNode syntaxNode)
return statement.Expression.CSharpKind() == SyntaxKind.SimpleAssignmentExpression;
}
}
-
-
}
View
9 .../StatementFactories/RDomBlockStatement.cs → ...toriesForStatements/RDomBlockStatement.cs
@@ -5,16 +5,16 @@
using Microsoft.CodeAnalysis.CSharp.Syntax;
using RoslynDom.Common;
-namespace RoslynDom.CSharpFactories
+namespace RoslynDom
{
public class RDomBlockStatementFactory
- : RDomStatementFactory<IBlockStatement, BlockSyntax>
+ : RDomStatementFactory<RDomBlockStatement, BlockSyntax>
{
- public override void InitializeItem(IBlockStatement newItem, BlockSyntax syntax)
+ public override void InitializeItem(RDomBlockStatement newItem, BlockSyntax syntax)
{
foreach (var statementSyntax in syntax.Statements)
{
- var statements = RDomFactoryHelper.StatementFactoryHelper.MakeItem(statementSyntax);
+ var statements = RDomFactoryHelper.GetHelper<IStatement>().MakeItem(statementSyntax);
foreach (var statement in statements)
{ newItem.AddOrMoveStatement(statement); }
}
@@ -32,5 +32,4 @@ public override IEnumerable<SyntaxNode> BuildSyntax(IStatement item)
}
}
-
}
View
13 ...mentFactories/RDomDeclarationStatement.cs → ...ForStatements/RDomDeclarationStatement.cs
@@ -4,12 +4,13 @@
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
+using Microsoft.Practices.Unity;
using RoslynDom.Common;
-namespace RoslynDom.CSharpFactories
+namespace RoslynDom
{
public class RDomDeclarationStatementFactory
- : RDomStatementFactory<IDeclarationStatement, VariableDeclaratorSyntax>
+ : RDomStatementFactory<RDomDeclarationStatement, VariableDeclaratorSyntax>
{
public override bool CanCreateFrom(SyntaxNode syntaxNode)
{
@@ -32,9 +33,9 @@ public override IEnumerable<IStatement> CreateFrom(SyntaxNode syntaxNode)
return list;
}
- public override void InitializeItem(IDeclarationStatement newItem, VariableDeclaratorSyntax syntax)
+ public override void InitializeItem(RDomDeclarationStatement newItem, VariableDeclaratorSyntax syntax)
{
- newItem.Name = newItem.Symbol.Name;
+ newItem.Name = newItem.TypedSymbol.Name;
var declaration = syntax.Parent as VariableDeclarationSyntax;
if (declaration == null) throw new InvalidOperationException();
newItem.IsImplicitlyTyped = (declaration.Type.ToString() == "var");
@@ -43,7 +44,7 @@ public override void InitializeItem(IDeclarationStatement newItem, VariableDecla
if (syntax.Initializer != null)
{
var equalsClause = syntax.Initializer;
- newItem.Initializer = RDomFactoryHelper.ExpressionFactoryHelper.MakeItem(equalsClause.Value).FirstOrDefault();
+ newItem.Initializer = RDomFactoryHelper.GetHelper<IExpression>().MakeItem(equalsClause.Value).FirstOrDefault();
}
}
@@ -70,6 +71,4 @@ public override IEnumerable<SyntaxNode> BuildSyntax(IStatement item)
return new SyntaxNode[] { RoslynUtilities.Format(node) };
}
}
-
-
}
View
18 ...ies/StatementFactories/RDomIfStatement.cs → ...FactoriesForStatements/RDomIfStatement.cs
@@ -6,17 +6,17 @@
using Microsoft.CodeAnalysis.CSharp.Syntax;
using RoslynDom.Common;
-namespace RoslynDom.CSharpFactories
+namespace RoslynDom
{
public class RDomIfStatementFactory
- : RDomStatementFactory<IIfStatement, IfStatementSyntax>
+ : RDomStatementFactory<RDomIfStatement, IfStatementSyntax>
{
- public override void InitializeItem(IIfStatement newItem, IfStatementSyntax syntax)
+ public override void InitializeItem(RDomIfStatement newItem, IfStatementSyntax syntax)
{
- newItem.Condition = RDomFactoryHelper.ExpressionFactoryHelper.MakeItem(syntax.Condition).FirstOrDefault();
+ newItem.Condition = RDomFactoryHelper.GetHelper<IExpression>().MakeItem(syntax.Condition).FirstOrDefault();
if (syntax.Condition == null) { throw new InvalidOperationException(); }
bool hasBlock = false;
- var statements = GetStatementsFromSyntax(syntax.Statement, ref hasBlock);
+ var statements = GetStatementsFromSyntax(newItem.TypedSyntax.Statement, ref hasBlock);
newItem.HasBlock = hasBlock;
foreach (var statement in statements)
{ newItem.AddOrMoveStatement(statement); }
@@ -24,7 +24,7 @@ public override void InitializeItem(IIfStatement newItem, IfStatementSyntax synt
InitializeElse(newItem, syntax);
}
- private void InitializeElse(IIfStatement newItem, IfStatementSyntax syntax)
+ private void InitializeElse(RDomIfStatement newItem, IfStatementSyntax syntax)
{
if (syntax.Else == null) return;
var elseAsIf = syntax.Else.Statement as IfStatementSyntax;
@@ -57,7 +57,7 @@ private void InitializeElse(IIfStatement newItem, IfStatementSyntax syntax)
}
}
- private void InitializeElseStatement(IIfStatement newItem, IfStatementSyntax syntax,StatementSyntax statement)
+ private void InitializeElseStatement(RDomIfStatement newItem, IfStatementSyntax syntax,StatementSyntax statement)
{
newItem.ElseHasBlock = statement is BlockSyntax;
bool hasBlock = false;
@@ -69,7 +69,7 @@ private void InitializeElseStatement(IIfStatement newItem, IfStatementSyntax syn
private IEnumerable<IStatement> GetStatementsFromSyntax(StatementSyntax statementSyntax, ref bool hasBlock)
{
- var statement = RDomFactoryHelper.StatementFactoryHelper.MakeItem(statementSyntax).First();
+ var statement = RDomFactoryHelper.GetHelper<IStatement>().MakeItem(statementSyntax).First();
var list = new List<IStatement>();
var blockStatement = statement as IBlockStatement;
if (blockStatement != null)
@@ -150,6 +150,4 @@ private ElseClauseSyntax BuildElseSyntax(IEnumerable<IIfStatement> elseIfs, IEnu
return elseClause;
}
}
-
-
}
View
10 ...ementFactories/RDomInvocationStatement.cs → ...sForStatements/RDomInvocationStatement.cs
@@ -6,15 +6,15 @@
using Microsoft.CodeAnalysis.CSharp.Syntax;
using RoslynDom.Common;
-namespace RoslynDom.CSharpFactories
+namespace RoslynDom
{
public class RDomInvocationStatementFactory
- : RDomStatementFactory<IInvocationStatement, ExpressionStatementSyntax>
+ : RDomStatementFactory<RDomInvocationStatement, ExpressionStatementSyntax>
{
- public override void InitializeItem(IInvocationStatement newItem, ExpressionStatementSyntax syntax)
+ public override void InitializeItem(RDomInvocationStatement newItem, ExpressionStatementSyntax syntax)
{
var expression = syntax.Expression;
- newItem.Invocation = RDomFactoryHelper.ExpressionFactoryHelper.MakeItem(expression).FirstOrDefault();
+ newItem.Invocation = RDomFactoryHelper.GetHelper<IExpression>().MakeItem(expression).FirstOrDefault();
}
public override IEnumerable<SyntaxNode> BuildSyntax(IStatement item)
@@ -36,6 +36,4 @@ public override bool CanCreateFrom(SyntaxNode syntaxNode)
return syntaxNode is ExpressionStatementSyntax;
}
}
-
-
}
View
10 ...StatementFactories/RDomReturnStatement.cs → ...oriesForStatements/RDomReturnStatement.cs
@@ -5,18 +5,19 @@
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
+using Microsoft.Practices.Unity;
using RoslynDom.Common;
-namespace RoslynDom.CSharpFactories
+namespace RoslynDom
{
public class RDomReturnStatementFactory
- : RDomStatementFactory<IReturnStatement, ReturnStatementSyntax>
+ : RDomStatementFactory<RDomReturnStatement, ReturnStatementSyntax>
{
- public override void InitializeItem(IReturnStatement newItem, ReturnStatementSyntax syntax)
+ public override void InitializeItem(RDomReturnStatement newItem, ReturnStatementSyntax syntax)
{
if (syntax.Expression != null)
{
- newItem.Return = RDomFactoryHelper.ExpressionFactoryHelper.MakeItem(syntax.Expression).FirstOrDefault();
+ newItem.Return = RDomFactoryHelper.GetHelper<IExpression>().MakeItem(syntax.Expression).FirstOrDefault();
if (newItem.Return == null) throw new InvalidOperationException();
}
}
@@ -33,5 +34,4 @@ public override IEnumerable<SyntaxNode> BuildSyntax(IStatement item)
return new SyntaxNode[] { RoslynUtilities.Format(node) };
}
}
-
}
View
15 RoslynDom/Implementations/RDomAccessor.cs
@@ -7,21 +7,6 @@
namespace RoslynDom
{
- public class RDomPropertyAccessorMiscFactory
- : RDomMiscFactory<RDomPropertyAccessor, AccessorDeclarationSyntax>
- {
- public override void InitializeItem(RDomPropertyAccessor newItem, AccessorDeclarationSyntax syntax)
- {
- newItem.AccessModifier = (AccessModifier)newItem.Symbol.DeclaredAccessibility;
- if (syntax.Body != null)
- {
- var statements = ListUtilities.MakeList(syntax, x => x.Body.Statements, x => RDomFactoryHelper.GetHelper<IStatement>().MakeItem(x));
- foreach (var statement in statements)
- { newItem.AddStatement(statement); }
- }
- }
- }
-
public class RDomPropertyAccessor : RDomBase<IAccessor, AccessorDeclarationSyntax, ISymbol>, IAccessor
{
private IList<IStatement> _statements = new List<IStatement>();
View
64 RoslynDom/Implementations/RDomClass.cs
@@ -8,70 +8,6 @@
namespace RoslynDom
{
- internal static class RDomClassFactoryHelper
- {
- public static void InitializeItem(RDomClass newItem, ClassDeclarationSyntax syntax)
- {
- newItem.Name = newItem.TypedSymbol.Name;
- newItem.AccessModifier = (AccessModifier)newItem.Symbol.DeclaredAccessibility;
- var newTypeParameters = newItem.TypedSymbol.TypeParametersFrom();
- foreach (var typeParameter in newTypeParameters)
- { newItem.AddOrMoveTypeParameter(typeParameter); }
- var members = ListUtilities.MakeList(newItem.TypedSyntax, x => x.Members, x => RDomFactoryHelper.GetHelper<ITypeMember>().MakeItem(x));
- foreach (var member in members)
- { newItem.AddOrMoveMember(member); }
- newItem.BaseType = new RDomReferencedType(newItem.TypedSymbol.DeclaringSyntaxReferences, newItem.TypedSymbol.BaseType);
- newItem.IsAbstract = newItem.Symbol.IsAbstract;
- newItem.IsSealed = newItem.Symbol.IsSealed;
- newItem.IsStatic = newItem.Symbol.IsStatic;
- }
-
- public static IEnumerable<SyntaxNode> BuildSyntax(RDomClass item)
- {
- var modifiers = item.BuildModfierSyntax();
- var identifier = SyntaxFactory.Identifier(item.Name);
- var node = SyntaxFactory.ClassDeclaration(identifier)
- .WithModifiers(modifiers);
- var itemAsClass = item as IClass;
- if (itemAsClass == null) { throw new InvalidOperationException(); }
- var attributes = BuildSyntaxExtensions.BuildAttributeListSyntax(item.Attributes);
- if (attributes.Any()) { node = node.WithAttributeLists(attributes); }
- var membersSyntax = itemAsClass.Members
- .SelectMany(x => RDomFactory.BuildSyntaxGroup(x))
- .ToList();
- node = node.WithMembers(SyntaxFactory.List(membersSyntax));
- // TODO: Class type members and type constraints
- return new SyntaxNode[] { RoslynUtilities.Format(node) };
- }
- }
- public class RDomClassTypeMemberFactory
- : RDomTypeMemberFactory<RDomClass, ClassDeclarationSyntax>
- {
- public override void InitializeItem(RDomClass newItem, ClassDeclarationSyntax syntax)
- {
- RDomClassFactoryHelper.InitializeItem(newItem, syntax);
- }
- public override IEnumerable<SyntaxNode> BuildSyntax(ITypeMember item)
- {
- return RDomClassFactoryHelper.BuildSyntax((RDomClass)item);
- }
- }
-
- public class RDomClassStemMemberFactory
- : RDomStemMemberFactory<RDomClass, ClassDeclarationSyntax>
- {
- public override void InitializeItem(RDomClass newItem, ClassDeclarationSyntax syntax)
- {
- RDomClassFactoryHelper.InitializeItem(newItem, syntax);
- }
- public override IEnumerable<SyntaxNode> BuildSyntax(IStemMember item)
- {
- return RDomClassFactoryHelper.BuildSyntax((RDomClass)item);
- }
- }
-
-
-
/// <summary>
///
/// </summary>
View
63 RoslynDom/Implementations/RDomEnum.cs
@@ -8,68 +8,7 @@
namespace RoslynDom
{
- internal static class RDomEnumFactoryHelper
- {
- public static void InitializeItem(RDomEnum newItem, EnumDeclarationSyntax syntax)
- {
- newItem.Name = newItem.TypedSymbol.Name;
- newItem.AccessModifier = (AccessModifier)newItem.Symbol.DeclaredAccessibility;
- var symbol = newItem.Symbol as INamedTypeSymbol;
- if (symbol != null)
- {
- var underlyingNamedTypeSymbol = symbol.EnumUnderlyingType;
- newItem.UnderlyingType = new RDomReferencedType(underlyingNamedTypeSymbol.DeclaringSyntaxReferences, underlyingNamedTypeSymbol);
- }
- }
-
- public static IEnumerable<SyntaxNode> BuildSyntax(RDomEnum item)
- {
- var modifiers = item.BuildModfierSyntax();
- var identifier = SyntaxFactory.Identifier(item.Name);
- var attributeSyntax = BuildSyntaxExtensions.BuildAttributeListSyntax(item.Attributes);
- var node = SyntaxFactory.EnumDeclaration(identifier)
- .WithModifiers(modifiers);
- var itemAsEnum = item as IEnum;
- if (itemAsEnum == null) { throw new InvalidOperationException(); }
- //var membersSyntax = itemAsEnum.Members
- // .SelectMany(x => RDomFactoryHelper.TypeMemberFactoryHelper.BuildSyntax(x))
- // .ToList();
- //node = node.WithMembers(SyntaxFactory.List(membersSyntax));
- // TODO: Class type members and type constraints
- return new SyntaxNode[] { RoslynUtilities.Format(node) };
- }
- }
-
- public class RDomEnumTypeMemberFactory
- : RDomTypeMemberFactory<RDomEnum, EnumDeclarationSyntax>
- {
- public override void InitializeItem(RDomEnum newItem, EnumDeclarationSyntax syntax)
- {
- RDomEnumFactoryHelper.InitializeItem(newItem, syntax);
- }
-
- public override IEnumerable<SyntaxNode> BuildSyntax(ITypeMember item)
- {
- return RDomEnumFactoryHelper.BuildSyntax((RDomEnum)item);
- }
- }
-
-
- public class RDomEnumStemMemberFactory
- : RDomStemMemberFactory<RDomEnum, EnumDeclarationSyntax>
- {
- public override void InitializeItem(RDomEnum newItem, EnumDeclarationSyntax syntax)
- {
- RDomEnumFactoryHelper.InitializeItem(newItem, syntax);
- }
- public override IEnumerable<SyntaxNode> BuildSyntax(IStemMember item)
- {
- return RDomEnumFactoryHelper.BuildSyntax((RDomEnum)item);
- }
- }
-
-
- public class RDomEnum : RDomBase<IEnum, EnumDeclarationSyntax, ISymbol>, IEnum
+ public class RDomEnum : RDomBase<IEnum, EnumDeclarationSyntax, ISymbol>, IEnum
{
internal RDomEnum(
EnumDeclarationSyntax rawItem)
View
45 RoslynDom/Implementations/RDomField.cs
@@ -7,51 +7,6 @@
namespace RoslynDom
{
- public class RDomFieldTypeMemberFactory
- : RDomTypeMemberFactory<RDomField, FieldDeclarationSyntax>
- {
- public override void InitializeItem(RDomField newItem, FieldDeclarationSyntax syntax)
- {
- newItem.Name = newItem.TypedSymbol.Name;
- newItem.AccessModifier = (AccessModifier)newItem.Symbol.DeclaredAccessibility;
- newItem.ReturnType = new RDomReferencedType(newItem.TypedSymbol.DeclaringSyntaxReferences, newItem.TypedSymbol.Type);
- newItem.IsStatic = newItem.Symbol.IsStatic;
- }
- public override IEnumerable<ITypeMember> CreateFrom(SyntaxNode syntaxNode)
- {
- var list = new List<ITypeMember>();
- // We can't do this in the constructor, because many may be created and we want to flatten
- var rawField = syntaxNode as FieldDeclarationSyntax;
- var declarators = rawField.Declaration.Variables.OfType<VariableDeclaratorSyntax>();
- foreach (var decl in declarators)
- {
- var newItem = new RDomField(rawField, decl);
- list.Add(newItem);
- InitializeItem(newItem, rawField);
- }
- return list;
- }
-
- public override IEnumerable<SyntaxNode> BuildSyntax(ITypeMember item)
- {
- var nameSyntax = SyntaxFactory.Identifier(item.Name);
- var itemAsField = item as IField;
- var returnType = (TypeSyntax)RDomFactory.BuildSyntaxGroup(itemAsField.ReturnType).First();
- var modifiers = BuildSyntaxExtensions.BuildModfierSyntax(item);
- var declaratorNode = SyntaxFactory.VariableDeclarator(nameSyntax);
- var variableNode = SyntaxFactory.VariableDeclaration(returnType)
- .WithVariables(
- SyntaxFactory.SingletonSeparatedList<VariableDeclaratorSyntax>(
- SyntaxFactory.VariableDeclarator(nameSyntax)));
- var node = SyntaxFactory.FieldDeclaration(variableNode)
- .WithModifiers(modifiers);
- var attributes = BuildSyntaxExtensions.BuildAttributeListSyntax(item.Attributes );
- if (attributes.Any()) { node = node.WithAttributeLists(attributes );}
- return new SyntaxNode[] { node.NormalizeWhitespace() };
- }
-
- }
-
/// <summary>
///
View
63 RoslynDom/Implementations/RDomInterface.cs
@@ -8,68 +8,7 @@
namespace RoslynDom
{
- internal static class RDomInterfaceFactoryHelper
- {
- public static void InitializeItem(RDomInterface newItem, InterfaceDeclarationSyntax syntax)
- {
- newItem.Name = newItem.TypedSymbol.Name;
- newItem.AccessModifier = (AccessModifier)newItem.Symbol.DeclaredAccessibility;
- var newTypeParameters = newItem.TypedSymbol.TypeParametersFrom();
- foreach (var typeParameter in newTypeParameters)
- { newItem.AddOrMoveTypeParameter(typeParameter); }
- var members = ListUtilities.MakeList(newItem.TypedSyntax, x => x.Members, x => RDomFactoryHelper.GetHelper<ITypeMember>().MakeItem(x));
- foreach (var member in members)
- { newItem.AddOrMoveMember(member); }
- }
-
- public static IEnumerable<SyntaxNode> BuildSyntax(RDomInterface item)
- {
- var modifiers = item.BuildModfierSyntax();
- var identifier = SyntaxFactory.Identifier(item.Name);
- var attributeSyntax = BuildSyntaxExtensions.BuildAttributeListSyntax(item.Attributes);
- var node = SyntaxFactory.InterfaceDeclaration(identifier)
- .WithModifiers(modifiers);
- var itemAsInterface = item as IInterface;
- if (itemAsInterface == null) { throw new InvalidOperationException(); }
- var membersSyntax = itemAsInterface.Members
- .SelectMany(x => RDomFactory.BuildSyntaxGroup(x))
- .ToList();
- node = node.WithMembers(SyntaxFactory.List(membersSyntax));
- // TODO: Class type members and type constraints
- return new SyntaxNode[] { RoslynUtilities.Format(node) };
- }
- }
-
- public class RDomInterfaceTypeMemberFactory
- : RDomTypeMemberFactory<RDomInterface, InterfaceDeclarationSyntax>
- {
- public override void InitializeItem(RDomInterface newItem, InterfaceDeclarationSyntax syntax)
- {
- RDomInterfaceFactoryHelper.InitializeItem(newItem, syntax);
- }
- public override IEnumerable<SyntaxNode> BuildSyntax(ITypeMember item)
- {
- return RDomInterfaceFactoryHelper.BuildSyntax((RDomInterface)item);
- }
- }
-
-
- public class RDomInterfaceStemMemberFactory
- : RDomStemMemberFactory<RDomInterface, InterfaceDeclarationSyntax>
- {
- public override void InitializeItem(RDomInterface newItem, InterfaceDeclarationSyntax syntax)
- {
- RDomInterfaceFactoryHelper.InitializeItem(newItem, syntax);
- }
- public override IEnumerable<SyntaxNode> BuildSyntax(IStemMember item)
- {
- return RDomInterfaceFactoryHelper.BuildSyntax((RDomInterface)item);
- }
- }
-
-
-
- public class RDomInterface : RDomBaseType<IInterface, InterfaceDeclarationSyntax>, IInterface
+ public class RDomInterface : RDomBaseType<IInterface, InterfaceDeclarationSyntax>, IInterface
{
internal RDomInterface(
InterfaceDeclarationSyntax rawItem)
View
54 RoslynDom/Implementations/RDomMethod.cs
@@ -7,60 +7,6 @@
namespace RoslynDom
{
- public class RDomMethodTypeMemberFactory
- : RDomTypeMemberFactory<RDomMethod, MethodDeclarationSyntax>
- {
- public override void InitializeItem(RDomMethod newItem, MethodDeclarationSyntax rawItem)
- {
- newItem.Name = newItem.TypedSymbol.Name;
- var typeParameters = newItem.TypedSymbol.TypeParametersFrom();
- foreach (var typeParameter in typeParameters)
- { newItem.AddTypeParameter(typeParameter); }
-
- newItem.AccessModifier = RoslynUtilities.GetAccessibilityFromSymbol(newItem.Symbol);
- newItem.ReturnType = new RDomReferencedType(newItem.TypedSymbol.DeclaringSyntaxReferences, newItem.TypedSymbol.ReturnType);
- newItem.IsAbstract = newItem.Symbol.IsAbstract;
- newItem.IsVirtual = newItem.Symbol.IsVirtual;
- newItem.IsOverride = newItem.Symbol.IsOverride;
- newItem.IsSealed = newItem.Symbol.IsSealed;
- newItem.IsStatic = newItem.Symbol.IsStatic;
- newItem.IsExtensionMethod = newItem.TypedSymbol.IsExtensionMethod;
- var parameters = ListUtilities.MakeList(rawItem, x => x.ParameterList.Parameters, x => RDomFactoryHelper.GetHelper<IMisc>().MakeItem(x));
- foreach (var parameter in parameters)
- { newItem.AddParameter((IParameter)parameter); }
- if (rawItem.Body != null)
- {
- var statements = ListUtilities.MakeList(rawItem, x => x.Body.Statements, x => RDomFactoryHelper.GetHelper<IStatement>().MakeItem(x));
- foreach (var statement in statements)
- { newItem.AddStatement(statement); }
- }
- }
-
- public override IEnumerable<SyntaxNode> BuildSyntax(ITypeMember item)
- {
- var nameSyntax = SyntaxFactory.Identifier(item.Name);
- var itemAsMethod = item as IMethod;
- var returnTypeSyntax = (TypeSyntax)RDomFactory.BuildSyntaxGroup(itemAsMethod.ReturnType).First();
- var modifiers = BuildSyntaxExtensions.BuildModfierSyntax(item);
- var node = SyntaxFactory.MethodDeclaration(returnTypeSyntax, nameSyntax)
- .WithModifiers(modifiers);
- var attributes = BuildSyntaxExtensions.BuildAttributeListSyntax(item.Attributes);
- if (attributes.Any()) { node = node.WithAttributeLists(attributes); }
- var parameterSyntaxList = itemAsMethod.Parameters
- .SelectMany(x => RDomFactory.BuildSyntaxGroup(x))
- .OfType<ParameterSyntax>()
- .ToList();
- if (parameterSyntaxList.Any()) { node = node.WithParameterList(SyntaxFactory.ParameterList(SyntaxFactory.SeparatedList(parameterSyntaxList))); }
- node = node.WithBody(RoslynUtilities.MakeStatementBlock(itemAsMethod.Statements));
-
- // TODO: typeParameters and constraintClauses
-
- return new SyntaxNode[] { RoslynUtilities.Format(node) };
- }
-
- }
-
-
public class RDomMethod : RDomBase<IMethod, MethodDeclarationSyntax, IMethodSymbol>, IMethod
{
private IList<IParameter> _parameters = new List<IParameter>();
View
38 RoslynDom/Implementations/RDomNamespace.cs
@@ -8,44 +8,6 @@
namespace RoslynDom
{
-
- public class RDomNamespaceStemMemberFactory
- : RDomStemMemberFactory<RDomNamespace, NamespaceDeclarationSyntax>
- {
- public override void InitializeItem(RDomNamespace newItem, NamespaceDeclarationSyntax syntax)
- {
- // Qualified name unbundles namespaces, and if it's defined together, we want it together here.
- // Thus, this replaces hte base Initialize name with the correct one
- newItem.Name = newItem.TypedSyntax.NameFrom();
- if (newItem.Name.StartsWith("@")) { newItem.Name = newItem.Name.Substring(1); }
- var members = ListUtilities.MakeList(newItem.TypedSyntax, x => x.Members, x => RDomFactoryHelper.GetHelper<IStemMember>().MakeItem(x));
- var usings = ListUtilities.MakeList(newItem.TypedSyntax, x => x.Usings, x => RDomFactoryHelper.GetHelper<IStemMember>().MakeItem(x));
- foreach (var member in members)
- { newItem.AddOrMoveStemMember(member); }
- foreach (var member in usings)
- { newItem.AddOrMoveStemMember(member); }
- }
- public override IEnumerable<SyntaxNode> BuildSyntax(IStemMember item)
- {
- var identifier = SyntaxFactory.IdentifierName(item.Name);
- var node = SyntaxFactory.NamespaceDeclaration (identifier);
- var itemAsNamespace = item as INamespace;
- if (itemAsNamespace == null) { throw new InvalidOperationException(); }
- var usingsSyntax = itemAsNamespace.Usings
- .Select(x => RDomFactory.BuildSyntaxGroup(x))
- .OfType<UsingDirectiveSyntax>()
- .ToList();
- if (usingsSyntax.Count() > 0) { node = node.WithUsings(SyntaxFactory.List<UsingDirectiveSyntax>(usingsSyntax)); }
- var membersSyntax = itemAsNamespace.StemMembers
- .Select(x => RDomFactory.BuildSyntaxGroup(x))
- .OfType<MemberDeclarationSyntax>()
- .ToList();
- if (usingsSyntax.Count() > 0) { node = node.WithMembers(SyntaxFactory.List<MemberDeclarationSyntax>(membersSyntax)); }
- return new SyntaxNode[] { node.NormalizeWhitespace() };
- }
- }
-
-
public class RDomNamespace : RDomBaseStemContainer<INamespace, NamespaceDeclarationSyntax, INamespaceSymbol>, INamespace
{
//private string _outerName;
View
38 RoslynDom/Implementations/RDomParameter.cs
@@ -7,44 +7,6 @@
namespace RoslynDom
{
- public class RDomParameterMiscFactory
- : RDomMiscFactory<RDomParameter, ParameterSyntax>
- {
- public override void InitializeItem(RDomParameter newItem, ParameterSyntax syntax)
- {
- newItem.Name = newItem.TypedSymbol.Name;
- newItem.Type = new RDomReferencedType(newItem.TypedSymbol.DeclaringSyntaxReferences, newItem.TypedSymbol.Type);
- newItem.IsOut = newItem.TypedSymbol.RefKind == RefKind.Out;
- newItem.IsRef = newItem.TypedSymbol.RefKind == RefKind.Ref;
- newItem.IsParamArray = newItem.TypedSymbol.IsParams;
- newItem.IsOptional = newItem.TypedSymbol.IsOptional;
- newItem.Ordinal = newItem.TypedSymbol.Ordinal;
- }
-
- public override IEnumerable<SyntaxNode> BuildSyntax(IMisc item)
- {
- var nameSyntax = SyntaxFactory.Identifier(item.Name);
- var itemAsT = item as IParameter;
- var syntaxType = (TypeSyntax)(RDomFactory.BuildSyntax(itemAsT.Type));
-
- var node = SyntaxFactory.Parameter(nameSyntax)
- .WithType(syntaxType);
-
- var attributes = BuildSyntaxExtensions.BuildAttributeListSyntax(itemAsT.Attributes);
- if (attributes.Any()) { node = node.WithAttributeLists(attributes); }
-
- var modifiers = SyntaxFactory.TokenList();
- if (itemAsT.IsOut) { modifiers = modifiers.Add(SyntaxFactory.Token(SyntaxKind.OutKeyword)); }
- if (itemAsT.IsRef) { modifiers = modifiers.Add(SyntaxFactory.Token(SyntaxKind.RefKeyword)); }
- if (itemAsT.IsParamArray) { modifiers = modifiers.Add(SyntaxFactory.Token(SyntaxKind.ParamsKeyword)); }
- if (itemAsT.IsRef) { modifiers = modifiers.Add(SyntaxFactory.Token(SyntaxKind.RefKeyword)); }
- if (modifiers.Any()) { node = node.WithModifiers(modifiers); }
- return new SyntaxNode[] { node.NormalizeWhitespace() };
-
- }
- }
-
-
public class RDomParameter : RDomBase<IParameter, ParameterSyntax, IParameterSymbol>, IParameter
{
View
51 RoslynDom/Implementations/RDomProperty.cs
@@ -8,57 +8,6 @@
namespace RoslynDom
{
- public class RDomPropertyTypeMemberFactory
- : RDomTypeMemberFactory<RDomProperty, PropertyDeclarationSyntax>
- {
- public override void InitializeItem(RDomProperty newItem, PropertyDeclarationSyntax syntax)
- {
- newItem.Name = newItem.TypedSymbol.Name;
- newItem.AccessModifier = (AccessModifier)newItem.Symbol.DeclaredAccessibility;
- // TODO: Get and set accessibility
- // TODO: Type parameters and constraints
- newItem.PropertyType = new RDomReferencedType(newItem.TypedSymbol.DeclaringSyntaxReferences, newItem.TypedSymbol.Type);
- newItem.IsAbstract = newItem.Symbol.IsAbstract;
- newItem.IsVirtual = newItem.Symbol.IsVirtual;
- newItem.IsOverride = newItem.Symbol.IsOverride;
- newItem.IsSealed = newItem.Symbol.IsSealed;
- newItem.IsStatic = newItem.Symbol.IsStatic;
- var propSymbol = newItem.Symbol as IPropertySymbol;
- if (propSymbol == null) throw new InvalidOperationException();
- newItem.CanGet = (!propSymbol.IsWriteOnly); // or check whether getAccessor is null
- newItem.CanSet = (!propSymbol.IsReadOnly); // or check whether setAccessor is null
- var getAccessorSyntax = newItem.TypedSyntax.AccessorList.Accessors.Where(x => x.CSharpKind() == SyntaxKind.GetAccessorDeclaration).FirstOrDefault();
- var setAccessorSyntax = newItem.TypedSyntax.AccessorList.Accessors.Where(x => x.CSharpKind() == SyntaxKind.SetAccessorDeclaration).FirstOrDefault();
- if (getAccessorSyntax != null)
- { newItem.GetAccessor = (IAccessor)(RDomFactoryHelper.GetHelper<IMisc>().MakeItem(getAccessorSyntax).FirstOrDefault()); }
- if (setAccessorSyntax != null)
- { newItem.SetAccessor = (IAccessor)(RDomFactoryHelper.GetHelper<IMisc>().MakeItem(setAccessorSyntax).FirstOrDefault()); }
- }
-
- public override IEnumerable<SyntaxNode> BuildSyntax(ITypeMember item)
- {
- var nameSyntax = SyntaxFactory.Identifier(item.Name);
- var itemAsProeprty = item as IProperty;
- var returnType = (TypeSyntax)RDomFactory.BuildSyntax(itemAsProeprty.ReturnType);
- var modifiers = BuildSyntaxExtensions.BuildModfierSyntax(item);
- var node = SyntaxFactory.PropertyDeclaration(returnType, nameSyntax)
- .WithModifiers(modifiers);
-
- var attributes = BuildSyntaxExtensions.BuildAttributeListSyntax(item.Attributes);
- if (attributes.Any()) { node = node.WithAttributeLists(attributes); }
-
- var accessors = SyntaxFactory.List<AccessorDeclarationSyntax>();
- var getAccessorSyntax = RDomFactory.BuildSyntaxGroup(itemAsProeprty.GetAccessor).FirstOrDefault();
- if (getAccessorSyntax != null) { accessors = accessors.Add((AccessorDeclarationSyntax)getAccessorSyntax); }
- var setAccessorSyntax = RDomFactory.BuildSyntaxGroup(itemAsProeprty.SetAccessor).FirstOrDefault();
- if (setAccessorSyntax != null) { accessors = accessors.Add((AccessorDeclarationSyntax)setAccessorSyntax); }
- if (accessors.Any()) { node = node.WithAccessorList(SyntaxFactory.AccessorList(accessors)); }
- // TODO: parameters , typeParameters and constraintClauses
-
- return new SyntaxNode[] { node.NormalizeWhitespace() };
- }
- }
-
public class RDomProperty : RDomBase<IProperty, PropertyDeclarationSyntax, IPropertySymbol>, IProperty
{
private IList<IParameter> _parameters = new List<IParameter>();
View
17 RoslynDom/Implementations/RDomReferencedType.cs
@@ -8,23 +8,6 @@
namespace RoslynDom
{
- public class RDomReferencedTypeMiscFactory
- : RDomMiscFactory<RDomReferencedType, FieldDeclarationSyntax>
- {
- // I'm still evolving how types are handled.
- public override IEnumerable<SyntaxNode> BuildSyntax(IMisc item)
- {
- var node = SyntaxFactory.ParseTypeName(item.Name);
- return new SyntaxNode[] { node.NormalizeWhitespace() };
- }
-
- public override IEnumerable<IMisc> CreateFrom(SyntaxNode syntaxNode)
- {
- // Not currently used
- throw new NotImplementedException();
- }
- }
-
public class RDomReferencedType : RDomBase, IReferencedType
{
// I'm still evolving how types are handled.
View
33 RoslynDom/Implementations/RDomRoot.cs
@@ -7,38 +7,7 @@
namespace RoslynDom
{
- public class RDomRootFactory
- : RDomRootContainerFactory<RDomRoot, CompilationUnitSyntax>
- {
- public override void InitializeItem(RDomRoot newItem, CompilationUnitSyntax syntax)
- {
- newItem.Name = "Root";
- var members = ListUtilities.MakeList(newItem.TypedSyntax, x => x.Members, x => RDomFactoryHelper.GetHelper<IStemMember >().MakeItem(x));
- var usings = ListUtilities.MakeList(newItem.TypedSyntax, x => x.Usings, x => RDomFactoryHelper.GetHelper<IStemMember>().MakeItem(x));
- foreach (var member in members)
- { newItem.AddOrMoveStemMember(member); }
- foreach (var member in usings)
- { newItem.AddOrMoveStemMember(member); }
- }
-
- public override IEnumerable<SyntaxNode> BuildSyntax(IRoot item)
- {
- var node = SyntaxFactory.CompilationUnit();
- var usingsSyntax = item.Usings
- .SelectMany(x => RDomFactory.BuildSyntaxGroup(x))
- .ToList();
- var membersSyntax = item.StemMembers
- .Where(x=>!(x is IUsing))
- .SelectMany(x => RDomFactory.BuildSyntaxGroup(x))
- .ToList();
- node = node.WithUsings(SyntaxFactory.List(usingsSyntax));
- node = node.WithMembers(SyntaxFactory.List(membersSyntax));
- return new SyntaxNode[] { RoslynUtilities.Format(node) };
- }
- }
-
-
- public class RDomRoot : RDomBaseStemContainer<IRoot, CompilationUnitSyntax, ISymbol>, IRoot
+ public class RDomRoot : RDomBaseStemContainer<IRoot, CompilationUnitSyntax, ISymbol>, IRoot
{
internal RDomRoot(CompilationUnitSyntax rawItem)
View
63 RoslynDom/Implementations/RDomStructure.cs
@@ -8,68 +8,7 @@
namespace RoslynDom
{
- internal static class RDomStructureFactoryHelper
- {
- public static void InitializeItem(RDomStructure newItem, StructDeclarationSyntax syntax)
- {
- newItem.Name = newItem.TypedSymbol.Name;
- newItem.AccessModifier = (AccessModifier)newItem.Symbol.DeclaredAccessibility;
- var newTypeParameters = newItem.TypedSymbol.TypeParametersFrom();
- foreach (var typeParameter in newTypeParameters)
- { newItem.AddOrMoveTypeParameter(typeParameter); }
- var members = ListUtilities.MakeList(newItem.TypedSyntax, x => x.Members, x => RDomFactoryHelper.GetHelper<ITypeMember>().MakeItem(x));
- foreach (var member in members)
- { newItem.AddOrMoveMember(member); }
- }
-
- public static IEnumerable<SyntaxNode> BuildSyntax(RDomStructure item)
- {
- // This is identical to Class, but didn't work out reuse here
- var modifiers = item.BuildModfierSyntax();
- var identifier = SyntaxFactory.Identifier(item.Name);
- var attributeSyntax = BuildSyntaxExtensions.BuildAttributeListSyntax(item.Attributes);
- var node = SyntaxFactory.StructDeclaration(identifier)
- .WithModifiers(modifiers);
- var itemAsStruct = item as IStructure;
- if (itemAsStruct == null) { throw new InvalidOperationException(); }
- var membersSyntax = itemAsStruct.Members
- .SelectMany(x => RDomFactory.BuildSyntaxGroup(x))
- .ToList();
- node = node.WithMembers(SyntaxFactory.List(membersSyntax));
- // TODO: Class type members and type constraints
- return new SyntaxNode[] { RoslynUtilities.Format(node) };
- }
- }
- public class RDomStructureTypeMemberFactory
- : RDomTypeMemberFactory<RDomStructure, StructDeclarationSyntax>
- {
- public override void InitializeItem(RDomStructure newItem, StructDeclarationSyntax syntax)
- {
- RDomStructureFactoryHelper.InitializeItem(newItem, syntax);
- }
- public override IEnumerable<SyntaxNode> BuildSyntax(ITypeMember item)
- {
- return RDomStructureFactoryHelper.BuildSyntax((RDomStructure)item);
- }
- }
-
-
- public class RDomStructureStemMemberFactory
- : RDomStemMemberFactory<RDomStructure, StructDeclarationSyntax>
- {
- public override void InitializeItem(RDomStructure newItem, StructDeclarationSyntax syntax)
- {
- RDomStructureFactoryHelper.InitializeItem(newItem, syntax);
- }
- public override IEnumerable<SyntaxNode> BuildSyntax(IStemMember item)
- {
-
- return RDomStructureFactoryHelper.BuildSyntax((RDomStructure)item);
- }
- }
-
-
- public class RDomStructure : RDomBaseType<IStructure, StructDeclarationSyntax>, IStructure
+ public class RDomStructure : RDomBaseType<IStructure, StructDeclarationSyntax>, IStructure
{
internal RDomStructure(
StructDeclarationSyntax rawItem)
View
20 RoslynDom/Implementations/RDomUsing.cs
@@ -6,25 +6,7 @@
namespace RoslynDom
{
- public class RDomUsingStemMemberFactory
- : RDomStemMemberFactory<RDomUsing, UsingDirectiveSyntax>
- {
- public override void InitializeItem(RDomUsing newItem, UsingDirectiveSyntax syntax)
- {
- newItem. Name = syntax.Name.NameFrom();
- }
- public override IEnumerable<SyntaxNode> BuildSyntax(IStemMember item)
- {
- // TODO: Handle alias's
- // TODO: Handle using statements, that's not done
- var identifier = SyntaxFactory.IdentifierName(item.Name);
- var node = SyntaxFactory.UsingDirective(identifier);
-
- return new SyntaxNode[] { node.NormalizeWhitespace() };
- }
- }
-
- public class RDomUsing : RDomBase<IUsing, UsingDirectiveSyntax, ISymbol>, IUsing
+ public class RDomUsing : RDomBase<IUsing, UsingDirectiveSyntax, ISymbol>, IUsing
{
internal RDomUsing(
UsingDirectiveSyntax rawItem)
View
19 RoslynDom/RoslynDom.csproj
@@ -74,6 +74,25 @@
<Compile Include="BasesAndBaseHelpers\RDomBaseStemContainer.cs" />
<Compile Include="BasesAndBaseHelpers\RDomExpression.cs" />
<Compile Include="BuildSyntaxExtensions.cs" />
+ <Compile Include="FactoriesForStatements\RDomAssignmentStatement.cs" />
+ <Compile Include="FactoriesForStatements\RDomBlockStatement.cs" />
+ <Compile Include="FactoriesForStatements\RDomDeclarationStatement.cs" />
+ <Compile Include="FactoriesForStatements\RDomIfStatement.cs" />
+ <Compile Include="FactoriesForStatements\RDomInvocationStatement.cs" />
+ <Compile Include="FactoriesForStatements\RDomReturnStatement.cs" />
+ <Compile Include="Factories\RDomAccessor.cs" />
+ <Compile Include="Factories\RDomClass.cs" />
+ <Compile Include="Factories\RDomEnum.cs" />
+ <Compile Include="Factories\RDomField.cs" />
+ <Compile Include="Factories\RDomInterface.cs" />
+ <Compile Include="Factories\RDomMethod.cs" />
+ <Compile Include="Factories\RDomNamespace.cs" />
+ <Compile Include="Factories\RDomParameter.cs" />
+ <Compile Include="Factories\RDomProperty.cs" />
+ <Compile Include="Factories\RDomReferencedType.cs" />
+ <Compile Include="Factories\RDomRoot.cs" />
+ <Compile Include="Factories\RDomStructure.cs" />
+ <Compile Include="Factories\RDomUsing.cs" />
<Compile Include="Implementations\RDomAttributeValue.cs" />
<Compile Include="Implementations\RDomAttribute.cs" />
<Compile Include="Implementations\RDomClass.cs" />
View
38 RoslynDom/StatementImplementations/RDomAssignmentStatement.cs
@@ -8,44 +8,6 @@
namespace RoslynDom
{
- public class RDomAssignmentStatementFactory
- : RDomStatementFactory<RDomAssignmentStatement, ExpressionStatementSyntax>
- {
- public override void InitializeItem(RDomAssignmentStatement newItem, ExpressionStatementSyntax syntax)
- {
- var binary = syntax.Expression as BinaryExpressionSyntax;
- if (binary == null) throw new InvalidOperationException();
- // TODO: handle all the other kinds of assigments here (like +=)
- if (binary.CSharpKind() != SyntaxKind.SimpleAssignmentExpression) { throw new NotImplementedException(); }
- var left = binary.Left;
- var identifier = left as IdentifierNameSyntax;
- if (identifier == null) throw new InvalidOperationException();
- var right = binary.Right;
- var expression = right as ExpressionSyntax;
- if (expression == null) throw new InvalidOperationException();
- newItem.Name = identifier.ToString();
- newItem.Expression = RDomFactoryHelper.GetHelper<IExpression>().MakeItem(expression).FirstOrDefault();
- }
- public override IEnumerable<SyntaxNode> BuildSyntax(IStatement item)
- {
- var nameSyntax = SyntaxFactory.IdentifierName(item.Name);
- var itemAsT = item as IAssignmentStatement;
- var expressionSyntax = RDomFactory.BuildSyntax(itemAsT.Expression );
-
- var assignmentSyntax = SyntaxFactory.BinaryExpression(SyntaxKind.SimpleAssignmentExpression, nameSyntax, (ExpressionSyntax)expressionSyntax);
- var node = SyntaxFactory.ExpressionStatement(assignmentSyntax );
- return new SyntaxNode[] { RoslynUtilities.Format(node) };
-
- }
- public override bool CanCreateFrom(SyntaxNode syntaxNode)
- {
- var statement = syntaxNode as ExpressionStatementSyntax;
- if (statement == null) { return false; }
- return statement.Expression.CSharpKind() == SyntaxKind.SimpleAssignmentExpression;
- }
- }
-
-
public class RDomAssignmentStatement : RDomBase<IAssignmentStatement, ExpressionStatementSyntax, ISymbol>, IAssignmentStatement
{
View
26 RoslynDom/StatementImplementations/RDomBlockStatement.cs
@@ -7,32 +7,6 @@
namespace RoslynDom
{
- public class RDomBlockStatementFactory
- : RDomStatementFactory<RDomBlockStatement, BlockSyntax>
- {
- public override void InitializeItem(RDomBlockStatement newItem, BlockSyntax syntax)
- {
- foreach (var statementSyntax in syntax.Statements)
- {
- var statements = RDomFactoryHelper.GetHelper<IStatement>().MakeItem(statementSyntax);
- foreach (var statement in statements)
- { newItem.AddOrMoveStatement(statement); }
- }
- }
- public override IEnumerable<SyntaxNode> BuildSyntax(IStatement item)
- {
- var itemAsT = item as IBlockStatement;
-
- var statementSyntaxList = itemAsT.Statements
- .SelectMany(x => RDomFactory.BuildSyntaxGroup(x))
- .ToList();
- var node = SyntaxFactory.Block(SyntaxFactory.List(statementSyntaxList));
- return new SyntaxNode[] { node.NormalizeWhitespace() };
-
- }
- }
-
-
public class RDomBlockStatement : RDomBase<IBlockStatement, BlockSyntax, ISymbol>, IBlockStatement
{
private IList<IStatement> _statements = new List<IStatement>();
View
66 RoslynDom/StatementImplementations/RDomDeclarationStatement.cs
@@ -9,71 +9,7 @@
namespace RoslynDom
{
- public class RDomDeclarationStatementFactory
- : RDomStatementFactory<RDomDeclarationStatement, VariableDeclaratorSyntax>
- {
- public override bool CanCreateFrom(SyntaxNode syntaxNode)
- {
- return syntaxNode is LocalDeclarationStatementSyntax;
- }
-
- public override IEnumerable<IStatement> CreateFrom(SyntaxNode syntaxNode)
- {
- var list = new List<IStatement>();
- // We can't do this in the constructor, because many may be created and we want to flatten
- var rawDeclaration = syntaxNode as LocalDeclarationStatementSyntax;
- var rawVariableDeclaration = rawDeclaration.Declaration;
- var declarators = rawDeclaration.Declaration.Variables.OfType<VariableDeclaratorSyntax>();
- foreach (var decl in declarators)
- {
- var newItem = new RDomDeclarationStatement( decl);
- list.Add(newItem);
- InitializeItem(newItem, decl);
- }
- return list;
- }
-
- public override void InitializeItem(RDomDeclarationStatement newItem, VariableDeclaratorSyntax syntax)
- {
- newItem.Name = newItem.TypedSymbol.Name;
- var declaration = syntax.Parent as VariableDeclarationSyntax;
- if (declaration == null) throw new InvalidOperationException();
- newItem.IsImplicitlyTyped = (declaration.Type.ToString() == "var");
- var typeSymbol = ((ILocalSymbol)newItem.TypedSymbol).Type;
- newItem.Type = new RDomReferencedType(newItem.TypedSymbol.DeclaringSyntaxReferences, typeSymbol);
- if (syntax.Initializer != null)
- {
- var equalsClause = syntax.Initializer;
- newItem.Initializer = RDomFactoryHelper.GetHelper<IExpression>().MakeItem(equalsClause.Value).FirstOrDefault();
- }
-
- }
-
- public override IEnumerable<SyntaxNode> BuildSyntax(IStatement item)
- {
- var itemAsT = item as IDeclarationStatement;
- var nameSyntax = SyntaxFactory.Identifier(item.Name);
- TypeSyntax typeSyntax;
- // TODO: Type alias are not currently being used. Could be brute forced here, but I'd rather run a simplifier for real world scenarios
- if (itemAsT.IsImplicitlyTyped)
- { typeSyntax = SyntaxFactory.IdentifierName("var"); }
- else
- { typeSyntax = (TypeSyntax)(RDomFactory.BuildSyntax(itemAsT.Type)); }
- var nodeDeclarator = SyntaxFactory.VariableDeclarator(item.Name);
- if (itemAsT.Initializer != null)
- {
- var expressionSyntax = RDomFactory.BuildSyntax(itemAsT.Initializer);
- nodeDeclarator = nodeDeclarator.WithInitializer(SyntaxFactory.EqualsValueClause((ExpressionSyntax)expressionSyntax));
- }
- var nodeDeclaratorInList = SyntaxFactory.SeparatedList(SyntaxFactory.List<VariableDeclaratorSyntax>(new VariableDeclaratorSyntax[] { (VariableDeclaratorSyntax)nodeDeclarator }));
- var nodeDeclaration = SyntaxFactory.VariableDeclaration(typeSyntax, nodeDeclaratorInList);
- var node = SyntaxFactory.LocalDeclarationStatement(nodeDeclaration);
- return new SyntaxNode[] { RoslynUtilities.Format(node) };
- }
- }
-
-
- public class RDomDeclarationStatement : RDomBase<IDeclarationStatement, VariableDeclaratorSyntax, ISymbol>, IDeclarationStatement
+ public class RDomDeclarationStatement : RDomBase<IDeclarationStatement, VariableDeclaratorSyntax, ISymbol>, IDeclarationStatement
{
internal RDomDeclarationStatement(VariableDeclaratorSyntax rawItem)
: base(rawItem)
View
144 RoslynDom/StatementImplementations/RDomIfStatement.cs
@@ -8,150 +8,6 @@
namespace RoslynDom
{
- public class RDomIfStatementFactory
- : RDomStatementFactory<RDomIfStatement, IfStatementSyntax>
- {
- public override void InitializeItem(RDomIfStatement newItem, IfStatementSyntax syntax)
- {
- newItem.Condition = RDomFactoryHelper.GetHelper<IExpression>().MakeItem(syntax.Condition).FirstOrDefault();
- if (syntax.Condition == null) { throw new InvalidOperationException(); }
- bool hasBlock = false;
- var statements = GetStatementsFromSyntax(newItem.TypedSyntax.Statement, ref hasBlock);
- newItem.HasBlock = hasBlock;
- foreach (var statement in statements)
- { newItem.AddOrMoveStatement(statement); }
-
- InitializeElse(newItem, syntax);
- }
-
- private void InitializeElse(RDomIfStatement newItem, IfStatementSyntax syntax)
- {
- if (syntax.Else == null) return;
- var elseAsIf = syntax.Else.Statement as IfStatementSyntax;
- if (elseAsIf == null)
- {
- InitializeElseStatement(newItem, syntax,syntax.Else.Statement);
- }
- else
- {
- // Recurse this down the if chain
- var newIf = new RDomIfStatement(elseAsIf);
- InitializeItem(newIf, elseAsIf);
- var elseIfs = newIf.ElseIfs;
- var elseStatements = newIf.ElseStatements;
- //foreach (var item in newIf.ElseIfs) { newIf.RemoveElseIf(item); }
- //foreach (var item in newIf.ElseStatements) { newIf.RemoveElseStatement(item); }
- newItem. AddOrMoveElseIf(newIf);
- if (!newIf.ElseIfs.Any())
- {
- // this should move them
- foreach (var elseif in elseIfs)
- { newItem.AddOrMoveElseIf(elseif); } // Don't need to copy as we are trashing original
- if (elseStatements.Any())
- {
- newItem.ElseHasBlock = newIf.ElseHasBlock;
- foreach (var statement in elseStatements)
- { newItem.AddOrMoveElseStatement(statement); }
- }
- }
- }
- }
-
- private void InitializeElseStatement(RDomIfStatement newItem, IfStatementSyntax syntax,StatementSyntax statement)
- {
- newItem.ElseHasBlock = statement is BlockSyntax;
- bool hasBlock = false;
- var statements = GetStatementsFromSyntax(syntax.Else.Statement, ref hasBlock);
- newItem.ElseHasBlock = hasBlock;
- foreach (var state in statements)
- { newItem.AddOrMoveElseStatement(state); }
- }
-
- private IEnumerable<IStatement> GetStatementsFromSyntax(StatementSyntax statementSyntax, ref bool hasBlock)
- {
- var statement = RDomFactoryHelper.GetHelper<IStatement>().MakeItem(statementSyntax).First();
- var list = new List<IStatement>();
- var blockStatement = statement as IBlockStatement;
- if (blockStatement != null)
- {
- hasBlock = true;
- foreach (var state in blockStatement.Statements)
- {
- // Don't need to copy because abandoning block
- list.Add(state);
- }
- }
- else
- { list.Add(statement); }
- return list;
- }
-
- public override IEnumerable<SyntaxNode> BuildSyntax(IStatement item)
- {
- var node = BuildSyntax(item, true);
- return new SyntaxNode[] { RoslynUtilities.Format(node) };
- }
-
- private SyntaxNode BuildSyntax(IStatement item, bool isIfRoot)
- {
- var itemAsT = item as IIfStatement;
- var elseSyntax = BuildElseSyntax(itemAsT.ElseIfs, itemAsT.ElseStatements, itemAsT.ElseHasBlock);
-
- return BuildSyntax(item, isIfRoot, elseSyntax);
- }
-
- private SyntaxNode BuildSyntax(IStatement item, bool isIfRoot, ElseClauseSyntax elseClauseSyntax)
- {
- var itemAsT = item as IIfStatement;
-
- if (itemAsT.Condition == null) return SyntaxFactory.EmptyStatement(); // This shold not happen
-
- var statement = BuildStatement(itemAsT.Statements, itemAsT.HasBlock);
- var condition = RDomFactory.BuildSyntax(itemAsT.Condition);
- var node = SyntaxFactory.IfStatement((ExpressionSyntax)condition, statement);
-
- if (elseClauseSyntax != null) { node = node.WithElse(elseClauseSyntax); }
-
- return node;
- }
-
- private StatementSyntax BuildStatement(IEnumerable<IStatement> statements, bool hasBlock)
- {
- StatementSyntax statement;
- var statementSyntaxList = statements
- .SelectMany(x => RDomFactory.BuildSyntaxGroup(x))
- .ToList();
- if (hasBlock || statements.Count() > 1)
- { statement = SyntaxFactory.Block(SyntaxFactory.List(statementSyntaxList)); }
- else if (statements.Count() == 1)
- { statement = (StatementSyntax)statementSyntaxList.First(); }
- else
- { statement = SyntaxFactory.EmptyStatement(); }
- return statement;
- }
-
- private ElseClauseSyntax BuildElseSyntax(IEnumerable<IIfStatement> elseIfs, IEnumerable<IStatement> elseStatements, bool elseHasBlock)
- {
- // Because we reversed the list, inner is first, inner to outer required for this approach
- elseIfs = elseIfs.Reverse();
- ElseClauseSyntax elseClause = null;
- if (elseStatements.Any())
- { elseClause = SyntaxFactory.ElseClause(BuildStatement(elseStatements, elseHasBlock)); }
- foreach (var nestedIf in elseIfs)
- {
- var statement = BuildStatement(nestedIf.Statements, nestedIf.HasBlock);
- // No need to go back to factory, as it would just return us here
- ElseClauseSyntax newElseClause;
-
- var newIfClause = BuildSyntax(nestedIf, false, elseClause);
- newElseClause = SyntaxFactory.ElseClause((StatementSyntax)newIfClause);
- elseClause = newElseClause;
- }
- return elseClause;
- }
- }
-
-
public class RDomIfStatement : RDomBase<IIfStatement, IfStatementSyntax, ISymbol>, IIfStatement
{
private IList<IIfStatement> _elses = new List<IIfStatement>();
View
30 RoslynDom/StatementImplementations/RDomInvocationStatement.cs
@@ -8,36 +8,6 @@
namespace RoslynDom
{
- public class RDomInvocationStatementFactory
- : RDomStatementFactory<RDomInvocationStatement, ExpressionStatementSyntax>
- {
- public override void InitializeItem(RDomInvocationStatement newItem, ExpressionStatementSyntax syntax)
- {
- var expression = syntax.Expression;
- newItem.Invocation = RDomFactoryHelper.GetHelper<IExpression>().MakeItem(expression).FirstOrDefault();
- }
-
- public override IEnumerable<SyntaxNode> BuildSyntax(IStatement item)
- {
- var itemAsT = item as IInvocationStatement;
- var expressionSyntax = RDomFactory.BuildSyntax(itemAsT.Invocation);
- var node = SyntaxFactory.ExpressionStatement((ExpressionSyntax)expressionSyntax);
- return new SyntaxNode[] { RoslynUtilities.Format(node) };
-
- }
-
- public override FactoryPriority Priority
- {
- get { return FactoryPriority.Normal - 1; }
- }
-
- public override bool CanCreateFrom(SyntaxNode syntaxNode)
- {
- return syntaxNode is ExpressionStatementSyntax;
- }
- }
-
-
public class RDomInvocationStatement : RDomBase<IInvocationStatement, ExpressionStatementSyntax, ISymbol>, IInvocationStatement
{
View
25 RoslynDom/StatementImplementations/RDomReturnStatement.cs
@@ -10,31 +10,6 @@
namespace RoslynDom
{
- public class RDomReturnStatementFactory
- : RDomStatementFactory<RDomReturnStatement, ReturnStatementSyntax>
- {
- public override void InitializeItem(RDomReturnStatement newItem, ReturnStatementSyntax syntax)
- {
- if (syntax.Expression != null)
- {
- newItem.Return = RDomFactoryHelper.GetHelper<IExpression>().MakeItem(syntax.Expression).FirstOrDefault();
- if (newItem.Return == null) throw new InvalidOperationException();
- }
- }
-
- public override IEnumerable<SyntaxNode> BuildSyntax(IStatement item)
- {
- var itemAsT = item as IReturnStatement;
- var node = SyntaxFactory.ReturnStatement();
- if (itemAsT.Return != null)
- {
- var returnExpressionSyntax = RDomFactory.BuildSyntax(itemAsT.Return);
- node = node.WithExpression((ExpressionSyntax)returnExpressionSyntax);
- }
- return new SyntaxNode[] { RoslynUtilities.Format(node) };
- }
- }
-
public class RDomReturnStatement : RDomBase<IReturnStatement, ReturnStatementSyntax, ISymbol>, IReturnStatement
{
View
18 RoslynDomCSharpFactories/RoslynDomCSharpFactories.csproj
@@ -61,27 +61,9 @@
<Compile Include="RDomFactory.cs" />
<Compile Include="RoslynDomCSharpUtilities.cs" />
<Compile Include="RoslynCSharpUtilities.cs" />
- <Compile Include="StructureFactories\RDomAccessor.cs" />
- <Compile Include="StatementFactories\RDomAssignmentStatement.cs" />
<Compile Include="BaseFactories\RDomBaseItemFactory.cs" />
<Compile Include="BaseFactories\RDomBaseFactoryHelper.cs" />
- <Compile Include="StatementFactories\RDomBlockStatement.cs" />
- <Compile Include="StructureFactories\RDomClass.cs" />
- <Compile Include="StatementFactories\RDomDeclarationStatement.cs" />
- <Compile Include="StructureFactories\RDomEnum.cs" />
<Compile Include="BaseFactories\RDomExpression.cs" />
- <Compile Include="StructureFactories\RDomField.cs" />
- <Compile Include="StatementFactories\RDomIfStatement.cs" />
- <Compile Include="StructureFactories\RDomInterface.cs" />
- <Compile Include="StatementFactories\RDomInvocationStatement.cs" />
- <Compile Include="StructureFactories\RDomMethod.cs" />
- <Compile Include="StructureFactories\RDomNamespace.cs" />
- <Compile Include="StructureFactories\RDomProperty.cs" />
- <Compile Include="StructureFactories\RDomReferencedType.cs" />
- <Compile Include="StatementFactories\RDomReturnStatement.cs" />
- <Compile Include="StructureFactories\RDomRoot.cs" />
- <Compile Include="StructureFactories\RDomStructure.cs" />
- <Compile Include="StructureFactories\RDomUsing.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />

0 comments on commit f227e60

Please sign in to comment.
Something went wrong with that request. Please try again.