Browse Source
- moved MoveClassToFile, GetDocument, and ExtractCode from ClassBookmarkMenuBuilder.cs to FindReferencesAndRenameHelper.cs to co-locate similar refactoring helpers - added ExtractInterface refactoring to the ClassBookmarkMenuBuilder, RefactoringProvider, and NRefactoryRefactoringProvider - added some test for NRefactoryRefactoringProvider in a new test project: ICSharpCode.SharpDevelop.Dom.Tests - added default string resources for ExtractInterface to both StringResources.resources and LocalizeDb.mdb git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@3019 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61shortcuts
20 changed files with 2052 additions and 187 deletions
@ -0,0 +1,275 @@ |
|||||||
|
/* |
||||||
|
* Created by SharpDevelop. |
||||||
|
* User: alperd1 |
||||||
|
* Date: 1/31/2008 |
||||||
|
* Time: 4:26 AM |
||||||
|
* |
||||||
|
* To change this template use Tools | Options | Coding | Edit Standard Headers. |
||||||
|
*/ |
||||||
|
namespace ICSharpCode.SharpDevelop.Gui |
||||||
|
{ |
||||||
|
partial class ExtractInterfaceDialog |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Designer variable used to keep track of non-visual components.
|
||||||
|
/// </summary>
|
||||||
|
private System.ComponentModel.IContainer components = null; |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Disposes resources used by the form.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
|
protected override void Dispose(bool disposing) |
||||||
|
{ |
||||||
|
if (disposing) { |
||||||
|
if (components != null) { |
||||||
|
components.Dispose(); |
||||||
|
} |
||||||
|
} |
||||||
|
base.Dispose(disposing); |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// This method is required for Windows Forms designer support.
|
||||||
|
/// Do not change the method contents inside the source code editor. The Forms designer might
|
||||||
|
/// not be able to load this method if it was changed manually.
|
||||||
|
/// </summary>
|
||||||
|
private void InitializeComponent() |
||||||
|
{ |
||||||
|
this.lblInterfaceName = new System.Windows.Forms.Label(); |
||||||
|
this.txtInterfaceName = new System.Windows.Forms.TextBox(); |
||||||
|
this.lblGeneratedName = new System.Windows.Forms.Label(); |
||||||
|
this.txtGeneratedName = new System.Windows.Forms.TextBox(); |
||||||
|
this.lblNewFileName = new System.Windows.Forms.Label(); |
||||||
|
this.txtNewFileName = new System.Windows.Forms.TextBox(); |
||||||
|
this.btnSelectAll = new System.Windows.Forms.Button(); |
||||||
|
this.selectMembersListBox = new System.Windows.Forms.CheckedListBox(); |
||||||
|
this.specifyInterfaceGroupBox = new System.Windows.Forms.GroupBox(); |
||||||
|
this.cbIncludeComments = new System.Windows.Forms.CheckBox(); |
||||||
|
this.btnDeselectAll = new System.Windows.Forms.Button(); |
||||||
|
this.btnCancel = new System.Windows.Forms.Button(); |
||||||
|
this.btnOK = new System.Windows.Forms.Button(); |
||||||
|
this.groupOptions = new System.Windows.Forms.GroupBox(); |
||||||
|
this.cbAddToClass = new System.Windows.Forms.CheckBox(); |
||||||
|
this.specifyInterfaceGroupBox.SuspendLayout(); |
||||||
|
this.groupOptions.SuspendLayout(); |
||||||
|
this.SuspendLayout(); |
||||||
|
//
|
||||||
|
// lblInterfaceName
|
||||||
|
//
|
||||||
|
this.lblInterfaceName.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) |
||||||
|
| System.Windows.Forms.AnchorStyles.Right))); |
||||||
|
this.lblInterfaceName.Location = new System.Drawing.Point(12, 9); |
||||||
|
this.lblInterfaceName.Name = "lblInterfaceName"; |
||||||
|
this.lblInterfaceName.Size = new System.Drawing.Size(283, 23); |
||||||
|
this.lblInterfaceName.TabIndex = 0; |
||||||
|
this.lblInterfaceName.Text = "${res:Dialog.Refactoring.ExtractInterface.InterfaceName}:"; |
||||||
|
this.lblInterfaceName.TextAlign = System.Drawing.ContentAlignment.BottomLeft; |
||||||
|
//
|
||||||
|
// txtInterfaceName
|
||||||
|
//
|
||||||
|
this.txtInterfaceName.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) |
||||||
|
| System.Windows.Forms.AnchorStyles.Right))); |
||||||
|
this.txtInterfaceName.Location = new System.Drawing.Point(15, 35); |
||||||
|
this.txtInterfaceName.Name = "txtInterfaceName"; |
||||||
|
this.txtInterfaceName.Size = new System.Drawing.Size(412, 20); |
||||||
|
this.txtInterfaceName.TabIndex = 6; |
||||||
|
this.txtInterfaceName.TextChanged += new System.EventHandler(this.TxtInterfaceNameTextChanged); |
||||||
|
//
|
||||||
|
// lblGeneratedName
|
||||||
|
//
|
||||||
|
this.lblGeneratedName.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) |
||||||
|
| System.Windows.Forms.AnchorStyles.Right))); |
||||||
|
this.lblGeneratedName.Location = new System.Drawing.Point(12, 58); |
||||||
|
this.lblGeneratedName.Name = "lblGeneratedName"; |
||||||
|
this.lblGeneratedName.Size = new System.Drawing.Size(289, 23); |
||||||
|
this.lblGeneratedName.TabIndex = 2; |
||||||
|
this.lblGeneratedName.Text = "${res:Dialog.Refactoring.ExtractInterface.GeneratedName}:"; |
||||||
|
this.lblGeneratedName.TextAlign = System.Drawing.ContentAlignment.BottomLeft; |
||||||
|
//
|
||||||
|
// txtGeneratedName
|
||||||
|
//
|
||||||
|
this.txtGeneratedName.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) |
||||||
|
| System.Windows.Forms.AnchorStyles.Right))); |
||||||
|
this.txtGeneratedName.Enabled = false; |
||||||
|
this.txtGeneratedName.Location = new System.Drawing.Point(15, 84); |
||||||
|
this.txtGeneratedName.Name = "txtGeneratedName"; |
||||||
|
this.txtGeneratedName.Size = new System.Drawing.Size(412, 20); |
||||||
|
this.txtGeneratedName.TabIndex = 7; |
||||||
|
//
|
||||||
|
// lblNewFileName
|
||||||
|
//
|
||||||
|
this.lblNewFileName.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) |
||||||
|
| System.Windows.Forms.AnchorStyles.Right))); |
||||||
|
this.lblNewFileName.Location = new System.Drawing.Point(12, 107); |
||||||
|
this.lblNewFileName.Name = "lblNewFileName"; |
||||||
|
this.lblNewFileName.Size = new System.Drawing.Size(286, 23); |
||||||
|
this.lblNewFileName.TabIndex = 1; |
||||||
|
this.lblNewFileName.Text = "${res:Dialog.Refactoring.ExtractInterface.NewFileName}:"; |
||||||
|
this.lblNewFileName.TextAlign = System.Drawing.ContentAlignment.BottomLeft; |
||||||
|
//
|
||||||
|
// txtNewFileName
|
||||||
|
//
|
||||||
|
this.txtNewFileName.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) |
||||||
|
| System.Windows.Forms.AnchorStyles.Right))); |
||||||
|
this.txtNewFileName.Location = new System.Drawing.Point(15, 133); |
||||||
|
this.txtNewFileName.Name = "txtNewFileName"; |
||||||
|
this.txtNewFileName.Size = new System.Drawing.Size(412, 20); |
||||||
|
this.txtNewFileName.TabIndex = 8; |
||||||
|
this.txtNewFileName.TextChanged += new System.EventHandler(this.TxtNewFileNameTextChanged); |
||||||
|
this.txtNewFileName.KeyDown += new System.Windows.Forms.KeyEventHandler(this.TxtNewFileNameKeyDown); |
||||||
|
//
|
||||||
|
// btnSelectAll
|
||||||
|
//
|
||||||
|
this.btnSelectAll.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); |
||||||
|
this.btnSelectAll.Location = new System.Drawing.Point(321, 16); |
||||||
|
this.btnSelectAll.Name = "btnSelectAll"; |
||||||
|
this.btnSelectAll.Size = new System.Drawing.Size(94, 23); |
||||||
|
this.btnSelectAll.TabIndex = 4; |
||||||
|
this.btnSelectAll.Text = "${res:Global.SelectAllButtonText}"; |
||||||
|
this.btnSelectAll.UseVisualStyleBackColor = true; |
||||||
|
this.btnSelectAll.Click += new System.EventHandler(this.BtnSelectAllClick); |
||||||
|
//
|
||||||
|
// selectMembersListBox
|
||||||
|
//
|
||||||
|
this.selectMembersListBox.CheckOnClick = true; |
||||||
|
this.selectMembersListBox.Dock = System.Windows.Forms.DockStyle.Left; |
||||||
|
this.selectMembersListBox.FormattingEnabled = true; |
||||||
|
this.selectMembersListBox.HorizontalScrollbar = true; |
||||||
|
this.selectMembersListBox.Location = new System.Drawing.Point(3, 16); |
||||||
|
this.selectMembersListBox.Name = "selectMembersListBox"; |
||||||
|
this.selectMembersListBox.Size = new System.Drawing.Size(312, 154); |
||||||
|
this.selectMembersListBox.TabIndex = 0; |
||||||
|
this.selectMembersListBox.ThreeDCheckBoxes = true; |
||||||
|
//
|
||||||
|
// specifyInterfaceGroupBox
|
||||||
|
//
|
||||||
|
this.specifyInterfaceGroupBox.Controls.Add(this.btnDeselectAll); |
||||||
|
this.specifyInterfaceGroupBox.Controls.Add(this.btnSelectAll); |
||||||
|
this.specifyInterfaceGroupBox.Controls.Add(this.selectMembersListBox); |
||||||
|
this.specifyInterfaceGroupBox.Location = new System.Drawing.Point(12, 231); |
||||||
|
this.specifyInterfaceGroupBox.Name = "specifyInterfaceGroupBox"; |
||||||
|
this.specifyInterfaceGroupBox.Size = new System.Drawing.Size(421, 173); |
||||||
|
this.specifyInterfaceGroupBox.TabIndex = 3; |
||||||
|
this.specifyInterfaceGroupBox.TabStop = false; |
||||||
|
this.specifyInterfaceGroupBox.Text = "${res:Dialog.Refactoring.ExtractInterface.SelectPublicMembers}"; |
||||||
|
//
|
||||||
|
// cbIncludeComments
|
||||||
|
//
|
||||||
|
this.cbIncludeComments.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) |
||||||
|
| System.Windows.Forms.AnchorStyles.Right))); |
||||||
|
this.cbIncludeComments.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft; |
||||||
|
this.cbIncludeComments.Location = new System.Drawing.Point(6, 19); |
||||||
|
this.cbIncludeComments.Name = "cbIncludeComments"; |
||||||
|
this.cbIncludeComments.Size = new System.Drawing.Size(410, 17); |
||||||
|
this.cbIncludeComments.TabIndex = 11; |
||||||
|
this.cbIncludeComments.Text = "${res:Dialog.Refactoring.ExtractInterface.IncludeComments}"; |
||||||
|
this.cbIncludeComments.UseVisualStyleBackColor = true; |
||||||
|
//
|
||||||
|
// btnDeselectAll
|
||||||
|
//
|
||||||
|
this.btnDeselectAll.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); |
||||||
|
this.btnDeselectAll.Location = new System.Drawing.Point(321, 45); |
||||||
|
this.btnDeselectAll.Name = "btnDeselectAll"; |
||||||
|
this.btnDeselectAll.Size = new System.Drawing.Size(94, 23); |
||||||
|
this.btnDeselectAll.TabIndex = 5; |
||||||
|
this.btnDeselectAll.Text = "${res:Global.DeselectAllButtonText}"; |
||||||
|
this.btnDeselectAll.UseVisualStyleBackColor = true; |
||||||
|
this.btnDeselectAll.Click += new System.EventHandler(this.BtnDeselectAllClick); |
||||||
|
//
|
||||||
|
// btnCancel
|
||||||
|
//
|
||||||
|
this.btnCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); |
||||||
|
this.btnCancel.Location = new System.Drawing.Point(352, 414); |
||||||
|
this.btnCancel.Name = "btnCancel"; |
||||||
|
this.btnCancel.Size = new System.Drawing.Size(75, 23); |
||||||
|
this.btnCancel.TabIndex = 9; |
||||||
|
this.btnCancel.Text = "${res:Global.CancelButtonText}"; |
||||||
|
this.btnCancel.UseVisualStyleBackColor = true; |
||||||
|
this.btnCancel.Click += new System.EventHandler(this.BtnCancelClick); |
||||||
|
//
|
||||||
|
// btnOK
|
||||||
|
//
|
||||||
|
this.btnOK.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); |
||||||
|
this.btnOK.Location = new System.Drawing.Point(271, 414); |
||||||
|
this.btnOK.Name = "btnOK"; |
||||||
|
this.btnOK.Size = new System.Drawing.Size(75, 23); |
||||||
|
this.btnOK.TabIndex = 10; |
||||||
|
this.btnOK.Text = "${res:Global.OKButtonText}"; |
||||||
|
this.btnOK.UseVisualStyleBackColor = true; |
||||||
|
this.btnOK.Click += new System.EventHandler(this.BtnOKClick); |
||||||
|
//
|
||||||
|
// groupOptions
|
||||||
|
//
|
||||||
|
this.groupOptions.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) |
||||||
|
| System.Windows.Forms.AnchorStyles.Right))); |
||||||
|
this.groupOptions.Controls.Add(this.cbAddToClass); |
||||||
|
this.groupOptions.Controls.Add(this.cbIncludeComments); |
||||||
|
this.groupOptions.Location = new System.Drawing.Point(12, 159); |
||||||
|
this.groupOptions.Name = "groupOptions"; |
||||||
|
this.groupOptions.Size = new System.Drawing.Size(421, 66); |
||||||
|
this.groupOptions.TabIndex = 11; |
||||||
|
this.groupOptions.TabStop = false; |
||||||
|
this.groupOptions.Text = "${res:Global.OptionsButtonText}"; |
||||||
|
//
|
||||||
|
// cbAddToClass
|
||||||
|
//
|
||||||
|
this.cbAddToClass.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) |
||||||
|
| System.Windows.Forms.AnchorStyles.Right))); |
||||||
|
this.cbAddToClass.Checked = true; |
||||||
|
this.cbAddToClass.CheckState = System.Windows.Forms.CheckState.Checked; |
||||||
|
this.cbAddToClass.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft; |
||||||
|
this.cbAddToClass.Location = new System.Drawing.Point(6, 42); |
||||||
|
this.cbAddToClass.Name = "cbAddToClass"; |
||||||
|
this.cbAddToClass.Size = new System.Drawing.Size(410, 17); |
||||||
|
this.cbAddToClass.TabIndex = 12; |
||||||
|
this.cbAddToClass.Text = "${res:Dialog.Refactoring.ExtractInterface.AddInterfaceToClass}"; |
||||||
|
this.cbAddToClass.UseVisualStyleBackColor = true; |
||||||
|
//
|
||||||
|
// ExtractInterfaceDialog
|
||||||
|
//
|
||||||
|
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); |
||||||
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; |
||||||
|
this.AutoSize = true; |
||||||
|
this.ClientSize = new System.Drawing.Size(445, 449); |
||||||
|
this.Controls.Add(this.groupOptions); |
||||||
|
this.Controls.Add(this.btnOK); |
||||||
|
this.Controls.Add(this.lblInterfaceName); |
||||||
|
this.Controls.Add(this.btnCancel); |
||||||
|
this.Controls.Add(this.txtInterfaceName); |
||||||
|
this.Controls.Add(this.txtNewFileName); |
||||||
|
this.Controls.Add(this.specifyInterfaceGroupBox); |
||||||
|
this.Controls.Add(this.lblGeneratedName); |
||||||
|
this.Controls.Add(this.txtGeneratedName); |
||||||
|
this.Controls.Add(this.lblNewFileName); |
||||||
|
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; |
||||||
|
this.HelpButton = true; |
||||||
|
this.MaximizeBox = false; |
||||||
|
this.MinimizeBox = false; |
||||||
|
this.Name = "ExtractInterfaceDialog"; |
||||||
|
this.ShowIcon = false; |
||||||
|
this.ShowInTaskbar = false; |
||||||
|
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; |
||||||
|
this.Text = "${res:SharpDevelop.Refactoring.ExtractInterfaceCommand}"; |
||||||
|
this.specifyInterfaceGroupBox.ResumeLayout(false); |
||||||
|
this.groupOptions.ResumeLayout(false); |
||||||
|
this.ResumeLayout(false); |
||||||
|
this.PerformLayout(); |
||||||
|
} |
||||||
|
private System.Windows.Forms.CheckBox cbAddToClass; |
||||||
|
private System.Windows.Forms.GroupBox groupOptions; |
||||||
|
private System.Windows.Forms.CheckBox cbIncludeComments; |
||||||
|
private System.Windows.Forms.Button btnOK; |
||||||
|
private System.Windows.Forms.Button btnCancel; |
||||||
|
private System.Windows.Forms.Button btnDeselectAll; |
||||||
|
private System.Windows.Forms.GroupBox specifyInterfaceGroupBox; |
||||||
|
private System.Windows.Forms.CheckedListBox selectMembersListBox; |
||||||
|
private System.Windows.Forms.Button btnSelectAll; |
||||||
|
private System.Windows.Forms.TextBox txtNewFileName; |
||||||
|
private System.Windows.Forms.Label lblNewFileName; |
||||||
|
private System.Windows.Forms.TextBox txtGeneratedName; |
||||||
|
private System.Windows.Forms.Label lblGeneratedName; |
||||||
|
private System.Windows.Forms.TextBox txtInterfaceName; |
||||||
|
private System.Windows.Forms.Label lblInterfaceName; |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,196 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="David Alpert" email="david@spinthemoose.com"/>
|
||||||
|
// <version>$Revision: $</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Collections.Generic; |
||||||
|
using System.Drawing; |
||||||
|
using System.Text; |
||||||
|
using System.Windows.Forms; |
||||||
|
|
||||||
|
using ICSharpCode.Core; |
||||||
|
using ICSharpCode.SharpDevelop.Dom; |
||||||
|
using ICSharpCode.SharpDevelop.Refactoring; |
||||||
|
|
||||||
|
namespace ICSharpCode.SharpDevelop.Gui |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Asks the user about Extract Interface refactoring options.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns><see cref="ExtractInterfaceDialogResults"/></returns>
|
||||||
|
public partial class ExtractInterfaceDialog : Form |
||||||
|
{ |
||||||
|
ExtractInterfaceOptions options; |
||||||
|
bool hasSetFilenameExplicitly; |
||||||
|
|
||||||
|
public ExtractInterfaceDialog() |
||||||
|
{ |
||||||
|
//
|
||||||
|
// The InitializeComponent() call is required for Windows Forms designer support.
|
||||||
|
//
|
||||||
|
InitializeComponent(); |
||||||
|
|
||||||
|
this.Owner = WorkbenchSingleton.MainForm; |
||||||
|
this.TopMost = true; |
||||||
|
this.possibleInterfaceMembers = new List<IMember>(); |
||||||
|
this.hasSetFilenameExplicitly = false; |
||||||
|
|
||||||
|
/// recursively passes the Text attribute of each Control on this form through our StringParser
|
||||||
|
ParseTextFor(this); |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Recursively passes the Text attribute of a <see cref="Control"/> (and it's
|
||||||
|
/// child controls) through our <see cref="StringParser"/>, rewriting the
|
||||||
|
/// Text values as it goes.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="control">The <see cref="Control"/> to process.</param>
|
||||||
|
void ParseTextFor(Control control) |
||||||
|
{ |
||||||
|
control.Text = StringParser.Parse(control.Text); |
||||||
|
foreach(Control subControl in control.Controls) { |
||||||
|
ParseTextFor(subControl); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A custom ShowDialog routine that handles pass-through deserialization and reserialization
|
||||||
|
/// of a <see cref="ExtractInterfaceOptions"/> object to encapsulate this operation's
|
||||||
|
/// parameters.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="options">
|
||||||
|
/// A <see cref="ExtractInterfaceOptions"/> containing initial, default values for the operation.
|
||||||
|
/// </param>
|
||||||
|
/// <returns>
|
||||||
|
/// A <see cref="ExtractInterfaceOptions"/> reference encapsulating the dialog's parameters.
|
||||||
|
/// </returns>
|
||||||
|
public ExtractInterfaceOptions ShowDialog(ExtractInterfaceOptions options) |
||||||
|
{ |
||||||
|
InitializeFields(options); |
||||||
|
options.IsCancelled = (base.ShowDialog() == DialogResult.Cancel); |
||||||
|
return options; |
||||||
|
} |
||||||
|
|
||||||
|
List<IMember> possibleInterfaceMembers; |
||||||
|
|
||||||
|
void InitializeFields(ExtractInterfaceOptions o) |
||||||
|
{ |
||||||
|
this.options = o; |
||||||
|
|
||||||
|
this.txtInterfaceName.Text = o.NewInterfaceName; |
||||||
|
this.txtNewFileName.Text = o.SuggestedFileName; |
||||||
|
this.txtGeneratedName.Text = o.FullyQualifiedName; |
||||||
|
|
||||||
|
IClass c = o.ClassEntity; |
||||||
|
foreach (IMethod m in c.Methods) { |
||||||
|
if (m.IsPublic && !m.IsConstructor && !m.IsConst && !m.IsStatic) { |
||||||
|
this.possibleInterfaceMembers.Add(m); |
||||||
|
this.selectMembersListBox.Items.Add(FormatMemberForDisplay(m), CheckState.Checked); |
||||||
|
} |
||||||
|
} |
||||||
|
foreach (IProperty p in c.Properties) { |
||||||
|
if (p.IsPublic && !p.IsConst && !p.IsStatic) { |
||||||
|
this.possibleInterfaceMembers.Add(p); |
||||||
|
this.selectMembersListBox.Items.Add(FormatMemberForDisplay(p), CheckState.Checked); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
// TODO: i think these really belong in the model (ExtractInterfaceOptions)
|
||||||
|
// rather than the view's code-behind...
|
||||||
|
string FormatMemberForDisplay(IMethod m) |
||||||
|
{ |
||||||
|
StringBuilder sb = new StringBuilder(); |
||||||
|
sb.AppendFormat("{0} {1} ( ", m.ReturnType.Name, m.Name); |
||||||
|
foreach (IParameter p in m.Parameters) { |
||||||
|
if (p != m.Parameters[0]) { |
||||||
|
sb.Append(" , "); |
||||||
|
} |
||||||
|
sb.AppendFormat("{0} {1}", p.ReturnType.Name, p.Name); |
||||||
|
} |
||||||
|
sb.Append(" );"); |
||||||
|
return sb.ToString(); |
||||||
|
} |
||||||
|
|
||||||
|
string FormatMemberForDisplay(IProperty p) |
||||||
|
{ |
||||||
|
StringBuilder sb = new StringBuilder(); |
||||||
|
sb.AppendFormat("{0} {1} {{ ", p.ReturnType.Name, p.Name); |
||||||
|
if (p.CanGet) sb.Append("get;"); |
||||||
|
if (p.CanSet && p.CanSet) sb.Append(" "); |
||||||
|
if (p.CanSet) sb.Append("set;"); |
||||||
|
sb.Append(" }"); |
||||||
|
return sb.ToString(); |
||||||
|
} |
||||||
|
|
||||||
|
#region Event Handlers
|
||||||
|
|
||||||
|
//bool insideCheckAll = false;
|
||||||
|
|
||||||
|
void BtnSelectAllClick(object sender, EventArgs e) |
||||||
|
{ |
||||||
|
//insideCheckAll = true;
|
||||||
|
var numItems = selectMembersListBox.Items.Count; |
||||||
|
for(var i = 0; i<numItems; i++) { |
||||||
|
selectMembersListBox.SetItemCheckState(i, CheckState.Checked); |
||||||
|
} |
||||||
|
|
||||||
|
//insideCheckAll = false;
|
||||||
|
} |
||||||
|
|
||||||
|
void BtnOKClick(object sender, EventArgs e) |
||||||
|
{ |
||||||
|
this.options.ChosenMembers.Clear(); |
||||||
|
foreach (int i in selectMembersListBox.CheckedIndices) { |
||||||
|
this.options.ChosenMembers.Add(this.possibleInterfaceMembers[i]); |
||||||
|
} |
||||||
|
this.options.IncludeComments = cbIncludeComments.CheckState == CheckState.Checked; |
||||||
|
this.options.AddInterfaceToClass = cbAddToClass.CheckState == CheckState.Checked; |
||||||
|
this.DialogResult = DialogResult.OK; |
||||||
|
this.Close(); |
||||||
|
} |
||||||
|
|
||||||
|
void BtnCancelClick(object sender, EventArgs e) |
||||||
|
{ |
||||||
|
this.DialogResult = DialogResult.Cancel; |
||||||
|
this.Close(); |
||||||
|
} |
||||||
|
|
||||||
|
void BtnDeselectAllClick(object sender, EventArgs e) |
||||||
|
{ |
||||||
|
//insideCheckAll = true;
|
||||||
|
var numItems = selectMembersListBox.Items.Count; |
||||||
|
for(var i = 0; i<numItems; i++) { |
||||||
|
selectMembersListBox.SetItemCheckState(i, CheckState.Unchecked); |
||||||
|
} |
||||||
|
|
||||||
|
//insideCheckAll = false;
|
||||||
|
} |
||||||
|
|
||||||
|
void TxtInterfaceNameTextChanged(object sender, EventArgs e) |
||||||
|
{ |
||||||
|
this.options.NewInterfaceName = this.txtInterfaceName.Text; |
||||||
|
this.txtGeneratedName.Text = this.options.FullyQualifiedName; |
||||||
|
if (!hasSetFilenameExplicitly) { |
||||||
|
this.options.NewFileName = this.txtNewFileName.Text = this.options.SuggestedFileName; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void TxtNewFileNameTextChanged(object sender, EventArgs e) |
||||||
|
{ |
||||||
|
// TODO: this logic should really be in the model...
|
||||||
|
if (hasSetFilenameExplicitly) { |
||||||
|
this.options.NewFileName = this.txtNewFileName.Text; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void TxtNewFileNameKeyDown(object sender, KeyEventArgs e) |
||||||
|
{ |
||||||
|
hasSetFilenameExplicitly = true; |
||||||
|
} |
||||||
|
#endregion
|
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,120 @@ |
|||||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||||
|
<root> |
||||||
|
<!-- |
||||||
|
Microsoft ResX Schema |
||||||
|
|
||||||
|
Version 2.0 |
||||||
|
|
||||||
|
The primary goals of this format is to allow a simple XML format |
||||||
|
that is mostly human readable. The generation and parsing of the |
||||||
|
various data types are done through the TypeConverter classes |
||||||
|
associated with the data types. |
||||||
|
|
||||||
|
Example: |
||||||
|
|
||||||
|
... ado.net/XML headers & schema ... |
||||||
|
<resheader name="resmimetype">text/microsoft-resx</resheader> |
||||||
|
<resheader name="version">2.0</resheader> |
||||||
|
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader> |
||||||
|
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader> |
||||||
|
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data> |
||||||
|
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data> |
||||||
|
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64"> |
||||||
|
<value>[base64 mime encoded serialized .NET Framework object]</value> |
||||||
|
</data> |
||||||
|
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64"> |
||||||
|
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value> |
||||||
|
<comment>This is a comment</comment> |
||||||
|
</data> |
||||||
|
|
||||||
|
There are any number of "resheader" rows that contain simple |
||||||
|
name/value pairs. |
||||||
|
|
||||||
|
Each data row contains a name, and value. The row also contains a |
||||||
|
type or mimetype. Type corresponds to a .NET class that support |
||||||
|
text/value conversion through the TypeConverter architecture. |
||||||
|
Classes that don't support this are serialized and stored with the |
||||||
|
mimetype set. |
||||||
|
|
||||||
|
The mimetype is used for serialized objects, and tells the |
||||||
|
ResXResourceReader how to depersist the object. This is currently not |
||||||
|
extensible. For a given mimetype the value must be set accordingly: |
||||||
|
|
||||||
|
Note - application/x-microsoft.net.object.binary.base64 is the format |
||||||
|
that the ResXResourceWriter will generate, however the reader can |
||||||
|
read any of the formats listed below. |
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.binary.base64 |
||||||
|
value : The object must be serialized with |
||||||
|
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter |
||||||
|
: and then encoded with base64 encoding. |
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.soap.base64 |
||||||
|
value : The object must be serialized with |
||||||
|
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter |
||||||
|
: and then encoded with base64 encoding. |
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.bytearray.base64 |
||||||
|
value : The object must be serialized into a byte array |
||||||
|
: using a System.ComponentModel.TypeConverter |
||||||
|
: and then encoded with base64 encoding. |
||||||
|
--> |
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> |
||||||
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" /> |
||||||
|
<xsd:element name="root" msdata:IsDataSet="true"> |
||||||
|
<xsd:complexType> |
||||||
|
<xsd:choice maxOccurs="unbounded"> |
||||||
|
<xsd:element name="metadata"> |
||||||
|
<xsd:complexType> |
||||||
|
<xsd:sequence> |
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" /> |
||||||
|
</xsd:sequence> |
||||||
|
<xsd:attribute name="name" use="required" type="xsd:string" /> |
||||||
|
<xsd:attribute name="type" type="xsd:string" /> |
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" /> |
||||||
|
<xsd:attribute ref="xml:space" /> |
||||||
|
</xsd:complexType> |
||||||
|
</xsd:element> |
||||||
|
<xsd:element name="assembly"> |
||||||
|
<xsd:complexType> |
||||||
|
<xsd:attribute name="alias" type="xsd:string" /> |
||||||
|
<xsd:attribute name="name" type="xsd:string" /> |
||||||
|
</xsd:complexType> |
||||||
|
</xsd:element> |
||||||
|
<xsd:element name="data"> |
||||||
|
<xsd:complexType> |
||||||
|
<xsd:sequence> |
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> |
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" /> |
||||||
|
</xsd:sequence> |
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" /> |
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" /> |
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" /> |
||||||
|
<xsd:attribute ref="xml:space" /> |
||||||
|
</xsd:complexType> |
||||||
|
</xsd:element> |
||||||
|
<xsd:element name="resheader"> |
||||||
|
<xsd:complexType> |
||||||
|
<xsd:sequence> |
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> |
||||||
|
</xsd:sequence> |
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" /> |
||||||
|
</xsd:complexType> |
||||||
|
</xsd:element> |
||||||
|
</xsd:choice> |
||||||
|
</xsd:complexType> |
||||||
|
</xsd:element> |
||||||
|
</xsd:schema> |
||||||
|
<resheader name="resmimetype"> |
||||||
|
<value>text/microsoft-resx</value> |
||||||
|
</resheader> |
||||||
|
<resheader name="version"> |
||||||
|
<value>2.0</value> |
||||||
|
</resheader> |
||||||
|
<resheader name="reader"> |
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> |
||||||
|
</resheader> |
||||||
|
<resheader name="writer"> |
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> |
||||||
|
</resheader> |
||||||
|
</root> |
||||||
@ -0,0 +1,64 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="David Alpert" email="david@spinthemoose.com"/>
|
||||||
|
// <version>$Revision: $</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Collections.Generic; |
||||||
|
using System.IO; |
||||||
|
using ICSharpCode.SharpDevelop.Dom; |
||||||
|
|
||||||
|
namespace ICSharpCode.SharpDevelop.Refactoring |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Description of ExtractInterfaceDetails.
|
||||||
|
/// </summary>
|
||||||
|
public class ExtractInterfaceOptions |
||||||
|
{ |
||||||
|
IClass c; |
||||||
|
public ExtractInterfaceOptions(IClass c) |
||||||
|
{ |
||||||
|
if (null == c) { |
||||||
|
throw new InvalidOperationException("ExtractInterfaceOptions requires a valid IClass"); |
||||||
|
} |
||||||
|
this.c = c; |
||||||
|
this.NewInterfaceName = this.ClassEntity.Name.StartsWith("I") ? |
||||||
|
String.Format("{0}1", this.ClassEntity.Name) : |
||||||
|
String.Format("I{0}", this.ClassEntity.Name); |
||||||
|
this.NewFileName = this.SuggestedFileName; |
||||||
|
this.ChosenMembers = new List<IMember>(); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
public IClass ClassEntity { |
||||||
|
get { |
||||||
|
return this.c; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public string NewInterfaceName {get; set;} |
||||||
|
public string NewFileName {get;set;} |
||||||
|
public bool IsCancelled {get; set;} |
||||||
|
public bool IncludeComments {get; set;} |
||||||
|
public bool AddInterfaceToClass {get; set;} |
||||||
|
public List<IMember> ChosenMembers; |
||||||
|
|
||||||
|
public string FullyQualifiedName { |
||||||
|
get { |
||||||
|
return String.Format("{0}.{1}", |
||||||
|
c.Namespace, |
||||||
|
this.NewInterfaceName); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public string SuggestedFileName { |
||||||
|
get { |
||||||
|
return String.Format("{0}{1}", |
||||||
|
this.NewInterfaceName, |
||||||
|
Path.GetExtension(ClassEntity.CompilationUnit.FileName)); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,31 @@ |
|||||||
|
#region Using directives
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Reflection; |
||||||
|
using System.Runtime.InteropServices; |
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
// General Information about an assembly is controlled through the following
|
||||||
|
// set of attributes. Change these attribute values to modify the information
|
||||||
|
// associated with an assembly.
|
||||||
|
[assembly: AssemblyTitle("ICSharpCode.SharpDevelop.Dom.Tests")] |
||||||
|
[assembly: AssemblyDescription("")] |
||||||
|
[assembly: AssemblyConfiguration("")] |
||||||
|
[assembly: AssemblyCompany("")] |
||||||
|
[assembly: AssemblyProduct("ICSharpCode.SharpDevelop.Dom.Tests")] |
||||||
|
[assembly: AssemblyCopyright("")] |
||||||
|
[assembly: AssemblyTrademark("")] |
||||||
|
[assembly: AssemblyCulture("")] |
||||||
|
|
||||||
|
// This sets the default COM visibility of types in the assembly to invisible.
|
||||||
|
// If you need to expose a type to COM, use [ComVisible(true)] on that type.
|
||||||
|
[assembly: ComVisible(false)] |
||||||
|
|
||||||
|
// The assembly version has following format :
|
||||||
|
//
|
||||||
|
// Major.Minor.Build.Revision
|
||||||
|
//
|
||||||
|
// You can specify all the values or you can use the default the Revision and
|
||||||
|
// Build Numbers by using the '*' as shown below:
|
||||||
|
[assembly: AssemblyVersion("1.0.*")] |
||||||
@ -0,0 +1,66 @@ |
|||||||
|
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
||||||
|
<PropertyGroup> |
||||||
|
<ProjectGuid>{7DB80259-24D4-46C3-A024-53FF1987733D}</ProjectGuid> |
||||||
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> |
||||||
|
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> |
||||||
|
<OutputType>Library</OutputType> |
||||||
|
<RootNamespace>ICSharpCode.SharpDevelop.Dom.Tests</RootNamespace> |
||||||
|
<AssemblyName>ICSharpCode.SharpDevelop.Dom.Tests</AssemblyName> |
||||||
|
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion> |
||||||
|
<AllowUnsafeBlocks>False</AllowUnsafeBlocks> |
||||||
|
<NoStdLib>False</NoStdLib> |
||||||
|
<WarningLevel>4</WarningLevel> |
||||||
|
<TreatWarningsAsErrors>false</TreatWarningsAsErrors> |
||||||
|
<OutputPath>..\..\..\..\..\bin\UnitTests\</OutputPath> |
||||||
|
</PropertyGroup> |
||||||
|
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' "> |
||||||
|
<DebugSymbols>true</DebugSymbols> |
||||||
|
<DebugType>Full</DebugType> |
||||||
|
<Optimize>False</Optimize> |
||||||
|
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow> |
||||||
|
<DefineConstants>DEBUG;TRACE</DefineConstants> |
||||||
|
</PropertyGroup> |
||||||
|
<PropertyGroup Condition=" '$(Configuration)' == 'Release' "> |
||||||
|
<DebugSymbols>False</DebugSymbols> |
||||||
|
<DebugType>None</DebugType> |
||||||
|
<Optimize>True</Optimize> |
||||||
|
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow> |
||||||
|
<DefineConstants>TRACE</DefineConstants> |
||||||
|
</PropertyGroup> |
||||||
|
<PropertyGroup Condition=" '$(Platform)' == 'AnyCPU' "> |
||||||
|
<RegisterForComInterop>False</RegisterForComInterop> |
||||||
|
<GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies> |
||||||
|
<BaseAddress>4194304</BaseAddress> |
||||||
|
<PlatformTarget>AnyCPU</PlatformTarget> |
||||||
|
<FileAlignment>4096</FileAlignment> |
||||||
|
</PropertyGroup> |
||||||
|
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" /> |
||||||
|
<ItemGroup> |
||||||
|
<Reference Include="nunit.framework"> |
||||||
|
<HintPath>..\..\..\..\Tools\NUnit\nunit.framework.dll</HintPath> |
||||||
|
</Reference> |
||||||
|
<Reference Include="System" /> |
||||||
|
<Reference Include="System.Xml" /> |
||||||
|
</ItemGroup> |
||||||
|
<ItemGroup> |
||||||
|
<Compile Include="AssemblyInfo.cs" /> |
||||||
|
<Compile Include="NRefactoryRefactoringProviderTests.cs" /> |
||||||
|
<Compile Include="NUnitHelpers\SyntaxHelpers.cs" /> |
||||||
|
<Compile Include="NUnitHelpers\Constraints.cs" /> |
||||||
|
</ItemGroup> |
||||||
|
<ItemGroup> |
||||||
|
<ProjectReference Include="..\..\..\..\Libraries\NRefactory\Project\NRefactory.csproj"> |
||||||
|
<Project>{3A9AE6AA-BC07-4A2F-972C-581E3AE2F195}</Project> |
||||||
|
<Name>NRefactory</Name> |
||||||
|
</ProjectReference> |
||||||
|
<ProjectReference Include="..\..\..\Base\Test\ICSharpCode.SharpDevelop.Tests.csproj"> |
||||||
|
<Project>{4980B743-B32F-4aba-AABD-45E2CAD3568D}</Project> |
||||||
|
<Name>ICSharpCode.SharpDevelop.Tests</Name> |
||||||
|
</ProjectReference> |
||||||
|
<ProjectReference Include="..\..\Project\ICSharpCode.SharpDevelop.Dom.csproj"> |
||||||
|
<Project>{924EE450-603D-49C1-A8E5-4AFAA31CE6F3}</Project> |
||||||
|
<Name>ICSharpCode.SharpDevelop.Dom</Name> |
||||||
|
</ProjectReference> |
||||||
|
<Folder Include="NUnitHelpers" /> |
||||||
|
</ItemGroup> |
||||||
|
</Project> |
||||||
@ -0,0 +1,25 @@ |
|||||||
|
/* |
||||||
|
* Created by SharpDevelop. |
||||||
|
* User: alperd1 |
||||||
|
* Date: 2/7/2008 |
||||||
|
* Time: 12:48 PM |
||||||
|
* |
||||||
|
* To change this template use Tools | Options | Coding | Edit Standard Headers. |
||||||
|
*/ |
||||||
|
|
||||||
|
using System; |
||||||
|
using NUnit.Framework; |
||||||
|
using NUnit.Framework.SyntaxHelpers; |
||||||
|
|
||||||
|
namespace ICSharpCode.SharpDevelop.Dom.Tests |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class NRefactoryRefactoringProviderTestFixture |
||||||
|
{ |
||||||
|
[Test] |
||||||
|
public void TestMethod() |
||||||
|
{ |
||||||
|
// TODO: Add your test.
|
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,500 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="David Alpert" email="david@spinthemoose.com"/>
|
||||||
|
// <version>$Revision: $</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Collections.Generic; |
||||||
|
|
||||||
|
using NUnit.Framework; |
||||||
|
using NUnit.Framework.SyntaxHelpers; |
||||||
|
|
||||||
|
using ICSharpCode.SharpDevelop.Dom; |
||||||
|
using ICSharpCode.SharpDevelop.Dom.Refactoring; |
||||||
|
using NR = ICSharpCode.NRefactory; |
||||||
|
|
||||||
|
using ICSharpCode.SharpDevelop.Tests; |
||||||
|
|
||||||
|
namespace ICSharpCode.SharpDevelop.Dom.Tests |
||||||
|
{ |
||||||
|
|
||||||
|
|
||||||
|
[TestFixture] |
||||||
|
public class NRefactoryRefactoringProviderTests |
||||||
|
{ |
||||||
|
NRefactoryResolverTests helper; |
||||||
|
NRefactoryRefactoringProvider csharpRefactoringProvider; |
||||||
|
|
||||||
|
// TODO: write VBNet tests to ensure that Extract Interface works on VB.NET syntax
|
||||||
|
NRefactoryRefactoringProvider vbnetRefactoringProvider; |
||||||
|
|
||||||
|
#region Extract Interface
|
||||||
|
|
||||||
|
private class ITestClass { |
||||||
|
public const string FileName = "ITestCase.cs"; |
||||||
|
public const string FileContent = @"// <file>
|
||||||
|
// <copyright see=""prj:///doc/copyright.txt""/>
|
||||||
|
// <license see=""prj:///doc/license.txt""/>
|
||||||
|
// <owner name=""David Alpert"" email=""david@spinthemoose.com""/>
|
||||||
|
// <version>$Revision: $</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Collections.Generics; |
||||||
|
|
||||||
|
namespace ExtractInterface.Tests { |
||||||
|
|
||||||
|
public interface ITestCase { |
||||||
|
string Name {get;} |
||||||
|
string Property {get; set;} |
||||||
|
string Configure {set;} |
||||||
|
|
||||||
|
IList<int> GetRange(string subject); |
||||||
|
int MultiplyBy5(int x, |
||||||
|
out bool success); |
||||||
|
|
||||||
|
event EventHandler<UnhandledExceptionEventArgs> ConfigurationChanged; |
||||||
|
} |
||||||
|
} |
||||||
|
";
|
||||||
|
} |
||||||
|
|
||||||
|
private class TestClass { |
||||||
|
public const string FileName = "TestCase.cs"; |
||||||
|
|
||||||
|
// TODO: write TestClass.FileContent to refactor the string literal code blocks
|
||||||
|
// from the following tests.
|
||||||
|
public const string FileContent = @""; |
||||||
|
} |
||||||
|
|
||||||
|
#region Sanity Test
|
||||||
|
|
||||||
|
[Test] |
||||||
|
/// <summary>
|
||||||
|
/// ensures that the custom assertions in this test fixture are working properly
|
||||||
|
/// </summary>
|
||||||
|
public void SanityCheckTest() { |
||||||
|
ICompilationUnit cu = helper.Parse(ITestClass.FileName, ITestClass.FileContent); |
||||||
|
Assert.That(cu.Classes, Has.Count(1)); |
||||||
|
|
||||||
|
IClass c = cu.Classes[0]; |
||||||
|
Assert.That(c.ClassType, Is.EqualTo(ClassType.Interface)); |
||||||
|
Assert.That(c.BaseTypes, Has.Count(0)); |
||||||
|
Assert.That(c.Attributes, Has.Count(0)); |
||||||
|
Assert.That(c.Events, Has.Count(1)); |
||||||
|
Assert.That(c.Methods, Has.Count(2)); |
||||||
|
{ |
||||||
|
IMethod m = c.Methods[0]; |
||||||
|
Assert.That(m.Name, Is.EqualTo("GetRange")); |
||||||
|
Assert.That(m.Parameters, Has.Count(1)); |
||||||
|
Assert.That(m, HasEmpty.MethodBody); |
||||||
|
|
||||||
|
m = c.Methods[1]; |
||||||
|
Assert.That(m.Name, Is.EqualTo("MultiplyBy5")); |
||||||
|
Assert.That(m.Parameters, Has.Count(2)); |
||||||
|
Assert.That(m, HasEmpty.MethodBody); |
||||||
|
} |
||||||
|
Assert.That(c.Properties, Has.Count(3)); |
||||||
|
{ |
||||||
|
IProperty p = c.Properties[0]; |
||||||
|
Assert.That(p.Name, Is.EqualTo("Name")); |
||||||
|
Assert.That(p.CanGet, Is.True); |
||||||
|
Assert.That(p, HasEmpty.GetRegion); |
||||||
|
Assert.That(p.CanSet, Is.False); |
||||||
|
|
||||||
|
p = c.Properties[1]; |
||||||
|
Assert.That(p.Name, Is.EqualTo("Property")); |
||||||
|
Assert.That(p.CanGet, Is.True); |
||||||
|
Assert.That(p, HasEmpty.GetRegion); |
||||||
|
Assert.That(p.CanSet, Is.True); |
||||||
|
Assert.That(p, HasEmpty.SetRegion); |
||||||
|
|
||||||
|
p = c.Properties[2]; |
||||||
|
Assert.That(p.Name, Is.EqualTo("Configure")); |
||||||
|
Assert.That(p.CanGet, Is.False); |
||||||
|
Assert.That(p.CanSet, Is.True); |
||||||
|
Assert.That(p, HasEmpty.SetRegion); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
[Test] |
||||||
|
public void GenerateInterfaceFromImplicitPropertyTest() { |
||||||
|
string fileContent = @"
|
||||||
|
using System; |
||||||
|
|
||||||
|
namespace ExtractInterfaceImplicitPropertyTest { |
||||||
|
public class ClassA { |
||||||
|
string myName; |
||||||
|
|
||||||
|
public ClassA() { |
||||||
|
string myName = String.Empty; |
||||||
|
} |
||||||
|
|
||||||
|
public string Category { |
||||||
|
get; set; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
";
|
||||||
|
IList<IMember> membersToExtract = new List<IMember>(); |
||||||
|
|
||||||
|
ICompilationUnit cu = helper.Parse(TestClass.FileName, fileContent); |
||||||
|
IClass c = cu.Classes[0]; |
||||||
|
IProperty originalProperty = c.Properties[0]; |
||||||
|
membersToExtract.Add(originalProperty); |
||||||
|
string interfaceName = "IA"; |
||||||
|
string sourceClassName = c.Name; |
||||||
|
string sourceNamespace = c.Namespace; |
||||||
|
|
||||||
|
string interfaceCode = csharpRefactoringProvider.GenerateInterfaceForClass(interfaceName, |
||||||
|
membersToExtract, |
||||||
|
false, |
||||||
|
sourceNamespace, |
||||||
|
sourceClassName, |
||||||
|
fileContent); |
||||||
|
|
||||||
|
ICompilationUnit icu = helper.Parse(TestClass.FileName, interfaceCode); |
||||||
|
IClass i = icu.Classes[0]; |
||||||
|
|
||||||
|
Assert.That(i.ClassType, Is.EqualTo(ClassType.Interface)); |
||||||
|
Assert.That(i.Name, Is.EqualTo(interfaceName)); |
||||||
|
Assert.That(i.Namespace, Is.EqualTo(c.Namespace)); |
||||||
|
Assert.That(i.Methods.Count, Is.EqualTo(0)); |
||||||
|
Assert.That(i.Properties.Count, Is.EqualTo(1)); |
||||||
|
|
||||||
|
IProperty extractedProperty = i.Properties[0]; |
||||||
|
|
||||||
|
Assert.That(extractedProperty.Name, Is.EqualTo(originalProperty.Name)); |
||||||
|
Assert.That(extractedProperty.CanGet, Is.True); |
||||||
|
Assert.That(extractedProperty, HasEmpty.GetRegion); |
||||||
|
Assert.That(extractedProperty.CanSet, Is.True); |
||||||
|
Assert.That(extractedProperty, HasEmpty.SetRegion); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
[Ignore] // TODO: C# parser seems to have trouble with an implicit property with a private setter?
|
||||||
|
public void GenerateInterfaceFromImplicitPropertyWithPrivateSetterTest() { |
||||||
|
string fileContent = @"
|
||||||
|
using System; |
||||||
|
|
||||||
|
namespace ExtractInterfaceImplicitPropertyTest { |
||||||
|
public class ClassA { |
||||||
|
string myName; |
||||||
|
|
||||||
|
public ClassA() { |
||||||
|
string myName = String.Empty; |
||||||
|
} |
||||||
|
|
||||||
|
public string Category { |
||||||
|
get; private set; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
";
|
||||||
|
IList<IMember> membersToExtract = new List<IMember>(); |
||||||
|
|
||||||
|
ICompilationUnit cu = helper.Parse(TestClass.FileName, fileContent); |
||||||
|
IClass c = cu.Classes[0]; |
||||||
|
IProperty originalProperty = c.Properties[0]; |
||||||
|
membersToExtract.Add(originalProperty); |
||||||
|
string interfaceName = "IA"; |
||||||
|
string sourceClassName = c.Name; |
||||||
|
string sourceNamespace = c.Namespace; |
||||||
|
|
||||||
|
string interfaceCode = csharpRefactoringProvider.GenerateInterfaceForClass(interfaceName, |
||||||
|
membersToExtract, |
||||||
|
false, |
||||||
|
sourceNamespace, |
||||||
|
sourceClassName, |
||||||
|
fileContent); |
||||||
|
|
||||||
|
ICompilationUnit icu = helper.Parse(TestClass.FileName, interfaceCode); |
||||||
|
IClass i = icu.Classes[0]; |
||||||
|
|
||||||
|
Assert.That(i.ClassType, Is.EqualTo(ClassType.Interface)); |
||||||
|
Assert.That(i.Name, Is.EqualTo(interfaceName)); |
||||||
|
Assert.That(i.Namespace, Is.EqualTo(c.Namespace)); |
||||||
|
Assert.That(i.Methods.Count, Is.EqualTo(0)); |
||||||
|
Assert.That(i.Properties.Count, Is.EqualTo(1)); |
||||||
|
|
||||||
|
IProperty extractedProperty = i.Properties[0]; |
||||||
|
|
||||||
|
Assert.That(extractedProperty.Name, Is.EqualTo(originalProperty.Name)); |
||||||
|
Assert.That(extractedProperty.CanGet, Is.True); |
||||||
|
Assert.That(extractedProperty, HasEmpty.GetRegion); |
||||||
|
Assert.That(extractedProperty.CanSet, Is.False); |
||||||
|
Assert.That(extractedProperty, HasEmpty.SetRegion); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void GenerateInterfaceFromExplicitPropertyTest() { |
||||||
|
string fileContent = @"
|
||||||
|
using System; |
||||||
|
|
||||||
|
namespace ExtractInterfaceImplicitPropertyTest { |
||||||
|
public class ClassA { |
||||||
|
string myName; |
||||||
|
|
||||||
|
public ClassA() { |
||||||
|
string myName = String.Empty; |
||||||
|
} |
||||||
|
|
||||||
|
public string Name { |
||||||
|
get{ |
||||||
|
return myName; |
||||||
|
} |
||||||
|
set { |
||||||
|
myName = value; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
";
|
||||||
|
IList<IMember> membersToExtract = new List<IMember>(); |
||||||
|
|
||||||
|
ICompilationUnit cu = helper.Parse(TestClass.FileName, fileContent); |
||||||
|
IClass c = cu.Classes[0]; |
||||||
|
IProperty originalProperty = c.Properties[0]; |
||||||
|
membersToExtract.Add(originalProperty); |
||||||
|
string interfaceName = "IA"; |
||||||
|
string sourceClassName = c.Name; |
||||||
|
string sourceNamespace = c.Namespace; |
||||||
|
|
||||||
|
string interfaceCode = csharpRefactoringProvider.GenerateInterfaceForClass(interfaceName, |
||||||
|
membersToExtract, |
||||||
|
false, |
||||||
|
sourceNamespace, |
||||||
|
sourceClassName, |
||||||
|
fileContent); |
||||||
|
|
||||||
|
ICompilationUnit icu = helper.Parse(ITestClass.FileName, interfaceCode); |
||||||
|
IClass i = icu.Classes[0]; |
||||||
|
|
||||||
|
Assert.That(i.ClassType, Is.EqualTo(ClassType.Interface)); |
||||||
|
Assert.That(i.Name, Is.EqualTo(interfaceName)); |
||||||
|
Assert.That(i.Namespace, Is.EqualTo(c.Namespace)); |
||||||
|
Assert.That(i.Methods.Count, Is.EqualTo(0)); |
||||||
|
IProperty extractedProperty = i.Properties[0]; |
||||||
|
|
||||||
|
Assert.That(extractedProperty.Name, Is.EqualTo(originalProperty.Name)); |
||||||
|
Assert.That(extractedProperty.CanGet, Is.True); |
||||||
|
Assert.That(extractedProperty, HasEmpty.GetRegion); |
||||||
|
Assert.That(extractedProperty.CanSet, Is.True); |
||||||
|
Assert.That(extractedProperty, HasEmpty.SetRegion); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void GenerateInterfaceFromMethodsTest() { |
||||||
|
string fileContent = @"
|
||||||
|
using System; |
||||||
|
|
||||||
|
namespace ExtractInterfaceImplicitPropertyTest { |
||||||
|
public class ClassA { |
||||||
|
string myName; |
||||||
|
|
||||||
|
public ClassA() { |
||||||
|
string myName = String.Empty; |
||||||
|
} |
||||||
|
|
||||||
|
public string GetName() { |
||||||
|
return myName; |
||||||
|
} |
||||||
|
|
||||||
|
static public int GetNumber() { |
||||||
|
return -4; |
||||||
|
} |
||||||
|
} |
||||||
|
public interface ITestInterface { |
||||||
|
string GetName(); |
||||||
|
int Number { |
||||||
|
get; set; |
||||||
|
} |
||||||
|
int AnotherNumber { |
||||||
|
get; |
||||||
|
} |
||||||
|
int AnInlineNumber {get;set; } |
||||||
|
} |
||||||
|
} |
||||||
|
";
|
||||||
|
IList<IMember> membersToExtract = new List<IMember>(); |
||||||
|
|
||||||
|
ICompilationUnit cu = helper.Parse(TestClass.FileName, fileContent); |
||||||
|
IClass c = cu.Classes[0]; |
||||||
|
IMethod originalMethod = c.Methods[1]; |
||||||
|
membersToExtract.Add(originalMethod); |
||||||
|
string interfaceName = "IClassA"; |
||||||
|
string sourceClassName = c.Name; |
||||||
|
string sourceNamespace = c.Namespace; |
||||||
|
|
||||||
|
string interfaceCode = csharpRefactoringProvider.GenerateInterfaceForClass(interfaceName, |
||||||
|
membersToExtract, |
||||||
|
false, |
||||||
|
sourceNamespace, |
||||||
|
sourceClassName, |
||||||
|
fileContent); |
||||||
|
|
||||||
|
ICompilationUnit icu = helper.Parse(ITestClass.FileName, interfaceCode); |
||||||
|
IClass i = icu.Classes[0]; |
||||||
|
|
||||||
|
Assert.That(i.ClassType, Is.EqualTo(ClassType.Interface)); |
||||||
|
Assert.That(i.Name, Is.EqualTo(interfaceName)); |
||||||
|
Assert.That(i.Namespace, Is.EqualTo(c.Namespace)); |
||||||
|
Assert.That(i.Properties.Count, Is.EqualTo(0)); |
||||||
|
Assert.That(i.Methods.Count, Is.EqualTo(1)); |
||||||
|
|
||||||
|
IMethod extractedMethod = i.Methods[0]; |
||||||
|
Assert.That(extractedMethod.Name, Is.EqualTo(originalMethod.Name)); |
||||||
|
Assert.That(extractedMethod, HasEmpty.MethodBody); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void GenerateInterfaceWithStaticMethodsTest() { |
||||||
|
string fileContent = @"
|
||||||
|
using System; |
||||||
|
|
||||||
|
namespace ExtractInterfaceImplicitPropertyTest { |
||||||
|
public class ClassA { |
||||||
|
string myName; |
||||||
|
|
||||||
|
public ClassA() { |
||||||
|
string myName = String.Empty; |
||||||
|
} |
||||||
|
|
||||||
|
public string GetName() { |
||||||
|
return myName; |
||||||
|
} |
||||||
|
|
||||||
|
static public int GetNumber() { |
||||||
|
return -4; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
";
|
||||||
|
IList<IMember> membersToExtract = new List<IMember>(); |
||||||
|
|
||||||
|
ICompilationUnit cu = helper.Parse(TestClass.FileName, fileContent); |
||||||
|
IClass c = cu.Classes[0]; |
||||||
|
|
||||||
|
IMethod originalMethod = c.Methods[1]; // GetName()
|
||||||
|
membersToExtract.Add(originalMethod); |
||||||
|
IMethod originalStaticMethod = c.Methods[2]; // GetNumber()
|
||||||
|
membersToExtract.Add(originalStaticMethod); |
||||||
|
|
||||||
|
string interfaceName = "IClassA"; |
||||||
|
string sourceClassName = c.Name; |
||||||
|
string sourceNamespace = c.Namespace; |
||||||
|
|
||||||
|
string interfaceCode = csharpRefactoringProvider.GenerateInterfaceForClass(interfaceName, |
||||||
|
membersToExtract, |
||||||
|
false, |
||||||
|
sourceNamespace, |
||||||
|
sourceClassName, |
||||||
|
fileContent); |
||||||
|
|
||||||
|
ICompilationUnit icu = helper.Parse(ITestClass.FileName, interfaceCode); |
||||||
|
IClass i = icu.Classes[0]; |
||||||
|
|
||||||
|
Assert.That(i.ClassType, Is.EqualTo(ClassType.Interface)); |
||||||
|
Assert.That(i.Name, Is.EqualTo(interfaceName)); |
||||||
|
Assert.That(i.Namespace, Is.EqualTo(c.Namespace)); |
||||||
|
Assert.That(i.Properties.Count, Is.EqualTo(0)); |
||||||
|
Assert.That(i.Methods.Count, Is.EqualTo(1)); |
||||||
|
|
||||||
|
IMethod extractedMethod = i.Methods[0]; |
||||||
|
Assert.That(extractedMethod.Name, Is.EqualTo(originalMethod.Name)); |
||||||
|
Assert.That(extractedMethod, HasEmpty.MethodBody); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region FindUnusedUsingDeclarations
|
||||||
|
|
||||||
|
[Test] |
||||||
|
public void FindUnusedUsingDeclarationsTest() |
||||||
|
{ |
||||||
|
string fileName = "a.cs"; |
||||||
|
string fileContent = @"
|
||||||
|
using System; |
||||||
|
using System.Collections; |
||||||
|
using System.Collections.Generic; |
||||||
|
|
||||||
|
namespace UnusedUsingDeclarationsTest { |
||||||
|
public class A { |
||||||
|
public A() { |
||||||
|
string testString = String.Empty; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
";
|
||||||
|
ICompilationUnit cu = helper.Parse(TestClass.FileName, fileContent); |
||||||
|
IList<IUsing> unusedUsings = csharpRefactoringProvider.FindUnusedUsingDeclarations(null, fileName, fileContent, cu); |
||||||
|
Assert.That(unusedUsings.Count, Is.EqualTo(2)); |
||||||
|
Assert.That(unusedUsings[0].Usings.Count, Is.EqualTo(1)); |
||||||
|
Assert.That(unusedUsings[0].Usings[0], Is.EqualTo("System.Collections")); |
||||||
|
Assert.That(unusedUsings[1].Usings.Count, Is.EqualTo(1)); |
||||||
|
Assert.That(unusedUsings[1].Usings[0], Is.EqualTo("System.Collections.Generic")); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void NoUnusedUsingDeclarationsToFindTest() |
||||||
|
{ |
||||||
|
string fileName = "a.cs"; |
||||||
|
string fileContent = @"
|
||||||
|
using System; |
||||||
|
|
||||||
|
namespace UnusedUsingDeclarationsTest { |
||||||
|
public class A { |
||||||
|
public A() { |
||||||
|
string testString = String.Empty; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
";
|
||||||
|
ICompilationUnit cu = helper.Parse(fileName, fileContent); |
||||||
|
IList<IUsing> unusedUsings = csharpRefactoringProvider.FindUnusedUsingDeclarations(null, fileName, fileContent, cu); |
||||||
|
Assert.That(unusedUsings.Count, Is.EqualTo(0)); |
||||||
|
} |
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Test-specific setup/tear down
|
||||||
|
|
||||||
|
[SetUp] |
||||||
|
public void TestInit() |
||||||
|
{ |
||||||
|
// TODO: Add Test-specific Init code.
|
||||||
|
} |
||||||
|
|
||||||
|
[TearDown] |
||||||
|
public void TestDispose() |
||||||
|
{ |
||||||
|
// TODO: Add Test-specific tear down code.
|
||||||
|
} |
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Fixture setup/tear down
|
||||||
|
|
||||||
|
[TestFixtureSetUp] |
||||||
|
public void Init() |
||||||
|
{ |
||||||
|
helper = new NRefactoryResolverTests(); |
||||||
|
csharpRefactoringProvider = NRefactoryRefactoringProvider.NRefactoryCSharpProviderInstance; |
||||||
|
vbnetRefactoringProvider = NRefactoryRefactoringProvider.NRefactoryVBNetProviderInstance; |
||||||
|
} |
||||||
|
|
||||||
|
[TestFixtureTearDown] |
||||||
|
public void Dispose() |
||||||
|
{ |
||||||
|
// TODO: Add Fixture tear down code.
|
||||||
|
} |
||||||
|
#endregion
|
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,99 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="David Alpert" email="david@spinthemoose.com"/>
|
||||||
|
// <version>$Revision: $</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
|
||||||
|
using ICSharpCode.SharpDevelop.Dom; |
||||||
|
|
||||||
|
namespace NUnit.Framework.Constraints |
||||||
|
{ |
||||||
|
#region IProperty constraints
|
||||||
|
/// <summary>
|
||||||
|
/// Abstract NUnit Constraint to refactor the test for
|
||||||
|
/// emptiness of an IProperty's get or set accessor region.
|
||||||
|
/// </summary>
|
||||||
|
public abstract class PropertyAccessorIsEmptyConstraint : NUnit.Framework.Constraints.Constraint |
||||||
|
{ |
||||||
|
protected IProperty p; |
||||||
|
protected abstract string accessorText {get;} |
||||||
|
protected abstract DomRegion RegionToTest {get;} |
||||||
|
|
||||||
|
public override bool Matches(object actual) |
||||||
|
{ |
||||||
|
this.actual = actual; |
||||||
|
this.p = actual as IProperty; |
||||||
|
if (actual is IProperty) { |
||||||
|
// test to ensure that the DomRegion encapsulates either "get;" or "set;"
|
||||||
|
return AccessorDomRegionIsEmpty(this.RegionToTest); |
||||||
|
} |
||||||
|
// not an IProperty
|
||||||
|
return false; |
||||||
|
} |
||||||
|
|
||||||
|
public bool AccessorDomRegionIsEmpty(DomRegion region) { |
||||||
|
return region.EndLine == region.BeginLine |
||||||
|
&& region.EndColumn - region.BeginColumn == 4; |
||||||
|
} |
||||||
|
|
||||||
|
public override void WriteMessageTo(MessageWriter writer) { |
||||||
|
if (this.actual is IProperty) { |
||||||
|
writer.WriteMessageLine("Expected {0} to have an empty {1} accessor but it was not empty {2}.", this.actual, this.accessorText, this.RegionToTest); |
||||||
|
} else { |
||||||
|
writer.WriteMessageLine("{0} is not an IProperty; cannot test for the emptiness of a {1} accessor.", this.actual, this.accessorText); |
||||||
|
} |
||||||
|
} |
||||||
|
public override void WriteDescriptionTo(MessageWriter writer) |
||||||
|
{ |
||||||
|
writer.WritePredicate(String.Format("An IProperty with an empty {0} region", this.accessorText)); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public class PropertyGetIsEmptyConstraint : PropertyAccessorIsEmptyConstraint |
||||||
|
{ |
||||||
|
protected override string accessorText { get { return "get"; } } |
||||||
|
protected override DomRegion RegionToTest { get { return this.p.GetterRegion; } } |
||||||
|
} |
||||||
|
|
||||||
|
public class PropertySetIsEmptyConstraint : PropertyAccessorIsEmptyConstraint |
||||||
|
{ |
||||||
|
protected override string accessorText { get { return "set"; } } |
||||||
|
protected override DomRegion RegionToTest { get { return this.p.SetterRegion; } } |
||||||
|
} |
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region IMethod Constraints
|
||||||
|
|
||||||
|
public class MethodBodyIsEmptyConstraint : NUnit.Framework.Constraints.Constraint |
||||||
|
{ |
||||||
|
IMethod m; |
||||||
|
public override bool Matches(object actual) |
||||||
|
{ |
||||||
|
this.actual = actual; |
||||||
|
this.m = actual as IMethod; |
||||||
|
if (this.m == null) { |
||||||
|
return false; |
||||||
|
} |
||||||
|
return m.BodyRegion.EndLine == 0 && m.BodyRegion.EndColumn == 0; |
||||||
|
} |
||||||
|
public override void WriteMessageTo(MessageWriter writer) |
||||||
|
{ |
||||||
|
if (this.actual is IMethod) { |
||||||
|
writer.WriteMessageLine("Expected {0} to have an empty BodyRegion but it was not empty {1}.", this.m, this.m.BodyRegion); |
||||||
|
} else { |
||||||
|
writer.WriteMessageLine("{0} is not an IMethod; cannot test for the emptiness of a it's BodyRegion.", this.actual); |
||||||
|
} |
||||||
|
} |
||||||
|
public override void WriteDescriptionTo(MessageWriter writer) |
||||||
|
{ |
||||||
|
writer.WritePredicate("A method with an empty BodyRegion"); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
} |
||||||
@ -0,0 +1,27 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="David Alpert" email="david@spinthemoose.com"/>
|
||||||
|
// <version>$Revision: $</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using NUnit.Framework.Constraints; |
||||||
|
|
||||||
|
namespace NUnit.Framework.SyntaxHelpers |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Syntax helper class that generates custom constraints to test ICSharpCode.SharpDevelop.Dom objects
|
||||||
|
/// </summary>
|
||||||
|
public class HasEmpty { |
||||||
|
public static PropertyGetIsEmptyConstraint GetRegion { |
||||||
|
get { return new PropertyGetIsEmptyConstraint(); } |
||||||
|
} |
||||||
|
public static PropertySetIsEmptyConstraint SetRegion { |
||||||
|
get { return new PropertySetIsEmptyConstraint(); } |
||||||
|
} |
||||||
|
public static MethodBodyIsEmptyConstraint MethodBody { |
||||||
|
get { return new MethodBodyIsEmptyConstraint(); } |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
Binary file not shown.
Loading…
Reference in new issue