Exemple #1
0
        public override void Execute(SolutionModel solutionModel, SelectionContext context)
        {
            FileModel fileModel;
            CodeSpan  selection;

            if (!solutionModel.IsEditorSelection(context, out fileModel, out selection))
            {
                return;
            }

            propertiesSelectedByUser = false;

            IIdentifier       identifier       = fileModel.InnerMost <IIdentifier>(selection);
            IClassDeclaration classDeclaration = identifier.ParentConstruct.As <IClassDeclaration>();

            if (classDeclaration.ExistsTextuallyInFile && classDeclaration.IsInUserCode() && !classDeclaration.IsPrivate())
            {
                IConstructEnumerable <IMemberDeclaration> propertiesForWrapping = GetPropertiesForWrapping(classDeclaration);
                if (!propertiesForWrapping.Any())
                {
                    CreateViewModelWithoutUserSelectedProperties(classDeclaration).NavigateTo();
                }
                else
                {
                    ConfirmOccurencesDialog confirmOccurencesDialog = fileModel.UIProcess.Get <ConfirmOccurencesDialog>();
                    confirmOccurencesDialog.ShowIfOccurencesToConfirmIn("Select properties for wrapping", "Select which properties to be wrapped",
                                                                        () => ConfirmPropertyDeclarationsToBeWrappedAndContinueWrapping(classDeclaration, propertiesForWrapping));
                }
            }
        }
        public override void Execute(SolutionModel solutionModel, SelectionContext context)
        {
            FileModel fileModel;
            CodeSpan  selection;

            if (!solutionModel.IsEditorSelection(context, out fileModel, out selection))
            {
                return;
            }

            IMemberDeclaration memberDeclaration = fileModel.InnerMost <IMemberDeclaration>(selection);

            if (memberDeclaration.ExistsTextuallyInFile && !memberDeclaration.Identifier.CodeSpan.Intersects(selection))
            {
                memberDeclaration.Identifier.Select();
            }
            else
            {
                ITypeDeclaration typeDeclaration = fileModel.InnerMost <ITypeDeclaration>(selection);

                if (typeDeclaration.ExistsTextuallyInFile)
                {
                    NavigateToTypeDeclaration(typeDeclaration, selection);
                }
            }
        }
        public override void Execute(SolutionModel solutionModel, SelectionContext context)
        {
            FileModel fileModel;
            CodeSpan selection;

            if (!solutionModel.IsEditorSelection(context, out fileModel, out selection))
            {
                return;
            }

            IMemberDeclaration memberDeclaration = fileModel.InnerMost<IMemberDeclaration>(selection);
            if (memberDeclaration.ExistsTextuallyInFile && !memberDeclaration.Identifier.CodeSpan.Intersects(selection))
            {
                memberDeclaration.Identifier.Select();
            }
            else
            {
                ITypeDeclaration typeDeclaration = fileModel.InnerMost<ITypeDeclaration>(selection);

                if (typeDeclaration.ExistsTextuallyInFile)
                {
                    NavigateToTypeDeclaration(typeDeclaration, selection);
                }
            }
        }
        public override void Execute(SolutionModel solutionModel, SelectionContext context)
        {
            FileModel fileModel;
            CodeSpan selection;

            if (!solutionModel.IsEditorSelection(context, out fileModel, out selection))
            {
                return;
            }

            propertiesSelectedByUser = false;

            IIdentifier identifier = fileModel.InnerMost<IIdentifier>(selection);
            IClassDeclaration classDeclaration = identifier.ParentConstruct.As<IClassDeclaration>();
            if (classDeclaration.ExistsTextuallyInFile && classDeclaration.IsInUserCode() && !classDeclaration.IsPrivate())
            {
                IConstructEnumerable<IMemberDeclaration> propertiesForWrapping = GetPropertiesForWrapping(classDeclaration);
                if (!propertiesForWrapping.Any())
                {
                    CreateViewModelWithoutUserSelectedProperties(classDeclaration).NavigateTo();
                }
                else
                {
                    ConfirmOccurencesDialog confirmOccurencesDialog = fileModel.UIProcess.Get<ConfirmOccurencesDialog>();
                    confirmOccurencesDialog.ShowIfOccurencesToConfirmIn("Select properties for wrapping", "Select which properties to be wrapped",
                        () => ConfirmPropertyDeclarationsToBeWrappedAndContinueWrapping(classDeclaration, propertiesForWrapping));
                }
            }
        }
        public override bool CanExecute(SolutionModel solutionModel, SelectionContext context)
        {
            FileModel fileModel;
            CodeSpan selection;

            if (!solutionModel.IsEditorSelection(context, out fileModel, out selection))
            {
                return false;
            }

            return fileModel.MemberIdentifierAt(selection).ExistsTextuallyInFile;
        }
        public override bool CanExecute(SolutionModel solutionModel, SelectionContext context)
        {
            FileModel fileModel;
            CodeSpan selection;

            if (!solutionModel.IsEditorSelection(context, out fileModel, out selection))
            {
                return false;
            }

            IConstructEnumerable<IFieldDeclaration> fields = FindFields(fileModel, selection);
            return fields.Exist() && ImplementsINotifyPropertyChanged(fields.First().EnclosingClass);
        }
        public override bool CanExecute(SolutionModel solutionModel, SelectionContext context)
        {
            FileModel fileModel;
            CodeSpan selection;

            if (!solutionModel.IsEditorSelection(context, out fileModel, out selection))
            {
                return false;
            }

            IMemberDeclaration member = fileModel.InnerMost<IMemberDeclaration>(selection);
            return member.ExistsTextuallyInFile && member.Identifier.CodeSpan.Intersects(selection);
        }
        public override bool CanExecute(SolutionModel solutionModel, SelectionContext context)
        {
            FileModel fileModel;
            CodeSpan selection;

            if (!solutionModel.IsEditorSelection(context, out fileModel, out selection))
            {
                return false;
            }

            IUsingDirectiveSection section = fileModel.InnerMost<IUsingDirectiveSection>(selection);

            return section.Exists && !section.Enclosing<INamespaceDeclaration>().Exists;
        }
