Permalink
Browse files

Factory move-stage 1 complete

  • Loading branch information...
1 parent 13dd468 commit e1f76ab0225300a5ae08f312f0b6e9155a070e33 Kathleen Dollard committed Jul 16, 2014
Showing with 470 additions and 600 deletions.
  1. +6 −0 RoslynDom.sln
  2. +0 −219 RoslynDom/BasesAndBaseHelpers/RDomBaseFactoryHelper.cs
  3. +1 −1 RoslynDom/BasesAndBaseHelpers/RDomBaseOfT.cs
  4. +1 −1 RoslynDom/BasesAndBaseHelpers/RDomBaseTTSyntaxTSymbol.cs
  5. +0 −13 RoslynDom/IRDomCanLoad.cs
  6. +0 −29 RoslynDom/IRDomContainers.cs
  7. +0 −59 RoslynDom/IRDomFactory.cs
  8. +0 −23 RoslynDom/IRoslynDom.cs
  9. +1 −1 RoslynDom/Implementations/RDomAccessor.cs
  10. +1 −1 RoslynDom/Implementations/RDomClass.cs
  11. +1 −1 RoslynDom/Implementations/RDomInterface.cs
  12. +2 −2 RoslynDom/Implementations/RDomMethod.cs
  13. +2 −2 RoslynDom/Implementations/RDomNamespace.cs
  14. +2 −2 RoslynDom/Implementations/RDomProperty.cs
  15. +2 −2 RoslynDom/Implementations/RDomReferencedType.cs
  16. +2 −2 RoslynDom/Implementations/RDomRoot.cs
  17. +1 −1 RoslynDom/Implementations/RDomStructure.cs
  18. +12 −15 RoslynDom/PublicAnnotationFactory.cs
  19. +3 −2 RoslynDom/RDomFactory.cs
  20. +43 −0 RoslynDom/RegisterCSharpFactories.cs
  21. +5 −7 RoslynDom/RoslynDom.csproj
  22. +12 −11 RoslynDom/RoslynDomUtilities.cs
  23. +31 −32 RoslynDom/RoslynUtilities.cs
  24. +1 −1 RoslynDom/StatementImplementations/RDomAssignmentStatement.cs
  25. +1 −1 RoslynDom/StatementImplementations/RDomBlockStatement.cs
  26. +1 −1 RoslynDom/StatementImplementations/RDomDeclarationStatement.cs
  27. +2 −2 RoslynDom/StatementImplementations/RDomIfStatement.cs
  28. +1 −1 RoslynDom/StatementImplementations/RDomInvocationStatement.cs
  29. +1 −1 RoslynDom/StatementImplementations/RDomReturnStatement.cs
  30. +1 −1 RoslynDomCSharpFactories/BaseFactories/RDomBaseFactoryHelper.cs
  31. +17 −20 RoslynDomCSharpFactories/BaseFactories/{RDomBaseFactory.cs → RDomBaseItemFactory.cs}
  32. +1 −1 RoslynDomCSharpFactories/BaseFactories/RDomExpression.cs
  33. +82 −0 RoslynDomCSharpFactories/RDomFactory.cs
  34. +1 −1 RoslynDomCSharpFactories/RoslynCSharpUtilities.cs
  35. +9 −4 RoslynDomCSharpFactories/RoslynDomCSharpFactories.csproj
  36. +1 −1 RoslynDomCSharpFactories/RoslynDomCSharpUtilities.cs
  37. +1 −1 RoslynDomCSharpFactories/StatementFactories/RDomAssignmentStatement.cs
  38. +1 −1 RoslynDomCSharpFactories/StatementFactories/RDomBlockStatement.cs
  39. +1 −1 RoslynDomCSharpFactories/StatementFactories/RDomDeclarationStatement.cs
  40. +1 −1 RoslynDomCSharpFactories/StatementFactories/RDomIfStatement.cs
  41. +1 −1 RoslynDomCSharpFactories/StatementFactories/RDomInvocationStatement.cs
  42. +1 −1 RoslynDomCSharpFactories/StatementFactories/RDomReturnStatement.cs
  43. +1 −1 RoslynDomCSharpFactories/StructureFactories/RDomAccessor.cs
  44. +1 −1 RoslynDomCSharpFactories/StructureFactories/RDomClass.cs
  45. +1 −1 RoslynDomCSharpFactories/StructureFactories/RDomEnum.cs
  46. +1 −1 RoslynDomCSharpFactories/StructureFactories/RDomField.cs
  47. +1 −1 RoslynDomCSharpFactories/StructureFactories/RDomInterface.cs
  48. +1 −1 RoslynDomCSharpFactories/StructureFactories/RDomMethod.cs
  49. +1 −1 RoslynDomCSharpFactories/StructureFactories/RDomNamespace.cs
  50. +1 −1 RoslynDomCSharpFactories/StructureFactories/RDomProperty.cs
  51. +1 −1 RoslynDomCSharpFactories/StructureFactories/RDomReferencedType.cs
  52. +1 −1 RoslynDomCSharpFactories/StructureFactories/RDomRoot.cs
  53. +1 −1 RoslynDomCSharpFactories/StructureFactories/RDomStructure.cs
  54. +1 −1 RoslynDomCSharpFactories/StructureFactories/RDomUsing.cs
  55. +6 −1 RoslynDomCommon/RoslynDomCommon.csproj
  56. +34 −16 RoslynDomRDomCommon/FactoryProvider.cs
  57. +3 −3 {RoslynDom/BasesAndBaseHelpers → RoslynDomRDomCommon}/RDomBase.cs
  58. +88 −89 RoslynDomRDomCommon/RDomBaseFactoryHelper.cs
  59. +42 −0 RoslynDomRDomCommon/RDomList.cs
  60. +3 −2 RoslynDomRDomCommon/RoslynDomRDomCommon.csproj
  61. +1 −1 RoslynDomRDomCommon/{RoslynUtilities.cs → RoslynRDomUtilities.cs}
  62. +4 −0 RoslynDomTests/RoslynDomTests.csproj
  63. +24 −9 RoslynDomUtilities/ReflectionUtilities.cs
