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); }
public MultilineParameterInspection(IDeclarationFinderProvider declarationFinderProvider) : base(declarationFinderProvider) { ContextListener = new ParameterListener(); }
public ImplicitContainingWorkbookReferenceInspection(IDeclarationFinderProvider declarationFinderProvider) : base(declarationFinderProvider) { }
public ChangeIntegerToLongQuickFix(IDeclarationFinderProvider declarationFinderProvider) : base(typeof(IntegerDataTypeInspection)) { _declarationFinderProvider = declarationFinderProvider; }
protected DeclarationInspectionBase(IDeclarationFinderProvider declarationFinderProvider, DeclarationType[] relevantDeclarationTypes, DeclarationType[] excludeDeclarationTypes) : base(declarationFinderProvider, relevantDeclarationTypes, excludeDeclarationTypes) { }
/// <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))); }
public ExpandBangNotationQuickFix(IDeclarationFinderProvider declarationFinderProvider) : base(typeof(UseOfBangNotationInspection), typeof(UseOfRecursiveBangNotationInspection)) { _declarationFinderProvider = declarationFinderProvider; }
public SetTypeResolver(IDeclarationFinderProvider declarationFinderProvider) { _declarationFinderProvider = declarationFinderProvider; }
protected ParseTreeInspectionBase(IDeclarationFinderProvider declarationFinderProvider) : base(declarationFinderProvider) { }
public ImplicitVariantReturnTypeInspection(IDeclarationFinderProvider declarationFinderProvider) : base(declarationFinderProvider, DeclarationType.Function) { }
public DefaultProjectNameInspection(IDeclarationFinderProvider declarationFinderProvider) : base(declarationFinderProvider, DeclarationType.Project) { }
public VariableTypeNotDeclaredInspection(IDeclarationFinderProvider declarationFinderProvider) : base(declarationFinderProvider, new [] { DeclarationType.Parameter, DeclarationType.Variable }, new[] { DeclarationType.Control }) { }
public EmptyMethodInspection(IDeclarationFinderProvider declarationFinderProvider) : base(declarationFinderProvider, DeclarationType.Member) { }
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)); }
public IntroduceParameterRefactoringAction(IDeclarationFinderProvider declarationFinderProvider, IRewritingManager rewritingManager) : base(rewritingManager) { _declarationFinderProvider = declarationFinderProvider; }
public ShadowedDeclarationInspection(IDeclarationFinderProvider declarationFinderProvider) : base(declarationFinderProvider) { }
public ParameterCanBeByValInspection(IDeclarationFinderProvider declarationFinderProvider) : base(declarationFinderProvider, DeclarationType.Parameter) { }
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))); }
public UnassignedVariableUsageInspection(IDeclarationFinderProvider declarationFinderProvider) : base(declarationFinderProvider) { }
public UseBackingFieldsStrategyConflictFinder(IDeclarationFinderProvider declarationFinderProvider, IEnumerable <IEncapsulateFieldCandidate> candidates, IEnumerable <IUserDefinedTypeMemberCandidate> udtCandidates) : base(declarationFinderProvider, candidates, udtCandidates) { }
public SheetAccessedUsingStringInspection(IDeclarationFinderProvider declarationFinderProvider, IProjectsProvider projectsProvider) : base(declarationFinderProvider) { _projectsProvider = projectsProvider; }
protected DeclarationInspectionBase(IDeclarationFinderProvider declarationFinderProvider, params DeclarationType[] relevantDeclarationTypes) : base(declarationFinderProvider, relevantDeclarationTypes) { }
public RunSelectedTestMethodCommand(ITestEngine engine, ISelectionService selectionService, IDeclarationFinderProvider finderProvider) : base(LogManager.GetCurrentClassLogger()) { _engine = engine; _selectionService = selectionService; _finderProvider = finderProvider; }
private RenameFolderViewModel TestViewModel(RenameFolderModel model, IDeclarationFinderProvider declarationFinderProvider, IMessageBox messageBox) { return(new RenameFolderViewModel(model, messageBox, declarationFinderProvider)); }
public MoveMultipleFoldersViewModel(MoveMultipleFoldersModel model, IMessageBox messageBox, IDeclarationFinderProvider declarationFinderProvider) : base(model) { _declarationFinderProvider = declarationFinderProvider; _messageBox = messageBox; }
public MoveFieldCloserToUsageInspection(IDeclarationFinderProvider declarationFinderProvider) : base(declarationFinderProvider, DeclarationType.Variable) { }
public ObsoleteWhileWendStatementInspection(IDeclarationFinderProvider declarationFinderProvider) : base(declarationFinderProvider) { ContextListener = new ObsoleteWhileWendStatementListener(); }
public AssignmentNotUsedInspection(IDeclarationFinderProvider declarationFinderProvider, Walker walker) : base(declarationFinderProvider) { _walker = walker; }
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; }