Exemple #9
0
        public override bool CanExecute(SolutionModel solutionModel, SelectionContext context)
        {
            FileModel fileModel;
            CodeSpan  selection;

            if (!solutionModel.IsEditorSelection(context, out fileModel, out selection))
            {
                return(false);
            }

            IConstructEnumerable <IFieldDeclaration> fields = FindFields(fileModel, selection);

            return(fields.Exist() && ImplementsINotifyPropertyChanged(fields.First().EnclosingClass));
        }
        public override bool CanExecute(SolutionModel solutionModel, SelectionContext context)
        {
            FileModel fileModel;
            CodeSpan selection;

            if (!solutionModel.IsEditorSelection(context, out fileModel, out selection))
            {
                return false;
            }

            IIdentifier identifier = fileModel.InnerMost<IIdentifier>(selection);
            IClassDeclaration classDeclaration = identifier.ParentConstruct.As<IClassDeclaration>();
            return classDeclaration.ExistsTextuallyInFile && classDeclaration.IsInUserCode() && !classDeclaration.IsPrivate();
        }
Exemple #11
0
        public override bool CanExecute(SolutionModel solutionModel, SelectionContext context)
        {
            FileModel fileModel;
            CodeSpan  selection;

            if (!solutionModel.IsEditorSelection(context, out fileModel, out selection))
            {
                return(false);
            }

            IMemberDeclaration member = fileModel.InnerMost <IMemberDeclaration>(selection);

            return(member.ExistsTextuallyInFile && member.Identifier.CodeSpan.Intersects(selection));
        }
        public override bool CanExecute(SolutionModel solutionModel, SelectionContext context)
        {
            FileModel fileModel;
            CodeSpan  selection;

            if (!solutionModel.IsEditorSelection(context, out fileModel, out selection))
            {
                return(false);
            }

            IUsingDirectiveSection section = fileModel.InnerMost <IUsingDirectiveSection>(selection);

            return(section.Exists && !section.Enclosing <INamespaceDeclaration>().Exists);
        }
