Browse Source

Fixed some bugs reported in the forum.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/2.0@1488 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 19 years ago
parent
commit
2ed82fd4cb
  1. 34
      src/Libraries/NRefactory/Project/Src/Output/CSharp/CSharpOutputVisitor.cs
  2. 4
      src/Libraries/NRefactory/Project/Src/Output/VBNet/VBNetOutputVisitor.cs
  3. 91
      src/Libraries/NRefactory/Project/Src/Parser/Visitors/VBNetConstructsConvertVisitor.cs
  4. 104
      src/Libraries/NRefactory/Test/Output/CSharp/VBToCSharpConverterTest.cs
  5. 46
      src/Libraries/NRefactory/Test/Output/SpecialOutputVisitor.cs
  6. 6
      src/Main/Base/Project/Src/Commands/CustomStringTagProvider.cs
  7. 3
      src/Main/Base/Project/Src/Commands/ProjectMenuCommands.cs
  8. 6
      src/Main/Base/Project/Src/Gui/Components/SideBar/AxSideBar.cs
  9. 5
      src/Main/Base/Project/Src/Gui/Dialogs/ProjectOptionsView.cs
  10. 3
      src/Main/Base/Project/Src/Project/ConfigurationGuiHelper.cs

34
src/Libraries/NRefactory/Project/Src/Output/CSharp/CSharpOutputVisitor.cs

@ -468,7 +468,6 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -468,7 +468,6 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
#region Type level
public object Visit(FieldDeclaration fieldDeclaration, object data)
{
// TODO: use FieldDeclaration.GetTypeForField and VB.NET fields aren't that easy....
if (!fieldDeclaration.TypeReference.IsNull) {
VisitAttributes(fieldDeclaration.Attributes, data);
outputFormatter.Indent();
@ -479,13 +478,13 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -479,13 +478,13 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
outputFormatter.PrintToken(Tokens.Semicolon);
outputFormatter.NewLine();
} else {
foreach (VariableDeclaration varDecl in fieldDeclaration.Fields) {
for (int i = 0; i < fieldDeclaration.Fields.Count; i++) {
VisitAttributes(fieldDeclaration.Attributes, data);
outputFormatter.Indent();
OutputModifier(fieldDeclaration.Modifier);
nodeTracker.TrackedVisit(varDecl.TypeReference, data);
nodeTracker.TrackedVisit(fieldDeclaration.GetTypeForField(i), data);
outputFormatter.Space();
nodeTracker.TrackedVisit(varDecl, data);
nodeTracker.TrackedVisit(fieldDeclaration.Fields[i], data);
outputFormatter.PrintToken(Tokens.Semicolon);
outputFormatter.NewLine();
}
@ -868,7 +867,6 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -868,7 +867,6 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
if (blockStatement.IsNull) {
outputFormatter.PrintToken(Tokens.Semicolon);
outputFormatter.NewLine();
nodeTracker.EndNode(blockStatement);
} else {
outputFormatter.BeginBrace(braceStyle);
foreach (Statement stmt in blockStatement.Children) {
@ -877,9 +875,9 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -877,9 +875,9 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
if (!outputFormatter.LastCharacterIsNewLine)
outputFormatter.NewLine();
}
nodeTracker.EndNode(blockStatement);
outputFormatter.EndBrace();
}
nodeTracker.EndNode(blockStatement);
}
public object Visit(BlockStatement blockStatement, object data)
@ -1240,6 +1238,30 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -1240,6 +1238,30 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
nodeTracker.TrackedVisit(caseLabel.Label, data);
}
outputFormatter.PrintToken(Tokens.Colon);
if (!caseLabel.ToExpression.IsNull) {
PrimitiveExpression pl = caseLabel.Label as PrimitiveExpression;
PrimitiveExpression pt = caseLabel.ToExpression as PrimitiveExpression;
if (pl != null && pt != null && pl.Value is int && pt.Value is int) {
int plv = (int)pl.Value;
int prv = (int)pt.Value;
if (plv < prv && plv + 12 > prv) {
for (int i = plv + 1; i <= prv; i++) {
outputFormatter.NewLine();
outputFormatter.Indent();
outputFormatter.PrintToken(Tokens.Case);
outputFormatter.Space();
outputFormatter.PrintText(i.ToString(NumberFormatInfo.InvariantInfo));
outputFormatter.PrintToken(Tokens.Colon);
}
} else {
outputFormatter.PrintText(" // TODO: to ");
nodeTracker.TrackedVisit(caseLabel.ToExpression, data);
}
} else {
outputFormatter.PrintText(" // TODO: to ");
nodeTracker.TrackedVisit(caseLabel.ToExpression, data);
}
}
outputFormatter.NewLine();
return null;
}

