Skip to content

Commit

Permalink
Change IsBuiltIn to IsUserDefined. Also clean up the code some.
Browse files Browse the repository at this point in the history
  • Loading branch information
Hosch250 committed Mar 25, 2017
1 parent ae55bfd commit 410c989
Show file tree
Hide file tree
Showing 61 changed files with 408 additions and 568 deletions.
22 changes: 11 additions & 11 deletions RetailCoder.VBE/Common/DeclarationExtensions.cs
Expand Up @@ -230,7 +230,7 @@ public static IEnumerable<Declaration> InScope(this IEnumerable<Declaration> dec
public static IEnumerable<Declaration> FindInterfaces(this IEnumerable<Declaration> declarations)
{
var classes = declarations.Where(item => item.DeclarationType == DeclarationType.ClassModule);
var interfaces = classes.Where(item => ((ClassModuleDeclaration)item).Subtypes.Any(s => !s.IsBuiltIn));
var interfaces = classes.Where(item => ((ClassModuleDeclaration)item).Subtypes.Any(s => s.IsUserDefined));
return interfaces;
}

Expand All @@ -241,7 +241,7 @@ public static IEnumerable<Declaration> FindInterfaceMembers(this IEnumerable<Dec
{
var items = declarations.ToList();
var interfaces = FindInterfaces(items).Select(i => i.Scope).ToList();
var interfaceMembers = items.Where(item => !item.IsBuiltIn
var interfaceMembers = items.Where(item => item.IsUserDefined
&& ProcedureTypes.Contains(item.DeclarationType)
&& interfaces.Any(i => item.ParentScope.StartsWith(i)))
.ToList();
Expand All @@ -265,7 +265,7 @@ public static IEnumerable<Declaration> FindUserEventHandlers(this IEnumerable<De
var declarationList = declarations.ToList();

var userEvents =
declarationList.Where(item => !item.IsBuiltIn && item.DeclarationType == DeclarationType.Event).ToList();
declarationList.Where(item => item.IsUserDefined && item.DeclarationType == DeclarationType.Event).ToList();

var handlers = new List<Declaration>();
foreach (var @event in userEvents)
Expand Down Expand Up @@ -293,7 +293,7 @@ public static Declaration FindSelectedDeclaration(this IEnumerable<Declaration>
/// </summary>
public static Declaration FindSelectedDeclaration(this IEnumerable<Declaration> declarations, QualifiedSelection selection, IEnumerable<DeclarationType> types, Func<Declaration, Selection> selector = null)
{
var userDeclarations = declarations.Where(item => !item.IsBuiltIn);
var userDeclarations = declarations.Where(item => item.IsUserDefined);
var items = userDeclarations.Where(item => types.Contains(item.DeclarationType)
&& item.QualifiedName.QualifiedModuleName == selection.QualifiedName).ToList();

Expand All @@ -308,7 +308,7 @@ public static Declaration FindSelectedDeclaration(this IEnumerable<Declaration>
}

// if we haven't returned yet, then we must be on an identifier reference.
declaration = items.SingleOrDefault(item => !item.IsBuiltIn
declaration = items.SingleOrDefault(item => item.IsUserDefined
&& types.Contains(item.DeclarationType)
&& item.References.Any(reference =>
reference.QualifiedModuleName == selection.QualifiedName
Expand Down Expand Up @@ -337,7 +337,7 @@ public static IEnumerable<Declaration> FindFormEventHandlers(this RubberduckPars
public static IEnumerable<Declaration> FindFormEventHandlers(this RubberduckParserState state, Declaration userForm)
{
var items = state.AllDeclarations.ToList();
var events = items.Where(item => item.IsBuiltIn
var events = items.Where(item => !item.IsUserDefined
&& item.ParentScope == "FM20.DLL;MSForms.FormEvents"
&& item.DeclarationType == DeclarationType.Event).ToList();

Expand Down Expand Up @@ -415,7 +415,7 @@ public static IEnumerable<Declaration> FindInterfaceImplementationMembers(this I
var items = declarations.ToList();
var members = FindInterfaceMembers(items);
var result = items.Where(item =>
!item.IsBuiltIn
item.IsUserDefined
&& ProcedureTypes.Contains(item.DeclarationType)
&& members.Select(m => m.ComponentName + '_' + m.IdentifierName).Contains(item.IdentifierName))
.ToList();
Expand All @@ -438,7 +438,7 @@ public static IEnumerable<Declaration> FindInterfaceImplementationMembers(this I
public static Declaration FindInterfaceMember(this IEnumerable<Declaration> declarations, Declaration implementation)
{
var members = FindInterfaceMembers(declarations);
var matches = members.Where(m => !m.IsBuiltIn && implementation.IdentifierName == m.ComponentName + '_' + m.IdentifierName).ToList();
var matches = members.Where(m => m.IsUserDefined && implementation.IdentifierName == m.ComponentName + '_' + m.IdentifierName).ToList();

return matches.Count > 1
? matches.SingleOrDefault(m => m.ProjectId == implementation.ProjectId)
Expand Down Expand Up @@ -466,7 +466,7 @@ public static Declaration FindTarget(this IEnumerable<Declaration> declarations,
// TODO: Due to the new binding mechanism this can have more than one match (e.g. in the case of index expressions + simple name expressions)
// Left as is for now because the binding is not fully integrated yet.
var target = items
.Where(item => !item.IsBuiltIn && validDeclarationTypes.Contains(item.DeclarationType))
.Where(item => item.IsUserDefined && validDeclarationTypes.Contains(item.DeclarationType))
.FirstOrDefault(item => item.IsSelected(selection)
|| item.References.Any(r => r.IsSelected(selection)));

Expand All @@ -476,7 +476,7 @@ public static Declaration FindTarget(this IEnumerable<Declaration> declarations,
}

var targets = items
.Where(item => !item.IsBuiltIn
.Where(item => item.IsUserDefined
&& item.ComponentName == selection.QualifiedName.ComponentName
&& validDeclarationTypes.Contains(item.DeclarationType));

Expand Down Expand Up @@ -534,7 +534,7 @@ public static Declaration FindTarget(this IEnumerable<Declaration> declarations,
/// <returns></returns>
public static Declaration FindVariable(this IEnumerable<Declaration> declarations, QualifiedSelection selection)
{
var items = declarations.Where(d => !d.IsBuiltIn && d.DeclarationType == DeclarationType.Variable).ToList();
var items = declarations.Where(d => d.IsUserDefined && d.DeclarationType == DeclarationType.Variable).ToList();

var target = items
.FirstOrDefault(item => item.IsSelected(selection) || item.References.Any(r => r.IsSelected(selection)));
Expand Down
2 changes: 1 addition & 1 deletion RetailCoder.VBE/Inspections/Abstract/InspectionBase.cs
Expand Up @@ -91,7 +91,7 @@ protected virtual IEnumerable<Declaration> UserDeclarations

protected virtual IEnumerable<Declaration> BuiltInDeclarations
{
get { return State.AllDeclarations.Where(declaration => declaration.IsBuiltIn); }
get { return State.AllDeclarations.Where(declaration => !declaration.IsUserDefined); }
}

protected bool IsIgnoringInspectionResultFor(IVBComponent component, int line)
Expand Down
Expand Up @@ -20,7 +20,7 @@ public ApplicationWorksheetFunctionInspection(RubberduckParserState state)

public override IEnumerable<IInspectionResult> GetInspectionResults()
{
var excel = State.DeclarationFinder.Projects.SingleOrDefault(item => item.IsBuiltIn && item.IdentifierName == "Excel");
var excel = State.DeclarationFinder.Projects.SingleOrDefault(item => !item.IsUserDefined && item.IdentifierName == "Excel");
if (excel == null) { return Enumerable.Empty<IInspectionResult>(); }

var members = new HashSet<string>(BuiltInDeclarations.Where(decl => decl.DeclarationType == DeclarationType.Function &&
Expand Down
Expand Up @@ -24,7 +24,7 @@ public ImplicitActiveSheetReferenceInspection(RubberduckParserState state)

public override IEnumerable<IInspectionResult> GetInspectionResults()
{
var excel = State.DeclarationFinder.Projects.SingleOrDefault(item => item.IsBuiltIn && item.IdentifierName == "Excel");
var excel = State.DeclarationFinder.Projects.SingleOrDefault(item => !item.IsUserDefined && item.IdentifierName == "Excel");
if (excel == null) { return Enumerable.Empty<InspectionResultBase>(); }

var globalModules = new[]
Expand Down
Expand Up @@ -24,7 +24,7 @@ public ImplicitActiveWorkbookReferenceInspection(RubberduckParserState state)

public override IEnumerable<IInspectionResult> GetInspectionResults()
{
var excel = State.DeclarationFinder.Projects.SingleOrDefault(item => item.IsBuiltIn && item.IdentifierName == "Excel");
var excel = State.DeclarationFinder.Projects.SingleOrDefault(item => !item.IsUserDefined && item.IdentifierName == "Excel");
if (excel == null) { return Enumerable.Empty<InspectionResultBase>(); }

var modules = new[]
Expand Down
Expand Up @@ -23,7 +23,7 @@ public override IEnumerable<IInspectionResult> GetInspectionResults()
var unresolved = State.DeclarationFinder.UnresolvedMemberDeclarations().Where(decl => !IsIgnoringInspectionResultFor(decl, AnnotationName)).ToList();

var targets = Declarations.Where(decl => decl.AsTypeDeclaration != null &&
decl.AsTypeDeclaration.IsBuiltIn &&
!decl.AsTypeDeclaration.IsUserDefined &&
decl.AsTypeDeclaration.DeclarationType == DeclarationType.ClassModule &&
((ClassModuleDeclaration)decl.AsTypeDeclaration).IsExtensible)
.SelectMany(decl => decl.References).ToList();
Expand Down
Expand Up @@ -30,7 +30,7 @@ public override IEnumerable<IInspectionResult> GetInspectionResults()

issues.AddRange(GetResults(declarations, interfaceDeclarationMembers));

var eventMembers = declarations.Where(item => !item.IsBuiltIn && item.DeclarationType == DeclarationType.Event).ToArray();
var eventMembers = declarations.Where(item => item.DeclarationType == DeclarationType.Event).ToArray();
var formEventHandlerScopes = State.FindFormEventHandlers().Select(handler => handler.Scope).ToArray();
var eventHandlerScopes = State.DeclarationFinder.FindEventHandlers().Concat(declarations.FindUserEventHandlers()).Select(e => e.Scope).ToArray();
var eventScopes = eventMembers.Select(s => s.Scope)
Expand Down
Expand Up @@ -106,8 +106,7 @@ private void UpdateCalls()
var procedureName = Identifier.GetName(_subStmtQualifiedContext.Context.subroutineName().identifier());

var procedure =
_state.AllDeclarations.SingleOrDefault(d =>
!d.IsBuiltIn &&
_state.AllUserDeclarations.SingleOrDefault(d =>
d.IdentifierName == procedureName &&
d.Context is VBAParser.SubStmtContext &&
d.QualifiedName.QualifiedModuleName.Equals(_subStmtQualifiedContext.ModuleName));
Expand Down
3 changes: 1 addition & 2 deletions RetailCoder.VBE/Inspections/WriteOnlyPropertyInspection.cs
Expand Up @@ -28,8 +28,7 @@ public override IEnumerable<IInspectionResult> GetInspectionResults()
item.Accessibility == Accessibility.Global)
&& (item.DeclarationType == DeclarationType.PropertyLet ||
item.DeclarationType == DeclarationType.PropertySet)
&& !declarations.Where(declaration => declaration.IdentifierName == item.IdentifierName)
.Any(accessor => !accessor.IsBuiltIn && accessor.DeclarationType == DeclarationType.PropertyGet))
&& declarations.Where(declaration => declaration.IdentifierName == item.IdentifierName).All(accessor => accessor.DeclarationType != DeclarationType.PropertyGet))
.GroupBy(item => new {item.QualifiedName, item.DeclarationType})
.Select(grouping => grouping.First()); // don't get both Let and Set accessors

Expand Down
Expand Up @@ -370,11 +370,11 @@ private Declaration CreateDeclaration(IVBComponent component)
{
return new ProceduralModuleDeclaration(
new QualifiedMemberName(new QualifiedModuleName(component), component.Name), projectDeclaration,
component.Name, false, new List<IAnnotation>(), null);
component.Name, true, new List<IAnnotation>(), null);
}

return new ClassModuleDeclaration(new QualifiedMemberName(new QualifiedModuleName(component), component.Name),
projectDeclaration, component.Name, false, new List<IAnnotation>(), null);
projectDeclaration, component.Name, true, new List<IAnnotation>(), null);
}

private void ReorderChildNodes(IEnumerable<CodeExplorerItemViewModel> nodes)
Expand Down
Expand Up @@ -9,8 +9,7 @@ namespace Rubberduck.Refactorings.EncapsulateField
{
public class EncapsulateFieldModel
{
private readonly RubberduckParserState _state;
public RubberduckParserState State { get { return _state; } }
public RubberduckParserState State { get; }

public Declaration TargetDeclaration { get; private set; }

Expand All @@ -22,9 +21,9 @@ public class EncapsulateFieldModel

public EncapsulateFieldModel(RubberduckParserState state, QualifiedSelection selection)
{
_state = state;
IList<Declaration> declarations = state.AllDeclarations
.Where(d => !d.IsBuiltIn && d.DeclarationType == DeclarationType.Variable)
State = state;
IList<Declaration> declarations = state.AllUserDeclarations
.Where(d => d.DeclarationType == DeclarationType.Variable)
.ToList();

TargetDeclaration = declarations.FindVariable(selection);
Expand Down
Expand Up @@ -34,8 +34,8 @@ public class ExtractInterfaceModel
public ExtractInterfaceModel(RubberduckParserState state, QualifiedSelection selection)
{
State = state;
var declarations = state.AllDeclarations.ToList();
var candidates = declarations.Where(item => !item.IsBuiltIn && ModuleTypes.Contains(item.DeclarationType)).ToList();
var declarations = state.AllUserDeclarations.ToList();
var candidates = declarations.Where(item => ModuleTypes.Contains(item.DeclarationType)).ToList();

TargetDeclaration = candidates.SingleOrDefault(item =>
item.QualifiedSelection.QualifiedName.Equals(selection.QualifiedName));
Expand All @@ -47,11 +47,10 @@ public ExtractInterfaceModel(RubberduckParserState state, QualifiedSelection sel

InterfaceName = "I" + TargetDeclaration.IdentifierName;

Members = declarations.Where(item => !item.IsBuiltIn
&& item.ProjectId == TargetDeclaration.ProjectId
&& item.ComponentName == TargetDeclaration.ComponentName
&& (item.Accessibility == Accessibility.Public || item.Accessibility == Accessibility.Implicit)
&& MemberTypes.Contains(item.DeclarationType))
Members = declarations.Where(item => item.ProjectId == TargetDeclaration.ProjectId
&& item.ComponentName == TargetDeclaration.ComponentName
&& (item.Accessibility == Accessibility.Public || item.Accessibility == Accessibility.Implicit)
&& MemberTypes.Contains(item.DeclarationType))
.OrderBy(o => o.Selection.StartLine)
.ThenBy(t => t.Selection.StartColumn)
.Select(d => new InterfaceMember(d))
Expand Down
Expand Up @@ -23,7 +23,7 @@ public bool withinSingleProcedure(QualifiedSelection qualifiedSelection)
{

var selection = qualifiedSelection.Selection;
IEnumerable<Declaration> procedures = _declarations.Where(d => !(d.IsBuiltIn) && (DeclarationExtensions.ProcedureTypes.Contains(d.DeclarationType)));
IEnumerable<Declaration> procedures = _declarations.Where(d => d.IsUserDefined && (DeclarationExtensions.ProcedureTypes.Contains(d.DeclarationType)));
Func<int, dynamic> ProcOfLine = (sl) => procedures.FirstOrDefault(d => d.Context.Start.Line < sl && d.Context.Stop.Line > sl);

var startLine = selection.StartLine;
Expand Down
Expand Up @@ -64,7 +64,7 @@ public void Refactor(QualifiedSelection selection)
_targetInterface = _declarations.FindInterface(selection);

_targetClass = _declarations.SingleOrDefault(d =>
!d.IsBuiltIn && ImplementingModuleTypes.Contains(d.DeclarationType) &&
ImplementingModuleTypes.Contains(d.DeclarationType) &&
d.QualifiedSelection.QualifiedName.Equals(selection.QualifiedName));

if (_targetClass == null || _targetInterface == null)
Expand Down
Expand Up @@ -22,8 +22,8 @@ public class IntroduceFieldRefactoring : IRefactoring

public IntroduceFieldRefactoring(IVBE vbe, RubberduckParserState state, IMessageBox messageBox)
{
_declarations = state.AllDeclarations
.Where(i => !i.IsBuiltIn && i.DeclarationType == DeclarationType.Variable)
_declarations = state.AllUserDeclarations
.Where(i => i.DeclarationType == DeclarationType.Variable)
.ToList();

_vbe = vbe;
Expand Down
2 changes: 1 addition & 1 deletion RetailCoder.VBE/Refactorings/Rename/RenameModel.cs
Expand Up @@ -49,7 +49,7 @@ public RenameModel(IVBE vbe, RubberduckParserState state, QualifiedSelection sel
private void AcquireTarget(out Declaration target, QualifiedSelection selection)
{
target = _declarations
.Where(item => !item.IsBuiltIn && item.DeclarationType != DeclarationType.ModuleOption)
.Where(item => item.IsUserDefined && item.DeclarationType != DeclarationType.ModuleOption)
.FirstOrDefault(item => item.IsSelected(selection) || item.References.Any(r => r.IsSelected(selection)));

PromptIfTargetImplementsInterface(ref target);
Expand Down
2 changes: 1 addition & 1 deletion RetailCoder.VBE/Refactorings/Rename/RenameRefactoring.cs
Expand Up @@ -70,7 +70,7 @@ public void Refactor(QualifiedSelection target)

public void Refactor(Declaration target)
{
if (target.IsBuiltIn) { return; }
if (!target.IsUserDefined) { return; }

var presenter = _factory.Create();
_model = presenter.Show(target);
Expand Down
2 changes: 1 addition & 1 deletion RetailCoder.VBE/UI/Command/FindSymbolCommand.cs
Expand Up @@ -34,7 +34,7 @@ public override RubberduckHotkey Hotkey

protected override void ExecuteImpl(object parameter)
{
var viewModel = new FindSymbolViewModel(_state.AllDeclarations.Where(item => !item.IsBuiltIn), _iconCache);
var viewModel = new FindSymbolViewModel(_state.AllUserDeclarations, _iconCache);
var view = new FindSymbolDialog(viewModel);
{
viewModel.Navigate += (sender, e) => { view.Hide(); };
Expand Down

0 comments on commit 410c989

Please sign in to comment.