Exemple #13
0
        public override bool CanExecute(SolutionModel solutionModel, SelectionContext context)
        {
            FileModel fileModel;
            CodeSpan  selection;

            if (!solutionModel.IsEditorSelection(context, out fileModel, out selection))
            {
                return(false);
            }

            IIdentifier       identifier       = fileModel.InnerMost <IIdentifier>(selection);
            IClassDeclaration classDeclaration = identifier.ParentConstruct.As <IClassDeclaration>();

            return(classDeclaration.ExistsTextuallyInFile && classDeclaration.IsInUserCode() && !classDeclaration.IsPrivate());
        }
        public override bool CanExecute(SolutionModel solutionModel, SelectionContext context)
        {
            FileModel fileModel;
            CodeSpan selection;

            if (!solutionModel.IsEditorSelection(context, out fileModel, out selection))
            {
                return false;
            }

            IPropertyDeclaration propertyDeclaration = fileModel.InnerMost<IPropertyDeclaration>(selection);

            if (IsFieldBackedPropertyWithSetterInsideClass(propertyDeclaration))
            {
                return EnclosingClassImplementsINotifyPropertyChanged(propertyDeclaration);
            }

            return false;
        }
        public override bool CanExecute(SolutionModel solutionModel, SelectionContext context)
        {
            FileModel fileModel;
            CodeSpan  selection;

            if (!solutionModel.IsEditorSelection(context, out fileModel, out selection))
            {
                return(false);
            }

            IPropertyDeclaration propertyDeclaration = fileModel.InnerMost <IPropertyDeclaration>(selection);

            if (IsFieldBackedPropertyWithSetterInsideClass(propertyDeclaration))
            {
                return(EnclosingClassImplementsINotifyPropertyChanged(propertyDeclaration));
            }

            return(false);
        }
