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. 37
      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. 2
      ICSharpCode.NRefactory.Tests/CSharp/CodeActions/DeclareLocalVariableTests.cs
  8. 36
      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.

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

@ -76,11 +76,7 @@ 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 |= t.Modifier;
m = (m & ~Modifiers.Protected) | Modifiers.ProtectedAndInternal;
} else {
m |= t.Modifier;
}
} }
return m; return m;
} }
@ -93,38 +89,17 @@ 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) { var newToken = new CSharpModifierToken(TextLocation.Empty, m);
// This modifier is a special case - it consists out of 2 tokens. node.InsertChildAfter(insertionPos, newToken, ModifierRole);
// note that protected or internal is handled by the ordering of the AllModifiers array. insertionPos = newToken;
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);
node.InsertChildAfter(insertionPos, newToken, ModifierRole);
insertionPos = newToken;
}
} else { } else {
// Modifier already exists // Modifier already exists
if (m == Modifiers.ProtectedAndInternal) { insertionPos = node.GetChildrenByRole(ModifierRole).First(t => t.Modifier == m);
insertionPos = node.GetChildrenByRole(ModifierRole).First(t => t.Modifier == Modifiers.Internal);
} else {
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 == m).Remove();
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();
}
} }
} }
} }

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:

2
ICSharpCode.NRefactory.Tests/CSharp/CodeActions/DeclareLocalVariableTests.cs

@ -206,7 +206,7 @@ namespace ICSharpCode.NRefactory.CSharp.CodeActions
void DoStuff() void DoStuff()
{ {
System.Func<int> getInt = GetInt; System.Func<int> getInt = GetInt;
if (getInt() == 0) { if (getInt () == 0) {
} }
} }

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

@ -30,9 +30,9 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.TypeMembers
ParseUtilCSharp.AssertTypeMember( ParseUtilCSharp.AssertTypeMember(
"int[,,,] myField;", "int[,,,] myField;",
new FieldDeclaration { new FieldDeclaration {
ReturnType = new PrimitiveType("int").MakeArrayType(4), ReturnType = new PrimitiveType("int").MakeArrayType(4),
Variables = { new VariableInitializer("myField") } Variables = { new VariableInitializer("myField") }
}); });
} }
[Test] [Test]
@ -77,8 +77,8 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.TypeMembers
ParseUtilCSharp.AssertTypeMember( ParseUtilCSharp.AssertTypeMember(
"public unsafe fixed int Field[100];", "public unsafe fixed int Field[100];",
new FixedFieldDeclaration() { new FixedFieldDeclaration() {
Modifiers = Modifiers.Public | Modifiers.Unsafe, Modifiers = Modifiers.Public | Modifiers.Unsafe,
ReturnType = new PrimitiveType("int"), ReturnType = new PrimitiveType("int"),
Variables = { Variables = {
new FixedVariableInitializer { new FixedVariableInitializer {
Name = "Field", Name = "Field",
@ -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