예제 #1
0
 public override void VisitUsingDirective(UsingDirectiveSyntax node)
 {
     //if (node.Name.ToString() != "System" && !node.Name.ToString().StartsWith("System."))
     //{
         this.Usings.Add(node);
     //}
 }
 protected override void VisitUsingDirective(UsingDirectiveSyntax node)
 {
     if (node.Name.GetText() != "System" &&
         !node.Name.GetText().StartsWith("System."))
     {
         Usings.Add(node);
     }
 }
 public override void VisitUsingDirective(UsingDirectiveSyntax node)
 {
     if (node.IsInSystemWindows() && !uiClass)
     {
         uiClass = true;
         Result.generalAsyncResults.NumUIClasses++;
     }
     base.VisitUsingDirective(node);
 }
		public static CompilationUnitSyntax AddUsingDirective(
			this CompilationUnitSyntax root,
			UsingDirectiveSyntax usingDirective,
			SyntaxNode contextNode,
			bool placeSystemNamespaceFirst,
			params SyntaxAnnotation[] annotations)
		{
			return root.AddUsingDirectives(new[] { usingDirective }, contextNode, placeSystemNamespaceFirst, annotations);
		}
예제 #5
0
        // Hay un visit por cada tipo de nodo. Es bastante útil.
        public override void VisitUsingDirective(UsingDirectiveSyntax node)
        {
            // Propiedad últil de los nodos: CSharpKind (en este caso sería siempre UsingDirective)

            /*Note the Name property of type NameSyntax; this stores the name of the namespace being imported.*/
            if (node.Name.ToString() != "System" &&
                !node.Name.ToString().StartsWith("System."))
            {
                this.Usings.Add(node);
            }
        }
        private static SyntaxToken? GetFirstIdentifierInUsingDirective(UsingDirectiveSyntax usingDirective)
        {
            foreach (var identifier in usingDirective.DescendantNodes())
            {
                IdentifierNameSyntax identifierName = identifier as IdentifierNameSyntax;

                if (identifierName != null && ExcludeGlobalKeyword(identifierName))
                {
                    return identifierName.Identifier;
                }
            }

            return null;
        }
            public override SyntaxNode VisitUsingDirective(UsingDirectiveSyntax node)
            {
                if (node == null) { throw new ArgumentNullException(nameof(node)); }

                if (node.UsingKeyword.TrailingTrivia.FullSpan.IsEmpty)
                {
                    node = node.WithUsingKeyword(node.UsingKeyword.WithTrailingTrivia(SyntaxFactory.Space));
                }

                if (node.SemicolonToken.TrailingTrivia.FullSpan.IsEmpty)
                {
                    node = node.WithSemicolonToken(node.SemicolonToken.WithTrailingTrivia(this.newLineTrivia));
                }

                return node;
            }
예제 #8
0
 //Note:It must exist, to shortcut visit the using [XXX], otherwise it will visit XXX
 public override SyntaxNode VisitUsingDirective(UsingDirectiveSyntax node)
 {
     if (node.Alias != null)
     {
         this.AppendCompileIssue(node, IssueType.Error, IssueId.UsingAliasNotSupport);
     }
     else
     {
         if (_template.SupportUsing)
         {
             var template = _template.CreateUsingTemplate();
             _output.Write(node, template.GetBeginString());
             this.Visit(node.Name);
             _output.TrivialWriteLine(template.GetEndString());
         }
     }
     return node;
 }
예제 #9
0
    public override void VisitUsingDirective(UsingDirectiveSyntax node)
    {

      // these could theoretically be acquired by indexing the GAC or something
      var namespaces = new List<String>
      {
        "System",
        "System.Collections",
        "System.Collections.Generic",
        "System.Text",
        "System.Linq"
      };
      string whatAreWeUsing = node.Name.ToString();
      if (!namespaces.Contains(whatAreWeUsing))
      {
        var parts = whatAreWeUsing.Split('.');
        cb.AppendIndent().Append("using namespace ").Append(string.Join("::", parts)).AppendLine(";");
      }
    }
        private static UsingDirectiveSyntax RemoveLeadingAndTrailingCompilerDirectives(UsingDirectiveSyntax usingSyntax)
        {
            UsingDirectiveSyntax usingDirectiveToUse = usingSyntax;
            if (usingDirectiveToUse.HasLeadingTrivia)
            {
                if (usingDirectiveToUse.HasLeadingTrivia)
                {
                    var newLeadingTrivia = RemoveCompilerDirectives(usingDirectiveToUse.GetLeadingTrivia());
                    usingDirectiveToUse = usingDirectiveToUse.WithLeadingTrivia(newLeadingTrivia);
                }
                if (usingDirectiveToUse.HasTrailingTrivia)
                {
                    var newTrailingTrivia = RemoveCompilerDirectives(usingDirectiveToUse.GetTrailingTrivia());
                    usingDirectiveToUse = usingDirectiveToUse.WithTrailingTrivia(newTrailingTrivia);
                }
            }

            return usingDirectiveToUse;
        }
        private IEnumerable<ClassifiedSpan> ClassifyUsingDirectiveSyntax(
            UsingDirectiveSyntax usingDirective,
            SemanticModel semanticModel,
            CancellationToken cancellationToken)
        {
            // For using aliases, we bind the target on the right of the equals and use that
            // binding to classify the alias.
            if (usingDirective.Alias != null)
            {
                var info = semanticModel.GetTypeInfo(usingDirective.Name, cancellationToken);
                if (info.Type != null)
                {
                    var classification = GetClassificationForType(info.Type);
                    if (classification != null)
                    {
                        var token = usingDirective.Alias.Name;
                        return SpecializedCollections.SingletonEnumerable(new ClassifiedSpan(token.Span, classification));
                    }
                }
            }

            return null;
        }
예제 #12
0
 private static string GetAliasName(UsingDirectiveSyntax usingDirective)
 {
     return (usingDirective.Alias == null || usingDirective.Alias.Name == null) ? null : usingDirective.Alias.Name.ToString();
 }
예제 #13
0
 private static bool UsingsMatch(UsingDirectiveSyntax usingDirective1, UsingDirectiveSyntax usingDirective2)
 {
     return usingDirective1.Name.ToString() == usingDirective2.Name.ToString() && GetAliasName(usingDirective1) == GetAliasName(usingDirective2);
 }
예제 #14
0
 static bool IsBindingFlags(UsingDirectiveSyntax @using)
 {
     return(@using.StaticKeyword.IsKind(SyntaxKind.StaticKeyword) &&
            @using.Name is QualifiedNameSyntax qn &&
            qn.Right.Identifier.ValueText == "BindingFlags");
 }