Exemple #16
0
        public override void Execute(SolutionModel solutionModel, SelectionContext context)
        {
            FileModel fileModel;
            CodeSpan  selection;

            if (!solutionModel.IsEditorSelection(context, out fileModel, out selection))
            {
                return;
            }

            IConstructEnumerable <IFieldDeclaration> fields = FindFields(fileModel, selection);

            if (fields.Exist())
            {
                IConstructLanguage language = fields.Language;

                foreach (IFieldDeclaration field in fields)
                {
                    IPropertyDeclaration property = language.Property(
                        language.None <IDocComment>(),
                        language.None <IAttributes>(),
                        language.Modifiers(Modifiers.Public),
                        language.TypeName(field.TypeName.Type),
                        language.None <IIdentifier>());

                    NamingPolicy propertyNamingPolicy = property.PrimaryNamingPolicy(fileModel.UserSettings);
                    string       propertyName         = propertyNamingPolicy.MakeMemberNameUniqueInScope(field, field.Identifier.Name);

                    property.Identifier = language.Identifier(propertyName);

                    IAccessor getter = language.FieldGetter(field.Identifier);
                    IAccessor setter = CreateSetter(language, propertyName, field);

                    property.Accessors = language.Enumerable(new List <IAccessor>()
                    {
                        getter, setter
                    });

                    field.EnclosingClass.Insert(property);
                }
            }
        }
        public override void Execute(SolutionModel solutionModel, SelectionContext context)
        {
            FileModel fileModel;
            CodeSpan selection;

            if (!solutionModel.IsEditorSelection(context, out fileModel, out selection))
            {
                return;
            }

            IMemberDeclaration memberDeclaration = fileModel.MemberIdentifierAt(selection);
            if (memberDeclaration.ExistsTextuallyInFile)
            {
                IMemberDeclaration nextMember = memberDeclaration.NextMember();
                if (nextMember.ExistsTextuallyInFile)
                {
                    nextMember.Identifier.NavigateTo();
                }
            }
        }
        public override void Execute(SolutionModel solutionModel, SelectionContext context)
        {
            FileModel fileModel;
            CodeSpan selection;

            if (!solutionModel.IsEditorSelection(context, out fileModel, out selection))
            {
                return;
            }

            IPropertyDeclaration propertyDeclaration = fileModel.InnerMost<IPropertyDeclaration>(selection);

            if (IsFieldBackedPropertyWithSetterInsideClass(propertyDeclaration) && EnclosingClassImplementsINotifyPropertyChanged(propertyDeclaration))
            {
                IConstructLanguage language = propertyDeclaration.Language;
                string methodInvocationName = language.Name == LanguageNames.CSharp ? "OnPropertyChanged" : "RaisePropertyChangedEvent";
                IMethodInvocation methodInvocation =
                    language.MethodInvocation(
                        language.None<IExpression>(),
                        language.Identifier(methodInvocationName),
                        language.None<ITypeArguments>(),
                        language.Arguments(
                            language.Argument(language.StringLiteral(propertyDeclaration.Identifier.Name))));

                IAccessor setter = propertyDeclaration.Setter();
                List<IStatement> ifBlockStatements = new List<IStatement>(setter.Block.ChildStatements);
                ifBlockStatements.Add(language.ExpressionStatement(methodInvocation));

                IIfStatement ifStatement =
                    language.IfStatement(
                        language.BinaryExpression(
                            language.MemberAccess(language.None<IExpression>(),
                            propertyDeclaration.BackingField().Identifier),
                        Operator.NotEqual,
                        language.Expression("value")),
                        language.Block(ifBlockStatements));

                IBlock newBlock = language.Block(ifStatement);
                setter.Block = newBlock;
            }
        }
        public override void Execute(SolutionModel solutionModel, SelectionContext context)
        {
            FileModel fileModel;
            CodeSpan  selection;

            if (!solutionModel.IsEditorSelection(context, out fileModel, out selection))
            {
                return;
            }

            IPropertyDeclaration propertyDeclaration = fileModel.InnerMost <IPropertyDeclaration>(selection);

            if (IsFieldBackedPropertyWithSetterInsideClass(propertyDeclaration) && EnclosingClassImplementsINotifyPropertyChanged(propertyDeclaration))
            {
                IConstructLanguage language             = propertyDeclaration.Language;
                string             methodInvocationName = language.Name == LanguageNames.CSharp ? "OnPropertyChanged" : "RaisePropertyChangedEvent";
                IMethodInvocation  methodInvocation     =
                    language.MethodInvocation(
                        language.None <IExpression>(),
                        language.Identifier(methodInvocationName),
                        language.None <ITypeArguments>(),
                        language.Arguments(
                            language.Argument(language.StringLiteral(propertyDeclaration.Identifier.Name))));

                IAccessor         setter            = propertyDeclaration.Setter();
                List <IStatement> ifBlockStatements = new List <IStatement>(setter.Block.ChildStatements);
                ifBlockStatements.Add(language.ExpressionStatement(methodInvocation));

                IIfStatement ifStatement =
                    language.IfStatement(
                        language.BinaryExpression(
                            language.MemberAccess(language.None <IExpression>(),
                                                  propertyDeclaration.BackingField().Identifier),
                            Operator.NotEqual,
                            language.Expression("value")),
                        language.Block(ifBlockStatements));

                IBlock newBlock = language.Block(ifStatement);
                setter.Block = newBlock;
            }
        }
        public override bool CanExecute(SolutionModel solutionModel, SelectionContext context)
        {
            FileModel fileModel;
            CodeSpan selection;

            if (!solutionModel.IsEditorSelection(context, out fileModel, out selection))
            {
                return false;
            }

            IMemberDeclaration memberDeclaration = fileModel.InnerMost<IMemberDeclaration>(selection);
            if (memberDeclaration.ExistsTextuallyInFile && !memberDeclaration.Identifier.CodeSpan.Intersects(selection))
            {
                return memberDeclaration.Is<IMethodDeclaration>() || memberDeclaration.Is<IPropertyDeclaration>() ||
                       memberDeclaration.Is<IConstructorDeclaration>() || memberDeclaration.Is<IStaticConstructorDeclaration>();
            }
            else
            {
                return fileModel.InnerMost<ITypeDeclaration>(selection).ExistsTextuallyInFile;
            }
        }
