Skip to content

Commit

Permalink
Merge pull request rubberduck-vba#1137 from rubberduck-vba/CodeExplorer
Browse files Browse the repository at this point in the history
adding ParentScoping and ParentNonScoping members to IdentifierRefere…
  • Loading branch information
retailcoder committed Feb 22, 2016
2 parents c5cb93c + 76c8731 commit c04ebf9
Show file tree
Hide file tree
Showing 44 changed files with 26,723 additions and 29,050 deletions.
13 changes: 0 additions & 13 deletions RetailCoder.VBE/App.cs
Expand Up @@ -24,9 +24,7 @@ public class App : IDisposable
{
private readonly VBE _vbe;
private readonly IMessageBox _messageBox;
private readonly IParserErrorsPresenterFactory _parserErrorsPresenterFactory;
private readonly IRubberduckParser _parser;
private readonly IInspectorFactory _inspectorFactory;
private readonly AutoSave.AutoSave _autoSave;
private readonly IGeneralConfigService _configService;
private readonly IAppMenu _appMenus;
Expand All @@ -39,9 +37,7 @@ public class App : IDisposable
private Configuration _config;

public App(VBE vbe, IMessageBox messageBox,
IParserErrorsPresenterFactory parserErrorsPresenterFactory,
IRubberduckParser parser,
IInspectorFactory inspectorFactory,
IGeneralConfigService configService,
IAppMenu appMenus,
RubberduckCommandBar stateBar,
Expand All @@ -50,9 +46,7 @@ public class App : IDisposable
{
_vbe = vbe;
_messageBox = messageBox;
_parserErrorsPresenterFactory = parserErrorsPresenterFactory;
_parser = parser;
_inspectorFactory = inspectorFactory;
_configService = configService;
_autoSave = new AutoSave.AutoSave(_vbe, _configService);
_appMenus = appMenus;
Expand Down Expand Up @@ -174,7 +168,6 @@ public void Startup()
private void CleanReloadConfig()
{
LoadConfig();
Setup();
}

private void ConfigServiceLanguageChanged(object sender, EventArgs e)
Expand Down Expand Up @@ -202,12 +195,6 @@ private void LoadConfig()
}
}

private void Setup()
{
_inspectorFactory.Create();
_parserErrorsPresenterFactory.Create();
}

public void Dispose()
{
//_hooks.MessageReceived -= hooks_MessageReceived;
Expand Down
Expand Up @@ -26,7 +26,7 @@ public override IEnumerable<InspectionResultBase> GetInspectionResults()
&& declaration.References.Any(reference => reference.IsAssignment));

var issues = assignedByValParameters
.Select(param => new AssignedByValParameterInspectionResult(this, param.Context, param.QualifiedName));
.Select(param => new AssignedByValParameterInspectionResult(this, param));

return issues;
}
Expand Down
@@ -1,6 +1,7 @@
using System.Collections.Generic;
using Antlr4.Runtime;
using Rubberduck.Parsing.Grammar;
using Rubberduck.Parsing.Symbols;
using Rubberduck.VBEditor;

