Skip to content

Commit

Permalink
Merge pull request #3571 from IvenBach/Rubberduck.TodoItems_C#6&7_Update
Browse files Browse the repository at this point in the history
Rubberduck c#6&7 update. Second half of Rubberduck folder
  • Loading branch information
retailcoder committed Dec 19, 2017
2 parents bd5105b + f4c970f commit 372fdbd
Show file tree
Hide file tree
Showing 59 changed files with 471 additions and 585 deletions.
26 changes: 9 additions & 17 deletions RetailCoder.VBE/API/VBA/Declaration.cs
Expand Up @@ -32,20 +32,18 @@ public interface IDeclaration
[EditorBrowsable(EditorBrowsableState.Always)]
public class Declaration : IDeclaration
{
private readonly RubberduckDeclaration _declaration;

internal Declaration(RubberduckDeclaration declaration)
{
_declaration = declaration;
Instance = declaration;
}

protected RubberduckDeclaration Instance { get { return _declaration; } }
protected RubberduckDeclaration Instance { get; }

public bool IsArray { get { return _declaration.IsArray; } }
public string Name { get { return _declaration.IdentifierName; } }
public Accessibility Accessibility { get { return (Accessibility)_declaration.Accessibility; } }
public DeclarationType DeclarationType {get { return TypeMappings[_declaration.DeclarationType]; }}
public string TypeName { get { return _declaration.AsTypeName; } }
public bool IsArray => Instance.IsArray;
public string Name => Instance.IdentifierName;
public Accessibility Accessibility => (Accessibility)Instance.Accessibility;
public DeclarationType DeclarationType => TypeMappings[Instance.DeclarationType];
public string TypeName => Instance.AsTypeName;

private static readonly IDictionary<Parsing.Symbols.DeclarationType,DeclarationType> TypeMappings =
new Dictionary<Parsing.Symbols.DeclarationType, DeclarationType>
Expand Down Expand Up @@ -75,20 +73,14 @@ internal Declaration(RubberduckDeclaration declaration)
};

private Declaration _parentDeclaration;
public Declaration ParentDeclaration
{
get
{
return _parentDeclaration ?? (_parentDeclaration = new Declaration(Instance.ParentDeclaration));
}
}
public Declaration ParentDeclaration => _parentDeclaration ?? (_parentDeclaration = new Declaration(Instance.ParentDeclaration));

private IdentifierReference[] _references;
public IdentifierReference[] References
{
get
{
return _references ?? (_references = _declaration.References.Select(item => new IdentifierReference(item)).ToArray());
return _references ?? (_references = Instance.References.Select(item => new IdentifierReference(item)).ToArray());
}
}
}
Expand Down
25 changes: 8 additions & 17 deletions RetailCoder.VBE/API/VBA/IdentifierReference.cs
Expand Up @@ -31,28 +31,19 @@ public IdentifierReference(Parsing.Symbols.IdentifierReference reference)
}

private Declaration _declaration;
public Declaration Declaration
{
get { return _declaration ?? (_declaration = new Declaration(_reference.Declaration)); }
}
public Declaration Declaration => _declaration ?? (_declaration = new Declaration(_reference.Declaration));

private Declaration _parentScoping;
public Declaration ParentScope
{
get { return _parentScoping ?? (_parentScoping = new Declaration(_reference.ParentScoping)); }
}
public Declaration ParentScope => _parentScoping ?? (_parentScoping = new Declaration(_reference.ParentScoping));

private Declaration _parentNonScoping;
public Declaration ParentNonScoping
{
get { return _parentNonScoping ?? (_parentNonScoping = new Declaration(_reference.ParentNonScoping)); }
}
public Declaration ParentNonScoping => _parentNonScoping ?? (_parentNonScoping = new Declaration(_reference.ParentNonScoping));

public bool IsAssignment { get { return _reference.IsAssignment; } }
public bool IsAssignment => _reference.IsAssignment;

