当前位置: 首页>>代码示例>>C#>>正文


C# VBEditor.Selection类代码示例

本文整理汇总了C#中Rubberduck.VBEditor.Selection的典型用法代码示例。如果您正苦于以下问题:C# Selection类的具体用法?C# Selection怎么用?C# Selection使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Selection类属于Rubberduck.VBEditor命名空间,在下文中一共展示了Selection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RemoveParamatersRefactoring_RemoveOnlyParam

        public void RemoveParamatersRefactoring_RemoveOnlyParam()
        {
            //Input
            const string inputCode =
@"Private Sub Foo(ByVal arg1 As Integer)
End Sub";
            var selection = new Selection(1, 23, 1, 27); //startLine, startCol, endLine, endCol

            //Expectation
            const string expectedCode =
@"Private Sub Foo()
End Sub";

            //Arrange
            SetupProject(inputCode);
            var parseResult = new RubberduckParser().Parse(_project.Object);

            var qualifiedSelection = GetQualifiedSelection(selection);

            //Specify Params to remove
            var model = new RemoveParametersModel(parseResult, qualifiedSelection);
            model.Parameters.ForEach(arg => arg.IsRemoved = true);

            //SetupFactory
            var factory = SetupFactory(model);

            //Act
            var refactoring = new RemoveParametersRefactoring(factory.Object);
            refactoring.Refactor(qualifiedSelection);

            //Assert
            Assert.AreEqual(expectedCode, _module.Object.Lines());
        }
开发者ID:ThunderFrame,项目名称:Rubberduck,代码行数:33,代码来源:RemoveParametersTests.cs

示例2: AddDeclarationItem

        /// <summary>Common method for adding declaration with some default values</summary>
        private void AddDeclarationItem(IMock<ParserRuleContext> context,
            Selection selection,
            QualifiedMemberName? qualifiedName = null,
            DeclarationType declarationType = DeclarationType.Project,
            string identifierName = "identifierName")
        {
            Declaration declarationItem = null;
            var qualName = qualifiedName ?? new QualifiedMemberName(_module, "fakeModule");

            declarationItem = new Declaration(
                qualifiedName: qualName,
                parentScope: "module.proc",
                asTypeName: "asTypeName",
                isSelfAssigned: false,
                isWithEvents: false,
                accessibility: Accessibility.Public,
                declarationType: declarationType,
                context: context.Object,
                selection: selection
                );

            _declarations.Add(declarationItem);
            if (_listDeclarations == null) _listDeclarations = new List<Declaration>();
            _listDeclarations.Add(declarationItem);
        }
开发者ID:ThunderFrame,项目名称:Rubberduck,代码行数:26,代码来源:RenamePresenterTests.cs

示例3: GetNavigateCodeEventArgs

        public static NavigateCodeEventArgs GetNavigateCodeEventArgs(this SyntaxErrorException exception, Declaration declaration)
        {
            if (declaration == null) return null;

            var selection = new Selection(exception.LineNumber, exception.Position, exception.LineNumber, exception.Position);
            return new NavigateCodeEventArgs(declaration.QualifiedName.QualifiedModuleName, selection);
        }
开发者ID:retailcoder,项目名称:Rubberduck,代码行数:7,代码来源:SyntaxErrorExtensions.cs

示例4: ValuedDeclaration

 public ValuedDeclaration(QualifiedMemberName qualifiedName, string parentScope,
     string asTypeName, Accessibility accessibility, DeclarationType declarationType, string value, 
     ParserRuleContext context, Selection selection, bool isBuiltIn = false)
     :base(qualifiedName, parentScope, asTypeName, true, false, accessibility, declarationType, context, selection, isBuiltIn)
 {
     _value = value;
 }
开发者ID:ThunderFrame,项目名称:Rubberduck,代码行数:7,代码来源:ValuedDeclaration.cs

示例5: FixTypeHintUsage

        private void FixTypeHintUsage(string hint, CodeModule module, Selection selection, bool isDeclaration = false)
        {
            var line = module.Lines[selection.StartLine, 1];

            var asTypeClause = ' ' + Tokens.As + ' ' + TypeHints[hint];

            string fix;

            if (isDeclaration && (Context is VBAParser.FunctionStmtContext || Context is VBAParser.PropertyGetStmtContext))
            {
                var typeHint = (ParserRuleContext)Context.children.First(c => c is VBAParser.TypeHintContext);
                var argList = (ParserRuleContext) Context.children.First(c => c is VBAParser.ArgListContext);
                var endLine = argList.Stop.Line;
                var endColumn = argList.Stop.Column;

                var oldLine = module.Lines[endLine, selection.LineCount];
                fix = oldLine.Insert(endColumn + 1, asTypeClause).Remove(typeHint.Start.Column, 1);  // adjust for VBA 0-based indexing

                module.ReplaceLine(endLine, fix);
            }
            else
            {
                var pattern = "\\b" + _declaration.IdentifierName + "\\" + hint;
                fix = Regex.Replace(line, pattern, _declaration.IdentifierName + (isDeclaration ? asTypeClause : string.Empty));
                module.ReplaceLine(selection.StartLine, fix);
            }
        }
