Browse Source

Merge branch 'master' of git://github.com/icsharpcode/ILSpy into Debugger

newNRvisualizers
Eusebiu Marcu 15 years ago
parent
commit
f3a2be8b50
  1. 52
      ICSharpCode.NRefactory/CSharp/Ast/CSharpModifierToken.cs
  2. 4
      ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/AttributedNode.cs

52
ICSharpCode.NRefactory/CSharp/Ast/CSharpModifierToken.cs

@ -25,6 +25,7 @@
// THE SOFTWARE. // THE SOFTWARE.
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
namespace ICSharpCode.NRefactory.CSharp namespace ICSharpCode.NRefactory.CSharp
{ {
@ -36,33 +37,40 @@ namespace ICSharpCode.NRefactory.CSharp
public Modifiers Modifier { public Modifiers Modifier {
get { return modifier; } get { return modifier; }
set { set {
modifier = value; for (int i = 0; i < lengthTable.Count; i++) {
if (!lengthTable.TryGetValue (modifier, out tokenLength)) if (lengthTable[i].Key == value) {
throw new InvalidOperationException ("Modifier " + modifier + " is invalid."); this.modifier = value;
this.tokenLength = lengthTable[i].Value;
return;
}
}
throw new ArgumentException ("Modifier " + value + " is invalid.");
} }
} }
static Dictionary<Modifiers, int> lengthTable = new Dictionary<Modifiers, int> () { // Not worth using a dictionary for such few elements.
{ Modifiers.Public, "public".Length }, // This table is sorted in the order that modifiers should be output when generating code.
{ Modifiers.Protected, "protected".Length }, static readonly List<KeyValuePair<Modifiers, int>> lengthTable = new List<KeyValuePair<Modifiers, int>> () {
{ Modifiers.Private, "private".Length }, new KeyValuePair<Modifiers, int>(Modifiers.Public, "public".Length),
{ Modifiers.Internal, "internal".Length }, new KeyValuePair<Modifiers, int>(Modifiers.Protected, "protected".Length),
{ Modifiers.New, "new".Length }, new KeyValuePair<Modifiers, int>(Modifiers.Private, "private".Length),
{ Modifiers.Unsafe, "unsafe".Length }, new KeyValuePair<Modifiers, int>(Modifiers.Internal, "internal".Length),
{ Modifiers.Abstract, "abstract".Length }, new KeyValuePair<Modifiers, int>(Modifiers.New, "new".Length),
{ Modifiers.Virtual, "virtual".Length }, new KeyValuePair<Modifiers, int>(Modifiers.Unsafe, "unsafe".Length),
{ Modifiers.Sealed, "sealed".Length }, new KeyValuePair<Modifiers, int>(Modifiers.Abstract, "abstract".Length),
{ Modifiers.Static, "static".Length }, new KeyValuePair<Modifiers, int>(Modifiers.Virtual, "virtual".Length),
{ Modifiers.Override, "override".Length }, new KeyValuePair<Modifiers, int>(Modifiers.Sealed, "sealed".Length),
{ Modifiers.Readonly, "readonly".Length }, new KeyValuePair<Modifiers, int>(Modifiers.Static, "static".Length),
{ Modifiers.Volatile, "volatile".Length }, new KeyValuePair<Modifiers, int>(Modifiers.Override, "override".Length),
{ Modifiers.Extern, "extern".Length }, new KeyValuePair<Modifiers, int>(Modifiers.Readonly, "readonly".Length),
{ Modifiers.Partial, "partial".Length }, new KeyValuePair<Modifiers, int>(Modifiers.Volatile, "volatile".Length),
{ Modifiers.Const, "const".Length }, new KeyValuePair<Modifiers, int>(Modifiers.Extern, "extern".Length),
new KeyValuePair<Modifiers, int>(Modifiers.Partial, "partial".Length),
new KeyValuePair<Modifiers, int>(Modifiers.Const, "const".Length)
}; };
public static ICollection<Modifiers> AllModifiers { public static IEnumerable<Modifiers> AllModifiers {
get { return lengthTable.Keys; } get { return lengthTable.Select(p => p.Key); }
} }
public CSharpModifierToken (AstLocation location, Modifiers modifier) : base (location, 0) public CSharpModifierToken (AstLocation location, Modifiers modifier) : base (location, 0)

4
ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/AttributedNode.cs

@ -42,7 +42,9 @@ namespace ICSharpCode.NRefactory.CSharp
if ((m & newValue) != 0) { if ((m & newValue) != 0) {
if ((m & oldValue) == 0) { if ((m & oldValue) == 0) {
// Modifier was added // Modifier was added
node.InsertChildAfter(insertionPos, new CSharpModifierToken(AstLocation.Empty, m), ModifierRole); var newToken = new CSharpModifierToken(AstLocation.Empty, m);
node.InsertChildAfter(insertionPos, newToken, ModifierRole);
insertionPos = newToken;
} else { } else {
// Modifier already exists // Modifier already exists
insertionPos = node.GetChildrenByRole(ModifierRole).First(t => t.Modifier == m); insertionPos = node.GetChildrenByRole(ModifierRole).First(t => t.Modifier == m);

Loading…
Cancel
Save