Browse Source

Fixed SD2-1021: Alias for namespaces not converted correctly between C#<-->VB.NET for base types.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@1725 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 20 years ago
parent
commit
ddf419442b
  1. 10
      src/Libraries/NRefactory/Project/Src/PrettyPrinter/CSharp/CSharpOutputVisitor.cs
  2. 5
      src/Libraries/NRefactory/Project/Src/PrettyPrinter/VBNet/VBNetOutputVisitor.cs
  3. 6
      src/Libraries/NRefactory/Test/Output/CSharp/VBToCSharpConverterTest.cs
  4. 6
      src/Libraries/NRefactory/Test/Output/VBNet/CSharpToVBConverterTest.cs
  5. 65
      src/Main/Base/Project/Src/Gui/WorkbenchSingleton.cs

10
src/Libraries/NRefactory/Project/Src/PrettyPrinter/CSharp/CSharpOutputVisitor.cs

@ -24,8 +24,8 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
CSharpOutputFormatter outputFormatter; CSharpOutputFormatter outputFormatter;
PrettyPrintOptions prettyPrintOptions = new PrettyPrintOptions(); PrettyPrintOptions prettyPrintOptions = new PrettyPrintOptions();
NodeTracker nodeTracker; NodeTracker nodeTracker;
// Stack<WithStatement> withExpressionStack = new Stack<WithStatement>(); Stack<WithStatement> withExpressionStack = new Stack<WithStatement>();
Stack withExpressionStack = new Stack(); bool printFullSystemType;
public string Text { public string Text {
get { get {
@ -176,7 +176,11 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
outputFormatter.PrintText("?"); outputFormatter.PrintText("?");
} else { } else {
if (typeReference.SystemType.Length > 0) { if (typeReference.SystemType.Length > 0) {
if (printFullSystemType) {
outputFormatter.PrintIdentifier(typeReference.SystemType);
} else {
outputFormatter.PrintText(ConvertTypeString(typeReference.SystemType)); outputFormatter.PrintText(ConvertTypeString(typeReference.SystemType));
}
} else { } else {
outputFormatter.PrintText(typeReference.Type); outputFormatter.PrintText(typeReference.Type);
} }
@ -289,7 +293,9 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
outputFormatter.Space(); outputFormatter.Space();
outputFormatter.PrintToken(Tokens.Assign); outputFormatter.PrintToken(Tokens.Assign);
outputFormatter.Space(); outputFormatter.Space();
printFullSystemType = true;
nodeTracker.TrackedVisit(@using.Alias, data); nodeTracker.TrackedVisit(@using.Alias, data);
printFullSystemType = false;
} }
outputFormatter.PrintToken(Tokens.Semicolon); outputFormatter.PrintToken(Tokens.Semicolon);

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

@ -25,6 +25,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
VBNetPrettyPrintOptions prettyPrintOptions = new VBNetPrettyPrintOptions(); VBNetPrettyPrintOptions prettyPrintOptions = new VBNetPrettyPrintOptions();
NodeTracker nodeTracker; NodeTracker nodeTracker;
TypeDeclaration currentType; TypeDeclaration currentType;
bool printFullSystemType;
Stack<int> exitTokenStack = new Stack<int>(); Stack<int> exitTokenStack = new Stack<int>();
@ -152,6 +153,8 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
} }
if (typeReference.Type == null || typeReference.Type.Length ==0) { if (typeReference.Type == null || typeReference.Type.Length ==0) {
outputFormatter.PrintText("Void"); outputFormatter.PrintText("Void");
} else if (printFullSystemType) {
outputFormatter.PrintIdentifier(typeReference.SystemType);
} else { } else {
string shortTypeName = ConvertTypeString(typeReference.SystemType); string shortTypeName = ConvertTypeString(typeReference.SystemType);
if (shortTypeName != null) { if (shortTypeName != null) {
@ -258,7 +261,9 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
outputFormatter.Space(); outputFormatter.Space();
outputFormatter.PrintToken(Tokens.Assign); outputFormatter.PrintToken(Tokens.Assign);
outputFormatter.Space(); outputFormatter.Space();
printFullSystemType = true;
nodeTracker.TrackedVisit(((Using)usingDeclaration.Usings[i]).Alias, data); nodeTracker.TrackedVisit(((Using)usingDeclaration.Usings[i]).Alias, data);
printFullSystemType = false;
} }
if (i + 1 < usingDeclaration.Usings.Count) { if (i + 1 < usingDeclaration.Usings.Count) {
outputFormatter.PrintToken(Tokens.Comma); outputFormatter.PrintToken(Tokens.Comma);

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

@ -549,5 +549,11 @@ static int static_Test2_j = 0;");
"\t}\n" + "\t}\n" +
"}"); "}");
} }
[Test]
public void ImportAliasPrimitiveType()
{
TestProgram("Imports T = System.Boolean", "using T = System.Boolean;\r\n");
}
} }
} }

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

