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());
        }
Example #2
0
        protected override Action <ITextControl> ExecuteTransaction(ISolution solution, IProgressIndicator progress)
        {
            var invocation = _provider.GetSelectedElement <IInvocationExpression>(false, false);

            if (invocation == null || invocation.Reference == null)
            {
                return(null);
            }

            var referenceExpression = invocation.InvokedExpression as IReferenceExpression;

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

            var invocationExpression = invocation as IInvocationExpressionNode;

            if (invocationExpression == null)
            {
                return(null);
            }
            var textRange = new TextRange(referenceExpression.Reference.GetTreeTextRange().StartOffset.Offset,
                                          invocationExpression.RPar.GetTreeStartOffset().Offset + 1);
            var argumentsText = _provider.Document.GetText(textRange);

            _provider.Document.ReplaceText(textRange, MethodName + "(x => x." + argumentsText + ")");
            return(null);
        }
Example #3
0
        public SqlScriptIndexGeneratorContextAction(ICSharpContextActionDataProvider provider)
        {
            factory          = provider.ElementFactory;
            classDeclaration = provider.GetSelectedElement <IClassDeclaration>();

            propertyDeclaration = provider.GetSelectedElement <IPropertyDeclaration>();
        }
        public override bool IsAvailable(IUserDataHolder cache)
        {
            var testProjectProvider = ComponentResolver.GetComponent <ITestProjectProvider>(_dataProvider);

            _selectedElement      = _dataProvider.GetSelectedElement <IObjectCreationExpression>(false, false);
            _csharpMemberProvider = ComponentResolver.GetComponent <ICsharpMemberProvider>(_dataProvider);
            if (!(_selectedElement?.TypeReference?.Resolve().DeclaredElement is IClass c))
            {
                return(false);
            }

            var parameterCount = _selectedElement.ArgumentList?.Arguments.Count(x => x.Kind != ParameterKind.UNKNOWN);

            _constructor = c.Constructors.FirstOrDefault(x => !x.IsParameterless &&
                                                         x.Parameters.Count > parameterCount &&
                                                         x.Parameters.All(_csharpMemberProvider.IsAbstractOrInterface));
            if (_constructor == null)
            {
                return(false);
            }

            var isAvailable = testProjectProvider.IsTestProject(_dataProvider.PsiModule) && _selectedElement != null && _selectedElement.Arguments.Count == 0;

            if (isAvailable)
            {
                cache.PutKey(AnchorKey.FillWithMockContextActionKey);
            }

            return(isAvailable);
        }
        protected override Action <ITextControl> ExecutePsiTransaction(ISolution solution, IProgressIndicator progress)
        {
            var block      = myProvider.GetSelectedElement <IBlock>().NotNull();
            var statements = block.GetStatementsRange(myProvider.SelectedTreeRange).Statements;

            var invocation = ExtractInvocation(statements[0]).NotNull();

            for (int i = 1; i < statements.Count - 1; i++)
            {
                var nextInvocation = ExtractInvocation(statements[i]).NotNull();
                invocation = MergeInvocations(invocation, nextInvocation);
            }

            var lastDeclaredVariable = ExtractDeclaredVariableName(statements[statements.Count - 2]);
            var lastInvocationUse    =
                FindLastInvocationUse(statements[statements.Count - 1], lastDeclaredVariable.Name).NotNull();
            var lastInvocation = lastInvocationUse.GetContainingNode <IInvocationExpression>().NotNull();

            MergeInvocations(invocation, lastInvocation);

            for (int i = 0; i < statements.Count - 1; i++)
            {
                block.RemoveStatement((ICSharpStatement)statements[i]);
            }

            var lastStatementCoords = DocumentHelper.GetPositionAfterStatement(statements[statements.Count - 1], myProvider.Document);

            return(textControl =>
            {
                textControl.Selection.RemoveSelection(false);
                textControl.Caret.MoveTo(lastStatementCoords, CaretVisualPlacement.DontScrollIfVisible);
            });
        }