Exemple #21
0
        public override void Execute(SolutionModel solutionModel, SelectionContext context)
        {
            FileModel fileModel;
            CodeSpan  selection;

            if (!solutionModel.IsEditorSelection(context, out fileModel, out selection))
            {
                return;
            }

            IMemberDeclaration memberDeclaration = fileModel.InnerMost <IMemberDeclaration>(selection);

            if (memberDeclaration.ExistsTextuallyInFile)
            {
                IMemberDeclaration nextMember = memberDeclaration.NextMember();
                if (nextMember.ExistsTextuallyInFile)
                {
                    nextMember.Identifier.NavigateTo();
                }
            }
        }
        public override bool CanExecute(SolutionModel solutionModel, SelectionContext context)
        {
            FileModel fileModel;
            CodeSpan  selection;

            if (!solutionModel.IsEditorSelection(context, out fileModel, out selection))
            {
                return(false);
            }

            IMemberDeclaration memberDeclaration = fileModel.InnerMost <IMemberDeclaration>(selection);

            if (memberDeclaration.ExistsTextuallyInFile && !memberDeclaration.Identifier.CodeSpan.Intersects(selection))
            {
                return(memberDeclaration.Is <IMethodDeclaration>() || memberDeclaration.Is <IPropertyDeclaration>() ||
                       memberDeclaration.Is <IConstructorDeclaration>() || memberDeclaration.Is <IStaticConstructorDeclaration>());
            }
            else
            {
                return(fileModel.InnerMost <ITypeDeclaration>(selection).ExistsTextuallyInFile);
            }
        }
        public override void Execute(SolutionModel solutionModel, SelectionContext context)
        {
            FileModel fileModel;
            CodeSpan selection;

            if (!solutionModel.IsEditorSelection(context, out fileModel, out selection))
            {
                return;
            }

            IConstructEnumerable<IFieldDeclaration> fields = FindFields(fileModel, selection);
            if (fields.Exist())
            {
                IConstructLanguage language = fields.Language;

                foreach (IFieldDeclaration field in fields)
                {
                    IPropertyDeclaration property = language.Property(
                        language.None<IDocComment>(),
                        language.None<IAttributes>(),
                        language.Modifiers(Modifiers.Public),
                        language.TypeName(field.TypeName.Type),
                        language.None<IIdentifier>());

                    NamingPolicy propertyNamingPolicy = property.PrimaryNamingPolicy(fileModel.UserSettings);
                    string propertyName = propertyNamingPolicy.MakeMemberNameUniqueInScope(field, field.Identifier.Name);

                    property.Identifier = language.Identifier(propertyName);

                    IAccessor getter = language.FieldGetter(field.Identifier);
                    IAccessor setter = CreateSetter(language, propertyName, field);

                    property.Accessors = language.Enumerable(new List<IAccessor>() { getter, setter });

                    field.EnclosingClass.Insert(property);
                }
            }
        }
        public override void Execute(SolutionModel solutionModel, SelectionContext context)
        {
            FileModel fileModel;
            CodeSpan selection;

            if (!solutionModel.IsEditorSelection(context, out fileModel, out selection))
            {
                return;
            }

            IUsingDirectiveSection mainSection = fileModel.InnerMost<IUsingDirectiveSection>(selection);

            if (mainSection.Exists)
            {
                HashSet<IUsingDirectiveSection> sections = new HashSet<IUsingDirectiveSection>();
                foreach (IUsingDirectiveSection section in fileModel.All<IUsingDirectiveSection>())
                {
                    INamespaceDeclaration nameSpaceItems = section.Enclosing<INamespaceDeclaration>();

                    //we are interested only in top level namespaces
                    if (nameSpaceItems.Exists && !nameSpaceItems.Enclosing<INamespaceDeclaration>().Exists)
                    {
                        sections.Add(section);
                    }
                }

                foreach (IUsingDirectiveSection section in sections)
                {
                    section.Insert(mainSection.Directives, fileModel);
                }
            }

            foreach (IUsingDirective directive in mainSection.Directives)
            {
                directive.Remove();
            }
        }
        public override void Execute(SolutionModel solutionModel, SelectionContext context)
        {
            FileModel fileModel;
            CodeSpan  selection;

            if (!solutionModel.IsEditorSelection(context, out fileModel, out selection))
            {
                return;
            }

            IUsingDirectiveSection mainSection = fileModel.InnerMost <IUsingDirectiveSection>(selection);

            if (mainSection.Exists)
            {
                HashSet <IUsingDirectiveSection> sections = new HashSet <IUsingDirectiveSection>();
                foreach (IUsingDirectiveSection section in fileModel.All <IUsingDirectiveSection>())
                {
                    INamespaceDeclaration nameSpaceItems = section.Enclosing <INamespaceDeclaration>();

                    //we are interested only in top level namespaces
                    if (nameSpaceItems.Exists && !nameSpaceItems.Enclosing <INamespaceDeclaration>().Exists)
                    {
                        sections.Add(section);
                    }
                }

                foreach (IUsingDirectiveSection section in sections)
                {
                    section.Insert(mainSection.Directives, fileModel);
                }
            }

            foreach (IUsingDirective directive in mainSection.Directives)
            {
                directive.Remove();
            }
        }