/// <summary>
		/// TODO Add summary
		/// </summary>
		private void moveTypesToFilesRefactoring_CheckAvailability(object sender, CheckContentAvailabilityEventArgs ea)
		{
			RefactoringProviderBase moveRefactoring = CodeRush.Refactoring.Get("Move Type to File");
			RefactoringProviderBase renameRefactoring = CodeRush.Refactoring.Get("Rename File to Match Type");
			ea.Available = moveRefactoring != null && renameRefactoring != null && 
				(ea.CodeActive.ElementType == LanguageElementType.Namespace || ea.CodeActive.ElementType == LanguageElementType.Class);
		}
Esempio n. 2
0
        public void ReplaceWith_CheckAvailability(Object sender, CheckContentAvailabilityEventArgs ea)
        {
            var SelectedText = CodeRush.Selection.Text;

            var Applicable = from replacement in mReplacements
                             where replacement.Replace == SelectedText
                             select replacement;
            switch (Applicable.Count())
            {
                case 0:
                    ea.Available = false;
                    break;
                //case 1:
                //
                //    ea.Available = true;
                //    break;
                default:
                    foreach (Replacement replacement in Applicable)
                    {
                        ea.AddSubMenuItem(new ReplaceMenu(replacement.Caption, replacement));
                    }
                    ea.Available = true;
                    break;
            }

            ea.Available = Applicable.Count() > 0; // Change this to return true, only when your Code should be available.
        }
 protected void AddProjectsToSubmenu(CheckContentAvailabilityEventArgs ea, string typeToDeclareString)
 {
     foreach (Project project in CodeRush.Solution.AllProjects.Where(p => p.Name != ea.Element.Project.Name && p.Type != ProjectType.Miscellaneous).OrderBy(p => p.Name))
     {
         ea.AddSubMenuItem(project.Name, project.Name, String.Format("Declare {0} in the {1} project", typeToDeclareString, project.Name));
     }
 }
Esempio n. 4
0
        private void NameMethodAfterFact_CheckAvailability(Object sender, CheckContentAvailabilityEventArgs ea)
        {
            DisplayNameArg = null;

            // Caret in Method signature
            Method Method = ea.Element as Method;

            if (Method == null)
            {
                return;
            }

            // Method Has Attribute called Fact
            var AttributeFact = Method.FindAttribute("Fact");

            if (AttributeFact == null)
            {
                return;
            }

            // Locate attribute called Displayname
            DisplayNameArg = GetTheArg(AttributeFact);
            if (DisplayNameArg == null)
            {
                return;
            }

            ea.Available = true;
        }
        } // IsXpoProperty(property)

        /// <summary>
        /// Refactoring provider check availability
        /// </summary>
        private void refactoringProvider_CheckAvailability(object sender, CheckContentAvailabilityEventArgs ea)
        {
            LanguageElement element = ea.Element;

            if (element == null)
            {
                return;
            }

            if (element.InsideClass && element is Property)
            {
                _Property          = (Property)element;
                _IsXpoProperty     = IsXpoProperty(_Property);
                _IsAutoImplemented = _Property.IsAutoImplemented;
                if (_IsAutoImplemented || _IsXpoProperty)
                {
                    ea.Available = true;
                    if (_IsAutoImplemented)
                    {
                        ea.AddSubMenuItem(MenuItem_ConvertTo_XPOProperty, "XPO property");
                    }
                    ea.AddSubMenuItem(MenuItem_ConvertTo_DelayedProperty, "Delayed property");
                }
            } // if
        }     // refactoringProvider_CheckAvailability(sender, ea)
 private void refactoringProvider1_CheckAvailability(object sender, CheckContentAvailabilityEventArgs ea)
 {
     if (enabled)
     {
         ea.Available = actionIsAvailable(ea.Element);
     }
 }
 public void AddProjectsToSubmenu(CheckContentAvailabilityEventArgs ea)
 {
     foreach (Project project in CodeRush.Solution.AllProjects.Where(p => p.Name != ea.Element.Project.Name && p.Type != ProjectType.Miscellaneous).OrderBy(p => p.Name))
     {
         ea.AddSubMenuItem(project.Name, project.Name, String.Format("Move type file in the {0} project", project.Name));
     }
 }