예제 #15
0
 private static async Task <Document> ReplaceOrInsertNewUsingDirectivePreview(Document document, UsingDirectiveSyntax oldDirective, CancellationToken cancellationToken)
 {
     return(await ReplaceOrInsertNewUsingDirective(document, oldDirective, false, cancellationToken).ConfigureAwait(false));
 }
            private int CompareUsings(UsingDirectiveSyntax left, UsingDirectiveSyntax right)
            {
                if ((left.Alias != null) && (right.Alias != null))
                {
                    return CultureInfo.InvariantCulture.CompareInfo.Compare(left.Alias.Name.Identifier.ValueText, right.Alias.Name.Identifier.ValueText, CompareOptions.IgnoreCase | CompareOptions.IgnoreNonSpace | CompareOptions.IgnoreWidth);
                }

                bool leftIsSystem = this.IsSeparatedSystemUsing(left);
                bool rightIsSystem = this.IsSeparatedSystemUsing(right);
                if (leftIsSystem != rightIsSystem)
                {
                    return leftIsSystem ? -1 : 1;
                }

                return CultureInfo.InvariantCulture.CompareInfo.Compare(left.Name.ToNormalizedString(), right.Name.ToNormalizedString(), CompareOptions.IgnoreCase | CompareOptions.IgnoreNonSpace | CompareOptions.IgnoreWidth);
            }
 private static bool HasNamespaceAliasQualifier(UsingDirectiveSyntax usingDirective) => usingDirective.DescendantNodes().Any(node => node.IsKind(SyntaxKind.AliasQualifiedName));
 public override void VisitUsingDirective(UsingDirectiveSyntax node)
 {
     PrintLn("open {0}", node.Name);
 }
예제 #19
0
        private void Validate()
        {
            if (this == Empty)
            {
                return;
            }

            DiagnosticBag semanticDiagnostics = _compilation.DeclarationDiagnostics;

            // Check constraints within named aliases.
            var diagnostics = BindingDiagnosticBag.GetInstance();

            // Force resolution of named aliases.
            foreach (var(_, alias) in UsingAliases)
            {
                NamespaceOrTypeSymbol target = alias.Alias.GetAliasTarget(basesBeingResolved: null);

                diagnostics.Clear();
                diagnostics.AddRange(alias.Alias.AliasTargetDiagnostics);

                alias.Alias.CheckConstraints(diagnostics);

                semanticDiagnostics.AddRange(diagnostics.DiagnosticBag);
                recordImportDependencies(alias.UsingDirective, target);
            }

            var corLibrary  = _compilation.SourceAssembly.CorLibrary;
            var conversions = new TypeConversions(corLibrary);

            foreach (var @using in Usings)
            {
                diagnostics.Clear();
                diagnostics.AddDependencies(@using.Dependencies);

                NamespaceOrTypeSymbol target = @using.NamespaceOrType;

                // Check if `using static` directives meet constraints.
                UsingDirectiveSyntax usingDirective = @using.UsingDirective;
                if (target.IsType)
                {
                    var typeSymbol = (TypeSymbol)target;
                    var location   = usingDirective?.Name.Location ?? NoLocation.Singleton;
                    typeSymbol.CheckAllConstraints(_compilation, conversions, location, diagnostics);
                }

                semanticDiagnostics.AddRange(diagnostics.DiagnosticBag);
                recordImportDependencies(usingDirective, target);
            }

            // Force resolution of extern aliases.
            foreach (var alias in ExternAliases)
            {
                var target = (NamespaceSymbol)alias.Alias.GetAliasTarget(null);
                Debug.Assert(target.IsGlobalNamespace);

                semanticDiagnostics.AddRange(alias.Alias.AliasTargetDiagnostics.DiagnosticBag);

                if (!Compilation.ReportUnusedImportsInTree(alias.ExternAliasDirective.SyntaxTree))
                {
                    diagnostics.Clear();
                    diagnostics.AddAssembliesUsedByNamespaceReference(target);
                    _compilation.AddUsedAssemblies(diagnostics.DependenciesBag);
                }
            }

            if (_diagnostics != null && !_diagnostics.IsEmptyWithoutResolution)
            {
                semanticDiagnostics.AddRange(_diagnostics.AsEnumerable());
            }

            diagnostics.Free();

            void recordImportDependencies(UsingDirectiveSyntax usingDirective, NamespaceOrTypeSymbol target)
            {
                if (usingDirective is object && Compilation.ReportUnusedImportsInTree(usingDirective.SyntaxTree))
                {
                    _compilation.RecordImportDependencies(usingDirective, diagnostics.DependenciesBag.ToImmutableArray());
                }
                else
                {
                    if (target.IsNamespace)
                    {
                        diagnostics.AddAssembliesUsedByNamespaceReference((NamespaceSymbol)target);
                    }

                    _compilation.AddUsedAssemblies(diagnostics.DependenciesBag);
                }
            }
        }
예제 #20
0
        private static string GetAliasName(UsingDirectiveSyntax usingDirective)
#pragma warning restore IDE0051 // Remove unused private members
        {
            return((usingDirective.Alias == null || usingDirective.Alias.Name == null) ? null : usingDirective.Alias.Name.ToString());
        }
예제 #21
0
        private static void AnalyzeUsings(SyntaxNodeAnalysisContext context, SyntaxList <UsingDirectiveSyntax> usings)
        {
            int count = usings.Count;

            if (count <= 1)
            {
                return;
            }

            UsingDirectiveSyntax usingDirective1 = usings[0];

            for (int i = 1; i < count; i++, usingDirective1 = usings[i - 1])
            {
                if (usingDirective1.StaticKeyword.IsKind(SyntaxKind.StaticKeyword))
                {
                    return;
                }

                if (usingDirective1.Alias != null)
                {
                    return;
                }

                UsingDirectiveSyntax usingDirective2 = usings[i];

                if (usingDirective2.StaticKeyword.IsKind(SyntaxKind.StaticKeyword))
                {
                    return;
                }

                if (usingDirective2.Alias != null)
                {
                    return;
                }

                SyntaxTriviaList trailingTrivia = usingDirective1.GetTrailingTrivia();

                if (!SyntaxTriviaAnalysis.IsOptionalWhitespaceThenOptionalSingleLineCommentThenEndOfLineTrivia(trailingTrivia))
                {
                    continue;
                }

                IdentifierNameSyntax rootNamespace1 = usingDirective1.GetRootNamespace();

                if (rootNamespace1 == null)
                {
                    continue;
                }

                IdentifierNameSyntax rootNamespace2 = usingDirective2.GetRootNamespace();

                if (rootNamespace2 == null)
                {
                    continue;
                }

                SyntaxTriviaList leadingTrivia = usingDirective2.GetLeadingTrivia();

                bool isEmptyLine = SyntaxTriviaAnalysis.StartsWithOptionalWhitespaceThenEndOfLineTrivia(leadingTrivia);

                if (string.Equals(rootNamespace1.Identifier.ValueText, rootNamespace2.Identifier.ValueText, StringComparison.Ordinal))
                {
                    if (isEmptyLine)
                    {
                        ReportDiagnostic(
                            context,
                            DiagnosticDescriptors.RemoveEmptyLineBetweenUsingDirectivesWithSameRootNamespace,
                            leadingTrivia[0]);
                    }
                }
                else if (isEmptyLine)
                {
                    ReportDiagnostic(
                        context,
                        DiagnosticDescriptors.RemoveEmptyLineBetweenUsingDirectivesWithDifferentRootNamespace,
                        leadingTrivia[0]);
                }
                else
                {
                    ReportDiagnostic(
                        context,
                        DiagnosticDescriptors.AddEmptyLineBetweenUsingDirectivesWithDifferentRootNamespace,
                        trailingTrivia.Last());
                }
            }
        }
