Microsoft.CodeAnalysis.Sarif.Converters.AndroidStudioConverter.ConvertProblemToSarifResult C# (CSharp) 메소드

ConvertProblemToSarifResult() 공개 메소드

public ConvertProblemToSarifResult ( AndroidStudioProblem problem ) : System.Result
problem AndroidStudioProblem
리턴 System.Result
        public Result ConvertProblemToSarifResult(AndroidStudioProblem problem)
        {
            var result = new Result();
            result.RuleId = problem.ProblemClass;
            string description = AndroidStudioConverter.GetShortDescriptionForProblem(problem);
            if (problem.Hints.IsEmpty)
            {
                result.Message = description;
            }
            else
            {
                result.Message = GenerateFullMessage(description, problem.Hints);
            }

            SetSarifResultPropertiesForProblem(result, problem);
            var location = new Location();
            location.FullyQualifiedLogicalName = CreateSignature(problem);

            string logicalLocationKey = CreateLogicalLocation(problem);

            if (logicalLocationKey != location.FullyQualifiedLogicalName)
            {
                location.LogicalLocationKey = logicalLocationKey;
            }

            Uri uri;
            string file = problem.File;
            if (!String.IsNullOrEmpty(file))
            {
                location.ResultFile = new PhysicalLocation
                {
                    Region = problem.Line <= 0 ? null : Extensions.CreateRegion(problem.Line)
                };

                if (RemoveBadRoot(file, out uri))
                {
                    location.ResultFile.UriBaseId = PROJECT_DIR;
                }
                location.ResultFile.Uri = uri;
            }

            if ("file".Equals(problem.EntryPointType, StringComparison.OrdinalIgnoreCase))
            {
                if (location.AnalysisTarget != null)
                {
                    location.ResultFile = location.AnalysisTarget;
                }

                location.AnalysisTarget = new PhysicalLocation();

                if (RemoveBadRoot(problem.EntryPointName, out uri))
                {
                    location.AnalysisTarget.UriBaseId = PROJECT_DIR;
                }
                location.AnalysisTarget.Uri = uri;
            }

            result.Locations = new List<Location> { location };

            return result;
        }

Usage Example

        public void AndroidStudioConverter_ConvertSarifResult_GeneratesLocationWithOnlyPackage()
        {
            var builder = AndroidStudioProblemTests.GetDefaultProblemBuilder();

            builder.File           = null;
            builder.Package        = "FancyPackageName";
            builder.Module         = null;
            builder.EntryPointName = null;

            var expectedLocation = new Location
            {
                FullyQualifiedLogicalName = "FancyPackageName"
            };

            var expectedLogicalLocations = new Dictionary <string, LogicalLocation>
            {
                {
                    "FancyPackageName", new LogicalLocation {
                        ParentKey = null, Kind = LogicalLocationKind.Package
                    }
                }
            };

            var    converter = new AndroidStudioConverter();
            Result result    = converter.ConvertProblemToSarifResult(new AndroidStudioProblem(builder));

            result.Locations[0].ValueEquals(expectedLocation).Should().BeTrue();

            foreach (string key in expectedLogicalLocations.Keys)
            {
                expectedLogicalLocations[key].ValueEquals(converter.LogicalLocationsDictionary[key]).Should().BeTrue();
            }
            converter.LogicalLocationsDictionary.Count.Should().Be(expectedLogicalLocations.Count);
        }
All Usage Examples Of Microsoft.CodeAnalysis.Sarif.Converters.AndroidStudioConverter::ConvertProblemToSarifResult