Exemple #1
0
        public static IEnumerable <IDeclaration> GetDeclarationsFromRoot(this ITreeNode from)
        {
            if (from is PascalBlock)
            {
                return(from.Children().Where(it => it is PascalVariableDeclarationPart).TryGetSingleItem()?.GetDeclarationsInDescendants() ?? Enumerable.Empty <IDeclaration>());
            }

            if (from is PascalProcedureDeclaration || from is PascalFunctionDeclaration)
            {
                return(from.Children().Where(it => it is PascalFormalParameterList).TryGetSingleItem()?.GetDeclarationsInDescendants() ?? Enumerable.Empty <IDeclaration>());
            }

            return(Enumerable.Empty <IDeclaration>());
        }
        private IEnumerable <IReference> GetReferencesImpl(ITreeNode element)
        {
            if (!(element is INitraAst))
            {
                yield break;
            }

            var reference = element as IReference;

            if (reference != null)
            {
                yield return(reference);
            }

            if (element is ITokenNode)
            {
                yield break;
            }

            foreach (var n in element.Children())
            {
                if (ReferenceEquals(n, element))
                {
                    continue;
                }

                foreach (var reference1 in GetReferencesImpl(n))
                {
                    yield return(reference1);
                }
            }
        }
 public IEnumerable <ClassificationTemplate> AvailableObservedDataCategoriesIn(ITreeNode <IClassification> parentClassificationNode)
 {
     return(parentClassificationNode.Children <ObservedDataNode>().SelectMany(node => node.Tag.Repository.ExtendedProperties)
            .Select(property => property.Name)
            .Distinct()
            .Select(property => new ClassificationTemplate(property)));
 }
Exemple #4
0
        private static void Traverse(ITreeNode node, StringBuilder sb, int depth, CompletionTargetMarker marker)
        {
            if (node.IsWhitespaceToken())
            {
                return;
            }

            sb.Indent(depth);
            sb.ObjectId(node, marker);
            sb.AppendLine();

            foreach (var child in node.Children())
            {
                if (Visited.Contains(child))
                {
                    sb.Indent(depth);
                    sb.Append("--> ");
                    sb.ObjectId(node, marker);
                    sb.AppendLine();
                }
                else
                {
                    Visited.Add(child);
                    Traverse(child, sb, depth + 1, marker);
                }
            }
        }
 public override void VisitNode(ITreeNode node, ISet <MethodRef> context)
 {
     foreach (var childNode in node.Children <ICSharpTreeNode>())
     {
         childNode.Accept(this, context);
     }
 }
 private static void ProcessCSharpChildren([NotNull] ITreeNode node, [NotNull] CodeStructureElement parentElement,
                                           [NotNull] CSharpCodeStructureProcessingState state)
 {
     foreach (ITreeNode childNode in node.Children())
     {
         ProcessCSharpNode(childNode, parentElement, state);
     }
 }
        static IEnumerable <ICSharpTreeNode> GetAllChildrenRecursive([NotNull] ITreeNode node)
        {
            foreach (var childNode in node.Children <ICSharpTreeNode>())
            {
                yield return(childNode);

                foreach (var n in GetAllChildrenRecursive(childNode))
                {
                    yield return(n);
                }
            }
        }
        public static IReferenceExpression TryGetFirstReferenceExpression(ITreeNode currentNode)
        {
            var childNodes     = currentNode.Children();
            var firstChildNode = childNodes.FirstOrDefault();

            if (firstChildNode == null)
            {
                return(null);
            }

            return(firstChildNode as IReferenceExpression ??
                   TryGetFirstReferenceExpression(firstChildNode));
        }
 public override void VisitNode(ITreeNode node, IList <IStatement> context)
 {
     node.Children <ICSharpTreeNode>().ForEach(
         child =>
     {
         try
         {
             child.Accept(this, context);
         }
         catch (NullReferenceException) { }
         catch (AssertException) { }
     });
 }
        public static int CountChildren <T>(this ITreeNode node) where T : ITreeNode
        {
            var treeNodes = node.Children().ToList();

            var childOfType = treeNodes.OfType <T>();
            var count       = childOfType.Count();

            foreach (var childNodes in treeNodes)
            {
                count += CountChildren <T>(childNodes);
            }
            return(count);
        }
