Skip to content

Commit

Permalink
Merge pull request rubberduck-vba#299 from retailcoder/refactor
Browse files Browse the repository at this point in the history
Abstracted IInspectionModel; closes #139
  • Loading branch information
rubberduck203 committed Mar 8, 2015
2 parents 54ce610 + fb691dc commit 3dfbee3
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 16 deletions.
12 changes: 6 additions & 6 deletions RetailCoder.VBE/Config/CodeInspectionSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@ namespace Rubberduck.Config
public class CodeInspectionSettings
{
[XmlArrayItemAttribute("CodeInspection", IsNullable = false)]
public CodeInspection[] CodeInspections { get; set; }
public CodeInspectionSetting[] CodeInspections { get; set; }

public CodeInspectionSettings()
{
//default constructor requied for serialization
}

public CodeInspectionSettings(CodeInspection[] inspections)
public CodeInspectionSettings(CodeInspectionSetting[] inspections)
{
this.CodeInspections = inspections;
}
}

[XmlTypeAttribute(AnonymousType = true)]
public class CodeInspection
public class CodeInspectionSetting : IInspectionModel
{
[XmlAttribute]
public string Name { get; set; }
Expand All @@ -33,19 +33,19 @@ public class CodeInspection
[XmlAttribute]
public CodeInspectionType InspectionType { get; set; }

public CodeInspection()
public CodeInspectionSetting()
{
//default constructor required for serialization
}

public CodeInspection(string name, CodeInspectionType type, CodeInspectionSeverity severity)
public CodeInspectionSetting(string name, CodeInspectionType type, CodeInspectionSeverity severity)
{
this.Name = name;
this.InspectionType = type;
this.Severity = severity;
}

public CodeInspection(Inspections.IInspection inspection)
public CodeInspectionSetting(IInspectionModel inspection)
: this(inspection.Name, inspection.InspectionType, inspection.Severity)
{ }
}
Expand Down
10 changes: 5 additions & 5 deletions RetailCoder.VBE/Config/ConfigurationLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public Configuration LoadConfiguration()
}
}

private List<CodeInspection> MergeImplementedInspectionsNotInConfig(List<CodeInspection> configInspections, IList<IInspection> implementedInspections)
private List<CodeInspectionSetting> MergeImplementedInspectionsNotInConfig(List<CodeInspectionSetting> configInspections, IList<IInspection> implementedInspections)
{
bool found;
foreach (var implementedInspection in implementedInspections)
Expand All @@ -106,7 +106,7 @@ private List<CodeInspection> MergeImplementedInspectionsNotInConfig(List<CodeIns

if (!found)
{
configInspections.Add(new CodeInspection(implementedInspection));
configInspections.Add(new CodeInspectionSetting(implementedInspection));
}
}
return configInspections;
Expand All @@ -133,12 +133,12 @@ public ToDoMarker[] GetDefaultTodoMarkers()

/// <summary> Converts implemented code inspections into array of Config.CodeInspection objects. </summary>
/// <returns> An array of Config.CodeInspection. </returns>
public CodeInspection[] GetDefaultCodeInspections()
public CodeInspectionSetting[] GetDefaultCodeInspections()
{
var configInspections = new List<CodeInspection>();
var configInspections = new List<CodeInspectionSetting>();
foreach (var inspection in GetImplementedCodeInspections())
{
configInspections.Add(new CodeInspection(inspection));
configInspections.Add(new CodeInspectionSetting(inspection));
}

return configInspections.ToArray();
Expand Down
2 changes: 1 addition & 1 deletion RetailCoder.VBE/Config/IConfigurationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Rubberduck.Config
{
public interface IConfigurationService
{
CodeInspection[] GetDefaultCodeInspections();
CodeInspectionSetting[] GetDefaultCodeInspections();
Configuration GetDefaultConfiguration();
ToDoMarker[] GetDefaultTodoMarkers();
IList<Rubberduck.Inspections.IInspection> GetImplementedCodeInspections();
Expand Down
10 changes: 8 additions & 2 deletions RetailCoder.VBE/Inspections/IInspection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
namespace Rubberduck.Inspections
{
/// <summary>
/// An interface that abstracts a code inspection.
/// An interface that abstracts the data structure for a code inspection
/// </summary>
public interface IInspection
public interface IInspectionModel
{
/// <summary>
/// Gets a short description for the code inspection.
Expand All @@ -26,7 +26,13 @@ public interface IInspection
/// Gets a value indicating the severity level of the code inspection.
/// </summary>
CodeInspectionSeverity Severity { get; set; }
}

/// <summary>
/// An interface that abstracts a runnable code inspection.
/// </summary>
public interface IInspection : IInspectionModel
{
/// <summary>
/// Runs code inspection on specified parse trees.
/// </summary>
Expand Down
4 changes: 2 additions & 2 deletions RetailCoder.VBE/UI/Settings/CodeInspectionControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ public CodeInspectionControl()
InitializeComponent();
}

public CodeInspectionControl(IEnumerable<CodeInspection> inspections)
public CodeInspectionControl(IEnumerable<CodeInspectionSetting> inspections)
: this()
{
var allInspections = new BindingList<CodeInspection>(inspections
var allInspections = new BindingList<CodeInspectionSetting>(inspections
.OrderBy(c => c.InspectionType.ToString())
.ThenBy(c => c.Name)
.ToList()
Expand Down

0 comments on commit 3dfbee3

Please sign in to comment.