Пример #1
0
        public static int InsertLineWithAttribute(
            SourceAnnotationFile sourceCodeFile, int insertLineNumber,
            TargetSourceLines benchmarkMethod,
            CompetitionMetricValue metricValue)
        {
            var whitespacePrefix = GetWhitespacePrefix(sourceCodeFile[insertLineNumber]);

            var newLine = GetNewAnnotationLine(whitespacePrefix, metricValue);

            var newLineNumber = insertLineNumber + 1;

            sourceCodeFile.InsertLine(newLineNumber, newLine);
            var attributeTypeHandle = metricValue.Metric.AttributeType.TypeHandle;

            benchmarkMethod.AddAttribute(attributeTypeHandle, newLineNumber);

            return(newLineNumber);
        }
Пример #2
0
        public static bool TryInsertAttributeInplace(
            SourceAnnotationFile sourceCodeFile, int inplaceLineNumber,
            TargetSourceLines benchmarkMethod,
            CompetitionMetricValue metricValue)
        {
            var line = sourceCodeFile[inplaceLineNumber];

            var inplacePosition = line.LastIndexOf(']');

            if (inplacePosition < 0)
            {
                return(false);
            }

            var appendText = GetInplaceAnnotationText(metricValue);

            line = line.Insert(inplacePosition, appendText);
            sourceCodeFile.ReplaceLine(inplaceLineNumber, line);
            var attributeTypeHandle = metricValue.Metric.AttributeType.TypeHandle;

            benchmarkMethod.AddAttribute(attributeTypeHandle, inplaceLineNumber);

            return(true);
        }