Browse Source

Revert "[AST] Handled protected and/or internal on AST level."

"protected internal" and "internal protected" are the same thing in C#.
Both map to ProtectedOrInternal; the ProtectedAndInternal accessibility is
not usable from C#.
This reverts commit b5ad2882ca.
newNRvisualizers
Daniel Grunwald 13 years ago
parent
commit
f558b300e7
  1. 4
      ICSharpCode.NRefactory.CSharp/Ast/CSharpModifierToken.cs
  2. 4
      ICSharpCode.NRefactory.CSharp/Ast/Modifiers.cs
  3. 25
      ICSharpCode.NRefactory.CSharp/Ast/TypeMembers/EntityDeclaration.cs
  4. 8
      ICSharpCode.NRefactory.CSharp/Parser/CSharpParser.cs
  5. 3
      ICSharpCode.NRefactory.CSharp/Refactoring/TypeSystemAstBuilder.cs
  6. 6
      ICSharpCode.NRefactory.CSharp/TypeSystem/TypeSystemConvertVisitor.cs
  7. 26
      ICSharpCode.NRefactory.Tests/CSharp/Parser/TypeMembers/FieldDeclarationTests.cs

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

@ -61,7 +61,7 @@ namespace ICSharpCode.NRefactory.CSharp
// Not worth using a dictionary for such few elements. // Not worth using a dictionary for such few elements.
// This table is sorted in the order that modifiers should be output when generating code. // This table is sorted in the order that modifiers should be output when generating code.
static readonly Modifiers[] allModifiers = { static readonly Modifiers[] allModifiers = {
Modifiers.Public, Modifiers.Internal, Modifiers.Protected, Modifiers.Private, Modifiers.ProtectedAndInternal, Modifiers.Public, Modifiers.Protected, Modifiers.Private, Modifiers.Internal,
Modifiers.New, Modifiers.New,
Modifiers.Unsafe, Modifiers.Unsafe,
Modifiers.Abstract, Modifiers.Virtual, Modifiers.Sealed, Modifiers.Static, Modifiers.Override, Modifiers.Abstract, Modifiers.Virtual, Modifiers.Sealed, Modifiers.Static, Modifiers.Override,
@ -89,8 +89,6 @@ namespace ICSharpCode.NRefactory.CSharp
return "internal"; return "internal";
case Modifiers.Protected: case Modifiers.Protected:
return "protected"; return "protected";
case Modifiers.ProtectedAndInternal:
return "internal protected";
case Modifiers.Public: case Modifiers.Public:
return "public"; return "public";
case Modifiers.Abstract: case Modifiers.Abstract:

4
ICSharpCode.NRefactory.CSharp/Ast/Modifiers.cs

@ -55,9 +55,7 @@ namespace ICSharpCode.NRefactory.CSharp
Unsafe = 0x8000, Unsafe = 0x8000,
Async = 0x10000, Async = 0x10000,
ProtectedOrInternal = Protected | Internal, VisibilityMask = Private | Internal | Protected | Public,
ProtectedAndInternal = 0x20000,
VisibilityMask = Private | Internal | Protected | Public | ProtectedAndInternal,
/// <summary> /// <summary>
/// Special value used to match any modifiers during pattern matching. /// Special value used to match any modifiers during pattern matching.

25
ICSharpCode.NRefactory.CSharp/Ast/TypeMembers/EntityDeclaration.cs

@ -76,12 +76,8 @@ namespace ICSharpCode.NRefactory.CSharp
{ {
Modifiers m = 0; Modifiers m = 0;
foreach (CSharpModifierToken t in node.GetChildrenByRole (ModifierRole)) { foreach (CSharpModifierToken t in node.GetChildrenByRole (ModifierRole)) {
if (t.Modifier == Modifiers.Internal && m.HasFlag (Modifiers.Protected)) {
m = (m & ~Modifiers.Protected) | Modifiers.ProtectedAndInternal;
} else {
m |= t.Modifier; m |= t.Modifier;
} }
}
return m; return m;
} }
@ -93,42 +89,21 @@ 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
if (m == Modifiers.ProtectedAndInternal) {
// This modifier is a special case - it consists out of 2 tokens.
// note that protected or internal is handled by the ordering of the AllModifiers array.
var newToken = new CSharpModifierToken(TextLocation.Empty, Modifiers.Protected);
node.InsertChildAfter(insertionPos, newToken, ModifierRole);
insertionPos = newToken;
newToken = new CSharpModifierToken(TextLocation.Empty, Modifiers.Internal);
node.InsertChildAfter(insertionPos, newToken, ModifierRole);
insertionPos = newToken;
} else {
var newToken = new CSharpModifierToken(TextLocation.Empty, m); var newToken = new CSharpModifierToken(TextLocation.Empty, m);
node.InsertChildAfter(insertionPos, newToken, ModifierRole); node.InsertChildAfter(insertionPos, newToken, ModifierRole);
insertionPos = newToken; insertionPos = newToken;
}
} else { } else {
// Modifier already exists // Modifier already exists
if (m == Modifiers.ProtectedAndInternal) {
insertionPos = node.GetChildrenByRole(ModifierRole).First(t => t.Modifier == Modifiers.Internal);
} else {
insertionPos = node.GetChildrenByRole(ModifierRole).First(t => t.Modifier == m); insertionPos = node.GetChildrenByRole(ModifierRole).First(t => t.Modifier == m);
} }
}
} else { } else {
if ((m & oldValue) != 0) { if ((m & oldValue) != 0) {
// Modifier was removed // Modifier was removed
if (m == Modifiers.ProtectedAndInternal) {
node.GetChildrenByRole (ModifierRole).First(t => t.Modifier == Modifiers.Protected).Remove();
node.GetChildrenByRole (ModifierRole).First(t => t.Modifier == Modifiers.Internal).Remove();
} else {
node.GetChildrenByRole (ModifierRole).First(t => t.Modifier == m).Remove(); node.GetChildrenByRole (ModifierRole).First(t => t.Modifier == m).Remove();
} }
} }
} }
} }
}
protected bool MatchAttributesAndModifiers (EntityDeclaration o, PatternMatching.Match match) protected bool MatchAttributesAndModifiers (EntityDeclaration o, PatternMatching.Match match)
{ {

8
ICSharpCode.NRefactory.CSharp/Parser/CSharpParser.cs

@ -1093,22 +1093,14 @@ namespace ICSharpCode.NRefactory.CSharp
{ {
if (location == null || location.Modifiers == null) if (location == null || location.Modifiers == null)
return; return;
Modifiers entityModifierMask = Modifiers.None;
foreach (var modifier in location.Modifiers) { foreach (var modifier in location.Modifiers) {
ICSharpCode.NRefactory.CSharp.Modifiers mod; ICSharpCode.NRefactory.CSharp.Modifiers mod;
if (!modifierTable.TryGetValue (modifier.Item1, out mod)) { if (!modifierTable.TryGetValue (modifier.Item1, out mod)) {
Console.WriteLine ("modifier " + modifier.Item1 + " can't be converted,"); Console.WriteLine ("modifier " + modifier.Item1 + " can't be converted,");
} }
if (mod == Modifiers.Internal && entityModifierMask.HasFlag (Modifiers.Protected)) {
entityModifierMask = (entityModifierMask & ~Modifiers.Protected) | Modifiers.ProtectedAndInternal;
} else {
entityModifierMask |= mod;
}
parent.AddChild (new CSharpModifierToken (Convert (modifier.Item2), mod), EntityDeclaration.ModifierRole); parent.AddChild (new CSharpModifierToken (Convert (modifier.Item2), mod), EntityDeclaration.ModifierRole);
} }
parent.Modifiers |= entityModifierMask;
} }
public override void Visit (Property p) public override void Visit (Property p)

3
ICSharpCode.NRefactory.CSharp/Refactoring/TypeSystemAstBuilder.cs

@ -753,9 +753,8 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
case Accessibility.Internal: case Accessibility.Internal:
return Modifiers.Internal; return Modifiers.Internal;
case Accessibility.ProtectedOrInternal: case Accessibility.ProtectedOrInternal:
return Modifiers.ProtectedOrInternal;
case Accessibility.ProtectedAndInternal: case Accessibility.ProtectedAndInternal:
return Modifiers.ProtectedAndInternal; return Modifiers.Protected | Modifiers.Internal;
default: default:
return Modifiers.None; return Modifiers.None;
} }

