Browse Source

- replaced file headers with standard header

- fixed http://community.sharpdevelop.net/forums/t/10395.aspx

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@5451 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
pull/1/head
Siegfried Pammer 16 years ago
parent
commit
efeb9277ab
  1. 17
      src/AddIns/Misc/SharpRefactoring/Project/Src/CSharpMethodExtractor.cs
  2. 5
      src/AddIns/Misc/SharpRefactoring/Project/Src/MethodExtractorBase.cs
  3. 108
      src/AddIns/Misc/SharpRefactoring/Project/Src/Visitors/FindJumpInstructionsVisitor.cs
  4. 12
      src/AddIns/Misc/SharpRefactoring/Project/Src/Visitors/FindMemberVisitor.cs
  5. 12
      src/AddIns/Misc/SharpRefactoring/Project/Src/Visitors/FindReferenceVisitor.cs
  6. 12
      src/AddIns/Misc/SharpRefactoring/Project/Src/Visitors/HasAssignmentsVisitor.cs
  7. 12
      src/AddIns/Misc/SharpRefactoring/Project/Src/Visitors/HasReturnStatementVisitor.cs
  8. 4
      src/AddIns/Misc/SharpRefactoring/Test/SharpRefactoring.Tests.csproj

17
src/AddIns/Misc/SharpRefactoring/Project/Src/CSharpMethodExtractor.cs

@ -69,7 +69,7 @@ namespace SharpRefactoring
// Initialise new method // Initialise new method
newMethod.Body = GetBlock(this.textEditor.SelectedText); newMethod.Body = GetBlock(this.textEditor.SelectedText);
newMethod.Body.StartLocation = new Location(0,0); newMethod.Body.StartLocation = new Location(0,0);
this.parentNode = GetParentMember(start, end); this.parentNode = GetParentMember(start, end);
if (parentNode == null) { if (parentNode == null) {
@ -77,8 +77,21 @@ namespace SharpRefactoring
return false; return false;
} }
if (!CheckForJumpInstructions(newMethod)) ErrorKind kind = CheckForJumpInstructions(newMethod);
if (kind != ErrorKind.None) {
switch (kind) {
case ErrorKind.ContainsBreak:
MessageService.ShowError("${res:AddIns.SharpRefactoring.ExtractMethod.ContainsBreakError}");
break;
case ErrorKind.ContainsContinue:
MessageService.ShowError("${res:AddIns.SharpRefactoring.ExtractMethod.ContainsContinueError}");
break;
case ErrorKind.ContainsGoto:
MessageService.ShowError("${res:AddIns.SharpRefactoring.ExtractMethod.ContainsGotoError}");
break;
}
return false; return false;
}
newMethod.Modifier = parentNode.Modifier; newMethod.Modifier = parentNode.Modifier;

5
src/AddIns/Misc/SharpRefactoring/Project/Src/MethodExtractorBase.cs

@ -134,13 +134,12 @@ namespace SharpRefactoring
} }
} }
protected static bool CheckForJumpInstructions(MethodDeclaration method) protected ErrorKind CheckForJumpInstructions(MethodDeclaration method)
{ {
FindJumpInstructionsVisitor fjiv = new FindJumpInstructionsVisitor(method); FindJumpInstructionsVisitor fjiv = new FindJumpInstructionsVisitor(method);
method.AcceptVisitor(fjiv, null); method.AcceptVisitor(fjiv, null);
return fjiv.DoCheck();
return fjiv.IsOk;
} }
protected bool IsInCurrentSelection(Location location) protected bool IsInCurrentSelection(Location location)

108
src/AddIns/Misc/SharpRefactoring/Project/Src/Visitors/FindJumpInstructionsVisitor.cs