Esempio n. 8
0
 public void AddProjectsToSubmenu(CheckContentAvailabilityEventArgs ea)
 {
     foreach (Project project in CodeRush.Solution.AllProjects.Where(p => p.Name != ea.Element.Project.Name && p.Type != ProjectType.Miscellaneous).OrderBy(p => p.Name))
     {
         ea.AddSubMenuItem(project.Name, project.Name, String.Format("Move type file in the {0} project", project.Name));
     }
 }
 private void AddSubmenuItems(CheckContentAvailabilityEventArgs ea, IList <Project> projectsInSolution)
 {
     foreach (Project project in CodeRush.Solution.AllProjects.Where(p => p.Name != ea.Element.Project.Name && p.Type != ProjectType.Miscellaneous).OrderBy(p => p.Name))
     {
         projectsInSolution.Add(project);
         ea.AddSubMenuItem(project.Name, project.Name, String.Format("Move type to Project {0}", project.Name));
     }
 }
 private void BuildMenu(CheckContentAvailabilityEventArgs ea)
 {
     var classes = _implementors.OrderBy(c => c.Name);
     foreach (var item in classes)
     {
         ea.AddSubMenuItem(item.FullName, item.Name);
     }
 }
Esempio n. 11
0
        /// <summary>
        /// TODO Add summary
        /// </summary>
        private void moveTypesToFilesRefactoring_CheckAvailability(object sender, CheckContentAvailabilityEventArgs ea)
        {
            RefactoringProviderBase moveRefactoring   = CodeRush.Refactoring.Get("Move Type to File");
            RefactoringProviderBase renameRefactoring = CodeRush.Refactoring.Get("Rename File to Match Type");

            ea.Available = moveRefactoring != null && renameRefactoring != null &&
                           (ea.CodeActive.ElementType == LanguageElementType.Namespace || ea.CodeActive.ElementType == LanguageElementType.Class);
        }
 private void AddSubmenuItems(CheckContentAvailabilityEventArgs ea, IList<Project> projectsInSolution)
 {
     foreach (Project project in CodeRush.Solution.AllProjects.Where(p => p.Name != ea.Element.Project.Name && p.Type != ProjectType.Miscellaneous).OrderBy(p => p.Name))
     {
         projectsInSolution.Add(project);
         ea.AddSubMenuItem(project.Name, project.Name, String.Format("Move type to Project {0}", project.Name));
     }
 }
        private void BuildMenu(CheckContentAvailabilityEventArgs ea)
        {
            var classes = _implementors.OrderBy(c => c.Name);

            foreach (var item in classes)
            {
                ea.AddSubMenuItem(item.FullName, item.Name);
            }
        }
Esempio n. 14
0
 private void ConvertToMultipleSingleLineComments_CheckAvailability(Object sender, CheckContentAvailabilityEventArgs ea)
 {
     var Comment = ea.CodeActive as Comment;
     if (Comment == null)
         return;
     if (Comment.CommentType == CommentType.SingleLine)
         return;
     ea.Available = true;
 }
        private void navigationProvider1_CheckAvailability(object sender, CheckContentAvailabilityEventArgs ea)
        {
            _implementors.Load(ea.Element);
            ea.Available = _implementors.Count > 0;
            if (!ea.Available)
                return;

            BuildMenu(ea);
        }
Esempio n. 16
0
 private void AddDataContract_CheckAvailability(Object sender, CheckContentAvailabilityEventArgs ea)
 {
     // Limit availability to when the caret is within the name of the active class.
     if (CodeRush.Source.ActiveClass == null)
         return; // No active class
     if (!CodeRush.Source.ActiveClass.NameRange.Contains(CodeRush.Caret.SourcePoint))
         return;  // Caret not in class name
     ea.Available = true;
 }
 private void navigationProvider1_CheckAvailability(object sender, CheckContentAvailabilityEventArgs ea)
 {
   if (enabled)
   {
     if (ea.Element == null)
       return;
     ea.Available = GetElementDeclaration(ea.Element) != null;
   }
 }
