private static UsingDirectiveSyntax EnsureFullyQualifiedName(UsingDirectiveSyntax usingDirective, SemanticModel semanticModel, CancellationToken cancellationToken) { NameSyntax name = usingDirective.Name; NameSyntax newName = EnsureFullyQualifiedName(); newName = newName.WithTriviaFrom(name); return(usingDirective.WithName(newName).WithFormatterAnnotation()); NameSyntax EnsureFullyQualifiedName() { ISymbol symbol = semanticModel.GetSymbol(name, cancellationToken); if (symbol != null) { if (semanticModel.GetAliasInfo(name, cancellationToken) != null || !symbol.ContainingNamespace.IsGlobalNamespace) { SymbolKind kind = symbol.Kind; if (kind == SymbolKind.Namespace) { return(SyntaxFactory.ParseName(symbol.ToString()).WithTriviaFrom(name)); } else if (kind == SymbolKind.NamedType) { return((NameSyntax)((INamedTypeSymbol)symbol).ToTypeSyntax(_symbolDisplayFormat).WithTriviaFrom(name)); } } } return(name); } }
private static SyntaxNode GetReplacementNode(SemanticModel semanticModel, UsingDirectiveSyntax node, CancellationToken cancellationToken) { SymbolInfo symbolInfo = semanticModel.GetSymbolInfo(node.Name, cancellationToken); var symbolNameSyntax = SyntaxFactory.ParseName(symbolInfo.Symbol.ToQualifiedString(node.Name)); var newName = GetReplacementName(symbolNameSyntax, node.Name); return(node.WithName((NameSyntax)newName)); }
internal static UsingDirectiveSyntax ReplaceUsing(this UsingDirectiveSyntax node, string oldUsing, string newUsing) { if (node.Name.ToString().Equals(oldUsing, StringComparison.OrdinalIgnoreCase)) { return(node.WithName(IdentifierName(newUsing))); } return(node); }
private static UsingDirectiveSyntax EnsureFullyQualifiedName(UsingDirectiveSyntax usingDirective, SemanticModel semanticModel, CancellationToken cancellationToken) { NameSyntax name = usingDirective.Name; NameSyntax newName = CSharpUtility.EnsureFullyQualifiedName(name, semanticModel, cancellationToken); newName = newName.WithTriviaFrom(name); return(usingDirective.WithName(newName).WithFormatterAnnotation()); }
public override SyntaxNode VisitUsingDirective(UsingDirectiveSyntax node) { node = (UsingDirectiveSyntax)base.VisitUsingDirective(node); if (node.Name.ToString() == OldNamespace) { var newIdentifier = SyntaxFactory.IdentifierName(NewNamespace); newIdentifier = node.Name.CopyAnnotationsTo(newIdentifier); node = node.WithName(newIdentifier); } return(node); }
public override SyntaxNode VisitUsingDirective(UsingDirectiveSyntax node) { var existing = m_semanticModel.GetSymbolInfo(node.Name); if (m_namespaceNUnit.ToFullString().Equals(existing.Symbol?.ToDisplayString())) { node = node.WithName(m_namespaceMsTest); Changed = true; } return(node); }
public override SyntaxNode VisitUsingDirective(UsingDirectiveSyntax node) { if (node.Name.ToString().Equals("NUnit.Framework")) { return(node.WithName(SyntaxFactory.IdentifierName("Xunit"))); } if (node.Name.ToString().Contains("NUnit")) { return(null); } return(base.VisitUsingDirective(node)); }
public override SyntaxNode VisitUsingDirective(UsingDirectiveSyntax node) { if (node.Name.ToString().Equals("NSubstitute")) { return(node.WithName(SyntaxFactory.IdentifierName("Moq"))); } if (node.Name.ToString().Contains("NSubstitute")) { return(null); } return(base.VisitUsingDirective(node)); }
public override SyntaxNode VisitUsingDirective(UsingDirectiveSyntax node) { var name = node.Name.ToString(); // replace using statements that we have a mapping for. NameSyntax replacementUsing; if (TryMapReplacement(name, out replacementUsing)) { var newUsing = node.WithName(replacementUsing); return(newUsing); } return(base.VisitUsingDirective(node)); }
public override SyntaxNode VisitUsingDirective(UsingDirectiveSyntax node) { var name = node.Name.WithoutTrivia().ToFullString(); if (assemblyResolver.Namespaces.ContainsKey(name)) { return(base.VisitUsingDirective(node.WithName(SyntaxFactory.ParseName(assemblyResolver.Namespaces[name]) .WithLeadingTrivia(node.Name.GetLeadingTrivia()) .WithTrailingTrivia(node.Name.GetTrailingTrivia())))); } else { return(base.VisitUsingDirective(node)); } }
private static SyntaxNode GetReplacementNode(SemanticModel semanticModel, UsingDirectiveSyntax node, CancellationToken cancellationToken) { SymbolInfo symbolInfo = semanticModel.GetSymbolInfo(node.Name, cancellationToken); return(node.WithName(SyntaxFactory.ParseName(symbolInfo.Symbol.ToString()))); }