예제 #22
0
 public override void VisitUsingDirective(UsingDirectiveSyntax Node)
 {
     base.VisitUsingDirective(Node);
     Usings.Add(Node.Name.ToString());
 }
예제 #23
0
 public void AddUsing(UsingDirectiveSyntax directive)
 {
     set.Add(directive.NormalizeWhitespace());
 }
예제 #24
0
        private static async Task <Document> ReplaceOrInsertNewUsingDirective(Document document, UsingDirectiveSyntax oldDirective, bool shouldUseQualifiedName, CancellationToken cancellationToken)
        {
            var @namespace = oldDirective.Name;
            var syntaxRoot = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);

            if (syntaxRoot is not CompilationUnitSyntax compilation)
            {
                return(document);
            }

            var isRequireNewUsingDirective = compilation.Usings.None(w => w.Alias.IsKind(SyntaxKind.None) && w.Name.IsEquivalentTo(@namespace, true));

            if (isRequireNewUsingDirective && !shouldUseQualifiedName)
            {
                UsingDirectiveSyntax ReplaceStaticDirective(UsingDirectiveSyntax directive)
                {
                    if (directive.IsEquivalentTo(oldDirective))
                    {
                        return(directive.WithAlias(null));
                    }
                    return(directive);
                }

                var usings = compilation.Usings.Select(ReplaceStaticDirective).ToList();
                return(await document.ReplaceNodeAsync(compilation, compilation.WithUsings(SyntaxFactory.List(usings)), cancellationToken).ConfigureAwait(false));
            }
            else
            {
                var usings = compilation.Usings.Where(w => !w.IsEquivalentTo(oldDirective)).ToList();
                return(await document.ReplaceNodeAsync(compilation, compilation.WithUsings(SyntaxFactory.List(usings)), cancellationToken).ConfigureAwait(false));
            }
        }
            private VirtualTreePoint GetStartPoint(SourceText text, UsingDirectiveSyntax node, EnvDTE.vsCMPart part)
            {
                int startPosition;

                switch (part)
                {
                    case EnvDTE.vsCMPart.vsCMPartName:
                    case EnvDTE.vsCMPart.vsCMPartAttributes:
                    case EnvDTE.vsCMPart.vsCMPartHeader:
                    case EnvDTE.vsCMPart.vsCMPartWhole:
                    case EnvDTE.vsCMPart.vsCMPartBodyWithDelimiter:
                    case EnvDTE.vsCMPart.vsCMPartHeaderWithAttributes:
                        throw Exceptions.ThrowENotImpl();

                    case EnvDTE.vsCMPart.vsCMPartAttributesWithDelimiter:
                    case EnvDTE.vsCMPart.vsCMPartBody:
                        throw Exceptions.ThrowEFail();

                    case EnvDTE.vsCMPart.vsCMPartWholeWithAttributes:
                        startPosition = node.SpanStart;
                        break;

                    case EnvDTE.vsCMPart.vsCMPartNavigate:
                        startPosition = node.Name.SpanStart;
                        break;

                    default:
                        throw Exceptions.ThrowEInvalidArg();
                }

                return new VirtualTreePoint(node.SyntaxTree, text, startPosition);
            }
        public override SyntaxNode VisitUsingDirective(UsingDirectiveSyntax node)
        {
            node = node.ReplaceUsing(oldUsing: Transformer.MSTEST_USING, newUsing: Transformer.XUNIT_USING);

            return(base.VisitUsingDirective(node));
        }
 private static int CompareSpanStart(UsingDirectiveSyntax left, UsingDirectiveSyntax right)
 {
     return left.SpanStart - right.SpanStart;
 }
예제 #28
0
 /// <summary>
 /// Check if <see cref="UsingDirectiveSyntax"/> is system using directive.
 /// </summary>
 /// <param name="usingDirective">The <see cref="UsingDirectiveSyntax"/> that will be checked.</param>
 /// <returns>Return true if the <see cref="UsingDirectiveSyntax"/>is system using directive, otherwise false.</returns>
 internal static bool IsSystemUsingDirective(this UsingDirectiveSyntax usingDirective) => string.Equals(SystemUsingDirectiveIdentifier, GetFirstIdentifierInUsingDirective(usingDirective)?.ValueText, StringComparison.Ordinal);
            private void AddUsingDirective(Dictionary<DirectiveSpan, List<UsingDirectiveSyntax>> container, UsingDirectiveSyntax usingDirective, DirectiveSpan owningSpan)
            {
                List<UsingDirectiveSyntax> usingList;

                if (!container.TryGetValue(owningSpan, out usingList))
                {
                    usingList = new List<UsingDirectiveSyntax>();
                    container.Add(owningSpan, usingList);
                }

                usingList.Add(usingDirective);
            }
예제 #30
0
 /// <summary>
 /// Check if the name of using directive contains a namespace alias qualifier.
 /// </summary>
 /// <param name="usingDirective">The <see cref="UsingDirectiveSyntax"/> that will be checked.</param>
 /// <returns>
 /// <see langword="true"/> if the <see cref="UsingDirectiveSyntax"/> contains a namespace alias qualifier;
 /// otherwise, <see langword="false"/>.
 /// </returns>
 internal static bool HasNamespaceAliasQualifier(this UsingDirectiveSyntax usingDirective) => usingDirective.DescendantNodes().Any(node => node.IsKind(SyntaxKind.AliasQualifiedName));
예제 #31
0
        private static async Task <bool> ShouldUseQualifiedNameInChanges(Document document, UsingDirectiveSyntax oldDirective, IEnumerable <SyntaxNode> references, CancellationToken cancellationToken)
        {
            // apply the changes once and get if there are any compilation errors.
            var indeterminateDocument = await ReplaceOrInsertNewUsingDirectivePreview(document, oldDirective, cancellationToken).ConfigureAwait(false);

            var determinateDocument = await ResolveMissingReferencesPreview(indeterminateDocument, oldDirective, references, cancellationToken).ConfigureAwait(false);

            var semanticModel = await determinateDocument.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false);

            var diagnostics = semanticModel.GetDiagnostics(null, cancellationToken);

            return(diagnostics.Any(w => w.Severity == DiagnosticSeverity.Error && w.Id == "CS0104" && w.Descriptor.Category == "Compiler"));
        }
