Exemplo n.º 1
0
 public void EvaluateCanExecute(RubberduckParserState state)
 {
     foreach (var menu in _menus)
     {
         menu.EvaluateCanExecute(state);
     }
 }
Exemplo n.º 2
0
 public RenameRefactoring(IRefactoringPresenterFactory<IRenamePresenter> factory, IActiveCodePaneEditor editor, IMessageBox messageBox, RubberduckParserState state)
 {
     _factory = factory;
     _editor = editor;
     _messageBox = messageBox;
     _state = state;
 }
 public RemoveUnusedParameterQuickFix(ParserRuleContext context, QualifiedSelection selection, 
     RemoveParametersRefactoring quickFixRefactoring, RubberduckParserState parseResult)
     : base(context, selection, InspectionsUI.RemoveUnusedParameterQuickFix)
 {
     _quickFixRefactoring = quickFixRefactoring;
     _parseResult = parseResult;
 }
            private ParseTreeResults GetParseTreeResults(RubberduckParserState state)
            {
                var result = new ParseTreeResults();

                foreach (var componentTreePair in state.ParseTrees)
                {
                    /*
                    Need to reinitialize these for each and every ParseTree we process, since the results are aggregated in the instances themselves 
                    before moving them into the ParseTreeResults after qualifying them 
                    */
                    var obsoleteCallStatementListener = new ObsoleteCallStatementInspection.ObsoleteCallStatementListener();
                    var obsoleteLetStatementListener = new ObsoleteLetStatementInspection.ObsoleteLetStatementListener();
                    var emptyStringLiteralListener = new EmptyStringLiteralInspection.EmptyStringLiteralListener();
                    var argListWithOneByRefParamListener = new ProcedureCanBeWrittenAsFunctionInspection.ArgListWithOneByRefParamListener();
                    var malformedAnnotationListener = new MalformedAnnotationInspection.MalformedAnnotationStatementListener();

                    var combinedListener = new CombinedParseTreeListener(new IParseTreeListener[]{
                        obsoleteCallStatementListener,
                        obsoleteLetStatementListener,
                        emptyStringLiteralListener,
                        argListWithOneByRefParamListener,
                        malformedAnnotationListener
                    });

                    ParseTreeWalker.Default.Walk(combinedListener, componentTreePair.Value);

                    result.ArgListsWithOneByRefParam = result.ArgListsWithOneByRefParam.Concat(argListWithOneByRefParamListener.Contexts.Select(context => new QualifiedContext(componentTreePair.Key, context)));
                    result.EmptyStringLiterals = result.EmptyStringLiterals.Concat(emptyStringLiteralListener.Contexts.Select(context => new QualifiedContext(componentTreePair.Key, context)));
                    result.ObsoleteLetContexts = result.ObsoleteLetContexts.Concat(obsoleteLetStatementListener.Contexts.Select(context => new QualifiedContext(componentTreePair.Key, context)));
                    result.ObsoleteCallContexts = result.ObsoleteCallContexts.Concat(obsoleteCallStatementListener.Contexts.Select(context => new QualifiedContext(componentTreePair.Key, context)));
                    result.MalformedAnnotations = result.MalformedAnnotations.Concat(malformedAnnotationListener.Contexts.Select(context => new QualifiedContext(componentTreePair.Key, context)));
                }
                return result;
            }
 public RenameProjectQuickFix(ParserRuleContext context, QualifiedSelection selection, Declaration target, RubberduckParserState state, ICodePaneWrapperFactory wrapperFactory)
     : base(context, selection, string.Format(RubberduckUI.Rename_DeclarationType, RubberduckUI.ResourceManager.GetString("DeclarationType_" + DeclarationType.Project, RubberduckUI.Culture)))
 {
     _target = target;
     _state = state;
     _wrapperFactory = wrapperFactory;
 }
 public ToDoExplorerViewModel(RubberduckParserState state, IGeneralConfigService configService)
 {
     _dispatcher = Dispatcher.CurrentDispatcher;
     _state = state;
     _configService = configService;
     _state.StateChanged += _state_StateChanged;
 }
 public ShowParserErrorsCommand(INavigateCommand navigateCommand, RubberduckParserState state, ISearchResultsWindowViewModel viewModel, SearchResultPresenterInstanceManager presenterService)
 {
     _navigateCommand = navigateCommand;
     _state = state;
     _viewModel = viewModel;
     _presenterService = presenterService;
 }
