示例#1
0
        private static bool CheckMethodMemberForExtensionSyntax(Syntax.InternalSyntax.CSharpSyntaxNode member)
        {
            if (member.Kind == SyntaxKind.MethodDeclaration)
            {
                var methodDecl = (Syntax.InternalSyntax.MethodDeclarationSyntax)member;

                var paramList = methodDecl.parameterList;
                if (paramList != null)
                {
                    var parameters = paramList.Parameters;

                    if (parameters.Count != 0)
                    {
                        var firstParameter = parameters[0];
                        foreach (var modifier in firstParameter.Modifiers)
                        {
                            if (modifier.Kind == SyntaxKind.ThisKeyword)
                            {
                                return(true);
                            }
                        }
                    }
                }
            }
            return(false);
        }
示例#2
0
            public override InternalSyntax.CSharpSyntaxNode Visit(
                InternalSyntax.CSharpSyntaxNode node
                )
            {
                var visited = base.Visit(node);

                return(_rewriteNode == null ? visited : _rewriteNode(visited));
            }
示例#3
0
        private static void AttachAndCheckDiagnostics(InternalSyntax.CSharpSyntaxNode node)
        {
            var nodeWithDiags = node.SetDiagnostics(new DiagnosticInfo[] { new CSDiagnosticInfo(ErrorCode.ERR_AbstractAndExtern) });
            var diags         = nodeWithDiags.GetDiagnostics();

            Assert.NotEqual(node, nodeWithDiags);
            Assert.Equal(1, diags.Length);
            Assert.Equal(ErrorCode.ERR_AbstractAndExtern, (ErrorCode)diags[0].Code);
        }
示例#4
0
 private static SyntaxTree CreateSyntaxTree(
     this InternalSyntax.CSharpSyntaxNode root,
     SourceText text
     )
 {
     return(CSharpSyntaxTree.CreateForDebugger(
                (CSharpSyntaxNode)root.CreateRed(),
                text,
                ParseOptions
                ));
 }
        private static bool CheckMemberForAttributes(Syntax.InternalSyntax.CSharpSyntaxNode member)
        {
            switch (member.Kind)
            {
            case SyntaxKind.CompilationUnit:
                return((((Syntax.InternalSyntax.CompilationUnitSyntax)member).AttributeLists).Any());

            case SyntaxKind.ConceptDeclaration:     //@t-mawind
            case SyntaxKind.InstanceDeclaration:    //@t-mawind
            case SyntaxKind.ClassDeclaration:
            case SyntaxKind.StructDeclaration:
            case SyntaxKind.InterfaceDeclaration:
            case SyntaxKind.EnumDeclaration:
                return((((Syntax.InternalSyntax.BaseTypeDeclarationSyntax)member).AttributeLists).Any());

            case SyntaxKind.DelegateDeclaration:
                return((((Syntax.InternalSyntax.DelegateDeclarationSyntax)member).AttributeLists).Any());

            case SyntaxKind.FieldDeclaration:
            case SyntaxKind.EventFieldDeclaration:
                return((((Syntax.InternalSyntax.BaseFieldDeclarationSyntax)member).AttributeLists).Any());

            case SyntaxKind.MethodDeclaration:
            case SyntaxKind.OperatorDeclaration:
            case SyntaxKind.ConversionOperatorDeclaration:
            case SyntaxKind.ConstructorDeclaration:
            case SyntaxKind.DestructorDeclaration:
                return((((Syntax.InternalSyntax.BaseMethodDeclarationSyntax)member).AttributeLists).Any());

            case SyntaxKind.PropertyDeclaration:
            case SyntaxKind.EventDeclaration:
            case SyntaxKind.IndexerDeclaration:
                var  baseProp      = (Syntax.InternalSyntax.BasePropertyDeclarationSyntax)member;
                bool hasAttributes = baseProp.AttributeLists.Any();

                if (!hasAttributes && baseProp.AccessorList != null)
                {
                    foreach (var accessor in baseProp.AccessorList.Accessors)
                    {
                        hasAttributes |= accessor.AttributeLists.Any();
                    }
                }

                return(hasAttributes);
            }

            return(false);
        }