Esempio n. 18
0
 private void SplitTag_CheckAvailability(Object sender, CheckContentAvailabilityEventArgs ea)
 {
     LanguageElement element = ea.Element;
     if ((element as SP.HtmlText) == null)
         return;
     SP.HtmlElement tag = (element.Parent as SP.HtmlElement);
     if (tag == null)
         return;
     ea.Available = true;
 }
 private void XmlSummaryCollapseProvider_CheckAvailability(object sender, CheckContentAvailabilityEventArgs ea)
 {
     if (ea.CodeActive.ElementType == LanguageElementType.XmlDocText)
     {               
         if (ea.Element.Name.Contains(Environment.NewLine))
             ea.Available = true;
     }
     else
         ea.Available = false;
 }
        private void MoveTypeToFileInSpecificProjectProvider_CheckAvailability(object sender, CheckContentAvailabilityEventArgs ea)
        {
            ea.Available = _moveTypeToFile.IsAvailable(ea);

            if (ea.Available == false)
                return;

            ea.MenuCaption = "Move Type To File In Project...";

            _moveTypeToFile.AddProjectsToSubmenu(ea);
        }
        private void DeclareClassInSpecificProject_CheckAvailability(object sender, CheckContentAvailabilityEventArgs ea)
        {
            ea.Available = _declareClassInProject.IsAvailable(ea);

            if (ea.Available == false)
                return;

            ea.MenuCaption = "Declare Class In Project...";

            _declareClassInProject.AddProjectsToSubmenu(ea);
        }
 private void navigationProvider1_CheckAvailability(object sender, CheckContentAvailabilityEventArgs ea)
 {
     if (enabled)
     {
         if (ea.Element == null)
         {
             return;
         }
         ea.Available = GetElementDeclaration(ea.Element) != null;
     }
 }
        private void navigationProvider1_CheckAvailability(object sender, CheckContentAvailabilityEventArgs ea)
        {
            _implementors.Load(ea.Element);
            ea.Available = _implementors.Count > 0;
            if (!ea.Available)
            {
                return;
            }

            BuildMenu(ea);
        }
 private void ConvertStringToAppSetting_CheckAvailability(Object sender, CheckContentAvailabilityEventArgs ea)
 {
     PrimitiveExpression Literal = ea.Element as PrimitiveExpression;
     if (Literal == null)
         return;
     if (Literal.PrimitiveType != PrimitiveType.String)
         return;
     if (((string)Literal.PrimitiveValue).Trim() == string.Empty)
         return;
     ea.Available = true;
 }
Esempio n. 25
0
        private void DeclareClassInSpecificProject_CheckAvailability(object sender, CheckContentAvailabilityEventArgs ea)
        {
            ea.Available = _declareClassInProject.IsAvailable(ea);

            if (ea.Available == false)
            {
                return;
            }

            ea.MenuCaption = "Declare Class In Project...";

            _declareClassInProject.AddProjectsToSubmenu(ea);
        }
Esempio n. 26
0
        void refactoringProvider_CheckAvailability(object sender, CheckContentAvailabilityEventArgs ea)
        {
            var el         = ea.Element;
            var isAvalable = false;

            while (!isAvalable && !(el is SourceFile))
            {
                isAvalable = el is NamespaceReference;
                el         = el.Parent;
            }

            ea.Available = isAvalable;
        }
		void refactoringProvider_CheckAvailability(object sender, CheckContentAvailabilityEventArgs ea)
		{
			var el = ea.Element;
			var isAvalable = false;

			while (!isAvalable && !(el is SourceFile))
			{
				isAvalable = el is NamespaceReference;
				el = el.Parent;
			}

			ea.Available = isAvalable;
		}
Esempio n. 28
0
 private void AddDataContract_CheckAvailability(Object sender, CheckContentAvailabilityEventArgs ea)
 {
     // Limit availability to when the caret is within the name of the active class.
     if (CodeRush.Source.ActiveClass == null)
     {
         return; // No active class
     }
     if (!CodeRush.Source.ActiveClass.NameRange.Contains(CodeRush.Caret.SourcePoint))
     {
         return;  // Caret not in class name
     }
     ea.Available = true;
 }
