Skip to content

Commit

Permalink
Add support for many new c# LST(#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
macsux authored Dec 18, 2024
1 parent 7dcf298 commit a3e92ff
Show file tree
Hide file tree
Showing 214 changed files with 10,783 additions and 1,087 deletions.
2 changes: 2 additions & 0 deletions Rewrite/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<RemotePrinter>True</RemotePrinter>
<DebugVisitor>False</DebugVisitor>
<SanitizeStackTrace>True</SanitizeStackTrace>
<EmbeddedServer>true</EmbeddedServer>
</PropertyGroup>

<PropertyGroup Condition="'$(RELEASE_PUBLICATION)'!=''">
Expand All @@ -30,5 +31,6 @@
<DefineConstants Condition="'$(RemotePrinter)'">$(DefineConstants);REMOTE_PRINTER</DefineConstants>
<DefineConstants Condition="'$(DebugVisitor)'">$(DefineConstants);DEBUG_VISITOR</DefineConstants>
<DefineConstants Condition="'$(SanitizeStackTrace)'">$(DefineConstants);SANITIZE_STACK_TRACE</DefineConstants>
<DefineConstants Condition="'$(EmbeddedServer)'">$(DefineConstants);EMBEDDED_SERVER</DefineConstants>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion Rewrite/Rewrite.Sources.sln
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rewrite.Test.CSharp", "src\
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rewrite.Test.Engine.Remote", "src\Rewrite.Test.Engine.Remote\Rewrite.Test.Engine.Remote.csproj", "{C04C7CA4-69C3-444F-A654-6C722A0FC3BE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rewrite.Server", "..\..\..\moderneinc\rewrite-remote\Rewrite.Remote\src\Rewrite.Server\Rewrite.Server.csproj", "{E0721BA1-2772-4486-BDF3-FC9301723BB9}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rewrite.Remote.Server", "..\..\..\moderneinc\rewrite-remote\Rewrite.Remote\src\Rewrite.Remote.Server\Rewrite.Remote.Server.csproj", "{E0721BA1-2772-4486-BDF3-FC9301723BB9}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rewrite.Analyzers", "src\Rewrite.Analyzers\Rewrite.Analyzers.csproj", "{9818146E-C516-4D3C-80CE-A84741E7772B}"
EndProject
Expand Down
385 changes: 347 additions & 38 deletions Rewrite/src/Rewrite.CSharp/CSharpPrinter.cs

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions Rewrite/src/Rewrite.CSharp/CSharpTypeSignatureBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ public string Signature(ISymbol type)
{
if (type is ITypeSymbol)
return type.ToDisplayString(SymbolDisplayFormat.CSharpErrorMessageFormat);
if(type is IPropertySymbol propertySymbol)
return propertySymbol.Type.ToDisplayString(SymbolDisplayFormat.CSharpErrorMessageFormat);
throw new NotImplementedException();
}

Expand Down Expand Up @@ -56,7 +58,7 @@ public string ParameterSignature(IParameterSymbol parameterSymbol)
{
containingSymbol = containingSymbol.ContainingSymbol;
}

string owner;
if (containingSymbol is IMethodSymbol ms)
{
Expand All @@ -66,4 +68,4 @@ public string ParameterSignature(IParameterSymbol parameterSymbol)
owner = Signature(containingSymbol);
return owner + '{' + parameterSymbol.Name + ',' + Signature(parameterSymbol.Type) + '}';
}
}
}
283 changes: 274 additions & 9 deletions Rewrite/src/Rewrite.CSharp/CSharpVisitor.g.cs

Large diffs are not rendered by default.

882 changes: 522 additions & 360 deletions Rewrite/src/Rewrite.CSharp/Parser/CSharpParserVisitor.cs

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions Rewrite/src/Rewrite.CSharp/Tree/AliasQualifiedName.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System.Diagnostics.CodeAnalysis;
using Rewrite.RewriteJava.Tree;

namespace Rewrite.RewriteCSharp.Tree;