namespace Rubberduck.Inspections
Expand All @@ -9,12 +10,12 @@ public class AssignedByValParameterInspectionResult : InspectionResultBase
{
private readonly IEnumerable<CodeInspectionQuickFix> _quickFixes;

public AssignedByValParameterInspectionResult(IInspection inspection, ParserRuleContext context, QualifiedMemberName qualifiedName)
: base(inspection, qualifiedName.QualifiedModuleName, context)
public AssignedByValParameterInspectionResult(IInspection inspection, Declaration target)
: base(inspection, target)
{
_quickFixes = new[]
{
new PassParameterByReferenceQuickFix(context, QualifiedSelection),
new PassParameterByReferenceQuickFix(target.Context, QualifiedSelection),
};
}

Expand Down
Expand Up @@ -98,7 +98,7 @@ private bool IsAddressOfCall(IdentifierReference usage)

private bool IsReturnStatement(Declaration function, IdentifierReference assignment)
{
return assignment.ParentScope == function.Scope;
return assignment.ParentScoping.Equals(function);
}

private bool IsCallWithoutAssignment(IdentifierReference usage)
Expand Down
Expand Up @@ -9,12 +9,9 @@ namespace Rubberduck.Inspections
public class FunctionReturnValueNotUsedInspectionResult : InspectionResultBase
{
private readonly IEnumerable<CodeInspectionQuickFix> _quickFixes;
private QualifiedMemberName _memberName;

public FunctionReturnValueNotUsedInspectionResult(
IInspection inspection,
ParserRuleContext context,
QualifiedMemberName qualifiedName,
IEnumerable<string> returnStatements)
public FunctionReturnValueNotUsedInspectionResult(IInspection inspection, ParserRuleContext context, QualifiedMemberName qualifiedName, IEnumerable<string> returnStatements)
: this(inspection, context, qualifiedName, returnStatements, new List<Tuple<ParserRuleContext, QualifiedSelection, IEnumerable<string>>>())
{
}
Expand All @@ -27,6 +24,7 @@ public class FunctionReturnValueNotUsedInspectionResult : InspectionResultBase
IEnumerable<Tuple<ParserRuleContext, QualifiedSelection, IEnumerable<string>>> children)
: base(inspection, qualifiedName.QualifiedModuleName, context)
{
_memberName = qualifiedName;
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)));
Expand All @@ -42,8 +40,7 @@ public override string Description
{
get
{
// bug NullReferenceException thrown here - null Target
return string.Format(InspectionsUI.FunctionReturnValueNotUsedInspectionResultFormat, Target.IdentifierName);
return string.Format(InspectionsUI.FunctionReturnValueNotUsedInspectionResultFormat, _memberName.MemberName);
}
}
}
Expand Down
Expand Up @@ -9,18 +9,25 @@ namespace Rubberduck.Inspections
public class IdentifierNotAssignedInspectionResult : IdentifierNotUsedInspectionResult
{
private readonly IEnumerable<CodeInspectionQuickFix> _quickFixes;
private readonly Declaration _target;

public IdentifierNotAssignedInspectionResult(IInspection inspection, Declaration target,
ParserRuleContext context, QualifiedModuleName qualifiedName)
: base(inspection, target, context, qualifiedName)
{
_target = target;
_quickFixes = new CodeInspectionQuickFix[]
{
new RemoveUnassignedIdentifierQuickFix(Context, QualifiedSelection),
new IgnoreOnceQuickFix(context, QualifiedSelection, Inspection.AnnotationName),
};
}

public override string Description
{
get { return string.Format(InspectionsUI.VariableNotAssignedInspectionResultFormat, _target.IdentifierName); }
}

public override IEnumerable<CodeInspectionQuickFix> QuickFixes { get { return _quickFixes; } }
}

Expand Down
Expand Up @@ -24,8 +24,7 @@ public class IdentifierNotUsedInspectionResult : InspectionResultBase
}

public override IEnumerable<CodeInspectionQuickFix> QuickFixes { get { return _quickFixes; } }

public override string Description
public override string Description
{
get
{
Expand Down
Expand Up @@ -29,8 +29,8 @@ public override IEnumerable<InspectionResultBase> GetInspectionResults()
&& !interfaceMembers.Select(m => m.Scope).Contains(item.ParentScope)
let arg = item.Context as VBAParser.ArgContext
where arg != null && arg.BYREF() == null && arg.BYVAL() == null
select new QualifiedContext<VBAParser.ArgContext>(item.QualifiedName, arg))
.Select(issue => new ImplicitByRefParameterInspectionResult(this, string.Format(Description, issue.Context.ambiguousIdentifier().GetText()), issue));
select new {Declaration = item, Context = new QualifiedContext<VBAParser.ArgContext>(item.QualifiedName, arg) })
.Select(issue => new ImplicitByRefParameterInspectionResult(this, issue.Context, issue.Declaration));


return issues;
Expand Down
Expand Up @@ -2,6 +2,7 @@
using Antlr4.Runtime;
using Rubberduck.Parsing;
using Rubberduck.Parsing.Grammar;
using Rubberduck.Parsing.Symbols;
using Rubberduck.VBEditor;