Esempio n. 29
0
        void refactoringProviderWRegions_CheckAvailability(object sender, CheckContentAvailabilityEventArgs ea)
        {
            if (ea == null)
            {
                return;
            }

            if (!IsValidSelection(ea.Element, ea.TextView.Selection, ea.Caret))
            {
                return;
            }

            ea.Available = ea.Element.ElementType == LanguageElementType.Class;
        }
 private void XmlSummaryCollapseProvider_CheckAvailability(object sender, CheckContentAvailabilityEventArgs ea)
 {
     if (ea.CodeActive.ElementType == LanguageElementType.XmlDocText)
     {
         if (ea.Element.Name.Contains(Environment.NewLine))
         {
             ea.Available = true;
         }
     }
     else
     {
         ea.Available = false;
     }
 }
        private void cpRemoveOuterBlock_CheckAvailability(object sender, CheckContentAvailabilityEventArgs ea)
        {
            ParentingStatement parentingStatement = ea.Element as ParentingStatement;

            if (parentingStatement == null)
            {
                return;
            }
            if (parentingStatement.ElementType == LanguageElementType.Switch)
            {
                return;
            }
            ea.Available = true;
        }
 private void IntroduceLocalAllArguments_CheckAvailability(Object sender, CheckContentAvailabilityEventArgs ea)
 {
     // Are we on a MethodReferenceExpression?
     LanguageElement element = CodeRush.Source.Active;
     MethodReferenceExpression MRE = element as MethodReferenceExpression;
     if (MRE == null)
         return;
     // Does Method have arguments?
     LanguageElement parent = MRE.Parent;
     ExpressionCollection arguments = getArguments(parent);
     if (arguments == null)
         return;
     ea.Available = true;
 }
Esempio n. 33
0
        private void rpUseNamedParameters_CheckAvailability(object sender, CheckContentAvailabilityEventArgs ea)
        {
            LanguageElement methodCall = GetMethodCall(ea.Element);

            if (methodCall == null)
            {
                return;
            }

            IHasArguments hasArguments = methodCall as IHasArguments;

            if (hasArguments == null)
            {
                return;
            }

            IWithParameters declaration = GetValidDeclaration(methodCall);

            if (declaration == null)
            {
                return;
            }

            ExpressionCollection arguments = hasArguments.Arguments;

            if (arguments == null || arguments.Count <= 0)
            {
                return;
            }

            bool hasAttributeVarInitializer = false;

            foreach (Expression arg in arguments)
            {
                if (arg is AttributeVariableInitializer)
                {
                    hasAttributeVarInitializer = true;
                    break;
                }
                if (arg is AnonymousMethodExpression)
                {
                    return;
                }
            }

            if (!hasAttributeVarInitializer)
            {
                ea.Available = true;
            }
        }
