当前位置: 首页>>代码示例>>C#>>正文


C# SyntaxTree.GetCompilationUnitRoot方法代码示例

本文整理汇总了C#中SyntaxTree.GetCompilationUnitRoot方法的典型用法代码示例。如果您正苦于以下问题:C# SyntaxTree.GetCompilationUnitRoot方法的具体用法?C# SyntaxTree.GetCompilationUnitRoot怎么用?C# SyntaxTree.GetCompilationUnitRoot使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SyntaxTree的用法示例。


在下文中一共展示了SyntaxTree.GetCompilationUnitRoot方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetRebuiltNodes

        /// <summary>
        /// Returns the nodes in the new tree that do not share the same underlying 
        /// representation in the old tree. These may be entirely new nodes or rebuilt nodes.
        /// </summary>
        public static ImmutableArray<SyntaxNodeOrToken> GetRebuiltNodes(SyntaxTree oldTree, SyntaxTree newTree)
        {
            var hashSet = new HashSet<GreenNode>();
            GatherNodes(oldTree.GetCompilationUnitRoot(), hashSet);

            var nodes = ArrayBuilder<SyntaxNodeOrToken>.GetInstance();
            GetRebuiltNodes(newTree.GetCompilationUnitRoot(), hashSet, nodes);
            return nodes.ToImmutableAndFree();
        }
开发者ID:Rickinio,项目名称:roslyn,代码行数:13,代码来源:SyntaxDifferences.cs

示例2: GetExpressionNode

 private static PrefixUnaryExpressionSyntax GetExpressionNode(SyntaxTree newTree)
 {
     var classType = newTree.GetCompilationUnitRoot().Members[0] as TypeDeclarationSyntax;
     var method = classType.Members[0] as MethodDeclarationSyntax;
     var block = method.Body;
     var statement = block.Statements[0] as ExpressionStatementSyntax;
     var expression = statement.Expression as PrefixUnaryExpressionSyntax;
     return expression;
 }
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:9,代码来源:UnaryExpression.cs

