コード例 #1
0
        private static QualifiedMemberName?GetQualifiedMemberName(IDeclarationFinderProvider declarationFinderProvider, IdentifierReference reference)
        {
            var members = declarationFinderProvider.DeclarationFinder.Members(reference.QualifiedModuleName);

            return(members.SingleOrDefault(m => reference.Context.IsDescendentOf(m.Context))?.QualifiedName);
        }
コード例 #2
0
 public MultilineParameterInspection(IDeclarationFinderProvider declarationFinderProvider)
     : base(declarationFinderProvider)
 {
     ContextListener = new ParameterListener();
 }
コード例 #3
0
 public ImplicitContainingWorkbookReferenceInspection(IDeclarationFinderProvider declarationFinderProvider)
     : base(declarationFinderProvider)
 {
 }
コード例 #4
0
 public ChangeIntegerToLongQuickFix(IDeclarationFinderProvider declarationFinderProvider)
     : base(typeof(IntegerDataTypeInspection))
 {
     _declarationFinderProvider = declarationFinderProvider;
 }
コード例 #5
0
 protected DeclarationInspectionBase(IDeclarationFinderProvider declarationFinderProvider, DeclarationType[] relevantDeclarationTypes, DeclarationType[] excludeDeclarationTypes)
     : base(declarationFinderProvider, relevantDeclarationTypes, excludeDeclarationTypes)
 {
 }
コード例 #6
0
        /// <summary>
        /// Determines whether the 'Set' keyword is required (whether it's present or not) for the specified identifier reference.
        /// </summary>
        /// <param name="reference">The identifier reference to analyze</param>
        /// <param name="declarationFinderProvider">The parser state</param>
        public static bool RequiresSetAssignment(IdentifierReference reference, IDeclarationFinderProvider declarationFinderProvider)
        {
            if (!reference.IsAssignment)
            {
                // reference isn't assigning its declaration; not interesting
                return(false);
            }

            if (reference.IsSetAssignment)
            {
                // don't assume Set keyword is legit...
                return(reference.Declaration.IsObject);
            }

            var declaration = reference.Declaration;

            if (declaration.IsArray)
            {
                // arrays don't need a Set statement... todo figure out if array items are objects
                return(false);
            }

            var isObjectVariable = declaration.IsObject;

            if (!isObjectVariable && !(declaration.IsUndeclared || Tokens.Variant.Equals(declaration.AsTypeName)))
            {
                return(false);
            }

            // For Each iterators are implicitly set.
            var letStmtContext = reference.Context.GetAncestor <VBAParser.LetStmtContext>();

            if (reference.Context.GetAncestor <VBAParser.ForEachStmtContext>() != null && letStmtContext == null)
            {
                return(false);
            }

            if (isObjectVariable)
            {
                // get the members of the returning type, a default member could make us lie otherwise
                var classModule = declaration.AsTypeDeclaration as ClassModuleDeclaration;
                return(!HasPotentiallyNonObjectParameterlessDefaultMember(classModule));
            }

            // assigned declaration is a variant. we need to know about the RHS of the assignment.
            if (letStmtContext == null)
            {
                // not an assignment
                return(false);
            }

            var expression = letStmtContext.expression();

            if (expression == null)
            {
                Debug.Assert(false, "RHS expression is empty? What's going on here?");
                return(false);
            }


            var module = Declaration.GetModuleParent(reference.ParentScoping);

            if (expression is VBAParser.NewExprContext newExpr)
            {
                var newTypeExpression = newExpr.expression();

                // todo resolve expression type

                //Covers the case of a single type on the RHS of the assignment.
                var simpleTypeName = newTypeExpression.GetDescendent <VBAParser.SimpleNameExprContext>();
                if (simpleTypeName != null && simpleTypeName.GetText() == newTypeExpression.GetText())
                {
                    var qualifiedIdentifierSelection = new QualifiedSelection(module.QualifiedModuleName,
                                                                              simpleTypeName.identifier().GetSelection());
                    var identifierText = simpleTypeName.identifier().GetText();
                    return(declarationFinderProvider.DeclarationFinder.IdentifierReferences(qualifiedIdentifierSelection)
                           .Select(identifierReference => identifierReference.Declaration)
                           .Where(decl => identifierText == decl.IdentifierName)
                           .OfType <ClassModuleDeclaration>()
                           .Any(typeDecl => !HasPotentiallyNonObjectParameterlessDefaultMember(typeDecl)));
                }
                //Here, we err on the side of false-positives, but that seems more appropriate than not to treat qualified type expressions incorrectly.
                //Whether there is a legitimate use here for default members is questionable anyway.
                return(true);
            }

            var literalExpression = expression as VBAParser.LiteralExprContext;

            if (literalExpression?.literalExpression()?.literalIdentifier()?.objectLiteralIdentifier() != null)
            {
                // RHS is a 'Nothing' token - LHS needs a 'Set' keyword:
                return(true);
            }
            if (literalExpression != null)
            {
                return(false); // any other literal expression definitely isn't an object.
            }

            // todo resolve expression return type

            //Covers the case of a single variable on the RHS of the assignment.
            var simpleName = expression.GetDescendent <VBAParser.SimpleNameExprContext>();

            if (simpleName != null && simpleName.GetText() == expression.GetText())
            {
                var qualifiedIdentifierSelection = new QualifiedSelection(module.QualifiedModuleName,
                                                                          simpleName.identifier().GetSelection());
                return(declarationFinderProvider.DeclarationFinder.IdentifierReferences(qualifiedIdentifierSelection)
                       .Select(identifierReference => identifierReference.Declaration)
                       .Where(decl => decl.IsObject &&
                              simpleName.identifier().GetText() == decl.IdentifierName)
                       .Select(typeDeclaration => typeDeclaration.AsTypeDeclaration as ClassModuleDeclaration)
                       .Any(typeDecl => !HasPotentiallyNonObjectParameterlessDefaultMember(typeDecl)));
            }

            var project = Declaration.GetProjectParent(reference.ParentScoping);

            //todo: Use code path analysis to ensure that we are really picking up the last assignment to the RHS.
            // is the reference referring to something else in scope that's a object?
            return(declarationFinderProvider.DeclarationFinder.MatchName(expression.GetText())
                   .Any(decl => (decl.DeclarationType.HasFlag(DeclarationType.ClassModule) || Tokens.Object.Equals(decl.AsTypeName)) &&
                        AccessibilityCheck.IsAccessible(project, module, reference.ParentScoping, decl)));
        }