示例#6
0
            private void VisitChildren(Syntax.InternalSyntax.CSharpSyntaxNode node)
            {
                var childCnt = node.SlotCount;

                for (int i = 0; i < childCnt; i++)
                {
                    var child = node.GetSlot(i);
                    if (child != null && child.SlotCount != 0)
                    {
                        if (child.IsList)
                        {
                            VisitChildren((Syntax.InternalSyntax.CSharpSyntaxNode)child);
                        }
                        else
                        {
                            ((Syntax.InternalSyntax.CSharpSyntaxNode)child).Accept(this);
                        }
                    }
                }
            }
示例#7
0
 private static GreenNode.NodeFlags GetFlags(SyntaxFactoryContext context)
 {
     GreenNode.NodeFlags flags = GetFlags();
     flags = CSharpSyntaxNode.SetFactoryContext(flags, context);
     return(flags);
 }
 internal WithThreeChildren(CSharpSyntaxNode child0, CSharpSyntaxNode child1, CSharpSyntaxNode child2)
 {
     this.SlotCount = 3;
     this.AdjustFlagsAndWidth(child0);
     this.child0 = child0;
     this.AdjustFlagsAndWidth(child1);
     this.child1 = child1;
     this.AdjustFlagsAndWidth(child2);
     this.child2 = child2;
 }
示例#9
0
 internal static SyntaxToken Literal(CSharpSyntaxNode leading, string text, char value, CSharpSyntaxNode trailing)
 {
     return(SyntaxToken.WithValue(SyntaxKind.CharacterLiteralToken, leading, text, value, trailing));
 }
 internal SyntaxTokenWithTrivia(SyntaxKind kind, CSharpSyntaxNode leading, CSharpSyntaxNode trailing, DiagnosticInfo[] diagnostics, SyntaxAnnotation[] annotations)
     : base(kind, diagnostics, annotations)
 {
     if (leading != null)
     {
         this.AdjustFlagsAndWidth(leading);
         this.LeadingField = leading;
     }
     if (trailing != null)
     {
         this.AdjustFlagsAndWidth(trailing);
         this.TrailingField = trailing;
     }
 }
 internal override SyntaxToken WithTrailingTrivia(CSharpSyntaxNode trivia)
 {
     return(new SyntaxTokenWithTrivia(this.Kind, this.LeadingField, trivia, this.GetDiagnostics(), this.GetAnnotations()));
 }
示例#12
0
 internal static SyntaxToken Literal(CSharpSyntaxNode leading, string text, SyntaxKind kind, string value, CSharpSyntaxNode trailing)
 {
     return(SyntaxToken.WithValue(kind, leading, text, value, trailing));
 }
示例#13
0
 internal static SyntaxToken Identifier(CSharpSyntaxNode leading, string text, CSharpSyntaxNode trailing)
 {
     return(Identifier(SyntaxKind.IdentifierToken, leading, text, text, trailing));
 }
示例#14
0
 public override void DefaultVisit(Syntax.InternalSyntax.CSharpSyntaxNode node)
 {
     VisitChildren(node);
 }
示例#15
0
 private static SyntaxTree CreateSyntaxTree(this InternalSyntax.CSharpSyntaxNode root, SourceText text)
 {
     return(CSharpSyntaxTree.Create((CSharpSyntaxNode)root.CreateRed(), text));
 }
示例#16
0
 internal static SyntaxToken Token(CSharpSyntaxNode leading, SyntaxKind kind, CSharpSyntaxNode trailing)
 {
     return(SyntaxToken.Create(kind, leading, trailing));
 }
