Browse Source

ResourceToolkit: Applied some fixes from FxCop. Especially reduced nesting of generics by using a custom ResourceItem class instead of KeyValuePair<string,string>.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@1891 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Christian Hornung 20 years ago
parent
commit
409a1a13d9
  1. 1
      src/AddIns/Misc/ResourceToolkit/Project/ResourceToolkit.csproj
  2. 2
      src/AddIns/Misc/ResourceToolkit/Project/Src/Commands/RefactoringCommands.cs
  3. 1
      src/AddIns/Misc/ResourceToolkit/Project/Src/Commands/TextEditorContextMenuBuilder.cs
  4. 1
      src/AddIns/Misc/ResourceToolkit/Project/Src/Gui/EditStringResourceDialog.cs
  5. 8
      src/AddIns/Misc/ResourceToolkit/Project/Src/Gui/UnusedResourceKeysCommands.cs
  6. 39
      src/AddIns/Misc/ResourceToolkit/Project/Src/Gui/UnusedResourceKeysViewContent.cs
  7. 13
      src/AddIns/Misc/ResourceToolkit/Project/Src/Refactoring/ResourceRefactoringService.cs
  8. 3
      src/AddIns/Misc/ResourceToolkit/Project/Src/Resolver/NRefactoryAstCacheService.cs
  9. 1
      src/AddIns/Misc/ResourceToolkit/Project/Src/Resolver/PropertyFieldAssociationVisitor.cs
  10. 2
      src/AddIns/Misc/ResourceToolkit/Project/Src/ResourceFileContent/DefaultFileLocalizedResourcesFinder.cs
  11. 4
      src/AddIns/Misc/ResourceToolkit/Project/Src/ResourceFileContent/MergedResourceFileContent.cs
  12. 53
      src/AddIns/Misc/ResourceToolkit/Project/Src/ResourceItem.cs

1
src/AddIns/Misc/ResourceToolkit/Project/ResourceToolkit.csproj

@ -89,6 +89,7 @@ @@ -89,6 +89,7 @@
<Compile Include="Src\Gui\UnusedResourceKeysCommands.cs" />
<Compile Include="Src\Gui\IFilter.cs" />
<Compile Include="Src\Gui\IFilterHost.cs" />
<Compile Include="Src\ResourceItem.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\..\Main\ICSharpCode.SharpDevelop.Dom\Project\ICSharpCode.SharpDevelop.Dom.csproj">

2
src/AddIns/Misc/ResourceToolkit/Project/Src/Commands/RefactoringCommands.cs