コード例 #7
0
 public ExpandBangNotationQuickFix(IDeclarationFinderProvider declarationFinderProvider)
     : base(typeof(UseOfBangNotationInspection), typeof(UseOfRecursiveBangNotationInspection))
 {
     _declarationFinderProvider = declarationFinderProvider;
 }
コード例 #8
0
 public SetTypeResolver(IDeclarationFinderProvider declarationFinderProvider)
 {
     _declarationFinderProvider = declarationFinderProvider;
 }
コード例 #9
0
 protected ParseTreeInspectionBase(IDeclarationFinderProvider declarationFinderProvider)
     : base(declarationFinderProvider)
 {
 }
コード例 #10
0
 public ImplicitVariantReturnTypeInspection(IDeclarationFinderProvider declarationFinderProvider)
     : base(declarationFinderProvider, DeclarationType.Function)
 {
 }
コード例 #11
0
 public DefaultProjectNameInspection(IDeclarationFinderProvider declarationFinderProvider)
     : base(declarationFinderProvider, DeclarationType.Project)
 {
 }
コード例 #12
0
 public VariableTypeNotDeclaredInspection(IDeclarationFinderProvider declarationFinderProvider)
     : base(declarationFinderProvider, new [] { DeclarationType.Parameter, DeclarationType.Variable }, new[] { DeclarationType.Control })
 {
 }
コード例 #13
0
 public EmptyMethodInspection(IDeclarationFinderProvider declarationFinderProvider)
     : base(declarationFinderProvider, DeclarationType.Member)
 {
 }
コード例 #14
0
        private static IRefactoring TestRefactoring(IRewritingManager rewritingManager, IDeclarationFinderProvider declarationFinderProvider, IMessageBox msgBox = null)
        {
            var selectionService = MockedSelectionService();

            if (msgBox == null)
            {
                msgBox = new Mock <IMessageBox>().Object;
            }
            return(new MoveCloserToUsageRefactoring(declarationFinderProvider, msgBox, rewritingManager, selectionService));
        }
