Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Cleanup and work on statements

  • Loading branch information...
commit 58f147fe9b9d3455c32b5a437a72f967df34cc09 1 parent afd2ac5
@KathleenDollard authored
Showing with 654 additions and 444 deletions.
  1. BIN  Documentation/Structural Interrogation Walk-throughs.docx
  2. +6 −2 Readme.md
  3. +165 −37 RoslynDom/RDomFactory.cs
  4. +7 −1 RoslynDom/RoslynDom.csproj
  5. +42 −0 RoslynDom/StatementImplementations/RDomAssignmentStatement.cs
  6. +11 −25 RoslynDom/{Implementations/RDomStatement.cs → StatementImplementations/RDomBaseBlock.cs}
  7. +37 −0 RoslynDom/StatementImplementations/RDomBlockStatement.cs
  8. +53 −0 RoslynDom/StatementImplementations/RDomDeclarationStatement.cs
  9. +82 −0 RoslynDom/StatementImplementations/RDomIfStatement.cs
  10. +42 −0 RoslynDom/StatementImplementations/RDomReturnStatemen.cs
  11. +35 −0 RoslynDom/StatementImplementations/RDomStatement.cs
  12. +0 −1  RoslynDomCommon/BaseInterfaces/IStatement.cs
  13. +12 −10 RoslynDomCommon/Enums/StatementKind.cs
  14. +3 −3 RoslynDomCommon/Interfaces/IAttribute.cs
  15. 0  RoslynDomCommon/InterfacesForStatements/{IContinue.cs → IContinueStatement.cs}
  16. +4 −4 RoslynDomCommon/InterfacesForStatements/IDeclarationStatement.cs
  17. +9 −0 RoslynDomCommon/InterfacesForStatements/IEmptyStatement.cs
  18. +3 −4 RoslynDomCommon/RoslynDomCommon.csproj
  19. +0 −29 RoslynDomCommon/SameIntentInitial/SameIIntentClass.cs
  20. +0 −21 RoslynDomCommon/SameIntentInitial/SameIntentBaseType.cs
  21. +0 −113 RoslynDomCommon/SameIntentInitial/SameIntentCommon.cs
  22. +0 −24 RoslynDomCommon/SameIntentInitial/SameIntentFactory.cs
  23. +0 −29 RoslynDomCommon/SameIntentInitial/SameIntentHelpers.cs
  24. +0 −22 RoslynDomCommon/SameIntentInitial/SameIntentNamespace.cs
  25. +0 −22 RoslynDomCommon/SameIntentInitial/SameIntentNestedContainer.cs
  26. +0 −21 RoslynDomCommon/SameIntentInitial/SameIntentRoot.cs
  27. +0 −22 RoslynDomCommon/SameIntentInitial/SameIntentStemContainer.cs
  28. +73 −29 RoslynDomExampleTests/Interrogation.cs
  29. +4 −4 RoslynDomExampleTests/RoslynDomLoad.cs
  30. +3 −3 RoslynDomExampleTests/Scenario_PatternMatchingSelection.cs
  31. +7 −3 RoslynDomExampleTests/TestFile.cs
  32. +3 −3 RoslynDomExampleTests/WorkspaceTests.cs
  33. +2 −1  RoslynDomTests/AttributeTests.cs
  34. +14 −6 RoslynDomTests/CopyTests.cs
  35. +37 −5 RoslynDomTests/PlaySpace.cs