예제 #32
0
        /// <summary>
        /// Checks if the Name part of the given using directive starts with an alias.
        /// </summary>
        /// <param name="usingDirective">The <see cref="UsingDirectiveSyntax"/> that will be used.</param>
        /// <param name="semanticModel">The <see cref="SemanticModel"/> that will be used.</param>
        /// <param name="cancellationToken">The cancellation token that can be used to interrupt the operation.</param>
        /// <returns>True if the name part of the using directive starts with an alias.</returns>
        internal static bool StartsWithAlias(this UsingDirectiveSyntax usingDirective, SemanticModel semanticModel, CancellationToken cancellationToken)
        {
            var firstPart = usingDirective.Name.DescendantNodes().FirstOrDefault() ?? usingDirective.Name;

            return(semanticModel.GetAliasInfo(firstPart, cancellationToken) != null);
        }
예제 #33
0
 public CsImportedNamespace(INamespaceSymbol namespaceSymbol, UsingDirectiveSyntax syntaxNode)
     : base(namespaceSymbol)
 {
     _syntaxNode = syntaxNode;
 }
예제 #34
0
    public override void Visit(SyntaxNode node)
    {
        Tabs++;

        // Tabs are too much.
        // var indents = new String('\t', Tabs);
        var indents = new String(' ', Tabs * 5);

        Console.WriteLine(indents + node.Kind());

        // Console.WriteLine(indents + "Add: " + node.GetDebuggerDisplay());
        Console.WriteLine(indents + "Enum value: " + node.RawKind);
        // Console.WriteLine(indents + "Add: " + node.ToString());

        // Check for the syntax kind (only on what would be more abstract syntax tree nodes).
        switch (node.Kind())
        {
        // names & type-names
        case SyntaxKind.IdentifierName:        // = 8616,
            break;

        case SyntaxKind.QualifiedName:        // = 8617,
            Console.WriteLine("Sorry, not implemented! node.Kind = " + node.Kind());

            QualifiedNameSyntax qualifiedNameNode = node as QualifiedNameSyntax;

            Console.WriteLine("   --- qualifiedNameNode.Kind      = " + qualifiedNameNode.Kind());
            // Console.WriteLine("   --- qualifiedNameNode.Qualifier = " + qualifiedNameNode.Qualifier());
            // Console.WriteLine("   --- qualifiedNameNode.Name      = " + qualifiedNameNode.Name());
            // Console.WriteLine("   --- qualifiedNameNode.Qualifier = " + qualifiedNameNode.Identifier);
            // Console.WriteLine("   --- qualifiedNameNode.Name      = " + qualifiedNameNode.Name());
            // Console.WriteLine("   --- qualifiedNameNode.Name      = " + qualifiedNameNode.GetUnqualifiedName);
            Console.WriteLine("   --- qualifiedNameNode.Left  = " + qualifiedNameNode.Left);
            Console.WriteLine("   --- qualifiedNameNode.Right = " + qualifiedNameNode.Right);

            break;

        case SyntaxKind.GenericName:         // = 8618,
        case SyntaxKind.TypeArgumentList:    // = 8619,
        case SyntaxKind.AliasQualifiedName:  // = 8620,
        case SyntaxKind.PredefinedType:      // = 8621,
        case SyntaxKind.ArrayType:           // = 8622,
        case SyntaxKind.ArrayRankSpecifier:  // = 8623,
        case SyntaxKind.PointerType:         // = 8624,
        case SyntaxKind.NullableType:        // = 8625,
        case SyntaxKind.OmittedTypeArgument: // = 8626,
            break;

        // expressions
        case SyntaxKind.ParenthesizedExpression:             // = 8632,
        case SyntaxKind.ConditionalExpression:               // = 8633,
        case SyntaxKind.InvocationExpression:                // = 8634,
        case SyntaxKind.ElementAccessExpression:             // = 8635,
        case SyntaxKind.ArgumentList:                        // = 8636,
        case SyntaxKind.BracketedArgumentList:               // = 8637,
        case SyntaxKind.Argument:                            // = 8638,
        case SyntaxKind.NameColon:                           // = 8639,
        case SyntaxKind.CastExpression:                      // = 8640,
        case SyntaxKind.AnonymousMethodExpression:           // = 8641,
        case SyntaxKind.SimpleLambdaExpression:              // = 8642,
        case SyntaxKind.ParenthesizedLambdaExpression:       // = 8643,
        case SyntaxKind.ObjectInitializerExpression:         // = 8644,
        case SyntaxKind.CollectionInitializerExpression:     // = 8645,
        case SyntaxKind.ArrayInitializerExpression:          // = 8646,
        case SyntaxKind.AnonymousObjectMemberDeclarator:     // = 8647,
        case SyntaxKind.ComplexElementInitializerExpression: // = 8648,
        case SyntaxKind.ObjectCreationExpression:            // = 8649,
        case SyntaxKind.AnonymousObjectCreationExpression:   // = 8650,
        case SyntaxKind.ArrayCreationExpression:             // = 8651,
        case SyntaxKind.ImplicitArrayCreationExpression:     // = 8652,
        case SyntaxKind.StackAllocArrayCreationExpression:   // = 8653,
        case SyntaxKind.OmittedArraySizeExpression:          // = 8654,
        case SyntaxKind.InterpolatedStringExpression:        // = 8655,
        case SyntaxKind.ImplicitElementAccess:               // = 8656,
        case SyntaxKind.IsPatternExpression:                 // = 8657,
            break;

        // binary expressions
        case SyntaxKind.AddExpression:                 // = 8668,
        case SyntaxKind.SubtractExpression:            // = 8669,
        case SyntaxKind.MultiplyExpression:            // = 8670,
        case SyntaxKind.DivideExpression:              // = 8671,
        case SyntaxKind.ModuloExpression:              // = 8672,
        case SyntaxKind.LeftShiftExpression:           // = 8673,
        case SyntaxKind.RightShiftExpression:          // = 8674,
        case SyntaxKind.LogicalOrExpression:           // = 8675,
        case SyntaxKind.LogicalAndExpression:          // = 8676,
        case SyntaxKind.BitwiseOrExpression:           // = 8677,
        case SyntaxKind.BitwiseAndExpression:          // = 8678,
        case SyntaxKind.ExclusiveOrExpression:         // = 8679,
        case SyntaxKind.EqualsExpression:              // = 8680,
        case SyntaxKind.NotEqualsExpression:           // = 8681,
        case SyntaxKind.LessThanExpression:            // = 8682,
        case SyntaxKind.LessThanOrEqualExpression:     // = 8683,
        case SyntaxKind.GreaterThanExpression:         // = 8684,
        case SyntaxKind.GreaterThanOrEqualExpression:  // = 8685,
        case SyntaxKind.IsExpression:                  // = 8686,
        case SyntaxKind.AsExpression:                  // = 8687,
        case SyntaxKind.CoalesceExpression:            // = 8688,
        case SyntaxKind.SimpleMemberAccessExpression:  // = 8689,  // dot access:   a.b
        case SyntaxKind.PointerMemberAccessExpression: // = 8690,  // arrow access:   a->b
        case SyntaxKind.ConditionalAccessExpression:   // = 8691,    // question mark access:   a?.b , a?[1]
            break;

        // binding expressions
        case SyntaxKind.MemberBindingExpression:        // = 8707,
        case SyntaxKind.ElementBindingExpression:       // = 8708,
            break;

        // binary assignment expressions
        case SyntaxKind.SimpleAssignmentExpression:      // = 8714,
        case SyntaxKind.AddAssignmentExpression:         // = 8715,
        case SyntaxKind.SubtractAssignmentExpression:    // = 8716,
        case SyntaxKind.MultiplyAssignmentExpression:    // = 8717,
        case SyntaxKind.DivideAssignmentExpression:      // = 8718,
        case SyntaxKind.ModuloAssignmentExpression:      // = 8719,
        case SyntaxKind.AndAssignmentExpression:         // = 8720,
        case SyntaxKind.ExclusiveOrAssignmentExpression: // = 8721,
        case SyntaxKind.OrAssignmentExpression:          // = 8722,
        case SyntaxKind.LeftShiftAssignmentExpression:   // = 8723,
        case SyntaxKind.RightShiftAssignmentExpression:  // = 8724,
            break;

        // unary expressions
        case SyntaxKind.UnaryPlusExpression:          // = 8730,
        case SyntaxKind.UnaryMinusExpression:         // = 8731,
        case SyntaxKind.BitwiseNotExpression:         // = 8732,
        case SyntaxKind.LogicalNotExpression:         // = 8733,
        case SyntaxKind.PreIncrementExpression:       // = 8734,
        case SyntaxKind.PreDecrementExpression:       // = 8735,
        case SyntaxKind.PointerIndirectionExpression: // = 8736,
        case SyntaxKind.AddressOfExpression:          // = 8737,
        case SyntaxKind.PostIncrementExpression:      // = 8738,
        case SyntaxKind.PostDecrementExpression:      // = 8739,
        case SyntaxKind.AwaitExpression:              // = 8740,
            break;

        // primary expression
        case SyntaxKind.ThisExpression:             // = 8746,
        case SyntaxKind.BaseExpression:             // = 8747,
        case SyntaxKind.ArgListExpression:          // = 8748,
        case SyntaxKind.NumericLiteralExpression:   // = 8749,
        case SyntaxKind.StringLiteralExpression:    // = 8750,
        case SyntaxKind.CharacterLiteralExpression: // = 8751,
        case SyntaxKind.TrueLiteralExpression:      // = 8752,
        case SyntaxKind.FalseLiteralExpression:     // = 8753,
        case SyntaxKind.NullLiteralExpression:      // = 8754,
        case SyntaxKind.DefaultLiteralExpression:   // = 8755,
            break;

        // primary function expressions
        case SyntaxKind.TypeOfExpression:        // = 8760,
        case SyntaxKind.SizeOfExpression:        // = 8761,
        case SyntaxKind.CheckedExpression:       // = 8762,
        case SyntaxKind.UncheckedExpression:     // = 8763,
        case SyntaxKind.DefaultExpression:       // = 8764,
        case SyntaxKind.MakeRefExpression:       // = 8765,
        case SyntaxKind.RefValueExpression:      // = 8766,
        case SyntaxKind.RefTypeExpression:       // = 8767,
            break;

        // NameOfExpression: // = 8768, // we represent nameof(x) as an invocation expression

        // query expressions
        case SyntaxKind.QueryExpression:    // = 8774,
        case SyntaxKind.QueryBody:          // = 8775,
        case SyntaxKind.FromClause:         // = 8776,
        case SyntaxKind.LetClause:          // = 8777,
        case SyntaxKind.JoinClause:         // = 8778,
        case SyntaxKind.JoinIntoClause:     // = 8779,
        case SyntaxKind.WhereClause:        // = 8780,
        case SyntaxKind.OrderByClause:      // = 8781,
        case SyntaxKind.AscendingOrdering:  // = 8782,
        case SyntaxKind.DescendingOrdering: // = 8783,
        case SyntaxKind.SelectClause:       // = 8784,
        case SyntaxKind.GroupClause:        // = 8785,
        case SyntaxKind.QueryContinuation:  // = 8786,
            break;

        // statements
        case SyntaxKind.Block:                     // = 8792,
        case SyntaxKind.LocalDeclarationStatement: // = 8793,
        case SyntaxKind.VariableDeclaration:       // = 8794,
        case SyntaxKind.VariableDeclarator:        // = 8795,
        case SyntaxKind.EqualsValueClause:         // = 8796,
        case SyntaxKind.ExpressionStatement:       // = 8797,
        case SyntaxKind.EmptyStatement:            // = 8798,
        case SyntaxKind.LabeledStatement:          // = 8799,
            break;

        // jump statements
        case SyntaxKind.GotoStatement:        // = 8800,
        case SyntaxKind.GotoCaseStatement:    // = 8801,
        case SyntaxKind.GotoDefaultStatement: // = 8802,
        case SyntaxKind.BreakStatement:       // = 8803,
        case SyntaxKind.ContinueStatement:    // = 8804,
        case SyntaxKind.ReturnStatement:      // = 8805,
        case SyntaxKind.YieldReturnStatement: // = 8806,
        case SyntaxKind.YieldBreakStatement:  // = 8807,
        case SyntaxKind.ThrowStatement:       // = 8808,
            break;

        case SyntaxKind.WhileStatement:     // = 8809,
        case SyntaxKind.DoStatement:        // = 8810,
        case SyntaxKind.ForStatement:       // = 8811,
        case SyntaxKind.ForEachStatement:   // = 8812,
            break;

        case SyntaxKind.UsingStatement:        // = 8813,
            Console.WriteLine("Sorry, not implemented! node.Kind = " + node.Kind());
            break;

        case SyntaxKind.FixedStatement:        // = 8814,
            break;

        // checked statements
        case SyntaxKind.CheckedStatement:        // = 8815,
        case SyntaxKind.UncheckedStatement:      // = 8816,
            break;

        case SyntaxKind.UnsafeStatement:    // = 8817,
        case SyntaxKind.LockStatement:      // = 8818,
        case SyntaxKind.IfStatement:        // = 8819,
        case SyntaxKind.ElseClause:         // = 8820,
        case SyntaxKind.SwitchStatement:    // = 8821,
        case SyntaxKind.SwitchSection:      // = 8822,
        case SyntaxKind.CaseSwitchLabel:    // = 8823,
        case SyntaxKind.DefaultSwitchLabel: // = 8824,
        case SyntaxKind.TryStatement:       // = 8825,
        case SyntaxKind.CatchClause:        // = 8826,
        case SyntaxKind.CatchDeclaration:   // = 8827,
        case SyntaxKind.CatchFilterClause:  // = 8828,
        case SyntaxKind.FinallyClause:      // = 8829,
            break;

        // statements that didn't fit above
        case SyntaxKind.LocalFunctionStatement:        // = 8830,
            break;

        // declarations
        case SyntaxKind.CompilationUnit:        // = 8840,
        case SyntaxKind.GlobalStatement:        // = 8841,
        case SyntaxKind.NamespaceDeclaration:   // = 8842,
            break;

        case SyntaxKind.UsingDirective:        // = 8843,
            Console.WriteLine("Sorry, not implemented! node.Kind = " + node.Kind());

            UsingDirectiveSyntax usingDirectiveNode = node as UsingDirectiveSyntax;

            Console.WriteLine("   --- usingDirectiveNode.Kind = " + usingDirectiveNode.Kind());
            Console.WriteLine("   --- usingDirectiveNode.Name = " + usingDirectiveNode.Name);

            break;

        case SyntaxKind.ExternAliasDirective:        // = 8844,
            break;

        // attributes
        case SyntaxKind.AttributeList:            // = 8847,
        case SyntaxKind.AttributeTargetSpecifier: // = 8848,
        case SyntaxKind.Attribute:                // = 8849,
        case SyntaxKind.AttributeArgumentList:    // = 8850,
        case SyntaxKind.AttributeArgument:        // = 8851,
        case SyntaxKind.NameEquals:               // = 8852,
            break;

        // type declarations
        case SyntaxKind.ClassDeclaration:       // = 8855,
        case SyntaxKind.StructDeclaration:      // = 8856,
        case SyntaxKind.InterfaceDeclaration:   // = 8857,
        case SyntaxKind.EnumDeclaration:        // = 8858,
        case SyntaxKind.DelegateDeclaration:    // = 8859,
            break;

        case SyntaxKind.BaseList:                      // = 8864,
        case SyntaxKind.SimpleBaseType:                // = 8865,
        case SyntaxKind.TypeParameterConstraintClause: // = 8866,
        case SyntaxKind.ConstructorConstraint:         // = 8867,
        case SyntaxKind.ClassConstraint:               // = 8868,
        case SyntaxKind.StructConstraint:              // = 8869,
        case SyntaxKind.TypeConstraint:                // = 8870,
        case SyntaxKind.ExplicitInterfaceSpecifier:    // = 8871,
        case SyntaxKind.EnumMemberDeclaration:         // = 8872,
        case SyntaxKind.FieldDeclaration:              // = 8873,
        case SyntaxKind.EventFieldDeclaration:         // = 8874,
        case SyntaxKind.MethodDeclaration:             // = 8875,
        case SyntaxKind.OperatorDeclaration:           // = 8876,
        case SyntaxKind.ConversionOperatorDeclaration: // = 8877,
        case SyntaxKind.ConstructorDeclaration:        // = 8878,
            break;

        case SyntaxKind.BaseConstructorInitializer: // = 8889,
        case SyntaxKind.ThisConstructorInitializer: // = 8890,
        case SyntaxKind.DestructorDeclaration:      // = 8891,
        case SyntaxKind.PropertyDeclaration:        // = 8892,
        case SyntaxKind.EventDeclaration:           // = 8893,
        case SyntaxKind.IndexerDeclaration:         // = 8894,
        case SyntaxKind.AccessorList:               // = 8895,
        case SyntaxKind.GetAccessorDeclaration:     // = 8896,
        case SyntaxKind.SetAccessorDeclaration:     // = 8897,
        case SyntaxKind.AddAccessorDeclaration:     // = 8898,
        case SyntaxKind.RemoveAccessorDeclaration:  // = 8899,
        case SyntaxKind.UnknownAccessorDeclaration: // = 8900,
        case SyntaxKind.ParameterList:              // = 8906,
        case SyntaxKind.BracketedParameterList:     // = 8907,
        case SyntaxKind.Parameter:                  // = 8908,
        case SyntaxKind.TypeParameterList:          // = 8909,
        case SyntaxKind.TypeParameter:              // = 8910,
        case SyntaxKind.IncompleteMember:           // = 8916,
        case SyntaxKind.ArrowExpressionClause:      // = 8917,
            break;

        default:
            Console.WriteLine("Error: default reached in switch over node.Kind = " + node.Kind());
            break;
        }

        base.Visit(node);
        Tabs--;
    }
        private static void AnalyzeCompilationUnit(SyntaxNodeAnalysisContext context)
        {
            var compilationUnit = (CompilationUnitSyntax)context.Node;

            UsingDirectiveSyntax usingDirective = compilationUnit.Usings.FirstOrDefault();

            if (usingDirective == null)
            {
                return;
            }

            SyntaxTriviaList.Reversed.Enumerator en = usingDirective.GetLeadingTrivia().Reverse().GetEnumerator();

            if (en.MoveNext())
            {
                if (en.Current.IsWhitespaceTrivia() &&
                    !en.MoveNext())
                {
                    if (IsPrecededWithExternAliasDirective())
                    {
                        ReportDiagnostic(usingDirective.SpanStart);
                    }
                }
                else
                {
                    switch (en.Current.Kind())
                    {
                    case SyntaxKind.EndOfLineTrivia:
                    {
                        if (en.MoveNext() &&
                            en.Current.IsKind(SyntaxKind.SingleLineCommentTrivia))
                        {
                            ReportDiagnostic(usingDirective.SpanStart);
                        }

                        break;
                    }

                    case SyntaxKind.RegionDirectiveTrivia:
                    {
                        SyntaxTrivia regionDirective = en.Current;

                        if (en.MoveNext())
                        {
                            if (en.Current.IsWhitespaceTrivia() &&
                                !en.MoveNext())
                            {
                                if (IsPrecededWithExternAliasDirective())
                                {
                                    ReportDiagnostic(regionDirective.SpanStart);
                                }
                            }
                            else if (en.Current.IsEndOfLineTrivia() &&
                                     en.MoveNext() &&
                                     en.Current.IsKind(SyntaxKind.SingleLineCommentTrivia))
                            {
                                ReportDiagnostic(regionDirective.SpanStart);
                            }
                        }
                        else if (IsPrecededWithExternAliasDirective())
                        {
                            ReportDiagnostic(regionDirective.SpanStart);
                        }

                        break;
                    }

                    default:
                    {
                        if (en.Current.IsDirective)
                        {
                            ReportDiagnostic(usingDirective.SpanStart);
                        }

                        break;
                    }
                    }
                }
            }
            else if (IsPrecededWithExternAliasDirective())
            {
                ReportDiagnostic(usingDirective.SpanStart);
            }

            bool IsPrecededWithExternAliasDirective()
            {
                ExternAliasDirectiveSyntax externAliasDirective = compilationUnit.Externs.LastOrDefault();

                return(externAliasDirective?.FullSpan.End == usingDirective.FullSpan.Start &&
                       SyntaxTriviaAnalysis.IsOptionalWhitespaceThenOptionalSingleLineCommentThenEndOfLineTrivia(externAliasDirective.GetTrailingTrivia()));
            }

            void ReportDiagnostic(int position)
            {
                context.ReportDiagnostic(
                    DiagnosticDescriptors.AddEmptyLineBeforeUsingDirectiveList,
                    Location.Create(compilationUnit.SyntaxTree, new TextSpan(position, 0)));
            }
        }
