Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
dd45779
Use spaces for consistency with rest of project
GrahamTheCoder Feb 18, 2018
ff41161
WIP define project and solution commands
GrahamTheCoder Feb 18, 2018
b831dff
Use specific method for this
GrahamTheCoder Feb 18, 2018
aee94ba
WIP VB -> C# Solution command works
GrahamTheCoder Feb 18, 2018
e5863de
Extract class
GrahamTheCoder Feb 18, 2018
6b3595f
Change the structure to slightly decrease confusion and duplication
GrahamTheCoder Feb 18, 2018
7ab76c3
Make optional source path part of result
GrahamTheCoder Feb 24, 2018
dc9fcec
Restrict to solutiondir
GrahamTheCoder Feb 24, 2018
6fcef65
Improve error details
GrahamTheCoder Feb 24, 2018
c290144
Also write file text and open a window with it in
GrahamTheCoder Feb 25, 2018
9b004e9
Parent same group for varying ways of selecting projects
GrahamTheCoder Feb 25, 2018
a655bae
Separate language specifics
GrahamTheCoder Feb 25, 2018
d30b819
Make project conversion for cs -> vb use the same code
GrahamTheCoder Feb 25, 2018
1a1be5c
Remove debug code
GrahamTheCoder Feb 25, 2018
804d7fe
Share new conversion code for VB and C#
GrahamTheCoder Feb 26, 2018
d2b8c53
Update copyright
GrahamTheCoder Feb 26, 2018
f621b2e
We no longer copy to the clipboard
GrahamTheCoder Feb 26, 2018
5037816
Rev version number and add release notes
GrahamTheCoder Feb 26, 2018
779ba33
Bring commands closer together
GrahamTheCoder Feb 26, 2018
10ac4f7
Let user know file is open but sort output
GrahamTheCoder Feb 26, 2018
1f05a83
Maintain file path information in syntax tree
GrahamTheCoder Feb 26, 2018
c254bd6
Copy structural changes into the C# -> VB converter to keep in step
GrahamTheCoder Feb 26, 2018
59467c2
Start testing csharp -> vb comment conversion
GrahamTheCoder Feb 26, 2018
fc76732
Set spacing the same on C# and vb now that trivia is converted
GrahamTheCoder Feb 26, 2018
c331059
Recognize both langauges' unimportant trivia and comment chars
GrahamTheCoder Feb 26, 2018
f08c5fc
API Change: Exclusively use new ProjectConversion code path
GrahamTheCoder Feb 26, 2018
0f419cf
Disable the trivia porting functionality and restore tests
GrahamTheCoder Feb 26, 2018
bd82a55
Write to an output window pane to avoid opening two files
GrahamTheCoder Feb 26, 2018
ca796b1
Try to vaguely cater for this possibility rather than error
GrahamTheCoder Feb 26, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,23 @@

All notable changes to the code converter will be documented here.

## 5.6 - 27/02/2018

### Visual studio extension
* Works reliably in VS2017
* Instead of copy to clipboard, opens result as Visual Studio window for quick viewing
* Writes summary to output window to explain what's happened
* Project context used for all conversions

### VB -> C# specific
* Query expression syntax converted in simple cases
* Anonymous object creation converted
* Object initializer syntax converted
* Converts comments in the majority of cases (though with some formatting oddities)
* Now works on sub-method snippets
* Names now fully qualified where necessary
* Out parameters correctly converted

## 5.5 - 12/29/2017