4
src/Libraries/NRefactory/Project/Src/Output/VBNet/VBNetOutputVisitor.cs

@ -827,9 +827,10 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -827,9 +827,10 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
outputFormatter.NewLine();
if (!IsAbstract(methodDeclaration)) {
nodeTracker.BeginNode(methodDeclaration.Body);
++outputFormatter.IndentationLevel;
exitTokenStack.Push(isSub ? Tokens.Sub : Tokens.Function);
nodeTracker.TrackedVisit(methodDeclaration.Body, data);
methodDeclaration.Body.AcceptVisitor(this, data);
exitTokenStack.Pop();
--outputFormatter.IndentationLevel;
@ -842,6 +843,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -842,6 +843,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
outputFormatter.PrintToken(Tokens.Function);
}
outputFormatter.NewLine();
nodeTracker.EndNode(methodDeclaration.Body);
}
return null;
}

91
src/Libraries/NRefactory/Project/Src/Parser/Visitors/VBNetConstructsConvertVisitor.cs

@ -30,8 +30,6 @@ namespace ICSharpCode.NRefactory.Parser @@ -30,8 +30,6 @@ namespace ICSharpCode.NRefactory.Parser
// Override Finalize => Destructor
// IIF(cond, true, false) => ConditionalExpression
// Built-in methods => Prefix with class name
// The following conversions should be implemented in the future:
// Function A() \n A = SomeValue \n End Function -> convert to return statement
Dictionary<string, string> usings;
@ -192,9 +190,82 @@ namespace ICSharpCode.NRefactory.Parser @@ -192,9 +190,82 @@ namespace ICSharpCode.NRefactory.Parser
}
}
if (methodDeclaration.TypeReference.SystemType != "System.Void" && methodDeclaration.Body.Children.Count > 0) {
if (IsAssignmentTo(methodDeclaration.Body.Children[methodDeclaration.Body.Children.Count - 1], methodDeclaration.Name))
{
ReturnStatement rs = new ReturnStatement(GetAssignmentFromStatement(methodDeclaration.Body.Children[methodDeclaration.Body.Children.Count - 1]).Right);
methodDeclaration.Body.Children.RemoveAt(methodDeclaration.Body.Children.Count - 1);
methodDeclaration.Body.AddChild(rs);
} else {
methodDeclaration.Body.AcceptVisitor(new ReturnStatementForFunctionAssignment(methodDeclaration.Name), null);
Expression init;
switch (methodDeclaration.TypeReference.SystemType) {
case "System.Int16":
case "System.Int32":
case "System.Int64":
case "System.Byte":
case "System.UInt16":
case "System.UInt32":
case "System.UInt64":
init = new PrimitiveExpression(0, "0");
break;
case "System.Boolean":
init = new PrimitiveExpression(false, "false");
break;
default:
init = new PrimitiveExpression(null, "null");
break;
}
methodDeclaration.Body.Children.Insert(0, new LocalVariableDeclaration(new VariableDeclaration(FunctionReturnValueName, init, methodDeclaration.TypeReference)));
methodDeclaration.Body.Children[0].Parent = methodDeclaration.Body;
methodDeclaration.Body.AddChild(new ReturnStatement(new IdentifierExpression(FunctionReturnValueName)));
}
}
return base.Visit(methodDeclaration, data);
}
public const string FunctionReturnValueName = "functionReturnValue";
static AssignmentExpression GetAssignmentFromStatement(INode statement)
{
StatementExpression se = statement as StatementExpression;
if (se == null) return null;
return se.Expression as AssignmentExpression;
}
static bool IsAssignmentTo(INode statement, string varName)
{
AssignmentExpression ass = GetAssignmentFromStatement(statement);
if (ass == null) return false;
IdentifierExpression ident = ass.Left as IdentifierExpression;
if (ident == null) return false;
return ident.Identifier.Equals(varName, StringComparison.InvariantCultureIgnoreCase);
}
#region Create return statement for assignment to function name
class ReturnStatementForFunctionAssignment : AbstractAstTransformer
{
string functionName;
public ReturnStatementForFunctionAssignment(string functionName)
{
this.functionName = functionName;
}
public override object Visit(AssignmentExpression assignmentExpression, object data)
{
IdentifierExpression ident = assignmentExpression.Left as IdentifierExpression;
if (ident != null) {
if (ident.Identifier.Equals(functionName, StringComparison.InvariantCultureIgnoreCase)) {
ident.Identifier = FunctionReturnValueName;
}
}
return base.Visit(assignmentExpression, data);
}
}
#endregion
public override object Visit(FieldDeclaration fieldDeclaration, object data)
{
fieldDeclaration.Modifier &= ~Modifier.Dim; // remove "Dim" flag
@ -323,5 +394,21 @@ namespace ICSharpCode.NRefactory.Parser @@ -323,5 +394,21 @@ namespace ICSharpCode.NRefactory.Parser
}
return null;
}
public override object Visit(UsingStatement usingStatement, object data)
{
LocalVariableDeclaration lvd = usingStatement.ResourceAcquisition as LocalVariableDeclaration;
if (lvd != null && lvd.Variables.Count > 1) {
usingStatement.ResourceAcquisition = new LocalVariableDeclaration(lvd.Variables[0]);
for (int i = 1; i < lvd.Variables.Count; i++) {
UsingStatement n = new UsingStatement(new LocalVariableDeclaration(lvd.Variables[i]),
usingStatement.EmbeddedStatement);
usingStatement.EmbeddedStatement = new BlockStatement();
usingStatement.EmbeddedStatement.AddChild(n);
usingStatement = n;
}
}
return base.Visit(usingStatement, data);
}
}
}

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

