/// <summary> /// Fixes the error. /// </summary> /// <param name="violationContext">Context for the violation.</param> /// <param name="token">The token that is missing a prefix.</param> private void FixPrefixLocalCallsWithThisViolation(ViolationContext violationContext, Token token) { Param.Ignore(violationContext); Param.AssertNotNull(token, "token"); CsDocument document = token.Document; // Find the item that is going to get replaced. CodeUnit itemToReplace = token; LiteralExpression parent = token.Parent as LiteralExpression; if (parent != null) { itemToReplace = parent; } // Record the location of this item. CodeUnitLocationMarker marker = document.GetCodeUnitLocationMarker(itemToReplace); // If the token is not already wrapped by a literal expression, create one. LiteralExpression rightHandSide = parent; if (rightHandSide == null) { rightHandSide = document.CreateLiteralExpression(token); } // Create the left-hand side and the expression. LiteralExpression leftHandSide = document.CreateLiteralExpression(document.CreateThisToken()); MemberAccessExpression expression = document.CreateMemberAccessExpression(leftHandSide, rightHandSide); // Insert the member access expression in the same location as the previous literal. document.Insert(expression, marker); }