/// <summary>Inspects the specified function.</summary> /// <param name="function">The function.</param> /// <returns>Returns the code annotation attribute.</returns> private static CodeAnnotationAttribute Inspect([NotNull] ICSharpFunctionDeclaration function) { if (function == null) { throw new ArgumentNullException("function"); } var project = function.GetProject(); if (project == null) { return(CodeAnnotationAttribute.Undefined); } var projectFile = project.ProjectFile; if (projectFile == null) { return(CodeAnnotationAttribute.Undefined); } if (!function.DeclaredElement.ReturnType.IsReferenceType()) { return(CodeAnnotationAttribute.Undefined); } // return CodeAnnotationAttribute.NotNull; new AllNonQualifiedSignatureReferencesResolver().Process(function); var builder = new CSharpControlFlowBuilder(); var graph = builder.GraphFromNode(function, null, true) as ICSharpControlFlowGraph; if (graph == null) { return(CodeAnnotationAttribute.Undefined); } var graphInspector = CSharpControlFlowGraphInspector.Inspect(graph, ValueAnalysisMode.OPTIMISTIC); switch (graphInspector.SuggestReturnValueAnnotationAttribute) { case CSharpControlFlowNullReferenceState.NOT_NULL: return(CodeAnnotationAttribute.NotNull); case CSharpControlFlowNullReferenceState.NULL: return(CodeAnnotationAttribute.CanBeNull); case CSharpControlFlowNullReferenceState.MAY_BE_NULL: return(CodeAnnotationAttribute.CanBeNull); } return(CodeAnnotationAttribute.NotSet); }