* Move from Refactoring Essentials to a repository of its own
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Linq;
using ICSharpCode.CodeConverter.Shared;
using ICSharpCode.CodeConverter.Util;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.VisualBasic;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Linq;
using ICSharpCode.CodeConverter.Shared;
using ICSharpCode.CodeConverter.Util;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
Expand All @@ -15,16 +16,16 @@ namespace ICSharpCode.CodeConverter.CSharp
public class CommentConvertingNodesVisitor : VisualBasicSyntaxVisitor<CSharpSyntaxNode>
{
public TriviaConverter TriviaConverter { get; }
private readonly VisualBasicSyntaxVisitor<CSharpSyntaxNode> wrappedVisitor;
private readonly VisualBasicSyntaxVisitor<CSharpSyntaxNode> _wrappedVisitor;

public CommentConvertingNodesVisitor(VisualBasicSyntaxVisitor<CSharpSyntaxNode> wrappedVisitor)
{
TriviaConverter = new TriviaConverter();
this.wrappedVisitor = wrappedVisitor;
this._wrappedVisitor = wrappedVisitor;
}
public override CSharpSyntaxNode DefaultVisit(SyntaxNode node)
{
return TriviaConverter.PortConvertedTrivia(node, wrappedVisitor.Visit(node));
return TriviaConverter.PortConvertedTrivia(node, _wrappedVisitor.Visit(node));
}

public override CSharpSyntaxNode VisitModuleBlock(VbSyntax.ModuleBlockSyntax node)
Expand Down Expand Up @@ -60,7 +61,7 @@ public override CSharpSyntaxNode VisitCompilationUnit(VbSyntax.CompilationUnitSy

private TDest WithPortedTrivia<TSource, TDest>(SyntaxNode node, Func<TSource, TDest, TDest> portExtraTrivia) where TSource : SyntaxNode where TDest : CSharpSyntaxNode
{
var cSharpSyntaxNode = portExtraTrivia((TSource)node, (TDest)wrappedVisitor.Visit(node));
var cSharpSyntaxNode = portExtraTrivia((TSource)node, (TDest)_wrappedVisitor.Visit(node));
return TriviaConverter.PortConvertedTrivia(node, cSharpSyntaxNode);
}

Expand Down
5 changes: 1 addition & 4 deletions ICSharpCode.CodeConverter/CSharp/CompilationErrorFixer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,7 @@ private SyntaxNode ComputeReplacementNode(SyntaxNode originalNode, SyntaxNode po
var refOrOutKeyword = GetRefKeyword(methodSymbol.Parameters[index]);
var currentSyntaxKind = nodeToReturn.Arguments[index].Kind();
if (!refOrOutKeyword.IsKind(currentSyntaxKind)) {
nodeToReturn = nodeToReturn.ReplaceNode(argument,
SyntaxFactory.Argument(argument.NameColon, refOrOutKeyword, argument.Expression)
.WithLeadingTrivia(argument.GetLeadingTrivia())
.WithTrailingTrivia(argument.GetTrailingTrivia()));
nodeToReturn = nodeToReturn.ReplaceNode(argument, argument.WithRefOrOutKeyword(refOrOutKeyword));
}
}
}
Expand Down
40 changes: 15 additions & 25 deletions ICSharpCode.CodeConverter/CSharp/MethodBodyVisitor.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using ICSharpCode.CodeConverter.Shared;
using ICSharpCode.CodeConverter.Util;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using ArgumentListSyntax = Microsoft.CodeAnalysis.CSharp.Syntax.ArgumentListSyntax;
using CSharpExtensions = Microsoft.CodeAnalysis.CSharp.CSharpExtensions;
using ExpressionSyntax = Microsoft.CodeAnalysis.CSharp.Syntax.ExpressionSyntax;
using IdentifierNameSyntax = Microsoft.CodeAnalysis.CSharp.Syntax.IdentifierNameSyntax;
using LocalDeclarationStatementSyntax = Microsoft.CodeAnalysis.CSharp.Syntax.LocalDeclarationStatementSyntax;
using StatementSyntax = Microsoft.CodeAnalysis.CSharp.Syntax.StatementSyntax;
using SyntaxFactory = Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
using SyntaxKind = Microsoft.CodeAnalysis.CSharp.SyntaxKind;
using TypeSyntax = Microsoft.CodeAnalysis.CSharp.Syntax.TypeSyntax;
using VBasic = Microsoft.CodeAnalysis.VisualBasic;
using VBSyntax = Microsoft.CodeAnalysis.VisualBasic.Syntax;

Expand All @@ -35,7 +27,7 @@ public MethodBodyVisitor(SemanticModel semanticModel, VBasic.VisualBasicSyntaxVi
this.semanticModel = semanticModel;
this.nodesVisitor = nodesVisitor;
this.withBlockTempVariableNames = withBlockTempVariableNames;
this.CommentConvertingVisitor = new CommentConvertingMethodBodyVisitor(this, triviaConverter);
CommentConvertingVisitor = new CommentConvertingMethodBodyVisitor(this, triviaConverter);
}

public override SyntaxList<StatementSyntax> DefaultVisit(SyntaxNode node)
Expand All @@ -56,7 +48,7 @@ private static string ConvertStopOrEndToCSharpStatementText(VBSyntax.StopOrEndSt
case VBasic.SyntaxKind.EndKeyword:
return "System.Environment.Exit(0);";
default:
throw new NotImplementedException(CSharpExtensions.Kind(node.StopOrEndKeyword) + " not implemented!");
throw new NotImplementedException(node.StopOrEndKeyword.Kind() + " not implemented!");
}
}