예제 #36
0
 private static string GetAliasName(UsingDirectiveSyntax usingDirective)
 {
     return((usingDirective.Alias == null || usingDirective.Alias.Name == null) ? null : usingDirective.Alias.Name.ToString());
 }
 public override void VisitUsingDirective(UsingDirectiveSyntax node)
 {
     CheckForInvalid(node);
     base.VisitUsingDirective(node);
 }
 public RichGenerationContext AddUsing(UsingDirectiveSyntax usingDirective)
 {
     Usings.Add(usingDirective);
     return(this);
 }
예제 #39
0
 public override void VisitUsingDirective(UsingDirectiveSyntax node)
 {
 }
예제 #40
0
 /// <inheritdoc />
 /// <summary>
 /// Called when the visitor visits a UsingDirectiveSyntax node.
 /// </summary>
 /// <param name="node">Visited node</param>
 public override void VisitUsingDirective(UsingDirectiveSyntax node)
 {
     base.VisitUsingDirective(node);
     counter_++;
 }
예제 #41
0
 /// <summary>
 /// Given a using declaration get the corresponding symbol for the using alias that was
 /// introduced.
 /// </summary>
 /// <param name="declarationSyntax"></param>
 /// <param name="cancellationToken">The cancellation token.</param>
 /// <returns>The alias symbol that was declared.</returns>
 /// <remarks>
 /// If the using directive is an error because it attempts to introduce an alias for which an existing alias was
 /// previously declared in the same scope, the result is a newly-constructed AliasSymbol (i.e. not one from the
 /// symbol table).
 /// </remarks>
 public abstract IAliasSymbol GetDeclaredSymbol(UsingDirectiveSyntax declarationSyntax, CancellationToken cancellationToken = default(CancellationToken));
