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 @@ -61,7 +61,7 @@ namespace ICSharpCode.NRefactory.CSharp
// Not worth using a dictionary for such few elements.
// This table is sorted in the order that modifiers should be output when generating code.
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.Unsafe,
Modifiers.Abstract, Modifiers.Virtual, Modifiers.Sealed, Modifiers.Static, Modifiers.Override,
@ -89,8 +89,6 @@ namespace ICSharpCode.NRefactory.CSharp @@ -89,8 +89,6 @@ namespace ICSharpCode.NRefactory.CSharp
return "internal";
case Modifiers.Protected:
return "protected";
case Modifiers.ProtectedAndInternal:
return "internal protected";
case Modifiers.Public:
return "public";
case Modifiers.Abstract:

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

@ -55,9 +55,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -55,9 +55,7 @@ namespace ICSharpCode.NRefactory.CSharp
Unsafe = 0x8000,
Async = 0x10000,
ProtectedOrInternal = Protected | Internal,
ProtectedAndInternal = 0x20000,
VisibilityMask = Private | Internal | Protected | Public | ProtectedAndInternal,
VisibilityMask = Private | Internal | Protected | Public,
/// <summary>
/// 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 @@ -76,11 +76,7 @@ namespace ICSharpCode.NRefactory.CSharp
{
Modifiers m = 0;
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;
}
@ -93,38 +89,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -93,38 +89,17 @@ namespace ICSharpCode.NRefactory.CSharp
if ((m & newValue) != 0) {
if ((m & oldValue) == 0) {
// 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);
node.InsertChildAfter(insertionPos, newToken, ModifierRole);
insertionPos = newToken;
}
var newToken = new CSharpModifierToken(TextLocation.Empty, m);
node.InsertChildAfter(insertionPos, newToken, ModifierRole);
insertionPos = newToken;
} else {
// 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 {
if ((m & oldValue) != 0) {
// 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();
}
}
}

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

@ -1093,22 +1093,14 @@ namespace ICSharpCode.NRefactory.CSharp @@ -1093,22 +1093,14 @@ namespace ICSharpCode.NRefactory.CSharp
{
if (location == null || location.Modifiers == null)
return;
Modifiers entityModifierMask = Modifiers.None;
foreach (var modifier in location.Modifiers) {
ICSharpCode.NRefactory.CSharp.Modifiers mod;
if (!modifierTable.TryGetValue (modifier.Item1, out mod)) {
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.Modifiers |= entityModifierMask;
}
public override void Visit (Property p)

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

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

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

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

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

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