Skip to content

Commit

Permalink
Use generic collections
Browse files Browse the repository at this point in the history
  • Loading branch information
drewnoakes committed Jul 6, 2018
1 parent 156b0df commit fd69af3
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 21 deletions.
7 changes: 4 additions & 3 deletions Project/Src/Document/HighlightingStrategy/HighlightRuleSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
// <version>$Revision$</version>
// </file>

using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Xml;
using ICSharpCode.TextEditor.Util;

Expand Down Expand Up @@ -85,7 +86,7 @@ public HighlightRuleSet(XmlElement el)
}
}

public ArrayList Spans { get; private set; } = new ArrayList();
public List<Span> Spans { get; private set; } = new List<Span>();

public LookupTable KeyWords { get; }

Expand All @@ -112,7 +113,7 @@ public void MergeFrom(HighlightRuleSet ruleSet)
Delimiters[i] |= ruleSet.Delimiters[i];
// insert merged spans in front of old spans
var oldSpans = Spans;
Spans = (ArrayList)ruleSet.Spans.Clone();
Spans = ruleSet.Spans.ToList();
Spans.AddRange(oldSpans);
//keyWords.MergeFrom(ruleSet.keyWords);
//prevMarkers.MergeFrom(ruleSet.prevMarkers);
Expand Down
36 changes: 19 additions & 17 deletions Project/Src/Document/HighlightingStrategy/HighlightingManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public class HighlightingManager
// hash table from extension name to highlighting definition,
// OR from extension name to Pair SyntaxMode,ISyntaxModeFileProvider

private readonly Hashtable extensionsToName = new Hashtable();
private readonly ArrayList syntaxModeFileProviders = new ArrayList();
private readonly Dictionary<string, string> extensionsToName = new Dictionary<string, string>();
private readonly List<ISyntaxModeFileProvider> syntaxModeFileProviders = new List<ISyntaxModeFileProvider>();

static HighlightingManager()
{
Expand All @@ -31,7 +31,7 @@ public HighlightingManager()
CreateDefaultHighlightingStrategy();
}

public Hashtable HighlightingDefinitions { get; } = new Hashtable();
public Dictionary<string, object> HighlightingDefinitions { get; } = new Dictionary<string, object>();

public static HighlightingManager Manager { get; }

Expand Down Expand Up @@ -111,28 +111,30 @@ internal KeyValuePair<SyntaxMode, ISyntaxModeFileProvider> FindHighlighterEntry(
foreach (var mode in provider.SyntaxModes)
if (mode.Name == name)
return new KeyValuePair<SyntaxMode, ISyntaxModeFileProvider>(mode, provider);
return new KeyValuePair<SyntaxMode, ISyntaxModeFileProvider>(key: null, value: null);
return default;
}

public IHighlightingStrategy FindHighlighter(string name)
{
var def = HighlightingDefinitions[name];
if (def is DictionaryEntry entry)
return LoadDefinition(entry);
return def == null ? DefaultHighlighting : (IHighlightingStrategy)def;
if (HighlightingDefinitions.TryGetValue(name, out var def))
{
switch (def)
{
case DictionaryEntry entry:
return LoadDefinition(entry);
case IHighlightingStrategy strategy:
return strategy;
}
}

return DefaultHighlighting;
}

public IHighlightingStrategy FindHighlighterForFile(string fileName)
{
var highlighterName = (string)extensionsToName[Path.GetExtension(fileName).ToUpperInvariant()];
if (highlighterName != null)
{
var def = HighlightingDefinitions[highlighterName];
if (def is DictionaryEntry entry)
return LoadDefinition(entry);
return def == null ? DefaultHighlighting : (IHighlightingStrategy)def;
}

var extension = Path.GetExtension(fileName).ToUpperInvariant();
if (extensionsToName.TryGetValue(extension, out var highlighterName))
return FindHighlighter(highlighterName);
return DefaultHighlighting;
}

Expand Down
2 changes: 1 addition & 1 deletion Project/Src/Document/IDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public interface IDocument
/// <remarks>
/// Returns a <see cref="LineSegment" /> for the given line number.
/// This function should be used to get a line instead of getting the
/// line using the <see cref="ArrayList" />.
/// line using the list.
/// </remarks>
/// <param name="lineNumber">
/// The line number which is requested.
Expand Down

0 comments on commit fd69af3

Please sign in to comment.