Example #6
0
        public override bool IsAvailable(IUserDataHolder cache)
        {
            var testProjectProvider = ComponentResolver.GetComponent <ITestProjectProvider>(_dataProvider);

            _parameterProvider = ComponentResolver.GetComponent <IParameterProvider>(_dataProvider);
            _selectedElement   = _dataProvider.GetSelectedElement <IObjectCreationExpression>(false, false);
            _block             = _dataProvider.GetSelectedElement <IBlock>();
            _classBody         = _dataProvider.GetSelectedElement <IClassBody>();
            _classDeclaration  = _classBody?.GetContainingTypeDeclaration() as IClassLikeDeclaration;

            if (_classDeclaration == null || _block == null || _selectedElement == null)
            {
                return(false);
            }

            if (!(_selectedElement.TypeReference?.Resolve().DeclaredElement is IClass c))
            {
                return(false);
            }

            _parameterNumber = _selectedElement.ArgumentList.Arguments.Count(x => x.Kind != ParameterKind.UNKNOWN);
            _constructor     = c.Constructors.ToArray().FirstOrDefault(x => !x.IsParameterless && x.Parameters.Count > _parameterNumber);
            if (_constructor == null)
            {
                return(false);
            }

            return(testProjectProvider.IsTestProject(_dataProvider.PsiModule));
        }
        public override bool IsAvailable(IUserDataHolder cache)
        {
            var propertyDeclaration = myDataProvider.GetSelectedElement <IPropertyDeclaration>();

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

            if (InterfaceDeclarationNavigator.GetByPropertyDeclaration(propertyDeclaration) != null)
            {
                return(false);
            }

            if (!CSharpAutoPropertyUtil.IsPropertyHeaderSelected(propertyDeclaration, myDataProvider.SelectedTreeRange))
            {
                return(false);
            }
            if (!CSharpAutoPropertyUtil.IsEmptyOrNotImplemented(propertyDeclaration))
            {
                return(false);
            }

            return(IsAvailable(propertyDeclaration));
        }
 public LogIntroducerContextAction(ICSharpContextActionDataProvider provider)
 {
     factory           = provider.ElementFactory;
     classDeclaration  = provider.GetSelectedElement <IClassDeclaration>();
     literalExpression = provider.GetSelectedElement <ICSharpLiteralExpression>();
     file = classDeclaration?.GetContainingFile() as ICSharpFile;
 }
Example #9
0
        protected override Action <ITextControl> ExecutePsiTransaction(ISolution solution, IProgressIndicator progress)
        {
            var block           = _dataProvider.GetSelectedElement <IBlock>();
            var selectedElement = _dataProvider.GetSelectedElement <IObjectCreationExpression>(false, false);

            if (!(selectedElement.TypeReference.Resolve()?.DeclaredElement is IClass c))
            {
                return(null);
            }

            var constructor = c.Constructors.OrderByDescending(x => x.Parameters.Count).FirstOrDefault(x => !x.IsParameterless);

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

            var parameters = _csharpMemberProvider.GetConstructorParameters(constructor.ToString()).ToArray();

            for (int i = 0; i < constructor.Parameters.Count; i++)
            {
                var shortName = constructor.Parameters[i].ShortName;
                var localVariableStatement = _dataProvider.ElementFactory.CreateStatement("var $0 = new Mock<$1>();", (object)shortName, (object)parameters[i]);

                block.AddStatementBefore(localVariableStatement, selectedElement.GetContainingStatement());
                var argument = _dataProvider.ElementFactory.CreateArgument(ParameterKind.VALUE, _dataProvider.ElementFactory.CreateExpression($"{shortName}.Object"));
                selectedElement.AddArgumentBefore(argument, null);
            }
            return(null);
        }
Example #10
0
        public override bool IsAvailable(IUserDataHolder cache)
        {
            var testProjectProvider = ComponentResolver.GetComponent <ITestProjectProvider>(_dataProvider);

            _selectedElement   = _dataProvider.GetSelectedElement <IObjectCreationExpression>(false, false);
            _parameterProvider = ComponentResolver.GetComponent <IParameterProvider>(_dataProvider);

            return(testProjectProvider.IsTestProject(_dataProvider.PsiModule) && _selectedElement != null && _selectedElement.Arguments.Count == 0);
        }