コード例 #15
0
 public IntroduceParameterRefactoringAction(IDeclarationFinderProvider declarationFinderProvider, IRewritingManager rewritingManager)
     : base(rewritingManager)
 {
     _declarationFinderProvider = declarationFinderProvider;
 }
コード例 #16
0
 public ShadowedDeclarationInspection(IDeclarationFinderProvider declarationFinderProvider)
     : base(declarationFinderProvider)
 {
 }
コード例 #17
0
 public ParameterCanBeByValInspection(IDeclarationFinderProvider declarationFinderProvider)
     : base(declarationFinderProvider, DeclarationType.Parameter)
 {
 }
コード例 #18
0
 public DefTypeStatementInspection(IDeclarationFinderProvider declarationFinderProvider)
     : base(declarationFinderProvider)
 {
     ContextListener = new DefTypeStatementInspectionListener();
 }
 private static Declaration GetUniquelyNamedDeclaration(IDeclarationFinderProvider declarationFinderProvider, DeclarationType declarationType, string identifier)
 {
     return(declarationFinderProvider.DeclarationFinder.UserDeclarations(declarationType).Single(d => d.IdentifierName.Equals(identifier)));
 }
コード例 #20
0
 public UnassignedVariableUsageInspection(IDeclarationFinderProvider declarationFinderProvider)
     : base(declarationFinderProvider)
 {
 }
コード例 #21
0
 public UseBackingFieldsStrategyConflictFinder(IDeclarationFinderProvider declarationFinderProvider, IEnumerable <IEncapsulateFieldCandidate> candidates, IEnumerable <IUserDefinedTypeMemberCandidate> udtCandidates)
     : base(declarationFinderProvider, candidates, udtCandidates)
 {
 }
コード例 #22
0
 public SheetAccessedUsingStringInspection(IDeclarationFinderProvider declarationFinderProvider, IProjectsProvider projectsProvider)
     : base(declarationFinderProvider)
 {
     _projectsProvider = projectsProvider;
 }
コード例 #23
0
 protected DeclarationInspectionBase(IDeclarationFinderProvider declarationFinderProvider, params DeclarationType[] relevantDeclarationTypes)
     : base(declarationFinderProvider, relevantDeclarationTypes)
 {
 }
コード例 #24
0
 public RunSelectedTestMethodCommand(ITestEngine engine, ISelectionService selectionService, IDeclarationFinderProvider finderProvider)
     : base(LogManager.GetCurrentClassLogger())
 {
     _engine           = engine;
     _selectionService = selectionService;
     _finderProvider   = finderProvider;
 }
コード例 #25
0
 private RenameFolderViewModel TestViewModel(RenameFolderModel model, IDeclarationFinderProvider declarationFinderProvider, IMessageBox messageBox)
 {
     return(new RenameFolderViewModel(model, messageBox, declarationFinderProvider));
 }
コード例 #26
0
 public MoveMultipleFoldersViewModel(MoveMultipleFoldersModel model, IMessageBox messageBox, IDeclarationFinderProvider declarationFinderProvider)
     : base(model)
 {
     _declarationFinderProvider = declarationFinderProvider;
     _messageBox = messageBox;
 }
コード例 #27
0
 public MoveFieldCloserToUsageInspection(IDeclarationFinderProvider declarationFinderProvider)
     : base(declarationFinderProvider, DeclarationType.Variable)
 {
 }
コード例 #28
0
 public ObsoleteWhileWendStatementInspection(IDeclarationFinderProvider declarationFinderProvider)
     : base(declarationFinderProvider)
 {
     ContextListener = new ObsoleteWhileWendStatementListener();
 }
コード例 #29
0
 public AssignmentNotUsedInspection(IDeclarationFinderProvider declarationFinderProvider, Walker walker)
     : base(declarationFinderProvider)
 {
     _walker = walker;
 }
コード例 #30
0
 public IdentifierReferenceInspectionResult(IInspection inspection, string description, IDeclarationFinderProvider declarationFinderProvider, IdentifierReference reference, dynamic properties = null) :
     base(inspection,
          description,
          reference.QualifiedModuleName,
          reference.Context,
          reference.Declaration,
          new QualifiedSelection(reference.QualifiedModuleName, reference.Context.GetSelection()),
          GetQualifiedMemberName(declarationFinderProvider, reference),
          (object)properties)
 {
     Reference = reference;
 }