Browse Source

Fixed SD2-992: C# Interface public elements are converted to VB as Privates ones.

Fixed default visibility of inner types.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@1674 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 19 years ago
parent
commit
66acc25b3b
  1. 8
      src/Libraries/NRefactory/Project/Src/Parser/VBNet/Parser.cs
  2. 8
      src/Libraries/NRefactory/Project/Src/Parser/VBNet/VBNET.ATG
  3. 2
      src/Libraries/NRefactory/Project/Src/PrettyPrinter/VBNet/VBNetOutputVisitor.cs
  4. 30
      src/Libraries/NRefactory/Project/Src/Visitors/ToVBNetConvertVisitor.cs
  5. 45
      src/Libraries/NRefactory/Project/Src/Visitors/VBNetConstructsConvertVisitor.cs
  6. 37
      src/Libraries/NRefactory/Test/Output/CSharp/VBToCSharpConverterTest.cs
  7. 37
      src/Libraries/NRefactory/Test/Output/VBNet/CSharpToVBConverterTest.cs
  8. 4
      src/Main/Base/Project/Src/TextEditor/Gui/Editor/CompletionWindow/AbstractCompletionDataProvider.cs
  9. 14
      src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/NRefactoryResolver/NRefactoryASTConvertVisitor.cs

8
src/Libraries/NRefactory/Project/Src/Parser/VBNet/Parser.cs