@ -1,39 +1,53 @@
/* // <file>
* Created by SharpDevelop. // <copyright see="prj:///doc/copyright.txt"/>
* User: HP // <license see="prj:///doc/license.txt"/>
* Date: 01.05.2008 // <owner name="Siegfried Pammer" email="sie_pam@gmx.at"/>
* Time: 20:37 // <version>$Revision$</version>
*/ // </file>
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using ICSharpCode.Core; using ICSharpCode.Core;
using ICSharpCode.NRefactory; using ICSharpCode.NRefactory;
using ICSharpCode.NRefactory.Ast; using ICSharpCode.NRefactory.Ast;
using ICSharpCode.NRefactory.PrettyPrinter;
using ICSharpCode.NRefactory.Visitors; using ICSharpCode.NRefactory.Visitors;
using Dom = ICSharpCode.SharpDevelop.Dom; using Dom = ICSharpCode.SharpDevelop.Dom;
namespace SharpRefactoring.Visitors namespace SharpRefactoring.Visitors
{ {
/// <summary> public enum ErrorKind {
/// Description of FindJumpInstructionVisitor. ContainsBreak,
/// </summary> ContainsContinue,
ContainsGoto,
None
}
public class FindJumpInstructionsVisitor : AbstractAstVisitor public class FindJumpInstructionsVisitor : AbstractAstVisitor
{ {
MethodDeclaration method; MethodDeclaration method;
List<LabelStatement> labels; List<LabelStatement> labels;
List<CaseLabel> cases; List<CaseLabel> cases;
bool isOk = true;
public bool IsOk { List<GotoStatement> gotos;
get { return isOk; } List<GotoCaseStatement> gotoCases;
}
List<BreakStatement> breaks;
List<ContinueStatement> continues;
public FindJumpInstructionsVisitor(MethodDeclaration method) public FindJumpInstructionsVisitor(MethodDeclaration method)
{ {
this.method = method; this.method = method;
this.labels = new List<LabelStatement>(); this.labels = new List<LabelStatement>();
this.cases = new List<CaseLabel>(); this.cases = new List<CaseLabel>();
this.gotoCases = new List<GotoCaseStatement>();
this.gotos = new List<GotoStatement>();
this.breaks = new List<BreakStatement>();
this.continues = new List<ContinueStatement>();
} }
public override object VisitDoLoopStatement(DoLoopStatement doLoopStatement, object data) public override object VisitDoLoopStatement(DoLoopStatement doLoopStatement, object data)
@ -63,19 +77,15 @@ namespace SharpRefactoring.Visitors
public override object VisitBreakStatement(BreakStatement breakStatement, object data) public override object VisitBreakStatement(BreakStatement breakStatement, object data)
{ {
if (!(data is bool)) { if (!(data is bool))
this.isOk = false; this.breaks.Add(breakStatement);
MessageService.ShowError("Selection contains a 'break' statement without the enclosing loop.");
}
return base.VisitBreakStatement(breakStatement, data); return base.VisitBreakStatement(breakStatement, data);
} }
public override object VisitContinueStatement(ContinueStatement continueStatement, object data) public override object VisitContinueStatement(ContinueStatement continueStatement, object data)
{ {
if (!(data is bool)) { if (!(data is bool))
this.isOk = false; this.continues.Add(continueStatement);
MessageService.ShowError("Selection contains a 'continue' statement without the enclosing loop.");
}
return base.VisitContinueStatement(continueStatement, data); return base.VisitContinueStatement(continueStatement, data);
} }
@ -93,30 +103,54 @@ namespace SharpRefactoring.Visitors
public override object VisitGotoCaseStatement(GotoCaseStatement gotoCaseStatement, object data) public override object VisitGotoCaseStatement(GotoCaseStatement gotoCaseStatement, object data)
{ {
this.isOk = false; gotoCases.Add(gotoCaseStatement);
foreach (CaseLabel label in this.cases) {
if (label.Label.ToString() == gotoCaseStatement.Expression.ToString())
this.isOk = true;
}
if (!this.isOk) {
MessageService.ShowError("Case section '" + ((PrimitiveExpression)gotoCaseStatement.Expression).StringValue + "' not found inside the selected range!");
}
return base.VisitGotoCaseStatement(gotoCaseStatement, data); return base.VisitGotoCaseStatement(gotoCaseStatement, data);
} }
public override object VisitGotoStatement(GotoStatement gotoStatement, object data) public override object VisitGotoStatement(GotoStatement gotoStatement, object data)
{ {
this.isOk = false; gotos.Add(gotoStatement);
foreach (LabelStatement label in this.labels) { return base.VisitGotoStatement(gotoStatement, data);
if (label.Label == gotoStatement.Label) }
this.isOk = true;
public ErrorKind DoCheck()
{
if (this.breaks.Any())
return ErrorKind.ContainsBreak;
if (this.continues.Any())
return ErrorKind.ContainsContinue;
if (this.gotos.Any()) {
foreach (GotoStatement stmt in this.gotos) {
if (!this.labels.Any(label => label.Label == stmt.Label))
return ErrorKind.ContainsGoto;
}
} }
if (!this.isOk) {
MessageService.ShowError("Label '" + gotoStatement.Label + "' not found inside the selected range!"); if (this.gotoCases.Any()) {
foreach (GotoCaseStatement stmt in this.gotoCases) {
if (!this.cases.Any(@case => CompareCase(@case, stmt)))
return ErrorKind.ContainsGoto;
}
} }
return base.VisitGotoStatement(gotoStatement, data); return ErrorKind.None;
}
bool CompareCase(CaseLabel label, GotoCaseStatement stmt)
{
if (label.IsDefault && stmt.IsDefaultCase)
return true;
if (stmt.Expression is PrimitiveExpression && label.Label is PrimitiveExpression) {
PrimitiveExpression e1 = stmt.Expression as PrimitiveExpression;
PrimitiveExpression e2 = label.Label as PrimitiveExpression;
return object.Equals(e1.Value, e2.Value);
}
return false;
} }
} }
} }

