Skip to content

Commit

Permalink
Partway through lambdas
Browse files Browse the repository at this point in the history
  • Loading branch information
Kathleen Dollard committed Nov 27, 2014
1 parent 0259ac2 commit 1a00f35
Show file tree
Hide file tree
Showing 30 changed files with 571 additions and 226 deletions.
2 changes: 1 addition & 1 deletion CreateNuGet.cmd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
set version=1.0.18-alpha
set version=1.0.21-alpha
if not exist .\nuget_packages mkdir nuget_packages
del /Q .\nuget_packages\*.*
.nuget\NuGet.exe pack RoslynDOM\RoslynDom.csproj -IncludeReferencedProjects -OutputDirectory .\nuget_packages -Version %version% -symbols
Expand Down
148 changes: 54 additions & 94 deletions Packages.dgml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

namespace RoslynDom
{
public class RDomExpression : RDomBase<IExpression, ISymbol>, IExpression
public abstract class RDomBaseExpression : RDomBase<IExpression, ISymbol>
{
public RDomExpression(IDom parent, string initialExpressionString,
protected RDomBaseExpression(IDom parent, string initialExpressionString,
string initialExpressionLanguage, ExpressionType expressionType)
: this(null, parent, null)
{
Expand All @@ -16,13 +16,11 @@ public RDomExpression(IDom parent, string initialExpressionString,
ExpressionType = expressionType;
}

public RDomExpression(SyntaxNode rawItem, IDom parent, SemanticModel model)
protected RDomBaseExpression(SyntaxNode rawItem, IDom parent, SemanticModel model)
: base(rawItem, parent, model)
{ }

[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
"CA1811:AvoidUncalledPrivateCode", Justification = "Called via Reflection")]
internal RDomExpression(RDomExpression oldRDom)
protected RDomBaseExpression(IExpression oldRDom)
: base(oldRDom)
{
InitialExpressionString = oldRDom.InitialExpressionString;
Expand Down
45 changes: 8 additions & 37 deletions RoslynDom/ExpressionImplementations/RDomInvocationExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,16 @@

namespace RoslynDom
{
public class RDomInvocationExpression : RDomBase<IExpression, ISymbol>, IInvocationExpression
public class RDomInvocationExpression : RDomBaseExpression, IInvocationExpression
{
private RDomCollection<IReferencedType> _typeArguments;
private RDomCollection<IArgument > _arguments;
private RDomCollection<IArgument> _arguments;

public RDomInvocationExpression(IDom parent, string initialExpressionString,
string initialExpressionLanguage)
: this(null, parent, null)
string initialExpressionLanguage, string methodName)
: base(parent, initialExpressionString, initialExpressionLanguage, ExpressionType.Invocation )
{
NeedsFormatting = true;
InitialExpressionString = initialExpressionString;
InitialExpressionLanguage = initialExpressionLanguage;
ExpressionType = ExpressionType.Invocation;
_methodName = methodName;
}

public RDomInvocationExpression(SyntaxNode rawItem, IDom parent, SemanticModel model)
Expand All @@ -30,42 +27,16 @@ public RDomInvocationExpression(SyntaxNode rawItem, IDom parent, SemanticModel m
internal RDomInvocationExpression(RDomInvocationExpression oldRDom)
: base(oldRDom)
{
Initialize();
InitialExpressionString = oldRDom.InitialExpressionString;
InitialExpressionLanguage = oldRDom.InitialExpressionLanguage;
ExpressionType = oldRDom.ExpressionType;
_typeArguments = oldRDom.TypeArguments.Copy(this);
_arguments = oldRDom.Arguments.Copy(this);
}

private void Initialize()
private void Initialize()
{
_typeArguments = new RDomCollection<IReferencedType>(this);
_arguments = new RDomCollection<IArgument>(this);
}

private string _intialExpressionString;
[Required]
public string InitialExpressionString
{
get { return _intialExpressionString; }
set { SetProperty(ref _intialExpressionString, value); }
}

private string _initialExpressionLanguage;
[Required]
public string InitialExpressionLanguage
{
get { return _initialExpressionLanguage; }
set { SetProperty(ref _initialExpressionLanguage, value); }
}

private ExpressionType _expressionType;
[Required]
public ExpressionType ExpressionType
{
get { return _expressionType; }
set { } // do nothing
}

private string _methodName;
[Required]
public string MethodName
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
using Microsoft.CodeAnalysis;
using RoslynDom.Common;
using System.ComponentModel.DataAnnotations;
using System;
using System.Collections.Generic;
using System.Linq;

namespace RoslynDom
{
public class RDomLambdaMultiLineExpression : RDomBaseExpression, ILambdaMultiLineExpression
{
private RDomCollection<IParameter> _parameters;
private RDomCollection<IStatementAndDetail> _statements;

public RDomLambdaMultiLineExpression(IDom parent, string initialExpressionString,
string initialExpressionLanguage)
: base(parent, initialExpressionString, initialExpressionLanguage, ExpressionType.Lambda)
{ }

public RDomLambdaMultiLineExpression(SyntaxNode rawItem, IDom parent, SemanticModel model)
: base(rawItem, parent, model)
{ Initialize(); }

[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
"CA1811:AvoidUncalledPrivateCode", Justification = "Called via Reflection")]
internal RDomLambdaMultiLineExpression(RDomLambdaMultiLineExpression oldRDom)
: base(oldRDom)
{
_parameters = oldRDom.Parameters.Copy(this);
_statements = oldRDom.StatementsAll.Copy(this);
}

private void Initialize()
{
_parameters = new RDomCollection<IParameter>(this);
_statements = new RDomCollection<IStatementAndDetail>(this);
}

public override IEnumerable<IDom> Children
{
get
{
var list = base.Children.ToList();
list.AddRange(_statements);
return list;
}
}

private IReferencedType _returnType;
[Required]
public IReferencedType ReturnType
{
get { return _returnType; }
set { SetProperty(ref _returnType, value); }
}

public RDomCollection<IParameter> Parameters
{ get { return _parameters; } }

public RDomCollection<IStatementAndDetail> StatementsAll
{ get { return _statements; } }

public IEnumerable<IStatement> Statements
{ get { return _statements.OfType<IStatement>().ToList(); } }

public bool HasBlock
{
get { return true; }
set { }
}
}
}
56 changes: 56 additions & 0 deletions RoslynDom/ExpressionImplementations/RDomLambdaSingleExpression.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using Microsoft.CodeAnalysis;
using RoslynDom.Common;
using System.ComponentModel.DataAnnotations;
using System;
using System.Collections.Generic;

namespace RoslynDom
{
public class RDomLambdaSingleExpression : RDomBaseExpression, ILambdaSingleExpression
{
private RDomCollection<IParameter> _parameters;

public RDomLambdaSingleExpression(IDom parent, string initialExpressionString,
string initialExpressionLanguage)
: base(parent, initialExpressionString, initialExpressionLanguage, ExpressionType.Lambda)
{ }

public RDomLambdaSingleExpression(SyntaxNode rawItem, IDom parent, SemanticModel model)
: base(rawItem, parent, model)
{ Initialize(); }

[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
"CA1811:AvoidUncalledPrivateCode", Justification = "Called via Reflection")]
internal RDomLambdaSingleExpression(RDomLambdaSingleExpression oldRDom)
: base(oldRDom)
{
_parameters = oldRDom.Parameters.Copy(this);
}

private void Initialize()
{
_parameters = new RDomCollection<IParameter>(this);
}

private IExpression _expression;
[Required]
public IExpression Expression
{
get { return _expression; }
set { SetProperty(ref _expression, value); }
}

private IReferencedType _returnType;
[Required]
public IReferencedType ReturnType
{
get { return _returnType; }
set { SetProperty(ref _returnType, value); }
}


public RDomCollection<IParameter > Parameters
{ get { return _parameters ; } }

}
}
24 changes: 24 additions & 0 deletions RoslynDom/ExpressionImplementations/RDomOtherExpression.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using Microsoft.CodeAnalysis;
using RoslynDom.Common;
using System.ComponentModel.DataAnnotations;

namespace RoslynDom
{
public class RDomOtherExpression : RDomBaseExpression, IOtherExpression
{
public RDomOtherExpression(IDom parent, string initialExpressionString,
string initialExpressionLanguage, ExpressionType expressionType)
: base(parent, initialExpressionString, initialExpressionLanguage, expressionType)
{ }

public RDomOtherExpression(SyntaxNode rawItem, IDom parent, SemanticModel model)
: base(rawItem, parent, model)
{ }

[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
"CA1811:AvoidUncalledPrivateCode", Justification = "Called via Reflection")]
internal RDomOtherExpression(RDomOtherExpression oldRDom)
: base(oldRDom)
{ }
}
}
2 changes: 1 addition & 1 deletion RoslynDom/Implementations/RDomReferencedType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public RDomReferencedType(SyntaxNode rawItem, IDom parent, SemanticModel model)
if (typeSymbol != null)
{
// TODO: See if this is a bug in the current preview
MetadataName = typeSymbol.ContainingNamespace + "." + typeSymbol.MetadataName;
_metadataName = typeSymbol.ContainingNamespace + "." + typeSymbol.MetadataName;
}
}

Expand Down
5 changes: 4 additions & 1 deletion RoslynDom/RoslynDom.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,11 @@
<Compile Include="BasesAndBaseHelpers\RDomBaseType.cs" />
<Compile Include="BasesAndBaseHelpers\RDomBaseStemContainer.cs" />
<Compile Include="BasesAndBaseHelpers\RDomDetail.cs" />
<Compile Include="ExpressionImplementations\RDomLambdaSingleExpression.cs" />
<Compile Include="ExpressionImplementations\RDomLambdaMultiLineExpression.cs" />
<Compile Include="ExpressionImplementations\RDomInvocationExpression.cs" />
<Compile Include="ExpressionImplementations\RDomExpression.cs" />
<Compile Include="BasesAndBaseHelpers\RDomBaseExpression.cs" />
<Compile Include="ExpressionImplementations\RDomOtherExpression.cs" />
<Compile Include="ExtensionMethods.cs" />
<Compile Include="Implementations\RDomPublicAnnotation.cs" />
<Compile Include="Implementations\RDomAttributeValue.cs" />
Expand Down
18 changes: 18 additions & 0 deletions RoslynDom/RoslynDom.nuspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2011/10/nuspec.xsd">
<metadata>
<id>RoslynDom</id>
<version>1.0.18-alpha</version>
<title>RoslynDom</title>
<authors>Kathleen</authors>
<owners>Kathleen</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Description</description>
<copyright>Copyright © 2014</copyright>
<dependencies>
<dependency id="Microsoft.CodeAnalysis.Workspaces.Common" version="1.0.0-beta1-20141031-01" />
<dependency id="Unity" version="3.5.1405-prerelease" />
<dependency id="System.Reflection.Metadata" version="1.0.17-beta" />
</dependencies>
</metadata>
</package>
4 changes: 2 additions & 2 deletions RoslynDomCSharpFactories/Factories/RDomExpressionFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
namespace RoslynDom.CSharp
{
public class RDomExpressionFactory
: RDomBaseSyntaxNodeFactory<RDomExpression, ExpressionSyntax>
: RDomBaseSyntaxNodeFactory<RDomOtherExpression, ExpressionSyntax>
{
public RDomExpressionFactory(RDomCorporation corporation)
: base(corporation)
Expand Down Expand Up @@ -39,7 +39,7 @@ protected override IDom CreateItemFrom(SyntaxNode syntaxNode, IDom parent, Seman
{
var syntax = syntaxNode as ExpressionSyntax;

var newItem = new RDomExpression(syntaxNode, parent, model);
var newItem = new RDomOtherExpression(syntaxNode, parent, model);
newItem.InitialExpressionString = syntax.ToString();
newItem.InitialExpressionLanguage = ExpectedLanguages.CSharp;
newItem.ExpressionType = ExpressionTypeFromSyntax(syntaxNode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,7 @@ private string GetMethodName(string expression)
return expression;
}

private ExpressionType ExpressionTypeFromSyntax(SyntaxNode syntaxNode)
{
if (syntaxNode is LiteralExpressionSyntax) { return ExpressionType.Literal; }
if (syntaxNode is ObjectCreationExpressionSyntax) { return ExpressionType.ObjectCreation; }
if (syntaxNode is InvocationExpressionSyntax) { return ExpressionType.Invocation; }
if (syntaxNode is IdentifierNameSyntax) { return ExpressionType.Identifier; }
if (syntaxNode is BinaryExpressionSyntax) { return ExpressionType.Complex; }
return ExpressionType.Unknown;
}


public override IEnumerable<SyntaxNode> BuildSyntax(IDom item)
public override IEnumerable<SyntaxNode> BuildSyntax(IDom item)
{
var itemAsT = item as IExpression;
if (itemAsT.InitialExpressionLanguage != ExpectedLanguages.CSharp) { throw new InvalidOperationException(); }
Expand Down
Loading

0 comments on commit 1a00f35

Please sign in to comment.