Exemplo n.º 8
0
 protected InspectionBase(RubberduckParserState state, CodeInspectionSeverity defaultSeverity = CodeInspectionSeverity.Warning)
 {
     State = state;
     _defaultSeverity = defaultSeverity;
     Severity = _defaultSeverity;
     _name = GetType().Name;
 }
Exemplo n.º 9
0
 public static RubberduckParser Create(VBE vbe, RubberduckParserState state)
 {
     var attributeParser = new Mock<IAttributeParser>();
     attributeParser.Setup(m => m.Parse(It.IsAny<VBComponent>()))
                    .Returns(() => new Dictionary<Tuple<string, DeclarationType>, Attributes>());
     return Create(vbe, state, attributeParser.Object);
 }
 public ParameterNotUsedInspection(VBE vbe, RubberduckParserState state, IMessageBox messageBox)
     : base(state)
 {
     _vbe = vbe;
     _messageBox = messageBox;
     _wrapperFactory = new CodePaneWrapperFactory();
 }
Exemplo n.º 11
0
 public ParserState()
 {
     _state = new RubberduckParserState();
     _attributeParser = new AttributeParser(new ModuleExporter());
     
     _state.StateChanged += _state_StateChanged;
 }
Exemplo n.º 12
0
        public EncapsulateFieldModel(RubberduckParserState parseResult, QualifiedSelection selection)
        {
            IList<Declaration> declarations = parseResult.AllDeclarations
                                                        .Where(d => !d.IsBuiltIn && d.DeclarationType == DeclarationType.Variable)
                                                        .ToList();

            TargetDeclaration = declarations.FindVariable(selection);
        }
 public DefaultProjectNameInspectionResult(IInspection inspection, Declaration target, RubberduckParserState parseResult, ICodePaneWrapperFactory wrapperFactory)
     : base(inspection, target)
 {
     _quickFixes = new[]
     {
         new RenameProjectQuickFix(target.Context, target.QualifiedSelection, target, parseResult, wrapperFactory),
     };
 }
Exemplo n.º 14
0
 public RubberduckCommandBar(RubberduckParserState state, VBE vbe, IShowParserErrorsCommand command)
 {
     _state = state;
     _vbe = vbe;
     _command = command;
     _state.StateChanged += State_StateChanged;
     Initialize();
 }
 public MoveFieldCloserToUsageQuickFix(ParserRuleContext context, QualifiedSelection selection, Declaration target, RubberduckParserState parseResult, ICodePaneWrapperFactory wrapperFactory, IMessageBox messageBox)
     : base(context, selection, string.Format(InspectionsUI.MoveFieldCloserToUsageInspectionResultFormat, target.IdentifierName))
 {
     _target = target;
     _parseResult = parseResult;
     _wrapperFactory = wrapperFactory;
     _messageBox = messageBox;
 }
 public MoveFieldCloserToUsageInspectionResult(IInspection inspection, Declaration target, RubberduckParserState parseResult, ICodePaneWrapperFactory wrapperFactory, IMessageBox messageBox)
     : base(inspection, target)
 {
     _quickFixes = new[]
     {
         new MoveFieldCloserToUsageQuickFix(target.Context, target.QualifiedSelection, target, parseResult, wrapperFactory, messageBox),
     };
 }
 public IntroduceFieldRefactoring(RubberduckParserState parserState, IActiveCodePaneEditor editor, IMessageBox messageBox)
 {
     _declarations =
         parserState.AllDeclarations.Where(i => !i.IsBuiltIn && i.DeclarationType == DeclarationType.Variable)
             .ToList();
     _editor = editor;
     _messageBox = messageBox;
 }
        public void QuickFix(RubberduckParserState parseResult, QualifiedSelection selection)
        {
            _model = new RemoveParametersModel(parseResult, selection, new MessageBox());
            var target = _model.Declarations.FindTarget(selection, new[] { DeclarationType.Parameter });

            // ReSharper disable once PossibleUnintendedReferenceComparison
            _model.Parameters.Find(param => param.Declaration == target).IsRemoved = true;
            RemoveParameters();
        }
