forked from paulirwin/JavaToCSharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIfStatementVisitor.cs
More file actions
40 lines (33 loc) · 1.28 KB
/
Copy pathIfStatementVisitor.cs
File metadata and controls
40 lines (33 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using com.github.javaparser.ast.stmt;
using JavaToCSharp.Expressions;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
namespace JavaToCSharp.Statements
{
public class IfStatementVisitor : StatementVisitor<IfStmt>
{
public override StatementSyntax? Visit(ConversionContext context, IfStmt ifStmt)
{
var condition = ifStmt.getCondition();
var conditionSyntax = ExpressionVisitor.VisitExpression(context, condition);
if (conditionSyntax is null)
{
return null;
}
var thenStmt = ifStmt.getThenStmt();
var thenSyntax = VisitStatement(context, thenStmt);
if (thenSyntax == null)
return null;
var elseStmt = ifStmt.getElseStmt();
if (elseStmt == null)
return SyntaxFactory.IfStatement(conditionSyntax, thenSyntax);
var elseStatementSyntax = VisitStatement(context, elseStmt);
if (elseStatementSyntax is null)
{
return null;
}
var elseSyntax = SyntaxFactory.ElseClause(elseStatementSyntax);
return SyntaxFactory.IfStatement(conditionSyntax, thenSyntax, elseSyntax);
}
}
}