Example #11
0
        protected override Action <ITextControl> ExecuteTransaction(ISolution solution, IProgressIndicator progress)
        {
            var item = _provider.GetSelectedElement <ICSharpArgument>(false, false);

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

            var owner = item.GetContainingElement <ICSharpArgumentsOwner>(false);

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

            var type = item.GetExpressionType();

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

            var typeName = type.GetLongPresentableName(owner.Language);

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

            var expressionText = item.GetText();

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

            var factory       = JetBrains.ReSharper.Psi.CSharp.CSharpElementFactory.GetInstance(owner.PsiModule);
            var newExpression = factory.CreateExpressionAsIs(string.Format("Arg<{0}>.Is.Equal({1})", typeName, expressionText));

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

            var newArgument = factory.CreateArgument(JetBrains.ReSharper.Psi.ParameterKind.VALUE, newExpression);

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

            item.ReplaceBy(newArgument);

            return(null);
        }
Example #12
0
        public override bool IsAvailable(IUserDataHolder cache)
        {
            if (!myDataProvider.Project.IsUnityProject())
            {
                return(false);
            }

            var fieldDeclaration = myDataProvider.GetSelectedElement <IFieldDeclaration>();

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

            // We can only apply the attribute to non-static, non-public fields
            // (private, protected, internal)
            if (fieldDeclaration.IsStatic || fieldDeclaration.GetAccessRights() == AccessRights.PUBLIC)
            {
                return(false);
            }

            foreach (var attribute in fieldDeclaration.Attributes)
            {
                if (attribute.TypeReference?.Resolve().DeclaredElement is ITypeElement element)
                {
                    var attributName = element.GetClrName();
                    if (Equals(attributName, KnownTypes.SerializeField))
                    {
                        return(false);
                    }

                    // TODO: Perhaps we should remove the NonSerialized attribute instead?
                    // Add a CA to convert to serialized field?
                    if (Equals(attributName, PredefinedType.NONSERIALIZED_ATTRIBUTE_CLASS))
                    {
                        return(false);
                    }
                }
            }

            var typeDeclaration = fieldDeclaration.GetContainingTypeDeclaration();
            var typeElement     = typeDeclaration?.DeclaredElement;

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

            // Is the type a Unity type?
            var unityApi = myDataProvider.Solution.GetComponent <UnityApi>();

            return(unityApi.IsUnityType(typeElement));
        }
        private static FieldOrPropertyDeclaration? TryCreateFieldOrProperty(ICSharpContextActionDataProvider provider)
        {
            var fieldDeclaration = provider.GetSelectedElement<IFieldDeclaration>(true, true);
            if (fieldDeclaration != null && IsFieldDeclarationValid(fieldDeclaration))
                return FieldOrPropertyDeclaration.FromFieldDeclaration(fieldDeclaration);

            var propertyDeclaration = provider.GetSelectedElement<IPropertyDeclaration>(true, true);
            if (propertyDeclaration != null && IsPropertyDeclarationValid(propertyDeclaration))
                return FieldOrPropertyDeclaration.FromPropertyDeclaration(propertyDeclaration);

            return null;
        }
        protected override Action <ITextControl> ExecutePsiTransaction(ISolution solution, IProgressIndicator progress)
        {
            if (_provider != null)
            {
                var method = _provider.GetSelectedElement <IMethodDeclaration>(false, true);

                if (method != null)
                {
                    method.SetStatic(true);
                }
            }

            return(null);
        }
        public bool IsAvailable(IUserDataHolder cache)
        {
            var item = _provider.GetSelectedElement <IMethodDeclaration>(false, true);

            if (item != null)
            {
                var accessRights = item.GetAccessRights();

                if (accessRights == AccessRights.PUBLIC && !item.IsStatic && !item.IsVirtual && !item.IsOverride)
                {
                    return(true);
                }
            }
            return(false);
        }