示例#17
0
 internal static CSharpSyntaxNode ListNode(CSharpSyntaxNode node0, CSharpSyntaxNode node1, CSharpSyntaxNode node2)
 {
     return(SyntaxList.List(node0, node1, node2));
 }
示例#18
0
 internal static SyntaxToken XmlEntity(CSharpSyntaxNode leading, string text, string value, CSharpSyntaxNode trailing)
 {
     return(SyntaxToken.WithValue(SyntaxKind.XmlEntityLiteralToken, leading, text, value, trailing));
 }
示例#19
0
        internal static SyntaxToken XmlTextNewLine(CSharpSyntaxNode leading, string text, string value, CSharpSyntaxNode trailing)
        {
            if (leading == null && trailing == null && text == CrLf && value == CrLf)
            {
                return(XmlCarriageReturnLineFeed);
            }

            return(SyntaxToken.WithValue(SyntaxKind.XmlTextLiteralNewLineToken, leading, text, value, trailing));
        }
示例#20
0
 internal static SyntaxToken BadToken(CSharpSyntaxNode leading, string text, CSharpSyntaxNode trailing)
 {
     return(SyntaxToken.WithValue(SyntaxKind.BadToken, leading, text, text, trailing));
 }
示例#21
0
 protected override InternalSyntax.CSharpSyntaxNode DefaultVisit(InternalSyntax.CSharpSyntaxNode node)
 {
     return(node);
 }
示例#22
0
 internal static SyntaxToken Identifier(SyntaxKind contextualKind, CSharpSyntaxNode leading, string text, string valueText, CSharpSyntaxNode trailing)
 {
     return(SyntaxToken.Identifier(contextualKind, leading, text, valueText, trailing));
 }
示例#23
0
 internal SyntaxList(CSharpSyntaxNode node)
 {
     this.node = node;
 }
示例#24
0
 internal static SyntaxToken Literal(CSharpSyntaxNode leading, string text, decimal value, CSharpSyntaxNode trailing)
 {
     return(SyntaxToken.WithValue(SyntaxKind.NumericLiteralToken, leading, text, value, trailing));
 }
示例#25
0
 protected virtual TResult DefaultVisit(CSharpSyntaxNode node)
 {
     return(default(TResult));
 }
 internal SyntaxTokenWithTrivia(SyntaxKind kind, CSharpSyntaxNode leading, CSharpSyntaxNode trailing)
     : base(kind)
 {
     if (leading != null)
     {
         this.AdjustFlagsAndWidth(leading);
         this.LeadingField = leading;
     }
     if (trailing != null)
     {
         this.AdjustFlagsAndWidth(trailing);
         this.TrailingField = trailing;
     }
 }
