/// <summary> /// Returns criteria displayed in toolwindow's filter, used to calculate localization probability /// </summary> public static new Dictionary <string, LocalizationCommonCriterion> GetCriteria() { var localizationCriteriaList = AbstractResultItem.GetCriteria(); var wasVerbatimPredicate = new LocalizationCommonCriterion("WasVerbatim", "Is verbatim string", LocalizationCriterionAction.VALUE, -10, (item) => { return(item.WasVerbatim); }); localizationCriteriaList.Add(wasVerbatimPredicate.Name, wasVerbatimPredicate); return(localizationCriteriaList); }
/// <summary> /// Adds few lines of code as a context to the result item /// </summary> private void AddContextToItem(AbstractResultItem item) { item.ContextRelativeLine = 0; int currentPos = item.AbsoluteCharOffset; string currentLine = GetLine(ref currentPos, 0); // current line's text currentLine = currentLine.Substring(0, Math.Min(item.ReplaceSpan.iStartIndex, currentLine.Length)) + StringConstants.ContextSubstituteText; StringBuilder context = new StringBuilder(); context.Append(currentLine); int topLines = 0; int botLines = 0; while ((currentLine = GetLine(ref currentPos, -1)) != null && topLines < NumericConstants.ContextLineRadius) { string lineText = currentLine.ToString(); if (lineText.Trim().Length > 0) { context.Insert(0, lineText + Environment.NewLine); item.ContextRelativeLine++; if (lineText.Trim().Length > 1) { topLines++; } } } currentPos = item.AbsoluteCharOffset + item.AbsoluteCharLength; currentLine = GetLine(ref currentPos, 0); context.Append(currentLine.Substring(Math.Min(item.ReplaceSpan.iEndIndex, currentLine.Length - 1))); while ((currentLine = GetLine(ref currentPos, +1)) != null && botLines < NumericConstants.ContextLineRadius) { string lineText = currentLine.ToString(); if (lineText.Trim().Length > 0) { context.Append(Environment.NewLine + lineText); if (lineText.Trim().Length > 1) { botLines++; } } } item.Context = context.ToString(); }
/// <summary> /// Adds context to the result item, coming from code block starting at given position /// </summary> protected void AddContextToItem(AbstractResultItem item, EditPoint2 editPoint) { StringBuilder context = new StringBuilder(); // indices +1 !! int topLines = 0; int currentLine = item.ReplaceSpan.iStartLine; int contextRelativeLine = 0; // add NumericConstants.ContextLineRadius lines above the result item with at least 2 non-whitespace characters while (currentLine >= 1 && topLines < NumericConstants.ContextLineRadius) { editPoint.MoveToLineAndOffset(currentLine, 1); string lineText = editPoint.GetText(editPoint.LineLength); if (lineText.Trim().Length > 0) { context.Insert(0, lineText + Environment.NewLine); contextRelativeLine++; if (lineText.Trim().Length > 1) { topLines++; } } currentLine--; } editPoint.MoveToLineAndOffset(item.ReplaceSpan.iStartLine + 1, 1); context.Append(editPoint.GetText(item.ReplaceSpan.iStartIndex)); context.Append(StringConstants.ContextSubstituteText); // add text that will be displayed instead of actual result item editPoint.MoveToLineAndOffset(item.ReplaceSpan.iEndLine + 1, item.ReplaceSpan.iEndIndex + 1); context.Append(editPoint.GetText(editPoint.LineLength - item.ReplaceSpan.iEndIndex + 1)); int botLines = 0; currentLine = item.ReplaceSpan.iEndLine + 2; // add NumericConstants.ContextLineRadius lines below the result item with at least 2 non-whitespace characters while (botLines < NumericConstants.ContextLineRadius) { editPoint.MoveToLineAndOffset(currentLine, 1); string lineText = editPoint.GetText(editPoint.LineLength); if (lineText.Trim().Length > 0) { context.Append(Environment.NewLine + lineText); if (lineText.Trim().Length > 1) { botLines++; } } editPoint.EndOfLine(); if (editPoint.AtEndOfDocument) { break; } currentLine++; } item.Context = context.ToString(); item.ContextRelativeLine = contextRelativeLine; // index of "middle" line }