[SuppressMessage("ReSharper", "InconsistentNaming")]
[SuppressMessage("ReSharper", "PossibleUnintendedReferenceComparison")]
[SuppressMessage("ReSharper", "InvertIf")]
[SuppressMessage("ReSharper", "RedundantExtendsListEntry")]
[SuppressMessage("ReSharper", "UnusedMember.Global")]
[SuppressMessage("ReSharper", "RedundantNameQualifier")]
public partial interface Cs : J
{
partial class AliasQualifiedName
{
public bool Equals(Core.Marker.Marker? other)
{
return other is AliasQualifiedName otherAlias && otherAlias.Alias.Equals(this.Alias) && otherAlias.Name.Equals(this.Name);
}
}
}
136 changes: 136 additions & 0 deletions Rewrite/src/Rewrite.CSharp/Tree/AliasQualifiedName.g.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
//------------------------------------------------------------------------------
// <auto-generated>
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
#nullable enable
#pragma warning disable CS0108 // 'member1' hides inherited member 'member2'. Use the new keyword if hiding was intended.
#pragma warning disable CS8767 // Nullability of reference types in type of parameter doesn't match implicitly implemented member (possibly because of nullability attributes).
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using Rewrite.Core;
using Rewrite.Core.Marker;
using FileAttributes = Rewrite.Core.FileAttributes;
using Rewrite.RewriteJava.Tree;

namespace Rewrite.RewriteCSharp.Tree;