Esempio n. 34
0
        private bool IsAvailable(CheckContentAvailabilityEventArgs ea)
        {
            Property activeProperty = GetActiveProperty(ea.Element);

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

            // Uncomment this is you want to prevent it from killing a property that has implementation in its get or set blocks
            //if (!IsSimpleProperty(activeProperty))
            //    return false;

            return(true);
        }
        private void navigationProvider1_CheckAvailability(object sender, CheckContentAvailabilityEventArgs ea)
        {
            if (ea.Element == null)
            {
                return;
            }

            IElement declaration;

            if (ea.Element.ElementType == LanguageElementType.TypeReferenceExpression)
            {
                declaration = ea.Element.GetDeclaration();
            }
            else
            {
                declaration = (IElement)ea.Element.GetClass() ?? (IElement)ea.Element.GetStruct() ?? (IElement)ea.Element.GetInterface();
            }

            if (declaration == null)
            {
                return;
            }

            ITypeElement typeElement = declaration as ITypeElement;

            if (typeElement == null)
            {
                return;
            }

            _classes = new List <LanguageElement>();
            var elements        = typeElement.FindAllReferences().ToLanguageElementCollection();
            var elementsInTests = from element in elements.OfType <LanguageElement>()
                                  let cls = element.GetClass()
                                            where ClassIsTestClass(cls)
                                            select element;

            if (elementsInTests.Count() == 0)
            {
                ea.Available = false;
                return;
            }

            _classes = elementsInTests.ToList();

            ea.Available   = true;
            ea.MenuCaption = string.Format("Test{0} {1} {2}", _classes.MoreThanOne() ? "s" : "", (char)0x21d2, typeElement.Name);
        }
        /// <summary>
        /// Handles the CheckAvailability event of the cpCreateContract control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="ea">The <see cref="DevExpress.CodeRush.Core.CheckContentAvailabilityEventArgs"/> instance containing the event data.</param>
        private void CheckAvailability(object sender, CheckContentAvailabilityEventArgs ea)
        {
            // Must be in an interface.
            this.activeInterface = ea.ClassInterfaceOrStruct as Interface;
            if (this.activeInterface == null || ea.Caret.Line != this.activeInterface.Range.Start.Line)
            {
                return;
            }

            // This object will provide assertions that statically provided services are not null.
            // If required services are null, an exception is thrown here by design.
            this.codeRushProxy = new CodeRushProxy();
            string filePath = this.codeRushProxy.Source.ActiveSourceFile.FilePath;

            if (string.IsNullOrEmpty(filePath))
            {
                return;
            }

            this.interfaceFilePath = filePath;

            SourceFile fileNode = this.activeInterface.FileNode;

            if (fileNode == null)
            {
                return;
            }

            this.interfaceSourceFile = fileNode;

            string interfaceName = this.activeInterface.Name;

            if (string.IsNullOrEmpty(interfaceName))
            {
                return;
            }

            this.interfaceName = interfaceName;

            // Must not already have the ContractClassAttribute
            ea.Available = this.activeInterface.AttributeSections == null ||
                           !(from AttributeSection section in this.activeInterface.AttributeSections
                             from DevExpress.CodeRush.StructuralParser.Attribute attribute in section.AttributeCollection
                             where attribute.Name == ContractClassAttributeName
                             select attribute).Any();
        }
Esempio n. 37
0
        private void ConvertToMultilineComment_CheckAvailability(Object sender, CheckContentAvailabilityEventArgs ea)
        {
            var Comment = ea.CodeActive as Comment;

            if (Comment == null)
            {
                return; // exit because the active element is not a comment
            }
            if (Comment.CommentType == CommentType.MultiLine)
            {
                return; // exit because this comment is already multiline
            }
            if (Comment.PreviousConnectedComment == null && Comment.NextConnectedComment == null)
            {
                return;          // Exit because no connected comments
            }
            ea.Available = true; // Change this to return true, only when your refactoring should be available.
        }
        private void ConvertStringToAppSetting_CheckAvailability(Object sender, CheckContentAvailabilityEventArgs ea)
        {
            PrimitiveExpression Literal = ea.Element as PrimitiveExpression;

            if (Literal == null)
            {
                return;
            }
            if (Literal.PrimitiveType != PrimitiveType.String)
            {
                return;
            }
            if (((string)Literal.PrimitiveValue).Trim() == string.Empty)
            {
                return;
            }
            ea.Available = true;
        }
Esempio n. 39
0
        private void CorrectReturnType_CheckAvailability(Object sender, CheckContentAvailabilityEventArgs ea)
        {
            if (ea.Element.ElementType != LanguageElementType.Return)
                return;
            Method Parent = ea.Element.GetParentMethod();
            if (Parent == null)
                return;
            if (Parent.MemberType == "void")
                return;

            var Return = (Return)ea.Element;

            var ExpressionType = Return.Expression.Resolve(ParserServices.SourceTreeResolver);

            if (ExpressionType.Name == Parent.MemberType)
                return;
            ea.Available = true;
        }
