/// <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);
        }
 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;
 }
 public ParameterCanBeByValInspectionResult(IInspection inspection, Declaration target, ParserRuleContext context, QualifiedMemberName qualifiedName)
     : base(inspection, qualifiedName.QualifiedModuleName, context, target)
 {
     _quickFixes = new[]
     {
         new PassParameterByValueQuickFix(Context, QualifiedSelection), 
     };
 }
 public ParameterNotUsedInspectionResult(string inspection, CodeInspectionSeverity type,
     ParserRuleContext context, QualifiedMemberName qualifiedName, bool isInterfaceImplementation, RemoveParametersRefactoring quickFixRefactoring, VBProjectParseResult parseResult)
     : base(inspection, type, qualifiedName.QualifiedModuleName, context)
 {
     _isInterfaceImplementation = isInterfaceImplementation;
     _quickFixRefactoring = quickFixRefactoring;
     _parseResult = parseResult;
 }
 public FunctionReturnValueNotUsedInspectionResult(
     IInspection inspection,
     ParserRuleContext context,
     QualifiedMemberName qualifiedName,
     IEnumerable<string> returnStatements,
     Declaration target)
     : this(inspection, context, qualifiedName, returnStatements, new List<Tuple<ParserRuleContext, QualifiedSelection, IEnumerable<string>>>(), target)
 {
 }
 public ParameterNotUsedInspectionResult(IInspection inspection, Declaration target,
     ParserRuleContext context, QualifiedMemberName qualifiedName, bool isInterfaceImplementation, 
     RemoveParametersRefactoring refactoring, RubberduckParserState parseResult)
     : base(inspection, qualifiedName.QualifiedModuleName, context, target)
 {
     _quickFixes = isInterfaceImplementation ? new CodeInspectionQuickFix[] {} : new CodeInspectionQuickFix[]
     {
         new RemoveUnusedParameterQuickFix(Context, QualifiedSelection, refactoring, parseResult),
         new IgnoreOnceQuickFix(Context, QualifiedSelection, Inspection.AnnotationName), 
     };
 }
 /// <summary>
 /// Creates a new built-in parameter declaration.
 /// </summary>
 public ParameterDeclaration(QualifiedMemberName qualifiedName, 
     Declaration parentDeclaration, 
     string asTypeName, 
     bool isOptional, 
     bool isByRef, 
     bool isArray = false, 
     bool isParamArray = false)
     : base(qualifiedName, parentDeclaration, parentDeclaration, asTypeName, false, false, Accessibility.Implicit, DeclarationType.Parameter, null, Selection.Home)
 {
     _isOptional = isOptional;
     _isByRef = isByRef;
     _isArray = isArray;
     _isParamArray = isParamArray;
 }
Esempio n. 8
0
 public Declaration(QualifiedMemberName qualifiedName, string parentScope,
     string asTypeName, bool isSelfAssigned, bool isWithEvents,
     Accessibility accessibility, DeclarationType declarationType, ParserRuleContext context, Selection selection, bool isBuiltIn = false)
 {
     _qualifiedName = qualifiedName;
     _parentScope = parentScope;
     _identifierName = qualifiedName.MemberName;
     _asTypeName = asTypeName;
     _isSelfAssigned = isSelfAssigned;
     _isWithEvents = isWithEvents;
     _accessibility = accessibility;
     _declarationType = declarationType;
     _selection = selection;
     _context = context;
     _isBuiltIn = isBuiltIn;
 }
 public FunctionReturnValueNotUsedInspectionResult(
     IInspection inspection,
     ParserRuleContext context,
     QualifiedMemberName qualifiedName,
     IEnumerable<string> returnStatements,
     IEnumerable<Tuple<ParserRuleContext, QualifiedSelection, IEnumerable<string>>> children,
     Declaration target)
     : base(inspection, qualifiedName.QualifiedModuleName, context, target)
 {
     var root = new ConvertToProcedureQuickFix(context, QualifiedSelection, returnStatements);
     var compositeFix = new CompositeCodeInspectionFix(root);
     children.ToList().ForEach(child => compositeFix.AddChild(new ConvertToProcedureQuickFix(child.Item1, child.Item2, child.Item3)));
     _quickFixes = new[]
     {
         compositeFix
     };
 }
Esempio n. 10
0
 public ProjectDeclaration(
     QualifiedMemberName qualifiedName,
     string name)
     : base(
           qualifiedName,
           null,
           (Declaration)null, 
           name, 
           false, 
           false, 
           Accessibility.Implicit, 
           DeclarationType.Project,
           null,
           Selection.Home,
           false)
 {
     _projectReferences = new List<ProjectReference>();
 }
        public VBProjectParseResult(VBProject project, IEnumerable<VBComponentParseResult> parseResults)
        {
            _project = project;
            _parseResults = parseResults;
            _declarations = new Declarations();

            var projectIdentifier = project.Name;
            var memberName = new QualifiedMemberName(new QualifiedModuleName(project), projectIdentifier);
            var projectDeclaration = new Declaration(memberName, "VBE", projectIdentifier, false, false, Accessibility.Global, DeclarationType.Project, false);
            _declarations.Add(projectDeclaration);

            foreach (var declaration in VbaStandardLib.Declarations)
            {
                _declarations.Add(declaration);
            }

            foreach (var declaration in _parseResults.SelectMany(item => item.Declarations))
            {
                _declarations.Add(declaration);
            }
        }
Esempio n. 12
0
 public TestMethodEventArgs(QualifiedMemberName qualifiedMemberName)
     :base(qualifiedMemberName.QualifiedModuleName)
 {
     _qualifiedMemberName = qualifiedMemberName;
 }