[SuppressMessage("ReSharper", "InconsistentNaming")]
[SuppressMessage("ReSharper", "PossibleUnintendedReferenceComparison")]
[SuppressMessage("ReSharper", "InvertIf")]
[SuppressMessage("ReSharper", "RedundantExtendsListEntry")]
[SuppressMessage("ReSharper", "UnusedMember.Global")]
[SuppressMessage("ReSharper", "RedundantNameQualifier")]
public partial interface Cs : J
{
/// <summary>
/// Represents a C# alias qualified name, which uses an extern alias to qualify a name.
/// <br/>
/// For example:
/// <code>
/// // Using LibA to qualify TypeName
/// LibA::TypeName
/// // Using LibB to qualify namespace
/// LibB::System.Collections
/// </code>
/// </summary>
#if DEBUG_VISITOR
[DebuggerStepThrough]
#endif
public partial class AliasQualifiedName(
Guid id,
Space prefix,
Markers markers,
JRightPadded<J.Identifier> alias,
Expression name
) : Cs, TypeTree, Expression, Rewrite.Core.Marker.Marker, Expression<AliasQualifiedName>, TypedTree<AliasQualifiedName>, J<AliasQualifiedName>, TypeTree<AliasQualifiedName>, MutableTree<AliasQualifiedName>
{
[NonSerialized] private WeakReference<PaddingHelper>? _padding;

public PaddingHelper Padding
{
get
{
PaddingHelper? p;
if (_padding == null)
{
p = new PaddingHelper(this);
_padding = new WeakReference<PaddingHelper>(p);
}
else
{
_padding.TryGetTarget(out p);
if (p == null || p.T != this)
{
p = new PaddingHelper(this);
_padding.SetTarget(p);
}
}
return p;
}
}

public J? AcceptCSharp<P>(CSharpVisitor<P> v, P p)
{
return v.VisitAliasQualifiedName(this, p);
}

public Guid Id => id;

public AliasQualifiedName WithId(Guid newId)
{
return newId == id ? this : new AliasQualifiedName(newId, prefix, markers, _alias, name);
}
public Space Prefix => prefix;

public AliasQualifiedName WithPrefix(Space newPrefix)
{
return newPrefix == prefix ? this : new AliasQualifiedName(id, newPrefix, markers, _alias, name);
}
public Markers Markers => markers;

public AliasQualifiedName WithMarkers(Markers newMarkers)
{
return ReferenceEquals(newMarkers, markers) ? this : new AliasQualifiedName(id, prefix, newMarkers, _alias, name);
}
private readonly JRightPadded<J.Identifier> _alias = alias;
public J.Identifier Alias => _alias.Element;

public AliasQualifiedName WithAlias(J.Identifier newAlias)
{
return Padding.WithAlias(_alias.WithElement(newAlias));
}
public Expression Name => name;

public AliasQualifiedName WithName(Expression newName)
{
return ReferenceEquals(newName, name) ? this : new AliasQualifiedName(id, prefix, markers, _alias, newName);
}
public sealed record PaddingHelper(Cs.AliasQualifiedName T)
{
public JRightPadded<J.Identifier> Alias => T._alias;

public Cs.AliasQualifiedName WithAlias(JRightPadded<J.Identifier> newAlias)
{
return T._alias == newAlias ? T : new Cs.AliasQualifiedName(T.Id, T.Prefix, T.Markers, newAlias, T.Name);
}

}

#if DEBUG_VISITOR
[DebuggerStepThrough]
#endif
public bool Equals(Rewrite.Core.Tree? other)
{
return other is AliasQualifiedName && other.Id == Id;
}
#if DEBUG_VISITOR
[DebuggerStepThrough]
#endif
public override int GetHashCode()
{
return Id.GetHashCode();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public partial class AllowsConstraintClause(
Space prefix,
Markers markers,
JContainer<AllowsConstraint> expressions
) : Cs, Cs.TypeParameterConstraint, MutableTree<AllowsConstraintClause>
) : Cs, Cs.TypeParameterConstraint, J<AllowsConstraintClause>, MutableTree<AllowsConstraintClause>
{
[NonSerialized] private WeakReference<PaddingHelper>? _padding;

Expand Down
2 changes: 1 addition & 1 deletion Rewrite/src/Rewrite.CSharp/Tree/AnnotatedStatement.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public partial class AnnotatedStatement(
Markers markers,
IList<AttributeList> attributeLists,
Statement statement
) : Cs, Statement, MutableTree<AnnotatedStatement>
) : Cs, Statement, J<AnnotatedStatement>, MutableTree<AnnotatedStatement>
{
public J? AcceptCSharp<P>(CSharpVisitor<P> v, P p)
{
Expand Down
2 changes: 1 addition & 1 deletion Rewrite/src/Rewrite.CSharp/Tree/Argument.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public partial class Argument(
JRightPadded<J.Identifier>? nameColumn,
Keyword? refKindKeyword,
Expression expression
) : Cs, Expression, Expression<Argument>, MutableTree<Argument>
) : Cs, Expression, Expression<Argument>, J<Argument>, MutableTree<Argument>
{
[NonSerialized] private WeakReference<PaddingHelper>? _padding;

Expand Down
2 changes: 1 addition & 1 deletion Rewrite/src/Rewrite.CSharp/Tree/ArrayRankSpecifier.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public partial class ArrayRankSpecifier(
Space prefix,
Markers markers,
JContainer<Expression> sizes
) : Cs, Expression, Expression<ArrayRankSpecifier>, MutableTree<ArrayRankSpecifier>
) : Cs, Expression, Expression<ArrayRankSpecifier>, J<ArrayRankSpecifier>, MutableTree<ArrayRankSpecifier>
{
[NonSerialized] private WeakReference<PaddingHelper>? _padding;

Expand Down
95 changes: 95 additions & 0 deletions Rewrite/src/Rewrite.CSharp/Tree/ArrayType.g.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
//------------------------------------------------------------------------------
// <auto-generated>
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
#nullable enable
#pragma warning disable CS0108 // 'member1' hides inherited member 'member2'. Use the new keyword if hiding was intended.
#pragma warning disable CS8767 // Nullability of reference types in type of parameter doesn't match implicitly implemented member (possibly because of nullability attributes).
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using Rewrite.Core;
using Rewrite.Core.Marker;
using FileAttributes = Rewrite.Core.FileAttributes;
using Rewrite.RewriteJava.Tree;

namespace Rewrite.RewriteCSharp.Tree;

[SuppressMessage("ReSharper", "InconsistentNaming")]
[SuppressMessage("ReSharper", "PossibleUnintendedReferenceComparison")]
[SuppressMessage("ReSharper", "InvertIf")]
[SuppressMessage("ReSharper", "RedundantExtendsListEntry")]
[SuppressMessage("ReSharper", "UnusedMember.Global")]
[SuppressMessage("ReSharper", "RedundantNameQualifier")]
public partial interface Cs : J
{
#if DEBUG_VISITOR
[DebuggerStepThrough]
#endif
public partial class ArrayType(
Guid id,
Space prefix,
Markers markers,
TypeTree? typeExpression,
IList<J.ArrayDimension> dimensions,
JavaType? type
) : Cs, Expression, TypeTree, Expression<ArrayType>, TypedTree<ArrayType>, J<ArrayType>, TypeTree<ArrayType>, MutableTree<ArrayType>
{
public J? AcceptCSharp<P>(CSharpVisitor<P> v, P p)
{
return v.VisitArrayType(this, p);
}

public Guid Id => id;

public ArrayType WithId(Guid newId)
{
return newId == id ? this : new ArrayType(newId, prefix, markers, typeExpression, dimensions, type);
}
public Space Prefix => prefix;

public ArrayType WithPrefix(Space newPrefix)
{
return newPrefix == prefix ? this : new ArrayType(id, newPrefix, markers, typeExpression, dimensions, type);
}
public Markers Markers => markers;

public ArrayType WithMarkers(Markers newMarkers)
{
return ReferenceEquals(newMarkers, markers) ? this : new ArrayType(id, prefix, newMarkers, typeExpression, dimensions, type);
}
public TypeTree? TypeExpression => typeExpression;

public ArrayType WithTypeExpression(TypeTree? newTypeExpression)
{
return ReferenceEquals(newTypeExpression, typeExpression) ? this : new ArrayType(id, prefix, markers, newTypeExpression, dimensions, type);
}
public IList<J.ArrayDimension> Dimensions => dimensions;

public ArrayType WithDimensions(IList<J.ArrayDimension> newDimensions)
{
return newDimensions == dimensions ? this : new ArrayType(id, prefix, markers, typeExpression, newDimensions, type);
}
public JavaType? Type => type;

public ArrayType WithType(JavaType? newType)
{
return newType == type ? this : new ArrayType(id, prefix, markers, typeExpression, dimensions, newType);
}
#if DEBUG_VISITOR
[DebuggerStepThrough]
#endif
public bool Equals(Rewrite.Core.Tree? other)
{
return other is ArrayType && other.Id == Id;
}
#if DEBUG_VISITOR
[DebuggerStepThrough]
#endif
public override int GetHashCode()
{
return Id.GetHashCode();
}
}
}
2 changes: 1 addition & 1 deletion Rewrite/src/Rewrite.CSharp/Tree/AssignmentOperation.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public partial class AssignmentOperation(
JLeftPadded<AssignmentOperation.OperatorType> @operator,
Expression assignment,
JavaType? type
) : Cs, Statement, Expression, TypedTree, Expression<AssignmentOperation>, TypedTree<AssignmentOperation>, MutableTree<AssignmentOperation>
) : Cs, Statement, Expression, TypedTree, Expression<AssignmentOperation>, TypedTree<AssignmentOperation>, J<AssignmentOperation>, MutableTree<AssignmentOperation>
{
[NonSerialized] private WeakReference<PaddingHelper>? _padding;

Expand Down
2 changes: 1 addition & 1 deletion Rewrite/src/Rewrite.CSharp/Tree/AttributeList.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public partial class AttributeList(
Markers markers,
JRightPadded<J.Identifier>? target,
IList<JRightPadded<J.Annotation>> attributes
) : Cs, MutableTree<AttributeList>
) : Cs, J<AttributeList>, MutableTree<AttributeList>
{
[NonSerialized] private WeakReference<PaddingHelper>? _padding;

Expand Down
8 changes: 4 additions & 4 deletions Rewrite/src/Rewrite.CSharp/Tree/AwaitExpression.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ public partial class AwaitExpression(
Guid id,
Space prefix,
Markers markers,
Expression expression,
J expression,
JavaType? type
) : Cs, Expression, Expression<AwaitExpression>, MutableTree<AwaitExpression>
) : Cs, Expression, Statement, Expression<AwaitExpression>, J<AwaitExpression>, MutableTree<AwaitExpression>
{
public J? AcceptCSharp<P>(CSharpVisitor<P> v, P p)
{
Expand All @@ -58,9 +58,9 @@ public AwaitExpression WithMarkers(Markers newMarkers)
{
return ReferenceEquals(newMarkers, markers) ? this : new AwaitExpression(id, prefix, newMarkers, expression, type);
}
public Expression Expression => expression;
public J Expression => expression;

public AwaitExpression WithExpression(Expression newExpression)
public AwaitExpression WithExpression(J newExpression)
{
return ReferenceEquals(newExpression, expression) ? this : new AwaitExpression(id, prefix, markers, newExpression, type);
}
Expand Down
2 changes: 1 addition & 1 deletion Rewrite/src/Rewrite.CSharp/Tree/Binary.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public partial class Binary(
JLeftPadded<Binary.OperatorType> @operator,
Expression right,
JavaType? type
) : Cs, Expression, TypedTree, Expression<Binary>, TypedTree<Binary>, MutableTree<Binary>
) : Cs, Expression, TypedTree, Expression<Binary>, TypedTree<Binary>, J<Binary>, MutableTree<Binary>
{
[NonSerialized] private WeakReference<PaddingHelper>? _padding;

Expand Down
Loading

0 comments on commit a3e92ff

Please sign in to comment.