Esempio n. 40
0
        private bool IsAvailable(CheckContentAvailabilityEventArgs ea)
        {
            Property activeProperty = GetActiveProperty(ea.Element);

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

            // TODO: check selection and caret position if needed...

            if (!IsSimpleProperty(activeProperty))
            {
                return(false);
            }

            return(true);
        }
        private static bool IsInsideInitializerToTypeWithSource(CheckContentAvailabilityEventArgs ea)
        {
            _TypeElement = null;
            _ObjectCreationExpression = ea.Element as ObjectCreationExpression;
            if (_ObjectCreationExpression == null)
            {
                _ObjectCreationExpression = ea.Element.GetParent(LanguageElementType.ObjectCreationExpression) as ObjectCreationExpression;
                if (_ObjectCreationExpression == null)
                    return false;
            }
            _InitializerExpression = _ObjectCreationExpression.ObjectInitializer;
            if (_InitializerExpression == null)
                return false;
            _TypeElement = _ObjectCreationExpression.ObjectType.Resolve(ParserServices.SourceTreeResolver) as ITypeElement;
            if (_TypeElement == null)
                return false;

            return !_TypeElement.InReferencedAssembly;
        }
        private void IntroduceLocalAllArguments_CheckAvailability(Object sender, CheckContentAvailabilityEventArgs ea)
        {
            // Are we on a MethodReferenceExpression?
            LanguageElement           element = CodeRush.Source.Active;
            MethodReferenceExpression MRE     = element as MethodReferenceExpression;

            if (MRE == null)
            {
                return;
            }
            // Does Method have arguments?
            LanguageElement      parent    = MRE.Parent;
            ExpressionCollection arguments = getArguments(parent);

            if (arguments == null)
            {
                return;
            }
            ea.Available = true;
        }
Esempio n. 43
0
 private void SortFormatTokens_CheckAvailability(Object sender, CheckContentAvailabilityEventArgs ea)
 {
     _PrimitiveString = (CodeRush.Source.Active as PrimitiveExpression);
     if (_PrimitiveString == null)
         return;
     if (_PrimitiveString.PrimitiveType != PrimitiveType.String)
         return;
     LanguageElement Parent = _PrimitiveString.Parent;
     if (Parent == null)
         return;
     MethodCallExpression MCE = (Parent as MethodCallExpression);
     if (MCE == null)
         return;
     if (MCE.Name != "Format")
         return;
     _tokens = new TokenGatherer().GetTokens(_PrimitiveString.Name);
     if (!SequenceRenumberer.RequiresRenumbering(from item in _tokens select item.Index))
         return;
     ea.Available = true;
 }
Esempio n. 44
0
        private void ReverseArgs_CheckAvailability(Object sender, CheckContentAvailabilityEventArgs ea)
        {
            TextDocument ActiveDoc = ea.TextDocument;
            TextViewSelection Selection = ActiveDoc.ActiveViewSelection;
            SourcePoint StartPoint = Selection.StartSourcePoint;
            SourcePoint EndPoint = Selection.EndSourcePoint;

            _startElement = PromoteIfReference(ActiveDoc.GetNodeAt(StartPoint));
            _endElement = PromoteIfReference(ActiveDoc.GetNodeAt(EndPoint));

            // Exit if selectionText does not contain ','
            if (_startElement == _endElement)
                return;

            if (_startElement.Parent == null)
                return; // not sure how, but cover ourselves anyway :)

            // Exit if Elements do not have same parent
            if (_startElement.Parent != _endElement.Parent)
                return;

            // Exit if elements are not siblings
            if (_startElement.PreviousCodeSibling != _endElement
                && _startElement.NextCodeSibling != _endElement)
                return;

            // don't overlap the name of the method\property.
            if (_startElement.ElementType == LanguageElementType.MethodReferenceExpression)
                return;
            if (_startElement.ElementType == LanguageElementType.ElementReferenceExpression)
                return;

            var Parent = _startElement.Parent.GetDeclaration();
            if (!(Parent is IHasParameters || Parent is IWithParameters))
                return; // Parent takes no parameters (ie method, property etc)

            // Restricted implementation at first.
            if (CodeRush.Selection.Height > 1)
                return;
            ea.Available = true;
        }
Esempio n. 45
0
        } // GetClassBaseType

        /// <summary>
        /// Nav easy goto check availability
        /// </summary>
        private void navEasyGoto_CheckAvailability(object sender, CheckContentAvailabilityEventArgs ea)
        {
            LanguageElement element = ea.Element;

            if (element == null)
            {
                return;
            }
            _currentClass = element.GetClass();
            if (_currentClass != null)
            {
                ea.Available = true;
                ea.AddSubMenuItem(MenuItem_ClassDefinition, "Class definition");
                _currentBaseClassRef = GetClassBaseType(_currentClass);
                if (_currentBaseClassRef != null)
                {
                    ea.AddSubMenuItem(MenuItem_ClassDefinition_InheritedClass, "Base class");
                    ea.AddSubMenuItem(MenuItem_ClassDefinition_InheritedClass_Definition, "Base class definition");
                }
            } // if
        }     // navEasyGoto_CheckAvailability