View
@@ -15,6 +15,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RoslynDomCommon", "RoslynDo
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RoslynDomExampleTests", "RoslynDomExampleTests\RoslynDomExampleTests.csproj", "{2ADA8185-732B-48EA-A8E4-F1506D8A8C30}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RoslynDomRDomCommon", "RoslynDomRDomCommon\RoslynDomRDomCommon.csproj", "{1E5B8601-B717-471D-A9EE-0C03D15491A5}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -45,6 +47,10 @@ Global
{2ADA8185-732B-48EA-A8E4-F1506D8A8C30}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2ADA8185-732B-48EA-A8E4-F1506D8A8C30}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2ADA8185-732B-48EA-A8E4-F1506D8A8C30}.Release|Any CPU.Build.0 = Release|Any CPU
+ {1E5B8601-B717-471D-A9EE-0C03D15491A5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {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
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -1,219 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Diagnostics.Contracts;
-using System.Linq;
-using System.Reflection;
-using Microsoft.CodeAnalysis;
-using Microsoft.CodeAnalysis.CSharp;
-using Microsoft.CodeAnalysis.CSharp.Syntax;
-using Microsoft.Practices.Unity;
-using RoslynDom.Common;
-
-namespace RoslynDom
-{
- // Factories are specific to the type, FactoryHelpers are specific to the level (StemMember, TypeMember, Statement, Expression)
-
- public abstract class RDomFactoryHelper
- {
- private static FactoryProvider factoryProvider = new FactoryProvider();
- private static IRDomFactory<PublicAnnotation> publicAnnotationFactory;
- private static RDomRootFactoryHelper rootFactoryHelper;
- private static RDomStemMemberFactoryHelper stemMemberFactoryHelper;
- private static RDomTypeMemberFactoryHelper typeMemberFactoryHelper;
- private static RDomStatementFactoryHelper statementFactoryHelper;
- private static RDomExpressionFactoryHelper expressionFactoryHelper;
- private static RDomMiscFactoryHelper miscFactoryHelper;
-
- public static void Initialize()
- {
- publicAnnotationFactory = factoryProvider.GetPublicAnnotationFactory();
- }
-
- public static RDomRootFactoryHelper RootFactoryHelper
- {
- get
- {
- if (rootFactoryHelper == null) { rootFactoryHelper = new RDomRootFactoryHelper(); }
- return rootFactoryHelper;
- }
- }
- public static RDomStemMemberFactoryHelper StemMemberFactoryHelper
- {
- get
- {
- if (stemMemberFactoryHelper == null) { stemMemberFactoryHelper = new RDomStemMemberFactoryHelper(); }
- return stemMemberFactoryHelper;
- }
- }
- public static RDomTypeMemberFactoryHelper TypeMemberFactoryHelper
- {
- get
- {
- if (typeMemberFactoryHelper == null) { typeMemberFactoryHelper = new RDomTypeMemberFactoryHelper(); }
- return typeMemberFactoryHelper;
- }
- }
- public static RDomStatementFactoryHelper StatementFactoryHelper
- {
- get
- {
- if (statementFactoryHelper == null) { statementFactoryHelper = new RDomStatementFactoryHelper(); }
- return statementFactoryHelper;
- }
- }
- public static RDomExpressionFactoryHelper ExpressionFactoryHelper
- {
- get
- {
- if (expressionFactoryHelper == null) { expressionFactoryHelper = new RDomExpressionFactoryHelper(); }
- return expressionFactoryHelper;
- }
- }
- public static RDomMiscFactoryHelper MiscFactoryHelper
- {
- get
- {
- if (miscFactoryHelper == null) { miscFactoryHelper = new RDomMiscFactoryHelper(); }
- return miscFactoryHelper;
- }
- }
-
- public static RDomFactoryHelper GetHelper<TKind>()
- {
- if (typeof(TKind) == typeof(IRoot)) { return RootFactoryHelper; }
- if (typeof(TKind) == typeof(IStemMember)) { return StemMemberFactoryHelper; }
- if (typeof(TKind) == typeof(ITypeMember)) { return TypeMemberFactoryHelper; }
- if (typeof(TKind) == typeof(IStatement)) { return StatementFactoryHelper; }
- if (typeof(TKind) == typeof(IExpression)) { return ExpressionFactoryHelper; }
- if (typeof(TKind) == typeof(IMisc)) { return MiscFactoryHelper; }
- throw new InvalidOperationException();
- }
-
- public static IEnumerable<PublicAnnotation> GetPublicAnnotations(SyntaxNode syntaxNode)
- {
- if (publicAnnotationFactory == null) Initialize();
- return publicAnnotationFactory.CreateFrom(syntaxNode);
- }
-
- protected static IEnumerable<IRDomFactory<T>> GetFactories<T>()
- {
- return factoryProvider.GetFactories<T>();
- }
-
- public abstract SyntaxNode BuildSyntax(IDom item);
- public abstract IEnumerable<SyntaxNode> BuildSyntaxGroup(IDom item);
-
- }
-
- public abstract class RDomFactoryHelper<T> : RDomFactoryHelper
- {
- private IEnumerable<IRDomFactory<T>> factories;
- private IRDomFactory<T> genericFactory;
- private IEnumerable<Tuple<IRDomFactory<T>, Type, Type>> factoryLookup;
-
- protected IEnumerable<IRDomFactory<T>> Factories
- {
- get
- {
- if (factories == null) { factories = GetFactories<T>(); }
- return factories;
- }
- }
-
- private IEnumerable<Tuple<IRDomFactory<T>, Type, Type>> FactoryLookup
- {
- get
- {
- if (factoryLookup == null)
- {
- var list = new List<Tuple<IRDomFactory<T>, Type, Type>>();
- foreach (var factory in Factories)
- {
- var newTuple = new Tuple<IRDomFactory<T>, Type, Type>
- (factory, GetSyntaxType(factory), GetTargetType(factory));
- list.Add(newTuple);
- }
- factoryLookup = list;
- }
- return factoryLookup;
- }
- }
-
- private Type GetSyntaxType(IRDomFactory<T> factory)
- {
- var factoryType = factory.GetType();
- var syntaxType = RoslynDomUtilities.FindFirstSyntaxNodeType(factoryType);
- return syntaxType;
- }
-
- private Type GetTargetType(IRDomFactory<T> factory)
- {
- var factoryType = factory.GetType();
- var syntaxType = RoslynDomUtilities.FindFirstIDomType(factoryType);
- return syntaxType;
- }
-
-
- protected IRDomFactory<T> GetFactory(T item)
- {
- var type = item.GetType();
- var found = FactoryLookup.Where(x => x.Item3 == type).FirstOrDefault();
- return found.Item1;
- }
-
- }
-
- public abstract class RDomFactoryHelper<T, TSyntax> : RDomFactoryHelper<T>
- where T : class
- where TSyntax : SyntaxNode
- {
- public IEnumerable<T> MakeItem(TSyntax rawStatement)
- {
- var factories = Factories.OrderByDescending(x => x.Priority).ToArray();
- foreach (var factory in factories)
- {
- if (factory.CanCreateFrom(rawStatement))
- {
- return factory.CreateFrom(rawStatement);
- }
- }
- return null;
- }
-
- public override IEnumerable<SyntaxNode> BuildSyntaxGroup(IDom item)
- {
- if (item == null) return null;
- var itemAsT = item as T;
- if (itemAsT == null) throw new InvalidOperationException();
- var factory = GetFactory(itemAsT);
- return factory.BuildSyntax(itemAsT);
- }
-
- public override SyntaxNode BuildSyntax(IDom item)
- {
- return BuildSyntaxGroup(item).Single();
- }
- }
-
- public class RDomRootFactoryHelper : RDomFactoryHelper<IRoot, CompilationUnitSyntax>
- { internal RDomRootFactoryHelper() { } }
-
- public class RDomStemMemberFactoryHelper : RDomFactoryHelper<IStemMember, SyntaxNode>
- { internal RDomStemMemberFactoryHelper() { } }
-
-
- public class RDomTypeMemberFactoryHelper : RDomFactoryHelper<ITypeMember, MemberDeclarationSyntax>
- { internal RDomTypeMemberFactoryHelper() { } }
-
-
- public class RDomStatementFactoryHelper : RDomFactoryHelper<IStatement, StatementSyntax>
- { internal RDomStatementFactoryHelper() { } }
-
-
- public class RDomExpressionFactoryHelper : RDomFactoryHelper<IExpression, ExpressionSyntax>
- { internal RDomExpressionFactoryHelper() { } }
-
- public class RDomMiscFactoryHelper : RDomFactoryHelper<IMisc, SyntaxNode>
- { internal RDomMiscFactoryHelper() { } }
-
-}
@@ -39,7 +39,7 @@ public virtual T Copy()
return (T)newItem;
}
- internal override bool SameIntentInternal<TLocal>(TLocal other, bool includePublicAnnotations)
+ protected override bool SameIntentInternal<TLocal>(TLocal other, bool includePublicAnnotations)
{
if (!CheckSameIntent(other as T, includePublicAnnotations)) { return false; }
return sameIntent.SameIntent(this as T, other as T, includePublicAnnotations);
@@ -167,7 +167,7 @@ private MetadataReference Mscorlib
}
}
- internal override ISymbol GetSymbol(SyntaxNode node)
+ protected override ISymbol GetSymbol(SyntaxNode node)
{
var model = GetModel();
var symbol = (TSymbol)model.GetDeclaredSymbol(node);
View
@@ -1,13 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace RoslynDom
-{
- internal interface IRDomCanLoad
- {
-
- }
-}
@@ -1,29 +0,0 @@
-using System.Collections.Generic;
-using RoslynDom.Common;
-
-namespace RoslynDom
-{
- public interface IRDomStemContainer :IStemContainer
- {
- void AddOrMoveStemMember(IStemMember member);
- void RemoveStemMember(IStemMember member);
- void ClearStemMembers();
- }
-
- public interface IRDomTypeMemberContainer :ITypeMemberContainer
- {
- void AddOrMoveMember(ITypeMember member);
- void RemoveMember(ITypeMember member);
- void ClearMembers();
- void AddOrMoveTypeParameter(ITypeParameter typeParameter);
- void RemoveTypeParameter(ITypeParameter typeParameter);
- void ClearTypeParameters();
- }
-
- public interface IRDomCodeContainer : ICodeContainer
- {
- void AddOrMoveStatement(IStatement member);
- void RemoveStatement(IStatement member);
- void ClearStatements();
- }
-}
View
@@ -1,59 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using Microsoft.CodeAnalysis;
-using RoslynDom.Common;
-
-namespace RoslynDom
-{
- public interface IRDomFactory<TKind> :IRDomFactory
- {
- bool CanCreateFrom(SyntaxNode syntaxNode);
- IEnumerable<TKind> CreateFrom(SyntaxNode syntaxNode);
- FactoryPriority Priority { get; }
-
- IEnumerable<SyntaxNode> BuildSyntax(TKind item);
- }
-
- public interface IRDomFactory
- {
-
- }
-
- public interface IPublicAnnotationFactory : IRDomFactory<PublicAnnotation >
- { }
- //public class RDomFactory<TSyntax, TCreate, TFactory>
- // (CandidatePriority candidatePriority, CandidateKind candidateKind)
- // where TFactory : IRDomStatementFactory< TCreate >
- // where TCreate : IDom
- //{
- // // TCandidate should be IStatement, IExpression, IStemMember or ITypeMember, but this isn't currently enforced
- // public CandidatePriority CandidatePriority { get; } = candidatePriority;
- // public CandidateKind CandidateKind { get; } = candidateKind;
- //}
-
-
- /// <summary>
- /// Priority for candidate selection. These are for clarity. Please add your
- /// own in the format "Normal + 1"
- /// </summary>
- public enum FactoryPriority
- {
- None = 0,
- Fallback =100,
- Normal = 200,
- Top = 300
- }
-
- //public enum CandidateKind
- //{
- // Unknown = 0,
- // StemMember,
- // TypeMember,
- // Statement,
- // Expression
- //}
-
-}
View
@@ -1,23 +0,0 @@
-using Microsoft.CodeAnalysis;
-using RoslynDom.Common;
-
-namespace RoslynDom
-{
- public interface IRoslynDom : IDom
- {
- ISymbol Symbol { get; }
- void RemoveFromParent();
-
- }
-
- [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1005:AvoidExcessiveParametersOnGenericTypes")]
- public interface IRoslynDom<T, TSyntax, TSymbol> : IDom<T>
- where TSyntax : SyntaxNode
- where TSymbol : ISymbol
- where T : IDom<T>
- {
- TSymbol TypedSymbol { get; }
- TSyntax TypedSyntax { get; }
- }
-}
-
@@ -15,7 +15,7 @@ public override void InitializeItem(RDomPropertyAccessor newItem, AccessorDeclar
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); }
}
Oops, something went wrong.

0 comments on commit e1f76ab

Please sign in to comment.