Skip to content

Commit c96f909

Browse files
committed
update roslyn & fix warnning
1 parent e3da7fc commit c96f909

File tree

6 files changed

+50
-66
lines changed

6 files changed

+50
-66
lines changed

CSharp.lua/CSharp.lua.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
</PropertyGroup>
1515

1616
<ItemGroup>
17-
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.3.1" />
17+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.4.0" />
1818
</ItemGroup>
1919

2020
<ItemGroup>

CSharp.lua/LuaSyntaxGenerator.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public int Indent {
122122
private readonly Dictionary<INamedTypeSymbol, List<PartialTypeDeclaration>> partialTypes_ = new Dictionary<INamedTypeSymbol, List<PartialTypeDeclaration>>();
123123
private readonly HashSet<string> monoBehaviourSpecialMethodNames_;
124124
private IMethodSymbol mainEntryPoint_;
125-
private List<LuaExpressionSyntax> assemblyAttributes_ = new List<LuaExpressionSyntax>();
125+
private readonly List<LuaExpressionSyntax> assemblyAttributes_ = new List<LuaExpressionSyntax>();
126126
public INamedTypeSymbol SystemExceptionTypeSymbol { get; }
127127
private readonly INamedTypeSymbol monoBehaviourTypeSymbol_;
128128

@@ -690,13 +690,13 @@ private LuaIdentifierNameSyntax InternalGetMemberName(ISymbol symbol) {
690690
}
691691

692692
private static bool IsSameNameSymbol(ISymbol member, ISymbol symbol) {
693-
if (member.Equals(symbol)) {
693+
if (member.EQ(symbol)) {
694694
return true;
695695
}
696696

697697
if (symbol.Kind == SymbolKind.Method) {
698698
var methodSymbol = (IMethodSymbol)symbol;
699-
if (methodSymbol.PartialDefinitionPart != null && methodSymbol.PartialDefinitionPart.Equals(member)) {
699+
if (methodSymbol.PartialDefinitionPart != null && methodSymbol.PartialDefinitionPart.EQ(member)) {
700700
return true;
701701
}
702702
}
@@ -782,7 +782,7 @@ private LuaIdentifierNameSyntax GetStaticClassMemberName(ISymbol symbol) {
782782
int index = 0;
783783
foreach (ISymbol member in sameNameMembers) {
784784
LuaIdentifierNameSyntax identifierName = GetMethodNameFromIndex(symbol, index);
785-
if (member.Equals(symbol)) {
785+
if (member.EQ(symbol)) {
786786
symbolExpression = identifierName;
787787
} else {
788788
if (!memberNames_.ContainsKey(member)) {
@@ -843,7 +843,7 @@ private List<ISymbol> GetSameNameMembers(ISymbol symbol) {
843843
var rootType = symbol.ContainingType;
844844
var curTypeSymbol = rootType;
845845
while (true) {
846-
AddSimilarNameMembers(curTypeSymbol, names, members, !rootType.Equals(curTypeSymbol));
846+
AddSimilarNameMembers(curTypeSymbol, names, members, !rootType.EQ(curTypeSymbol));
847847
var baseTypeSymbol = curTypeSymbol.BaseType;
848848
if (baseTypeSymbol != null) {
849849
curTypeSymbol = baseTypeSymbol;
@@ -950,7 +950,7 @@ private int MemberSymbolComparison(ISymbol a, ISymbol b) {
950950
if (countOfA == 1) {
951951
var implementationOfA = a.InterfaceImplementations().First();
952952
var implementationOfB = b.InterfaceImplementations().First();
953-
if (implementationOfA.Equals(implementationOfB)) {
953+
if (implementationOfA.EQ(implementationOfB)) {
954954
throw new CompilationErrorException($"{a} is conflict with {b}");
955955
}
956956

@@ -976,7 +976,7 @@ private int MemberSymbolComparison(ISymbol a, ISymbol b) {
976976
}
977977

978978
private int MemberSymbolCommonComparison(ISymbol a, ISymbol b) {
979-
if (a.ContainingType.Equals(b.ContainingType)) {
979+
if (a.ContainingType.EQ(b.ContainingType)) {
980980
var type = a.ContainingType;
981981
var names = GetSymbolNames(a);
982982
List<ISymbol> members = new List<ISymbol>();
@@ -1306,7 +1306,7 @@ private void CheckImplicitInterfaceImplementation(INamedTypeSymbol type) {
13061306
}
13071307

13081308
var implementationType = implementationMember.ContainingType;
1309-
if (!implementationType.Equals(type)) {
1309+
if (!implementationType.EQ(type)) {
13101310
if (!implementationType.AllInterfaces.Contains(baseInterface)) {
13111311
generator_.AddImplicitInterfaceImplementation(implementationMember, interfaceMember);
13121312
generator_.TryAddExtend(baseInterface, implementationType);
@@ -1372,7 +1372,7 @@ private string GetTypeOrNamespaceNewName(IEnumerable<ISymbol> allSymbols, ISymbo
13721372
}
13731373

13741374
private static bool CheckTypeNameExists(IEnumerable<ISymbol> all, ISymbol type, string newName) {
1375-
return all.Where(i => i.ContainingNamespace.Equals(type.ContainingNamespace)).Any(i => i.Name == newName);
1375+
return all.Where(i => i.ContainingNamespace.EQ(type.ContainingNamespace)).Any(i => i.Name == newName);
13761376
}
13771377

13781378
private void CheckNamespace() {
@@ -1599,12 +1599,12 @@ public bool IsMoreThanLocalVariables(ISymbol symbol) {
15991599
int index = 0;
16001600
switch (symbol.Kind) {
16011601
case SymbolKind.Method: {
1602-
index = methods.FindIndex(i => i.Equals(symbol));
1602+
index = methods.FindIndex(i => i.EQ(symbol));
16031603
break;
16041604
}
16051605
case SymbolKind.Property:
16061606
case SymbolKind.Event: {
1607-
index = methods.FindIndex(i => i.Kind == SymbolKind.Method && symbol.Equals(((IMethodSymbol)i).AssociatedSymbol)) + 1;
1607+
index = methods.FindIndex(i => i.Kind == SymbolKind.Method && symbol.EQ(((IMethodSymbol)i).AssociatedSymbol)) + 1;
16081608
break;
16091609
}
16101610
}

CSharp.lua/LuaSyntaxNodeTransform.Helper.cs

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -873,7 +873,7 @@ internal bool AddGenericImport(LuaInvocationExpressionSyntax invocationExpressio
873873
}
874874

875875
internal void ImportGenericTypeName(ref LuaExpressionSyntax luaExpression, ITypeSymbol symbol) {
876-
if (!IsNoImportTypeName && !CurTypeSymbol.Equals(symbol) && !IsCurMethodTypeArgument(symbol)) {
876+
if (!IsNoImportTypeName && !CurTypeSymbol.EQ(symbol) && !IsCurMethodTypeArgument(symbol)) {
877877
var invocationExpression = (LuaInvocationExpressionSyntax)luaExpression;
878878
string newName = GetGenericTypeImportName(invocationExpression, out var argumentTypeNames);
879879
if (!IsLocalVarExistsInCurMethod(newName)) {
@@ -1094,8 +1094,7 @@ private void CheckValueTypeClone(ITypeSymbol typeSymbol, IdentifierNameSyntax no
10941094
}
10951095
}
10961096

1097-
var symbol = semanticModel_.GetSymbolInfo(argument.Parent.Parent).Symbol as IMethodSymbol;
1098-
if (symbol != null) {
1097+
if (semanticModel_.GetSymbolInfo(argument.Parent.Parent).Symbol is IMethodSymbol symbol) {
10991098
if (symbol.IsFromAssembly() && !symbol.ContainingType.IsCollectionType()) {
11001099
break;
11011100
}
@@ -1266,7 +1265,7 @@ private void CheckConversion(ExpressionSyntax node, ref LuaExpressionSyntax expr
12661265

12671266
private LuaExpressionSyntax GetOperatorMemberAccessExpression(IMethodSymbol methodSymbol) {
12681267
var methodName = GetMemberName(methodSymbol);
1269-
if (CurTypeSymbol.Equals(methodSymbol.ContainingType)) {
1268+
if (CurTypeSymbol.EQ(methodSymbol.ContainingType)) {
12701269
return methodName;
12711270
}
12721271

@@ -1392,7 +1391,7 @@ public SymbolAssignmentSearcher(LuaSyntaxGenerator generator, ISymbol symbol) {
13921391
public override void VisitAssignmentExpression(AssignmentExpressionSyntax node) {
13931392
var semanticModel = generator_.GetSemanticModel(node.SyntaxTree);
13941393
var symbol = semanticModel.GetSymbolInfo(node.Left).Symbol;
1395-
if (symbol_.Equals(symbol)) {
1394+
if (symbol_.EQ(symbol)) {
13961395
Found();
13971396
}
13981397

@@ -1411,7 +1410,7 @@ public override void VisitInvocationExpression(InvocationExpressionSyntax node)
14111410
foreach (var argument in node.ArgumentList.Arguments) {
14121411
if (argument.RefKindKeyword.IsOutOrRef()) {
14131412
var symbol = semanticModel.GetSymbolInfo(argument.Expression).Symbol;
1414-
if (symbol.Equals(symbol_)) {
1413+
if (symbol.EQ(symbol_)) {
14151414
Found();
14161415
}
14171416
}
@@ -1751,7 +1750,7 @@ public override void VisitInvocationExpression(InvocationExpressionSyntax node)
17511750

17521751
var methodSymbol = (IMethodSymbol)semanticModel.GetSymbolInfo(node).Symbol;
17531752
if (methodSymbol != null) {
1754-
if (methodSymbol.Equals(symbol_)) {
1753+
if (methodSymbol.EQ(symbol_)) {
17551754
Found();
17561755
}
17571756
}
@@ -1776,8 +1775,7 @@ private bool InliningInvocationExpression(SyntaxNode root, IMethodSymbol symbol,
17761775
BlockSyntax bodyNode;
17771776
ArrowExpressionClauseSyntax expressionBodyNode;
17781777
if (symbol.MethodKind == MethodKind.PropertyGet) {
1779-
var propertyDeclaration = symbol.AssociatedSymbol.GetDeclaringSyntaxNode() as PropertyDeclarationSyntax;
1780-
if (propertyDeclaration == null) {
1778+
if (!(symbol.AssociatedSymbol.GetDeclaringSyntaxNode() is PropertyDeclarationSyntax propertyDeclaration)) {
17811779
goto Fail;
17821780
}
17831781

@@ -1787,8 +1785,7 @@ private bool InliningInvocationExpression(SyntaxNode root, IMethodSymbol symbol,
17871785
expressionBodyNode = accessor.ExpressionBody;
17881786
parameterList = null;
17891787
} else {
1790-
var methodDeclaration = symbol.GetDeclaringSyntaxNode() as MethodDeclarationSyntax;
1791-
if (methodDeclaration == null) {
1788+
if (!(symbol.GetDeclaringSyntaxNode() is MethodDeclarationSyntax methodDeclaration)) {
17921789
goto Fail;
17931790
}
17941791

@@ -1945,13 +1942,11 @@ private LuaExpressionSyntax CompressionInliningBlock(SyntaxNode root, LuaBlockSt
19451942
}
19461943
}
19471944

1948-
var expressionStatement = block.Statements.Last() as LuaExpressionStatementSyntax;
1949-
if (expressionStatement == null) {
1945+
if (!(block.Statements.Last() is LuaExpressionStatementSyntax expressionStatement)) {
19501946
return null;
19511947
}
19521948

1953-
var assignment = expressionStatement.Expression as LuaAssignmentExpressionSyntax;
1954-
if (assignment == null) {
1949+
if (!(expressionStatement.Expression is LuaAssignmentExpressionSyntax assignment)) {
19551950
return null;
19561951
}
19571952

@@ -2038,8 +2033,7 @@ private bool IsWantInline(IPropertySymbol symbol) {
20382033
return false;
20392034
}
20402035

2041-
var propertyDeclaration = symbol.GetDeclaringSyntaxNode() as PropertyDeclarationSyntax;
2042-
if (propertyDeclaration == null || propertyDeclaration.AccessorList == null) {
2036+
if (!(symbol.GetDeclaringSyntaxNode() is PropertyDeclarationSyntax propertyDeclaration) || propertyDeclaration.AccessorList == null) {
20432037
return false;
20442038
}
20452039

@@ -2050,8 +2044,7 @@ private bool IsWantInline(IPropertySymbol symbol) {
20502044
return false;
20512045
}
20522046

2053-
var returnStatement = accessor.Body.Statements.First() as ReturnStatementSyntax;
2054-
if (returnStatement == null) {
2047+
if (!(accessor.Body.Statements.First() is ReturnStatementSyntax returnStatement)) {
20552048
return false;
20562049
}
20572050

CSharp.lua/LuaSyntaxNodeTransform.Object.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ private LuaTryAdapterExpressionSyntax VisitTryCatchesExpress(SyntaxList<CatchCla
560560
if (catchNode.Declaration != null) {
561561
var typeName = catchNode.Declaration.Type.Accept<LuaIdentifierNameSyntax>(this);
562562
var typeSymbol = semanticModel_.GetTypeInfo(catchNode.Declaration.Type).Type;
563-
if (!typeSymbol.Equals(generator_.SystemExceptionTypeSymbol)) {
563+
if (!typeSymbol.EQ(generator_.SystemExceptionTypeSymbol)) {
564564
var mathcTypeInvocation = new LuaInvocationExpressionSyntax(LuaIdentifierNameSyntax.Is, temp, typeName);
565565
if (ifCondition != null) {
566566
ifCondition = ifCondition.And(mathcTypeInvocation);
@@ -781,7 +781,7 @@ private BaseVisitType CheckBaseVisitType<T>(T symbol, Func<T, ISymbol> overridde
781781
if (generator_.IsSealed(curTypeSymbol)) {
782782
bool exists = curTypeSymbol.GetMembers().OfType<T>().Any(i => {
783783
var overriddenSymbol = overriddenFunc(i);
784-
return overriddenSymbol != null && overriddenSymbol.OriginalDefinition.Equals(symbol.OriginalDefinition);
784+
return overriddenSymbol != null && overriddenSymbol.OriginalDefinition.EQ(symbol.OriginalDefinition);
785785
});
786786
return exists ? BaseVisitType.UseBase : BaseVisitType.UseThis;
787787
} else {
@@ -1191,7 +1191,7 @@ public override LuaSyntaxNode VisitArrowExpressionClause(ArrowExpressionClauseSy
11911191
}
11921192

11931193
public override LuaSyntaxNode VisitLocalFunctionStatement(LocalFunctionStatementSyntax node) {
1194-
var result = BuildMethodDeclaration(node, default, node.ParameterList, node.TypeParameterList, node.Body, node.ExpressionBody, node.ReturnType);
1194+
var result = BuildMethodDeclaration(node, default, node.ParameterList, node.TypeParameterList, node.Body, node.ExpressionBody);
11951195
if (node.Modifiers.IsStatic() && IsStaticLocalMethodEnableAddToType(result.Symbol)) {
11961196
CurTypeDeclaration.TypeDeclaration.AddMethod(result.Name, result.Function, true, result.Document);
11971197
return LuaStatementSyntax.Empty;

CSharp.lua/LuaSyntaxNodeTransform.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public TypeDeclarationInfo(INamedTypeSymbol typeSymbol, LuaTypeDeclarationSyntax
5858
}
5959

6060
public bool CheckTypeName(INamedTypeSymbol getNameTypeSymbol, out LuaIdentifierNameSyntax name) {
61-
if (getNameTypeSymbol.Equals(TypeSymbol)) {
61+
if (getNameTypeSymbol.EQ(TypeSymbol)) {
6262
TypeDeclaration.IsClassUsed = true;
6363
name = LuaIdentifierNameSyntax.Class;
6464
return true;
@@ -624,8 +624,7 @@ private MethodDeclarationResult BuildMethodDeclaration(
624624
ParameterListSyntax parameterList,
625625
TypeParameterListSyntax typeParameterList,
626626
BlockSyntax body,
627-
ArrowExpressionClauseSyntax expressionBody,
628-
TypeSyntax returnType) {
627+
ArrowExpressionClauseSyntax expressionBody) {
629628
IMethodSymbol symbol = (IMethodSymbol)semanticModel_.GetDeclaredSymbol(node);
630629
var refOrOutParameters = new List<LuaExpressionSyntax>();
631630
MethodInfo methodInfo = new MethodInfo(symbol, refOrOutParameters);
@@ -720,7 +719,7 @@ private bool IsCurTypeSerializable {
720719

721720
public override LuaSyntaxNode VisitMethodDeclaration(MethodDeclarationSyntax node) {
722721
if ((node.Body != null || node.ExpressionBody != null) && !node.HasCSharpLuaAttribute(LuaDocumentStatement.AttributeFlags.Ignore)) {
723-
var result = BuildMethodDeclaration(node, node.AttributeLists, node.ParameterList, node.TypeParameterList, node.Body, node.ExpressionBody, node.ReturnType);
722+
var result = BuildMethodDeclaration(node, node.AttributeLists, node.ParameterList, node.TypeParameterList, node.Body, node.ExpressionBody);
724723
bool isMoreThanLocalVariables = IsMoreThanLocalVariables(result.Symbol);
725724
CurType.AddMethod(result.Name, result.Function, result.IsPrivate, result.Document, isMoreThanLocalVariables, result.Symbol.IsInterfaceDefaultMethod());
726725
if (IsCurTypeExportMetadataAll || result.Attributes.Count > 0 || result.IsMetadata) {
@@ -1278,7 +1277,7 @@ public LuaSyntaxNode Visit(LuaSyntaxNodeTransform transfor) {
12781277
return new LuaShortCommentStatement(commentContent);
12791278
}
12801279
case SyntaxKind.MultiLineCommentTrivia: {
1281-
string commentContent = content.Substring(kCommentCharCount, content.Length - kCommentCharCount - kCommentCharCount);
1280+
string commentContent = content[kCommentCharCount..^kCommentCharCount];
12821281
commentContent = commentContent.ReplaceNewline();
12831282
if (CheckInsertLuaCodeTemplate(commentContent, out var codeStatement)) {
12841283
return codeStatement;
@@ -2864,7 +2863,7 @@ private void CheckDelegateBind(IMethodSymbol symbol, CSharpSyntaxNode node, ref
28642863
const int kReturnParameterIndex = int.MaxValue;
28652864
if (symbol.IsGenericMethod) {
28662865
var originalDefinition = symbol.OriginalDefinition;
2867-
if (!originalDefinition.Equals(symbol)) {
2866+
if (!originalDefinition.EQ(symbol)) {
28682867
var targetMethodSymbol = GetDelegateTargetMethodSymbol(node);
28692868
var targetTypeParameters = new List<TypeParameterPlaceholder>();
28702869
foreach (var typeArgument in targetMethodSymbol.ContainingType.TypeArguments) {
@@ -4339,7 +4338,7 @@ private void ChecktIncrementExpression(ExpressionSyntax operand, ref LuaExpressi
43394338
var symbol = semanticModel_.GetTypeInfo(operand).Type;
43404339
if (!symbol.IsNumberType()) {
43414340
var op_Implicits = symbol.GetMembers("op_Implicit").OfType<IMethodSymbol>();
4342-
var methodSymbol = op_Implicits.FirstOrDefault(i => isAddOrAssignment ? i.ReturnType.IsIntegerType() : i.ReturnType.Equals(symbol));
4341+
var methodSymbol = op_Implicits.FirstOrDefault(i => isAddOrAssignment ? i.ReturnType.IsIntegerType() : i.ReturnType.EQ(symbol));
43434342
if (methodSymbol != null) {
43444343
expression = BuildConversionExpression(methodSymbol, expression);
43454344
}
@@ -4615,7 +4614,7 @@ private void CheckForeachCast(LuaIdentifierNameSyntax identifier, ForEachStateme
46154614
bool hasCast = false;
46164615
var elementType = !isAsync ? sourceType.GetIEnumerableElementType() : sourceType.GetIAsyncEnumerableElementType();
46174616
if (elementType != null) {
4618-
if (!elementType.Equals(targetType) && !elementType.Is(targetType)) {
4617+
if (!elementType.EQ(targetType) && !elementType.Is(targetType)) {
46194618
hasCast = true;
46204619
}
46214620
} else {

0 commit comments

Comments
 (0)