private Diagnostic Analyze(MemberAccessExpressionSyntax methodCall, SemanticModel semanticModel) { var methodName = methodCall.GetName(); switch (methodName) { case Constants.ILog.DebugFormat: case Constants.ILog.InfoFormat: case Constants.ILog.WarnFormat: case Constants.ILog.ErrorFormat: case Constants.ILog.FatalFormat: { // check for correct type (only ILog methods shall be reported) var type = methodCall.GetTypeSymbol(semanticModel); if (type.Name != Constants.ILog.TypeName) { return(null); } var enclosingMethod = methodCall.GetEnclosingMethod(semanticModel); return(Issue(enclosingMethod.Name, methodCall.Name, methodName, methodName.Without(Format))); } default: return(null); } }
private Diagnostic AnalyzeFormatCall(MemberAccessExpressionSyntax methodCall, IEnumerable <ArgumentSyntax> arguments, SemanticModel semanticModel, string proposedMethodName) { // check for correct type (only ILog methods shall be reported) var type = methodCall.GetTypeSymbol(semanticModel); if (type.Name == Constants.ILog.TypeName && arguments.Any(_ => _.IsException(semanticModel))) { var enclosingMethod = methodCall.GetEnclosingMethod(semanticModel); return(Issue(enclosingMethod.Name, methodCall.Name, proposedMethodName)); } return(null); }
private Diagnostic Analyze(MemberAccessExpressionSyntax methodCall, SemanticModel semanticModel) { var methodName = methodCall.GetName(); switch (methodName) { case Constants.ILog.Debug: case Constants.ILog.DebugFormat: { // check if inside IsDebugEnabled call for if or block if (methodCall.IsInsideIfStatementWithCallTo(Constants.ILog.IsDebugEnabled)) { return(null); } // check for correct type (only ILog methods shall be reported) var type = methodCall.GetTypeSymbol(semanticModel); if (type.Name != Constants.ILog.TypeName) { // skip it as it's no matching type return(null); } if (type.GetMembers(Constants.ILog.IsDebugEnabled).None()) { // skip it as it has no matching method return(null); } var enclosingMethod = methodCall.GetEnclosingMethod(semanticModel); return(Issue(enclosingMethod.Name, methodCall.Parent, methodName, Constants.ILog.IsDebugEnabled)); } default: { return(null); } } }
private bool IsCall(MemberAccessExpressionSyntax call, SemanticModel semanticModel) { var type = call.GetTypeSymbol(semanticModel); return(type != null && IsCall(type)); }