Esempio n. 46
0
        private void CompressEvent_CheckAvailability(Object sender, CheckContentAvailabilityEventArgs ea)
        {
            CodeRush.Documents.ActiveTextDocument.ParseIfNeeded();
            _EventToCompress = GetEvent(ea.Caret);
            // Exit if no Event found under caret
            if (_EventToCompress == null)
                return;
            // Exit if _Event has no Add or Remove
            if (_EventToCompress.Nodes.Count == 0)
                return;

            var EventAdd = (EventAdd)_EventToCompress.Nodes[0];
            var EventRemove = (EventRemove)_EventToCompress.Nodes[1];

            // Add and Remove must contain exactly one assignment statement
            if (EventAdd.Nodes.Count != 1)
                return;
            if (EventRemove.Nodes.Count != 1)
                return;

            var EventAddAssign = (Assignment)EventAdd.Nodes[0];
            var EventRemoveAssign = (Assignment)EventRemove.Nodes[0];

            // Assignment Statements must assign to same variable
            if (EventAddAssign.LeftSide.Name != EventRemoveAssign.LeftSide.Name)
                return;

            var EventField = EventAddAssign.LeftSide;
            _EventToCompressFieldDeclaration = (Variable)EventField.GetDeclaration().ToLanguageElement();
            // Variable must be of type EventHandler
            if (_EventToCompressFieldDeclaration.MemberType != "EventHandler")
                return;

            // Variable must have 2 and only 2 references.
            if (_EventToCompressFieldDeclaration.FindAllReferences().Count != 2)
                return;

            ea.Available = true;
        }
 private void cpMoveToSetup_CheckAvailability(object sender, CheckContentAvailabilityEventArgs ea)
 {
     _currentClass = ea.Element.GetClass();
     _setupMethod = GetSetupMethod(_currentClass);
     if(_setupMethod == null)
     {
         ea.Available = false;
         return;
     }
     _parentAssignment = ea.Element.FindParentByElementType(LanguageElementType.Assignment) as Assignment;
     if (_parentAssignment == null)
     {
         ea.Available = false;
         return;
     }
     var referencedVariable = ((Assignment)_parentAssignment).LeftSide as ElementReferenceExpression;
     
     ea.Available = _parentAssignment != null 
                 && _parentAssignment.LeftSide.ElementType == LanguageElementType.ElementReferenceExpression
                 && referencedVariable.GetDeclaringType() == _currentClass
                 && IsInTestClass() 
                 && HasSetUp();
 }
Esempio n. 48
0
        // event handlers...
        private void cpAddReference_CheckAvailability(object sender, CheckContentAvailabilityEventArgs ea)
        {
            LanguageElement activeMethodRerence = GetActiveMethodReference(ea.Element);

            if (activeMethodRerence == null)
            {
                return;
            }

            ITypeElement callerType;
            Expression   qualifier;

            if (!IsValidReferenceAndQualifier(activeMethodRerence, out callerType, out qualifier))
            {
                return;
            }

            IEnumerable projectSymbols = GetProjectSymbols();

            if (projectSymbols == null)
            {
                return;
            }

            string         methodNameToFind = activeMethodRerence.Name;
            IMethodElement extensionMethod  = FindExtensionMethod(projectSymbols, methodNameToFind, callerType, qualifier);

            if (extensionMethod == null || extensionMethod.ParentNamespace == null)
            {
                return;
            }

            _NamespaceOfExtensionMethod = extensionMethod.ParentNamespace.FullName;

            ea.Available = true;
        }
        private void AddNamespaceReference_CheckAvailability(Object sender, CheckContentAvailabilityEventArgs ea)
        {
            LanguageElement activeMethodRerence = GetActiveMethodReference(ea.Element);
            if (activeMethodRerence == null)
                return;

            ITypeElement callerType;
            Expression qualifier;
            if (!IsValidReferenceAndQualifier(activeMethodRerence, out callerType, out qualifier))
                return;

            IEnumerable projectSymbols = GetProjectSymbols();
            if (projectSymbols == null)
                return;

            string methodNameToFind = activeMethodRerence.Name;
            IMethodElement extensionMethod = FindExtensionMethod(projectSymbols, methodNameToFind, callerType, qualifier);
            if (extensionMethod == null || extensionMethod.ParentNamespace == null)
                return;

            _NamespaceOfExtensionMethod = extensionMethod.ParentNamespace.FullName;

            ea.Available = true;
        }
        private void codeProvider_CheckAvailability(object sender, CheckContentAvailabilityEventArgs ea)
        {
            //make sure that the language element is not null
            _activeElement = ea.Element;
            if (_activeElement == null) return;

            //get the current class that this language element belongs to.
            _childClass = CodeRush.Source.ActiveClass;
            if (_childClass == null) return;
            //make sure that the class also has a parent class.
            if (_childClass.PrimaryAncestorType == null) return;
            _parentClass = _childClass.PrimaryAncestorType.GetDeclaration() as Class;
            if (_parentClass == null) return;

            //make sure that the element selected is also generalizable.
            if(IsGeneralizableElement(_activeElement))
            {
                ea.Available = true;
            }
            else
            {
                ea.Available = false;
            }
        }
