private FieldVariableTransformationResult TransformFieldVariable( VariableDeclaratorSyntax variableNode, FieldVariableTransformationResult result, bool canCopy) { var variableResult = result.AnalyzationResult; var conversion = variableResult.Conversion; if (conversion == FieldVariableConversion.Ignore || !canCopy) { return(result); } var startVariableSpan = variableResult.Node.Span.Start; variableNode = variableNode.WithAdditionalAnnotations(new SyntaxAnnotation(result.Annotation)); startVariableSpan -= variableNode.SpanStart; // First we need to annotate nodes that will be modified in order to find them later on. // We cannot rely on spans after the first modification as they will change var typeReferencesAnnotations = new List <string>(); foreach (var typeReference in variableResult.TypeReferences.Where(o => o.TypeAnalyzationResult.Conversion == TypeConversion.NewType)) { var reference = typeReference.ReferenceLocation; var refSpanStart = reference.Location.SourceSpan.Start - startVariableSpan; var nameNode = variableNode.GetSimpleName(refSpanStart, reference.Location.SourceSpan.Length, typeReference.IsCref); var annotation = Guid.NewGuid().ToString(); variableNode = variableNode.ReplaceNode(nameNode, nameNode.WithAdditionalAnnotations(new SyntaxAnnotation(annotation))); typeReferencesAnnotations.Add(annotation); } // Modify references foreach (var refAnnotation in typeReferencesAnnotations) { var nameNode = variableNode.GetAnnotatedNodes(refAnnotation).OfType <SimpleNameSyntax>().First(); variableNode = variableNode .ReplaceNode(nameNode, nameNode.WithIdentifier(Identifier(nameNode.Identifier.Value + "Async").WithTriviaFrom(nameNode.Identifier))); } result.Transformed = variableNode; return(result); }