Exemple #11
0
        private void HighlightMethodChainsThatAreTooLong(ITreeNode statement, IHighlightingConsumer consumer, int threshold)
        {
            var children = statement.Children();

            foreach (var treeNode in children)
            {
                if (treeNode is IReferenceExpression referenceExpression)
                {
                    HighlightReferenceExpressionIfNeeded(referenceExpression, consumer, threshold);
                }
                else
                {
                    HighlightMethodChainsThatAreTooLong(treeNode, consumer, threshold);
                }
            }
        }
        public static List <IDeclaration> GetSiblingDecls(ITreeNode element)
        {
            var res = new List <IDeclaration>();

            if (element is HaskellTopdecl || element is HaskellDecl || element is HaskellFunlhs || element is HaskellApat)
            {
                res = element.Children().SelectMany(x => GetSiblingDecls(x)).ToList();
            }

            if (element is IDeclaration d)
            {
                res.Add(d);
            }

            return(res);
        }
        private static IEnumerable<IStructuralMatchResult> FindMatches(IStructuralMatcher matcher, ITreeNode statement)
        {
            if (statement == null || !statement.IsValid())
                yield break;

            var result = matcher.Match(statement);
            if (result.Matched)
            {
                yield return result;
                yield break;
            }
            foreach (var r in statement.Children().SelectMany(node => FindMatches(matcher, node)))
            {
                yield return r;
            }
        }
 public static IEnumerable <ITreeNode> GetEnvDTEModelChildren([NotNull] this ITreeNode node)
 {
     foreach (var directChild in node.Children())
     {
         if (PsiElementRegistrar.ShouldAddToModel(directChild))
         {
             yield return(directChild);
         }
         else if (PsiElementRegistrar.ShouldVisitChildren(directChild))
         {
             foreach (var modelChild in GetEnvDTEModelChildren(directChild))
             {
                 yield return(modelChild);
             }
         }
     }
 }
        public static int GetChildrenDepth(this ITreeNode node)
        {
            var childrenDepth = 0;
            var children      = node.Children();

            foreach (var block in children)
            {
                var levelOfCurrentBlock = GetChildrenDepth(block);
                childrenDepth = Math.Max(levelOfCurrentBlock, childrenDepth);
            }

            if (IsNodeThatIncreasesDepth(node))
            {
                return(childrenDepth + 1);
            }
            return(childrenDepth);
        }
        static IEnumerable <ICSharpTreeNode> GetAllChildrenRecursive([NotNull] ITreeNode node)
        {
            foreach (var childNode in node.Children <ICSharpTreeNode>())
            {
                if (childNode is ILocalFunctionDeclaration || childNode is IAnonymousFunctionExpression)
                {
                    continue; // skip the element (do not drill down)
                }

                yield return(childNode);

                foreach (var n in GetAllChildrenRecursive(childNode))
                {
                    yield return(n);
                }
            }
        }
Exemple #17
0
        public static IEnumerable <T> GetChildrenRecursive <T>(this ITreeNode node) where T : ITreeNode
        {
            var nodeChildren = node.Children().ToList();

            var list = new List <T>();

            var childOfType = nodeChildren.OfType <T>();

            list.AddRange(childOfType);

            foreach (var childNode in nodeChildren)
            {
                var childrenOfType = GetChildrenRecursive <T>(childNode);
                list.AddRange(childrenOfType);
            }

            return(list);
        }
        private static IEnumerable <IStructuralMatchResult> FindMatches(IStructuralMatcher matcher, ITreeNode statement)
        {
            if (statement == null || !statement.IsValid())
            {
                yield break;
            }
            var result = matcher.Match(statement);

            if (result.Matched)
            {
                yield return(result);

                yield break;
            }
            foreach (var r in statement.Children().SelectMany(node => FindMatches(matcher, node)))
            {
                yield return(r);
            }
        }
Exemple #19
0
        private IEnumerable<IReference> GetReferencesImpl(ITreeNode element)
        {
            if (!(element is INitraAst))
            yield break;

              var reference = element as IReference;

              if (reference != null)
            yield return reference;

              if (element is ITokenNode)
            yield break;

              foreach (var n in element.Children())
              {
            if (ReferenceEquals(n, element))
              continue;

            foreach (var reference1 in GetReferencesImpl(n))
              yield return reference1;
              }
        }
