diff --git a/Design/Rule0039ArgumentDifferentTypeThenExpected.cs b/Design/Rule0039ArgumentDifferentTypeThenExpected.cs index 27783c22..dff34d6d 100644 --- a/Design/Rule0039ArgumentDifferentTypeThenExpected.cs +++ b/Design/Rule0039ArgumentDifferentTypeThenExpected.cs @@ -54,39 +54,33 @@ private void AnalyzeRunPageArguments(OperationAnalysisContext ctx) private void AnalyzeSetRecordArgument(OperationAnalysisContext ctx) { - try - { - if (ctx.ContainingSymbol.GetContainingObjectTypeSymbol().IsObsoletePending || ctx.ContainingSymbol.GetContainingObjectTypeSymbol().IsObsoleteRemoved) return; - if (ctx.ContainingSymbol.IsObsoletePending || ctx.ContainingSymbol.IsObsoleteRemoved) return; + if (ctx.ContainingSymbol.GetContainingObjectTypeSymbol().IsObsoletePending || ctx.ContainingSymbol.GetContainingObjectTypeSymbol().IsObsoleteRemoved) return; + if (ctx.ContainingSymbol.IsObsoletePending || ctx.ContainingSymbol.IsObsoleteRemoved) return; - IInvocationExpression operation = (IInvocationExpression)ctx.Operation; - if (operation.TargetMethod.MethodKind != MethodKind.BuiltInMethod) return; + IInvocationExpression operation = (IInvocationExpression)ctx.Operation; + if (operation.TargetMethod.MethodKind != MethodKind.BuiltInMethod) return; - if (operation.TargetMethod.ContainingType.GetTypeSymbol().GetNavTypeKindSafe() != NavTypeKind.Page) return; - string[] procedureNames = { "GetRecord", "SetRecord", "SetSelectionFilter", "SetTableView" }; - if (!procedureNames.Contains(operation.TargetMethod.Name)) return; - if (operation.Arguments.Count() != 1) return; + if (operation.TargetMethod.ContainingType.GetTypeSymbol().GetNavTypeKindSafe() != NavTypeKind.Page) return; + string[] procedureNames = { "GetRecord", "SetRecord", "SetSelectionFilter", "SetTableView" }; + if (!procedureNames.Contains(operation.TargetMethod.Name)) return; + if (operation.Arguments.Count() != 1) return; - if (operation.Arguments[0].Syntax.Kind != SyntaxKind.IdentifierName || operation.Arguments[0].Value.Kind != OperationKind.ConversionExpression) return; + if (operation.Arguments[0].Syntax.Kind != SyntaxKind.IdentifierName || operation.Arguments[0].Value.Kind != OperationKind.ConversionExpression) return; - IOperation pageReference = ctx.Operation.DescendantsAndSelf().Where(x => x.GetSymbol() != null) - .Where(x => x.Type.GetNavTypeKindSafe() == NavTypeKind.Page) - .SingleOrDefault(); - if (pageReference == null) return; - IVariableSymbol variableSymbol = (IVariableSymbol)pageReference.GetSymbol().OriginalDefinition; - IPageTypeSymbol pageTypeSymbol = (IPageTypeSymbol)variableSymbol.GetTypeSymbol().OriginalDefinition; - ITableTypeSymbol pageSourceTable = pageTypeSymbol.RelatedTable; + IOperation pageReference = ctx.Operation.DescendantsAndSelf().Where(x => x.GetSymbol() != null) + .Where(x => x.Type.GetNavTypeKindSafe() == NavTypeKind.Page) + .SingleOrDefault(); + if (pageReference == null) return; + IVariableSymbol variableSymbol = (IVariableSymbol)pageReference.GetSymbol().OriginalDefinition; + IPageTypeSymbol pageTypeSymbol = (IPageTypeSymbol)variableSymbol.GetTypeSymbol().OriginalDefinition; + if (pageTypeSymbol.RelatedTable == null) return; + ITableTypeSymbol pageSourceTable = pageTypeSymbol.RelatedTable; - IOperation operand = ((IConversionExpression)operation.Arguments[0].Value).Operand; - ITableTypeSymbol recordArgument = ((IRecordTypeSymbol)operand.GetSymbol().GetTypeSymbol()).BaseTable; + IOperation operand = ((IConversionExpression)operation.Arguments[0].Value).Operand; + ITableTypeSymbol recordArgument = ((IRecordTypeSymbol)operand.GetSymbol().GetTypeSymbol()).BaseTable; - if (!AreTheSameNavObjects(recordArgument, pageSourceTable)) - ctx.ReportDiagnostic(Diagnostic.Create(DiagnosticDescriptors.Rule0039ArgumentDifferentTypeThenExpected, ctx.Operation.Syntax.GetLocation(), new object[] { 1, operand.GetSymbol().GetTypeSymbol().ToString(), pageSourceTable.GetNavTypeKindSafe() + " \"" + pageSourceTable.Name + "\"" })); - } - catch (NullReferenceException) - { - ctx.ReportDiagnostic(Diagnostic.Create(DiagnosticDescriptors.Rule0000ErrorInRule, ctx.Operation.Syntax.GetLocation(), new Object[] { "Rule0039", "NullReferenceException" })); - } + if (!AreTheSameNavObjects(recordArgument, pageSourceTable)) + ctx.ReportDiagnostic(Diagnostic.Create(DiagnosticDescriptors.Rule0039ArgumentDifferentTypeThenExpected, ctx.Operation.Syntax.GetLocation(), new object[] { 1, operand.GetSymbol().GetTypeSymbol().ToString(), pageSourceTable.GetNavTypeKindSafe() + " \"" + pageSourceTable.Name + "\"" })); } private void AnalyzeTableReferencePageProvider(SymbolAnalysisContext ctx) diff --git a/Design/Rule0048ErrorWithTextConstant.cs b/Design/Rule0048ErrorWithTextConstant.cs index 9f0f6ebf..1242c59a 100644 --- a/Design/Rule0048ErrorWithTextConstant.cs +++ b/Design/Rule0048ErrorWithTextConstant.cs @@ -15,35 +15,29 @@ public class Rule0048ErrorWithTextConstant : DiagnosticAnalyzer private void AnalyzeErrorMethod(OperationAnalysisContext ctx) { - try - { - if (ctx.ContainingSymbol.GetContainingObjectTypeSymbol().IsObsoletePending || ctx.ContainingSymbol.GetContainingObjectTypeSymbol().IsObsoleteRemoved) return; - if (ctx.ContainingSymbol.IsObsoletePending || ctx.ContainingSymbol.IsObsoleteRemoved) return; - - IInvocationExpression operation = (IInvocationExpression)ctx.Operation; - if (operation.TargetMethod.MethodKind != MethodKind.BuiltInMethod) return; - if (!SemanticFacts.IsSameName(operation.TargetMethod.Name, "Error")) return; - if (operation.Arguments.Length == 0) return; + if (ctx.ContainingSymbol.GetContainingObjectTypeSymbol().IsObsoletePending || ctx.ContainingSymbol.GetContainingObjectTypeSymbol().IsObsoleteRemoved) return; + if (ctx.ContainingSymbol.IsObsoletePending || ctx.ContainingSymbol.IsObsoleteRemoved) return; - if (operation.Arguments[0].Value.Type.GetNavTypeKindSafe() == NavTypeKind.ErrorInfo) return; + IInvocationExpression operation = (IInvocationExpression)ctx.Operation; + if (operation.TargetMethod.MethodKind != MethodKind.BuiltInMethod) return; + if (!SemanticFacts.IsSameName(operation.TargetMethod.Name, "Error")) return; + if (operation.Arguments.Length == 0) return; - switch (operation.Arguments[0].Syntax.Kind) - { - case SyntaxKind.IdentifierName: - IOperation operand = ((IConversionExpression)operation.Arguments[0].Value).Operand; - if (operand.GetSymbol().OriginalDefinition.GetTypeSymbol().GetNavTypeKindSafe() == NavTypeKind.Label) return; - break; - case SyntaxKind.LiteralExpression: - if (operation.Arguments[0].Syntax.GetIdentifierOrLiteralValue() == "") return; - break; - } + if (operation.Arguments[0].Value.Type.GetNavTypeKindSafe() == NavTypeKind.ErrorInfo) return; - ctx.ReportDiagnostic(Diagnostic.Create(DiagnosticDescriptors.Rule0048ErrorWithTextConstant, ctx.Operation.Syntax.GetLocation())); - } - catch (InvalidCastException) + switch (operation.Arguments[0].Syntax.Kind) { - ctx.ReportDiagnostic(Diagnostic.Create(DiagnosticDescriptors.Rule0000ErrorInRule, ctx.Operation.Syntax.GetLocation(), new Object[] { "Rule0048", "InvalidCastException" })); + case SyntaxKind.IdentifierName: + if (operation.Arguments[0].Value.Kind != OperationKind.ConversionExpression) break; + IOperation operand = ((IConversionExpression)operation.Arguments[0].Value).Operand; + if (operand.GetSymbol().OriginalDefinition.GetTypeSymbol().GetNavTypeKindSafe() == NavTypeKind.Label) return; + break; + case SyntaxKind.LiteralExpression: + if (operation.Arguments[0].Syntax.GetIdentifierOrLiteralValue() == "") return; + break; } + + ctx.ReportDiagnostic(Diagnostic.Create(DiagnosticDescriptors.Rule0048ErrorWithTextConstant, ctx.Operation.Syntax.GetLocation())); } } } \ No newline at end of file