6
ICSharpCode.NRefactory.CSharp/TypeSystem/TypeSystemConvertVisitor.cs

@ -829,12 +829,10 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem
switch (modifiers & Modifiers.VisibilityMask) { switch (modifiers & Modifiers.VisibilityMask) {
case Modifiers.Private: case Modifiers.Private:
return Accessibility.Private; return Accessibility.Private;
case Modifiers.ProtectedOrInternal: // Modifiers.Protected | Modifiers.Internal
return Accessibility.ProtectedOrInternal;
case Modifiers.ProtectedAndInternal:
return Accessibility.ProtectedAndInternal;
case Modifiers.Internal: case Modifiers.Internal:
return Accessibility.Internal; return Accessibility.Internal;
case Modifiers.Protected | Modifiers.Internal:
return Accessibility.ProtectedOrInternal;
case Modifiers.Protected: case Modifiers.Protected:
return Accessibility.Protected; return Accessibility.Protected;
case Modifiers.Public: case Modifiers.Public:

26
ICSharpCode.NRefactory.Tests/CSharp/Parser/TypeMembers/FieldDeclarationTests.cs

@ -87,31 +87,5 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.TypeMembers
} }
}); });
} }
[Test]
public void InternalAndProtectedFieldTest()
{
ParseUtilCSharp.AssertTypeMember(
"protected internal int myField;",
new FieldDeclaration {
Modifiers = Modifiers.ProtectedAndInternal,
ReturnType = new PrimitiveType("int"),
Variables = { new VariableInitializer("myField") }
}
);
}
[Test]
public void InternalOrProtectedFieldTest()
{
ParseUtilCSharp.AssertTypeMember(
"internal protected int myField;",
new FieldDeclaration {
Modifiers = Modifiers.ProtectedOrInternal,
ReturnType = new PrimitiveType("int"),
Variables = { new VariableInitializer("myField") }
}
);
}
} }
} }

Loading…
Cancel
Save