internal SyntaxTransporter(CommonSyntaxToken token) { try { var t = (CSharp.SyntaxToken)token; SourceLanguage = LanguageNames.CSharp; } catch { var t = (VisualBasic.SyntaxToken)token; SourceLanguage = LanguageNames.VisualBasic; } SyntaxStream = new MemoryStream(); var rootNode = GetRootNode(token); if (rootNode != null) { if (SourceLanguage == LanguageNames.CSharp) { var csharpRootNode = (CSharp.SyntaxNode)rootNode; csharpRootNode.SerializeTo(SyntaxStream); } else { var vbRootNode = (VisualBasic.SyntaxNode)rootNode; vbRootNode.SerializeTo(SyntaxStream); } } ItemSpan = token.Span; ItemKind = token.GetKind(SourceLanguage); ItemCategory = SyntaxCategory.SyntaxToken; }
protected override bool TryInitializeExplicitInterfaceState( IDocument document, CommonSyntaxNode node, CancellationToken cancellationToken, out CommonSyntaxToken identifierToken, out IPropertySymbol propertySymbol, out INamedTypeSymbol typeToGenerateIn) { var propertyDeclaration = (PropertyDeclarationSyntax)node; identifierToken = propertyDeclaration.Identifier; if (propertyDeclaration.ExplicitInterfaceSpecifier != null) { var semanticModel = document.GetSemanticModel(cancellationToken); propertySymbol = semanticModel.GetDeclaredSymbol(propertyDeclaration, cancellationToken) as IPropertySymbol; if (propertySymbol != null && !propertySymbol.ExplicitInterfaceImplementations.Any()) { var info = semanticModel.GetTypeInfo(propertyDeclaration.ExplicitInterfaceSpecifier.Name, cancellationToken); typeToGenerateIn = info.Type as INamedTypeSymbol; return(typeToGenerateIn != null); } } identifierToken = default(CommonSyntaxToken); propertySymbol = null; typeToGenerateIn = null; return(false); }
protected override void VisitToken(CommonSyntaxToken token) { if (token.GetText() == textToSearch) { symbolFoundDelegate(token.SyntaxTree.GetLineSpan(token.Span, false).StartLinePosition.Line); } base.VisitToken(token); }
protected override void VisitToken(CommonSyntaxToken token, List <CommonSyntaxTrivia> results) { // if it doesnt have annotations, don't even bother to go in. if (!token.Node.HasAnnotations) { return; } base.VisitToken(token, results); }
protected override void VisitToken(CommonSyntaxToken token) { if (token.GetText() == parameter.Text) { var symbol = this.semanticModel.GetSymbolInfo(token.Parent); if ((searchTokenKind == TokenKind.MethodCall && token.Parent.Kind == (int)Roslyn.Compilers.CSharp.SyntaxKind.MethodDeclaration) || (searchTokenKind == TokenKind.ObjectCreation && token.Parent.Kind == (int)Roslyn.Compilers.CSharp.SyntaxKind.ClassDeclaration)) { symbolFoundDelegate(token.SyntaxTree.GetLineSpan(token.Span, false).StartLinePosition.Line); } } base.VisitToken(token); }
protected override void VisitToken(CommonSyntaxToken token, List <CommonSyntaxNodeOrToken> results) { // if it doesnt have annotations, don't even bother to go in. if (!token.Node.HasAnnotations) { return; } var annotations = token.Node.GetAnnotations(); AddNodeIfAnnotationExist(annotations, token, results); base.VisitToken(token, results); }
private CommonSyntaxNode GetRootNode(CommonSyntaxToken token) { CommonSyntaxNode rootNode = null; if (token.SyntaxTree != null) { rootNode = token.SyntaxTree.GetRoot(); } else { rootNode = GetRootNode(token.Parent); } return(rootNode); }
public static string GetKind(this CommonSyntaxToken token, string language) { var kind = string.Empty; if (language == LanguageNames.CSharp) { kind = ((CSharp.SyntaxKind)token.Kind).ToString(); } else { kind = ((VisualBasic.SyntaxKind)token.Kind).ToString(); } return(kind); }
private void DisplaySyntaxTokenDgml(CommonSyntaxToken token) { if (activeWpfTextView != null) { var snapshot = activeWpfTextView.TextBuffer.CurrentSnapshot; var contentType = snapshot.ContentType; XElement dgml = null; if (contentType.IsOfType(ContentTypeNames.CSharpContentType)) { dgml = token.ToDgml(LanguageNames.CSharp, activeSyntaxTree); } else if (contentType.IsOfType(ContentTypeNames.VisualBasicContentType)) { dgml = token.ToDgml(LanguageNames.VisualBasic, activeSyntaxTree); } DisplayDgml(dgml); } }
protected override bool TryInitializeIdentifierNameState( IDocument document, SimpleNameSyntax identifierName, CancellationToken cancellationToken, out CommonSyntaxToken identifierToken, out ExpressionSyntax simpleNameOrMemberAccessExpression) { identifierToken = identifierName.Identifier; if (identifierToken.ValueText != string.Empty && !identifierName.IsVar) { var memberAccess = identifierName.Parent as MemberAccessExpressionSyntax; simpleNameOrMemberAccessExpression = memberAccess != null && memberAccess.Name == identifierName ? (ExpressionSyntax)memberAccess : identifierName; // If we're being invoked, then don't offer this, offer generate method instead. // Note: we could offer to generate a field with a delegate type. However, that's // very esoteric and probably not what most users want. if (!IsLegal(simpleNameOrMemberAccessExpression)) { return(false); } #if false if (simpleNameOrMemberAccessExpression.IsParentKind(SyntaxKind.InvocationExpression) || simpleNameOrMemberAccessExpression.IsParentKind(SyntaxKind.ObjectCreationExpression) || simpleNameOrMemberAccessExpression.IsParentKind(SyntaxKind.GotoStatement) || simpleNameOrMemberAccessExpression.IsParentKind(SyntaxKind.AliasQualifiedName) || simpleNameOrMemberAccessExpression.IsParentKind(SyntaxKind.NameColon) || simpleNameOrMemberAccessExpression.IsParentKind(SyntaxKind.QualifiedName) || simpleNameOrMemberAccessExpression.IsParentKind(SyntaxKind.IncompleteMember) || identifierName.getan.IsParentKind(SyntaxKind.UsingDirective)) { return(false); } #endif return(true); } identifierToken = default(CommonSyntaxToken); simpleNameOrMemberAccessExpression = null; return(false); }
/// <summary> /// Gets the semantic information for a syntax node as seen from the perspective of the /// node's parent. /// </summary> /// <param name="semanticModel">The SemanticModel object to get semantic information /// from.</param> /// <param name="token">The token to get semantic information from. This must be part of the syntax tree /// associated with the binding.</param> /// <remarks> /// This method allows observing the result of implicit conversions that do not have syntax node's directly /// associated with them. For example, consider the following code: /// <code> /// void f(long x); /// int i = 17; /// f(i); /// </code> /// A call to GetSemanticInfo on the syntax node for "i" in "f(i)" would have a Type of "int". A call to /// GetSemanticInfoInParent on the same syntax node would have a Type of "long", since there is an implicit /// conversion from int to long as part of the function call to f. /// </remarks> public static ISemanticInfo GetSemanticInfoInParent(this ISemanticModel semanticModel, CommonSyntaxToken token) { return(semanticModel.GetSemanticInfoInParent(token.Parent)); }
private void AddToken(TreeViewItem parentItem, CommonSyntaxToken token) { var kind = token.GetKind(SourceLanguage); var tag = new SyntaxTag() { SyntaxToken = token, Category = SyntaxCategory.SyntaxToken, Span = token.Span, FullSpan = token.FullSpan, Kind = kind, ParentItem = parentItem }; var item = new TreeViewItem() { Tag = tag, IsExpanded = false, Foreground = Brushes.LightGreen, //Background = token.ContainsDiagnostics ? Brushes.Pink : Brushes.White, Header = tag.Kind + " " + token.Span.ToString() }; if (SyntaxTree != null && token.ContainsDiagnostics) { item.ToolTip = string.Empty; foreach (var diagnostic in SyntaxTree.GetDiagnostics(token)) { item.ToolTip += diagnostic.ToString(null) + "\n"; } item.ToolTip = item.ToolTip.ToString().Trim(); } item.Selected += new RoutedEventHandler((sender, e) => { isNavigatingFromTreeToSource = true; //typeTextLabel.Visibility = Visibility.Visible; //kindTextLabel.Visibility = Visibility.Visible; //kindValueLabel.Content = kind; try { propertyGrid.Instance = token; } catch { } item.IsExpanded = true; if (!isNavigatingFromSourceToTree && SyntaxTokenNavigationToSourceRequested != null) { SyntaxTokenNavigationToSourceRequested(token); } isNavigatingFromTreeToSource = false; e.Handled = true; }); item.Expanded += new RoutedEventHandler((sender, e) => { if (item.Items.Count == 1 && item.Items[0] == null) { // Remove placeholder child and populate real children. item.Items.RemoveAt(0); foreach (var trivia in token.LeadingTrivia) { AddTrivia(item, trivia, true); } foreach (var trivia in token.TrailingTrivia) { AddTrivia(item, trivia, false); } } }); if (parentItem == root) { parentItem.Items.Clear(); parentItem.Items.Add(item); parentItem.IsExpanded = true; } else { parentItem.Items.Add(item); } if (token.HasLeadingTrivia || token.HasTrailingTrivia) { if (IsLazy) { // Add placeholder child to indicate that real children need to be populated on expansion. item.Items.Add(null); } else { // Recursively populate all descendants. foreach (var trivia in token.LeadingTrivia) { AddTrivia(item, trivia, true); } foreach (var trivia in token.TrailingTrivia) { AddTrivia(item, trivia, false); } } } }
private CommonSyntaxNode GetRootNode(CommonSyntaxToken token) { CommonSyntaxNode rootNode = null; if (token.SyntaxTree != null) { rootNode = token.SyntaxTree.GetRoot(); } else { rootNode = GetRootNode(token.Parent); } return rootNode; }
public CommonSyntaxNodeOrToken(CommonSyntaxToken token) : this() { _token = token; }
public IEnumerable <CodeIssue> GetIssues(IDocument document, CommonSyntaxToken token, CancellationToken cancellationToken) { throw new NotImplementedException(); }
public IEnumerable<SyntaxClassification> ClassifyToken(IDocument document, CommonSyntaxToken syntax, CancellationToken cancellationToken) { throw new NotImplementedException(); }
private void AddToken(TreeViewItem parentItem, CommonSyntaxToken token) { var kind = token.GetKind(SourceLanguage); var tag = new SyntaxTag() { SyntaxToken = token, IsSyntaxNode = false, IsSyntaxToken = true, IsSyntaxTrivia = false, Span = token.Span, FullSpan = token.FullSpan, Kind = kind, ParentItem = parentItem }; var item = new TreeViewItem() { Tag = tag, IsExpanded = true, Foreground = Brushes.DarkGreen, Background = token.HasDiagnostics ? Brushes.Pink : Brushes.White, Header = tag.Kind + " " + token.Span.ToString() }; if (token.HasDiagnostics) { item.ToolTip = string.Empty; foreach (var diagnostic in SyntaxTree.GetDiagnostics(token)) { item.ToolTip += diagnostic.ToString(null) + "\n"; } item.ToolTip = item.ToolTip.ToString().Trim(); } item.Selected += new RoutedEventHandler((sender, e) => { if (!e.Handled) { isNavigatingFromTreeToSource = true; typeTextLabel.Visibility = Visibility.Visible; kindTextLabel.Visibility = Visibility.Visible; typeValueLabel.Content = token.GetType().Name; kindValueLabel.Content = kind; propertyGrid.SelectedObject = token; // If IsLazy is true then populate only child items. if (IsLazy && item.Items.Count == 0) { if (token.HasLeadingTrivia) { foreach (var trivia in token.LeadingTrivia) { AddTrivia(item, trivia, true); } } if (token.HasTrailingTrivia) { foreach (var trivia in token.TrailingTrivia) { AddTrivia(item, trivia, false); } } } item.IsExpanded = true; if (!isNavigatingFromSourceToTree && SyntaxTokenNavigationToSourceRequested != null) { SyntaxTokenNavigationToSourceRequested(token); } isNavigatingFromTreeToSource = false; e.Handled = true; } }); if (parentItem == null) { treeView.Items.Clear(); treeView.Items.Add(item); } else { parentItem.Items.Add(item); } // If IsLazy is false then recursively populate all descendent items. if (!IsLazy) { if (token.HasLeadingTrivia) { foreach (var trivia in token.LeadingTrivia) { AddTrivia(item, trivia, true); } } if (token.HasTrailingTrivia) { foreach (var trivia in token.TrailingTrivia) { AddTrivia(item, trivia, false); } } } }
public IEnumerable<Microsoft.CodeAnalysis.CodeActions.CodeIssue> GetIssues(Microsoft.CodeAnalysis.Document document, CommonSyntaxToken syntax, CancellationToken cancellationToken) { throw new NotImplementedException(); }
/// <summary> /// Gets the semantic information for a syntax node as seen from the perspective of the /// node's parent. /// </summary> /// <param name="semanticModel">The SemanticModel object to get semantic information /// from.</param> /// <param name="token">The token to get semantic information from. This must be part of the syntax tree /// associated with the binding.</param> /// <remarks> /// This method allows observing the result of implicit conversions that do not have syntax node's directly /// associated with them. For example, consider the following code: /// <code> /// void f(long x); /// int i = 17; /// f(i); /// </code> /// A call to GetSemanticInfo on the syntax node for "i" in "f(i)" would have a Type of "int". A call to /// GetSemanticInfoInParent on the same syntax node would have a Type of "long", since there is an implicit /// conversion from int to long as part of the function call to f. /// </remarks> public static ISemanticInfo GetSemanticInfoInParent(this ISemanticModel semanticModel, CommonSyntaxToken token) { return semanticModel.GetSemanticInfoInParent(token.Parent); }
public IEnumerable<CodeIssue> GetIssues(IDocument document, CommonSyntaxToken token, CancellationToken cancellationToken) { yield break; }
CommonSyntaxToken ISyntaxAnnotation.AddAnnotationTo(CommonSyntaxToken token) { return(this.AddAnnotationTo((SyntaxToken)token)); }
public IEnumerable <CodeIssue> GetIssues(IDocument document, CommonSyntaxToken token, CancellationToken cancellationToken) { yield break; }
public IEnumerable <SyntaxClassification> ClassifyToken(IDocument document, CommonSyntaxToken syntax, CancellationToken cancellationToken) { throw new NotImplementedException(); }
public IEnumerable<CodeIssue> GetIssues(IDocument document, CommonSyntaxToken token, CancellationToken cancellationToken) { throw new NotImplementedException(); }
public IEnumerable <Microsoft.CodeAnalysis.CodeActions.CodeIssue> GetIssues(Microsoft.CodeAnalysis.Document document, CommonSyntaxToken syntax, CancellationToken cancellationToken) { throw new NotImplementedException(); }