@ -36,7 +36,7 @@ namespace Hornung.ResourceToolkit.Commands @@ -36,7 +36,7 @@ namespace Hornung.ResourceToolkit.Commands
{
public override void Run()
{
ICollection<KeyValuePair<string, string>> unusedKeys = ResourceRefactoringService.FindUnusedKeys();
ICollection<ResourceItem> unusedKeys = ResourceRefactoringService.FindUnusedKeys();
if (unusedKeys == null) {
return;

1
src/AddIns/Misc/ResourceToolkit/Project/Src/Commands/TextEditorContextMenuBuilder.cs

@ -74,6 +74,7 @@ namespace Hornung.ResourceToolkit.Commands @@ -74,6 +74,7 @@ namespace Hornung.ResourceToolkit.Commands
// ********************************************************************************************************************************
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1303:DoNotPassLiteralsAsLocalizedParameters", MessageId = "ICSharpCode.Core.MessageService.ShowWarning(System.String)")]
void EditResource(object sender, EventArgs e)
{
MenuCommand cmd = sender as MenuCommand;

1
src/AddIns/Misc/ResourceToolkit/Project/Src/Gui/EditStringResourceDialog.cs

@ -55,6 +55,7 @@ namespace Hornung.ResourceToolkit.Gui @@ -55,6 +55,7 @@ namespace Hornung.ResourceToolkit.Gui
SetupFromXmlStream(this.GetType().Assembly.GetManifestResourceStream("Hornung.ResourceToolkit.Resources.EditStringResourceDialog.xfrm"));
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1303:DoNotPassLiteralsAsLocalizedParameters", MessageId = "ICSharpCode.Core.MessageService.ShowWarning(System.String)")]
void KeyValidating(object sender, CancelEventArgs e)
{
TextBox textBox = (TextBox)sender;

8
src/AddIns/Misc/ResourceToolkit/Project/Src/Gui/UnusedResourceKeysCommands.cs

@ -17,7 +17,7 @@ namespace Hornung.ResourceToolkit.Gui @@ -17,7 +17,7 @@ namespace Hornung.ResourceToolkit.Gui
/// <summary>
/// Hides or shows the ICSharpCode.Core host resources in an UnusedResourceKeysViewContent.
/// </summary>
public class UnusedResourceKeysHideICSharpCodeCoreHostResourcesCommand : AbstractCheckableMenuCommand, IFilter<KeyValuePair<string, string>>
public class UnusedResourceKeysHideICSharpCodeCoreHostResourcesCommand : AbstractCheckableMenuCommand, IFilter<ResourceItem>
{
string icSharpCodeCoreHostResourceFileName;
@ -25,7 +25,7 @@ namespace Hornung.ResourceToolkit.Gui @@ -25,7 +25,7 @@ namespace Hornung.ResourceToolkit.Gui
{
base.Run();
IFilterHost<KeyValuePair<string, string>> host = ((ToolBarCheckBox)this.Owner).Caller as IFilterHost<KeyValuePair<string, string>>;
IFilterHost<ResourceItem> host = ((ToolBarCheckBox)this.Owner).Caller as IFilterHost<ResourceItem>;
if (host != null) {
if (this.IsChecked) {
this.icSharpCodeCoreHostResourceFileName = ICSharpCodeCoreResourceResolver.GetICSharpCodeCoreHostResourceFileName(null);
@ -41,9 +41,9 @@ namespace Hornung.ResourceToolkit.Gui @@ -41,9 +41,9 @@ namespace Hornung.ResourceToolkit.Gui
/// </summary>
/// <param name="item">The item to test.</param>
/// <returns><c>true</c>, if the specified item matches the current filter criteria, otherwise <c>false</c>.</returns>
public bool IsMatch(KeyValuePair<string, string> item)
public bool IsMatch(ResourceItem item)
{
return !FileUtility.IsEqualFileName(item.Value, this.icSharpCodeCoreHostResourceFileName);
return !FileUtility.IsEqualFileName(item.FileName, this.icSharpCodeCoreHostResourceFileName);
}
}
}

39
src/AddIns/Misc/ResourceToolkit/Project/Src/Gui/UnusedResourceKeysViewContent.cs

@ -22,9 +22,9 @@ namespace Hornung.ResourceToolkit.Gui @@ -22,9 +22,9 @@ namespace Hornung.ResourceToolkit.Gui
/// <summary>
/// Displays unused resource keys in a list and allows the user to delete them.
/// </summary>
public class UnusedResourceKeysViewContent : AbstractViewContent, IClipboardHandler, IFilterHost<KeyValuePair<string, string>>
public class UnusedResourceKeysViewContent : AbstractViewContent, IClipboardHandler, IFilterHost<ResourceItem>
{
readonly ICollection<KeyValuePair<string, string>> unusedKeys;
readonly ICollection<ResourceItem> unusedKeys;
Panel panel;
ListView listView;
ToolStrip toolStrip;
@ -47,7 +47,7 @@ namespace Hornung.ResourceToolkit.Gui @@ -47,7 +47,7 @@ namespace Hornung.ResourceToolkit.Gui
/// <summary>
/// Gets a collection of key/value pairs where the values are the resource file names and the keys are the unused resource keys.
/// </summary>
public ICollection<KeyValuePair<string, string>> UnusedKeys {
public ICollection<ResourceItem> UnusedKeys {
get {
return this.unusedKeys;
}
@ -56,8 +56,8 @@ namespace Hornung.ResourceToolkit.Gui @@ -56,8 +56,8 @@ namespace Hornung.ResourceToolkit.Gui
/// <summary>
/// Initializes a new instance of the <see cref="UnusedResourceKeysViewContent"/> class.
/// </summary>
/// <param name="unusedKeys">A collection of key/value pairs where the values are the resource file names and the keys are the unused resource keys.</param>
public UnusedResourceKeysViewContent(ICollection<KeyValuePair<string, string>> unusedKeys)
/// <param name="unusedKeys">A collection of <see cref="ResourceItem"/> classes that represent the unused resource keys to display.</param>
public UnusedResourceKeysViewContent(ICollection<ResourceItem> unusedKeys)
: base(StringParser.Parse("${res:Hornung.ResourceToolkit.UnusedResourceKeys.Title}"))
{
LoggingService.Debug("ResourceToolkit: Creating new UnusedResourceKeysViewContent");
@ -144,7 +144,7 @@ namespace Hornung.ResourceToolkit.Gui @@ -144,7 +144,7 @@ namespace Hornung.ResourceToolkit.Gui
}
}
bool fillListViewQueued = false;
bool fillListViewQueued;
/// <summary>
/// Fills the list view with all unused resource keys that match the current filter after processing the message queue.
@ -178,32 +178,32 @@ namespace Hornung.ResourceToolkit.Gui @@ -178,32 +178,32 @@ namespace Hornung.ResourceToolkit.Gui
Dictionary<string, ListViewGroup> fileGroups = new Dictionary<string, ListViewGroup>();
// Create the ListViewItems.
foreach (KeyValuePair<string, string> entry in this.UnusedKeys) {
foreach (ResourceItem entry in this.UnusedKeys) {
// Skip if any filter rejects this item.
if (!this.ItemMatchesCurrentFilter(entry)) {
continue;
}
IResourceFileContent c = ResourceFileContentRegistry.GetResourceFileContent(entry.Value);
IResourceFileContent c = ResourceFileContentRegistry.GetResourceFileContent(entry.FileName);
object o;
// only add the file name to save space
// and show the full path as tooltip
ListViewItem item = new ListViewItem(Path.GetFileName(entry.Value));
item.ToolTipText = entry.Value;
ListViewItem item = new ListViewItem(Path.GetFileName(entry.FileName));
item.ToolTipText = entry.FileName;
item.SubItems.Add(entry.Key);
if (c.TryGetValue(entry.Key, out o)) {
item.SubItems.Add((o ?? (object)"<<null>>").ToString());
} else {
throw new InvalidOperationException("The key '"+entry.Key+"' in file '"+entry.Value+"' does not exist although it was reported as unused.");
throw new InvalidOperationException("The key '"+entry.Key+"' in file '"+entry.FileName+"' does not exist although it was reported as unused.");
}
// Use ListViewGroups to group by file names
ListViewGroup grp;
if (!fileGroups.TryGetValue(entry.Value, out grp)) {
grp = new ListViewGroup(entry.Value);
fileGroups.Add(entry.Value, grp);
if (!fileGroups.TryGetValue(entry.FileName, out grp)) {
grp = new ListViewGroup(entry.FileName);
fileGroups.Add(entry.FileName, grp);
this.ListView.Groups.Add(grp);
}
grp.Items.Add(item);
@ -222,7 +222,7 @@ namespace Hornung.ResourceToolkit.Gui @@ -222,7 +222,7 @@ namespace Hornung.ResourceToolkit.Gui
#region Filter
readonly List<IFilter<KeyValuePair<string, string>>> filters = new List<IFilter<KeyValuePair<string, string>>>();
readonly List<IFilter<ResourceItem>> filters = new List<IFilter<ResourceItem>>();
/// <summary>
/// Registers a new filter with the filter host, if the filter is not already registered,
@ -230,7 +230,7 @@ namespace Hornung.ResourceToolkit.Gui @@ -230,7 +230,7 @@ namespace Hornung.ResourceToolkit.Gui
/// </summary>
/// <param name="filter">The filter to be registered.</param>
/// <exception cref="ArgumentNullException">The <paramref name="filter"/> parameter is <c>null</c>.</exception>
public void RegisterFilter(IFilter<KeyValuePair<string, string>> filter)
public void RegisterFilter(IFilter<ResourceItem> filter)
{
if (filter == null) {
throw new ArgumentNullException("filter");
@ -248,7 +248,7 @@ namespace Hornung.ResourceToolkit.Gui @@ -248,7 +248,7 @@ namespace Hornung.ResourceToolkit.Gui
/// </summary>
/// <param name="filter">The filter to be removed.</param>
/// <exception cref="ArgumentNullException">The <paramref name="filter"/> parameter is <c>null</c>.</exception>
public void UnregisterFilter(IFilter<KeyValuePair<string, string>> filter)
public void UnregisterFilter(IFilter<ResourceItem> filter)
{
if (filter == null) {
throw new ArgumentNullException("filter");
@ -264,9 +264,9 @@ namespace Hornung.ResourceToolkit.Gui @@ -264,9 +264,9 @@ namespace Hornung.ResourceToolkit.Gui
/// according to the current filter.
/// </summary>
/// <returns><c>true</c>, if the resource should be included in the list view, otherwise <c>false</c>.</returns>
bool ItemMatchesCurrentFilter(KeyValuePair<string, string> item)
bool ItemMatchesCurrentFilter(ResourceItem item)
{
foreach (IFilter<KeyValuePair<string, string>> filter in this.filters) {
foreach (IFilter<ResourceItem> filter in this.filters) {
if (!filter.IsMatch(item)) {
return false;
}
@ -325,6 +325,7 @@ namespace Hornung.ResourceToolkit.Gui @@ -325,6 +325,7 @@ namespace Hornung.ResourceToolkit.Gui
throw new NotImplementedException();
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1814:PreferJaggedArraysOverMultidimensional", MessageId = "Body")]
public void Delete()
{
if (this.ListView.SelectedItems.Count > 0) {

13
src/AddIns/Misc/ResourceToolkit/Project/Src/Refactoring/ResourceRefactoringService.cs

@ -170,8 +170,8 @@ namespace Hornung.ResourceToolkit.Refactoring @@ -170,8 +170,8 @@ namespace Hornung.ResourceToolkit.Refactoring
/// Finds all unused resource keys in all resource files that are referenced
/// in code at least once in the whole solution.
/// </summary>
/// <returns>A collection of key/value pairs where the values are the resource file names and the keys are the unused resource keys.</returns>
public static ICollection<KeyValuePair<string, string>> FindUnusedKeys()
/// <returns>A collection of <see cref="ResourceItem"/> classes that represent the unused resource keys.</returns>
public static ICollection<ResourceItem> FindUnusedKeys()
{
List<Reference> references = FindAllReferences();
if (references == null) {
@ -179,7 +179,7 @@ namespace Hornung.ResourceToolkit.Refactoring @@ -179,7 +179,7 @@ namespace Hornung.ResourceToolkit.Refactoring
}
DateTime startTime = DateTime.UtcNow;
List<KeyValuePair<string, string>> unused = new List<KeyValuePair<string, string>>();
List<ResourceItem> unused = new List<ResourceItem>();
// Get a list of all referenced resource files.
// Generate a dictonary of resource file names and the
@ -207,7 +207,7 @@ namespace Hornung.ResourceToolkit.Refactoring @@ -207,7 +207,7 @@ namespace Hornung.ResourceToolkit.Refactoring
#endif
foreach (KeyValuePair<string, object> entry in ResourceFileContentRegistry.GetResourceFileContent(fileName).Data) {
if (!referencedKeys[fileName].Contains(entry.Key)) {
unused.Add(new KeyValuePair<string, string>(entry.Key, fileName));
unused.Add(new ResourceItem(fileName, entry.Key));
}
}
}
@ -224,6 +224,7 @@ namespace Hornung.ResourceToolkit.Refactoring @@ -224,6 +224,7 @@ namespace Hornung.ResourceToolkit.Refactoring
/// Asks the user for a new name.
/// </summary>
/// <param name="rrr">The resource to be renamed.</param>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1303:DoNotPassLiteralsAsLocalizedParameters", MessageId = "ICSharpCode.Core.MessageService.ShowInputBox(System.String,System.String,System.String)")]
public static void Rename(ResourceResolveResult rrr)
{
string newKey = MessageService.ShowInputBox("${res:SharpDevelop.Refactoring.Rename}", "${res:Hornung.ResourceToolkit.RenameResourceText}", rrr.Key);
@ -275,7 +276,7 @@ namespace Hornung.ResourceToolkit.Refactoring @@ -275,7 +276,7 @@ namespace Hornung.ResourceToolkit.Refactoring
/// Gets a list of names of files which can possibly contain resource references.
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")]
public static List<string> GetPossibleFiles()
public static ICollection<string> GetPossibleFiles()
{
List<string> files = new List<string>();
@ -307,7 +308,7 @@ namespace Hornung.ResourceToolkit.Refactoring @@ -307,7 +308,7 @@ namespace Hornung.ResourceToolkit.Refactoring
}
return files;
return files.AsReadOnly();
}
/// <summary>

3
src/AddIns/Misc/ResourceToolkit/Project/Src/Resolver/NRefactoryAstCacheService.cs

@ -22,7 +22,7 @@ namespace Hornung.ResourceToolkit.Resolver @@ -22,7 +22,7 @@ namespace Hornung.ResourceToolkit.Resolver
/// </summary>
public static class NRefactoryAstCacheService
{
static bool cacheEnabled = false;
static bool cacheEnabled;
static Dictionary<string, CompilationUnit> cachedAstInfo = new Dictionary<string, CompilationUnit>();
/// <summary>
@ -38,6 +38,7 @@ namespace Hornung.ResourceToolkit.Resolver @@ -38,6 +38,7 @@ namespace Hornung.ResourceToolkit.Resolver
/// Enables the AST cache.
/// </summary>
/// <exception cref="InvalidOperationException">The AST cache is already enabled.</exception>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1303:DoNotPassLiteralsAsLocalizedParameters", MessageId = "System.InvalidOperationException.#ctor(System.String)")]
public static void EnableCache()
{
if (CacheEnabled) {

1
src/AddIns/Misc/ResourceToolkit/Project/Src/Resolver/PropertyFieldAssociationVisitor.cs

@ -228,6 +228,7 @@ namespace Hornung.ResourceToolkit.Resolver @@ -228,6 +228,7 @@ namespace Hornung.ResourceToolkit.Resolver
/// Initializes a new instance of the <see cref="PropertyFieldAssociationVisitor"/> class.
/// </summary>
/// <param name="field">The field to find the associated property for.</param>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1303:DoNotPassLiteralsAsLocalizedParameters", MessageId = "System.ArgumentException.#ctor(System.String,System.String)")]
public PropertyFieldAssociationVisitor(IField field) : base()
{
if (field == null) {

2
src/AddIns/Misc/ResourceToolkit/Project/Src/ResourceFileContent/DefaultFileLocalizedResourcesFinder.cs

@ -35,7 +35,7 @@ namespace Hornung.ResourceToolkit.ResourceFileContent @@ -35,7 +35,7 @@ namespace Hornung.ResourceToolkit.ResourceFileContent
string culture = Path.GetExtension(fileNameWithoutExtension);
if (!String.IsNullOrEmpty(culture)) {
try {
CultureInfo dummy = CultureInfo.GetCultureInfo(culture);
CultureInfo.GetCultureInfo(culture);
// the specified file is a localized resource file itself
LoggingService.Debug("ResourceToolkit: DefaultFileLocalizedResourcesFinder.GetLocalizedContents: Returning null for file '"+fileName+"' because it has been detected as being a localized resource file itself.");
return null;

4
src/AddIns/Misc/ResourceToolkit/Project/Src/ResourceFileContent/MergedResourceFileContent.cs

@ -28,6 +28,7 @@ namespace Hornung.ResourceToolkit.ResourceFileContent @@ -28,6 +28,7 @@ namespace Hornung.ResourceToolkit.ResourceFileContent
/// <param name="masterContent">The master resource file content.</param>
/// <param name="otherContents">Additional resource file contents.</param>
/// <exception cref="ArgumentException">The cultures of the specified resource file contents do not match.</exception>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1303:DoNotPassLiteralsAsLocalizedParameters", MessageId = "System.ArgumentException.#ctor(System.String)")]
public MergedResourceFileContent(IResourceFileContent masterContent, IResourceFileContent[] otherContents)
{
this.masterContent = masterContent;
@ -123,6 +124,7 @@ namespace Hornung.ResourceToolkit.ResourceFileContent @@ -123,6 +124,7 @@ namespace Hornung.ResourceToolkit.ResourceFileContent
/// Modify the value of an existing entry.
/// </summary>
/// <exception cref="ArgumentException">The specified key does not exist.</exception>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1303:DoNotPassLiteralsAsLocalizedParameters", MessageId = "System.ArgumentException.#ctor(System.String,System.String)")]
public void SetValue(string key, object value)
{
if (this.masterContent.ContainsKey(key)) {
@ -145,6 +147,7 @@ namespace Hornung.ResourceToolkit.ResourceFileContent @@ -145,6 +147,7 @@ namespace Hornung.ResourceToolkit.ResourceFileContent
/// <param name="oldName">The old name of the resource key to rename.</param>
/// <param name="newName">The new name of the resource key.</param>
/// <exception cref="ArgumentException">The specified key does not exist or the new key does already exist.</exception>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1303:DoNotPassLiteralsAsLocalizedParameters", MessageId = "System.ArgumentException.#ctor(System.String,System.String)")]
public void RenameKey(string oldName, string newName)
{
if (this.masterContent.ContainsKey(oldName)) {
@ -166,6 +169,7 @@ namespace Hornung.ResourceToolkit.ResourceFileContent @@ -166,6 +169,7 @@ namespace Hornung.ResourceToolkit.ResourceFileContent
/// </summary>
/// <param name="key">The resource key to remove.</param>
/// <exception cref="ArgumentException">The specified key does not exist.</exception>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1303:DoNotPassLiteralsAsLocalizedParameters", MessageId = "System.ArgumentException.#ctor(System.String,System.String)")]
public void RemoveKey(string key)
{
if (this.masterContent.ContainsKey(key)) {

53
src/AddIns/Misc/ResourceToolkit/Project/Src/ResourceItem.cs

@ -0,0 +1,53 @@ @@ -0,0 +1,53 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Christian Hornung" email="c-hornung@gmx.de"/>
// <version>$Revision$</version>
// </file>
using System;
namespace Hornung.ResourceToolkit
{
/// <summary>
/// Describes a resource item by file name and key.
/// </summary>
public class ResourceItem
{
readonly string fileName;
readonly string key;
/// <summary>
/// Initializes a new instance of the <see cref="ResourceItem"/> class.
/// </summary>
/// <param name="fileName">The name of the resource file.</param>
/// <param name="key">The resource key.</param>
/// <exception cref="ArgumentNullException">The <paramref name="fileName"/> parameter is <c>null</c>.</exception>
public ResourceItem(string fileName, string key)
{
if (fileName == null) {
throw new ArgumentNullException("fileName");
}
this.fileName = fileName;
this.key = key;
}
/// <summary>
/// Gets the name of the resource file this resource item is contained in.
/// </summary>
public string FileName {
get {
return fileName;
}
}
/// <summary>
/// Gets the resource key of this resource item.
/// </summary>
public string Key {
get {
return key;
}
}
}
}
Loading…
Cancel
Save