Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ env:
jobs:
build:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
with:
Expand Down
1 change: 1 addition & 0 deletions Rewrite/dotnet-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dotnet test Rewrite.Sources.sln --filter "Category!=KnownBug & Category!=Exploratory"
31 changes: 26 additions & 5 deletions Rewrite/src/Rewrite.CSharp/CSharpPrinter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ public CSharpPrinter()
_delegate = new CSharpJavaPrinter(this);
}

// [DebuggerNonUserCode]
// [DebuggerStepperBoundary]
#if DEBUG_VISITOR
[DebuggerStepThrough]
#endif
public override J? Visit(Rewrite.Core.Tree? tree, PrintOutputCapture<TState> p)
{
if (!(tree is Cs))
Expand Down Expand Up @@ -369,6 +370,23 @@ public override Cs VisitFileScopeNamespaceDeclaration(Cs.FileScopeNamespaceDecla
return usingDirective;
}

public override Cs VisitLambda(Cs.Lambda lambda, PrintOutputCapture<TState> p)
{
var javaLambda = lambda.LambdaExpression;
BeforeSyntax(javaLambda, Space.Location.LAMBDA_PREFIX, p);
VisitSpace(javaLambda.Prefix, Space.Location.LAMBDA_PARAMETERS_PREFIX, p);
VisitMarkers(javaLambda.Markers, p);
// _delegate.VisitContainer(lambda.Modifiers, JContainer.Location.ANY, p);
foreach (var modifier in lambda.Modifiers)
{
_delegate.VisitModifier(modifier, p);
}

Visit(javaLambda, p);
AfterSyntax(lambda, p);
return lambda;
}

protected override Space VisitSpace(Space space, CsSpace.Location loc, PrintOutputCapture<TState> p)
{
return _delegate.VisitSpace(space, Space.Location.LANGUAGE_EXTENSION, p);
Expand Down Expand Up @@ -471,9 +489,12 @@ protected void VisitStatement(JRightPadded<Statement> paddedStat, CsRightPadded.
_delegate.PrintStatementTerminator(paddedStat.Element, p);
}


private class CSharpJavaPrinter(CSharpPrinter<TState> _parent) : JavaPrinter<TState>
{
[DebuggerHidden]
#if DEBUG_VISITOR
[DebuggerStepThrough]
#endif
public override J? Visit(Rewrite.Core.Tree? tree, PrintOutputCapture<TState> p)
{
if (tree is Cs)
Expand Down Expand Up @@ -844,12 +865,12 @@ public override Markers VisitMarkers(Markers? markers, PrintOutputCapture<TState
private static readonly Func<string, string> JAVA_MARKER_WRAPPER =
o => "/*~~" + o + (string.IsNullOrEmpty(o) ? "" : "~~") + ">*/";

private void BeforeSyntax(Cs cs, Space.Location loc, PrintOutputCapture<TState> p)
private void BeforeSyntax(J cs, Space.Location loc, PrintOutputCapture<TState> p)
{
BeforeSyntax(cs.Prefix, cs.Markers, loc, p);
}

private void BeforeSyntax(Cs cs, CsSpace.Location loc, PrintOutputCapture<TState> p)
private void BeforeSyntax(J cs, CsSpace.Location loc, PrintOutputCapture<TState> p)
{
BeforeSyntax(cs.Prefix, cs.Markers, loc, p);
}
Expand Down
21 changes: 21 additions & 0 deletions Rewrite/src/Rewrite.CSharp/CSharpVisitor.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,27 @@ public override bool IsAcceptable(SourceFile sourceFile, P p)
return propertyDeclaration;
}

public virtual J? VisitLambda(Cs.Lambda lambda, P p)
{
lambda = lambda.WithPrefix(VisitSpace(lambda.Prefix, CsSpace.Location.LAMBDA_PREFIX, p)!);
var tempStatement = (Statement) VisitStatement(lambda, p);
if (tempStatement is not Cs.Lambda)
{
return tempStatement;
}
lambda = (Cs.Lambda) tempStatement;
var tempExpression = (Expression) VisitExpression(lambda, p);
if (tempExpression is not Cs.Lambda)
{
return tempExpression;
}
lambda = (Cs.Lambda) tempExpression;
lambda = lambda.WithMarkers(VisitMarkers(lambda.Markers, p));
lambda = lambda.WithLambdaExpression(VisitAndCast<J.Lambda>(lambda.LambdaExpression, p)!);
lambda = lambda.WithModifiers(lambda.Modifiers.Map(el => (J.Modifier?)Visit(el, p)));
return lambda;
}

protected virtual JContainer<J2>? VisitContainer<J2>(JContainer<J2>? container, CsContainer.Location loc, P p) where J2 : J
{
if (container == null) {
Expand Down
71 changes: 40 additions & 31 deletions Rewrite/src/Rewrite.CSharp/Parser/CSharpParserVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ public override J VisitIdentifierName(IdentifierNameSyntax node)
Core.Tree.RandomId(),
prefix,
fa.Markers,
new JRightPadded<Expression>(fa.Target, Format(operatorToken.LeadingTrivia), Markers.EMPTY),
new JRightPadded<Expression>(fa.Target, fa.Padding.Name.Before, Markers.EMPTY),
null,
fa.Name,
MapArgumentList(node.ArgumentList),
Expand Down Expand Up @@ -494,7 +494,7 @@ pt.Clazz is J.Identifier i
private JContainer<Expression> MapArgumentList(ArgumentListSyntax argumentList)
{
return new JContainer<Expression>(
Format(Trailing(argumentList.OpenParenToken)),
Format(Leading(argumentList.OpenParenToken)),
argumentList.Arguments.Select(MapArgument).ToList(),
Markers.EMPTY
);
Expand Down Expand Up @@ -1865,49 +1865,57 @@ private J.ArrayAccess MapArrayAccess(ElementAccessExpressionSyntax node, int ind
);
}

public override J? VisitSimpleLambdaExpression(SimpleLambdaExpressionSyntax node)
public override J? VisitRefExpression(RefExpressionSyntax node)
{
return new J.Lambda(
Core.Tree.RandomId(),
Format((Leading(node))),
Markers.EMPTY,
new J.Lambda.Parameters(
Core.Tree.RandomId(),
Space.EMPTY,
Markers.EMPTY,
false,
[
MapParameter<J>(node.Parameter)
]
),
Format(Leading(node.ArrowToken)),
Convert<J>(node.Body)!,
MapType(node)
);
return base.VisitRefExpression(node);
}

public override J? VisitRefExpression(RefExpressionSyntax node)
public override J? VisitSimpleLambdaExpression(SimpleLambdaExpressionSyntax node)
{
return base.VisitRefExpression(node);
return VisitLambdaExpressionSyntax(node);
}

public override J? VisitParenthesizedLambdaExpression(ParenthesizedLambdaExpressionSyntax node)
{
return new J.Lambda(
Core.Tree.RandomId(),
Format((Leading(node))),
Markers.EMPTY,
new J.Lambda.Parameters(
return VisitLambdaExpressionSyntax(node);
}

private J? VisitLambdaExpressionSyntax(LambdaExpressionSyntax node)
{
J.Lambda.Parameters parameters = node switch
{
ParenthesizedLambdaExpressionSyntax parenthesizedLambdaExpression => new J.Lambda.Parameters(
Core.Tree.RandomId(),
Space.EMPTY,
Format(Trailing(node.AsyncKeyword)),
Markers.EMPTY,
true,
MapParameters<J>(node.ParameterList)!.Elements
),
MapParameters<J>(parenthesizedLambdaExpression.ParameterList)!.Elements),
SimpleLambdaExpressionSyntax simpleLambdaExpression => new J.Lambda.Parameters(
Core.Tree.RandomId(),
Format(Trailing(node.AsyncKeyword)),
Markers.EMPTY,
false,
[MapParameter<J>(simpleLambdaExpression.Parameter)]),
_ => throw new NotSupportedException($"Unsupported type {node.GetType()}")
};

var jLambda = new J.Lambda(
Core.Tree.RandomId(),
Space.EMPTY,
Markers.EMPTY,
parameters,
Format(Leading(node.ArrowToken)),
Convert<J>(node.Body)!,
MapType(node)
);
var csLambda = new Cs.Lambda(
Core.Tree.RandomId(),
Format((Leading(node))),
Markers.EMPTY,
jLambda,
MapModifiers(node.Modifiers)
);
return csLambda;
}

public override J? VisitInitializerExpression(InitializerExpressionSyntax node)
Expand Down Expand Up @@ -2493,7 +2501,7 @@ private JRightPadded<Statement> MapAnonymousObjectMember(AnonymousObjectMemberDe

public override J? VisitGlobalStatement(GlobalStatementSyntax node)
{
return base.VisitGlobalStatement(node);
return node.Statement.Accept(this);
}

public override J? VisitLocalFunctionStatement(LocalFunctionStatementSyntax node)
Expand Down Expand Up @@ -3703,6 +3711,7 @@ private JRightPadded<T> MapParameter<T>(ParameterSyntax tps) where T : J
)).ToList();
}


#if DEBUG_VISITOR
[DebuggerStepThrough]
#endif
Expand Down
7 changes: 6 additions & 1 deletion Rewrite/src/Rewrite.CSharp/Tree/AnnotatedStatement.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,16 @@ public AnnotatedStatement WithStatement(Statement newStatement)
{
return ReferenceEquals(newStatement, statement) ? this : new AnnotatedStatement(id, prefix, markers, attributeLists, newStatement);
}
#if DEBUG_VISITOR
[DebuggerStepThrough]
#endif
public bool Equals(Rewrite.Core.Tree? other)
{
return other is AnnotatedStatement && other.Id == Id;
}

#if DEBUG_VISITOR
[DebuggerStepThrough]
#endif
public override int GetHashCode()
{
return Id.GetHashCode();
Expand Down
7 changes: 6 additions & 1 deletion Rewrite/src/Rewrite.CSharp/Tree/ArrayRankSpecifier.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,16 @@ public Cs.ArrayRankSpecifier WithSizes(JContainer<Expression> newSizes)

}

#if DEBUG_VISITOR
[DebuggerStepThrough]
#endif
public bool Equals(Rewrite.Core.Tree? other)
{
return other is ArrayRankSpecifier && other.Id == Id;
}

#if DEBUG_VISITOR
[DebuggerStepThrough]
#endif
public override int GetHashCode()
{
return Id.GetHashCode();
Expand Down
7 changes: 6 additions & 1 deletion Rewrite/src/Rewrite.CSharp/Tree/AssignmentOperation.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,16 @@ public Cs.AssignmentOperation WithOperator(JLeftPadded<Cs.AssignmentOperation.Op

}

#if DEBUG_VISITOR
[DebuggerStepThrough]
#endif
public bool Equals(Rewrite.Core.Tree? other)
{
return other is AssignmentOperation && other.Id == Id;
}

#if DEBUG_VISITOR
[DebuggerStepThrough]
#endif
public override int GetHashCode()
{
return Id.GetHashCode();
Expand Down
7 changes: 6 additions & 1 deletion Rewrite/src/Rewrite.CSharp/Tree/AttributeList.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,16 @@ public Cs.AttributeList WithAttributes(IList<JRightPadded<J.Annotation>> newAttr

}

#if DEBUG_VISITOR
[DebuggerStepThrough]
#endif
public bool Equals(Rewrite.Core.Tree? other)
{
return other is AttributeList && other.Id == Id;
}

#if DEBUG_VISITOR
[DebuggerStepThrough]
#endif
public override int GetHashCode()
{
return Id.GetHashCode();
Expand Down
7 changes: 6 additions & 1 deletion Rewrite/src/Rewrite.CSharp/Tree/AwaitExpression.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,16 @@ public AwaitExpression WithType(JavaType? newType)
{
return newType == type ? this : new AwaitExpression(id, prefix, markers, expression, newType);
}
#if DEBUG_VISITOR
[DebuggerStepThrough]
#endif
public bool Equals(Rewrite.Core.Tree? other)
{
return other is AwaitExpression && other.Id == Id;
}

#if DEBUG_VISITOR
[DebuggerStepThrough]
#endif
public override int GetHashCode()
{
return Id.GetHashCode();
Expand Down
7 changes: 6 additions & 1 deletion Rewrite/src/Rewrite.CSharp/Tree/Binary.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,16 @@ public Cs.Binary WithOperator(JLeftPadded<Cs.Binary.OperatorType> newOperator)

}

#if DEBUG_VISITOR
[DebuggerStepThrough]
#endif
public bool Equals(Rewrite.Core.Tree? other)
{
return other is Binary && other.Id == Id;
}

#if DEBUG_VISITOR
[DebuggerStepThrough]
#endif
public override int GetHashCode()
{
return Id.GetHashCode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,16 @@ public Cs.BlockScopeNamespaceDeclaration WithMembers(IList<JRightPadded<Statemen

}

#if DEBUG_VISITOR
[DebuggerStepThrough]
#endif
public bool Equals(Rewrite.Core.Tree? other)
{
return other is BlockScopeNamespaceDeclaration && other.Id == Id;
}

#if DEBUG_VISITOR
[DebuggerStepThrough]
#endif
public override int GetHashCode()
{
return Id.GetHashCode();
Expand Down
7 changes: 6 additions & 1 deletion Rewrite/src/Rewrite.CSharp/Tree/CollectionExpression.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,16 @@ public Cs.CollectionExpression WithElements(IList<JRightPadded<Expression>> newE

}

#if DEBUG_VISITOR
[DebuggerStepThrough]
#endif
public bool Equals(Rewrite.Core.Tree? other)
{
return other is CollectionExpression && other.Id == Id;
}

#if DEBUG_VISITOR
[DebuggerStepThrough]
#endif
public override int GetHashCode()
{
return Id.GetHashCode();
Expand Down
7 changes: 6 additions & 1 deletion Rewrite/src/Rewrite.CSharp/Tree/CompilationUnit.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,16 @@ public Cs.CompilationUnit WithMembers(IList<JRightPadded<Statement>> newMembers)

}

#if DEBUG_VISITOR
[DebuggerStepThrough]
#endif
public bool Equals(Rewrite.Core.Tree? other)
{
return other is CompilationUnit && other.Id == Id;
}

#if DEBUG_VISITOR
[DebuggerStepThrough]
#endif
public override int GetHashCode()
{
return Id.GetHashCode();
Expand Down
Loading
Loading