@ -167,6 +167,22 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter @@ -167,6 +167,22 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter
"string f;");
}
[Test]
public void MultipleFields()
{
TestMember("Private example, test As Single",
"private float example;\n" +
"private float test;");
}
[Test]
public void MultipleVariables()
{
TestStatement("Dim example, test As Single",
"float example;\n" +
"float test;");
}
[Test]
public void PInvoke()
{
@ -312,5 +328,93 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter @@ -312,5 +328,93 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter
"}\n" +
"while (!(i == 10000));");
}
[Test]
public void UsingStatement()
{
TestStatement("Using r1 As New StreamReader(file1), r2 As New StreamReader(file2)\n" +
"End Using",
"using (StreamReader r1 = new StreamReader(file1)) {\n" +
"\tusing (StreamReader r2 = new StreamReader(file2)) {\n" +
"\t}\n" +
"}");
}
[Test]
public void SwitchStatement()
{
TestStatement(@"Select Case i
Case 0 To 5
i = 10
Case 11
i = 0
Case Else
i = 9
End Select",
"switch (i) {\n" +
"\tcase 0:\n" +
"\tcase 1:\n" +
"\tcase 2:\n" +
"\tcase 3:\n" +
"\tcase 4:\n" +
"\tcase 5:\n" +
"\t\ti = 10;\n" +
"\t\tbreak;\n" +
"\tcase 11:\n" +
"\t\ti = 0;\n" +
"\t\tbreak;\n" +
"\tdefault:\n" +
"\t\ti = 9;\n" +
"\t\tbreak;\n" +
"}");
}
[Test]
public void FunctionWithImplicitReturn()
{
TestMember("Public Function run(i As Integer) As Integer\n" +
" run = 0\n" +
"End Function",
"public int run(int i)\n" +
"{\n" +
"\treturn 0;\n" +
"}");
}
[Test]
public void FunctionWithImplicitReturn2()
{
TestMember("Public Function run(i As Integer) As Integer\n" +
" While something\n" +
" run += i\n" +
" End While\n" +
"End Function",
"public int run(int i)\n" +
"{\n" +
"\tint " + VBNetConstructsConvertVisitor.FunctionReturnValueName + " = 0;\n" +
"\twhile (something) {\n" +
"\t\t" + VBNetConstructsConvertVisitor.FunctionReturnValueName + " += i;\n" +
"\t}\n" +
"\treturn " + VBNetConstructsConvertVisitor.FunctionReturnValueName + ";\n" +
"}");
}
[Test]
public void FunctionWithImplicitReturn3()
{
TestMember("Public Function run(i As Integer) As CustomType\n" +
" While something\n" +
" run = New CustomType()\n" +
" End While\n" +
"End Function",
"public CustomType run(int i)\n" +
"{\n" +
"\tCustomType " + VBNetConstructsConvertVisitor.FunctionReturnValueName + " = null;\n" +
"\twhile (something) {\n" +
"\t\t" + VBNetConstructsConvertVisitor.FunctionReturnValueName + " = new CustomType();\n" +
"\t}\n" +
"\treturn " + VBNetConstructsConvertVisitor.FunctionReturnValueName + ";\n" +
"}");
}
}
}

46
src/Libraries/NRefactory/Test/Output/SpecialOutputVisitor.cs