Example #16
0
 protected JsonPropertyContextActionBase([NotNull] ICSharpContextActionDataProvider provider, [CanBeNull] Func <string, string> propertyNameTransform = null)
 {
     this.provider              = provider;
     factory                    = provider.ElementFactory;
     classDeclaration           = provider.GetSelectedElement <IClassDeclaration>();
     this.propertyNameTransform = propertyNameTransform ?? (x => x);
 }
        public override bool IsAvailable(IUserDataHolder cache)
        {
            var literal = _provider.GetSelectedElement <ILiteralExpression>(true, true);

            //var processor = new YC.ReSharper.AbstractAnalysis.Plugin.Core.Processor(_provider);
            //var parserRes = processor.Process();
            //parserRes.
            ////var style = new TextStyle(FontStyle.Italic, Color.Aqua, Color.Bisque);
            ////var t =  CSharpHighlightingConsumerExtension.AddHighlighting()
            ////t.
            ////ITextControl
            ////var t = _provider.Document. // TextControl;
            ////t.Document.
            ////var h = new TextControlMarkup.HighlighterProcessor();
            ////var gg = HighlighterLayer.
            ////var tt = highli
            ////ITextControl.
            //Console.WriteLine(parserRes);
            if (literal != null && literal.IsConstantValue() && literal.ConstantValue.IsString())
            {
                var s = literal.ConstantValue.Value as string;
                if (!string.IsNullOrEmpty(s))
                {
                    _stringLiteral = literal;
                    return(true);
                }
            }
            return(false);
        }
        public bool IsAvailable(IUserDataHolder cache)
        {
            var typeDeclaration = _provider.GetSelectedElement <ICSharpTypeDeclaration>(true, true);

            if (typeDeclaration == null || !typeDeclaration.IsValid())
            {
                return(false);
            }

            var element = typeDeclaration.DeclaredElement;

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

            if (typeDeclaration.GetContainingTypeDeclaration() != null)
            {
                return(false);
            }
            if (!typeDeclaration.GetNameRange().Contains(_provider.CaretOffset))
            {
                return(false);
            }

            _currentProject = typeDeclaration.GetProject();

            if (RenameFileToMatchTypeNameAction.CountTopLevelTypeDeclarations(_provider.PsiFile as ICSharpFile) <= 1)
            {
                return(false);
            }
            return(RenameFileToMatchTypeNameAction.TypeNameNameDoesNotCorrespondWithFileName(element, _provider.ProjectFile));
        }
        protected override Action <ITextControl> ExecutePsiTransaction(ISolution solution, IProgressIndicator progress)
        {
            var fieldDeclaration = myDataProvider.GetSelectedElement <IFieldDeclaration>();

            if (fieldDeclaration != null)
            {
                var typeElement = TypeFactory.CreateTypeByCLRName(KnownTypes.SerializeField, myDataProvider.PsiModule).GetTypeElement();
                if (typeElement == null)
                {
                    return(null);
                }
                var attribute = myDataProvider.ElementFactory.CreateAttribute(typeElement);
                fieldDeclaration.AddAttributeAfter(attribute, null);
            }

            return(null);
        }
Example #20
0
        protected override Action <ITextControl> ExecutePsiTransaction(ISolution solution, IProgressIndicator progress)
        {
            var fieldDeclaration = myDataProvider.GetSelectedElement <IFieldDeclaration>();

            if (fieldDeclaration != null)
            {
                var typeElement = TypeFactory.CreateTypeByCLRName(PredefinedType.NONSERIALIZED_ATTRIBUTE_CLASS, myDataProvider.PsiModule).GetTypeElement();
                if (typeElement == null)
                {
                    return(null);
                }
                var attribute = myDataProvider.ElementFactory.CreateAttribute(typeElement);
                fieldDeclaration.AddAttributeAfter(attribute, null);
            }

            return(null);
        }
Example #21
0
        private static FieldOrPropertyDeclaration?TryCreateFieldOrProperty(ICSharpContextActionDataProvider provider)
        {
            var fieldDeclaration = provider.GetSelectedElement <IFieldDeclaration>(true, true);

            if (fieldDeclaration != null && IsFieldDeclarationValid(fieldDeclaration))
            {
                return(FieldOrPropertyDeclaration.FromFieldDeclaration(fieldDeclaration));
            }

            var propertyDeclaration = provider.GetSelectedElement <IPropertyDeclaration>(true, true);

            if (propertyDeclaration != null && IsPropertyDeclarationValid(propertyDeclaration))
            {
                return(FieldOrPropertyDeclaration.FromPropertyDeclaration(propertyDeclaration));
            }

            return(null);
        }