Esempio n. 51
0
        private void codeProvider_CheckAvailability(object sender, CheckContentAvailabilityEventArgs ea)
        {
            //make sure that the language element is not null
            _activeElement = ea.Element;
            if (_activeElement == null)
            {
                return;
            }

            //get the current class that this language element belongs to.
            _childClass = CodeRush.Source.ActiveClass;
            if (_childClass == null)
            {
                return;
            }
            //make sure that the class also has a parent class.
            if (_childClass.PrimaryAncestorType == null)
            {
                return;
            }
            _parentClass = _childClass.PrimaryAncestorType.GetDeclaration() as Class;
            if (_parentClass == null)
            {
                return;
            }

            //make sure that the element selected is also generalizable.
            if (IsGeneralizableElement(_activeElement))
            {
                ea.Available = true;
            }
            else
            {
                ea.Available = false;
            }
        }
		/// <summary>
		/// TODO Add summary
		/// </summary>
		private void createPersistentClassCodeProvider_CheckAvailability(object sender, CheckContentAvailabilityEventArgs ea)
		{
			ea.Available = ea.CodeActive.ElementType == LanguageElementType.Namespace ||
				ea.CodeActive.ElementType == LanguageElementType.Class;
		}
 private void CheckAvailability(object sender, CheckContentAvailabilityEventArgs ea)
 {
     ea.Available = IsAvailable(ea);
 }
 private void cpConvertToJQuery_CheckAvailability(object sender, CheckContentAvailabilityEventArgs ea)
 {
     ea.Available = IsAvailable(ea.Element);
 }
        private bool IsAvailable(CheckContentAvailabilityEventArgs ea)
        {
            Property activeProperty = GetActiveProperty(ea.Element);
            if (activeProperty == null)
                return false;

            // TODO: check selection and caret position if needed...

            if (!IsSimpleProperty(activeProperty))
                return false;

            return true;
        }
Esempio n. 56
0
		private void cpAssignmentExpressionToEqualityCheck_CheckAvailability(object sender, CheckContentAvailabilityEventArgs ea)
		{
			AssignmentExpression assignmentExpression = GetAssignmentExpression(ea.Element);
			ea.Available = assignmentExpression != null;
		}
 private void refactoringUpdateNamespace_CheckAvailability(object sender, CheckContentAvailabilityEventArgs ea)
 {
     ea.Available = ShouldBeAvailable(ea.Caret);
 }
Esempio n. 58
0
        private void cpAssignmentExpressionToEqualityCheck_CheckAvailability(object sender, CheckContentAvailabilityEventArgs ea)
        {
            AssignmentExpression assignmentExpression = GetAssignmentExpression(ea.Element);

            ea.Available = assignmentExpression != null;
        }
 public bool IsAvailable(CheckContentAvailabilityEventArgs ea)
 {
     return(IsValidSelection(ea.Element, ea.TextView.Selection) && IsValidType(ea.Element));
 }