Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix #46 Formatting and whitespace fixes

F our tests are failing because of remaining formatting issues
  • Loading branch information...
commit d14c3cc2737363948aa9f59e4eff144db0590a0b 1 parent 8ab6fa5
@KathleenDollard authored
Showing with 329 additions and 175 deletions.
  1. BIN  Documentation/Long Term ToDo.docx
  2. +93 −0 Packages.dgml
  3. +15 −6 RoslynDom/BasesAndBaseHelpers/RDomCommentWhite.cs
  4. +7 −0 RoslynDom/Implementations/RDomComment.cs
  5. +9 −1 RoslynDom/Implementations/RDomVerticalWhitespace.cs
  6. +3 −3 RoslynDom/StatementImplementations/RDomAssignmentStatement.cs
  7. +54 −12 RoslynDomCSharpFactories/BuildSyntaxExtensions.cs
  8. +0 −25 RoslynDomCSharpFactories/CommentWhiteFactory.cs
  9. +1 −1  RoslynDomCSharpFactories/Factories/RDomAccessorFactory.cs
  10. +3 −5 RoslynDomCSharpFactories/Factories/RDomClassFactory.cs
  11. +2 −2 RoslynDomCSharpFactories/Factories/RDomEnumFactory.cs
  12. +1 −2  RoslynDomCSharpFactories/Factories/RDomFieldFactory.cs
  13. +1 −1  RoslynDomCSharpFactories/Factories/RDomInterfaceFactory.cs
  14. +1 −2  RoslynDomCSharpFactories/Factories/RDomMethodFactory.cs
  15. +2 −2 RoslynDomCSharpFactories/Factories/RDomNamespaceFactory.cs
  16. +2 −2 RoslynDomCSharpFactories/Factories/RDomParameterFactory.cs
  17. +1 −2  RoslynDomCSharpFactories/Factories/RDomPropertyFactory.cs
  18. +1 −2  RoslynDomCSharpFactories/Factories/RDomReferencedTypeFactory.cs
  19. +1 −1  RoslynDomCSharpFactories/Factories/RDomRootFactory.cs
  20. +1 −1  RoslynDomCSharpFactories/Factories/RDomStructureFactory.cs
  21. +1 −2  RoslynDomCSharpFactories/Factories/RDomUsingFactory.cs
  22. +5 −1 RoslynDomCSharpFactories/FactoriesForStatements/LoopFactoryHelper.cs
  23. +10 −7 RoslynDomCSharpFactories/FactoriesForStatements/RDomAssignmentStatementFactory.cs
  24. +2 −2 RoslynDomCSharpFactories/FactoriesForStatements/RDomBlockStatementFactory.cs
  25. +2 −1  RoslynDomCSharpFactories/FactoriesForStatements/RDomDeclarationStatementFactory.cs
  26. +2 −3 RoslynDomCSharpFactories/FactoriesForStatements/RDomForEachStatementFactory.cs
  27. +5 −5 RoslynDomCSharpFactories/FactoriesForStatements/RDomForStatementFactory.cs
  28. +1 −1  RoslynDomCSharpFactories/FactoriesForStatements/RDomIfStatementFactory.cs
  29. +3 −3 RoslynDomCSharpFactories/FactoriesForStatements/RDomInvocationStatementFactory.cs
  30. +2 −1  RoslynDomCSharpFactories/FactoriesForStatements/RDomReturnStatementFactory.cs
  31. +2 −1  RoslynDomCSharpFactories/FactoriesForStatements/RDomVariableDeclarationtFactory.cs
  32. +1 −8 RoslynDomCSharpFactories/RoslynCSharpUtilities.cs
  33. +2 −1  RoslynDomCommon/Interfaces_Statements/IAssignmentStatement.cs
  34. +0 −15 RoslynDomCommon/Interfaces_Statements/IDoWhileStatement.cs
  35. +1 −1  RoslynDomCommon/Interfaces_Statements/IInvocationStatement.cs
  36. +0 −5 RoslynDomRDomCommon/RDomBaseFactoryHelper.cs
  37. +21 −1 RoslynDomTests/BugResponseTests.cs
  38. +71 −47 RoslynDomTests/FactoryTests.cs
