Esempio n. 1
0
        public bool IsAvailable(IUserDataHolder cache)
        {
            var identifier        = myDataProvider.GetSelectedElement <ITreeNode>() as ICSharpIdentifier;
            var methodDeclaration = MethodDeclarationNavigator.GetByNameIdentifier(identifier);

            return(AddDiscardAttributeUtil.IsAvailable(methodDeclaration));
        }
Esempio n. 2
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);
        }
        public IEnumerable <IntentionAction> CreateBulbItems()
        {
            var identifier        = myDataProvider.GetSelectedElement <ITreeNode>() as ICSharpIdentifier;
            var methodDeclaration = MethodDeclarationNavigator.GetByNameIdentifier(identifier);

            if (methodDeclaration == null)
            {
                return(EmptyList <IntentionAction> .Instance);
            }

            if (!UnityCallGraphUtil.IsSweaCompleted(mySwa))
            {
                return(EmptyList <IntentionAction> .Instance);
            }

            var processKind = UnityCallGraphUtil.GetProcessKindForGraph(mySwa);

            if (myExpensiveContextProvider.HasContext(methodDeclaration, processKind))
            {
                return(EmptyList <IntentionAction> .Instance);
            }

            var isPerformanceContext = myPerformanceContextProvider.HasContext(methodDeclaration, processKind);

            if (!isPerformanceContext)
            {
                return(EmptyList <IntentionAction> .Instance);
            }

            var bulbAction = new AddExpensiveCommentBulbAction(methodDeclaration);

            return(bulbAction.ToContextActionIntentions());
        }
        public static IMethodDeclaration GetMethodDeclarationByIdentifierOnBothSides([NotNull] ICSharpContextActionDataProvider dataProvider)
        {
            var result = MethodDeclarationByTreeNode(dataProvider.TokenAfterCaret);

            return(result ?? MethodDeclarationByTreeNode(dataProvider.TokenBeforeCaret));

            IMethodDeclaration MethodDeclarationByTreeNode(ITreeNode node)
            {
                var identifierAfter   = node as ICSharpIdentifier;
                var methodDeclaration = MethodDeclarationNavigator.GetByNameIdentifier(identifierAfter);

                return(methodDeclaration);
            }
        }
        public bool IsAvailable(IUserDataHolder cache)
        {
            var identifier        = myDataProvider.GetSelectedElement <ITreeNode>() as ICSharpIdentifier;
            var methodDeclaration = MethodDeclarationNavigator.GetByNameIdentifier(identifier);

            if (methodDeclaration == null)
            {
                return(false);
            }

            var declaredElement = methodDeclaration.DeclaredElement;

            return(declaredElement != null && methodDeclaration.IsValid() &&
                   !PerformanceCriticalCodeStageUtil.IsPerformanceCriticalRootMethod(methodDeclaration));
        }
        public override bool IsAvailable(IUserDataHolder cache)
        {
            var methodName        = this.Provider.GetSelectedElement <ICSharpIdentifier>();
            var methodDeclaration = MethodDeclarationNavigator.GetByNameIdentifier(methodName);

            var declaredMethod = methodDeclaration?.DeclaredElement;

            if (declaredMethod == null)
            {
                return(false);
            }

            var isAlreadyDeclared = this.FindPureAttribute(methodDeclaration) != null;

            return(this.ResolveIsAvailable(isAlreadyDeclared, declaredMethod));
        }
Esempio n. 7
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);
        }