예제 #42
0
 private static bool IsAliasOrStaticUsingDirective(UsingDirectiveSyntax usingDirective) => usingDirective.Alias != null || usingDirective.StaticKeyword.IsKind(SyntaxKind.StaticKeyword);
 private static bool IsAliasOrStaticUsingDirective(UsingDirectiveSyntax usingDirective) => usingDirective.Alias != null || usingDirective.StaticKeyword.IsKind(SyntaxKind.StaticKeyword);
예제 #44
0
 public override void VisitUsingDirective(UsingDirectiveSyntax node)
 {
 }
예제 #45
0
 public override IAliasSymbol GetDeclaredSymbol(UsingDirectiveSyntax declarationSyntax, CancellationToken cancellationToken = default(CancellationToken))
 {
     // Can't define alias inside member.
     return null;
 }
예제 #46
0
 internal AliasSymbol(Binder binder, UsingDirectiveSyntax syntax)
     : this(binder, syntax.Alias.Name.Identifier)
 {
     _aliasTargetName = syntax.Name;
 }
            private UsingDirectiveSyntax QualifyUsingDirective(UsingDirectiveSyntax usingDirective)
            {
                NameSyntax originalName = usingDirective.Name;
                NameSyntax rewrittenName;
                switch (originalName.Kind())
                {
                case SyntaxKind.QualifiedName:
                case SyntaxKind.IdentifierName:
                case SyntaxKind.GenericName:
                    if (originalName.Parent.IsKind(SyntaxKind.UsingDirective)
                        || originalName.Parent.IsKind(SyntaxKind.TypeArgumentList))
                    {
                        var symbol = this.semanticModel.GetSymbolInfo(originalName, cancellationToken: CancellationToken.None).Symbol;
                        if (symbol == null)
                        {
                            rewrittenName = originalName;
                            break;
                        }

                        if (symbol is INamespaceSymbol)
                        {
                            // TODO: Preserve inner trivia
                            string fullName = symbol.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat);
                            NameSyntax replacement = SyntaxFactory.ParseName(fullName);
                            if (!originalName.DescendantNodesAndSelf().OfType<AliasQualifiedNameSyntax>().Any())
                            {
                                replacement = replacement.ReplaceNodes(
                                    replacement.DescendantNodesAndSelf().OfType<AliasQualifiedNameSyntax>(),
                                    (originalNode2, rewrittenNode2) => rewrittenNode2.Name);
                            }

                            rewrittenName = replacement.WithTriviaFrom(originalName);
                            break;
                        }
                        else if (symbol is INamedTypeSymbol)
                        {
                            // TODO: Preserve inner trivia
                            // TODO: simplify after qualification
                            string fullName;
                            if (SpecialTypeHelper.IsPredefinedType(((INamedTypeSymbol)symbol).OriginalDefinition.SpecialType))
                            {
                                fullName = "global::System." + symbol.Name;
                            }
                            else
                            {
                                fullName = symbol.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat);
                            }

                            NameSyntax replacement = SyntaxFactory.ParseName(fullName);
                            if (!originalName.DescendantNodesAndSelf().OfType<AliasQualifiedNameSyntax>().Any())
                            {
                                replacement = replacement.ReplaceNodes(
                                    replacement.DescendantNodesAndSelf().OfType<AliasQualifiedNameSyntax>(),
                                    (originalNode2, rewrittenNode2) => rewrittenNode2.Name);
                            }

                            rewrittenName = replacement.WithTriviaFrom(originalName);
                            break;
                        }
                        else
                        {
                            rewrittenName = originalName;
                            break;
                        }
                    }
                    else
                    {
                        rewrittenName = originalName;
                        break;
                    }

                case SyntaxKind.AliasQualifiedName:
                case SyntaxKind.PredefinedType:
                default:
                    rewrittenName = originalName;
                    break;
                }

                if (rewrittenName == originalName)
                {
                    return usingDirective;
                }

                return usingDirective.ReplaceNode(originalName, rewrittenName);
            }
 public NamespaceOrTypeAndUsingDirective(NamespaceOrTypeSymbol namespaceOrType, UsingDirectiveSyntax usingDirective)
 {
     this.NamespaceOrType = namespaceOrType;
     this.UsingDirective = usingDirective;
 }
            private bool IsSeparatedSystemUsing(UsingDirectiveSyntax syntax)
            {
                if (!this.separateSystemDirectives)
                {
                    return false;
                }

                return syntax.Alias == null
                    && syntax.IsSystemUsingDirective()
                    && !syntax.HasNamespaceAliasQualifier()
                    && syntax.StaticKeyword.IsKind(SyntaxKind.None);
            }