public int StartLine { get { return _reference.Selection.StartLine; } }
public int EndLine { get { return _reference.Selection.EndLine; } }
public int StartColumn { get { return _reference.Selection.StartColumn; } }
public int EndColumn { get { return _reference.Selection.EndColumn; } }
public int StartLine => _reference.Selection.StartLine;
public int EndLine => _reference.Selection.EndLine;
public int StartColumn => _reference.Selection.StartColumn;
public int EndColumn => _reference.Selection.EndColumn;
}
}
19 changes: 4 additions & 15 deletions RetailCoder.VBE/API/VBA/ParserState.cs
Expand Up @@ -150,11 +150,11 @@ public void BeginParse()

private void _state_StateChanged(object sender, EventArgs e)
{
_allDeclarations = _state.AllDeclarations
AllDeclarations = _state.AllDeclarations
.Select(item => new Declaration(item))
.ToArray();

_userDeclarations = _state.AllUserDeclarations
UserDeclarations = _state.AllUserDeclarations
.Select(item => new Declaration(item))
.ToArray();

Expand All @@ -177,20 +177,9 @@ private void _state_StateChanged(object sender, EventArgs e)
}
}

private Declaration[] _allDeclarations;
public Declaration[] AllDeclarations { get; private set; }

public Declaration[] AllDeclarations
{
//[return: MarshalAs(UnmanagedType.SafeArray/*, SafeArraySubType = VarEnum.VT_VARIANT*/)]
get { return _allDeclarations; }
}

private Declaration[] _userDeclarations;
public Declaration[] UserDeclarations
{
//[return: MarshalAs(UnmanagedType.SafeArray/*, SafeArraySubType = VarEnum.VT_VARIANT*/)]
get { return _userDeclarations; }
}
public Declaration[] UserDeclarations { get; private set; }

private bool _disposed;
public void Dispose()
Expand Down
6 changes: 3 additions & 3 deletions RetailCoder.VBE/App.cs
Expand Up @@ -120,7 +120,7 @@ public void Startup()
_hooks.HookHotkeys(); // need to hook hotkeys before we localize menus, to correctly display ShortcutTexts
_appMenus.Localize();