12
src/AddIns/Misc/SharpRefactoring/Project/Src/Visitors/FindMemberVisitor.cs

@ -1,9 +1,9 @@
/* // <file>
* Created by SharpDevelop. // <copyright see="prj:///doc/copyright.txt"/>
* User: HP // <license see="prj:///doc/license.txt"/>
* Date: 28.04.2008 // <owner name="Siegfried Pammer" email="sie_pam@gmx.at"/>
* Time: 22:18 // <version>$Revision$</version>
*/ // </file>
using System; using System;
using ICSharpCode.NRefactory; using ICSharpCode.NRefactory;

12
src/AddIns/Misc/SharpRefactoring/Project/Src/Visitors/FindReferenceVisitor.cs

@ -1,9 +1,9 @@
/* // <file>
* Created by SharpDevelop. // <copyright see="prj:///doc/copyright.txt"/>
* User: HP // <license see="prj:///doc/license.txt"/>
* Date: 28.04.2008 // <owner name="Siegfried Pammer" email="sie_pam@gmx.at"/>
* Time: 22:18 // <version>$Revision$</version>
*/ // </file>
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;

12
src/AddIns/Misc/SharpRefactoring/Project/Src/Visitors/HasAssignmentsVisitor.cs

@ -1,9 +1,9 @@
/* // <file>
* Created by SharpDevelop. // <copyright see="prj:///doc/copyright.txt"/>
* User: HP // <license see="prj:///doc/license.txt"/>
* Date: 28.04.2008 // <owner name="Siegfried Pammer" email="sie_pam@gmx.at"/>
* Time: 22:18 // <version>$Revision$</version>
*/ // </file>
using ICSharpCode.NRefactory; using ICSharpCode.NRefactory;
using System; using System;

12
src/AddIns/Misc/SharpRefactoring/Project/Src/Visitors/HasReturnStatementVisitor.cs

@ -1,9 +1,9 @@
/* // <file>
* Created by SharpDevelop. // <copyright see="prj:///doc/copyright.txt"/>
* User: HP // <license see="prj:///doc/license.txt"/>
* Date: 28.04.2008 // <owner name="Siegfried Pammer" email="sie_pam@gmx.at"/>
* Time: 22:18 // <version>$Revision$</version>
*/ // </file>
using System; using System;
using ICSharpCode.NRefactory.Ast; using ICSharpCode.NRefactory.Ast;

4
src/AddIns/Misc/SharpRefactoring/Test/SharpRefactoring.Tests.csproj

@ -78,6 +78,10 @@
<Name>NRefactory</Name> <Name>NRefactory</Name>
<Private>False</Private> <Private>False</Private>
</ProjectReference> </ProjectReference>
<ProjectReference Include="..\..\..\..\Libraries\NRefactory\Test\NRefactoryTests.csproj">
<Project>{870115DD-960A-4406-A6B9-600BCDC36A03}</Project>
<Name>NRefactoryTests</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\..\Main\Base\Project\ICSharpCode.SharpDevelop.csproj"> <ProjectReference Include="..\..\..\..\Main\Base\Project\ICSharpCode.SharpDevelop.csproj">
<Project>{2748AD25-9C63-4E12-877B-4DCE96FBED54}</Project> <Project>{2748AD25-9C63-4E12-877B-4DCE96FBED54}</Project>
<Name>ICSharpCode.SharpDevelop</Name> <Name>ICSharpCode.SharpDevelop</Name>

Loading…
Cancel
Save