@ -28,7 +28,7 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter @@ -28,7 +28,7 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter
outputVisitor.Visit(parser.CompilationUnit, null);
}
Assert.AreEqual("", outputVisitor.Errors.ErrorOutput);
Assert.AreEqual(program, outputVisitor.Text.TrimEnd().Replace("\r", ""));
Assert.AreEqual(program.Replace("\r", ""), outputVisitor.Text.TrimEnd().Replace("\r", ""));
parser.Dispose();
}
@ -43,7 +43,7 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter @@ -43,7 +43,7 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter
outputVisitor.Visit(parser.CompilationUnit, null);
}
Assert.AreEqual("", outputVisitor.Errors.ErrorOutput);
Assert.AreEqual(program, outputVisitor.Text.TrimEnd().Replace("\r", ""));
Assert.AreEqual(program.Replace("\r", ""), outputVisitor.Text.TrimEnd().Replace("\r", ""));
parser.Dispose();
}
@ -97,13 +97,41 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter @@ -97,13 +97,41 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter
public void EnumVB()
{
TestProgramVB("Enum Test\n" +
"\t' a\n" +
"\tm1\n" +
"\t' b\n" +
"\tm2\n" +
"\t' c\n" +
"End Enum\n" +
"' d");
"\t' a\n" +
"\tm1\n" +
"\t' b\n" +
"\tm2\n" +
"\t' c\n" +
"End Enum\n" +
"' d");
}
[Test]
public void RegionInsideMethod()
{
TestProgram(@"public class Class1
{
private bool test(int l, int lvw)
{
#region Metodos Auxiliares
int i = 1;
return false;
#endregion
}
}");
}
[Test]
public void RegionInsideMethodVB()
{
TestProgramVB(@"Public Class Class1
Private Function test(ByVal l As Integer, ByVal lvw As Integer) As Boolean
' Begin
Dim i As Integer = 1
Return False
' End of method
End Function
End Class");
}
}
}

6
src/Main/Base/Project/Src/Commands/CustomStringTagProvider.cs

@ -71,8 +71,10 @@ namespace ICSharpCode.SharpDevelop.Commands @@ -71,8 +71,10 @@ namespace ICSharpCode.SharpDevelop.Commands
case "TaskService.Messages":
return TaskService.GetCount(TaskType.Message).ToString();
case "CurrentProjectName":
// TODO: Translate "<empty>"!!!!
return ProjectService.CurrentProject == null ? "<empty>" : ProjectService.CurrentProject.Name;
if (ProjectService.CurrentProject == null)
return "<no current project>";
else
return ProjectService.CurrentProject.Name;
}
switch (tag.ToUpperInvariant()) {

3
src/Main/Base/Project/Src/Commands/ProjectMenuCommands.cs

@ -42,8 +42,7 @@ namespace ICSharpCode.SharpDevelop.Project.Commands @@ -42,8 +42,7 @@ namespace ICSharpCode.SharpDevelop.Project.Commands
ProjectOptionsView projectOptions = new ProjectOptionsView(projectOptionsNode, project);
WorkbenchSingleton.Workbench.ShowView(projectOptions);
} catch (TreePathNotFoundException) {
// TODO: Translate me!
MessageService.ShowError("No installed project options panels were found.");
MessageService.ShowError("${res:Dialog.ProjectOptions.NoPanelsInstalledForProject}");
}
}
}

6
src/Main/Base/Project/Src/Gui/Components/SideBar/AxSideBar.cs

@ -912,8 +912,10 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -912,8 +912,10 @@ namespace ICSharpCode.SharpDevelop.Gui
protected override void OnMouseDown(MouseEventArgs e)
{
base.OnMouseDown(e);
mouseDownPos = e.Location;
sideBar.activeTab.ChoosedItem = sideBar.activeTab.SelectedItem;
if (e.Button == MouseButtons.Left) {
mouseDownPos = e.Location;
sideBar.activeTab.ChoosedItem = sideBar.activeTab.SelectedItem;
}
Refresh();
}

5
src/Main/Base/Project/Src/Gui/Dialogs/ProjectOptionsView.cs

@ -125,6 +125,11 @@ namespace ICSharpCode.SharpDevelop.Project.Dialogs @@ -125,6 +125,11 @@ namespace ICSharpCode.SharpDevelop.Project.Dialogs
this.IsDirty = dirty;
}
public override void Load(string fileName)
{
// TODO: reload project file
}
public override void Save(string fileName)
{
foreach (IDialogPanelDescriptor pane in descriptors) {

3
src/Main/Base/Project/Src/Project/ConfigurationGuiHelper.cs

@ -346,8 +346,7 @@ namespace ICSharpCode.SharpDevelop.Project @@ -346,8 +346,7 @@ namespace ICSharpCode.SharpDevelop.Project
int val;
if (!int.TryParse(txt, style, NumberFormatInfo.InvariantInfo, out val)) {
textBox.Focus();
// TODO: Translate Please enter a valid number.
MessageService.ShowMessage("Please enter a valid number.");
MessageService.ShowMessage("${res:Dialog.ProjectOptions.PleaseEnterValidNumber}");
return false;
}
Set(val.ToString(NumberFormatInfo.InvariantInfo));

Loading…
Cancel
Save