Exemplo n.º 19
0
        public CodeExplorerViewModel(RubberduckParserState state, INavigateCommand navigateCommand)
        {
            _state = state;
            _navigateCommand = navigateCommand;
            _state.StateChanged += ParserState_StateChanged;
            _state.ModuleStateChanged += ParserState_ModuleStateChanged;

            _refreshCommand = new DelegateCommand(ExecuteRefreshCommand);
        }
 public FindAllReferencesCommand(INavigateCommand navigateCommand, IMessageBox messageBox, RubberduckParserState state, VBE vbe, ISearchResultsWindowViewModel viewModel, SearchResultPresenterInstanceManager presenterService)
 {
     _navigateCommand = navigateCommand;
     _messageBox = messageBox;
     _state = state;
     _vbe = vbe;
     _viewModel = viewModel;
     _presenterService = presenterService;
 }
 public UseMeaningfulNameInspectionResult(IInspection inspection, Declaration target, RubberduckParserState parserState, ICodePaneWrapperFactory wrapperFactory, IMessageBox messageBox)
     : base(inspection, target)
 {
     _quickFixes = new CodeInspectionQuickFix[]
     {
         new RenameDeclarationQuickFix(target.Context, target.QualifiedSelection, target, parserState, wrapperFactory, messageBox),
         new IgnoreOnceQuickFix(Context, QualifiedSelection, Inspection.AnnotationName), 
     };
 }
Exemplo n.º 22
0
        public RenameModel(VBE vbe, RubberduckParserState parseResult, QualifiedSelection selection, IMessageBox messageBox)
        {
            _vbe = vbe;
            _parseResult = parseResult;
            _declarations = parseResult.AllDeclarations.ToList();
            _selection = selection;
            _messageBox = messageBox;

            AcquireTarget(out _target, Selection);
        }
        public ReorderParametersModel(RubberduckParserState parseResult, QualifiedSelection selection, IMessageBox messageBox)
        {
            _parseResult = parseResult;
            _declarations = parseResult.AllUserDeclarations;
            _messageBox = messageBox;

            AcquireTarget(selection);

            Parameters = new List<Parameter>();
            LoadParameters();
        }
 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), 
     };
 }