@ -407,5 +407,11 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter
"\tProperty Name() As String\n" + "\tProperty Name() As String\n" +
"End Interface"); "End Interface");
} }
[Test]
public void ImportAliasPrimitiveType()
{
TestProgram("using T = System.Boolean;", "Imports T = System.Boolean\r\n");
}
} }
} }

65
src/Main/Base/Project/Src/Gui/WorkbenchSingleton.cs

@ -100,19 +100,11 @@ namespace ICSharpCode.SharpDevelop.Gui
/// </summary> /// </summary>
private class STAThreadCaller private class STAThreadCaller
{ {
delegate object PerformCallDelegate(object target, string methodName, object[] arguments);
Control ctl; Control ctl;
PerformCallDelegate performCallDelegate;
#if DEBUG
string callerStack;
#endif
public STAThreadCaller(Control ctl) public STAThreadCaller(Control ctl)
{ {
this.ctl = ctl; this.ctl = ctl;
performCallDelegate = new PerformCallDelegate(DoPerformCall);
} }
public object Call(Delegate method, object[] arguments) public object Call(Delegate method, object[] arguments)
@ -123,19 +115,6 @@ namespace ICSharpCode.SharpDevelop.Gui
return ctl.Invoke(method, arguments); return ctl.Invoke(method, arguments);
} }
public object Call(object target, string methodName, object[] arguments)
{
if (target == null) {
throw new ArgumentNullException("target");
}
#if DEBUG
callerStack = Environment.StackTrace;
#endif
return ctl.Invoke(performCallDelegate, new object[] {target, methodName, arguments});
}
public void BeginCall(Delegate method, object[] arguments) public void BeginCall(Delegate method, object[] arguments)
{ {
if (method == null) { if (method == null) {
@ -143,50 +122,6 @@ namespace ICSharpCode.SharpDevelop.Gui
} }
ctl.BeginInvoke(method, arguments); ctl.BeginInvoke(method, arguments);
} }
public void BeginCall(object target, string methodName, object[] arguments)
{
if (target == null) {
throw new ArgumentNullException("target");
}
#if DEBUG
callerStack = Environment.StackTrace;
#endif
ctl.BeginInvoke(performCallDelegate, new object[] {target, methodName, arguments});
}
object DoPerformCall(object target, string methodName, object[] arguments)
{
MethodInfo methodInfo = null;
if (target is Type) {
methodInfo = ((Type)target).GetMethod(methodName, BindingFlags.Public | BindingFlags.Static | BindingFlags.NonPublic);
} else {
methodInfo = target.GetType().GetMethod(methodName, BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic);
}
if (methodInfo == null) {
throw new System.ArgumentException("method not found : " + methodName);
} else {
try {
if (target is Type) {
return methodInfo.Invoke(null, arguments);
} else {
return methodInfo.Invoke(target, arguments);
}
} catch (Exception ex) {
if (ex is TargetInvocationException && ex.InnerException != null) {
ex = ex.InnerException;
}
MessageService.ShowError(ex, "Exception got.");
#if DEBUG
LoggingService.Info("Stacktrace of source thread:\n" + callerStack);
#endif
}
}
return null;
}
} }
public static bool InvokeRequired { public static bool InvokeRequired {

Loading…
Cancel
Save