View
BIN  Documentation/Structural Interrogation Walk-throughs.docx
Binary file not shown
View
8 Readme.md
@@ -1,11 +1,15 @@
-RoslynDOM
+RoslynDom
=========
-This provides programmer friendly view of your application via the Roslyn AST, currently in a very preliminary form
+This provides programmer friendly view of your application via the .NET Compiler Platform (code named Roslyn) from Microsoft. This is an early, experimental release.
Available on NuGet
---
[Install-Package RoslynDOM -Pre](https://www.nuget.org/packages/RoslynDOM/)
+More info
+---
+You can find more info on [my blog] (http://msmvps.com/blogs/kathleen/default.aspx)
+
Examples
---
```C#
View
202 RoslynDom/RDomFactory.cs
@@ -87,6 +87,26 @@ private static IUsing MakeUsingDirective(UsingDirectiveSyntax x)
return (list.Count() > startCount);
}
+ private static bool DoStatement<T>(StatementSyntax val,
+ Func<T, IStatement> doAction, out IStatement retValue)
+ where T : class
+ {
+ var item = val as T;
+ retValue = item != null ? doAction(item) : null;
+ return (retValue != null);
+ }
+
+ private static bool DoStatements<T>(StatementSyntax val,
+ Action<T, List<IStatement>> doAction, List<IStatement> list)
+ where T : class
+ {
+ var item = val as T;
+ if (item == null) return false;
+ var startCount = list.Count();
+ doAction(item, list);
+ return (list.Count() > startCount);
+ }
+
/// <summary>
/// Creates namespace and class
/// </summary>
@@ -177,9 +197,109 @@ private static IParameter MakeParameter(ParameterSyntax rawParm)
private static IStatement MakeStatement(StatementSyntax rawStatement)
{
- var statements = ListUtilities.MakeList(rawStatement, x => GetStatements(x), x => MakeStatement(x));
- var publicAnnotations = GetPublicAnnotations(rawStatement).ToArray();
- return new RDomStatement(rawStatement, statements, publicAnnotations);
+ IStatement ret;
+ // The action happens in DoMember. I felt it read better with else than negation and it made copying new lines easier
+ if (DoStatement<BlockSyntax>(rawStatement, MakeBlockStatement, out ret)) { }
+ else if (DoStatement<IfStatementSyntax>(rawStatement, MakeIfStatement, out ret)) { }
+ return ret as IStatement;
+
+ //ForEach,
+ //For,
+ //Empty,
+ //Return,
+ //Declaration,
+ //Try,
+
+ ////While, variation of Do
+ ////Else, characteristic of If
+ ////Using, characteristic of Block
+ ////Catch, characteristic of Try
+ ////Switch, // can this be handled as a special case of if?
+ //Break, // probably have to support
+ //Continue, // probably have to support
+ //Throw, // probably have to support
+
+ ////Expression statements, // break this appart into two kinds
+ //Invocation,
+ //Assignment,
+
+ //Special // (platform or lanuguage specific)
+ ////Checked (block)
+ ////Lock,
+ ////Yield, Split into YieldBreak and YieldReturn (expression)
+
+ // Planning to avoid unless someone has a scenario
+ //Unsafe,
+ //Fixed,
+ //Goto,
+ //Labeled,
+ }
+
+ private static IBlockStatement MakeBlockStatement(BlockSyntax rawBlock)
+ {
+ var publicAnnotations = GetPublicAnnotations(rawBlock).ToArray();
+ var statements = ListUtilities.MakeList(rawBlock, x => x.Statements, x => MakeStatement(x));
+ return new RDomBlockStatement(rawBlock, statements, publicAnnotations);
+ }
+
+ private static IIfStatement MakeIfStatement(IfStatementSyntax rawIf)
+ {
+ var publicAnnotations = GetPublicAnnotations(rawIf).ToArray();
+ var hasBlock = false;
+ var statements = new List<IStatement>();
+ var block = rawIf.Statement as BlockSyntax;
+ if (block != null)
+ {
+ hasBlock = true;
+ statements.AddRange(ListUtilities.MakeList(rawIf, x => block.Statements, x => MakeStatement(x)));
+ }
+ else
+ { statements.Add(MakeStatement(rawIf.Statement)); }
+ IEnumerable<IIfStatement> elses = null;
+ if (rawIf.Else != null)
+ { elses = MakeElses(rawIf.Else.Statement); }
+ return new RDomIfStatement(rawIf, hasBlock, statements, elses, publicAnnotations);
+ }
+
+ private static IEnumerable<IIfStatement> MakeElses(StatementSyntax rawElseStatement)
+ {
+ var publicAnnotations = GetPublicAnnotations(rawElseStatement).ToArray();
+ var elses = new List<IIfStatement>();
+ var elseStatement = rawElseStatement as IfStatementSyntax;
+ if (elseStatement != null)
+ {
+ elses.Add(MakeIfStatement(elseStatement));
+ elses.AddRange(MakeElses(elseStatement.Else.Statement));
+ }
+ else
+ {
+ var statements = new List<IStatement>();
+ bool hasBlock = false;
+ var blockElseStatement = rawElseStatement as BlockSyntax;
+ if (blockElseStatement != null)
+ {
+ hasBlock = true;
+ statements.AddRange(ListUtilities.MakeList(rawElseStatement, x => blockElseStatement.Statements, x => MakeStatement(x)));
+ }
+ else
+ { statements.Add(MakeStatement(rawElseStatement)); }
+ elses.Add(new RDomIfStatement(null, hasBlock, statements, null, publicAnnotations));
+
+ }
+ return elses;
+ }
+
+ private static IEnumerable<IDeclarationStatement> MakeDeclarationStatement(LocalDeclarationStatementSyntax rawDeclaration)
+ {
+ var list = new List<IDeclarationStatement>();
+ var declaration = rawDeclaration.Declaration;
+ var variables = declaration.Variables.OfType<VariableDeclaratorSyntax>();
+ foreach (var variable in variables)
+ {
+ var publicAnnotations = GetPublicAnnotations(rawDeclaration).ToArray();
+ list.Add(new RDomDeclarationStatement(rawDeclaration, declaration, variable, publicAnnotations));
+ }
+ return list;
}
private static IEnumerable<StatementSyntax> GetStatements(MethodDeclarationSyntax rawMethod)
@@ -188,47 +308,55 @@ private static IEnumerable<StatementSyntax> GetStatements(MethodDeclarationSynta
return rawMethod.Body.Statements;
}
+
private static IEnumerable<StatementSyntax> GetStatements(StatementSyntax rawStatement)
{
var list = new List<StatementSyntax>();
-
- // These have nested block syntax
+ // This handles method and property
if (LoadStatementListFromList<BlockSyntax>(rawStatement, x => x.Statements, list)) { return list; }
- if (LoadStatementListFromList<UnsafeStatementSyntax>(rawStatement, x => x.Block.Statements, list)) { return list; }
- if (LoadStatementListFromList<CheckedStatementSyntax>(rawStatement, x => x.Block.Statements, list)) { return list; }
- if (LoadStatementListFromList<TryStatementSyntax>(rawStatement, x => x.Block.Statements, list)) { return list; }
-
- // These have a statement which often, but not always, holds a nested block
- if (LoadStatementListFromItem<DoStatementSyntax>(rawStatement, x => x.Statement, list)) { return list; }
- if (LoadStatementListFromItem<ForEachStatementSyntax>(rawStatement, x => x.Statement, list)) { return list; }
- if (LoadStatementListFromItem<ForStatementSyntax>(rawStatement, x => x.Statement, list)) { return list; }
- if (LoadStatementListFromItem<LockStatementSyntax>(rawStatement, x => x.Statement, list)) { return list; }
- if (LoadStatementListFromItem<WhileStatementSyntax>(rawStatement, x => x.Statement, list)) { return list; }
- if (LoadStatementListFromItem<UsingStatementSyntax>(rawStatement, x => x.Statement, list)) { return list; }
- if (LoadStatementListFromItem<IfStatementSyntax>(rawStatement, x => x.Statement, list)) { return list; } // if has a second block for else
-
- // These do not have nested blocksyntax or statements
- // BreakStatementSyntax
- // ContinueStatementSyntax
- // EmptyStatementSyntax
- // ExpressionStatementSyntax
- // LocalDeclarationStatement
- // ReturnStatementSyntax
- // ThrowStatementSyntax
- // YieldStatementSyntax
-
- // This is a very weird special case
- // SwitchStatementSyntax
-
- // These are items I currently do not plan to support - although need to confirm that switch doesn't use labeled statements
- // FixedStatementSyntax
- // GotoStatementSyntax
- // LabeledStatementSyntax
+
+ //// These have nested block syntax
+ //if (LoadStatementListFromList<BlockSyntax>(rawStatement, x => x.Statements, list)) { return list; }
+ //if (LoadStatementListFromList<CheckedStatementSyntax>(rawStatement, x => x.Block.Statements, list)) { return list; }
+
+ //// These have a statement which often, but not always, holds a nested block
+ //if (LoadStatementListFromItem<DoStatementSyntax>(rawStatement, x => x.Statement, list)) { return list; }
+ //if (LoadStatementListFromItem<ForEachStatementSyntax>(rawStatement, x => x.Statement, list)) { return list; }
+ //if (LoadStatementListFromItem<ForStatementSyntax>(rawStatement, x => x.Statement, list)) { return list; }
+ //if (LoadStatementListFromItem<LockStatementSyntax>(rawStatement, x => x.Statement, list)) { return list; }
+ //if (LoadStatementListFromItem<WhileStatementSyntax>(rawStatement, x => x.Statement, list)) { return list; }
+ //if (LoadStatementListFromItem<UsingStatementSyntax>(rawStatement, x => x.Statement, list)) { return list; }
+
+ //// These have more than one statement block
+ //if (LoadStatementListFromItem<IfStatementSyntax>(rawStatement, x => x.Statement, list)) { return list; } // if has a second block for else
+ //if (LoadStatementListFromList<TryStatementSyntax>(rawStatement, x => x.Block.Statements, list)) { return list; }
+
+ //// These do not have nested blocksyntax or statements
+ //// BreakStatementSyntax
+ //// ContinueStatementSyntax
+ //// EmptyStatementSyntax
+ //// ExpressionStatementSyntax
+ //// LocalDeclarationStatement
+ //// ReturnStatementSyntax
+ //// ThrowStatementSyntax
+ //// YieldStatementSyntax
+
+ //// This is a very weird special case
+ //// SwitchStatementSyntax
+
+ //// These are items I currently do not plan to support - although need to confirm that switch doesn't use labeled statements
+ //// FixedStatementSyntax
+ //// GotoStatementSyntax
+ //// LabeledStatementSyntax
+ //// UnsafeStatementSyntax
return list;
}
- private static bool LoadStatementListFromList<T>(StatementSyntax rawStatement, Func<T, IEnumerable<StatementSyntax>> getList, List<StatementSyntax> list)
+ private static bool LoadStatementListFromList<T>(
+ StatementSyntax rawStatement,
+ Func<T, IEnumerable<StatementSyntax>> getList,
+ List<StatementSyntax> list)
where T : StatementSyntax
{
var typed = rawStatement as T;
@@ -256,7 +384,7 @@ private static IMember MakeProperty(PropertyDeclarationSyntax rawProperty)
return new RDomProperty(rawProperty, parms, getAccessor, setAccessor, publicAnnotations);
}
- private static IAccessor MakeAccessor(AccessorDeclarationSyntax rawAccessor)
+ private static IAccessor MakeAccessor(AccessorDeclarationSyntax rawAccessor)
{
if (rawAccessor == null) return null;
var statements = ListUtilities.MakeList(rawAccessor, x => GetStatements(rawAccessor.Body), x => MakeStatement(x));
View
8 RoslynDom/RoslynDom.csproj
@@ -72,7 +72,10 @@
<Compile Include="Implementations\RDomInterface.cs" />
<Compile Include="Implementations\RDomInvalidTypeMember.cs" />
<Compile Include="Implementations\RDomAccessor.cs" />
- <Compile Include="Implementations\RDomStatement.cs" />
+ <Compile Include="StatementImplementations\RDomAssignmentStatement.cs" />
+ <Compile Include="StatementImplementations\RDomReturnStatemen.cs" />
+ <Compile Include="StatementImplementations\RDomDeclarationStatement.cs" />
+ <Compile Include="StatementImplementations\RDomStatement.cs" />
<Compile Include="Implementations\RDomMethod.cs" />
<Compile Include="Implementations\RDomNamespace.cs" />
<Compile Include="Implementations\RDomParameter.cs" />
@@ -88,6 +91,9 @@
<Compile Include="RDomFactory.cs" />
<Compile Include="RoslynUtilities.cs" />
<Compile Include="RoslynDomUtilities.cs" />
+ <Compile Include="StatementImplementations\RDomBaseBlock.cs" />
+ <Compile Include="StatementImplementations\RDomIfStatement.cs" />
+ <Compile Include="StatementImplementations\RDomBlockStatement.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
View
42 RoslynDom/StatementImplementations/RDomAssignmentStatement.cs
@@ -0,0 +1,42 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using Microsoft.CodeAnalysis;
+using Microsoft.CodeAnalysis.CSharp;
+using Microsoft.CodeAnalysis.CSharp.Syntax;
+using RoslynDom.Common;
+
+namespace RoslynDom
+{
+ public class RDomAssignmentStatement : RDomStatement, IAssignmentStatement
+ {
+ private VariableDeclarationSyntax _variableSyntax;
+ private VariableDeclaratorSyntax _declaratorSyntax;
+
+
+ internal RDomAssignmentStatement(
+ ExpressionStatementSyntax rawExpression,
+ params PublicAnnotation[] publicAnnotations)
+ : base(rawExpression, StatementKind.Assignment, publicAnnotations)
+ {
+ Initialize();
+ }
+
+ internal RDomAssignmentStatement(RDomAssignmentStatement oldRDom)
+ : base(oldRDom)
+ { }
+
+ protected override void Initialize()
+ {
+ base.Initialize();
+ }
+
+ public override StatementSyntax BuildSyntax()
+ {
+ return null;
+ }
+
+ public string VarName { get; set; }
+ public IExpression Expression { get; set; }
+ }
+}
View
36 RoslynDom/Implementations/RDomStatement.cs → RoslynDom/StatementImplementations/RDomBaseBlock.cs
@@ -7,56 +7,42 @@
namespace RoslynDom
{
- public class RDomStatement : RDomBase<IStatement, StatementSyntax, ISymbol>, IStatement
+ public abstract class RDomBaseBlock : RDomStatement
{
private IList<IStatement> _statements = new List<IStatement>();
- internal RDomStatement(
+ internal RDomBaseBlock(
StatementSyntax rawItem,
IEnumerable<IStatement> statements,
+ StatementKind statementKind,
params PublicAnnotation[] publicAnnotations)
- : base(rawItem, publicAnnotations)
+ : base(rawItem, statementKind, publicAnnotations)
{
foreach (var statement in statements)
- { AddStatement(statement); }
- Initialize();
+ { AddOrMoveStatement(statement); }
}
- internal RDomStatement(RDomStatement oldRDom)
+ internal RDomBaseBlock(RDomBaseBlock oldRDom)
: base(oldRDom)
{
var newStatements = RoslynDomUtilities.CopyMembers(oldRDom._statements);
foreach (var statement in newStatements)
- { AddStatement(statement); }
-
- IsBlock = oldRDom.IsBlock;
- StatementKind = oldRDom.StatementKind;
- }
-
- protected override void Initialize()
- {
- base.Initialize();
- IsBlock = _statements.Count() > 1 || TypedSyntax is BlockSyntax;
+ { AddOrMoveStatement(statement); }
}
public override StatementSyntax BuildSyntax()
{
- return TypedSyntax;
+ return null;
}
-
+
public void RemoveStatement(IStatement statement)
{ _statements.Remove(statement); }
- public void AddStatement(IStatement statement)
+ public void AddOrMoveStatement(IStatement statement)
{ _statements.Add(statement); }
-
- public bool IsBlock { get; set; }
-
- public StatementKind StatementKind { get; set; }
-
public IEnumerable<IStatement> Statements
{ get { return _statements; } }
-
+
}
}
View
37 RoslynDom/StatementImplementations/RDomBlockStatement.cs
@@ -0,0 +1,37 @@
+using System.Collections.Generic;
+using System.Linq;
+using Microsoft.CodeAnalysis;
+using Microsoft.CodeAnalysis.CSharp;
+using Microsoft.CodeAnalysis.CSharp.Syntax;
+using RoslynDom.Common;
+
+namespace RoslynDom
+{
+ public class RDomBlockStatement : RDomBaseBlock, IBlockStatement
+ {
+
+ internal RDomBlockStatement(
+ BlockSyntax rawItem,
+ IEnumerable<IStatement> statements,
+ params PublicAnnotation[] publicAnnotations)
+ : base(rawItem, statements, StatementKind.Block, publicAnnotations)
+ {
+ Initialize();
+ }
+
+ internal RDomBlockStatement(RDomBlockStatement oldRDom)
+ : base(oldRDom)
+ { }
+
+ protected override void Initialize()
+ {
+ base.Initialize();
+ }
+
+ public override StatementSyntax BuildSyntax()
+ {
+ return null;
+ }
+
+ }
+}
View
53 RoslynDom/StatementImplementations/RDomDeclarationStatement.cs
@@ -0,0 +1,53 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using Microsoft.CodeAnalysis;
+using Microsoft.CodeAnalysis.CSharp;
+using Microsoft.CodeAnalysis.CSharp.Syntax;
+using RoslynDom.Common;
+
+namespace RoslynDom
+{
+ public class RDomDeclarationStatement : RDomStatement, IDeclarationStatement
+ {
+ private VariableDeclarationSyntax _variableSyntax;
+ private VariableDeclaratorSyntax _declaratorSyntax;
+ internal RDomDeclarationStatement(
+ LocalDeclarationStatementSyntax rawDeclaration,
+ VariableDeclarationSyntax rawVariable,
+ VariableDeclaratorSyntax rawDeclarator,
+ params PublicAnnotation[] publicAnnotations)
+ : base(rawDeclaration, StatementKind.Declaration, publicAnnotations)
+ {
+ Initialize();
+ var Name = rawDeclarator.Identifier ;
+ _variableSyntax = rawVariable;
+ _declaratorSyntax = rawDeclarator;
+ //var Initilizer = rawVariable.Initializer;
+ // var Type = rawDeclaration.
+ }
+
+ internal RDomDeclarationStatement(RDomDeclarationStatement oldRDom)
+ : base(oldRDom)
+ { }
+
+ protected override void Initialize()
+ {
+ base.Initialize();
+ }
+
+ public override StatementSyntax BuildSyntax()
+ {
+ return null;
+ }
+
+ public IExpression Initializer { get; set; }
+
+ public IReferencedType Type { get; set; }
+
+ public bool IsImplicitlyTyped { get; set; }
+ public bool IsConst { get; set; }
+
+
+ }
+}
View
82 RoslynDom/StatementImplementations/RDomIfStatement.cs
@@ -0,0 +1,82 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using Microsoft.CodeAnalysis;
+using Microsoft.CodeAnalysis.CSharp;
+using Microsoft.CodeAnalysis.CSharp.Syntax;
+using RoslynDom.Common;
+
+namespace RoslynDom
+{
+ public class RDomIfStatement : RDomBaseBlock, IIfStatement
+ {
+ private IList<IIfStatement> _elses = new List<IIfStatement>();
+
+ internal RDomIfStatement(
+ IfStatementSyntax rawItem,
+ bool hasBlock,
+ IEnumerable<IStatement> statements,
+ IEnumerable<IIfStatement> elses,
+ params PublicAnnotation[] publicAnnotations)
+ : base(rawItem, statements, StatementKind.If, publicAnnotations)
+ {
+ HasBlock = hasBlock;
+ if (elses != null)
+ {
+ foreach (var elseItem in elses)
+ { AddOrMoveElse(elseItem); }
+ }
+ Initialize();
+ }
+
+ internal RDomIfStatement(RDomIfStatement oldRDom)
+ : base(oldRDom)
+ {
+ var newElses = RoslynDomUtilities.CopyMembers(oldRDom._elses);
+ foreach (var elseItem in newElses)
+ { AddOrMoveElse(elseItem); }
+ }
+
+ protected override void Initialize()
+ {
+ base.Initialize();
+ }
+
+ public override StatementSyntax BuildSyntax()
+ {
+ // TODO: Current work KAD
+ //var nameSyntax = SyntaxFactory.Identifier(Name);
+ //var statementsAsSyntax = Statements.Select(x => ((RDomStatement)x).BuildSyntax()).ToArray();
+ //StatementSyntax statement;
+ //if (HasBlock || this.Statements.Count() > 1)
+ //{ statement = SyntaxFactory.Block(statementsAsSyntax); }
+ //else if (this.Statements.Count() == 1)
+ //{ statement = statementsAsSyntax.First(); }
+ //else
+ //{ statement = SyntaxFactory.EmptyStatement(); }
+ //var condition = (Condition as RDomCondition).BuildSyntax();
+ //var node = SyntaxFactory.IfStatement(condition, statement);
+
+ //node = RoslynUtilities.UpdateNodeIfItemNotNull(BuildElseSyntax(), node, (n, item) => n.WithElse(item));
+
+ //return (StatementSyntax)RoslynUtilities.Format(node);
+ return null;
+ }
+
+
+
+ public ICondition Condition { get; set; }
+
+ public bool HasBlock { get; set; }
+
+ public void RemoveElse(IIfStatement statement)
+ { _elses.Remove(statement); }
+
+ public void AddOrMoveElse(IIfStatement statement)
+ { _elses.Add(statement); }
+
+ public IEnumerable<IIfStatement> Elses
+ { get { return _elses; } }
+
+ }
+}
View
42 RoslynDom/StatementImplementations/RDomReturnStatemen.cs
@@ -0,0 +1,42 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using Microsoft.CodeAnalysis;
+using Microsoft.CodeAnalysis.CSharp;
+using Microsoft.CodeAnalysis.CSharp.Syntax;
+using RoslynDom.Common;
+
+namespace RoslynDom
+{
+ public class RDomReturnStatement : RDomStatement, IReturnStatement
+ {
+ private VariableDeclarationSyntax _variableSyntax;
+ private VariableDeclaratorSyntax _declaratorSyntax;
+
+
+ internal RDomReturnStatement(
+ ReturnStatementSyntax rawReturn,
+ params PublicAnnotation[] publicAnnotations)
+ : base(rawReturn, StatementKind.Return, publicAnnotations)
+ {
+ Initialize();
+ // Return = expression
+ }
+
+ internal RDomReturnStatement(RDomReturnStatement oldRDom)
+ : base(oldRDom)
+ { }
+
+ protected override void Initialize()
+ {
+ base.Initialize();
+ }
+
+ public override StatementSyntax BuildSyntax()
+ {
+ return null;
+ }
+
+ public IExpression Return { get; set; }
+ }
+}
View
35 RoslynDom/StatementImplementations/RDomStatement.cs
@@ -0,0 +1,35 @@
+using System.Collections.Generic;
+using System.Linq;
+using Microsoft.CodeAnalysis;
+using Microsoft.CodeAnalysis.CSharp;
+using Microsoft.CodeAnalysis.CSharp.Syntax;
+using RoslynDom.Common;
+
+namespace RoslynDom
+{
+ public class RDomStatement : RDomBase<IStatement, StatementSyntax, ISymbol>, IStatement
+ {
+
+ internal RDomStatement(
+ StatementSyntax rawItem,
+ StatementKind statementKind,
+ params PublicAnnotation[] publicAnnotations)
+ : base(rawItem, publicAnnotations)
+ { StatementKind = statementKind; }
+
+ internal RDomStatement(RDomStatement oldRDom)
+ : base(oldRDom)
+ {
+ StatementKind = oldRDom.StatementKind;
+ }
+
+ public override StatementSyntax BuildSyntax()
+ {
+ return TypedSyntax;
+ }
+
+ public StatementKind StatementKind { get; set; }
+
+
+ }
+}
View
1  RoslynDomCommon/BaseInterfaces/IStatement.cs
@@ -8,7 +8,6 @@ namespace RoslynDom.Common
{
public interface IStatement : IDom<IStatement>
{
- bool IsBlock { get; }
StatementKind StatementKind { get; }
}
}
View
22 RoslynDomCommon/Enums/StatementKind.cs
@@ -7,32 +7,34 @@ public enum StatementKind
Do,
ForEach,
For,
- While,
If,
- Else,
Empty,
Return,
- LocalDeclaration,
+ Declaration,
Try,
- //Using, make characteristic of block
+ //While, variation of Do
+ //Else, characteristic of If
+ //Using, characteristic of Block
+ //Catch, characteristic of Try
+ //Switch, // can this be handled as a special case of if?
Break, // probably have to support
Continue, // probably have to support
Throw, // probably have to support
- Switch, // can this be handled as a special case of if?
- //Expression, // break this appart into two kinds
+ //Expression statements, // break this appart into two kinds
Invocation,
Assignment,
- Special
- //Checked,
+ Special // (platform or lanuguage specific)
+ //Checked (block)
//Lock,
+ //Yield, Split into YieldBreak and YieldReturn (expression)
+
+ // Planning to avoid unless someone has a scenario
//Unsafe,
- //Yield,
//Fixed,
//Goto,
//Labeled,
-
}
}
View
6 RoslynDomCommon/Interfaces/IAttribute.cs
@@ -4,10 +4,10 @@ namespace RoslynDom.Common
{
public interface IAttribute : IDom<IAttribute>
{
- // TODO: Determine how AllowMultiple will play
- // Not including Attribute usage, scope and other info about the attribute class at this point
+ // TODO: Consider: Determine how AllowMultiple will play
+ // TODO: Consider: Not supporting methods on attributes yet
+ // TODO: Consider: Not including Attribute usage, scope and other info about the attribute class at this point
// Do not currently see a use for an IHasProperties interface for Class/Attribute similarities
- // Not supporting methods on attributes
IEnumerable<IAttributeValue> AttributeValues { get; }
}
}
View
0  RoslynDomCommon/InterfacesForStatements/IContinue.cs → ...mon/InterfacesForStatements/IContinueStatement.cs
File renamed without changes
View
8 RoslynDomCommon/InterfacesForStatements/IDeclarationStatement.cs
@@ -2,11 +2,11 @@
namespace RoslynDom.Common
{
- public interface IDeclarationStatement
+ public interface IDeclarationStatement : IStatement
{
- string VarName { get; }
- IExpression Expression { get; }
+ IExpression Initializer { get; }
IReferencedType Type { get; }
- bool ImplicitlyTyped { get; }
+ bool IsImplicitlyTyped { get; }
+ bool IsConst { get; }
}
}
View
9 RoslynDomCommon/InterfacesForStatements/IEmptyStatement.cs
@@ -0,0 +1,9 @@
+using RoslynDom.Common;
+
+namespace RoslynDomCommon.InterfacesForStatements
+{
+ public interface IEmptyStatement : IStatement
+ {
+
+ }
+}
View
7 RoslynDomCommon/RoslynDomCommon.csproj
@@ -55,7 +55,8 @@
<Compile Include="InterfacesForStatements\IAssignmentStatement.cs" />
<Compile Include="InterfacesForStatements\IBlockStatement.cs" />
<Compile Include="InterfacesForStatements\IArgument.cs" />
- <Compile Include="InterfacesForStatements\IContinue.cs" />
+ <Compile Include="InterfacesForStatements\IEmptyStatement.cs" />
+ <Compile Include="InterfacesForStatements\IContinueStatement.cs" />
<Compile Include="InterfacesForStatements\IBreakStatement.cs" />
<Compile Include="InterfacesForStatements\ICondition.cs" />
<Compile Include="InterfacesForStatements\IDeclarationStatement.cs" />
@@ -143,9 +144,7 @@
<ItemGroup>
<None Include="InterfaceCommonality.cd" />
</ItemGroup>
- <ItemGroup>
- <Folder Include="SameIntentInitial\" />
- </ItemGroup>
+ <ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
View
29 RoslynDomCommon/SameIntentInitial/SameIIntentClass.cs
@@ -1,29 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace RoslynDom.Common
-{
- public class SameIntentClass : ISameIntent<IClass>
- {
- private SameIntentStemContainer sameIntentStemContainer = new SameIntentStemContainer();
- public bool SameIntent(IClass one, IClass other, bool includePublicAnnotations)
- {
- if (other == null) return false;
- if (!sameIntentStemContainer.SameIntent(one,other, includePublicAnnotations)) return false;
- if (one.IsAbstract != other.IsAbstract) return false;
- if (one.IsSealed != other.IsSealed) return false;
- if (one.IsStatic != other.IsStatic) return false;
- if (!one.BaseType.SameIntent(other.BaseType)) return false;
- if (!SameIntentHelpers.CheckSameIntentChildList(one.Classes, other.Classes)) return false;
- if (!SameIntentHelpers.CheckSameIntentChildList(one.Structures, other.Structures)) return false;
- if (!SameIntentHelpers.CheckSameIntentChildList(one.Interfaces, other.Interfaces)) return false;
- if (!SameIntentHelpers.CheckSameIntentChildList(one.Enums, other.Enums)) return false;
- if (!SameIntentHelpers.CheckSameIntentChildList(one.TypeParameters, other.TypeParameters)) return false;
- if (!SameIntentHelpers.CheckSameIntentChildList(one.AllImplementedInterfaces, other.AllImplementedInterfaces)) return false;
- return true;
- }
- }
-}
View
21 RoslynDomCommon/SameIntentInitial/SameIntentBaseType.cs
@@ -1,21 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace RoslynDom.Common
-{
- public class SameIntentBaseType : ISameIntent<IType>
- {
- private SameIntentCommon sameIntentCommon = new SameIntentCommon();
- public bool SameIntent(IType one, IType other, bool includePublicAnnotations)
- {
- if (!base.CheckSameIntent(other, includePublicAnnotations)) return false;
- if (!SameIntentHelpers.CheckSameIntentChildList(one.Fields, other.Fields)) return false;
- if (!SameIntentHelpers.CheckSameIntentChildList(one.Properties, other.Properties)) return false;
- if (!SameIntentHelpers.CheckSameIntentChildList(one.Methods, other.Methods)) return false;
- return true;
- }
- }
-}
View
113 RoslynDomCommon/SameIntentInitial/SameIntentCommon.cs
@@ -1,113 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace RoslynDom.Common
-{
- public class SameIntentCommon
- {
- public bool CheckSameIntent<T>(T one, T other, bool includePublicAnnotations)
- where T :IDom
- {
- if (one == null) { throw new InvalidOperationException(); }
- if (one.Name != other.Name) { return false; }
- //if (!CheckSameIntentNamespaceNames(one, other)) { return false;}
- if (!CheckSameIntentAccessModifier(one, other)) { return false; }
- if (!CheckSameIntentAttributes(one, other)) { return false; }
- if (!CheckSameIntentAccessModifier(one, other)) { return false; }
- if (!CheckSameIntentStaticModfier(one, other)) { return false; }
- if (!CheckSameIntentReturnType(one, other)) { return false; }
- if (!CheckSameIntentPropertyOrMethod(one, other)) { return false; }
-
- return true;
- }
-
- public bool CheckSameIntentNamespaceNames<T>(T one, T other)
- where T : IDom
- {
- if (one.OuterName != other.OuterName) return false;
- var item = one as IHasNamespace;
- if (item != null)
- {
- var otherItem = other as IHasNamespace;
- if (item.Namespace != otherItem.Namespace) return false;
- if (item.QualifiedName != otherItem.QualifiedName) return false;
- }
- return true;
- }
-
- private static bool CheckSameIntentAttributes<T>(T one, T other)
- {
- var item = one as IHasAttributes;
- if (item != null)
- {
- var otherItem = other as IHasAttributes;
- var attributes = item.Attributes;
- var otherAttributes = otherItem.Attributes;
- if (attributes != null || otherAttributes != null)
- {
- if (attributes == null && otherAttributes != null) return false;
- if (attributes != null && otherAttributes == null) return false;
- if (attributes.Count() != otherAttributes.Count()) return false;
- foreach (var attribute in attributes)
- {
- // TODO: Consider multiple attributes of the same name and values/attribute type
- var otherAttribute = otherAttributes.Where(x => x.Name == attribute.Name).FirstOrDefault();
- if (otherAttribute == null) return false;
- if (!attribute.SameIntent(otherAttribute)) return false;
- }
- }
- }
- return true;
- }
-
- private static bool CheckSameIntentAccessModifier<T>(T one, T other)
- {
- var item = one as IHasAccessModifier;
- if (item != null)
- {
- var otherItem = other as IHasAccessModifier;
- if (item.AccessModifier != otherItem.AccessModifier) return false;
- }
- return true;
- }
-
- private static bool CheckSameIntentStaticModfier<T>(T one, T other)
- {
- var item = one as ICanBeStatic;
- if (item != null)
- {
- var otherItem = other as ICanBeStatic;
- if (item.IsStatic != otherItem.IsStatic) return false;
- }
- return true;
- }
-
- private static bool CheckSameIntentReturnType<T>(T one, T other)
- {
- var item = one as IHasReturnType;
- if (item != null)
- {
- var otherItem = other as IHasReturnType;
- if (!item.ReturnType.SameIntent(otherItem.ReturnType)) return false;
- }
- return true;
- }
-
- private static bool CheckSameIntentPropertyOrMethod<T>(T one, T other)
- {
- var item = one as IPropertyOrMethod;
- if (item != null)
- {
- var otherItem = other as IPropertyOrMethod;
- if (item.IsAbstract != otherItem.IsAbstract) return false;
- if (item.IsOverride != otherItem.IsOverride) return false;
- if (item.IsSealed != otherItem.IsSealed) return false;
- if (item.IsVirtual != otherItem.IsVirtual) return false;
- }
- return true;
- }
- }
-}
View
24 RoslynDomCommon/SameIntentInitial/SameIntentFactory.cs
@@ -1,24 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace RoslynDom.Common
-{
- /// <summary>
- ///
- /// </summary>
- public class SameIntentFactory
- {
- // This is a totally butt ugly implementation, temporary because I don't want to introduce
- // DI until I better understand overall needs
- public ISameIntent<T> SameIntent<T>()
- {
- if (typeof(T) == typeof(IRoot))
- { return (ISameIntent<T>)new SameIntentRoot(); }
- if (typeof(T) == typeof(INamespace))
- { return (ISameIntent<T>)new SameIntentNamespace(); }
- }
- }
-}
View
29 RoslynDomCommon/SameIntentInitial/SameIntentHelpers.cs
@@ -1,29 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace RoslynDom.Common
-{
- public class SameIntentHelpers
- {
- public static bool CheckSameIntentChildList<TChild>(
- IEnumerable<TChild> thisList,
- IEnumerable<TChild> otherList)
- where TChild : class, IDom<TChild>
- {
- if (thisList == null) return (otherList == null);
- if (otherList == null) return false;
- if (thisList.Count() != otherList.Count()) return false;
- if (thisList == null) return false; // can't happen, suppresse FxCop error
- foreach (var item in thisList)
- {
- var otherItem = otherList.Where(x => item.Matches(x)).FirstOrDefault();
- if (otherItem == null) return false;
- if (!item.SameIntent(otherItem)) return false;
- }
- return true;
- }
- }
-}
View
22 RoslynDomCommon/SameIntentInitial/SameIntentNamespace.cs
@@ -1,22 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace RoslynDom.Common
-{
- public class SameIntentNamespace : ISameIntent<INamespace>
- {
- private SameIntentStemContainer sameIntentStemContainer = new SameIntentStemContainer();
- public bool SameIntent(INamespace one, INamespace other, bool includePublicAnnotations)
- {
- if (other == null) return false;
- // Base class checks classes, etc
- if (!sameIntentStemContainer.SameIntent(one,other, includePublicAnnotations)) return false;
- if (!SameIntentHelpers.CheckSameIntentChildList(one.NonemptyNamespaces, other.NonemptyNamespaces)) return false;
- if (!SameIntentHelpers.CheckSameIntentChildList(one.AllChildNamespaces, other.AllChildNamespaces)) return false;
- return true;
- }
- }
-}
View
22 RoslynDomCommon/SameIntentInitial/SameIntentNestedContainer.cs
@@ -1,22 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace RoslynDom.Common
-{
- public class SameIntentNestedContainer : ISameIntent<INestedContainer>
- {
- private SameIntentCommon sameIntentCommon = new SameIntentCommon();
- public bool SameIntent(INestedContainer one, INestedContainer other, bool includePublicAnnotations)
- {
- if (!sameIntentCommon.CheckSameIntent(one,other, includePublicAnnotations)) return false;
- if (!SameIntentHelpers.CheckSameIntentChildList(one.Classes, other.Classes)) return false;
- if (!SameIntentHelpers.CheckSameIntentChildList(one.Interfaces, other.Interfaces)) return false;
- if (!SameIntentHelpers.CheckSameIntentChildList(one.Structures, other.Structures)) return false;
- if (!SameIntentHelpers.CheckSameIntentChildList(one.Enums, other.Enums)) return false;
- return true;
- }
- }
-}
View
21 RoslynDomCommon/SameIntentInitial/SameIntentRoot.cs
@@ -1,21 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace RoslynDom.Common
-{
- public class SameIntentRoot : ISameIntent<IRoot>
- {
- private SameIntentStemContainer sameIntentStemContainer = new SameIntentStemContainer();
- public bool SameIntent(IRoot one, IRoot other, bool includePublicAnnotations)
- {
- if (other == null) return false;
- // Base class checks classes, etc
- if (!sameIntentStemContainer.SameIntent(one,other, includePublicAnnotations)) return false;
- if (!SameIntentHelpers.CheckSameIntentChildList(one.NonemptyNamespaces, other.NonemptyNamespaces)) return false;
- return true;
- }
- }
-}
View
22 RoslynDomCommon/SameIntentInitial/SameIntentStemContainer.cs
@@ -1,22 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace RoslynDom.Common
-{
- public class SameIntentStemContainer : ISameIntent<IStemContainer>
- {
- private SameIntentCommon sameIntentCommon = new SameIntentCommon();
- public bool SameIntent(IStemContainer one, IStemContainer other, bool includePublicAnnotations)
- {
- if (!sameIntentCommon.CheckSameIntent(one,other, includePublicAnnotations)) return false;
- if (!SameIntentHelpers.CheckSameIntentChildList(one.Classes, other.Classes)) return false;
- if (!SameIntentHelpers.CheckSameIntentChildList(one.Interfaces, other.Interfaces)) return false;
- if (!SameIntentHelpers.CheckSameIntentChildList(one.Structures, other.Structures)) return false;
- if (!SameIntentHelpers.CheckSameIntentChildList(one.Enums, other.Enums)) return false;
- return true;
- }
- }
-}
View
102 RoslynDomExampleTests/Interrogation.cs
@@ -12,18 +12,19 @@ namespace RoslynDomExampleTests
public class Interrogation
{
[TestMethod]
- public void Get_using_statements()
+ public void Interrogate_using_statements()
{
IRoot root = RDomFactory.GetRootFromFile(@"..\..\TestFile.cs");
var usings = root.Usings.ToArray();
- Assert.AreEqual(3, usings.Count());
- Assert.AreEqual("System.Diagnostics.Tracing", usings[0].Name);
- Assert.AreEqual("System", usings[1].Name);
- Assert.AreEqual("System.Linq", usings[2].Name);
+ Assert.AreEqual(4, usings.Count());
+ Assert.AreEqual("System", usings[0].Name);
+ Assert.AreEqual("System.Diagnostics.CodeAnalysis", usings[1].Name);
+ Assert.AreEqual("System.Diagnostics.Tracing", usings[2].Name);
+ Assert.AreEqual("System.Linq", usings[3].Name);
}
[TestMethod]
- public void Get_namespaces()
+ public void Interrogate_namespaces()
{
IRoot root = RDomFactory.GetRootFromFile(@"..\..\TestFile.cs");
var nspaces = root.Namespaces.ToArray();
@@ -36,7 +37,7 @@ public void Get_namespaces()
}
[TestMethod]
- public void Get_all_namespaces()
+ public void Interrogate_all_namespaces()
{
IRoot root = RDomFactory.GetRootFromFile(@"..\..\TestFile.cs");
// All Namespaces are designed to return all creatable qualified syntax names,
@@ -44,26 +45,26 @@ public void Get_all_namespaces()
var nspaces = root.AllChildNamespaces.ToArray();
Assert.AreEqual(4, nspaces.Count());
Assert.AreEqual("testing", nspaces[0].Name);
- Assert.AreEqual("Namespace3", nspaces[1].Name);
- Assert.AreEqual("testing.Namespace3", nspaces[1].QualifiedName);
+ Assert.AreEqual("Namespace3.testing", nspaces[1].Name);
+ Assert.AreEqual("testing.Namespace3.testing", nspaces[1].QualifiedName);
Assert.AreEqual("testing.Namespace1", nspaces[2].QualifiedName);
Assert.AreEqual("Namespace2", nspaces[3].Name);
}
[TestMethod]
- public void Get_non_empty_namespaces()
+ public void Interrogate_non_empty_namespaces()
{
IRoot root = RDomFactory.GetRootFromFile(@"..\..\TestFile.cs");
// Nonempty namespaces are anticipated to be the primary namespace access mechanism.
var nspaces = root.NonemptyNamespaces.ToArray();
Assert.AreEqual(2, nspaces.Count());
- Assert.AreEqual("Namespace3", nspaces[0].Name);
- Assert.AreEqual("testing.Namespace3", nspaces[0].QualifiedName);
+ Assert.AreEqual("Namespace3.testing", nspaces[0].Name);
+ Assert.AreEqual("testing.Namespace3.testing", nspaces[0].QualifiedName);
Assert.AreEqual("Namespace2", nspaces[1].Name);
}
[TestMethod]
- public void Get_classes_in_namespaces()
+ public void Interrogate_classes_in_namespaces()
{
IRoot root = RDomFactory.GetRootFromFile(@"..\..\TestFile.cs");
var nspace = root.Namespaces.Last();
@@ -74,7 +75,18 @@ public void Get_classes_in_namespaces()
}
[TestMethod]
- public void Get_structs_in_namespace()
+ public void Interrogate_classes_in_root()
+ {
+ IRoot root = RDomFactory.GetRootFromFile(@"..\..\TestFile.cs");
+ var classes = root.RootClasses.ToArray();
+ Assert.AreEqual(3, classes.Count());
+ Assert.AreEqual("FooClass1", classes[0].Name);
+ Assert.AreEqual("FooClass", classes[1].Name);
+ Assert.AreEqual("BarClass", classes[2].Name);
+ }
+
+ [TestMethod]
+ public void Interrogate_structs_in_namespace()
{
IRoot root = RDomFactory.GetRootFromFile(@"..\..\TestFile.cs");
var nspace = root.Namespaces.Last();
@@ -84,17 +96,17 @@ public void Get_structs_in_namespace()
}
[TestMethod]
- public void Get_interfaces_in_namespace()
+ public void Interrogate_interfaces_in_namespace()
{
IRoot root = RDomFactory.GetRootFromFile(@"..\..\TestFile.cs");
var nspace = root.Namespaces.Last();
var interfaces = nspace.Interfaces.ToArray();
Assert.AreEqual(1, interfaces.Count());
Assert.AreEqual("FooInterface", interfaces[0].Name);
- }
+ }
[TestMethod]
- public void Get_enums_in_namespace()
+ public void Interrogate_enums_in_namespace()
{
IRoot root = RDomFactory.GetRootFromFile(@"..\..\TestFile.cs");
var nspace = root.Namespaces.Last();
@@ -104,44 +116,76 @@ public void Get_enums_in_namespace()
}
[TestMethod]
- public void Get_methods_in_class()
+ public void Interrogate_methods_in_class()
{
IRoot root = RDomFactory.GetRootFromFile(@"..\..\TestFile.cs");
- var nspace = root.Namespaces.Last();
- var methods = nspace.Classes.First().Methods.ToArray();
+ var class1 = root.Namespaces.Last().Classes.First();
+ var methods = class1.Methods.ToArray();
Assert.AreEqual(1, methods.Count());
Assert.AreEqual("FooMethod", methods[0].Name);
}
[TestMethod]
- public void Get_fields_in_class()
+ public void Interrogate_fields_in_class()
{
IRoot root = RDomFactory.GetRootFromFile(@"..\..\TestFile.cs");
- var nspace = root.Namespaces.Last();
- var fields = nspace.Classes.First().Fields.ToArray();
+ var class1 = root.Namespaces.Last().Classes.First();
+ var fields = class1.Fields.ToArray();
Assert.AreEqual(1, fields.Count());
Assert.AreEqual("FooField", fields[0].Name);
}
[TestMethod]
- public void Get_properties_in_class()
+ public void Interrogate_properties_in_class()
{
IRoot root = RDomFactory.GetRootFromFile(@"..\..\TestFile.cs");
- var nspace = root.Namespaces.Last();
- var properties = nspace.Classes.First().Properties.ToArray();
+ var class1 = root.Namespaces.Last().Classes.First();
+ var properties = class1.Properties.ToArray();
Assert.AreEqual(1, properties.Count());
Assert.AreEqual("FooProperty", properties[0].Name);
}
[TestMethod]
- public void Get_parameters_for_method()
+ public void Interrogate_parameters_for_method()
{
IRoot root = RDomFactory.GetRootFromFile(@"..\..\TestFile.cs");
- var nspace = root.Namespaces.Last();
- var parameters = nspace.Classes.First().Methods.First().Parameters.ToArray() ;
+ var class1 = root.Namespaces.Last().Classes.First();
+ var method = class1.Methods.First();
+ var parameters = method.Parameters.ToArray();
Assert.AreEqual(2, parameters.Count());
+ Assert.AreEqual("FooMethod", method.Name);
+ Assert.AreEqual("String", method.ReturnType.Name);
+ Assert.AreEqual(AccessModifier.Public, method.AccessModifier);
+ Assert.IsFalse(method.IsAbstract);
+ Assert.IsFalse(method.IsExtensionMethod);
+ Assert.IsFalse(method.IsOverride);
+ Assert.IsFalse(method.IsSealed);
+ Assert.IsFalse(method.IsStatic);
+ Assert.IsFalse(method.IsVirtual);
+ Assert.IsFalse(method.IsVirtual);
Assert.AreEqual("bar1", parameters[0].Name);
+ Assert.AreEqual("Int32", parameters[0].Type.Name);
+ Assert.AreEqual(0, parameters[0].Ordinal);
Assert.AreEqual("bar2", parameters[1].Name);
+ Assert.AreEqual("String", parameters[1].Type.Name);
+ Assert.AreEqual(1, parameters[1].Ordinal);
+ Assert.IsFalse(parameters[1].IsOptional);
+ Assert.IsFalse(parameters[1].IsOut);
+ Assert.IsFalse(parameters[1].IsParamArray);
+ }
+
+ [TestMethod]
+ public void Interrogate_attributes_for_class()
+ {
+IRoot root = RDomFactory.GetRootFromFile(@"..\..\TestFile.cs");
+var class1 = root.Namespaces.Last().Classes.First();
+var attributes = class1.Attributes.ToArray();
+Assert.AreEqual(2, attributes.Count());
+Assert.AreEqual("ExcludeFromCodeCoverage", attributes[0].Name);
+Assert.AreEqual("EventSource", attributes[1].Name);
+Assert.AreEqual("Name", attributes[1].AttributeValues.First().Name);
+Assert.AreEqual("George", attributes[1].AttributeValues.First().Value);
+Assert.AreEqual(LiteralKind.String, attributes[1].AttributeValues.First().ValueType);
}
}
}
View
8 RoslynDomExampleTests/RoslynDomLoad.cs
@@ -13,7 +13,7 @@ namespace RoslynDomExampleTests
public class RoslynDomLoad
{
[TestMethod]
- public void Get_root_from_file_example()
+ public void Load_root_from_file_example()
{
IRoot root = RDomFactory.GetRootFromFile(@"..\..\TestFile.cs");
Assert.IsNotNull(root);
@@ -21,7 +21,7 @@ public void Get_root_from_file_example()
}
[TestMethod]
- public void Get_root_from_string_example()
+ public void Load_root_from_string_example()
{
var csharpCode = File.ReadAllText(@"..\..\TestFile.cs");
IRoot root = RDomFactory.GetRootFromString(csharpCode);
@@ -30,7 +30,7 @@ public void Get_root_from_string_example()
}
[TestMethod]
- public void Get_root_from_syntaxtree_example()
+ public void Load_root_from_syntaxtree_example()
{
var csharpCode = File.ReadAllText(@"..\..\TestFile.cs");
var tree = CSharpSyntaxTree.ParseText(csharpCode);
@@ -40,7 +40,7 @@ public void Get_root_from_syntaxtree_example()
}
[TestMethod]
- public void Get_root_from_document_example()
+ public void Load_root_from_document_example()
{
var slnFile = TestUtilities.GetNearestSolution(Environment.CurrentDirectory);
var ws = MSBuildWorkspace.Create();
View
6 RoslynDomExampleTests/Scenario_PatternMatchingSelection.cs
@@ -66,9 +66,9 @@ private IEnumerable<string> GetRootAttributeNames(IRoot root)
{
// This method may go away in favor of public annotations as soon as I work that out
// I don't see this being used except as design time annotations
- var classAttributeNames = from x in root.RootClasses
- from a in x.Attributes
- select a.Name;
+var classAttributeNames = from x in root.RootClasses
+ from a in x.Attributes
+ select a.Name;
return classAttributeNames;
}
View
10 RoslynDomExampleTests/TestFile.cs
@@ -1,12 +1,13 @@
-using System.Diagnostics.Tracing;
using System;
+using System.Diagnostics.CodeAnalysis;
+using System.Diagnostics.Tracing;
using System.Linq;
namespace testing
{
- namespace Namespace3
+ namespace Namespace3.testing
{
- public class FooClass
+ public class FooClass1
{ }
}
}
@@ -17,6 +18,9 @@ namespace testing.Namespace1
namespace Namespace2
{
+ // Yes these attributes are a bit dumb on this class, but I didn't want extra dependencies
+ [ExcludeFromCodeCoverage]
+ [EventSource(Name ="George")]
public class FooClass
{
public string FooField = "Bar";
View
6 RoslynDomExampleTests/WorkspaceTests.cs
@@ -14,7 +14,7 @@ namespace RoslynDomExampleTests
public class WorkspaceTests
{
[TestMethod]
- public void Open_solution()
+ public void Workspace_open_solution()
{
// Find the solution directory in this root.
// this test will break if there are multiple solutions
@@ -28,7 +28,7 @@ public void Open_solution()
}
[TestMethod]
- public void Open_project()
+ public void Workspace_open_project()
{
var slnFile = TestUtilities.GetNearestSolution(Environment.CurrentDirectory);
@@ -41,7 +41,7 @@ public void Open_project()
}
[TestMethod]
- public void Open_document()
+ public void Workspace_open_document()
{
var slnFile = TestUtilities.GetNearestSolution(Environment.CurrentDirectory);
View
3  RoslynDomTests/AttributeTests.cs
@@ -26,7 +26,8 @@ public class MyClass
{ }
";
var root = RDomFactory.GetRootFromString(csharpCode);
- var attributes = root.Classes.First().Attributes;
+ var class1 = root.Classes.First();
+ var attributes = class1.Attributes;
Assert.AreEqual(1, attributes.Count());
Assert.AreEqual("Serializable", attributes.First().Name);
}
View
20 RoslynDomTests/CopyTests.cs
@@ -80,8 +80,9 @@ public class Bar
{
public string Foo(int id, string firstName, string lastName)
{
+ if (true) {}
var x = "", "";
- var ret = lastName + x + firstName;
+ x = lastName + x + firstName;
return ret;
}
}
@@ -92,7 +93,9 @@ public string Foo(int id, string firstName, string lastName)
Assert.IsNotNull(newMethod);
Assert.IsTrue(newMethod.SameIntent(newMethod));
var rDomStatement = newMethod.Statements.First() as RDomStatement;
- Assert.AreEqual(@"var x = "", "";", rDomStatement.BuildSyntax().ToString());
+ // TODO: Include BuildSyntax in test
+ Assert.IsNotNull( rDomStatement);
+ // Assert.AreEqual(@"var x = "", "";", rDomStatement.BuildSyntax().ToString());
}
[TestMethod, TestCategory(CopyCategory)]
@@ -132,8 +135,11 @@ public string Foo
var newProperty = property.Copy();
Assert.IsNotNull(newProperty);
Assert.IsTrue(newProperty.SameIntent(newProperty));
- var rDomStatement = newProperty.GetAccessor.Statements.First() as RDomStatement;
- Assert.AreEqual(@"var x = "", "";", rDomStatement.BuildSyntax().ToString());
+ // TODO: Include BuildSyntax in test
+ Assert.IsNotNull(newProperty.GetAccessor);
+ //var rDomStatement = newProperty.GetAccessor.Statements.First() as RDomStatement;
+ //var rDomStatement = newProperty.GetAccessor.Statements.First() as RDomStatement;
+ //Assert.AreEqual(@"var x = "", "";", rDomStatement.BuildSyntax().ToString());
}
[TestMethod, TestCategory(CopyCategory)]
@@ -165,8 +171,10 @@ public string Foo
var newProperty = property.Copy();
Assert.IsNotNull(newProperty);
Assert.IsTrue(newProperty.SameIntent(newProperty));
- var rDomStatement = newProperty.SetAccessor.Statements.First() as RDomStatement;
- Assert.AreEqual(@"var x = "", "";", rDomStatement.BuildSyntax().ToString());
+ // TODO: Include BuildSyntax in test
+ Assert.IsNotNull(newProperty.SetAccessor);
+ //var rDomStatement = newProperty.SetAccessor.Statements.First() as RDomStatement;
+ //Assert.AreEqual(@"var x = "", "";", rDomStatement.BuildSyntax().ToString());
}
[TestMethod, TestCategory(CopyCategory)]
View
42 RoslynDomTests/PlaySpace.cs
@@ -5,13 +5,45 @@
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CSharp;
+namespace RoslynDom
+{
+ namespace Common.Test
+ {
+ public class Foo { }
+ }
+}
+
+
+namespace RoslynDom
+{
+ namespace Common
+ {
+ namespace Test
+ {
+ // public class Foo { }
+ }
+ }
+}
+
+namespace RoslynDom.Common.Test
+{
+ //public class Foo { }
+}
+
namespace RoslynDomTests
{
+
public class SomeAttr : Attribute { }
- struct Foo<T>
- { }
+ public class SomeAttr2 : Attribute { }
+ [SomeAttr, SomeAttr2]
+ struct Foo<T>
+ {
+ public void FooBar()
+ {
+ }
+ }
class PlaySpace
{
@@ -24,7 +56,7 @@ public void Foo()
public string Bar
{
- [SomeAttr() ]
+ [SomeAttr()]
get
{
return "";
@@ -58,14 +90,14 @@ class C2
{
public static void Foo()
{
-#region
+ #region
try
{ }
catch (Exception ex)
{ }
finally
{ }
-#endregion
+ #endregion
}
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.