开发者ID:retailcoder,项目名称:Rubberduck,代码行数:27,代码来源:ObsoleteTypeHintInspectionResult.cs

示例6: GetQualifiedSelection

 protected QualifiedSelection GetQualifiedSelection(Selection selection)
 {
     if (_ide.Object.ActiveCodePane == null)
     {
         _ide.Object.ActiveVBProject = _ide.Object.VBProjects.Item(0);
         _ide.Object.ActiveCodePane = _ide.Object.ActiveVBProject.VBComponents.Item(0).CodeModule.CodePane;
     }
     return new QualifiedSelection(new QualifiedModuleName(_ide.Object.ActiveCodePane.CodeModule.Parent), selection);
 }
开发者ID:retailcoder,项目名称:Rubberduck,代码行数:9,代码来源:VbeTestBase.cs

示例7: AmbiguousId

        private Declaration AmbiguousId()
        {
            var values = _model.Declarations.Items.Where(item => (item.Scope.Contains(_model.Target.Scope)
                                              || _model.Target.ParentScope.Contains(item.ParentScope))
                                              && _model.NewName == item.IdentifierName).ToList();

            if (values.Any())
            {
                return values.FirstOrDefault();
            }

            foreach (var reference in _model.Target.References)
            {
                var targetReference = reference;
                var potentialDeclarations = _model.Declarations.Items.Where(item => !item.IsBuiltIn
                                                         && item.Project.Equals(targetReference.Declaration.Project)
                                                         && ((item.Context != null
                                                         && item.Context.Start.Line <= targetReference.Selection.StartLine
                                                         && item.Context.Stop.Line >= targetReference.Selection.EndLine)
                                                         || (item.Selection.StartLine <= targetReference.Selection.StartLine
                                                         && item.Selection.EndLine >= targetReference.Selection.EndLine))
                                                         && item.QualifiedName.QualifiedModuleName.ComponentName == targetReference.QualifiedModuleName.ComponentName);

                var currentSelection = new Selection(0, 0, int.MaxValue, int.MaxValue);

                Declaration target = null;
                foreach (var item in potentialDeclarations)
                {
                    var startLine = item.Context == null ? item.Selection.StartLine : item.Context.Start.Line;
                    var endLine = item.Context == null ? item.Selection.EndLine : item.Context.Stop.Column;
                    var startColumn = item.Context == null ? item.Selection.StartColumn : item.Context.Start.Column;
                    var endColumn = item.Context == null ? item.Selection.EndColumn : item.Context.Stop.Column;

                    var selection = new Selection(startLine, startColumn, endLine, endColumn);

                    if (currentSelection.Contains(selection))
                    {
                        currentSelection = selection;
                        target = item;
                    }
                }

                if (target == null) { continue; }

                values = _model.Declarations.Items.Where(item => (item.Scope.Contains(target.Scope)
                                              || target.ParentScope.Contains(item.ParentScope))
                                              && _model.NewName == item.IdentifierName).ToList();

                if (values.Any())
                {
                    return values.FirstOrDefault();
                }
            }

            return null;
        }
开发者ID:ThunderFrame,项目名称:Rubberduck,代码行数:56,代码来源:RenameRefactoring.cs

示例8: FixTypeHintUsage

        private void FixTypeHintUsage(string hint, CodeModule module, Selection selection, bool isDeclaration = false)
        {
            var line = module.get_Lines(selection.StartLine, 1);

            var asTypeClause = ' ' + Tokens.As + ' ' + TypeHints[hint];
            var pattern = "\\b" + _declaration.IdentifierName + "\\" + hint;
            var fix = Regex.Replace(line, pattern, _declaration.IdentifierName + (isDeclaration ? asTypeClause : string.Empty));

            module.ReplaceLine(selection.StartLine, fix);
        }
开发者ID:ThunderFrame,项目名称:Rubberduck,代码行数:10,代码来源:ObsoleteTypeHintInspectionResult.cs

示例9: SetSelection

        public void SetSelection(Selection selection)
        {
            if (Editor == null)
            {
                return;
            }

            var codePane = _wrapperFactory.Create(Editor.CodePane);
            codePane.Selection = selection;
        }
开发者ID:retailcoder,项目名称:Rubberduck,代码行数:10,代码来源:ActiveCodePaneEditor.cs

示例10: IdentifierReference

 public IdentifierReference(QualifiedModuleName qualifiedName, string identifierName, Selection selection, ParserRuleContext context, Declaration declaration, bool isAssignmentTarget = false, bool hasExplicitLetStatement = false)
 {
     _qualifiedName = qualifiedName;
     _identifierName = identifierName;
     _selection = selection;
     _context = context;
     _declaration = declaration;
     _hasExplicitLetStatement = hasExplicitLetStatement;
     _isAssignmentTarget = isAssignmentTarget;
 }
开发者ID:ThunderFrame,项目名称:Rubberduck,代码行数:10,代码来源:IdentifierReference.cs