namespace Rubberduck.Inspections
Expand All @@ -10,8 +11,8 @@ public class ImplicitByRefParameterInspectionResult : InspectionResultBase
{
private readonly IEnumerable<CodeInspectionQuickFix> _quickFixes;

public ImplicitByRefParameterInspectionResult(IInspection inspection, string result, QualifiedContext<VBAParser.ArgContext> qualifiedContext)
: base(inspection, qualifiedContext.ModuleName, qualifiedContext.Context)
public ImplicitByRefParameterInspectionResult(IInspection inspection, QualifiedContext<VBAParser.ArgContext> qualifiedContext, Declaration declaration)
: base(inspection, declaration)
{
_quickFixes = new CodeInspectionQuickFix[]
{
Expand Down
4 changes: 2 additions & 2 deletions RetailCoder.VBE/Inspections/InspectionResultBase.cs
Expand Up @@ -13,7 +13,7 @@ namespace Rubberduck.Inspections
public abstract class InspectionResultBase : ICodeInspectionResult, INavigateSource
{
protected InspectionResultBase(IInspection inspection, Declaration target)
: this(inspection, target.QualifiedName.QualifiedModuleName, null)
: this(inspection, target.QualifiedName.QualifiedModuleName, target.Context)
{
_target = target;
}
Expand Down Expand Up @@ -51,7 +51,7 @@ protected InspectionResultBase(IInspection inspection, QualifiedModuleName quali
public CommentNode Comment { get { return _comment; } }

private readonly Declaration _target;
protected Declaration Target { get { return _target; } }
protected virtual Declaration Target { get { return _target; } }

/// <summary>
/// Gets the information needed to select the target instruction in the VBE.
Expand Down
9 changes: 9 additions & 0 deletions RetailCoder.VBE/Inspections/InspectionsUI.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions RetailCoder.VBE/Inspections/InspectionsUI.resx
Expand Up @@ -494,4 +494,7 @@
<data name="SplitMultipleDeclarationsQuickFix" xml:space="preserve">
<value>Separate multiple declarations into multiple instructions</value>
</data>
<data name="VariableNotAssignedInspectionResultFormat" xml:space="preserve">
<value>Variable '{0}' is never assigned</value>
</data>
</root>
5 changes: 0 additions & 5 deletions RetailCoder.VBE/Inspections/Inspector.cs
Expand Up @@ -9,11 +9,6 @@

namespace Rubberduck.Inspections
{
public interface IInspectorFactory
{
IInspector Create();
}

public class Inspector : IInspector, IDisposable
{
private readonly IGeneralConfigService _configService;
Expand Down
Expand Up @@ -36,7 +36,7 @@ public override IEnumerable<InspectionResultBase> GetInspectionResults()
var firstReference = declaration.References.FirstOrDefault();
if (firstReference == null ||
declaration.References.Any(r => r.ParentScope != firstReference.ParentScope))
declaration.References.Any(r => r.ParentScoping != firstReference.ParentScoping))
{
return false;
}
Expand All @@ -60,7 +60,7 @@ private Declaration ParentDeclaration(IdentifierReference reference)
var declarationTypes = new[] {DeclarationType.Function, DeclarationType.Procedure, DeclarationType.Property};

return UserDeclarations.SingleOrDefault(d =>
d.Scope == reference.ParentScope && declarationTypes.Contains(d.DeclarationType) &&
reference.ParentScoping.Equals(d) && declarationTypes.Contains(d.DeclarationType) &&
d.Project == reference.QualifiedModuleName.Project);
}
}
Expand Down
4 changes: 2 additions & 2 deletions RetailCoder.VBE/Inspections/ParameterCanBeByValInspection.cs
Expand Up @@ -64,7 +64,7 @@ public override IEnumerable<InspectionResultBase> GetInspectionResults()
&& ((VBAParser.ArgContext) declaration.Context).BYVAL() == null
&& !IsUsedAsByRefParam(declarations, declaration)
&& !declaration.References.Any(reference => reference.IsAssignment))
.Select(issue => new ParameterCanBeByValInspectionResult(this, string.Format(Description, issue.IdentifierName), ((dynamic)issue.Context).ambiguousIdentifier(), issue.QualifiedName));
.Select(issue => new ParameterCanBeByValInspectionResult(this, issue));

return issues;
}
Expand All @@ -77,7 +77,7 @@ private static bool IsUsedAsByRefParam(IEnumerable<Declaration> declarations, De
var items = declarations as List<Declaration> ?? declarations.ToList();

var procedureCalls = items.Where(item => item.DeclarationType.HasFlag(DeclarationType.Member))
.SelectMany(member => member.References.Where(reference => reference.ParentScope == parameter.ParentScope))
.SelectMany(member => member.References.Where(reference => reference.ParentScoping.Equals(parameter.ParentScopeDeclaration)))
.GroupBy(call => call.Declaration)
.ToList(); // only check a procedure once. its declaration doesn't change if it's called 20 times anyway.

Expand Down
14 changes: 11 additions & 3 deletions RetailCoder.VBE/Inspections/ParameterCanBeByValInspectionResult.cs
@@ -1,17 +1,20 @@
using System.Collections.Generic;
using Antlr4.Runtime;
using Rubberduck.Parsing.Grammar;
using Rubberduck.Parsing.Symbols;
using Rubberduck.VBEditor;

namespace Rubberduck.Inspections
{
public class ParameterCanBeByValInspectionResult : InspectionResultBase
{
private readonly Declaration _declaration;
private readonly IEnumerable<CodeInspectionQuickFix> _quickFixes;

public ParameterCanBeByValInspectionResult(IInspection inspection, string result, ParserRuleContext context, QualifiedMemberName qualifiedName)
: base(inspection, qualifiedName.QualifiedModuleName, context)
public ParameterCanBeByValInspectionResult(IInspection inspection, Declaration declaration)
: base(inspection, declaration)
{
_declaration = declaration;
_quickFixes = new[]
{
new PassParameterByValueQuickFix(Context, QualifiedSelection),
Expand All @@ -20,6 +23,11 @@ public ParameterCanBeByValInspectionResult(IInspection inspection, string result

public override IEnumerable<CodeInspectionQuickFix> QuickFixes { get { return _quickFixes; } }

protected override Declaration Target
{
get { return _declaration; }
}

public override string Description
{
get { return string.Format(InspectionsUI.ParameterCanBeByValInspectionResultFormat, Target.IdentifierName); }
Expand All @@ -35,7 +43,7 @@ public PassParameterByValueQuickFix(ParserRuleContext context, QualifiedSelectio

public override void Fix()
{
var parameter = Context.Parent.GetText();
var parameter = Context.GetText();
var newContent = string.Concat(Tokens.ByVal, " ", parameter.Replace(Tokens.ByRef, string.Empty).Trim());
var selection = Selection.Selection;

Expand Down
4 changes: 1 addition & 3 deletions RetailCoder.VBE/Inspections/ParameterNotUsedInspection.cs
Expand Up @@ -55,9 +55,7 @@ public override IEnumerable<InspectionResultBase> GetInspectionResults()
!IsInterfaceMemberParameter(parameter, interfaceMemberScopes)
&& !builtInHandlers.Contains(parameter.ParentDeclaration))
let isInterfaceImplementationMember = IsInterfaceMemberImplementationParameter(issue, interfaceImplementationMemberScopes)
select new ParameterNotUsedInspectionResult(this, string.Format(Description, issue.IdentifierName),
((dynamic) issue.Context).ambiguousIdentifier(), issue.QualifiedName,
isInterfaceImplementationMember, quickFixRefactoring, State);
select new ParameterNotUsedInspectionResult(this, issue, isInterfaceImplementationMember, quickFixRefactoring, State);

return issues.ToList();
}
Expand Down
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using Antlr4.Runtime;
using Rubberduck.Parsing.Symbols;
using Rubberduck.Parsing.VBA;
using Rubberduck.Refactorings.RemoveParameters;
using Rubberduck.VBEditor;
Expand All @@ -10,10 +11,9 @@ public class ParameterNotUsedInspectionResult : InspectionResultBase
{
private readonly IEnumerable<CodeInspectionQuickFix> _quickFixes;

public ParameterNotUsedInspectionResult(IInspection inspection, string result,
ParserRuleContext context, QualifiedMemberName qualifiedName, bool isInterfaceImplementation,
public ParameterNotUsedInspectionResult(IInspection inspection, Declaration declaration, bool isInterfaceImplementation,
RemoveParametersRefactoring refactoring, RubberduckParserState parseResult)
: base(inspection, qualifiedName.QualifiedModuleName, context)
: base(inspection, declaration)
{
_quickFixes = isInterfaceImplementation ? new CodeInspectionQuickFix[] {} : new CodeInspectionQuickFix[]
{
Expand Down
Expand Up @@ -29,7 +29,7 @@ public override IEnumerable<InspectionResultBase> GetInspectionResults()

foreach (var issue in usages)
{
yield return new UnassignedVariableUsageInspectionResult(this, issue.Context, issue.QualifiedModuleName);
yield return new UnassignedVariableUsageInspectionResult(this, issue.Context, issue.QualifiedModuleName, issue.Declaration);
}
}
}
Expand Down

0 comments on commit c04ebf9

Please sign in to comment.