@ -1711,13 +1711,13 @@ out charsetModifer); @@ -1711,13 +1711,13 @@ out charsetModifer);
Expect(3);
#line 902 "VBNET.ATG"
library = t.literalValue.ToString();
library = t.literalValue as string;
if (la.kind == 44) {
lexer.NextToken();
Expect(3);
#line 903 "VBNET.ATG"
alias = t.literalValue.ToString();
alias = t.literalValue as string;
}
if (la.kind == 24) {
lexer.NextToken();
@ -1746,13 +1746,13 @@ p); @@ -1746,13 +1746,13 @@ p);
Expect(3);
#line 915 "VBNET.ATG"
library = t.literalValue.ToString();
library = t.literalValue as string;
if (la.kind == 44) {
lexer.NextToken();
Expect(3);
#line 916 "VBNET.ATG"
alias = t.literalValue.ToString();
alias = t.literalValue as string;
}
if (la.kind == 24) {
lexer.NextToken();

8
src/Libraries/NRefactory/Project/Src/Parser/VBNet/VBNET.ATG

@ -899,8 +899,8 @@ StructureMemberDecl<ModifierList m, List<AttributeSection> attributes> @@ -899,8 +899,8 @@ StructureMemberDecl<ModifierList m, List<AttributeSection> attributes>
(
"Sub"
Identifier (. name = t.val; .)
"Lib" LiteralString (. library = t.literalValue.ToString(); .)
["Alias" LiteralString (. alias = t.literalValue.ToString(); .)]
"Lib" LiteralString (. library = t.literalValue as string; .)
["Alias" LiteralString (. alias = t.literalValue as string; .)]
[ "(" [ FormalParameterList<p> ] ")" ]
EOL
(.
@ -912,8 +912,8 @@ StructureMemberDecl<ModifierList m, List<AttributeSection> attributes> @@ -912,8 +912,8 @@ StructureMemberDecl<ModifierList m, List<AttributeSection> attributes>
|
"Function"
Identifier (. name = t.val; .)
"Lib" LiteralString (. library = t.literalValue.ToString(); .)
["Alias" LiteralString (. alias = t.literalValue.ToString(); .)]
"Lib" LiteralString (. library = t.literalValue as string; .)
["Alias" LiteralString (. alias = t.literalValue as string; .)]
[ "(" [ FormalParameterList<p> ] ")" ]
["As" TypeName<out type> ]
EOL

2
src/Libraries/NRefactory/Project/Src/PrettyPrinter/VBNet/VBNetOutputVisitor.cs

@ -424,6 +424,8 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -424,6 +424,8 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
public object VisitDelegateDeclaration(DelegateDeclaration delegateDeclaration, object data)
{
VisitAttributes(delegateDeclaration.Attributes, data);
outputFormatter.Indent();
OutputModifier(delegateDeclaration.Modifier, true);
outputFormatter.PrintToken(Tokens.Delegate);
outputFormatter.Space();

30
src/Libraries/NRefactory/Project/Src/Visitors/ToVBNetConvertVisitor.cs

@ -56,6 +56,10 @@ namespace ICSharpCode.NRefactory.Visitors @@ -56,6 +56,10 @@ namespace ICSharpCode.NRefactory.Visitors
public override object VisitTypeDeclaration(TypeDeclaration typeDeclaration, object data)
{
// fix default inner type visibility
if (currentType != null && (typeDeclaration.Modifier & Modifiers.Visibility) == 0)
typeDeclaration.Modifier |= Modifiers.Private;
TypeDeclaration outerType = currentType;
currentType = typeDeclaration;
@ -88,6 +92,15 @@ namespace ICSharpCode.NRefactory.Visitors @@ -88,6 +92,15 @@ namespace ICSharpCode.NRefactory.Visitors
return null;
}
public override object VisitDelegateDeclaration(DelegateDeclaration delegateDeclaration, object data)
{
// fix default inner type visibility
if (currentType != null && (delegateDeclaration.Modifier & Modifiers.Visibility) == 0)
delegateDeclaration.Modifier |= Modifiers.Private;
return base.VisitDelegateDeclaration(delegateDeclaration, data);
}
string GetAnonymousMethodName()
{
for (int i = 1;; i++) {
@ -171,9 +184,15 @@ namespace ICSharpCode.NRefactory.Visitors @@ -171,9 +184,15 @@ namespace ICSharpCode.NRefactory.Visitors
return base.VisitAssignmentExpression(assignmentExpression, data);
}
bool IsClassType(ClassType c)
{
if (currentType == null) return false;
return currentType.Type == c;
}
public override object VisitMethodDeclaration(MethodDeclaration methodDeclaration, object data)
{
if ((methodDeclaration.Modifier & Modifiers.Visibility) == 0)
if (!IsClassType(ClassType.Interface) && (methodDeclaration.Modifier & Modifiers.Visibility) == 0)
methodDeclaration.Modifier |= Modifiers.Private;
base.VisitMethodDeclaration(methodDeclaration, data);
@ -277,11 +296,18 @@ namespace ICSharpCode.NRefactory.Visitors @@ -277,11 +296,18 @@ namespace ICSharpCode.NRefactory.Visitors
public override object VisitPropertyDeclaration(PropertyDeclaration propertyDeclaration, object data)
{
if ((propertyDeclaration.Modifier & Modifiers.Visibility) == 0)
if (!IsClassType(ClassType.Interface) && (propertyDeclaration.Modifier & Modifiers.Visibility) == 0)
propertyDeclaration.Modifier |= Modifiers.Private;
return base.VisitPropertyDeclaration(propertyDeclaration, data);
}
public override object VisitEventDeclaration(EventDeclaration eventDeclaration, object data)
{
if (!IsClassType(ClassType.Interface) && (eventDeclaration.Modifier & Modifiers.Visibility) == 0)
eventDeclaration.Modifier |= Modifiers.Private;
return base.VisitEventDeclaration(eventDeclaration, data);
}
public override object VisitConstructorDeclaration(ConstructorDeclaration constructorDeclaration, object data)
{
// make constructor private if visiblity is not set (unless constructor is static)

45
src/Libraries/NRefactory/Project/Src/Visitors/VBNetConstructsConvertVisitor.cs

@ -26,7 +26,7 @@ namespace ICSharpCode.NRefactory.Visitors @@ -26,7 +26,7 @@ namespace ICSharpCode.NRefactory.Visitors
{
// The following conversions are implemented:
// MyBase.New() and MyClass.New() calls inside the constructor are converted to :base() and :this()
// Add Public Modifier to methods and properties
// Add Public Modifier to inner types, methods, properties and fields in structures
// Override Finalize => Destructor
// IIF(cond, true, false) => ConditionalExpression
// Built-in methods => Prefix with class name
@ -34,7 +34,7 @@ namespace ICSharpCode.NRefactory.Visitors @@ -34,7 +34,7 @@ namespace ICSharpCode.NRefactory.Visitors
Dictionary<string, string> usings;
List<UsingDeclaration> addedUsings;
bool isInStructure;
TypeDeclaration currentTypeDeclaration;
public override object VisitCompilationUnit(CompilationUnit compilationUnit, object data)
{
@ -65,13 +65,32 @@ namespace ICSharpCode.NRefactory.Visitors @@ -65,13 +65,32 @@ namespace ICSharpCode.NRefactory.Visitors
public override object VisitTypeDeclaration(TypeDeclaration typeDeclaration, object data)
{
bool oldIsInStructure = isInStructure;
isInStructure = typeDeclaration.Type == ClassType.Struct;
// fix default visibility of inner classes
if (currentTypeDeclaration != null && (typeDeclaration.Modifier & Modifiers.Visibility) == 0)
typeDeclaration.Modifier |= Modifiers.Public;
TypeDeclaration oldTypeDeclaration = currentTypeDeclaration;
currentTypeDeclaration = typeDeclaration;
base.VisitTypeDeclaration(typeDeclaration, data);
isInStructure = oldIsInStructure;
currentTypeDeclaration = oldTypeDeclaration;
return null;
}
public override object VisitDelegateDeclaration(DelegateDeclaration delegateDeclaration, object data)
{
// fix default visibility of inner classes
if (currentTypeDeclaration != null && (delegateDeclaration.Modifier & Modifiers.Visibility) == 0)
delegateDeclaration.Modifier |= Modifiers.Public;
return base.VisitDelegateDeclaration(delegateDeclaration, data);
}
bool IsClassType(ClassType c)
{
if (currentTypeDeclaration == null) return false;
return currentTypeDeclaration.Type == c;
}
public override object VisitConstructorDeclaration(ConstructorDeclaration constructorDeclaration, object data)
{
// make constructor public if visiblity is not set (unless constructor is static)
@ -115,6 +134,8 @@ namespace ICSharpCode.NRefactory.Visitors @@ -115,6 +134,8 @@ namespace ICSharpCode.NRefactory.Visitors
MethodDeclaration method = new MethodDeclaration(declareDeclaration.Name, declareDeclaration.Modifier,
declareDeclaration.TypeReference, declareDeclaration.Parameters,
declareDeclaration.Attributes);
if ((method.Modifier & Modifiers.Visibility) == 0)
method.Modifier |= Modifiers.Public;
method.Modifier |= Modifiers.Extern | Modifiers.Static;
Attribute att = new Attribute("DllImport", null, null);
att.PositionalArguments.Add(CreateStringLiteral(declareDeclaration.Library));
@ -154,7 +175,7 @@ namespace ICSharpCode.NRefactory.Visitors @@ -154,7 +175,7 @@ namespace ICSharpCode.NRefactory.Visitors
public override object VisitMethodDeclaration(MethodDeclaration methodDeclaration, object data)
{
if ((methodDeclaration.Modifier & Modifiers.Visibility) == 0)
if (!IsClassType(ClassType.Interface) && (methodDeclaration.Modifier & Modifiers.Visibility) == 0)
methodDeclaration.Modifier |= Modifiers.Public;
if ("Finalize".Equals(methodDeclaration.Name, StringComparison.InvariantCultureIgnoreCase)
@ -279,16 +300,24 @@ namespace ICSharpCode.NRefactory.Visitors @@ -279,16 +300,24 @@ namespace ICSharpCode.NRefactory.Visitors
public override object VisitFieldDeclaration(FieldDeclaration fieldDeclaration, object data)
{
fieldDeclaration.Modifier &= ~Modifiers.Dim; // remove "Dim" flag
if (isInStructure) {
if (IsClassType(ClassType.Struct)) {
if ((fieldDeclaration.Modifier & Modifiers.Visibility) == 0)
fieldDeclaration.Modifier |= Modifiers.Public;
}
return base.VisitFieldDeclaration(fieldDeclaration, data);
}
public override object VisitEventDeclaration(EventDeclaration eventDeclaration, object data)
{
if (!IsClassType(ClassType.Interface) && (eventDeclaration.Modifier & Modifiers.Visibility) == 0)
eventDeclaration.Modifier |= Modifiers.Public;
return base.VisitEventDeclaration(eventDeclaration, data);
}
public override object VisitPropertyDeclaration(PropertyDeclaration propertyDeclaration, object data)
{
if ((propertyDeclaration.Modifier & Modifiers.Visibility) == 0)
if (!IsClassType(ClassType.Interface) && (propertyDeclaration.Modifier & Modifiers.Visibility) == 0)
propertyDeclaration.Modifier |= Modifiers.Public;
if (propertyDeclaration.HasSetRegion) {

37
src/Libraries/NRefactory/Test/Output/CSharp/VBToCSharpConverterTest.cs

@ -210,17 +210,17 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter @@ -210,17 +210,17 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter
{
TestMember("Declare Function SendMessage Lib \"user32.dll\" (ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As UIntPtr, ByVal lParam As IntPtr) As IntPtr",
"[DllImport(\"user32.dll\", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]\n" +
"static extern IntPtr SendMessage(IntPtr hWnd, int Msg, UIntPtr wParam, IntPtr lParam);",
"public static extern IntPtr SendMessage(IntPtr hWnd, int Msg, UIntPtr wParam, IntPtr lParam);",
"System.Runtime.InteropServices");
TestMember("Declare Unicode Function SendMessage Lib \"user32.dll\" Alias \"SendMessageW\" (ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As UIntPtr, ByVal lParam As IntPtr) As IntPtr",
"[DllImport(\"user32.dll\", EntryPoint = \"SendMessageW\", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]\n" +
"static extern IntPtr SendMessage(IntPtr hWnd, int Msg, UIntPtr wParam, IntPtr lParam);",
"public static extern IntPtr SendMessage(IntPtr hWnd, int Msg, UIntPtr wParam, IntPtr lParam);",
"System.Runtime.InteropServices");
TestMember("Declare Auto Function SendMessage Lib \"user32.dll\" (ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As UIntPtr, ByVal lParam As IntPtr) As IntPtr",
"[DllImport(\"user32.dll\", CharSet = CharSet.Auto, SetLastError = true, ExactSpelling = true)]\n" +
"static extern IntPtr SendMessage(IntPtr hWnd, int Msg, UIntPtr wParam, IntPtr lParam);",
"public static extern IntPtr SendMessage(IntPtr hWnd, int Msg, UIntPtr wParam, IntPtr lParam);",
"System.Runtime.InteropServices");
TestMember("<DllImport(\"user32.dll\", CharSet:=CharSet.Auto)> _\n" +
@ -518,5 +518,36 @@ static int static_Test2_j = 0;"); @@ -518,5 +518,36 @@ static int static_Test2_j = 0;");
TestMember("Public Structure Example \n Dim x As Object \n End Structure",
"public struct Example\n{\n\tpublic object x;\n}");
}
[Test]
public void InnerClassVisibility()
{
TestMember("Class Inner \n End Class",
"public class Inner\n{\n}");
}
[Test]
public void InnerDelegateVisibility()
{
TestMember("Delegate Sub Test()",
"public delegate void Test();");
}
[Test]
public void InterfaceVisibility()
{
TestMember("Public Interface ITest\n" +
"\tSub Test()\n" +
"\tProperty Name As String\n" +
"End Interface",
"public interface ITest\n" +
"{\n" +
"\tvoid Test();\n" +
"\tstring Name {\n" +
"\t\tget;\n" +
"\t\tset;\n" +
"\t}\n" +
"}");
}
}
}

37
src/Libraries/NRefactory/Test/Output/VBNet/CSharpToVBConverterTest.cs

@ -370,5 +370,42 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter @@ -370,5 +370,42 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter
"\tExit Do\n" +
"Loop While test IsNot Nothing");
}
[Test]
public void StructFieldVisibility()
{
TestMember("public struct A { int field; }",
"Public Structure A\n" +
"\tPrivate field As Integer\n" +
"End Structure");
}
[Test]
public void InnerClassVisibility()
{
TestMember("class Inner\n{\n}",
"Private Class Inner\n" +
"End Class");
}
[Test]
public void InnerDelegateVisibility()
{
TestMember("delegate void Test();",
"Private Delegate Sub Test()");
}
[Test]
public void InterfaceVisibility()
{
TestMember("public interface ITest {\n" +
" void Test();\n" +
" string Name { get; set; }\n" +
"}",
"Public Interface ITest\n" +
"\tSub Test()\n" +
"\tProperty Name() As String\n" +
"End Interface");
}
}
}

4
src/Main/Base/Project/Src/TextEditor/Gui/Editor/CompletionWindow/AbstractCompletionDataProvider.cs

@ -69,13 +69,15 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor @@ -69,13 +69,15 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor
{
CompletionDataProviderKeyResult res;
if (key == ' ' && insertSpace) {
insertSpace = false; // insert space only once
res = CompletionDataProviderKeyResult.BeforeStartKey;
} else if (char.IsLetterOrDigit(key) || key == '_') {
insertSpace = false; // don't insert space if user types normally
res = CompletionDataProviderKeyResult.NormalKey;
} else {
// do not reset insertSpace when doing an insertion!
res = CompletionDataProviderKeyResult.InsertionKey;
}
insertSpace = false;
return res;
}

14
src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/NRefactoryResolver/NRefactoryASTConvertVisitor.cs

@ -51,6 +51,16 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver @@ -51,6 +51,16 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
return ConvertModifier(m, ModifierEnum.Private);
}
ModifierEnum ConvertTypeModifier(AST.Modifiers m)
{
if (this.IsVisualBasic)
return ConvertModifier(m, ModifierEnum.Public);
if (currentClass.Count > 0)
return ConvertModifier(m, ModifierEnum.Private);
else
return ConvertModifier(m, ModifierEnum.Internal);
}
ModifierEnum ConvertModifier(AST.Modifiers m, ModifierEnum defaultVisibility)
{
ModifierEnum r = (ModifierEnum)m;
@ -282,7 +292,7 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver @@ -282,7 +292,7 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
DomRegion region = GetRegion(typeDeclaration.StartLocation, typeDeclaration.EndLocation);
DomRegion bodyRegion = GetRegion(typeDeclaration.BodyStartLocation, typeDeclaration.EndLocation);
DefaultClass c = new DefaultClass(cu, TranslateClassType(typeDeclaration.Type), ConvertModifier(typeDeclaration.Modifier, ModifierEnum.Internal), region, GetCurrentClass());
DefaultClass c = new DefaultClass(cu, TranslateClassType(typeDeclaration.Type), ConvertTypeModifier(typeDeclaration.Modifier), region, GetCurrentClass());
c.BodyRegion = bodyRegion;
ConvertAttributes(typeDeclaration, c);
c.Documentation = GetDocumentation(region.BeginLine, typeDeclaration.Attributes);
@ -371,7 +381,7 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver @@ -371,7 +381,7 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
public override object VisitDelegateDeclaration(AST.DelegateDeclaration delegateDeclaration, object data)
{
DomRegion region = GetRegion(delegateDeclaration.StartLocation, delegateDeclaration.EndLocation);
DefaultClass c = new DefaultClass(cu, ClassType.Delegate, ConvertModifier(delegateDeclaration.Modifier, ModifierEnum.Internal), region, GetCurrentClass());
DefaultClass c = new DefaultClass(cu, ClassType.Delegate, ConvertTypeModifier(delegateDeclaration.Modifier), region, GetCurrentClass());
c.Documentation = GetDocumentation(region.BeginLine, delegateDeclaration.Attributes);
ConvertAttributes(delegateDeclaration, c);
CreateDelegate(c, delegateDeclaration.Name, delegateDeclaration.ReturnType,

Loading…
Cancel
Save