示例11: EncapsulatePublicField_WithSetter

        public void EncapsulatePublicField_WithSetter()
        {
            //Input
            const string inputCode =
@"Public fizz As Variant";
            var selection = new Selection(1, 1, 1, 1);

            //Expectation
            const string expectedCode =
@"Private fizz As Variant

Public Property Get Name() As Variant
    Name = fizz
End Property

Public Property Set Name(ByVal value As Variant)
    fizz = value
End Property
";

            //Arrange
            var builder = new MockVbeBuilder();
            VBComponent component;
            var vbe = builder.BuildFromSingleStandardModule(inputCode, out component);
            var project = vbe.Object.VBProjects.Item(0);
            var module = project.VBComponents.Item(0).CodeModule;
            var codePaneFactory = new CodePaneWrapperFactory();
            var mockHost = new Mock<IHostApplication>();
            mockHost.SetupAllProperties();
            var parser = MockParser.Create(vbe.Object, new RubberduckParserState());

            parser.Parse();
            if (parser.State.Status == ParserState.Error) { Assert.Inconclusive("Parser Error"); }

            var qualifiedSelection = new QualifiedSelection(new QualifiedModuleName(component), selection);

            var model = new EncapsulateFieldModel(parser.State, qualifiedSelection)
            {
                ImplementLetSetterType = false,
                ImplementSetSetterType = true,
                ParameterName = "value",
                PropertyName = "Name"
            };

            //SetupFactory
            var factory = SetupFactory(model);

            //Act
            var refactoring = new EncapsulateFieldRefactoring(factory.Object, new ActiveCodePaneEditor(vbe.Object, codePaneFactory));
            refactoring.Refactor(qualifiedSelection);

            //Assert
            Assert.AreEqual(expectedCode, module.Lines());
        }
开发者ID:retailcoder,项目名称:Rubberduck,代码行数:54,代码来源:EncapsulateFieldTests.cs

示例12: Node

        /// <summary>
        /// Represents a context in the code tree.
        /// </summary>
        /// <param name="context">The parser rule context, obtained from an ANTLR-generated parser method.</param>
        /// <param name="parentScope">The scope this context belongs to. <c>null</c> for the root context.</param>
        /// <param name="localScope">The scope this context defines, if any. <c>null</c> if omitted.</param>
        /// <param name="childNodes">The child nodes.</param>
        /// <remarks>
        /// Specifying a <c>localScope</c> ensures child nodes can be added, regardless of 
        /// </remarks>
        protected Node(ParserRuleContext context, string parentScope, string localScope = null, ICollection<Node> childNodes = null)
        {
            _context = context;
            _selection = context.GetSelection();
            _parentScope = parentScope;

            _localScope = localScope;

            _childNodes = (localScope != null && childNodes == null)
                            ? new List<Node>()
                            : childNodes;
        }
开发者ID:retailcoder,项目名称:Rubberduck,代码行数:22,代码来源:Node.cs

示例13: ConstructorWorks_IsNotNull

        public void ConstructorWorks_IsNotNull()
        {
            // arange
            var symbolSelection = new Selection(1, 1, 2, 2);
            var qualifiedSelection = new QualifiedSelection(_module, symbolSelection);

            //act
            //var presenter = new RenamePresenter(_vbe.Object, _view.Object, _declarations, qualifiedSelection);
            Assert.Inconclusive("This test is broken");

            //assert
            //Assert.IsNotNull(presenter, "Successfully initialized");
        }
开发者ID:ThunderFrame,项目名称:Rubberduck,代码行数:13,代码来源:RenamePresenterTests.cs

示例14: GetParameters

        private IEnumerable<Declaration> GetParameters()
        {
            var targetSelection = new Selection(TargetDeclaration.Context.Start.Line,
                TargetDeclaration.Context.Start.Column,
                TargetDeclaration.Context.Stop.Line,
                TargetDeclaration.Context.Stop.Column);

            return Declarations.Where(d => d.DeclarationType == DeclarationType.Parameter
                                       && d.ComponentName == TargetDeclaration.ComponentName
                                       && d.ProjectId == TargetDeclaration.ProjectId
                                       && targetSelection.Contains(d.Selection))
                              .OrderBy(item => item.Selection.StartLine)
                              .ThenBy(item => item.Selection.StartColumn);
        }
开发者ID:retailcoder,项目名称:Rubberduck,代码行数:14,代码来源:RemoveParametersModel.cs

示例15: GetSelectedProcedureScope

        public string GetSelectedProcedureScope(Selection selection)
        {
            var moduleName = Editor.Name;
            var projectName = Editor.Parent.Collection.Parent.Name;
            var parentScope = projectName + '.' + moduleName;

            vbext_ProcKind kind;
            var procStart = Editor.get_ProcOfLine(selection.StartLine, out kind);
            var procEnd = Editor.get_ProcOfLine(selection.EndLine, out kind);

            return procStart == procEnd
                ? parentScope + '.' + procStart
                : null;
        }
开发者ID:ThunderFrame,项目名称:Rubberduck,代码行数:14,代码来源:ActiveCodePaneEditor.cs


注:本文中的Rubberduck.VBEditor.Selection类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。