本文整理汇总了C#中IDocument.GetSyntaxRoot方法的典型用法代码示例。如果您正苦于以下问题:C# IDocument.GetSyntaxRoot方法的具体用法?C# IDocument.GetSyntaxRoot怎么用?C# IDocument.GetSyntaxRoot使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDocument
的用法示例。
在下文中一共展示了IDocument.GetSyntaxRoot方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetMethodBlock
private SyntaxNode GetMethodBlock(IDocument document, string name)
{
var methods = ASTUtil.GetMethodsDeclarations((SyntaxNode) document.GetSyntaxRoot());
var method = (MethodDeclarationSyntax)methods.First(m => ((MethodDeclarationSyntax) m).
Identifier.ValueText.Equals(name));
return method.Body;
}
示例2: Annotate
public static IDocument Annotate(IDocument document, TextSpan span, out IEnumerable<SyntaxAnnotation> annotations)
{
var oldRoot = (CompilationUnitSyntax)document.GetSyntaxRoot();
var propertyAnnotater = new PropertyAnnotater(document, span);
var newRoot = (CompilationUnitSyntax)propertyAnnotater.Visit(oldRoot);
annotations = propertyAnnotater.annotations;
return document.UpdateSyntaxRoot(newRoot);
}
示例3: TypeHierarchyAnalyzerTests
public TypeHierarchyAnalyzerTests()
{
var source = FileUtil.ReadAllText(TestUtil.GetFakeSourceFolder() + "/TypeHierarchyFakeSource.cs");
var converter = new String2IDocumentConverter();
document = (IDocument)converter.Convert(source, null, null, null);
analyzer = AnalyzerFactory.GetTypeHierarchyAnalyzer();
analyzer.SetSemanticModel(document.GetSemanticModel());
root = (SyntaxNode) document.GetSyntaxRoot();
}
示例4: MethodInvocationAnalyzerTests
public MethodInvocationAnalyzerTests()
{
this.analyzer = AnalyzerFactory.GetMethodInvocationAnalyzer();
var converter = new String2IDocumentConverter();
this.document = (IDocument) converter.Convert(FileUtil.ReadAllText(
TestUtil.GetFakeSourceFolder() + "ChangeMethodSignatureAfter.txt"), null, null, null);
this.invocations = ((SyntaxNode)document.GetSyntaxRoot()).
DescendantNodes().Where(i => i.Kind == SyntaxKind.InvocationExpression);
this.logger = NLoggerUtil.GetNLogger(typeof(MethodInvocationAnalyzerTests));
}
示例5: TransformSyntaxRoot
private static CommonSyntaxNode TransformSyntaxRoot(IDocument document)
{
var originalRoot = document.GetSyntaxRoot();
switch (document.LanguageServices.Language)
{
case LanguageNames.CSharp:
return TransformRootCSharp((Roslyn.Compilers.CSharp.SyntaxNode)originalRoot);
case LanguageNames.VisualBasic:
return TransformRootVisualBasic((Roslyn.Compilers.VisualBasic.SyntaxNode)originalRoot);
}
return originalRoot;
}
示例6: IsDocumentRight
/* Is the document where the inline methodAfter refactoring happened? */
private bool IsDocumentRight(IDocument document)
{
// Get the qualified name of the type that encloses the methodAfter.
var analyzer = AnalyzerFactory.GetQualifiedNameAnalyzer();
analyzer.SetSyntaxNode(methodAfter);
var containingMethodName = analyzer.GetOutsideTypeQualifiedName();
// Get the qualified names of types that are contained in the document.
analyzer.SetSyntaxNode((SyntaxNode)document.GetSyntaxRoot());
var documentContainedNames = analyzer.GetInsideQualifiedNames();
// If the type names in the document contains the name we want.
return documentContainedNames.Contains(containingMethodName);
}
示例7: ComputerAllCodeIssues
private IEnumerable<CodeIssue> ComputerAllCodeIssues(ICodeIssueComputer computer, IDocument document)
{
var root = (SyntaxNode)document.GetSyntaxRoot();
return root.DescendantNodes().SelectMany(n => computer.ComputeCodeIssues(document, n));
}
示例8: MapToAnotherDocument
public SyntaxNode MapToAnotherDocument(IDocument target)
{
// Do not need to parse into the node that does not include the node.
return (SyntaxNode)target.GetSyntaxRoot().DescendantNodes(n => n.Span.Contains(node.Span)).
First(n => n.Span.Equals(node.Span));
}
示例9: GetPossibleSyntaxNodes
public override IEnumerable<SyntaxNode> GetPossibleSyntaxNodes(IDocument document)
{
return ((SyntaxNode) document.GetSyntaxRoot()).DescendantNodes().Where(n => n
is StatementSyntax);
}
示例10: SetDocument
public void SetDocument(IDocument document)
{
this.document = document;
this.root = (SyntaxNode)document.GetSyntaxRoot();
}
示例11: GetPossibleSyntaxNodes
public override IEnumerable<SyntaxNode> GetPossibleSyntaxNodes(IDocument document)
{
return ((SyntaxNode) document.GetSyntaxRoot()).DescendantNodes(n => n.Kind != SyntaxKind.
MethodDeclaration).OfType<MethodDeclarationSyntax>().Select(m => m.ReturnType);
}
示例12: SetDocument
public void SetDocument(IDocument document)
{
root = (SyntaxNode) document.GetSyntaxRoot();
model = document.GetSemanticModel();
this.document = document;
}
示例13: updateMethodInvocations
/// <summary>
/// Update all the method invocations in the solution.
/// </summary>
/// <param name="document"></param>
/// <returns></returns>
private IDocument updateMethodInvocations(IDocument document)
{
// Get the retriever for method invocations.
var retriever = RetrieverFactory.GetMethodInvocationRetriever();
retriever.SetMethodDeclaration(declaration);
// Get all the invocations in the document for the given method
// declaration.
retriever.SetDocument(document);
var invocations = retriever.GetInvocations();
// If there are invocations in the document.
if (invocations.Any())
{
// Update root
var root = (SyntaxNode) document.GetSyntaxRoot();
var updatedRoot = new InvocationsAddArgumentsRewriter(invocations,
typeNameTuple.Item2).Visit(root);
// Update solution by update the document.
document = document.UpdateSyntaxRoot(updatedRoot);
}
return document;
}
示例14: updateMethodDeclaration
private IDocument updateMethodDeclaration(IDocument document)
{
// Get the simplified name of the method
var methodName = ((MethodDeclarationSyntax) declaration).Identifier.ValueText;
var documentAnalyzer = AnalyzerFactory.GetDocumentAnalyzer();
documentAnalyzer.SetDocument(document);
// Get the root of the current document.
var root = ((SyntaxNode) document.GetSyntaxRoot());
// Find the method
SyntaxNode method = root.DescendantNodes().Where(
// Find all the method declarations.
n => n.Kind == SyntaxKind.MethodDeclaration).
// Convert all of them to the RefactoringType MethodDeclarationSyntax.
Select(n => (MethodDeclarationSyntax) n).
// Get the one whose name is same with the given method declaration.
First(m => m.Identifier.ValueText.Equals(methodName));
// If we can find this method.
if (method != null)
{
// Get the updated method declaration.
var methodAnalyzer = AnalyzerFactory.GetMethodDeclarationAnalyzer();
methodAnalyzer.SetMethodDeclaration(method);
var updatedMethod = methodAnalyzer.AddParameters(new[] {typeNameTuple});
// Update the root, document and finally return the code action.
var updatedRoot = new MethodDeclarationRewriter(method, updatedMethod).
Visit(root);
return document.UpdateSyntaxRoot(updatedRoot);
}
return document;
}
示例15: SetDocument
public void SetDocument(IDocument document)
{
model = document.GetSemanticModel();
root = (SyntaxNode) document.GetSyntaxRoot();
}