Expand Down Expand Up @@ -135,7 +127,7 @@ public override SyntaxList<StatementSyntax> VisitExitStatement(VBSyntax.ExitStat
VBasic.VisualBasicSyntaxNode typeContainer = (VBasic.VisualBasicSyntaxNode)node.Ancestors().OfType<VBSyntax.LambdaExpressionSyntax>().FirstOrDefault()
?? node.Ancestors().OfType<VBSyntax.MethodBlockSyntax>().FirstOrDefault();
var info = typeContainer.TypeSwitch(
(VBSyntax.LambdaExpressionSyntax e) => ModelExtensions.GetTypeInfo(semanticModel, e).Type.GetReturnType(),
(VBSyntax.LambdaExpressionSyntax e) => semanticModel.GetTypeInfo(e).Type.GetReturnType(),
(VBSyntax.MethodBlockSyntax e) => {
var type = (TypeSyntax)e.SubOrFunctionStatement.AsClause?.Type.Accept(nodesVisitor) ?? SyntaxFactory.ParseTypeName("object");
return semanticModel.GetSymbolInfo(type).Symbol.GetReturnType();
Expand Down Expand Up @@ -369,10 +361,10 @@ public override SyntaxList<StatementSyntax> VisitUsingBlock(VBSyntax.UsingBlockS
foreach (var declaration in SplitVariableDeclarations(v, nodesVisitor, semanticModel).Values.Reverse())
stmt = SyntaxFactory.UsingStatement(declaration, null, stmt);
return SingleStatement(stmt);
} else {
var expr = (ExpressionSyntax)node.UsingStatement.Expression.Accept(nodesVisitor);
return SingleStatement(SyntaxFactory.UsingStatement(null, expr, SyntaxFactory.Block(node.Statements.SelectMany(s => s.Accept(CommentConvertingVisitor))).UnpackBlock()));
}

var expr = (ExpressionSyntax)node.UsingStatement.Expression.Accept(nodesVisitor);
return SingleStatement(SyntaxFactory.UsingStatement(null, expr, SyntaxFactory.Block(node.Statements.SelectMany(s => s.Accept(CommentConvertingVisitor))).UnpackBlock()));
}

public override SyntaxList<StatementSyntax> VisitWhileBlock(VBSyntax.WhileBlockSyntax node)
Expand All @@ -392,11 +384,10 @@ public override SyntaxList<StatementSyntax> VisitDoLoopBlock(VBSyntax.DoLoopBloc
(ExpressionSyntax)stmt.Condition.Accept(nodesVisitor),
SyntaxFactory.Block(node.Statements.SelectMany(s => s.Accept(CommentConvertingVisitor))).UnpackBlock()
));
else
return SingleStatement(SyntaxFactory.WhileStatement(
SyntaxFactory.PrefixUnaryExpression(SyntaxKind.LogicalNotExpression, (ExpressionSyntax)stmt.Condition.Accept(nodesVisitor)),
SyntaxFactory.Block(node.Statements.SelectMany(s => s.Accept(CommentConvertingVisitor))).UnpackBlock()
));
return SingleStatement(SyntaxFactory.WhileStatement(
SyntaxFactory.PrefixUnaryExpression(SyntaxKind.LogicalNotExpression, (ExpressionSyntax)stmt.Condition.Accept(nodesVisitor)),
SyntaxFactory.Block(node.Statements.SelectMany(s => s.Accept(CommentConvertingVisitor))).UnpackBlock()
));
}
if (node.LoopStatement.WhileOrUntilClause != null) {
var stmt = node.LoopStatement.WhileOrUntilClause;
Expand All @@ -405,11 +396,10 @@ public override SyntaxList<StatementSyntax> VisitDoLoopBlock(VBSyntax.DoLoopBloc
SyntaxFactory.Block(node.Statements.SelectMany(s => s.Accept(CommentConvertingVisitor))).UnpackBlock(),
(ExpressionSyntax)stmt.Condition.Accept(nodesVisitor)
));
else
return SingleStatement(SyntaxFactory.DoStatement(
SyntaxFactory.Block(node.Statements.SelectMany(s => s.Accept(CommentConvertingVisitor))).UnpackBlock(),
SyntaxFactory.PrefixUnaryExpression(SyntaxKind.LogicalNotExpression, (ExpressionSyntax)stmt.Condition.Accept(nodesVisitor))
));
return SingleStatement(SyntaxFactory.DoStatement(
SyntaxFactory.Block(node.Statements.SelectMany(s => s.Accept(CommentConvertingVisitor))).UnpackBlock(),
SyntaxFactory.PrefixUnaryExpression(SyntaxKind.LogicalNotExpression, (ExpressionSyntax)stmt.Condition.Accept(nodesVisitor))
));
}
throw new NotSupportedException();
}
Expand Down
Loading