Esempio n. 13
0
 public QualifiedContext(QualifiedMemberName memberName, ParserRuleContext context)
     : this(memberName.QualifiedModuleName, context)
 {
     _memberName = memberName;
 }
Esempio n. 14
0
 /// <summary>
 /// Creates a new valued built-in declaration.
 /// </summary>
 public ValuedDeclaration(QualifiedMemberName qualifiedName, string parentScope,
     string asTypeName, Accessibility accessibility, DeclarationType declarationType, string value)
     : this(qualifiedName, parentScope, asTypeName, accessibility, declarationType, value, null, Selection.Home, true)
 {
 }
 public ParameterCanBeByValInspectionResult(string inspection, CodeInspectionSeverity type,
     ParserRuleContext context, QualifiedMemberName qualifiedName)
     : base(inspection, type, qualifiedName.QualifiedModuleName, context)
 {
 }
        public void AcquireTarget_MethodRenamingMoreComponents_CorrectTargetChosen()
        {
            // arange
            // initial selection
            var symbolSelection = new Selection(4, 5, 4, 8);
            var selectedComponent = new QualifiedModuleName("TestProject", "Module1");
            var qualifiedSelection = new QualifiedSelection(selectedComponent, symbolSelection);

            // just for passing null reference exception            
            var context = new Mock<ParserRuleContext>();
            context.SetupGet(c => c.Start.Line).Returns(-1);
            context.SetupGet(c => c.Stop.Line).Returns(-1);
            context.SetupGet(c => c.Stop.Text).Returns("Fake");

            // simulate all the components and symbols   
            IdentifierReference reference;
            var differentComponent = new QualifiedModuleName("TestProject", "Module2");
            var differentMember = new QualifiedMemberName(differentComponent, "Module2");
            AddDeclarationItem(context, new Selection(4, 9, 4, 16), differentMember, DeclarationType.Variable, "FooTest");

            // add references to the Foo declaration item to simulate prod usage
            AddDeclarationItem(context, new Selection(3, 5, 3, 8), differentMember, DeclarationType.Procedure, "Foo");
            var declarationItem = _listDeclarations[_listDeclarations.Count - 1];
            reference = new IdentifierReference(selectedComponent, "Foo", new Selection(7, 5, 7, 11), context.Object, declarationItem);
            AddReference(declarationItem, reference);
            reference = new IdentifierReference(selectedComponent, "Foo", symbolSelection, context.Object, declarationItem);
            AddReference(declarationItem, reference);

            AddDeclarationItem(context, new Selection(1, 1, 1, 1), differentMember, DeclarationType.Module, "Module2");
            var member = new QualifiedMemberName(selectedComponent, "fakeModule");
            AddDeclarationItem(context, new Selection(7, 5, 7, 11), member, DeclarationType.Procedure, "RunFoo");
            AddDeclarationItem(context, new Selection(3, 5, 3, 9), member, DeclarationType.Procedure, "Main");
            AddDeclarationItem(context, new Selection(1, 1, 1, 1), member, DeclarationType.Module, "Module1");

            _view.Setup(view => view.ShowDialog()).Returns(DialogResult.Cancel);
            _view.SetupProperty(view => view.Target);

            //act
            //var presenter = new RenamePresenter(_vbe.Object, _view.Object, _declarations, qualifiedSelection);
            //presenter.Show();

            Assert.Inconclusive("This test is broken");

            //assert
            var retVal = _view.Object.Target;
            Assert.AreEqual("Foo", retVal.IdentifierName, "Selected the correct symbol name");
            Assert.AreEqual(declarationItem.References.Count(), retVal.References.Count());
        }
        public void AcquireTarget_MethodRenamingAtSameComponent_CorrectTargetChosen()
        {
            // arange
            var symbolSelection = new Selection(8, 1, 8, 16);
            var selectedComponent = new QualifiedModuleName("TestProject", "TestModule");
            var qualifiedSelection = new QualifiedSelection(selectedComponent, symbolSelection);

            // just for passing null reference exception            
            var context = new Mock<ParserRuleContext>();
            context.SetupGet(c => c.Start.Line).Returns(1);
            context.SetupGet(c => c.Stop.Line).Returns(2);
            context.SetupGet(c => c.Stop.Text).Returns("Four");

            // simulate all the components and symbols   
            var member = new QualifiedMemberName(selectedComponent, "fakeModule");
            const string identifierName = "Foo";
            AddDeclarationItem(context, symbolSelection, member, DeclarationType.Procedure, identifierName);
            AddDeclarationItem(context, new Selection(1, 1, 1, 16), member, DeclarationType.Procedure);
            AddDeclarationItem(context, new Selection(1, 1, 1, 1), member, DeclarationType.Module);

            // allow Moq to set the Target property
            _view.Setup(view => view.ShowDialog()).Returns(DialogResult.Cancel);
            _view.SetupProperty(view => view.Target);

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

            //assert
            var retVal = _view.Object.Target;
            Assert.AreEqual(symbolSelection, retVal.Selection, "Returns only the declaration on the desired selection");
            Assert.AreEqual(identifierName, retVal.IdentifierName);
        }
Esempio n. 18
0
 public Declaration(QualifiedMemberName qualifiedName, string parentScope,
     string asTypeName, bool isSelfAssigned, bool isWithEvents,
     Accessibility accessibility, DeclarationType declarationType, bool isBuiltIn = true)
     :this(qualifiedName, parentScope, asTypeName, isSelfAssigned, isWithEvents, accessibility, declarationType, null, Selection.Home, isBuiltIn)
 {}
 public MultilineParameterInspectionResult(string inspection, CodeInspectionSeverity severity, ParserRuleContext context, QualifiedMemberName qualifiedName)
     : base(inspection, severity, qualifiedName.QualifiedModuleName, context)
 {
     
 }