示例3: ReplaceSyntaxTree

        public SyntaxAndDeclarationManager ReplaceSyntaxTree(SyntaxTree oldTree, SyntaxTree newTree)
        {
            var state = _lazyState;
            var newExternalSyntaxTrees = this.ExternalSyntaxTrees.Replace(oldTree, newTree);
            if (state == null)
            {
                return this.WithExternalSyntaxTrees(newExternalSyntaxTrees);
            }

            var newLoadDirectivesSyntax = newTree.GetCompilationUnitRoot().GetLoadDirectives();
            var loadDirectivesHaveChanged = !oldTree.GetCompilationUnitRoot().GetLoadDirectives().SequenceEqual(newLoadDirectivesSyntax);
            var syntaxTrees = state.SyntaxTrees;
            var ordinalMap = state.OrdinalMap;
            var loadDirectiveMap = state.LoadDirectiveMap;
            var loadedSyntaxTreeMap = state.LoadedSyntaxTreeMap;
            var removeSet = PooledHashSet<SyntaxTree>.GetInstance();
            int totalReferencedTreeCount;
            ImmutableArray<LoadDirective> oldLoadDirectives;
            GetRemoveSet(
                oldTree,
                loadDirectivesHaveChanged,
                syntaxTrees,
                ordinalMap,
                loadDirectiveMap,
                loadedSyntaxTreeMap,
                removeSet,
                out totalReferencedTreeCount,
                out oldLoadDirectives);

            var loadDirectiveMapBuilder = loadDirectiveMap.ToBuilder();
            var loadedSyntaxTreeMapBuilder = loadedSyntaxTreeMap.ToBuilder();
            var declMapBuilder = state.RootNamespaces.ToBuilder();
            var declTable = state.DeclarationTable;
            foreach (var tree in removeSet)
            {
                loadDirectiveMapBuilder.Remove(tree);
                loadedSyntaxTreeMapBuilder.Remove(tree.FilePath);
                RemoveSyntaxTreeFromDeclarationMapAndTable(tree, declMapBuilder, ref declTable);
            }
            removeSet.Free();

            var oldOrdinal = ordinalMap[oldTree];
            ImmutableArray<SyntaxTree> newTrees;
            if (loadDirectivesHaveChanged)
            {
                // Should have been removed above...
                Debug.Assert(!loadDirectiveMapBuilder.ContainsKey(oldTree));
                Debug.Assert(!loadDirectiveMapBuilder.ContainsKey(newTree));

                // If we're inserting new #load'ed trees, we'll rebuild
                // the whole syntaxTree array and the ordinalMap.
                var treesBuilder = ArrayBuilder<SyntaxTree>.GetInstance();
                var ordinalMapBuilder = PooledDictionary<SyntaxTree, int>.GetInstance();
                for (var i = 0; i <= (oldOrdinal - totalReferencedTreeCount); i++)
                {
                    var tree = syntaxTrees[i];
                    treesBuilder.Add(tree);
                    ordinalMapBuilder.Add(tree, i);
                }

                AppendAllSyntaxTrees(
                    treesBuilder,
                    newTree,
                    this.ScriptClassName,
                    this.Resolver,
                    this.MessageProvider,
                    this.IsSubmission,
                    ordinalMapBuilder,
                    loadDirectiveMapBuilder,
                    loadedSyntaxTreeMapBuilder,
                    declMapBuilder,
                    ref declTable);

                for (var i = oldOrdinal + 1; i < syntaxTrees.Length; i++)
                {
                    var tree = syntaxTrees[i];
                    if (!IsLoadedSyntaxTree(tree, loadedSyntaxTreeMap))
                    {
                        UpdateSyntaxTreesAndOrdinalMapOnly(
                            treesBuilder,
                            tree,
                            ordinalMapBuilder,
                            loadDirectiveMap,
                            loadedSyntaxTreeMap);
                    }
                }

                newTrees = treesBuilder.ToImmutableAndFree();
                ordinalMap = ordinalMapBuilder.ToImmutableDictionaryAndFree();
                Debug.Assert(newTrees.Length == ordinalMap.Count);
            }
            else
            {
                AddSyntaxTreeToDeclarationMapAndTable(newTree, this.ScriptClassName, this.IsSubmission, declMapBuilder, ref declTable);

                if (newLoadDirectivesSyntax.Any())
                {
                    // If load directives have not changed and there are new directives,
                    // then there should have been (matching) old directives as well.
                    Debug.Assert(!oldLoadDirectives.IsDefault);
//.........这里部分代码省略.........
开发者ID:robertoenbarcelona,项目名称:roslyn,代码行数:101,代码来源:SyntaxAndDeclarationManager.cs

示例4: AppendAllLoadedSyntaxTrees

        private static void AppendAllLoadedSyntaxTrees(
            ArrayBuilder<SyntaxTree> treesBuilder,
            SyntaxTree tree,
            string scriptClassName,
            SourceReferenceResolver resolver,
            CommonMessageProvider messageProvider,
            bool isSubmission,
            IDictionary<SyntaxTree, int> ordinalMapBuilder,
            IDictionary<SyntaxTree, ImmutableArray<LoadDirective>> loadDirectiveMapBuilder,
            IDictionary<string, SyntaxTree> loadedSyntaxTreeMapBuilder,
            IDictionary<SyntaxTree, Lazy<RootSingleNamespaceDeclaration>> declMapBuilder,
            ref DeclarationTable declTable)
        {
            ArrayBuilder<LoadDirective> loadDirectives = null;

            foreach (var directive in tree.GetCompilationUnitRoot().GetLoadDirectives())
            {
                var fileToken = directive.File;
                var path = (string)fileToken.Value;
                if (path == null)
                {
                    // If there is no path, the parser should have some Diagnostics to report (if we're in an active region).
                    Debug.Assert(!directive.IsActive || tree.GetDiagnostics().Any(d => d.Severity == DiagnosticSeverity.Error));
                    continue;
                }

                var diagnostics = DiagnosticBag.GetInstance();
                string resolvedFilePath = null;
                if (resolver == null)
                {
                    diagnostics.Add(
                        messageProvider.CreateDiagnostic(
                            (int)ErrorCode.ERR_SourceFileReferencesNotSupported,
                            directive.Location));
                }
                else
                {
                    resolvedFilePath = resolver.ResolveReference(path, baseFilePath: tree.FilePath);
                    if (resolvedFilePath == null)
                    {
                        diagnostics.Add(
                            messageProvider.CreateDiagnostic(
                                (int)ErrorCode.ERR_NoSourceFile,
                                fileToken.GetLocation(),
                                path,
                                CSharpResources.CouldNotFindFile));
                    }
                    else if (!loadedSyntaxTreeMapBuilder.ContainsKey(resolvedFilePath))
                    {
                        try
                        {
                            var code = resolver.ReadText(resolvedFilePath);
                            var loadedTree = SyntaxFactory.ParseSyntaxTree(
                                code,
                                tree.Options, // Use ParseOptions propagated from "external" tree.
                                resolvedFilePath);

                            // All #load'ed trees should have unique path information.
                            loadedSyntaxTreeMapBuilder.Add(loadedTree.FilePath, loadedTree);

                            AppendAllSyntaxTrees(
                                treesBuilder,
                                loadedTree,
                                scriptClassName,
                                resolver,
                                messageProvider,
                                isSubmission,
                                ordinalMapBuilder,
                                loadDirectiveMapBuilder,
                                loadedSyntaxTreeMapBuilder,
                                declMapBuilder,
                                ref declTable);
                        }
                        catch (Exception e)
                        {
                            diagnostics.Add(
                                CommonCompiler.ToFileReadDiagnostics(messageProvider, e, resolvedFilePath),
                                fileToken.GetLocation());
                        }
                    }
                    else
                    {
                        // The path resolved, but we've seen this file before,
                        // so don't attempt to load it again.
                        Debug.Assert(diagnostics.IsEmptyWithoutResolution);
                    }
                }

                if (loadDirectives == null)
                {
                    loadDirectives = ArrayBuilder<LoadDirective>.GetInstance();
                }
                loadDirectives.Add(new LoadDirective(resolvedFilePath, diagnostics.ToReadOnlyAndFree()));
            }

            if (loadDirectives != null)
            {
                loadDirectiveMapBuilder.Add(tree, loadDirectives.ToImmutableAndFree());
            }
        }
开发者ID:robertoenbarcelona,项目名称:roslyn,代码行数:100,代码来源:SyntaxAndDeclarationManager.cs

示例5: CompareIncToFullParseErrors

        private void CompareIncToFullParseErrors(SyntaxTree incrementalTree, SyntaxTree parsedTree)
        {
            var pd = parsedTree.GetDiagnostics();
            var id = incrementalTree.GetDiagnostics();
            Assert.Equal(pd.Count(), id.Count());
            for (int i = 0; i < id.Count(); i++)
            {
                Assert.Equal(pd.ElementAt(i).Stringize(), id.ElementAt(i).Stringize());
            }

            ParentChecker.CheckParents(parsedTree.GetCompilationUnitRoot(), parsedTree);
            ParentChecker.CheckParents(incrementalTree.GetCompilationUnitRoot(), incrementalTree);
        }
开发者ID:XieShuquan,项目名称:roslyn,代码行数:13,代码来源:IncrementalParsingTests.cs

示例6: GetExprSyntaxList

 private List<ExpressionSyntax> GetExprSyntaxList(SyntaxTree syntaxTree)
 {
     return GetExprSyntaxList(syntaxTree.GetCompilationUnitRoot(), null);
 }
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:4,代码来源:InteractiveSemanticModelTests.cs

示例7: GetSyntaxNodeList

 protected List<SyntaxNode> GetSyntaxNodeList(SyntaxTree syntaxTree)
 {
     return GetSyntaxNodeList(syntaxTree.GetCompilationUnitRoot(), null);
 }
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:4,代码来源:InteractiveSemanticModelTests.cs

示例8: VerifyIdenticalStructure

        private void VerifyIdenticalStructure(SyntaxTree syntaxTree)
        {
            var incrementalRoot = syntaxTree.GetCompilationUnitRoot();
            var parsedRoot = SyntaxFactory.ParseCompilationUnit(syntaxTree.GetText().ToString());

            AssertNodesAreEquivalent(parsedRoot, incrementalRoot);
        }
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:7,代码来源:GrammarAmbiguities.cs

示例9: GetGlobalExpressionNode

 private static ExpressionSyntax GetGlobalExpressionNode(SyntaxTree newTree)
 {
     var statementType = newTree.GetCompilationUnitRoot().Members[0] as GlobalStatementSyntax;
     var statement = statementType.Statement as ExpressionStatementSyntax;
     return statement.Expression;
 }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:6,代码来源:BinaryExpression.cs

示例10: GetExpressionNode

 private static ExpressionSyntax GetExpressionNode(SyntaxTree newTree)
 {
     TypeDeclarationSyntax classType = newTree.GetCompilationUnitRoot().Members[0] as TypeDeclarationSyntax;
     MethodDeclarationSyntax method = classType.Members[0] as MethodDeclarationSyntax;
     var block = method.Body;
     var statement = block.Statements[0] as ExpressionStatementSyntax;
     return statement.Expression;
 }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:8,代码来源:BinaryExpression.cs

示例11: CountedSyntaxTree

            public CountedSyntaxTree(SyntaxTree underlying)
            {
                Debug.Assert(underlying != null);
                Debug.Assert(underlying.HasCompilationUnitRoot);

                _underlyingTree = underlying;
                _root = CloneNodeAsRoot(_underlyingTree.GetCompilationUnitRoot(CancellationToken.None));
            }
开发者ID:RoryVL,项目名称:roslyn,代码行数:8,代码来源:DeclarationTests.cs

示例12: GetGlobalStatementSyntaxChange

 private static BinaryExpressionSyntax GetGlobalStatementSyntaxChange(SyntaxTree newTree)
 {
     var statementType = newTree.GetCompilationUnitRoot().Members[0] as GlobalStatementSyntax;
     var statement = statementType.Statement as ExpressionStatementSyntax;
     var expression = statement.Expression as BinaryExpressionSyntax;
     return expression;
 }
开发者ID:EkardNT,项目名称:Roslyn,代码行数:7,代码来源:CompoundAssignment.cs

示例13: CheckTree

 private void CheckTree(SyntaxTree tree)
 {
     Assert.Throws<InvalidCastException>(() => { var _ = (CSharpSyntaxTree) (Object) tree.GetCompilationUnitRoot(); });
     Assert.Throws<ArgumentNullException>(() => { tree.GetDiagnostics((CSharpSyntaxNode) null); });
     Assert.Throws<InvalidOperationException>(() => { tree.GetDiagnostics(default(SyntaxToken) ); });
     Assert.Throws<ArgumentNullException>(() => { tree.GetDiagnostics((SyntaxNode) null); });
     Assert.Throws<InvalidOperationException>(() => { tree.GetDiagnostics(default(SyntaxTrivia) ); });
 }
开发者ID:Rickinio,项目名称:roslyn,代码行数:8,代码来源:SyntaxTreeRootTests.cs

示例14: GetGlobalMethodDeclarationSyntaxChange

 private static ExpressionSyntax GetGlobalMethodDeclarationSyntaxChange(SyntaxTree newTree)
 {
     var method = newTree.GetCompilationUnitRoot().Members[0] as MethodDeclarationSyntax;
     return method.ReturnType;
 }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:5,代码来源:ChangingIdentifiers.cs

示例15: GetExpressionSyntaxChange

 private static ExpressionSyntax GetExpressionSyntaxChange(SyntaxTree newTree)
 {
     TypeDeclarationSyntax classType = newTree.GetCompilationUnitRoot().Members[0] as TypeDeclarationSyntax;
     MethodDeclarationSyntax method = classType.Members[0] as MethodDeclarationSyntax;
     var nameTree = method.ReturnType;
     return nameTree;
 }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:7,代码来源:ChangingIdentifiers.cs


注:本文中的SyntaxTree.GetCompilationUnitRoot方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。