Ejemplo n.º 1
0
        private static DeclaredElementInfo FindConstant([NotNull] ITreeNode node, [NotNull] IFile file)
        {
            var literalExpression = node.GetContainingNode <ILiteralExpression>(true);

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

            TreeTextRange literalRange = literalExpression.Literal.GetTreeTextRange();

            if (!literalRange.Intersects(node.GetTreeTextRange()))
            {
                return(null);
            }

            var declaredType = literalExpression.ConstantValue.Type as IDeclaredType;

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

            ITypeElement typeElement = declaredType.GetTypeElement();

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

            return(new DeclaredElementInfo(typeElement, declaredType.GetSubstitution(), file, file.GetDocumentRange(literalRange).TextRange, null));
        }
Ejemplo n.º 2
0
        private static DeclaredElementInfo FindDeclaration([NotNull] ITreeNode node, [NotNull] IFile file)
        {
            var declaration = node.GetContainingNode <IDeclaration>(true);

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

            TreeTextRange nameRange = declaration.GetNameRange();

            if (!nameRange.Intersects(node.GetTreeTextRange()))
            {
                return(null);
            }

            IDeclaredElement declaredElement = declaration.DeclaredElement;

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

            return(new DeclaredElementInfo(declaredElement, EmptySubstitution.INSTANCE, file, file.GetDocumentRange(nameRange).TextRange, null));
        }