示例#27
0
        private static void AddNonTypeMemberNames(Syntax.InternalSyntax.CSharpSyntaxNode member, HashSet <string> set, ref bool anyNonTypeMembers)
        {
            switch (member.Kind)
            {
            case SyntaxKind.FieldDeclaration:
                anyNonTypeMembers = true;
                Syntax.InternalSyntax.SeparatedSyntaxList <Syntax.InternalSyntax.VariableDeclaratorSyntax> fieldDeclarators =
                    ((Syntax.InternalSyntax.FieldDeclarationSyntax)member).Declaration.Variables;
                int numFieldDeclarators = fieldDeclarators.Count;
                for (int i = 0; i < numFieldDeclarators; i++)
                {
                    set.Add(fieldDeclarators[i].Identifier.ValueText);
                }
                break;

            case SyntaxKind.EventFieldDeclaration:
                anyNonTypeMembers = true;
                Syntax.InternalSyntax.SeparatedSyntaxList <Syntax.InternalSyntax.VariableDeclaratorSyntax> eventDeclarators =
                    ((Syntax.InternalSyntax.EventFieldDeclarationSyntax)member).Declaration.Variables;
                int numEventDeclarators = eventDeclarators.Count;
                for (int i = 0; i < numEventDeclarators; i++)
                {
                    set.Add(eventDeclarators[i].Identifier.ValueText);
                }
                break;

            case SyntaxKind.MethodDeclaration:
                anyNonTypeMembers = true;
                // Member names are exposed via NamedTypeSymbol.MemberNames and are used primarily
                // as an acid test to determine whether a more in-depth search of a type is worthwhile.
                // We decided that it was reasonable to exclude explicit interface implementations
                // from the list of member names.
                var methodDecl = (Syntax.InternalSyntax.MethodDeclarationSyntax)member;
                if (methodDecl.ExplicitInterfaceSpecifier == null)
                {
                    set.Add(methodDecl.Identifier.ValueText);
                }
                break;

            case SyntaxKind.PropertyDeclaration:
                anyNonTypeMembers = true;
                // Handle in the same way as explicit method implementations
                var propertyDecl = (Syntax.InternalSyntax.PropertyDeclarationSyntax)member;
                if (propertyDecl.ExplicitInterfaceSpecifier == null)
                {
                    set.Add(propertyDecl.Identifier.ValueText);
                }
                break;

            case SyntaxKind.EventDeclaration:
                anyNonTypeMembers = true;
                // Handle in the same way as explicit method implementations
                var eventDecl = (Syntax.InternalSyntax.EventDeclarationSyntax)member;
                if (eventDecl.ExplicitInterfaceSpecifier == null)
                {
                    set.Add(eventDecl.Identifier.ValueText);
                }
                break;

            case SyntaxKind.ConstructorDeclaration:
                anyNonTypeMembers = true;
                set.Add(((Syntax.InternalSyntax.ConstructorDeclarationSyntax)member).Modifiers.Any(SyntaxKind.StaticKeyword)
                        ? WellKnownMemberNames.StaticConstructorName
                        : WellKnownMemberNames.InstanceConstructorName);
                break;

            case SyntaxKind.DestructorDeclaration:
                anyNonTypeMembers = true;
                set.Add(WellKnownMemberNames.DestructorName);
                break;

            case SyntaxKind.IndexerDeclaration:
                anyNonTypeMembers = true;
                set.Add(WellKnownMemberNames.Indexer);
                break;

            case SyntaxKind.OperatorDeclaration:
                anyNonTypeMembers = true;
                var opDecl = (Syntax.InternalSyntax.OperatorDeclarationSyntax)member;
                var name   = OperatorFacts.OperatorNameFromDeclaration(opDecl);
                set.Add(name);
                break;

            case SyntaxKind.ConversionOperatorDeclaration:
                anyNonTypeMembers = true;
                set.Add(((Syntax.InternalSyntax.ConversionOperatorDeclarationSyntax)member).ImplicitOrExplicitKeyword.Kind == SyntaxKind.ImplicitKeyword
                        ? WellKnownMemberNames.ImplicitConversionName
                        : WellKnownMemberNames.ExplicitConversionName);
                break;

            case SyntaxKind.GlobalStatement:
                anyNonTypeMembers = true;
                break;
            }
        }
示例#28
0
        internal static SyntaxToken Token(CSharpSyntaxNode leading, SyntaxKind kind, string text, string valueText, CSharpSyntaxNode trailing)
        {
            Debug.Assert(SyntaxFacts.IsAnyToken(kind));
            Debug.Assert(kind != SyntaxKind.IdentifierToken);
            Debug.Assert(kind != SyntaxKind.CharacterLiteralToken);
            Debug.Assert(kind != SyntaxKind.NumericLiteralToken);

            string defaultText = SyntaxFacts.GetText(kind);

            return(kind >= SyntaxToken.FirstTokenWithWellKnownText && kind <= SyntaxToken.LastTokenWithWellKnownText && text == defaultText && valueText == defaultText
                ? Token(leading, kind, trailing)
                : SyntaxToken.WithValue(kind, leading, text, valueText, trailing));
        }