if (_config.UserSettings.GeneralSettings.CheckVersion)
if (_config.UserSettings.GeneralSettings.CanCheckVersion)
{
_checkVersionCommand.Execute(null);
}
Expand Down Expand Up @@ -165,7 +165,7 @@ private void CheckForLegacyIndenterSettings()
try
{
Logger.Trace("Checking for legacy Smart Indenter settings.");
if (_config.UserSettings.GeneralSettings.SmartIndenterPrompted ||
if (_config.UserSettings.GeneralSettings.IsSmartIndenterPrompted ||
!_config.UserSettings.IndenterSettings.LegacySettingsExist())
{
return;
Expand All @@ -177,7 +177,7 @@ private void CheckForLegacyIndenterSettings()
Logger.Trace("Attempting to load legacy Smart Indenter settings.");
_config.UserSettings.IndenterSettings.LoadLegacyFromRegistry();
}
_config.UserSettings.GeneralSettings.SmartIndenterPrompted = true;
_config.UserSettings.GeneralSettings.IsSmartIndenterPrompted = true;
_configService.SaveConfiguration(_config);
}
catch
Expand Down
4 changes: 2 additions & 2 deletions RetailCoder.VBE/Common/ClipboardWriter.cs
Expand Up @@ -19,8 +19,8 @@ public class ClipboardWriter : IClipboardWriter

public void Write(string text)
{
this.AppendString(DataFormats.UnicodeText, text);
this.Flush();
AppendString(DataFormats.UnicodeText, text);
Flush();
}

public void AppendImage(BitmapSource image)
Expand Down
35 changes: 14 additions & 21 deletions RetailCoder.VBE/Common/DeclarationExtensions.cs
Expand Up @@ -42,7 +42,7 @@ public static Selection GetVariableStmtContextSelection(this Declaration target)
{
if (target.DeclarationType != DeclarationType.Variable)
{
throw new ArgumentException("Target DeclarationType is not Variable.", "target");
throw new ArgumentException("Target DeclarationType is not Variable.", nameof(target));
}

var statement = GetVariableStmtContext(target) ?? target.Context; // undeclared variables don't have a VariableStmtContext
Expand All @@ -59,7 +59,7 @@ public static Selection GetConstStmtContextSelection(this Declaration target)
{
if (target.DeclarationType != DeclarationType.Constant)
{
throw new ArgumentException("Target DeclarationType is not Constant.", "target");
throw new ArgumentException("Target DeclarationType is not Constant.", nameof(target));
}

var statement = GetConstStmtContext(target);
Expand All @@ -76,7 +76,7 @@ public static VBAParser.VariableStmtContext GetVariableStmtContext(this Declarat
{
if (target.DeclarationType != DeclarationType.Variable)
{
throw new ArgumentException("Target DeclarationType is not Variable.", "target");
throw new ArgumentException("Target DeclarationType is not Variable.", nameof(target));
}

Debug.Assert(target.IsUndeclared || target.Context is VBAParser.VariableSubStmtContext);
Expand All @@ -99,7 +99,7 @@ public static VBAParser.ConstStmtContext GetConstStmtContext(this Declaration ta
{
if (target.DeclarationType != DeclarationType.Constant)
{
throw new ArgumentException("Target DeclarationType is not Constant.", "target");
throw new ArgumentException("Target DeclarationType is not Constant.", nameof(target));
}

var statement = target.Context.Parent as VBAParser.ConstStmtContext;
Expand All @@ -121,11 +121,11 @@ public static bool HasMultipleDeclarationsInStatement(this Declaration target)
{
if (target.DeclarationType != DeclarationType.Variable)
{
throw new ArgumentException("Target DeclarationType is not Variable.", "target");
throw new ArgumentException("Target DeclarationType is not Variable.", nameof(target));
}

var statement = target.Context.Parent as VBAParser.VariableListStmtContext;
return statement != null && statement.children.OfType<VBAParser.VariableSubStmtContext>().Count() > 1;
return target.Context.Parent is VBAParser.VariableListStmtContext statement
&& statement.children.OfType<VBAParser.VariableSubStmtContext>().Count() > 1;
}

/// <summary>
Expand All @@ -138,17 +138,15 @@ public static int CountOfDeclarationsInStatement(this Declaration target)
{
if (target.DeclarationType != DeclarationType.Variable)
{
throw new ArgumentException("Target DeclarationType is not Variable.", "target");
throw new ArgumentException("Target DeclarationType is not Variable.", nameof(target));
}

var statement = target.Context.Parent as VBAParser.VariableListStmtContext;

if (statement != null)
if (target.Context.Parent is VBAParser.VariableListStmtContext statement)
{
return statement.children.OfType<VBAParser.VariableSubStmtContext>().Count();
}

throw new ArgumentException("'target.Context.Parent' is not type VBAParser.VariabelListStmtContext", "target");
throw new ArgumentException("'target.Context.Parent' is not type VBAParser.VariabelListStmtContext", nameof(target));
}

/// <summary>
Expand All @@ -161,20 +159,17 @@ public static int IndexOfVariableDeclarationInStatement(this Declaration target)
{
if (target.DeclarationType != DeclarationType.Variable)
{
throw new ArgumentException("Target DeclarationType is not Variable.", "target");
throw new ArgumentException("Target DeclarationType is not Variable.", nameof(target));
}

var statement = target.Context.Parent as VBAParser.VariableListStmtContext;

if (statement != null)
if (target.Context.Parent is VBAParser.VariableListStmtContext statement)
{
return statement.children.OfType<VBAParser.VariableSubStmtContext>()
.ToList()
.IndexOf((VBAParser.VariableSubStmtContext)target.Context) + 1;
}

// ReSharper disable once LocalizableElement
throw new ArgumentException("'target.Context.Parent' is not type VBAParser.VariabelListStmtContext", "target");
throw new ArgumentException("'target.Context.Parent' is not type VBAParser.VariableListStmtContext", nameof(target));
}

public static readonly DeclarationType[] ProcedureTypes =
Expand Down Expand Up @@ -298,9 +293,7 @@ public static Declaration FindSelectedDeclaration(this IEnumerable<Declaration>
&& item.QualifiedName.QualifiedModuleName == selection.QualifiedName).ToList();

var declaration = items.SingleOrDefault(item =>
selector == null
? item.Selection.Contains(selection.Selection)
: selector(item).Contains(selection.Selection));
selector?.Invoke(item).Contains(selection.Selection) ?? item.Selection.Contains(selection.Selection));

if (declaration != null)
{
Expand Down

0 comments on commit 372fdbd

Please sign in to comment.