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); }
public override InternalSyntax.CSharpSyntaxNode Visit( InternalSyntax.CSharpSyntaxNode node ) { var visited = base.Visit(node); return(_rewriteNode == null ? visited : _rewriteNode(visited)); }
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); }
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); }
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); } } } }
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; }
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())); }
internal static SyntaxToken Literal(CSharpSyntaxNode leading, string text, SyntaxKind kind, string value, CSharpSyntaxNode trailing) { return(SyntaxToken.WithValue(kind, leading, text, value, trailing)); }
internal static SyntaxToken Identifier(CSharpSyntaxNode leading, string text, CSharpSyntaxNode trailing) { return(Identifier(SyntaxKind.IdentifierToken, leading, text, text, trailing)); }
public override void DefaultVisit(Syntax.InternalSyntax.CSharpSyntaxNode node) { VisitChildren(node); }
private static SyntaxTree CreateSyntaxTree(this InternalSyntax.CSharpSyntaxNode root, SourceText text) { return(CSharpSyntaxTree.Create((CSharpSyntaxNode)root.CreateRed(), text)); }
internal static SyntaxToken Token(CSharpSyntaxNode leading, SyntaxKind kind, CSharpSyntaxNode trailing) { return(SyntaxToken.Create(kind, leading, trailing)); }
internal static CSharpSyntaxNode ListNode(CSharpSyntaxNode node0, CSharpSyntaxNode node1, CSharpSyntaxNode node2) { return(SyntaxList.List(node0, node1, node2)); }
internal static SyntaxToken XmlEntity(CSharpSyntaxNode leading, string text, string value, CSharpSyntaxNode trailing) { return(SyntaxToken.WithValue(SyntaxKind.XmlEntityLiteralToken, leading, text, value, trailing)); }
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)); }
internal static SyntaxToken BadToken(CSharpSyntaxNode leading, string text, CSharpSyntaxNode trailing) { return(SyntaxToken.WithValue(SyntaxKind.BadToken, leading, text, text, trailing)); }
protected override InternalSyntax.CSharpSyntaxNode DefaultVisit(InternalSyntax.CSharpSyntaxNode node) { return(node); }
internal static SyntaxToken Identifier(SyntaxKind contextualKind, CSharpSyntaxNode leading, string text, string valueText, CSharpSyntaxNode trailing) { return(SyntaxToken.Identifier(contextualKind, leading, text, valueText, trailing)); }
internal SyntaxList(CSharpSyntaxNode node) { this.node = node; }
internal static SyntaxToken Literal(CSharpSyntaxNode leading, string text, decimal value, CSharpSyntaxNode trailing) { return(SyntaxToken.WithValue(SyntaxKind.NumericLiteralToken, leading, text, value, trailing)); }
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; } }
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; } }
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)); }