Ejemplo n.º 1
0
        public bool IsAvailable(IUserDataHolder cache)
        {
            var methodName = this._myProvider.GetSelectedElement <ICSharpIdentifier>();

            var methodDeclaration = MethodDeclarationNavigator.GetByNameIdentifier(methodName);

            ICSharpParametersOwnerDeclaration paramsOwnerDeclaration = methodDeclaration;
            IFormalParameterList paramsList = methodDeclaration?.Params;

            //If unable to resolve by method declaration, try to resolve for ctor.
            if (paramsOwnerDeclaration == null)
            {
                var constructorDeclaration = ConstructorDeclarationNavigator.GetByTypeName(methodName);
                paramsOwnerDeclaration = constructorDeclaration;
                paramsList             = constructorDeclaration?.Params;
            }

            if (paramsOwnerDeclaration == null)
            {
                return(false);
            }
            if (paramsOwnerDeclaration.ParameterDeclarations.IsEmpty)
            {
                return(false);
            }

            this.ParametersOwnerDeclaration = paramsOwnerDeclaration;
            this.FormalParameterList        = paramsList;

            return(true);
        }
Ejemplo n.º 2
0
        private static IDeclaredElement FindDeclaredElement([NotNull] IPsiView psiView)
        {
            var referenceExpression = psiView.GetSelectedTreeNode <IReferenceExpression>();

            if (referenceExpression != null)
            {
                return(referenceExpression.Reference.Resolve().DeclaredElement);
            }

            var identifier = psiView.GetSelectedTreeNode <ICSharpIdentifier>();

            if (identifier != null)
            {
                var referenceName = ReferenceNameNavigator.GetByNameIdentifier(identifier);
                if (referenceName != null)
                {
                    return(referenceName.Reference.Resolve().DeclaredElement);
                }

                var declarationUnderCaret =
                    FieldDeclarationNavigator.GetByNameIdentifier(identifier) ??
                    PropertyDeclarationNavigator.GetByNameIdentifier(identifier) ??
                    MethodDeclarationNavigator.GetByNameIdentifier(identifier) ??
                    ConstructorDeclarationNavigator.GetByTypeName(identifier) ??
                    CSharpTypeDeclarationNavigator.GetByNameIdentifier(identifier) ??
                    EventDeclarationNavigator.GetByNameIdentifier(identifier) ??
                    ConstantDeclarationNavigator.GetByNameIdentifier(identifier) ??
                    VariableDeclarationNavigator.GetByNameIdentifier(identifier);

                return(declarationUnderCaret?.DeclaredElement);
            }

            var predefinedTypeUsage = psiView.GetSelectedTreeNode <IPredefinedTypeUsage>();

            return(predefinedTypeUsage?.ScalarPredefinedTypeName.Reference.Resolve().DeclaredElement);
        }