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. 15
      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

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

@ -77,8 +77,21 @@ namespace SharpRefactoring @@ -77,8 +77,21 @@ namespace SharpRefactoring
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;
}
newMethod.Modifier = parentNode.Modifier;

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

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

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

@ -1,39 +1,53 @@ @@ -1,39 +1,53 @@
/*
* Created by SharpDevelop.
* User: HP
* Date: 01.05.2008
* Time: 20:37
*/
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Siegfried Pammer" email="sie_pam@gmx.at"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Collections.Generic;
using System.Linq;
using ICSharpCode.Core;
using ICSharpCode.NRefactory;
using ICSharpCode.NRefactory.Ast;
using ICSharpCode.NRefactory.PrettyPrinter;
using ICSharpCode.NRefactory.Visitors;
using Dom = ICSharpCode.SharpDevelop.Dom;
namespace SharpRefactoring.Visitors
{
/// <summary>
/// Description of FindJumpInstructionVisitor.
/// </summary>
public enum ErrorKind {
ContainsBreak,
ContainsContinue,
ContainsGoto,
None
}
public class FindJumpInstructionsVisitor : AbstractAstVisitor
{
MethodDeclaration method;
List<LabelStatement> labels;
List<CaseLabel> cases;
bool isOk = true;
public bool IsOk {
get { return isOk; }
}
List<GotoStatement> gotos;
List<GotoCaseStatement> gotoCases;
List<BreakStatement> breaks;
List<ContinueStatement> continues;
public FindJumpInstructionsVisitor(MethodDeclaration method)
{
this.method = method;
this.labels = new List<LabelStatement>();
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)
@ -63,19 +77,15 @@ namespace SharpRefactoring.Visitors @@ -63,19 +77,15 @@ namespace SharpRefactoring.Visitors
public override object VisitBreakStatement(BreakStatement breakStatement, object data)
{
if (!(data is bool)) {
this.isOk = false;
MessageService.ShowError("Selection contains a 'break' statement without the enclosing loop.");
}
if (!(data is bool))
this.breaks.Add(breakStatement);
return base.VisitBreakStatement(breakStatement, data);
}
public override object VisitContinueStatement(ContinueStatement continueStatement, object data)
{
if (!(data is bool)) {
this.isOk = false;
MessageService.ShowError("Selection contains a 'continue' statement without the enclosing loop.");
}
if (!(data is bool))
this.continues.Add(continueStatement);
return base.VisitContinueStatement(continueStatement, data);
}
@ -93,30 +103,54 @@ namespace SharpRefactoring.Visitors @@ -93,30 +103,54 @@ namespace SharpRefactoring.Visitors
public override object VisitGotoCaseStatement(GotoCaseStatement gotoCaseStatement, object data)
{
this.isOk = false;
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!");
}
gotoCases.Add(gotoCaseStatement);
return base.VisitGotoCaseStatement(gotoCaseStatement, data);
}
public override object VisitGotoStatement(GotoStatement gotoStatement, object data)
{
this.isOk = false;
foreach (LabelStatement label in this.labels) {
if (label.Label == gotoStatement.Label)
this.isOk = true;
gotos.Add(gotoStatement);
return base.VisitGotoStatement(gotoStatement, data);
}
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 @@ @@ -1,9 +1,9 @@
/*
* Created by SharpDevelop.
* User: HP
* Date: 28.04.2008
* Time: 22:18
*/
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Siegfried Pammer" email="sie_pam@gmx.at"/>
// <version>$Revision$</version>
// </file>
using System;
using ICSharpCode.NRefactory;

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

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

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

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

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

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

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

@ -78,6 +78,10 @@ @@ -78,6 +78,10 @@
<Name>NRefactory</Name>
<Private>False</Private>
</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">
<Project>{2748AD25-9C63-4E12-877B-4DCE96FBED54}</Project>
<Name>ICSharpCode.SharpDevelop</Name>

Loading…
Cancel
Save