Browse files

Outputting minimal info almost all features

  • Loading branch information...
1 parent 90e4b38 commit afd2ac58e657c1fa220713910307e729d8faada9 @KathleenDollard committed Jul 10, 2014
View
2 CreateNuGet.cmd
@@ -1,4 +1,4 @@
-set version=1.0.8-alpha
+set version=1.0.9-alpha
if not exist .\nuget_packages mkdir nuget_packages
del /Q .\nuget_packages\*.*
.nuget\NuGet.exe pack RoslynDOM\RoslynDom.csproj -IncludeReferencedProjects -OutputDirectory .\nuget_packages -Version %version% -symbols
View
68 RoslynDom/BasesAndBaseHelpers/RDomBaseStemContainer.cs
@@ -4,6 +4,7 @@
using System.Text;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
+using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using RoslynDom.Common;
@@ -42,7 +43,7 @@ internal RDomBaseStemContainer(T oldIDom)
{
//ordered in approx expectation of frequency
var rDomClass = member as RDomClass;
- if (rDomClass != null) { AddOrMoveStemMember (new RDomClass(rDomClass)); }
+ if (rDomClass != null) { AddOrMoveStemMember(new RDomClass(rDomClass)); }
else
{
var rDomStructure = member as RDomStructure;
@@ -61,8 +62,8 @@ internal RDomBaseStemContainer(T oldIDom)
if (rDomNamespace != null) { AddOrMoveStemMember(new RDomNamespace(rDomNamespace)); }
else
{
- var rDomUsing = member as RDomUsingDirective;
- if (rDomUsing != null) { AddOrMoveStemMember(new RDomUsingDirective(rDomUsing)); }
+ var rDomUsing = member as RDomUsing;
+ if (rDomUsing != null) { AddOrMoveStemMember(new RDomUsing(rDomUsing)); }
else
{
throw new InvalidOperationException();
@@ -80,6 +81,49 @@ protected override void Initialize()
base.Initialize();
}
+ protected SyntaxList<MemberDeclarationSyntax> BuildStemMembers()
+ {
+ var list = new List<MemberDeclarationSyntax>();
+ foreach (var member in StemMembers)
+ {
+ if (BuildStemMember(list, member)) { continue; }
+ if (member is RDomUsing) continue;
+ throw new InvalidOperationException();
+ }
+ return SyntaxFactory.List<SyntaxNode>(list);
+ }
+
+ protected virtual bool BuildStemMember(IList<MemberDeclarationSyntax> list, IStemMember member)
+ {
+ if (TryAddMemberSyntaxNode<RDomNamespace>(list, member, x => x.BuildSyntax())) { return true; }
+ if (TryAddMemberSyntaxNode<RDomClass>(list, member, x => x.BuildSyntax())) { return true; }
+ if (TryAddMemberSyntaxNode<RDomStructure>(list, member, x => x.BuildSyntax())) { return true; }
+ if (TryAddMemberSyntaxNode<RDomInterface>(list, member, x => x.BuildSyntax())) { return true; }
+ if (TryAddMemberSyntaxNode<RDomEnum>(list, member, x => x.BuildSyntax())) { return true; }
+ return false;
+ }
+
+ protected SyntaxList<UsingDirectiveSyntax> BuildUsings()
+ {
+ var list = new List<UsingDirectiveSyntax>();
+ if (Usings != null)
+ {
+ foreach (var member in Usings)
+ {
+ if (RoslynUtilities.TryAddSyntaxNode<IStemMember, UsingDirectiveSyntax, RDomUsing>(list, member, x => x.BuildSyntax())) { continue; };
+ throw new InvalidOperationException();
+ }
+ }
+ return SyntaxFactory.List<UsingDirectiveSyntax>(list);
+ }
+
+ protected bool TryAddMemberSyntaxNode<TRDom>(IList<MemberDeclarationSyntax> list, IStemMember member, Func<TRDom, MemberDeclarationSyntax> makeDelegate)
+ where TRDom : class
+ {
+ return RoslynUtilities.TryAddSyntaxNode<IStemMember, MemberDeclarationSyntax, TRDom>(list, member, makeDelegate);
+ }
+
+
public string Namespace
// Parent always works here - if its a namespace, we deliberately skip the current, otherwise, the current is never a namespace
{ get { return RoslynDomUtilities.GetNamespace(this.Parent); } }
@@ -103,23 +147,13 @@ public void AddOrMoveStemMember(IStemMember member)
}
public void ClearStemMembers()
- { _members.Clear(); }
+ { _members.Clear(); }
public IEnumerable<INamespace> AllChildNamespaces
- {
- get
- {
- return RoslynDomUtilities.GetAllChildNamespaces(this);
- }
- }
+ { get { return RoslynDomUtilities.GetAllChildNamespaces(this); } }
public IEnumerable<INamespace> NonemptyNamespaces
- {
- get
- {
- return RoslynDomUtilities.GetNonEmptyNamespaces(this);
- }
- }
+ { get { return RoslynDomUtilities.GetNonEmptyNamespaces(this); } }
public IEnumerable<IStemMember> StemMembers
{ get { return _members; } }
@@ -141,7 +175,7 @@ public IEnumerable<IEnum> Enums
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Usings")]
public IEnumerable<IUsing> Usings
- { get { return StemMembers.OfType<IUsing>(); } }
+ { get { return StemMembers.OfType<IUsing>().ToList(); } }
public IEnumerable<IType> Types
{ get { return StemMembers.OfType<IType>(); } }
View
11 RoslynDom/BasesAndBaseHelpers/RDomBaseTTSyntaxTSymbol.cs
@@ -57,7 +57,7 @@ public virtual TSyntax BuildSyntax()
protected SyntaxList<AttributeListSyntax> BuildAttributeListSyntax()
{
var list = SyntaxFactory.List<AttributeListSyntax>();
- if (_attributes.Any())
+ if (GetAttributes().Any())
{
var attribList = SyntaxFactory.AttributeList();
var attributes = _attributes.Select(x => ((RDomAttribute)x).BuildSyntax());
@@ -78,13 +78,12 @@ protected SyntaxTokenList BuildModfierSyntax()
return list;
}
- protected BlockSyntax BuildStatementBlock()
+ protected BlockSyntax BuildStatementBlock(IEnumerable<IStatement> statements)
{
- var statements = new List<StatementSyntax>();
- var thisAsStatementContainer = this as IStatementContainer;
+ var statementSyntaxList = new List<StatementSyntax>();
- //f (thisAsStatementContainer.Statements.Count() == 0) { statements.Add(SyntaxFactory.EmptyStatement()); }
- var ret = SyntaxFactory.Block(statements);
+ //f (statementContainer.Statements.Count() == 0) { statements.Add(SyntaxFactory.EmptyStatement()); }
+ var ret = SyntaxFactory.Block(statementSyntaxList);
return ret;
}
View
36 RoslynDom/BasesAndBaseHelpers/RDomBaseType.cs
@@ -2,6 +2,8 @@
using System.Collections.Generic;
using System.Linq;
using Microsoft.CodeAnalysis;
+using Microsoft.CodeAnalysis.CSharp;
+using Microsoft.CodeAnalysis.CSharp.Syntax;
using RoslynDom.Common;
namespace RoslynDom
@@ -54,6 +56,38 @@ protected override void Initialize()
{ AddOrMoveTypeParameter(typeParameter); }
}
+ protected SyntaxList<MemberDeclarationSyntax> BuildMembers(bool nestedTypesAllowed)
+ {
+ var list = new List<MemberDeclarationSyntax>();
+ foreach (var member in Members)
+ {
+ if (!BuildMember(list, member, nestedTypesAllowed)) { throw new InvalidOperationException(); }
+ }
+ return SyntaxFactory.List<MemberDeclarationSyntax>(list);
+ }
+
+ protected virtual bool BuildMember(IList<MemberDeclarationSyntax> list, ITypeMember member, bool nestedTypesAllowed)
+ {
+ if (TryAddMemberSyntaxNode<RDomMethod>(list, member, x => x.BuildSyntax())) { return true; }
+ if (TryAddMemberSyntaxNode<RDomProperty>(list, member, x => x.BuildSyntax())) { return true; }
+ if (TryAddMemberSyntaxNode<RDomField>(list, member, x => x.BuildSyntax())) { return true; }
+ if (nestedTypesAllowed)
+ {
+ if (TryAddMemberSyntaxNode<RDomClass>(list, member, x => x.BuildSyntax())) { return true; }
+ if (TryAddMemberSyntaxNode<RDomStructure>(list, member, x => x.BuildSyntax())) { return true; }
+ if (TryAddMemberSyntaxNode<RDomInterface>(list, member, x => x.BuildSyntax())) { return true; }
+ if (TryAddMemberSyntaxNode<RDomEnum>(list, member, x => x.BuildSyntax())) { return true; }
+ }
+ return false;
+ }
+
+ protected bool TryAddMemberSyntaxNode<TRDom>(IList<MemberDeclarationSyntax> list, ITypeMember member, Func<TRDom, MemberDeclarationSyntax> makeDelegate)
+ where TRDom : class
+ {
+ return RoslynUtilities.TryAddSyntaxNode<ITypeMember, MemberDeclarationSyntax, TRDom>(list, member, makeDelegate);
+ }
+
+
public void RemoveMember(ITypeMember member)
{
if (member.Parent == null)
@@ -62,7 +96,7 @@ public void RemoveMember(ITypeMember member)
{ RoslynDomUtilities.RemoveMemberFromParent(this, member); }
}
- public void AddOrMoveMember(ITypeMember member)
+ public void AddOrMoveMember(ITypeMember member)
{
RoslynDomUtilities.PrepMemberForAdd(this, member);
_members.Add(member);
View
38 RoslynDom/Implementations/RDomClass.cs
@@ -36,39 +36,27 @@ internal RDomClass(RDomClass oldRDom)
protected override void Initialize()
{
base.Initialize();
- BaseType =new RDomReferencedType(TypedSymbol.DeclaringSyntaxReferences, TypedSymbol.BaseType);
+ BaseType = new RDomReferencedType(TypedSymbol.DeclaringSyntaxReferences, TypedSymbol.BaseType);
IsAbstract = Symbol.IsAbstract;
IsSealed = Symbol.IsSealed;
IsStatic = Symbol.IsStatic;
}
- public override ClassDeclarationSyntax BuildSyntax()
+ public override ClassDeclarationSyntax BuildSyntax()
{
var modifiers = BuildModfierSyntax();
- //var typeParameters = BuildTypeParameterList();
- //var constraintClauses = BuildConstraintClauses();
- var members = BuildMembers();
-
var node = SyntaxFactory.ClassDeclaration(Name)
- .WithModifiers(modifiers)
- .WithMembers(members);
- var attributesLists = BuildAttributeListSyntax();
- if (attributesLists.Any()) { node = node.WithAttributeLists(attributesLists); }
- return (ClassDeclarationSyntax)RoslynUtilities.Format(node);
- }
+ .WithModifiers(modifiers);
- private SyntaxList<MemberDeclarationSyntax> BuildMembers()
- {
- var list = SyntaxFactory.List<MemberDeclarationSyntax>();
- foreach (var member in Members)
- {
- var memberAsRDomMethod = member as RDomMethod;
- if (memberAsRDomMethod != null)
- { list = list.Add(memberAsRDomMethod.BuildSyntax()); }
- }
- return list;
+ node = RoslynUtilities.UpdateNodeIfListNotEmpty(BuildMembers(true), node, (n, l) => n.WithMembers(l));
+ //node = RoslynUtilities.UpdateNodeIfListNotEmpty(BuildTypeParameterList(), node, (n, l) => n.WithTypeParameters(l));
+ //node = RoslynUtilities.UpdateNodeIfListNotEmpty(BuildConstraintClauses(), node, (n, l) => n.WithTypeConstraints(l));
+ node = RoslynUtilities.UpdateNodeIfListNotEmpty(BuildAttributeListSyntax(), node, (n, l) => n.WithAttributeLists(l));
+
+ return (ClassDeclarationSyntax)RoslynUtilities.Format(node);
}
+
public IEnumerable<IClass> Classes
{ get { return Members.OfType<IClass>(); } }
@@ -101,9 +89,9 @@ public IEnumerable<IEnum> Enums
public bool IsStatic { get; set; }
-
- public IReferencedType BaseType { get;set; }
-
+
+ public IReferencedType BaseType { get; set; }
+
public IEnumerable<IReferencedType> ImplementedInterfaces
{
get
View
14 RoslynDom/Implementations/RDomEnum.cs
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using Microsoft.CodeAnalysis;
+using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using RoslynDom.Common;
@@ -35,7 +36,18 @@ protected override void Initialize()
}
}
- public IEnumerable<IAttribute> Attributes
+ public override EnumDeclarationSyntax BuildSyntax()
+ {
+ var modifiers = BuildModfierSyntax();
+ var node = SyntaxFactory.EnumDeclaration(Name)
+ .WithModifiers(modifiers);
+ // TODO: Support enum members
+ node = RoslynUtilities.UpdateNodeIfListNotEmpty(BuildAttributeListSyntax(), node, (n, l) => n.WithAttributeLists(l));
+
+ return (EnumDeclarationSyntax)RoslynUtilities.Format(node);
+ }
+
+ public IEnumerable<IAttribute> Attributes
{ get { return GetAttributes(); } }
public string Namespace
View
23 RoslynDom/Implementations/RDomField.cs
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using Microsoft.CodeAnalysis;
+using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using RoslynDom.Common;
@@ -46,11 +47,29 @@ protected override void Initialize()
IsStatic = Symbol.IsStatic;
}
+ public override FieldDeclarationSyntax BuildSyntax()
+ {
+ var nameSyntax = SyntaxFactory.Identifier(Name);
+ var returnType = ((RDomReferencedType)ReturnType).BuildSyntax();
+ var modifiers = BuildModfierSyntax();
+ var declaratorNode = SyntaxFactory.VariableDeclarator(nameSyntax);
+ var variableNode = SyntaxFactory.VariableDeclaration(returnType)
+ .WithVariables(
+ SyntaxFactory.SingletonSeparatedList<VariableDeclaratorSyntax>(
+ SyntaxFactory.VariableDeclarator(nameSyntax)));
+ var node = SyntaxFactory.FieldDeclaration(variableNode )
+ .WithModifiers(modifiers);
+
+ node = RoslynUtilities.UpdateNodeIfListNotEmpty(BuildAttributeListSyntax(), node, (n, list) => n.WithAttributeLists(list));
+
+ return (FieldDeclarationSyntax)RoslynUtilities.Format(node);
+ }
+
protected override bool CheckSameIntent(IField other, bool includePublicAnnotations)
{
if (!base.CheckSameIntent(other, includePublicAnnotations)) return false;
if (AccessModifier != other.AccessModifier) return false;
- if (ReturnType.QualifiedName != other.ReturnType.QualifiedName ) return false;
+ if (ReturnType.QualifiedName != other.ReturnType.QualifiedName) return false;
if (IsStatic != other.IsStatic) return false;
return true;
}
@@ -60,7 +79,7 @@ public IEnumerable<IAttribute> Attributes
public AccessModifier AccessModifier { get; set; }
- public override IFieldSymbol TypedSymbol
+ public override IFieldSymbol TypedSymbol
{ get { return (IFieldSymbol)base.GetSymbol(_varSyntax); } }
public IReferencedType ReturnType { get; set; }
View
17 RoslynDom/Implementations/RDomInterface.cs
@@ -1,4 +1,5 @@
using System.Collections.Generic;
+using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using RoslynDom.Common;
@@ -19,7 +20,21 @@ internal RDomInterface(RDomInterface oldRDom)
: base(oldRDom)
{ }
- public IEnumerable<IReferencedType> AllImplementedInterfaces
+ public override InterfaceDeclarationSyntax BuildSyntax()
+ {
+ var modifiers = BuildModfierSyntax();
+ var node = SyntaxFactory.InterfaceDeclaration(Name)
+ .WithModifiers(modifiers);
+
+ node = RoslynUtilities.UpdateNodeIfListNotEmpty(BuildMembers(false), node, (n, l) => n.WithMembers(l));
+ //node = RoslynUtilities.UpdateNodeIfListNotEmpty(BuildTypeParameterList(), node, (n, l) => n.WithTypeParameters(l));
+ //node = RoslynUtilities.UpdateNodeIfListNotEmpty(BuildConstraintClauses(), node, (n, l) => n.WithTypeConstraints(l));
+ node = RoslynUtilities.UpdateNodeIfListNotEmpty(BuildAttributeListSyntax(), node, (n, l) => n.WithAttributeLists(l));
+
+ return (InterfaceDeclarationSyntax)RoslynUtilities.Format(node);
+ }
+
+ public IEnumerable<IReferencedType> AllImplementedInterfaces
{
get
{
View
50 RoslynDom/Implementations/RDomMethod.cs
@@ -74,36 +74,18 @@ public override MethodDeclarationSyntax BuildSyntax()
var nameSyntax = SyntaxFactory.Identifier(Name);
var returnType = ((RDomReferencedType)ReturnType).BuildSyntax();
var modifiers = BuildModfierSyntax();
+ var node = SyntaxFactory.MethodDeclaration(returnType, nameSyntax)
+ .WithModifiers(modifiers);
+
+ node = RoslynUtilities.UpdateNodeIfListNotEmpty(BuildAttributeListSyntax(), node, (n, list) => n.WithAttributeLists(list));
+ node = RoslynUtilities.UpdateNodeIfItemNotNull (BuildStatementBlock(Statements), node, (n, item) => n.WithBody(item));
+ //var parameters = BuildParameterList();
//var typeParameters = BuildTypeParameterList();
//var constraintClauses = BuildConstraintClauses();
- var block = BuildStatementBlock();
- var node = SyntaxFactory.MethodDeclaration(returnType, nameSyntax)
- .WithModifiers(modifiers)
- .WithBody(block);
- var attributesLists = BuildAttributeListSyntax();
- if (attributesLists.Any()) { node = node.WithAttributeLists(attributesLists); }
return (MethodDeclarationSyntax)RoslynUtilities.Format(node);
}
-
- public void RemoveParameter(IParameter parameter)
- { _parameters.Remove(parameter); }
-
- public void AddParameter(IParameter parameter)
- { _parameters.Add (parameter); }
-
- public void RemoveTypeParameter(ITypeParameter typeParameter)
- { _typeParameters.Remove(typeParameter); }
-
- public void AddTypeParameter(ITypeParameter typeParameter)
- { _typeParameters.Add(typeParameter); }
-
- public void RemoveStatement(IStatement statement)
- { _statements .Remove(statement); }
-
- public void AddStatement(IStatement statement)
- { _statements.Add(statement); }
-
+
public IEnumerable<IAttribute> Attributes
{ get { return GetAttributes(); } }
@@ -117,12 +99,30 @@ public IEnumerable<IAttribute> Attributes
public bool IsExtensionMethod { get; set; }
+ public void RemoveTypeParameter(ITypeParameter typeParameter)
+ { _typeParameters.Remove(typeParameter); }
+
+ public void AddTypeParameter(ITypeParameter typeParameter)
+ { _typeParameters.Add(typeParameter); }
+
public IEnumerable<ITypeParameter> TypeParameters
{ get { return _typeParameters; } }
+ public void RemoveParameter(IParameter parameter)
+ { _parameters.Remove(parameter); }
+
+ public void AddParameter(IParameter parameter)
+ { _parameters.Add(parameter); }
+
public IEnumerable<IParameter> Parameters
{ get { return _parameters; } }
+ public void RemoveStatement(IStatement statement)
+ { _statements.Remove(statement); }
+
+ public void AddStatement(IStatement statement)
+ { _statements.Add(statement); }
+
public IEnumerable<IStatement> Statements
{ get { return _statements ; } }
View
13 RoslynDom/Implementations/RDomNamespace.cs
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using Microsoft.CodeAnalysis;
+using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using RoslynDom.Common;
@@ -35,14 +36,14 @@ protected override void Initialize()
if (Name.StartsWith("@")) { Name = Name.Substring(1); }
}
- public IEnumerable<INamespace> AllChildNamespaces
+ public override NamespaceDeclarationSyntax BuildSyntax()
{
- get { return RoslynDomUtilities.GetAllChildNamespaces(this); }
- }
+ var node = SyntaxFactory.NamespaceDeclaration (SyntaxFactory.IdentifierName(Name));
- public IEnumerable<INamespace> NonemptyNamespaces
- {
- get { return RoslynDomUtilities.GetNonEmptyNamespaces(this); }
+ node = RoslynUtilities.UpdateNodeIfListNotEmpty(BuildUsings(), node, (n, l) => n.WithUsings(l));
+ node = RoslynUtilities.UpdateNodeIfListNotEmpty(BuildStemMembers(), node, (n, l) => n.WithMembers(l));
+
+ return (NamespaceDeclarationSyntax)RoslynUtilities.Format(node);
}
public override string OuterName
View
64 RoslynDom/Implementations/RDomProperty.cs
@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using Microsoft.CodeAnalysis;
+using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using RoslynDom.Common;
@@ -10,6 +11,8 @@ namespace RoslynDom
public class RDomProperty : RDomBase<IProperty, PropertyDeclarationSyntax, IPropertySymbol>, IProperty
{
private IList<IParameter> _parameters = new List<IParameter>();
+ private IList<IStatement> _getStatements = new List<IStatement>();
+ private IList<IStatement> _setStatements = new List<IStatement>();
internal RDomProperty(
PropertyDeclarationSyntax rawItem,
@@ -61,11 +64,40 @@ protected override void Initialize()
CanSet = (!propSymbol.IsReadOnly); // or check whether setAccessor is null
}
- public void RemoveParameter(IParameter parameter)
- { _parameters.Remove(parameter); }
+ public override PropertyDeclarationSyntax BuildSyntax()
+ {
+ var nameSyntax = SyntaxFactory.Identifier(Name);
+ var returnType = ((RDomReferencedType)PropertyType).BuildSyntax();
+ var modifiers = BuildModfierSyntax();
+ var node = SyntaxFactory.PropertyDeclaration(returnType, nameSyntax)
+ .WithModifiers(modifiers);
+
+ node = RoslynUtilities.UpdateNodeIfListNotEmpty(BuildAttributeListSyntax(), node, (n, list) => n.WithAttributeLists(list));
+ node = RoslynUtilities.UpdateNodeIfItemNotNull (BuildAccessorList(), node, (n, item) => n.WithAccessorList (item));
+ //var parameters = BuildTypeParameterList();
+ //var typeParameters = BuildTypeParameterList();
+ //var constraintClauses = BuildConstraintClauses();
+
+ return (PropertyDeclarationSyntax)RoslynUtilities.Format(node);
+ }
- public void AddParameter(IParameter parameter)
- { _parameters.Add(parameter); }
+ private AccessorListSyntax BuildAccessorList( )
+ {
+ var list = new List<AccessorDeclarationSyntax>();
+ if (CanGet)
+ {
+ var node = SyntaxFactory.AccessorDeclaration(SyntaxKind.GetAccessorDeclaration);
+ node = RoslynUtilities.UpdateNodeIfItemNotNull(BuildStatementBlock(GetStatements), node, (n, item) => n.WithBody(item));
+ list.Add(node);
+ }
+ if (CanSet)
+ {
+ var node = SyntaxFactory.AccessorDeclaration(SyntaxKind.SetAccessorDeclaration);
+ node = RoslynUtilities.UpdateNodeIfItemNotNull(BuildStatementBlock(SetStatements), node, (n, item) => n.WithBody(item));
+ list.Add(node);
+ }
+ return SyntaxFactory.AccessorList(SyntaxFactory.List<AccessorDeclarationSyntax>(list));
+ }
public IEnumerable<IAttribute> Attributes
{ get { return GetAttributes(); } }
@@ -96,6 +128,12 @@ public IReferencedType ReturnType
public bool CanSet { get; set; }
+ public void RemoveParameter(IParameter parameter)
+ { _parameters.Remove(parameter); }
+
+ public void AddParameter(IParameter parameter)
+ { _parameters.Add(parameter); }
+
/// <summary>
///
/// </summary>
@@ -110,6 +148,24 @@ public IEnumerable<IParameter> Parameters
// This is for VB, wihch I have not yet implemented, but don't want things crashing so will ignore
{ get { return _parameters; } }
+ public void RemoveGetStatement(IStatement statement)
+ { _getStatements.Remove(statement); }
+
+ public void AddGetStatement(IStatement statement)
+ { _getStatements.Add(statement); }
+
+ public IEnumerable<IStatement> GetStatements
+ { get { return _getStatements; } }
+
+ public void RemoveSetStatement(IStatement statement)
+ { _setStatements.Remove(statement); }
+
+ public void AddSetStatement(IStatement statement)
+ { _setStatements.Add(statement); }
+
+ public IEnumerable<IStatement> SetStatements
+ { get { return _setStatements; } }
+
public MemberKind MemberKind
{ get { return MemberKind.Property; } }
View
13 RoslynDom/Implementations/RDomRoot.cs
@@ -1,6 +1,7 @@
using System.Collections.Generic;
using System.Linq;
using Microsoft.CodeAnalysis;
+using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using RoslynDom.Common;
@@ -28,7 +29,17 @@ protected override void Initialize()
Name = "Root";
}
- public bool HasSyntaxErrors
+ public override CompilationUnitSyntax BuildSyntax()
+ {
+ var node = SyntaxFactory.CompilationUnit();
+
+ node = RoslynUtilities.UpdateNodeIfListNotEmpty(BuildUsings(), node, (n, l) => n.WithUsings(l));
+ node = RoslynUtilities.UpdateNodeIfListNotEmpty(BuildStemMembers(), node, (n, l) => n.WithMembers (l));
+
+ return (CompilationUnitSyntax)RoslynUtilities.Format(node);
+ }
+
+ public bool HasSyntaxErrors
{
get
{
View
16 RoslynDom/Implementations/RDomStructure.cs
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.Linq;
+using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using RoslynDom.Common;
@@ -19,6 +20,21 @@ internal RDomStructure(RDomStructure oldRDom)
: base(oldRDom)
{ }
+ public override StructDeclarationSyntax BuildSyntax()
+ {
+ var modifiers = BuildModfierSyntax();
+ var node = SyntaxFactory.StructDeclaration(Name)
+ .WithModifiers(modifiers);
+
+ node = RoslynUtilities.UpdateNodeIfListNotEmpty(BuildMembers(true), node, (n, l) => n.WithMembers(l));
+ //node = RoslynUtilities.UpdateNodeIfListNotEmpty(BuildTypeParameterList(), node, (n, l) => n.WithTypeParameters(l));
+ //node = RoslynUtilities.UpdateNodeIfListNotEmpty(BuildConstraintClauses(), node, (n, l) => n.WithTypeConstraints(l));
+ node = RoslynUtilities.UpdateNodeIfListNotEmpty(BuildAttributeListSyntax(), node, (n, l) => n.WithAttributeLists(l));
+
+ return (StructDeclarationSyntax)RoslynUtilities.Format(node);
+ }
+
+
public IEnumerable<IClass> Classes
{
get
View
17 RoslynDom/Implementations/RDomUsing.cs
@@ -1,27 +1,36 @@
using Microsoft.CodeAnalysis;
+using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using RoslynDom.Common;
namespace RoslynDom
{
- public class RDomUsingDirective : RDomBase<IUsing, UsingDirectiveSyntax, ISymbol>, IUsing
+ public class RDomUsing : RDomBase<IUsing, UsingDirectiveSyntax, ISymbol>, IUsing
{
- internal RDomUsingDirective(
+ internal RDomUsing(
UsingDirectiveSyntax rawItem,
params PublicAnnotation[] publicAnnotations)
: base(rawItem, publicAnnotations)
{
Initialize();
}
- internal RDomUsingDirective(RDomUsingDirective oldRDom)
+ internal RDomUsing(RDomUsing oldRDom)
: base(oldRDom)
{ }
protected override void Initialize()
{
base.Initialize();
- Name = TypedSyntax.Name.NameFrom();
+ Name = TypedSyntax.Name.NameFrom();
+ }
+
+ public override UsingDirectiveSyntax BuildSyntax()
+ {
+ var nameSyntax = SyntaxFactory.IdentifierName(Name);
+ var node = SyntaxFactory.UsingDirective(nameSyntax);
+
+ return (UsingDirectiveSyntax)RoslynUtilities.Format(node);
}
public StemMemberKind StemMemberKind
View
2 RoslynDom/RDomFactory.cs
@@ -64,7 +64,7 @@ private static RDomRoot MakeRoot(SyntaxTree tree)
private static IUsing MakeUsingDirective(UsingDirectiveSyntax x)
{
var publicAnnotations = GetPublicAnnotations(x).ToArray();
- return new RDomUsingDirective(x, publicAnnotations);
+ return new RDomUsing(x, publicAnnotations);
}
private static bool DoMember<T>(MemberDeclarationSyntax val,
View
30 RoslynDom/RoslynUtilities.cs
@@ -107,12 +107,40 @@ public static IEnumerable<IStatement> GetStatements(BlockSyntax blockSyntax)
{
var list = new List<IStatement>();
var statements = blockSyntax.Statements;
- foreach (var statement in statements)
+ foreach (var statement in statements)
{
}
return list;
}
+ internal static bool TryAddSyntaxNode<TInput, TSyntaxNode, TRDom>(IList<TSyntaxNode> list, TInput member, Func<TRDom, TSyntaxNode> makeDelegate)
+ where TRDom : class
+ {
+ var memberAsT = member as TRDom;
+ if (memberAsT == null) return false;
+ list.Add(makeDelegate(memberAsT));
+ return true; ;
+
+ }
+
+ internal static TReturn UpdateNodeIfListNotEmpty<T, TReturn>(SyntaxList<T> list, TReturn input, Func<TReturn, SyntaxList<T>, TReturn> makeDelegate)
+ where T : SyntaxNode
+ where TReturn : SyntaxNode
+ {
+ if (list.Any()) { return makeDelegate(input, list); }
+ return input;
+
+ }
+
+ internal static TReturn UpdateNodeIfItemNotNull<T, TReturn>(T item, TReturn input, Func<TReturn, T, TReturn> makeDelegate)
+ where T : SyntaxNode
+ where TReturn : SyntaxNode
+ {
+ if (item != null) { return makeDelegate(input, item); }
+ return input;
+
+ }
+
}
}
View
20 RoslynDomTests/MutabilityTests.cs
@@ -112,7 +112,7 @@ public class Bar<T>
Assert.IsFalse(class1.SameIntent(class2));
Assert.AreEqual("Bar2", class2.Name);
var newCode = class2.BuildSyntax().ToString();
- Assert.AreEqual("[Foo(\"Fred\", bar: 3, bar2 = 3.14)]\r\npublic class Bar2\r\n{\r\n [Bar(bar: 42)]\r\n public String FooBar()\r\n {\r\n }\r\n}", newCode);
+ Assert.AreEqual("[Foo(\"Fred\", bar: 3, bar2 = 3.14)]\r\npublic class Bar2\r\n{\r\n private Int32 fooish;\r\n\r\n [Bar(bar: 42)]\r\n public String FooBar()\r\n {\r\n }\r\n}", newCode);
}
[TestMethod, TestCategory(MutabilityCategory)]
@@ -213,7 +213,7 @@ public struct Bar2{} ";
}
[TestMethod, TestCategory(MutabilityCategory)]
- public void Can_copy_complex_root()
+ public void Can_copy_multi_member_root()
{
var csharpCode = @"
using System;
@@ -228,7 +228,21 @@ public interface Bar4{}
Assert.IsTrue(rDomRoot.SameIntent(rDomRoot2));
}
-
+ [TestMethod, TestCategory(MutabilityCategory)]
+ public void Can_build_syntax_for_multi_member_root()
+ {
+ var csharpCode = @"
+ using System;
+ public class Bar{}
+ public struct Bar2{}
+ public enum Bar3{}
+ public interface Bar4{}
+ ";
+ var rDomRoot = RDomFactory.GetRootFromString(csharpCode) as RDomRoot;
+ var output = rDomRoot.BuildSyntax();
+ var expectedCode = "using System;\r\n\r\npublic class Bar\r\n{\r\n}\r\n\r\npublic struct Bar2\r\n{\r\n}\r\n\r\npublic enum Bar3\r\n{\r\n}\r\n\r\npublic interface Bar4\r\n{\r\n}";
+ Assert.AreEqual(expectedCode,output.ToString() );
+ }
#endregion
}
}

0 comments on commit afd2ac5

Please sign in to comment.