예제 #50
0
 public override void VisitUsingDirective(UsingDirectiveSyntax node)
 {
     //   base.VisitUsingDirective(node);
 }
            public override SyntaxNode VisitUsingDirective(UsingDirectiveSyntax node)
            {
                // The strip list is used to remove using directives that will be moved.
                if (this.stripList.Contains(node))
                {
                    var nextToken = node.SemicolonToken.GetNextToken();

                    if (!nextToken.IsKind(SyntaxKind.None))
                    {
                        var index = TriviaHelper.IndexOfFirstNonBlankLineTrivia(nextToken.LeadingTrivia);
                        if (index != 0)
                        {
                            this.tokensToStrip.AddLast(nextToken);
                        }
                    }

                    return null;
                }

                // The replacement map is used to replace using declarations in place in sorted order (inside directive trivia)
                UsingDirectiveSyntax replacementNode;
                if (this.replaceMap.TryGetValue(node, out replacementNode))
                {
                    return replacementNode;
                }

                return base.VisitUsingDirective(node);
            }
 private static int CompareSpanStart(UsingDirectiveSyntax left, UsingDirectiveSyntax right)
 {
     return(left.SpanStart - right.SpanStart);
 }
예제 #53
0
		public override SyntaxNode VisitUsingDirective(UsingDirectiveSyntax node)
		{
			return null;
		}
            private UsingDirectiveSyntax QualifyUsingDirective(UsingDirectiveSyntax usingDirective)
            {
                NameSyntax originalName = usingDirective.Name;
                NameSyntax rewrittenName;

                switch (originalName.Kind())
                {
                case SyntaxKind.QualifiedName:
                case SyntaxKind.IdentifierName:
                case SyntaxKind.GenericName:
                    if (originalName.Parent.IsKind(SyntaxKind.UsingDirective) ||
                        originalName.Parent.IsKind(SyntaxKind.TypeArgumentList))
                    {
                        var symbol = this.semanticModel.GetSymbolInfo(originalName, cancellationToken: CancellationToken.None).Symbol;
                        if (symbol == null)
                        {
                            rewrittenName = originalName;
                            break;
                        }

                        if (symbol is INamespaceSymbol)
                        {
                            // TODO: Preserve inner trivia
                            string     fullName    = symbol.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat);
                            NameSyntax replacement = SyntaxFactory.ParseName(fullName);
                            if (!originalName.DescendantNodesAndSelf().OfType <AliasQualifiedNameSyntax>().Any())
                            {
                                replacement = replacement.ReplaceNodes(
                                    replacement.DescendantNodesAndSelf().OfType <AliasQualifiedNameSyntax>(),
                                    (originalNode2, rewrittenNode2) => rewrittenNode2.Name);
                            }

                            rewrittenName = replacement.WithTriviaFrom(originalName);
                            break;
                        }
                        else if (symbol is INamedTypeSymbol)
                        {
                            // TODO: Preserve inner trivia
                            // TODO: simplify after qualification
                            string fullName;
                            if (SpecialTypeHelper.IsPredefinedType(((INamedTypeSymbol)symbol).OriginalDefinition.SpecialType))
                            {
                                fullName = "global::System." + symbol.Name;
                            }
                            else
                            {
                                fullName = symbol.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat);
                            }

                            NameSyntax replacement = SyntaxFactory.ParseName(fullName);
                            if (!originalName.DescendantNodesAndSelf().OfType <AliasQualifiedNameSyntax>().Any())
                            {
                                replacement = replacement.ReplaceNodes(
                                    replacement.DescendantNodesAndSelf().OfType <AliasQualifiedNameSyntax>(),
                                    (originalNode2, rewrittenNode2) => rewrittenNode2.Name);
                            }

                            rewrittenName = replacement.WithTriviaFrom(originalName);
                            break;
                        }
                        else
                        {
                            rewrittenName = originalName;
                            break;
                        }
                    }
                    else
                    {
                        rewrittenName = originalName;
                        break;
                    }

                case SyntaxKind.AliasQualifiedName:
                case SyntaxKind.PredefinedType:
                default:
                    rewrittenName = originalName;
                    break;
                }

                if (rewrittenName == originalName)
                {
                    return(usingDirective);
                }

                return(usingDirective.ReplaceNode(originalName, rewrittenName));
            }