View
BIN  Documentation/Long Term ToDo.docx
Binary file not shown
View
93 Packages.dgml
@@ -0,0 +1,93 @@
+<?xml version="1.0" encoding="utf-8"?>
+<DirectedGraph GraphDirection="LeftToRight" xmlns="http://schemas.microsoft.com/vs/2009/dgml">
+ <Nodes>
+ <Node Id="RoslynDomCSharpFactories" Label="RoslynDomCSharpFactories" Category="Project" />
+ <Node Id="Microsoft.Bcl.Immutable 1.1.20-beta" Label="Microsoft.Bcl.Immutable 1.1.20-beta" Category="Package" />
+ <Node Id="Microsoft.Bcl.Metadata 1.0.11-alpha" Label="Microsoft.Bcl.Metadata 1.0.11-alpha" Category="Package" />
+ <Node Id="Microsoft.CodeAnalysis.Common 0.7.4052301-beta" Label="Microsoft.CodeAnalysis.Common 0.7.4052301-beta" Category="Package" />
+ <Node Id="Microsoft.CodeAnalysis.CSharp 0.7.4052301-beta" Label="Microsoft.CodeAnalysis.CSharp 0.7.4052301-beta" Category="Package" />
+ <Node Id="Microsoft.CodeAnalysis.CSharp.Workspaces 0.7.4052301-beta" Label="Microsoft.CodeAnalysis.CSharp.Workspaces 0.7.4052301-beta" Category="Package" />
+ <Node Id="Microsoft.CodeAnalysis.Workspaces.Common 0.7.4052301-beta" Label="Microsoft.CodeAnalysis.Workspaces.Common 0.7.4052301-beta" Category="Package" />
+ <Node Id="RoslynDomRDomCommon" Label="RoslynDomRDomCommon" Category="Project" />
+ <Node Id="Microsoft.Bcl.Immutable 1.1.20-beta" Label="Microsoft.Bcl.Immutable 1.1.20-beta" Category="Package" />
+ <Node Id="Microsoft.Bcl.Metadata 1.0.11-alpha" Label="Microsoft.Bcl.Metadata 1.0.11-alpha" Category="Package" />
+ <Node Id="Microsoft.CodeAnalysis.Common 0.7.4052301-beta" Label="Microsoft.CodeAnalysis.Common 0.7.4052301-beta" Category="Package" />
+ <Node Id="Unity 3.5.1405-prerelease" Label="Unity 3.5.1405-prerelease" Category="Package" />
+ <Node Id="RoslynDomExampleTests" Label="RoslynDomExampleTests" Category="Project" />
+ <Node Id="Microsoft.Bcl.Immutable 1.1.20-beta" Label="Microsoft.Bcl.Immutable 1.1.20-beta" Category="Package" />
+ <Node Id="Microsoft.Bcl.Metadata 1.0.11-alpha" Label="Microsoft.Bcl.Metadata 1.0.11-alpha" Category="Package" />
+ <Node Id="Microsoft.CodeAnalysis.Common 0.7.4052301-beta" Label="Microsoft.CodeAnalysis.Common 0.7.4052301-beta" Category="Package" />
+ <Node Id="Microsoft.CodeAnalysis.CSharp 0.7.4052301-beta" Label="Microsoft.CodeAnalysis.CSharp 0.7.4052301-beta" Category="Package" />
+ <Node Id="Microsoft.CodeAnalysis.CSharp.Workspaces 0.7.4052301-beta" Label="Microsoft.CodeAnalysis.CSharp.Workspaces 0.7.4052301-beta" Category="Package" />
+ <Node Id="Microsoft.CodeAnalysis.Workspaces.Common 0.7.4052301-beta" Label="Microsoft.CodeAnalysis.Workspaces.Common 0.7.4052301-beta" Category="Package" />
+ <Node Id="RoslynDomTests" Label="RoslynDomTests" Category="Project" />
+ <Node Id="Microsoft.Bcl.Immutable 1.1.20-beta" Label="Microsoft.Bcl.Immutable 1.1.20-beta" Category="Package" />
+ <Node Id="Microsoft.Bcl.Metadata 1.0.11-alpha" Label="Microsoft.Bcl.Metadata 1.0.11-alpha" Category="Package" />
+ <Node Id="Microsoft.CodeAnalysis.Common 0.7.4052301-beta" Label="Microsoft.CodeAnalysis.Common 0.7.4052301-beta" Category="Package" />
+ <Node Id="Microsoft.CodeAnalysis.CSharp 0.7.4052301-beta" Label="Microsoft.CodeAnalysis.CSharp 0.7.4052301-beta" Category="Package" />
+ <Node Id="Microsoft.CodeAnalysis.CSharp.Workspaces 0.7.4052301-beta" Label="Microsoft.CodeAnalysis.CSharp.Workspaces 0.7.4052301-beta" Category="Package" />
+ <Node Id="Microsoft.CodeAnalysis.Workspaces.Common 0.7.4052301-beta" Label="Microsoft.CodeAnalysis.Workspaces.Common 0.7.4052301-beta" Category="Package" />
+ <Node Id="RoslynDom" Label="RoslynDom" Category="Project" />
+ <Node Id="Microsoft.Bcl.Immutable 1.1.20-beta" Label="Microsoft.Bcl.Immutable 1.1.20-beta" Category="Package" />
+ <Node Id="Microsoft.Bcl.Metadata 1.0.11-alpha" Label="Microsoft.Bcl.Metadata 1.0.11-alpha" Category="Package" />
+ <Node Id="Microsoft.CodeAnalysis.Common 0.7.4052301-beta" Label="Microsoft.CodeAnalysis.Common 0.7.4052301-beta" Category="Package" />
+ <Node Id="Microsoft.CodeAnalysis.CSharp 0.7.4052301-beta" Label="Microsoft.CodeAnalysis.CSharp 0.7.4052301-beta" Category="Package" />
+ <Node Id="Microsoft.CodeAnalysis.CSharp.Workspaces 0.7.4052301-beta" Label="Microsoft.CodeAnalysis.CSharp.Workspaces 0.7.4052301-beta" Category="Package" />
+ <Node Id="Microsoft.CodeAnalysis.Workspaces.Common 0.7.4052301-beta" Label="Microsoft.CodeAnalysis.Workspaces.Common 0.7.4052301-beta" Category="Package" />
+ <Node Id="Unity 3.5.1405-prerelease" Label="Unity 3.5.1405-prerelease" Category="Package" />
+ </Nodes>
+ <Links>
+ <Link Source="Microsoft.Bcl.Metadata 1.0.11-alpha" Target="Microsoft.Bcl.Immutable 1.1.20-beta" Category="Package Dependency" />
+ <Link Source="Microsoft.CodeAnalysis.Common 0.7.4052301-beta" Target="Microsoft.Bcl.Immutable 1.1.20-beta" Category="Package Dependency" />
+ <Link Source="Microsoft.CodeAnalysis.Common 0.7.4052301-beta" Target="Microsoft.Bcl.Metadata 1.0.11-alpha" Category="Package Dependency" />
+ <Link Source="Microsoft.CodeAnalysis.CSharp 0.7.4052301-beta" Target="Microsoft.CodeAnalysis.Common 0.7.4052301-beta" Category="Package Dependency" />
+ <Link Source="Microsoft.CodeAnalysis.CSharp.Workspaces 0.7.4052301-beta" Target="Microsoft.CodeAnalysis.Workspaces.Common 0.7.4052301-beta" Category="Package Dependency" />
+ <Link Source="Microsoft.CodeAnalysis.CSharp.Workspaces 0.7.4052301-beta" Target="Microsoft.CodeAnalysis.CSharp 0.7.4052301-beta" Category="Package Dependency" />
+ <Link Source="Microsoft.CodeAnalysis.Workspaces.Common 0.7.4052301-beta" Target="Microsoft.CodeAnalysis.Common 0.7.4052301-beta" Category="Package Dependency" />
+ <Link Source="RoslynDomCSharpFactories" Target="Microsoft.CodeAnalysis.CSharp.Workspaces 0.7.4052301-beta" Category="Installed Package" />
+ <Link Source="Microsoft.Bcl.Metadata 1.0.11-alpha" Target="Microsoft.Bcl.Immutable 1.1.20-beta" Category="Package Dependency" />
+ <Link Source="Microsoft.CodeAnalysis.Common 0.7.4052301-beta" Target="Microsoft.Bcl.Immutable 1.1.20-beta" Category="Package Dependency" />
+ <Link Source="Microsoft.CodeAnalysis.Common 0.7.4052301-beta" Target="Microsoft.Bcl.Metadata 1.0.11-alpha" Category="Package Dependency" />
+ <Link Source="RoslynDomRDomCommon" Target="Microsoft.CodeAnalysis.Common 0.7.4052301-beta" Category="Installed Package" />
+ <Link Source="RoslynDomRDomCommon" Target="Unity 3.5.1405-prerelease" Category="Installed Package" />
+ <Link Source="Microsoft.Bcl.Metadata 1.0.11-alpha" Target="Microsoft.Bcl.Immutable 1.1.20-beta" Category="Package Dependency" />
+ <Link Source="Microsoft.CodeAnalysis.Common 0.7.4052301-beta" Target="Microsoft.Bcl.Immutable 1.1.20-beta" Category="Package Dependency" />
+ <Link Source="Microsoft.CodeAnalysis.Common 0.7.4052301-beta" Target="Microsoft.Bcl.Metadata 1.0.11-alpha" Category="Package Dependency" />
+ <Link Source="Microsoft.CodeAnalysis.CSharp 0.7.4052301-beta" Target="Microsoft.CodeAnalysis.Common 0.7.4052301-beta" Category="Package Dependency" />
+ <Link Source="Microsoft.CodeAnalysis.CSharp.Workspaces 0.7.4052301-beta" Target="Microsoft.CodeAnalysis.Workspaces.Common 0.7.4052301-beta" Category="Package Dependency" />
+ <Link Source="Microsoft.CodeAnalysis.CSharp.Workspaces 0.7.4052301-beta" Target="Microsoft.CodeAnalysis.CSharp 0.7.4052301-beta" Category="Package Dependency" />
+ <Link Source="Microsoft.CodeAnalysis.Workspaces.Common 0.7.4052301-beta" Target="Microsoft.CodeAnalysis.Common 0.7.4052301-beta" Category="Package Dependency" />
+ <Link Source="RoslynDomExampleTests" Target="Microsoft.CodeAnalysis.CSharp.Workspaces 0.7.4052301-beta" Category="Installed Package" />
+ <Link Source="Microsoft.Bcl.Metadata 1.0.11-alpha" Target="Microsoft.Bcl.Immutable 1.1.20-beta" Category="Package Dependency" />
+ <Link Source="Microsoft.CodeAnalysis.Common 0.7.4052301-beta" Target="Microsoft.Bcl.Immutable 1.1.20-beta" Category="Package Dependency" />
+ <Link Source="Microsoft.CodeAnalysis.Common 0.7.4052301-beta" Target="Microsoft.Bcl.Metadata 1.0.11-alpha" Category="Package Dependency" />
+ <Link Source="Microsoft.CodeAnalysis.CSharp 0.7.4052301-beta" Target="Microsoft.CodeAnalysis.Common 0.7.4052301-beta" Category="Package Dependency" />
+ <Link Source="Microsoft.CodeAnalysis.CSharp.Workspaces 0.7.4052301-beta" Target="Microsoft.CodeAnalysis.Workspaces.Common 0.7.4052301-beta" Category="Package Dependency" />
+ <Link Source="Microsoft.CodeAnalysis.CSharp.Workspaces 0.7.4052301-beta" Target="Microsoft.CodeAnalysis.CSharp 0.7.4052301-beta" Category="Package Dependency" />
+ <Link Source="Microsoft.CodeAnalysis.Workspaces.Common 0.7.4052301-beta" Target="Microsoft.CodeAnalysis.Common 0.7.4052301-beta" Category="Package Dependency" />
+ <Link Source="RoslynDomTests" Target="Microsoft.CodeAnalysis.CSharp.Workspaces 0.7.4052301-beta" Category="Installed Package" />
+ <Link Source="Microsoft.Bcl.Metadata 1.0.11-alpha" Target="Microsoft.Bcl.Immutable 1.1.20-beta" Category="Package Dependency" />
+ <Link Source="Microsoft.CodeAnalysis.Common 0.7.4052301-beta" Target="Microsoft.Bcl.Immutable 1.1.20-beta" Category="Package Dependency" />
+ <Link Source="Microsoft.CodeAnalysis.Common 0.7.4052301-beta" Target="Microsoft.Bcl.Metadata 1.0.11-alpha" Category="Package Dependency" />
+ <Link Source="Microsoft.CodeAnalysis.CSharp 0.7.4052301-beta" Target="Microsoft.CodeAnalysis.Common 0.7.4052301-beta" Category="Package Dependency" />
+ <Link Source="Microsoft.CodeAnalysis.CSharp.Workspaces 0.7.4052301-beta" Target="Microsoft.CodeAnalysis.Workspaces.Common 0.7.4052301-beta" Category="Package Dependency" />
+ <Link Source="Microsoft.CodeAnalysis.CSharp.Workspaces 0.7.4052301-beta" Target="Microsoft.CodeAnalysis.CSharp 0.7.4052301-beta" Category="Package Dependency" />
+ <Link Source="Microsoft.CodeAnalysis.Workspaces.Common 0.7.4052301-beta" Target="Microsoft.CodeAnalysis.Common 0.7.4052301-beta" Category="Package Dependency" />
+ <Link Source="RoslynDom" Target="Microsoft.CodeAnalysis.CSharp.Workspaces 0.7.4052301-beta" Category="Installed Package" />
+ <Link Source="RoslynDom" Target="Unity 3.5.1405-prerelease" Category="Installed Package" />
+ </Links>
+ <Categories>
+ <Category Id="Project" />
+ <Category Id="Package" />
+ </Categories>
+ <Styles>
+ <Style TargetType="Node" GroupLabel="Project" ValueLabel="True">
+ <Condition Expression="HasCategory('Project')" />
+ <Setter Property="Background" Value="Blue" />
+ </Style>
+ <Style TargetType="Link" GroupLabel="Package Dependency" ValueLabel="True">
+ <Condition Expression="HasCategory('Package Dependency')" />
+ <Setter Property="Background" Value="Yellow" />
+ </Style>
+ </Styles>
+</DirectedGraph>
View
21 RoslynDom/BasesAndBaseHelpers/RDomCommentWhite.cs
@@ -10,9 +10,21 @@ namespace RoslynDom
{
public abstract class RDomCommentWhite : RDomBase, ICommentWhite
{
-
- public MemberKind MemberKind
- { get { return MemberKind.Whitespace; } }
+ internal RDomCommentWhite(StemMemberKind stemMemberKind, MemberKind memberKind)
+ {
+ StemMemberKind = stemMemberKind;
+ MemberKind = memberKind;
+ }
+
+ internal RDomCommentWhite(RDomCommentWhite oldRDom)
+ : base(oldRDom)
+ {
+ StemMemberKind = oldRDom.StemMemberKind;
+ MemberKind = oldRDom.MemberKind;
+ }
+
+ public StemMemberKind StemMemberKind { get; set; }
+ public MemberKind MemberKind { get; set; }
public override object OriginalRawItem
{ get { return null; } }
@@ -23,9 +35,6 @@ public override string OuterName
public override object RawItem
{ get { return null; } }
- public StemMemberKind StemMemberKind
- { get { return StemMemberKind.Whitespace; } }
-
public override ISymbol Symbol
{ get { return null; } }
View
7 RoslynDom/Implementations/RDomComment.cs
@@ -11,10 +11,17 @@ namespace RoslynDom
public class RDomComment : RDomCommentWhite, IComment
{
public RDomComment (string text, bool isMultiline)
+ : base(StemMemberKind.Comment, MemberKind.Comment )
{
Text = text;
IsMultiline = isMultiline;
}
+ internal RDomComment( RDomComment oldRDom)
+ : base(oldRDom)
+ {
+ Text = oldRDom.Text;
+ IsMultiline = oldRDom.IsMultiline;
+ }
public string Text { get; set; }
View
10 RoslynDom/Implementations/RDomVerticalWhitespace.cs
@@ -10,12 +10,20 @@ namespace RoslynDom
{
public class RDomVerticalWhitespace : RDomCommentWhite, IVerticalWhitespace
{
- public RDomVerticalWhitespace (int count, bool isElastic)
+ public RDomVerticalWhitespace(int count, bool isElastic)
+ : base(StemMemberKind.Whitespace, MemberKind.Whitespace )
{
Count = count;
IsElastic = isElastic;
}
+ internal RDomVerticalWhitespace(RDomVerticalWhitespace oldRDom)
+ : base(oldRDom)
+ {
+ Count = oldRDom.Count;
+ IsElastic = oldRDom.IsElastic;
+ }
+
public int Count { get; set; }
public bool IsElastic { get; set; }
View
6 RoslynDom/StatementImplementations/RDomAssignmentStatement.cs
@@ -14,8 +14,8 @@ public RDomAssignmentStatement(SyntaxNode rawItem, IDom parent, SemanticModel mo
internal RDomAssignmentStatement(RDomAssignmentStatement oldRDom)
: base(oldRDom)
{
- Name = oldRDom.Name;
- Expression = oldRDom.Expression;
+ Left = oldRDom.Left.Copy();
+ Expression = oldRDom.Expression.Copy();
}
public override IEnumerable<IDom> Children
@@ -24,7 +24,7 @@ public override IEnumerable<IDom> Children
public override IEnumerable<IDom> Descendants
{ get { return new List<IDom>() { Expression }; } }
- public string Name { get; set; }
+ public IExpression Left { get; set; }
public IExpression Expression { get; set; }
}
}
View
66 RoslynDomCSharpFactories/BuildSyntaxExtensions.cs
@@ -13,6 +13,14 @@ namespace RoslynDom
{
public static class BuildSyntaxExtensions
{
+ public static IEnumerable<SyntaxNode> PrepareForBuildSyntaxOutput(this IDom item, SyntaxNode node)
+ {
+ var leadingTrivia = BuildSyntaxExtensions.LeadingTrivia(item);
+ node = node.WithLeadingTrivia(leadingTrivia);
+
+ return new SyntaxNode[] { RoslynUtilities.Format(node) };
+ }
+
public static SyntaxList<AttributeListSyntax> WrapInAttributeList(this IEnumerable<SyntaxNode> attributes)
{
var node = SyntaxFactory.List<AttributeListSyntax>(attributes.OfType<AttributeListSyntax>());
@@ -39,27 +47,60 @@ public static SyntaxTriviaList LeadingTrivia(IDom item)
return SyntaxFactory.TriviaList(leadingTrivia);
}
+ //private static IEnumerable<SyntaxTrivia> BuildCommentWhite(IDom item)
+ //{
+ // var ret = new List<SyntaxTrivia>();
+ // // This can happen if someone copies an item to a new item, does not attach it to a tree,
+ // // and asks for the syntax. It's actually expected to sometimes be unattached.
+ // if (item.Parent == null) { return ret; }
+ // if (item is IStemMember)
+ // {
+ // var parentAsStem = item.Parent as IStemContainer;
+ // if (parentAsStem == null) throw new InvalidOperationException();
+ // var commentWhites = parentAsStem.StemMembersAll
+ // .PreviousSiblingsUntil(item, x => !(x is IComment || x is IVerticalWhitespace))
+ // .OfType<ICommentWhite>();
+ // ret.AddRange(MakeWhiteCommentTrivia(commentWhites));
+ // }
+ // return ret;
+ //}
+
private static IEnumerable<SyntaxTrivia> BuildCommentWhite(IDom item)
{
var ret = new List<SyntaxTrivia>();
- if (item is IStemMember)
- {
- var parentAsStem = item.Parent as IStemContainer;
- if (parentAsStem == null) throw new InvalidOperationException();
- var commentWhites = parentAsStem.StemMembersAll
- .PreviousSiblingsUntil(item, x => !(x is IComment || x is IVerticalWhitespace))
- .OfType<ICommentWhite>();
- ret.AddRange( MakeWhiteCommentTrivia(commentWhites));
- }
+ // This can happen if someone copies an item to a new item, does not attach it to a tree,
+ // and asks for the syntax. It's actually expected to sometimes be unattached.
+ if (item.Parent == null) { return ret; }
+ if (TryBuildCommentWhiteFor<IStemMemberCommentWhite, IStemContainer>(item, ret, x => x.StemMembersAll)) { return ret; }
+ if (TryBuildCommentWhiteFor<ITypeMemberCommentWhite, ITypeMemberContainer>(item, ret, x => x.MembersAll)) { return ret; }
+ if (TryBuildCommentWhiteFor<IStatementCommentWhite, IStatementContainer>(item, ret, x => x.StatementsAll)) { return ret; }
return ret;
}
+ private static bool TryBuildCommentWhiteFor<TKind, TParent>
+ (IDom item, List<SyntaxTrivia> trivias, Func<TParent, IEnumerable<TKind>> getCandidates)
+ where TParent : class
+ where TKind : class
+ {
+ var itemAsTKind = item as TKind;
+ if (itemAsTKind == null) { return false; }
+ // if item is TKind, parent may not be TParent because types can be multiply rooted (stem or nested type)
+ var parentAsTParent = item.Parent as TParent;
+ if (parentAsTParent == null) return false;
+ var candidates = getCandidates(parentAsTParent);
+ var commentWhites = candidates
+ .PreviousSiblingsUntil(itemAsTKind, x => !(x is IComment || x is IVerticalWhitespace))
+ .OfType<ICommentWhite>();
+ trivias.AddRange(MakeWhiteCommentTrivia(commentWhites));
+ return true;
+ }
+
private static IEnumerable<SyntaxTrivia> MakeWhiteCommentTrivia(IEnumerable<ICommentWhite> commentWhites)
{
var ret = new List<SyntaxTrivia>();
foreach (var item in commentWhites)
{
- if (item is IVerticalWhitespace) { ret.Add(SyntaxFactory.EndOfLine("")); }
+ if (item is IVerticalWhitespace) { ret.Add(SyntaxFactory.EndOfLine("\r\n")); }
else
{
var itemAsComment = item as IComment;
@@ -68,6 +109,7 @@ private static IEnumerable<SyntaxTrivia> MakeWhiteCommentTrivia(IEnumerable<ICom
if (itemAsComment.IsMultiline) { comment = "/* " + itemAsComment.Text + "*/"; }
else { comment = "// " + itemAsComment.Text; }
ret.Add(SyntaxFactory.Comment(comment));
+ ret.Add(SyntaxFactory.EndOfLine("\r\n"));
}
}
return ret;
@@ -75,9 +117,9 @@ private static IEnumerable<SyntaxTrivia> MakeWhiteCommentTrivia(IEnumerable<ICom
public static SyntaxTriviaList BuildStructuredDocumentationSyntax(IHasStructuredDocumentation itemHasStructDoc)
{
- var ret = SyntaxFactory.TriviaList ();
+ var ret = SyntaxFactory.TriviaList();
if (itemHasStructDoc == null || string.IsNullOrWhiteSpace(itemHasStructDoc.Description)) return ret;
- var description = "\r\n" + itemHasStructDoc.Description + "\r\n";
+ var description = "\r\n" + itemHasStructDoc.Description + "\r\n";
XDocument xDoc = null;
if (itemHasStructDoc.StructuredDocumentation == null)
{
View
25 RoslynDomCSharpFactories/CommentWhiteFactory.cs
@@ -75,37 +75,12 @@ private string ExtractComment(SyntaxTrivia trivia, SyntaxNode node)
public override IEnumerable<SyntaxNode> BuildSyntax(IMisc item)
{
return null;
- //return BuildSyntax((IAttribute)item);
}
public IEnumerable<SyntaxNode> BuildSyntax(ICommentWhite item)
{
return null;
- //var itemAsT = item as IAttribute;
- //var nameSyntax = SyntaxFactory.ParseName(itemAsT.Name);
- //var arguments = new SeparatedSyntaxList<AttributeArgumentSyntax>();
- //var values = itemAsT.AttributeValues.Select(x => BuildAttributeValueSyntax(x));
- //arguments = arguments.AddRange(values.OfType<AttributeArgumentSyntax>().ToList());
- //var argumentList = SyntaxFactory.AttributeArgumentList(arguments);
- //var node = SyntaxFactory.Attribute(nameSyntax, argumentList);
-
- //return new SyntaxNode[] { RoslynUtilities.Format(node) };
}
- //public IEnumerable<SyntaxNode> BuildSyntax(AttributeList attributeList)
- //{
- // var list = SyntaxFactory.List<SyntaxNode>();
- // var attributes = attributeList.Attributes;
- // if (attributes.Any())
- // {
- // var attribList = SyntaxFactory.AttributeList();
- // var attributeSyntaxItems = attributes.SelectMany(x => BuildSyntax(x)).ToArray();
- // // TODO: attributeSyntaxItems = attributeSyntaxItems.Select(x => x.Format()).ToArray();
- // attribList = attribList.AddAttributes(attributeSyntaxItems.OfType<AttributeSyntax>().ToArray());
- // list = list.Add(attribList);
- // }
- // return list;
- //}
-
}
}
View
2  RoslynDomCSharpFactories/Factories/RDomAccessorFactory.cs
@@ -47,7 +47,7 @@ public override IEnumerable<SyntaxNode> BuildSyntax(IMisc item)
var attributes = RDomFactoryHelper.BuildAttributeSyntax(itemAsAccessor.Attributes);
if (attributes.Any()) { node = node.WithAttributeLists(attributes.WrapInAttributeList()); }
- return new SyntaxNode[] { RoslynUtilities.Format(node) };
+ return item.PrepareForBuildSyntaxOutput(node);
}
}
View
8 RoslynDomCSharpFactories/Factories/RDomClassFactory.cs
@@ -48,11 +48,9 @@ public static IEnumerable<SyntaxNode> BuildSyntax(RDomClass item)
.ToList();
node = node.WithMembers(SyntaxFactory.List(membersSyntax));
- var leadingTrivia = BuildSyntaxExtensions.LeadingTrivia(item);
- node = node.WithLeadingTrivia(leadingTrivia);
-
// TODO: Class type members and type constraints
- return new SyntaxNode[] { RoslynUtilities.Format(node) };
+
+ return item.PrepareForBuildSyntaxOutput(node);
}
}
public class RDomClassTypeMemberFactory
@@ -60,7 +58,7 @@ public class RDomClassTypeMemberFactory
{
protected override ITypeMemberCommentWhite CreateItemFrom(SyntaxNode syntaxNode, IDom parent, SemanticModel model)
{
- return RDomClassFactoryHelper.CreateFromInternal(syntaxNode, parent, model);
+ return RDomClassFactoryHelper.CreateFromInternal(syntaxNode, parent, model);
}
public override IEnumerable<SyntaxNode> BuildSyntax(ITypeMemberCommentWhite item)
View
4 RoslynDomCSharpFactories/Factories/RDomEnumFactory.cs
@@ -42,13 +42,13 @@ public static IEnumerable<SyntaxNode> BuildSyntax(RDomEnum item)
if (itemAsEnum == null) { throw new InvalidOperationException(); }
node.WithLeadingTrivia(BuildSyntaxExtensions.LeadingTrivia(item));
-
+
//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) };
+ return item.PrepareForBuildSyntaxOutput(node);
}
}
View
3  RoslynDomCSharpFactories/Factories/RDomFieldFactory.cs
@@ -59,8 +59,7 @@ public override IEnumerable<SyntaxNode> BuildSyntax(ITypeMemberCommentWhite item
node.WithLeadingTrivia(BuildSyntaxExtensions.LeadingTrivia(item));
- // TODO: return new SyntaxNode[] { node.Format() };
- return new SyntaxNode[] { node };
+ return item.PrepareForBuildSyntaxOutput(node);
}
}
View
2  RoslynDomCSharpFactories/Factories/RDomInterfaceFactory.cs
@@ -46,7 +46,7 @@ public static IEnumerable<SyntaxNode> BuildSyntax(RDomInterface item)
node = node.WithMembers(SyntaxFactory.List(membersSyntax));
node.WithLeadingTrivia(BuildSyntaxExtensions.LeadingTrivia(item));
// TODO: Class type members and type constraints
- return new SyntaxNode[] { RoslynUtilities.Format(node) };
+ return item.PrepareForBuildSyntaxOutput(node);
}
}
View
3  RoslynDomCSharpFactories/Factories/RDomMethodFactory.cs
@@ -64,8 +64,7 @@ public override IEnumerable<SyntaxNode> BuildSyntax(ITypeMemberCommentWhite item
// TODO: typeParameters and constraintClauses
- // TODO: return new SyntaxNode[] { node.Format() };
- return new SyntaxNode[] { RoslynUtilities.Format(node) };
+ return item.PrepareForBuildSyntaxOutput(node);
}
}
View
4 RoslynDomCSharpFactories/Factories/RDomNamespaceFactory.cs
@@ -46,8 +46,8 @@ public override IEnumerable<SyntaxNode> BuildSyntax(IStemMemberCommentWhite item
.OfType<MemberDeclarationSyntax>()
.ToList();
if (membersSyntax.Count() > 0) { node = node.WithMembers(SyntaxFactory.List<MemberDeclarationSyntax>(membersSyntax)); }
- // TODO: return new SyntaxNode[] { node.Format() };
- return new SyntaxNode[] { node };
+
+ return item.PrepareForBuildSyntaxOutput(node);
}
}
View
4 RoslynDomCSharpFactories/Factories/RDomParameterFactory.cs
@@ -47,8 +47,8 @@ public override IEnumerable<SyntaxNode> BuildSyntax(IMisc item)
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); }
- // TODO:return new SyntaxNode[] { node.Format() };
- return new SyntaxNode[] { node };
+
+ return item.PrepareForBuildSyntaxOutput(node);
}
}
View
3  RoslynDomCSharpFactories/Factories/RDomPropertyFactory.cs
@@ -68,8 +68,7 @@ public override IEnumerable<SyntaxNode> BuildSyntax(ITypeMemberCommentWhite item
node.WithLeadingTrivia(BuildSyntaxExtensions.LeadingTrivia(item));
// TODO: parameters , typeParameters and constraintClauses
- // TODO: return new SyntaxNode[] { node.Format() };
- return new SyntaxNode[] { node };
+ return item.PrepareForBuildSyntaxOutput(node);
}
}
View
3  RoslynDomCSharpFactories/Factories/RDomReferencedTypeFactory.cs
@@ -16,8 +16,7 @@ public override IEnumerable<SyntaxNode> BuildSyntax(IMisc item)
{
var itemAsT = item as IReferencedType;
var node = SyntaxFactory.ParseTypeName(itemAsT.Name);
- // TODO: return new SyntaxNode[] { node.Format() };
- return new SyntaxNode[] { node };
+ return item.PrepareForBuildSyntaxOutput(node);
}
protected override IMisc CreateItemFrom(SyntaxNode syntaxNode, IDom parent, SemanticModel model)
View
2  RoslynDomCSharpFactories/Factories/RDomRootFactory.cs
@@ -36,7 +36,7 @@ public override IEnumerable<SyntaxNode> BuildSyntax(IRoot item)
.ToList();
node = node.WithUsings(SyntaxFactory.List(usingsSyntax));
node = node.WithMembers(SyntaxFactory.List(membersSyntax));
- return new SyntaxNode[] { RoslynUtilities.Format(node) };
+ return item.PrepareForBuildSyntaxOutput(node);
}
}
View
2  RoslynDomCSharpFactories/Factories/RDomStructureFactory.cs
@@ -47,7 +47,7 @@ public static IEnumerable<SyntaxNode> BuildSyntax(RDomStructure item)
node = node.WithMembers(SyntaxFactory.List(membersSyntax));
node.WithLeadingTrivia(BuildSyntaxExtensions.LeadingTrivia(item));
// TODO: Class type members and type constraints
- return new SyntaxNode[] { RoslynUtilities.Format(node) };
+ return item.PrepareForBuildSyntaxOutput(node);
}
}
public class RDomStructureTypeMemberFactory
View
3  RoslynDomCSharpFactories/Factories/RDomUsingFactory.cs
@@ -27,8 +27,7 @@ public override IEnumerable<SyntaxNode> BuildSyntax(IStemMemberCommentWhite item
var identifier = SyntaxFactory.IdentifierName(itemAsT.Name);
var node = SyntaxFactory.UsingDirective(identifier);
- // TODO: return new SyntaxNode[] { node.Format() };
- return new SyntaxNode[] { node };
+ return item.PrepareForBuildSyntaxOutput(node);
}
}
View
6 RoslynDomCSharpFactories/FactoriesForStatements/LoopFactoryHelper.cs
@@ -42,7 +42,11 @@ internal class LoopFactoryHelper
var condition = RDomCSharpFactory.Factory.BuildSyntax(item.Condition);
node = makeSyntaxDelegate((ExpressionSyntax)condition, statement);
}
- return new SyntaxNode[] { RoslynUtilities.Format(node) };
+
+ var leadingTrivia = BuildSyntaxExtensions.LeadingTrivia(item);
+ node = node.WithLeadingTrivia(leadingTrivia);
+
+ return item.PrepareForBuildSyntaxOutput(node);
}
}
}
View
17 RoslynDomCSharpFactories/FactoriesForStatements/RDomAssignmentStatementFactory.cs
@@ -20,13 +20,14 @@ protected override IStatementCommentWhite CreateItemFrom(SyntaxNode syntaxNode,
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 left = binary.Left as ExpressionSyntax;
+ // Previously tested for identifier here, but can also be SimpleMemberAccess and ElementAccess expressions
+ // not currently seeing value in testing for the type. Fix #46
+ // Also changed Name to Left and string to expression
var right = binary.Right;
var expression = right as ExpressionSyntax;
if (expression == null) throw new InvalidOperationException();
- newItem.Name = identifier.ToString();
+ newItem.Left = RDomFactoryHelper.GetHelperForExpression().MakeItems(left, newItem, model).FirstOrDefault();
newItem.Expression = RDomFactoryHelper.GetHelperForExpression().MakeItems(expression, newItem, model).FirstOrDefault();
return newItem ;
@@ -34,12 +35,14 @@ protected override IStatementCommentWhite CreateItemFrom(SyntaxNode syntaxNode,
public override IEnumerable<SyntaxNode> BuildSyntax(IStatementCommentWhite item)
{
var itemAsT = item as IAssignmentStatement;
- var nameSyntax = SyntaxFactory.IdentifierName(itemAsT.Name);
+ var leftSyntax = RDomCSharpFactory.Factory.BuildSyntax(itemAsT.Left);
var expressionSyntax = RDomCSharpFactory.Factory.BuildSyntax(itemAsT.Expression );
- var assignmentSyntax = SyntaxFactory.BinaryExpression(SyntaxKind.SimpleAssignmentExpression, nameSyntax, (ExpressionSyntax)expressionSyntax);
+ var assignmentSyntax = SyntaxFactory.BinaryExpression(SyntaxKind.SimpleAssignmentExpression,
+ (ExpressionSyntax)leftSyntax, (ExpressionSyntax)expressionSyntax);
var node = SyntaxFactory.ExpressionStatement(assignmentSyntax );
- return new SyntaxNode[] { RoslynUtilities.Format(node) };
+
+ return item.PrepareForBuildSyntaxOutput(node);
}
public override bool CanCreateFrom(SyntaxNode syntaxNode)
View
4 RoslynDomCSharpFactories/FactoriesForStatements/RDomBlockStatementFactory.cs
@@ -31,8 +31,8 @@ public override IEnumerable<SyntaxNode> BuildSyntax(IStatementCommentWhite item)
.SelectMany(x => RDomCSharpFactory.Factory.BuildSyntaxGroup(x))
.ToList();
var node = SyntaxFactory.Block(SyntaxFactory.List(statementSyntaxList));
- // TODO: return new SyntaxNode[] { node.Format() };
- return new SyntaxNode[] { node };
+
+ return item.PrepareForBuildSyntaxOutput(node);
}
}
View
3  RoslynDomCSharpFactories/FactoriesForStatements/RDomDeclarationStatementFactory.cs
@@ -68,7 +68,8 @@ public override IEnumerable<SyntaxNode> BuildSyntax(IStatementCommentWhite item)
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) };
+
+ return item.PrepareForBuildSyntaxOutput(node);
}
}
}
View
5 RoslynDomCSharpFactories/FactoriesForStatements/RDomForEachStatementFactory.cs
@@ -36,10 +36,9 @@ public override IEnumerable<SyntaxNode> BuildSyntax(IStatementCommentWhite item)
else
{ typeSyntax = (TypeSyntax)(RDomCSharpFactory.Factory.BuildSyntax(itemAsT.Variable.Type)); }
- var node = LoopFactoryHelper.BuildSyntax<IForEachStatement>
- (itemAsT, (c, s) => SyntaxFactory.ForEachStatement(typeSyntax, itemAsT.Variable.Name, c,s)).First() as ForEachStatementSyntax ;
+ return LoopFactoryHelper.BuildSyntax<IForEachStatement>
+ (itemAsT, (c, s) => SyntaxFactory.ForEachStatement(typeSyntax, itemAsT.Variable.Name, c,s)) ;
- return new SyntaxNode[] { RoslynUtilities.Format(node) };
}
View
10 RoslynDomCSharpFactories/FactoriesForStatements/RDomForStatementFactory.cs
@@ -11,7 +11,7 @@ namespace RoslynDom.CSharp
public class RDomForStatementFactory
: RDomStatementFactory<RDomForStatement, ForStatementSyntax>
{
- protected override IStatementCommentWhite CreateItemFrom(SyntaxNode syntaxNode, IDom parent, SemanticModel model)
+ protected override IStatementCommentWhite CreateItemFrom(SyntaxNode syntaxNode, IDom parent, SemanticModel model)
{
var syntax = syntaxNode as ForStatementSyntax;
var newItem = new RDomForStatement(syntaxNode, parent, model);
@@ -26,7 +26,7 @@ protected override IStatementCommentWhite CreateItemFrom(SyntaxNode syntaxNode,
public override IEnumerable<SyntaxNode> BuildSyntax(IStatementCommentWhite item)
{
var itemAsT = item as IForStatement;
- var node = LoopFactoryHelper.BuildSyntax<IForStatement>(itemAsT, (c, s) => SyntaxFactory.ForStatement(s).WithCondition(c)).First() as ForStatementSyntax ;
+ var node = LoopFactoryHelper.BuildSyntax<IForStatement>(itemAsT, (c, s) => SyntaxFactory.ForStatement(s).WithCondition(c)).First() as ForStatementSyntax;
// TODO: Try to share this code with DeclarationSyntaxStatementFactory
TypeSyntax typeSyntax;
@@ -41,10 +41,10 @@ public override IEnumerable<SyntaxNode> BuildSyntax(IStatementCommentWhite item)
var nodeDeclaration = SyntaxFactory.VariableDeclaration(typeSyntax, nodeDeclaratorInList);
node = node.WithDeclaration(nodeDeclaration);
- var incrementorSyntax = RDomCSharpFactory.Factory.BuildSyntax(itemAsT.Incrementor );
- node = node.WithIncrementors(SyntaxFactory.SeparatedList<ExpressionSyntax>(new ExpressionSyntax[] {(ExpressionSyntax) incrementorSyntax }));
+ var incrementorSyntax = RDomCSharpFactory.Factory.BuildSyntax(itemAsT.Incrementor);
+ node = node.WithIncrementors(SyntaxFactory.SeparatedList<ExpressionSyntax>(new ExpressionSyntax[] { (ExpressionSyntax)incrementorSyntax }));
- return new SyntaxNode[] { RoslynUtilities.Format(node) };
+ return item.PrepareForBuildSyntaxOutput(node);
}
View
2  RoslynDomCSharpFactories/FactoriesForStatements/RDomIfStatementFactory.cs
@@ -75,7 +75,7 @@ public override IEnumerable<SyntaxNode> BuildSyntax(IStatementCommentWhite item)
var node = SyntaxFactory.IfStatement(GetCondition(itemAsT), GetStatement(itemAsT));
if (elseSyntax != null) { node = node.WithElse(elseSyntax); }
- return new SyntaxNode[] { RoslynUtilities.Format(node) };
+ return item.PrepareForBuildSyntaxOutput(node);
}
private ElseClauseSyntax BuildElseSyntax(IEnumerable<IElseStatement> elses)
View
6 RoslynDomCSharpFactories/FactoriesForStatements/RDomInvocationStatementFactory.cs
@@ -11,7 +11,7 @@ namespace RoslynDom.CSharp
public class RDomInvocationStatementFactory
: RDomStatementFactory<RDomInvocationStatement, ExpressionStatementSyntax>
{
- protected override IStatementCommentWhite CreateItemFrom(SyntaxNode syntaxNode, IDom parent, SemanticModel model)
+ protected override IStatementCommentWhite CreateItemFrom(SyntaxNode syntaxNode, IDom parent, SemanticModel model)
{
var syntax = syntaxNode as ExpressionStatementSyntax;
var newItem = new RDomInvocationStatement(syntaxNode, parent, model);
@@ -19,7 +19,7 @@ protected override IStatementCommentWhite CreateItemFrom(SyntaxNode syntaxNode,
var expression = syntax.Expression;
newItem.Invocation = RDomFactoryHelper.GetHelperForExpression().MakeItems(expression, newItem, model).FirstOrDefault();
- return newItem ;
+ return newItem;
}
public override IEnumerable<SyntaxNode> BuildSyntax(IStatementCommentWhite item)
@@ -27,8 +27,8 @@ public override IEnumerable<SyntaxNode> BuildSyntax(IStatementCommentWhite item)
var itemAsT = item as IInvocationStatement;
var expressionSyntax = RDomCSharpFactory.Factory.BuildSyntax(itemAsT.Invocation);
var node = SyntaxFactory.ExpressionStatement((ExpressionSyntax)expressionSyntax);
- return new SyntaxNode[] { RoslynUtilities.Format(node) };
+ return item.PrepareForBuildSyntaxOutput(node);
}
public override FactoryPriority Priority
View
3  RoslynDomCSharpFactories/FactoriesForStatements/RDomReturnStatementFactory.cs
@@ -35,7 +35,8 @@ public override IEnumerable<SyntaxNode> BuildSyntax(IStatementCommentWhite item)
var returnExpressionSyntax = RDomCSharpFactory.Factory.BuildSyntax(itemAsT.Return);
node = node.WithExpression((ExpressionSyntax)returnExpressionSyntax);
}
- return new SyntaxNode[] { RoslynUtilities.Format(node) };
+
+ return item.PrepareForBuildSyntaxOutput(node);
}
}
}
View
3  RoslynDomCSharpFactories/FactoriesForStatements/RDomVariableDeclarationtFactory.cs
@@ -67,7 +67,8 @@ public override IEnumerable<SyntaxNode> BuildSyntax(IMisc item)
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) };
+
+ return item.PrepareForBuildSyntaxOutput(node);
}
}
}
View
9 RoslynDomCSharpFactories/RoslynCSharpUtilities.cs
@@ -84,14 +84,7 @@ public static SyntaxKind SyntaxKindFromLiteralKind(LiteralKind literalKind, obje
}
}
- public static SyntaxNode Format(SyntaxNode node)
- {
- var span = node.FullSpan;
- node = Formatter.Format(node, span, new CustomWorkspace());
- return node;
- }
-
- public static string Simplify(SyntaxNode node)
+ public static string Simplify(SyntaxNode node)
{
var source = node.ToString();
var projectId = ProjectId.CreateNewId();
View
3  RoslynDomCommon/Interfaces_Statements/IAssignmentStatement.cs
@@ -2,9 +2,10 @@
namespace RoslynDom.Common
{
- public interface IAssignmentStatement : IStatement, IDom<IAssignmentStatement >, IHasName
+ public interface IAssignmentStatement : IStatement, IDom<IAssignmentStatement >
{
IExpression Expression { get; set; }
+ IExpression Left { get; set; }
}
}
View
15 RoslynDomCommon/Interfaces_Statements/IDoWhileStatement.cs
@@ -1,15 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace RoslynDom.Common
-{
- public interface IDoWhileStatement :ILoop<IDoWh>
- {
- IExpression Condition { get; set; }
- bool HasBlock { get; set; }
- bool TestAtEnd { get; set; }
- }
-}
View
2  RoslynDomCommon/Interfaces_Statements/IInvocationStatement.cs
@@ -4,7 +4,7 @@ namespace RoslynDom.Common
{
public interface IInvocationStatement : IStatement , IDom<IInvocationStatement>
{
- IExpression Invocation { get; set; } // NOt ready to dive here yet
+ IExpression Invocation { get; set; } // Not ready to dive here yet
}
}
View
5 RoslynDomRDomCommon/RDomBaseFactoryHelper.cs
@@ -12,11 +12,6 @@ public abstract class RDomFactoryHelper
{
// WARNING: At present you must register all factories before retrieving any.
private static FactoryProvider factoryProvider = new FactoryProvider();
- // TODO: Determine whether we need to use a caching strategy
- //private static IRDomFactory<IAttributeFactory> attributeFactory;
- //private static IRDomFactory<ICommentWhiteFactory> commentWhiteFactory;
- //private static IRDomFactory<IPublicAnnotation> publicAnnotationFactory;
- //private static IRDomFactory<IStructuredDocumentation> structuredDocumentationFactory;
private static List<Tuple<Type, RDomFactoryHelper>> registration = new List<Tuple<Type, RDomFactoryHelper>>();
public static void Register<TKind>(RDomFactoryHelper<TKind> factoryHelper)
View
22 RoslynDomTests/BugResponseTests.cs
@@ -1,4 +1,6 @@
-using Microsoft.VisualStudio.TestTools.UnitTesting;
+using System.Linq;
+using Microsoft.CodeAnalysis;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
using RoslynDom;
using RoslynDom.CSharp;
@@ -23,5 +25,23 @@ public class MyClass
Assert.IsFalse (root.PublicAnnotations.HasPublicAnnotation("_xf_OutputForEach"));
}
+ [TestMethod, TestCategory(BugResponseCategory)] // #46
+ public void Can_parse_for_property_bug_46()
+ {
+ var csharpCode = @"
+ public class MyClass
+ {
+ protected int _flotDialogue
+ {
+ get { return MyStaticClass1._flotDialogue; }
+ set { MyStaticClass1._flotDialogue = value; }
+ }
+ }";
+ var root = RDomCSharpFactory.Factory.GetRootFromString(csharpCode);
+ var symbol = ((RDomProperty)root.Classes.First().Properties.First()).TypedSymbol as IPropertySymbol;
+ Assert.IsNotNull(symbol);
+ Assert.AreEqual("_flotDialogue", symbol.Name);
+ }
+
}
}
View
118 RoslynDomTests/FactoryTests.cs
@@ -96,7 +96,7 @@ namespace testing.Namespace1
Assert.IsNotNull(root);
Assert.AreEqual(1, root.Namespaces.Count());
}
-#endregion
+ #endregion
#region symbol tests
[TestMethod]
@@ -245,7 +245,7 @@ namespace testing.Namespace1
{ }
";
var root = RDomCSharpFactory.Factory.GetRootFromString(csharpCode);
- var symbol = ((RDomNamespace)root.Namespaces.First()).TypedSymbol as INamespaceSymbol ;
+ var symbol = ((RDomNamespace)root.Namespaces.First()).TypedSymbol as INamespaceSymbol;
Assert.AreEqual("Namespace1", symbol.Name);
Assert.IsNotNull(symbol);
}
@@ -273,7 +273,7 @@ public enum MyEnum
{ }
";
var root = RDomCSharpFactory.Factory.GetRootFromString(csharpCode);
- var symbol = ((RDomEnum )root.Enums.First()).TypedSymbol as INamedTypeSymbol ;
+ var symbol = ((RDomEnum)root.Enums.First()).TypedSymbol as INamedTypeSymbol;
Assert.IsNotNull(symbol);
Assert.AreEqual("MyEnum", symbol.Name);
}
@@ -287,7 +287,7 @@ public struct MyStruct
{ }
";
var root = RDomCSharpFactory.Factory.GetRootFromString(csharpCode);
- var symbol = ((RDomStructure )root.Structures.First()).TypedSymbol as INamedTypeSymbol;
+ var symbol = ((RDomStructure)root.Structures.First()).TypedSymbol as INamedTypeSymbol;
Assert.IsNotNull(symbol);
Assert.AreEqual("MyStruct", symbol.Name);
}
@@ -301,21 +301,21 @@ public interface MyInterface
{ }
";
var root = RDomCSharpFactory.Factory.GetRootFromString(csharpCode);
- var symbol = ((RDomInterface )root.Interfaces.First()).TypedSymbol as INamedTypeSymbol;
+ var symbol = ((RDomInterface)root.Interfaces.First()).TypedSymbol as INamedTypeSymbol;
Assert.IsNotNull(symbol);
Assert.AreEqual("MyInterface", symbol.Name);
}
[TestMethod]
- [TestCategory(TypedSymbolCategory)]
+ [TestCategory(TypedSymbolCategory)]
public void Can_get_typed_symbol_for_field()
{
var csharpCode = @"
public class MyClass
{ public int myField; }";
var root = RDomCSharpFactory.Factory.GetRootFromString(csharpCode);
- var symbol = ((RDomField)root.Classes.First().Fields.First()).TypedSymbol as IFieldSymbol ;
+ var symbol = ((RDomField)root.Classes.First().Fields.First()).TypedSymbol as IFieldSymbol;
Assert.IsNotNull(symbol);
Assert.AreEqual("myField", symbol.Name);
}
@@ -515,7 +515,7 @@ public class Foo
#endregion
#region typedSyntax tests
- [TestMethod,TestCategory(TypedSyntaxCategory)]
+ [TestMethod, TestCategory(TypedSyntaxCategory)]
public void Can_get_typedSyntax_for_namespace()
{
var csharpCode = @"
@@ -528,7 +528,7 @@ namespace testing.Namespace1
Assert.IsTrue(typedSyntax is NamespaceDeclarationSyntax);
}
- [TestMethod,TestCategory(TypedSyntaxCategory)]
+ [TestMethod, TestCategory(TypedSyntaxCategory)]
public void Can_get_typedSyntax_for_class()
{
var csharpCode = @"
@@ -541,7 +541,7 @@ public class MyClass
Assert.IsTrue(typedSyntax is ClassDeclarationSyntax);
}
- [TestMethod,TestCategory(TypedSyntaxCategory)]
+ [TestMethod, TestCategory(TypedSyntaxCategory)]
public void Can_get_typedSyntax_for_enum()
{
var csharpCode = @"
@@ -554,7 +554,7 @@ public enum MyEnum
Assert.IsTrue(typedSyntax is EnumDeclarationSyntax);
}
- [TestMethod,TestCategory(TypedSyntaxCategory)]
+ [TestMethod, TestCategory(TypedSyntaxCategory)]
public void Can_get_typedSyntax_for_struct()
{
var csharpCode = @"
@@ -567,7 +567,7 @@ public struct MyStruct
Assert.IsTrue(typedSyntax is StructDeclarationSyntax);
}
- [TestMethod,TestCategory(TypedSyntaxCategory)]
+ [TestMethod, TestCategory(TypedSyntaxCategory)]
public void Can_get_typedSyntax_for_interface()
{
var csharpCode = @"
@@ -581,7 +581,7 @@ public interface MyInterface
}
- [TestMethod,TestCategory(TypedSyntaxCategory)]
+ [TestMethod, TestCategory(TypedSyntaxCategory)]
public void Can_get_typedSyntax_for_field()
{
var csharpCode = @"
@@ -590,10 +590,10 @@ public class MyClass
var root = RDomCSharpFactory.Factory.GetRootFromString(csharpCode);
var typedSyntax = ((RDomField)root.Classes.First().Fields.First()).TypedSyntax;
Assert.IsNotNull(typedSyntax);
- Assert.IsTrue(typedSyntax is VariableDeclaratorSyntax );
+ Assert.IsTrue(typedSyntax is VariableDeclaratorSyntax);
}
- [TestMethod,TestCategory(TypedSyntaxCategory)]
+ [TestMethod, TestCategory(TypedSyntaxCategory)]
public void Can_get_typedSyntax_for_property()
{
var csharpCode = @"
@@ -605,7 +605,7 @@ public class MyClass
Assert.IsTrue(typedSyntax is PropertyDeclarationSyntax);
}
- [TestMethod,TestCategory(TypedSyntaxCategory)]
+ [TestMethod, TestCategory(TypedSyntaxCategory)]
public void Can_get_typedSyntax_for_method()
{
var csharpCode = @"
@@ -617,7 +617,7 @@ public class MyClass
Assert.IsTrue(typedSyntax is MethodDeclarationSyntax);
}
- [TestMethod,TestCategory(TypedSyntaxCategory)]
+ [TestMethod, TestCategory(TypedSyntaxCategory)]
public void Can_get_typedSyntax_for_nestedType()
{
var csharpCode = @"
@@ -631,7 +631,7 @@ public class MyClass
#endregion
#region stemContainer
- [TestMethod,TestCategory(StemContainerCategory)]
+ [TestMethod, TestCategory(StemContainerCategory)]
public void Can_get_namespaces()
{
var csharpCode = @"
@@ -645,7 +645,7 @@ namespace testing.Namespace2
Assert.AreEqual(2, root.Namespaces.Count());
}
- [TestMethod,TestCategory(StemContainerCategory)]
+ [TestMethod, TestCategory(StemContainerCategory)]
public void Can_get_classes()
{
var csharpCode = @"
@@ -660,7 +660,7 @@ class Class3
Assert.AreEqual(3, root.Classes.Count());
}
- [TestMethod,TestCategory(StemContainerCategory)]
+ [TestMethod, TestCategory(StemContainerCategory)]
public void Can_get_interfaces()
{
var csharpCode = @"
@@ -687,7 +687,7 @@ interface Interface
// Assert.AreEqual(1, root.Interfaces.First().Members.Count());
// }
- [TestMethod,TestCategory(StemContainerCategory)]
+ [TestMethod, TestCategory(StemContainerCategory)]
public void Can_get_structures()
{
var csharpCode = @"
@@ -701,7 +701,7 @@ struct Struct1
Assert.AreEqual(2, root.Structures.Count());
}
- [TestMethod,TestCategory(StemContainerCategory)]
+ [TestMethod, TestCategory(StemContainerCategory)]
public void Can_get_enums()
{
var csharpCode = @"
@@ -714,7 +714,7 @@ enum B
Assert.AreEqual(2, root.Enums.Count());
}
- [TestMethod,TestCategory(StemContainerCategory)]
+ [TestMethod, TestCategory(StemContainerCategory)]
public void Can_get_usings()
{
var csharpCode = @"
@@ -740,7 +740,7 @@ namespace Foo
Assert.AreEqual(2, root.Namespaces.First().Usings.Count());
}
- [TestMethod,TestCategory(StemContainerCategory)]
+ [TestMethod, TestCategory(StemContainerCategory)]
public void Can_get_types()
{
var csharpCode = @"
@@ -806,15 +806,19 @@ struct K
{ }";
var root = RDomCSharpFactory.Factory.GetRootFromString(csharpCode);
Assert.AreEqual(11, root.Types.Count());
- Assert.AreEqual(17, root.StemMembersAll.Count());
+
+ // Check that all were found
var members = root.StemMembersAll.ToArray();
- Assert.IsInstanceOfType(members[3], typeof(IVerticalWhitespace ));
+ Assert.AreEqual(17, members.Count());
+
+ // Check some reality stuff
+ Assert.IsInstanceOfType(members[3], typeof(IVerticalWhitespace));
Assert.IsInstanceOfType(members[4], typeof(IComment));
Assert.IsInstanceOfType(members[7], typeof(IComment));
Assert.IsInstanceOfType(members[9], typeof(IComment));
Assert.IsInstanceOfType(members[12], typeof(IComment));
Assert.AreEqual(1, ((IVerticalWhitespace)members[3]).Count);
- Assert.IsFalse(((IVerticalWhitespace)members[3]).IsElastic );
+ Assert.IsFalse(((IVerticalWhitespace)members[3]).IsElastic);
var expected = "Single line comment with whitespace";
Assert.AreEqual(expected, ((IComment)members[4]).Text);
Assert.IsFalse(((IComment)members[4]).IsMultiline);
@@ -827,6 +831,11 @@ struct K
expected = "Multiline comment \r\n on multiple line";
Assert.AreEqual(expected, ((IComment)members[12]).Text);
Assert.IsTrue(((IComment)members[12]).IsMultiline);
+
+ // Check output
+ expected = "";
+ var actual = RDomCSharpFactory.Factory.BuildSyntax(root);
+ Assert.AreEqual(expected, actual);
}
#endregion
@@ -837,30 +846,32 @@ public void Can_get_members_with_comments_and_whitespace_from_typeContainer()
public class Bar
{
private string firstName;
- private string lastName;
-
- public string Foo()
- {
-
- var ret = lastName;
- ret = Foo();
- ret = ""xyz"";
// Comment and whitespace
- var xx = new String('a', 4);
- ret = ""abc"" + Foo();
- if (!string.IsNullOrEmpty(firstName))
- { ret = firstName + lastName; }
+ private string lastName;
+
// comment
- var x = "", "";
- uint y = 42;
- x = lastName + x + firstName;
- Foo2(x);
- return x;
- }
+ public string Foo()
+ {}
}";
var root = RDomCSharpFactory.Factory.GetRootFromString(csharpCode);
- Assert.AreEqual(11, root.Types.Count());
+
+ // Check that all were found
+ var members = root.Classes.First().MembersAll.ToArray();
+ Assert.AreEqual(7, members.Count());
+
+ // Check some reality stuff
+ Assert.AreEqual(1, ((IVerticalWhitespace)members[1]).Count);
+ Assert.IsFalse(((IVerticalWhitespace)members[1]).IsElastic);
+ var expected = "Comment and whitespace";
+ Assert.AreEqual(expected, ((IComment)members[2]).Text);
+ Assert.IsFalse(((IComment)members[2]).IsMultiline);
+
+ // Check output
+ expected = "";
+ var actual = RDomCSharpFactory.Factory.BuildSyntax(root);
+ Assert.AreEqual(expected, actual);
+ Assert.Fail();
}
[TestMethod, TestCategory(StemContainerCategory)]
@@ -893,9 +904,22 @@ public string Foo()
}
}";
var root = RDomCSharpFactory.Factory.GetRootFromString(csharpCode);
+
+ // Check that all were found
var statements = root.Classes.First().Methods.First().StatementsAll.ToArray();
Assert.AreEqual(15, statements.Count());
- Assert.Fail();
+
+ // Check some reality stuff
+ Assert.AreEqual(1, ((IVerticalWhitespace)statements[4]).Count);
+ Assert.IsFalse(((IVerticalWhitespace)statements[4]).IsElastic);
+ var expected = "Comment and whitespace";
+ Assert.AreEqual(expected, ((IComment)statements[5]).Text);
+ Assert.IsFalse(((IComment)statements[5]).IsMultiline);
+
+ // Check output
+ expected = "";
+ var actual = RDomCSharpFactory.Factory.BuildSyntax(root);
+ Assert.AreEqual(expected, actual);
}
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.