Example #22
0
        public static IParameterDeclaration GetSelectedParameterDeclaration(
            this ICSharpContextActionDataProvider provider)
        {
            Contract.Requires(provider != null);

            // If the carret is on the parameter _parameterDeclaration,
            // GetSelectedElement will return not-null value
            var parameterDeclaration = provider.GetSelectedElement <IParameterDeclaration>(true, true);

            if (parameterDeclaration != null)
            {
                return(parameterDeclaration);
            }

            // But parameter could be selected inside method body
            var selectedDeclaration = provider.GetSelectedElement <IReferenceExpression>(true, true)
                                      .With(x => x.Reference)
                                      .With(x => x.Resolve())
                                      .With(x => x.DeclaredElement)
                                      .With(x => x.GetDeclarations().FirstOrDefault())
                                      .Return(x => x as IParameterDeclaration);

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

            var currentFunction =
                provider.GetSelectedElement <IFunctionDeclaration>(true, true);

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

            bool isArgument =
                currentFunction.DeclaredElement.Parameters
                .SelectMany(pm => pm.GetDeclarations())
                .Select(pm => pm as IParameterDeclaration)
                .Where(pm => pm != null)
                .Contains(selectedDeclaration);

            return(isArgument ? selectedDeclaration : null);
        }
        protected override Action <ITextControl> ExecutePsiTransaction(ISolution solution, IProgressIndicator progress)
        {
            var csharpMemberProvider = ComponentResolver.GetComponent <ICsharpMemberProvider>(_dataProvider);
            var selectedElement      = _dataProvider.GetSelectedElement <IObjectCreationExpression>(false, false);
            var argumentList         = selectedElement.ArgumentList;
            var @class                 = (IClass)selectedElement.TypeReference?.Resolve().DeclaredElement;
            var parameterCount         = selectedElement.ArgumentList?.Arguments.Count(x => x.Kind != ParameterKind.UNKNOWN);
            var constructor            = @class.Constructors.ToArray().FirstOrDefault(x => !x.IsParameterless && x.Parameters.Count > parameterCount);
            var parameters             = csharpMemberProvider.GetConstructorParameters(constructor.ToString()).ToArray();
            var parameterNumber        = csharpMemberProvider.GetCurrentParameterNumber(selectedElement, _dataProvider);
            var shortName              = constructor.Parameters[parameterNumber].ShortName;
            var currentParam           = parameters[parameterNumber];
            var block                  = _dataProvider.GetSelectedElement <IBlock>();
            var localVariableStatement = _dataProvider.ElementFactory.CreateStatement("var $0 = new Mock<$1>();", (object)shortName, currentParam);

            block.AddStatementBefore(localVariableStatement, selectedElement.GetContainingStatement());

            return(csharpMemberProvider.FillCurrentParameterWithMock(shortName, argumentList, selectedElement, parameterNumber, _dataProvider));
        }
Example #24
0
        public override bool IsAvailable(IUserDataHolder cache)
        {
            if (!myDataProvider.Project.IsUnityProject())
            {
                return(false);
            }

            var fieldDeclaration = myDataProvider.GetSelectedElement <IFieldDeclaration>();

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

            var unityApi = myDataProvider.Solution.GetComponent <UnityApi>();

            var field = fieldDeclaration.DeclaredElement;

            return(field != null && unityApi.IsUnityField(field));
        }
        private InvariantAvailability(ICSharpContextActionDataProvider provider,
            FieldOrPropertyDeclaration selectedElement)
        {
            Contract.Requires(provider != null);
            
            _classDeclaration = provider.GetSelectedElement<IClassLikeDeclaration>(true, true);
            _selectedElement = selectedElement;

            IsAvailable = AnalyzeAvailability();
            if (IsAvailable)
                SelectedMemberName = _selectedElement.Name;
        }
        [Pure] private bool IsPropertyWithGetterSelected()
        {
            // Ensures is available for indexer, but should not be available for selected setters
            var indexedPropertyDeclaration = _provider.GetSelectedElement <IIndexerDeclaration>(true, true);

            if (indexedPropertyDeclaration != null)
            {
                var selectedAccessor = _provider.GetSelectedElement <IAccessorDeclaration>(true, true);

                var getter = indexedPropertyDeclaration.AccessorDeclarations.FirstOrDefault(a => a.Kind == AccessorKind.GETTER);
                if (getter != null)
                {
                    if (selectedAccessor == null || selectedAccessor == getter)
                    {
                        return(true);
                    }
                }
            }

            var propertyDeclaration = _provider.GetSelectedElement <IPropertyDeclaration>(true, true);

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

            if (propertyDeclaration.IsAuto)
            {
                return(false);
            }

            return(propertyDeclaration.AccessorDeclarations.Any(a => a.Kind == AccessorKind.GETTER));
        }