Exemplo n.º 25
0
        public RubberduckParser(VBE vbe, RubberduckParserState state, IAttributeParser attributeParser)
        {
            _resolverTokenSource = CancellationTokenSource.CreateLinkedTokenSource(_central.Token);
            _vbe = vbe;
            _state = state;
            _attributeParser = attributeParser;

            _comReflector = new ReferencedDeclarationsCollector();

            state.ParseRequest += ReparseRequested;
            state.StateChanged += StateOnStateChanged;
        }
 public ChangeProcedureToFunction(RubberduckParserState state,
                                  QualifiedContext<VBAParser.ArgListContext> argListQualifiedContext,
                                  QualifiedContext<VBAParser.SubStmtContext> subStmtQualifiedContext,
                                  QualifiedSelection selection)
     : base(subStmtQualifiedContext.Context, selection, InspectionsUI.ProcedureShouldBeFunctionInspectionQuickFix)
 {
     _state = state;
     _argListQualifiedContext = argListQualifiedContext;
     _subStmtQualifiedContext = subStmtQualifiedContext;
     _argQualifiedContext = new QualifiedContext<VBAParser.ArgContext>(_argListQualifiedContext.ModuleName,
         _argListQualifiedContext.Context.arg()
             .First(a => a.BYREF() != null || (a.BYREF() == null && a.BYVAL() == null)));
 }
       public ProcedureShouldBeFunctionInspectionResult(IInspection inspection, RubberduckParserState state, QualifiedContext<VBAParser.ArgListContext> argListQualifiedContext, QualifiedContext<VBAParser.SubStmtContext> subStmtQualifiedContext)
           : base(inspection,
                subStmtQualifiedContext.ModuleName,
                subStmtQualifiedContext.Context.ambiguousIdentifier())
        {
           _target = state.AllUserDeclarations.Single(declaration => 
               declaration.DeclarationType == DeclarationType.Procedure
               && declaration.Context == subStmtQualifiedContext.Context);

            _quickFixes = new[]
            {
                new ChangeProcedureToFunction(state, argListQualifiedContext, subStmtQualifiedContext, QualifiedSelection), 
            };
        }
 private string Parse(string code)
 {
     var builder = new MockVbeBuilder();
     VBComponent component;
     var vbe = builder.BuildFromSingleStandardModule(code, out component);
     var mockHost = new Mock<IHostApplication>();
     mockHost.SetupAllProperties();
     var state = new RubberduckParserState();
     var parser = MockParser.Create(vbe.Object, state);
     parser.Parse();
     if (parser.State.Status == ParserState.Error) { Assert.Inconclusive("Parser Error"); }
     var tree = state.GetParseTree(component);
     var parsed = tree.GetText();
     var withoutEOF = parsed.Substring(0, parsed.Length - 5);
     return withoutEOF;
 }
            public DefaultInspector(IEnumerable<IInspection> inspections, RubberduckParserState state)
            {
                _inspections = inspections.ToList();

                if (_inspections.All(i => i.Name != nameof(ParameterNotUsedInspection)))
                {
                    _inspections.Add(new ParameterNotUsedInspection(null, state, null));
                }

                if (_inspections.All(i => i.Name != nameof(UseMeaningfulNameInspection)))
                {
                    var settings = new Mock<IPersistanceService<CodeInspectionSettings>>();
                    settings.Setup(s => s.Load(It.IsAny<CodeInspectionSettings>()))
                        .Returns(new CodeInspectionSettings());
                    _inspections.Add(new UseMeaningfulNameInspection(null, state, settings.Object));
                }
            }
Exemplo n.º 30
0
            public async Task<IList<ICodeInspectionResult>> FindIssuesAsync(RubberduckParserState state, CancellationToken token)
            {
                if (state == null || !state.AllUserDeclarations.Any())
                {
                    return new ICodeInspectionResult[] { };
                }

                await Task.Yield();

                state.OnStatusMessageUpdate(RubberduckUI.CodeInspections_Inspecting);
                UpdateInspectionSeverity();
                //OnReset();

                var allIssues = new ConcurrentBag<ICodeInspectionResult>();

                var inspections = _inspections.Where(inspection => inspection.Severity != CodeInspectionSeverity.DoNotShow)
                    .Select(inspection =>
                        new Task(() =>
                        {
                            token.ThrowIfCancellationRequested();
                            var inspectionResults = inspection.GetInspectionResults();
                            var results = inspectionResults as IList<InspectionResultBase> ?? inspectionResults.ToList();

                            if (results.Any())
                            {
                                //OnIssuesFound(results);

                                foreach (var inspectionResult in results)
                                {
                                    allIssues.Add(inspectionResult);
                                }
                            }
                        })).ToArray();

                foreach (var inspection in inspections)
                {
                    inspection.Start();
                }

                Task.WaitAll(inspections);
                state.OnStatusMessageUpdate(RubberduckUI.ResourceManager.GetString("ParserState_" + state.Status)); // should be "Ready"

                return allIssues.ToList();
            }
Exemplo n.º 31
0
 public ParserStateManager(RubberduckParserState state)
     : base(state)
 {
 }