예제 #55
0
        /// <summary>
        /// Given a using declaration get the corresponding symbol for the using alias that was introduced.  
        /// </summary>
        /// <param name="declarationSyntax"></param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>The alias symbol that was declared.</returns>
        /// <remarks>
        /// If the using directive is an error because it attempts to introduce an alias for which an existing alias was
        /// previously declared in the same scope, the result is a newly-constructed AliasSymbol (i.e. not one from the
        /// symbol table).
        /// </remarks>
        public override IAliasSymbol GetDeclaredSymbol(
            UsingDirectiveSyntax declarationSyntax,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            CheckSyntaxNode(declarationSyntax);

            if (declarationSyntax.Alias == null)
            {
                return null;
            }

            InContainerBinder binder = _binderFactory.GetImportsBinder(declarationSyntax.Parent);
            var imports = binder.GetImports(basesBeingResolved: null);
            var alias = imports.UsingAliases[declarationSyntax.Alias.Name.Identifier.ValueText];

            if ((object)alias.Alias == null)
            {
                // Case: no aliases
                return null;
            }
            else if (alias.Alias.Locations[0].SourceSpan == declarationSyntax.Alias.Name.Span)
            {
                // Case: first alias (there may be others)
                return alias.Alias;
            }
            else
            {
                // Case: multiple aliases, not the first (see DevDiv #9368)
                return new AliasSymbol(binder, declarationSyntax);
            }
        }
예제 #56
0
 public override SyntaxNode VisitUsingDirective(UsingDirectiveSyntax node)
 {
     node = (UsingDirectiveSyntax)base.VisitUsingDirective(node);
     Classes.Add(node);
     return(node);
 }
예제 #57
0
        /// <summary>Called when the visitor visits a UsingDirectiveSyntax node.</summary>
        public override SyntaxNode VisitUsingDirective(UsingDirectiveSyntax node)
        {
            var r = base.VisitUsingDirective(node);

            return(r.WithTrailingTrivia(Tabs.BrTabs()));
        }
예제 #58
0
 public static bool IsNUnitUsing(this UsingDirectiveSyntax node) =>
 node.Name.ToString() == "NUnit.Framework";
 internal void RecordImport(UsingDirectiveSyntax syntax)
 {
     RecordImportInternal(syntax);
 }
예제 #60
0
 public override void VisitUsingDirective(UsingDirectiveSyntax node)
 {
     _usings.Add(node);
 }