Example #27
0
        private InvariantAvailability(ICSharpContextActionDataProvider provider,
                                      FieldOrPropertyDeclaration selectedElement)
        {
            Contract.Requires(provider != null);

            _classDeclaration = provider.GetSelectedElement <IClassLikeDeclaration>(true, true);
            _selectedElement  = selectedElement;

            IsAvailable = AnalyzeAvailability();
            if (IsAvailable)
            {
                SelectedMemberName = _selectedElement.Name;
            }
        }
Example #28
0
        public override bool IsAvailable(IUserDataHolder cache)
        {
            var commandType = _provider.GetSelectedElement <IDeclaration>(true, true);

            if (commandType != null && commandType.IsValid())
            {
                if (!string.IsNullOrEmpty(commandType.DeclaredName) && commandType.DeclaredName.EndsWith("Command"))
                {
                    _commandType = commandType;
                    return(true);
                }
            }
            return(false);
        }
        public override bool IsAvailable(IUserDataHolder cache)
        {
            var literal = _provider.GetSelectedElement <ILiteralExpression>(true, true);

            if (literal != null && literal.IsConstantValue() && literal.ConstantValue.IsString())
            {
                var s = literal.ConstantValue.Value as string;
                if (!string.IsNullOrEmpty(s))
                {
                    _stringLiteral = literal;
                    return(true);
                }
            }
            return(false);
        }
        private bool IsAbstractClassOrInterface()
        {
            if (_provider.IsSelected <IInterfaceDeclaration>())
            {
                return(true);
            }

            var classDeclaration = _provider.GetSelectedElement <IClassDeclaration>(true, true);

            if (classDeclaration == null)
            {
                return(false); // disabling if outside the class declaration
            }
            return(classDeclaration.IsAbstract);
        }
Example #31
0
        public InvariantActionExecutor(InvariantAvailability invariantAvailability,
                                       ICSharpContextActionDataProvider provider)
            : base(provider)
        {
            Contract.Requires(invariantAvailability != null);
            Contract.Requires(provider != null);
            Contract.Requires(invariantAvailability.IsAvailable);

            _invariantAvailability = invariantAvailability;
            _provider = provider;
            // TODO: look at this class CSharpStatementNavigator

            _classDeclaration = provider.GetSelectedElement <IClassLikeDeclaration>(true, true);

            Contract.Assert(provider.SelectedElement != null);
        }
        public InvariantActionExecutor(InvariantAvailability invariantAvailability,
            ICSharpContextActionDataProvider provider)
            : base(provider)
        {
            Contract.Requires(invariantAvailability != null);
            Contract.Requires(provider != null);
            Contract.Requires(invariantAvailability.IsAvailable);

            _invariantAvailability = invariantAvailability;
            _provider = provider;
            // TODO: look at this class CSharpStatementNavigator

            _classDeclaration = provider.GetSelectedElement<IClassLikeDeclaration>(true, true);
            
            Contract.Assert(provider.SelectedElement != null);
        }
        private void ComputeSelectedDeclarationMember()
        {
            InterfaceDeclaration = _provider.GetSelectedElement <IInterfaceDeclaration>(true, true);

            if (InterfaceDeclaration == null)
            {
                ClassDeclaration = _provider.GetSelectedElement <IClassDeclaration>(true, true);
            }

            SelectedDeclarationTypeName = GetSelectedTypeName();
        }
        public AddContractForExecutor(AddContractForAvailability addContractForAvailability,
            ICSharpContextActionDataProvider provider)
        {
            Contract.Requires(addContractForAvailability != null);
            Contract.Requires(addContractForAvailability.IsAvailable);
            Contract.Requires(provider != null);

            _addContractForAvailability = addContractForAvailability;
            _provider = provider;

            _factory = CSharpElementFactory.GetInstance(provider.PsiModule);
            // TODO: look at this class CSharpStatementNavigator

            _classDeclaration = provider.GetSelectedElement<IClassLikeDeclaration>(true, true);

            Contract.Assert(provider.SelectedElement != null);
            _currentFile = (ICSharpFile)provider.SelectedElement.GetContainingFile();

        }