protected override IEnumerable <Diagnostic> Analyze(IMethodSymbol symbol) { var commentXml = symbol.GetComment(); foreach (var parameter in symbol.Parameters) { var comment = parameter.GetComment(commentXml); if (comment.ContainsAny(Constants.Comments.FuturePhrase)) { return(new[] { Issue(parameter) }); } } return(Enumerable.Empty <Diagnostic>()); }
public static bool IsBool(this IMethodSymbol method) { if (method.ReturnType.Name != "Int32") { return(false); } string comment = method.GetComment(); if (comment == null) { return(false); } if (comment.StartsWith("True if ")) { return(true); } if (comment.StartsWith("Return a bool")) { return(true); } return(Regex.IsMatch(comment, @"returns?\s+true", RegexOptions.IgnoreCase) || Regex.IsMatch(comment, @"returns?\s+false", RegexOptions.IgnoreCase)); }
public static bool IsBool(this IParameterSymbol parameter) { if (parameter.Type.Name != "Int32") { return(false); } string name = parameter.Name; IMethodSymbol method = (IMethodSymbol)parameter.ContainingSymbol; AttributeData nativeNameAttribute = method.GetAttributes().FirstOrDefault(attr => attr.AttributeClass.Name == "NativeNameAttribute"); string methodNativeName = nativeNameAttribute?.ConstructorArguments[0].Value as string; if (methodNativeName != null) { string methodName = (method.ContainingType.Name + "::" + methodNativeName).TrimStart('_'); foreach (BoolIntInfo boolInt in BooleanInt.Value) { if (boolInt.Method == methodName && boolInt.Arg == name) { return(true); } } } string comment = method.GetComment(); if (name.StartsWith("is") && name.Length > 2 && (name[2] == '_' || char.IsUpper(name[2]))) { return(true); } if ((name.StartsWith("can") || name.StartsWith("has")) && name.Length > 3 && (name[3] == '_' || char.IsUpper(name[3]))) { return(true); } string namePattern = "|" + name + "|"; int startPos = 0; while (true) { startPos = comment.IndexOf(namePattern, startPos + 1); if (startPos == -1) { return(false); } int endPos = comment.IndexOf('.', startPos); if (endPos == -1) { endPos = comment.Length; } foreach (string word in comment.Substring(startPos, endPos - startPos).Split(WordSplittres, 5, StringSplitOptions.RemoveEmptyEntries).Skip(1)) { if (word.StartsWith('|') && word.EndsWith('|')) { break; // found another parameter } if (word.StartsWith("true") || word.StartsWith("false")) { return(true); } } } }