Exemple #20
0
        private static void AddScope(ITreeNode node, Scope parentScope)
        {
            var scope = parentScope;

            if (node is SpringDefine define)
            {
                define.ParentScope = parentScope;
            }
            else if (node is SpringLambda lambda)
            {
                lambda.Scope = new Scope(parentScope);
                scope        = lambda.Scope;
            }
            else if (node is SpringLet let)
            {
                let.Scope = new Scope(parentScope);
                scope     = let.Scope;
            }
            else if (node is SpringIdent ident)
            {
                ident.ParentScope = scope;
            }
            else if (node is SpringIdentDecl decl)
            {
                scope.Add(decl.DeclaredElement);
            }
            else if (node is SpringBindingExpr)
            {
                // Let node passes to Bind (<ident> <expr>)
                // newly created scope, but <expr> have to have
                // it's parent scope.
                scope = scope.ParentScope;
            }

            foreach (var child in node.Children())
            {
                AddScope(child, scope);
            }
        }
Exemple #21
0
        public IDictionary <int, IList <ITreeNode> > Visit(ITreeNode treeRootNode, IDictionary <int, IList <ITreeNode> > mapTree)
        {
            CheckVisitParameters(treeRootNode, mapTree);

            IList <ITreeNode> listNodes = null;

            if (mapTree.TryGetValue(treeRootNode.Level(), out listNodes))
            {
                listNodes.Add(treeRootNode);
            }
            else
            {
                listNodes = new List <ITreeNode>();
                listNodes.Add(treeRootNode);
                mapTree.Add(treeRootNode.Level(), listNodes);
            }

            foreach (var treeNode in treeRootNode.Children())
            {
                mapTree = Visit(treeNode, mapTree);
            }

            return(mapTree);
        }
 public virtual void RemoveChildrenClassifications(ITreeNode <IClassification> parentClassificationNode)
 {
     parentClassificationNode.Children <ITreeNode <IClassification> >().Each(c => removeClassification(c, recursive: true));
 }
Exemple #23
0
 public override void VisitNode(ITreeNode node, SST context)
 {
     _cancellationToken.ThrowIfCancellationRequested();
     node.Children <ICSharpTreeNode>().ForEach(child => child.Accept(this, context));
 }
Exemple #24
0
 public static IReadOnlyList <ITreeNode <T> > NodesWithTags <T>(this ITreeNode treeNode)
 {
     return(treeNode.Children <ITreeNode <T> >());
 }
 private ITreeNode simulationConfigurationNodeUnder(ITreeNode simulationNode)
 {
     return(simulationNode.Children <BuildConfigurationNode>().First());
 }
Exemple #26
0
        public override void VisitNode(ITreeNode node, IHighlightingConsumer consumer)
        {
            var sourceFile = node.GetSourceFile();

            if (sourceFile == null)
            {
                return;
            }

            if (!myInternalMode && myProcessKind != DaemonProcessKind.VISIBLE_DOCUMENT)
            {
                return;
            }

            if (myProcessKind == DaemonProcessKind.VISIBLE_DOCUMENT)
            {
                // TODO: Highlight identifiers
                // if (myIdentifierHighlightingEnabled)

                var info = myVisualElementHighlighter.CreateColorHighlightingInfo(node);
                if (info != null)
                {
                    consumer.AddHighlighting(info.Highlighting, info.Range);
                }
            }


            var references = node.GetReferences(myReferenceProvider);

            myResolveProblemHighlighter.CheckForResolveProblems(node, consumer, references);

            // TODO: Move to ShaderLabSyntaxHighlightingStage
            // (Not Rider's syntax highlighting though!)
            // E.g. protobuf support has a SyntaxHighlightingStage that will do this,
            // plus look for simple syntax validation errors, e.g. enums must have at
            // least one value defined, correct value for `syntax "proto3"`, etc.
            // And then a separate identifier
            if (!sourceFile.PsiModule.IsMiscFilesProjectModule() && node is IErrorElement errorElement)
            {
                DocumentRange range;
                if (node.Children().Any(t => t.Children <ICgContent>().Any()))
                {
                    range = node.MeaningfulChildren().FirstOrDefault()?.GetDocumentRange() ?? DocumentRange.InvalidRange;
                }
                else
                {
                    range = errorElement.GetDocumentRange();
                }

                if (!range.IsValid())
                {
                    range = node.Parent.GetDocumentRange();
                }
                if (range.TextRange.IsEmpty)
                {
                    if (range.TextRange.EndOffset < range.Document.GetTextLength())
                    {
                        range = range.ExtendRight(1);
                    }
                    else if (range.TextRange.StartOffset > 0)
                    {
                        range = range.ExtendLeft(1);
                    }
                }
                consumer.AddHighlighting(new ShaderLabSyntaxError(errorElement.ErrorDescription, range));
            }

            base.VisitNode(node, consumer);
        }