Browse Source
git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@5402 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61pull/1/head
37 changed files with 772 additions and 1659 deletions
@ -0,0 +1,52 @@
@@ -0,0 +1,52 @@
|
||||
<gui:AbstractInlineRefactorDialog x:Class="SharpRefactoring.Gui.InsertCtorDialog" |
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
||||
xmlns:gui="clr-namespace:SharpRefactoring.Gui" |
||||
xmlns:addin="clr-namespace:SharpRefactoring" |
||||
xmlns:sd="http://icsharpcode.net/sharpdevelop/core" |
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> |
||||
<DockPanel Cursor="Arrow"> |
||||
<TextBlock DockPanel.Dock="Top" Margin="3" |
||||
Text="{sd:Localize AddIns.SharpRefactoring.InsertCtor.Description}" |
||||
TextWrapping="Wrap" /> |
||||
<DockPanel DockPanel.Dock="Bottom" LastChildFill="False"> |
||||
<Button DockPanel.Dock="Left" Content="{sd:Localize Global.OKButtonText}" Margin="3" Click="OKButtonClick" /> |
||||
<Button DockPanel.Dock="Left" Content="{sd:Localize Global.CancelButtonText}" Margin="3" Click="CancelButtonClick" /> |
||||
<Button DockPanel.Dock="Right" Content="Down" Margin="3" Click="DownClick" /> |
||||
<Button DockPanel.Dock="Right" Content="Up" Margin="3" Click="UpClick" /> |
||||
</DockPanel> |
||||
<ListView x:Name="varList"> |
||||
<ListView.View> |
||||
<GridView> |
||||
<GridViewColumn Header="Variable"> |
||||
<GridViewColumn.CellTemplate> |
||||
<DataTemplate> |
||||
<CheckBox Content="{Binding Text}" IsChecked="{Binding IsSelected, Mode=TwoWay}" /> |
||||
</DataTemplate> |
||||
</GridViewColumn.CellTemplate> |
||||
</GridViewColumn> |
||||
<GridViewColumn Header="Add check for null"> |
||||
<GridViewColumn.CellTemplate> |
||||
<DataTemplate> |
||||
<CheckBox IsChecked="{Binding AddCheckForNull, Mode=TwoWay}" IsEnabled="{Binding IsNullable}" /> |
||||
</DataTemplate> |
||||
</GridViewColumn.CellTemplate> |
||||
</GridViewColumn> |
||||
<GridViewColumn Header="Add range check"> |
||||
<GridViewColumn.CellTemplate> |
||||
<DataTemplate> |
||||
<Grid> |
||||
<Grid.ColumnDefinitions> |
||||
<ColumnDefinition Width="*" /> |
||||
<ColumnDefinition Width="*" /> |
||||
</Grid.ColumnDefinitions> |
||||
<TextBox Margin="3,0" Text="{Binding LowerBound, Mode=TwoWay}" IsEnabled="{Binding HasRange}" /> |
||||
<TextBox Margin="3,0" Grid.Column="1" Text="{Binding UpperBound, Mode=TwoWay}" IsEnabled="{Binding HasRange}" /> |
||||
</Grid> |
||||
</DataTemplate> |
||||
</GridViewColumn.CellTemplate> |
||||
</GridViewColumn> |
||||
</GridView> |
||||
</ListView.View> |
||||
</ListView> |
||||
</DockPanel> |
||||
</gui:AbstractInlineRefactorDialog> |
||||
@ -0,0 +1,207 @@
@@ -0,0 +1,207 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Siegfried Pammer" email="siegfriedpammer@gmail.com" />
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Globalization; |
||||
using System.Linq; |
||||
using System.Text; |
||||
|
||||
using ICSharpCode.NRefactory.Ast; |
||||
using ICSharpCode.SharpDevelop.Dom; |
||||
using ICSharpCode.SharpDevelop.Dom.Refactoring; |
||||
using ICSharpCode.SharpDevelop.Editor; |
||||
|
||||
namespace SharpRefactoring.Gui |
||||
{ |
||||
/// <summary>
|
||||
/// Interaction logic for InsertCtorDialog.xaml
|
||||
/// </summary>
|
||||
public partial class InsertCtorDialog : AbstractInlineRefactorDialog |
||||
{ |
||||
IList<CtorParamWrapper> paramList; |
||||
|
||||
public InsertCtorDialog(ITextEditor editor, ITextAnchor anchor, IClass current) |
||||
: base(editor, anchor) |
||||
{ |
||||
InitializeComponent(); |
||||
|
||||
this.varList.ItemsSource = paramList = CreateCtorParams(current.Fields).ToList(); |
||||
} |
||||
|
||||
IEnumerable<CtorParamWrapper> CreateCtorParams(IEnumerable<IField> fields) |
||||
{ |
||||
int i = 0; |
||||
|
||||
foreach (IField f in fields) { |
||||
yield return new CtorParamWrapper(f) { Index = i }; |
||||
i++; |
||||
} |
||||
} |
||||
|
||||
protected override string GenerateCode(CodeGenerator generator, IClass currentClass) |
||||
{ |
||||
StringBuilder builder = new StringBuilder(); |
||||
|
||||
var line = editor.Document.GetLineForOffset(editor.Caret.Offset); |
||||
|
||||
string indent = DocumentUtilitites.GetWhitespaceAfter(editor.Document, line.Offset); |
||||
|
||||
var filtered = paramList.Where(p => p.IsSelected).OrderBy(p => p.Index).ToList(); |
||||
|
||||
BlockStatement block = new BlockStatement(); |
||||
|
||||
foreach (CtorParamWrapper w in filtered) { |
||||
if (w.AddCheckForNull) { |
||||
if (w.Type.IsReferenceType == true) |
||||
block.AddChild( |
||||
new IfElseStatement( |
||||
new BinaryOperatorExpression(new IdentifierExpression(w.Name), BinaryOperatorType.Equality, new PrimitiveExpression(null)), |
||||
new ThrowStatement(new ObjectCreateExpression(new TypeReference("ArgumentNullException"), new List<Expression>() { new PrimitiveExpression(w.Name, '"' + w.Name + '"') })) |
||||
) |
||||
); |
||||
else |
||||
block.AddChild( |
||||
new IfElseStatement( |
||||
new UnaryOperatorExpression(new MemberReferenceExpression(new IdentifierExpression(w.Name), "HasValue"), UnaryOperatorType.Not), |
||||
new ThrowStatement(new ObjectCreateExpression(new TypeReference("ArgumentNullException"), new List<Expression>() { new PrimitiveExpression(w.Name, '"' + w.Name + '"') })) |
||||
) |
||||
); |
||||
} |
||||
if (!string.IsNullOrWhiteSpace(w.UpperBound) && !string.IsNullOrWhiteSpace(w.LowerBound)) { |
||||
double upper, lower; |
||||
if (!double.TryParse(w.UpperBound, out upper)) |
||||
throw new Exception("Upper bound not valid for parameter " + w.Name); |
||||
if (!double.TryParse(w.LowerBound, out lower)) |
||||
throw new Exception("Lower bound not valid for parameter " + w.Name); |
||||
block.AddChild( |
||||
new IfElseStatement( |
||||
new BinaryOperatorExpression( |
||||
new BinaryOperatorExpression(new IdentifierExpression(w.Name), BinaryOperatorType.LessThan, new PrimitiveExpression(lower)), |
||||
BinaryOperatorType.LogicalOr, |
||||
new BinaryOperatorExpression(new IdentifierExpression(w.Name), BinaryOperatorType.GreaterThan, new PrimitiveExpression(upper)) |
||||
), |
||||
new ThrowStatement( |
||||
new ObjectCreateExpression( |
||||
new TypeReference("ArgumentOutOfRangeException"), |
||||
new List<Expression>() { new PrimitiveExpression(w.Name, '"' + w.Name + '"'), new IdentifierExpression(w.Name), new PrimitiveExpression("Value must be between " + lower.ToString(CultureInfo.InvariantCulture) + " and " + upper.ToString(CultureInfo.InvariantCulture)) } |
||||
) |
||||
) |
||||
) |
||||
); |
||||
} |
||||
} |
||||
|
||||
foreach (CtorParamWrapper w in filtered) |
||||
block.AddChild(new ExpressionStatement(new AssignmentExpression(new MemberReferenceExpression(new ThisReferenceExpression(), w.Name), AssignmentOperatorType.Assign, new IdentifierExpression(w.Name)))); |
||||
|
||||
ConstructorDeclaration ctor = new ConstructorDeclaration(currentClass.Name, Modifiers.Public, filtered.Select(p => new ParameterDeclarationExpression(ConvertType(p.Type), p.Name)).ToList(), null) { |
||||
Body = block |
||||
}; |
||||
|
||||
builder.Append(generator.GenerateCode(ctor, indent)); |
||||
|
||||
return builder.ToString(); |
||||
} |
||||
|
||||
void UpClick(object sender, System.Windows.RoutedEventArgs e) |
||||
{ |
||||
int selection = varList.SelectedIndex; |
||||
|
||||
if (selection <= 0) |
||||
return; |
||||
|
||||
var curItem = paramList.First(p => p.Index == selection); |
||||
var exchangeItem = paramList.First(p => p.Index == selection - 1); |
||||
|
||||
curItem.Index = selection - 1; |
||||
exchangeItem.Index = selection; |
||||
|
||||
varList.ItemsSource = paramList.OrderBy(p => p.Index); |
||||
varList.SelectedIndex = selection - 1; |
||||
} |
||||
|
||||
void DownClick(object sender, System.Windows.RoutedEventArgs e) |
||||
{ |
||||
int selection = varList.SelectedIndex; |
||||
|
||||
if (selection >= paramList.Count - 1) |
||||
return; |
||||
|
||||
var curItem = paramList.First(p => p.Index == selection); |
||||
var exchangeItem = paramList.First(p => p.Index == selection + 1); |
||||
|
||||
curItem.Index = selection + 1; |
||||
exchangeItem.Index = selection; |
||||
|
||||
varList.ItemsSource = paramList.OrderBy(p => p.Index); |
||||
varList.SelectedIndex = selection + 1; |
||||
} |
||||
} |
||||
|
||||
public class CtorParamWrapper |
||||
{ |
||||
IField field; |
||||
|
||||
public string Text { |
||||
get { return field.ProjectContent.Language.GetAmbience().Convert(field); } |
||||
} |
||||
|
||||
public bool IsNullable { |
||||
get { |
||||
return field.ReturnType.IsReferenceType == true || |
||||
field.ReturnType.IsConstructedReturnType && field.ReturnType.Name == "Nullable"; |
||||
} |
||||
} |
||||
|
||||
public bool HasRange { |
||||
get { |
||||
return (field.ReturnType.IsConstructedReturnType && |
||||
IsTypeWithRange(field.ReturnType.CastToConstructedReturnType().TypeArguments.First()) |
||||
) || IsTypeWithRange(field.ReturnType); |
||||
} |
||||
} |
||||
|
||||
public int Index { get; set; } |
||||
|
||||
public bool IsSelected { get; set; } |
||||
|
||||
public bool AddCheckForNull { get; set; } |
||||
|
||||
public string LowerBound { get; set; } |
||||
|
||||
public string UpperBound { get; set; } |
||||
|
||||
public string Name { |
||||
get { return field.Name; } |
||||
} |
||||
|
||||
public IReturnType Type { |
||||
get { return field.ReturnType; } |
||||
} |
||||
|
||||
bool IsTypeWithRange(IReturnType type) |
||||
{ |
||||
return type.Name == "Int32" || |
||||
type.Name == "Int16" || |
||||
type.Name == "Int64" || |
||||
type.Name == "Single" || |
||||
type.Name == "Double" || |
||||
type.Name == "UInt16" || |
||||
type.Name == "UInt32" || |
||||
type.Name == "UInt64"; |
||||
} |
||||
|
||||
public CtorParamWrapper(IField field) |
||||
{ |
||||
if (field == null || field.ReturnType == null) |
||||
throw new ArgumentNullException("field"); |
||||
|
||||
this.field = field; |
||||
} |
||||
} |
||||
} |
||||
@ -1,78 +0,0 @@
@@ -1,78 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Siegfried Pammer" email="siegfriedpammer@gmail.com" />
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Linq; |
||||
using System.Windows; |
||||
using System.Windows.Controls; |
||||
|
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.Core.Presentation; |
||||
using ICSharpCode.SharpDevelop.Dom; |
||||
using ICSharpCode.SharpDevelop.Dom.Refactoring; |
||||
using ICSharpCode.SharpDevelop.Editor; |
||||
|
||||
namespace SharpRefactoring.Gui |
||||
{ |
||||
public class OverrideEqualsGetHashCodeMethodsDialog : AbstractInlineRefactorDialog |
||||
{ |
||||
CheckBox addIEquatableCheckBox; |
||||
CheckBox addOperatorOverrides; |
||||
CheckBox implementAllIEquatables; |
||||
|
||||
IClass selectedClass; |
||||
|
||||
public OverrideEqualsGetHashCodeMethodsDialog(ITextEditor editor, ITextAnchor anchor, IClass selectedClass) |
||||
: base(editor, anchor) |
||||
{ |
||||
if (selectedClass == null) |
||||
throw new ArgumentNullException("selectedClass"); |
||||
|
||||
this.selectedClass = selectedClass; |
||||
|
||||
addIEquatableCheckBox.Content = string.Format(StringParser.Parse("${res:AddIns.SharpRefactoring.AddInterface}"), "IEquatable<" + selectedClass.Name + ">"); |
||||
addIEquatableCheckBox.IsEnabled = !selectedClass.BaseTypes.Any(type => { |
||||
if (!type.IsGenericReturnType) |
||||
return false; |
||||
var genericType = type.CastToGenericReturnType(); |
||||
var boundTo = genericType.TypeParameter.BoundTo; |
||||
if (boundTo == null) |
||||
return false; |
||||
return boundTo.Name == selectedClass.Name; |
||||
} |
||||
); |
||||
|
||||
addIEquatableCheckBox.SetValueToExtension(CheckBox.IsCheckedProperty, |
||||
new OptionBinding(typeof(Options), "AddInterface") |
||||
); |
||||
} |
||||
|
||||
protected override UIElement CreateContentElement() |
||||
{ |
||||
addIEquatableCheckBox = new CheckBox(); |
||||
|
||||
StackPanel panel = new StackPanel() { |
||||
Orientation = Orientation.Vertical, |
||||
Children = { |
||||
addIEquatableCheckBox |
||||
} |
||||
}; |
||||
|
||||
return panel; |
||||
} |
||||
|
||||
protected override string GenerateCode(CodeGenerator generator, IClass currentClass) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public interface IInlineRefactoring |
||||
{ |
||||
void GenerateCode(ITextEditor editor); |
||||
} |
||||
} |
||||
@ -0,0 +1,30 @@
@@ -0,0 +1,30 @@
|
||||
<gui:AbstractInlineRefactorDialog x:Class="SharpRefactoring.Gui.OverrideEqualsGetHashCodeMethodsDialog" |
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
||||
xmlns:gui="clr-namespace:SharpRefactoring.Gui" |
||||
xmlns:addin="clr-namespace:SharpRefactoring" |
||||
xmlns:sd="http://icsharpcode.net/sharpdevelop/core" |
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> |
||||
<DockPanel Cursor="Arrow"> |
||||
<TextBlock DockPanel.Dock="Top" Margin="3" |
||||
Text="{sd:Localize AddIns.SharpRefactoring.OverrideEqualsGetHashCodeMethods.Description}" |
||||
TextWrapping="Wrap" /> |
||||
<StackPanel Orientation="Horizontal" DockPanel.Dock="Bottom"> |
||||
<Button Content="{sd:Localize Global.OKButtonText}" Margin="3" Click="OKButtonClick" /> |
||||
<Button Content="{sd:Localize Global.CancelButtonText}" Margin="3" Click="CancelButtonClick" /> |
||||
</StackPanel> |
||||
<StackPanel Orientation="Vertical"> |
||||
<CheckBox |
||||
x:Name="addIEquatable" |
||||
Margin="3" |
||||
IsChecked="{sd:OptionBinding addin:Options.AddIEquatableInterface}" /> |
||||
<CheckBox |
||||
Content="{sd:Localize AddIns.SharpRefactoring.OverrideEqualsGetHashCodeMethods.AddOperatorOverrides}" |
||||
Margin="3" |
||||
IsChecked="{sd:OptionBinding addin:Options.AddOperatorOverrides}" /> |
||||
<CheckBox |
||||
Content="{sd:Localize AddIns.SharpRefactoring.OverrideEqualsGetHashCodeMethods.SurroundWithRegion}" |
||||
Margin="3" |
||||
IsChecked="{sd:OptionBinding addin:Options.SurroundWithRegion}" /> |
||||
</StackPanel> |
||||
</DockPanel> |
||||
</gui:AbstractInlineRefactorDialog> |
||||
@ -1,7 +1,16 @@
@@ -1,7 +1,16 @@
|
||||
<UserControl x:Class="SharpRefactoring.Gui.OverrideToStringMethodDialog" |
||||
<local:AbstractInlineRefactorDialog x:Class="SharpRefactoring.Gui.OverrideToStringMethodDialog" |
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
||||
xmlns:local="clr-namespace:SharpRefactoring.Gui" |
||||
xmlns:sd="http://icsharpcode.net/sharpdevelop/core" |
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> |
||||
<Grid> |
||||
|
||||
</Grid> |
||||
</UserControl> |
||||
<DockPanel Cursor="Arrow"> |
||||
<TextBlock DockPanel.Dock="Top" Margin="3" |
||||
Text="{sd:Localize AddIns.SharpRefactoring.OverrideToStringMethod.Description}" |
||||
TextWrapping="Wrap" /> |
||||
<StackPanel Orientation="Horizontal" DockPanel.Dock="Bottom"> |
||||
<Button Content="{sd:Localize Global.OKButtonText}" Margin="3" Click="OKButtonClick" /> |
||||
<Button Content="{sd:Localize Global.CancelButtonText}" Margin="3" Click="CancelButtonClick" /> |
||||
</StackPanel> |
||||
<ListBox Margin="4" x:Name="listBox" /> |
||||
</DockPanel> |
||||
</local:AbstractInlineRefactorDialog> |
||||
@ -1,119 +0,0 @@
@@ -1,119 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Siegfried Pammer" email="siegfriedpammer@gmail.com" />
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text; |
||||
using System.Windows; |
||||
using System.Windows.Controls; |
||||
using System.Windows.Media; |
||||
|
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.NRefactory.Ast; |
||||
using ICSharpCode.SharpDevelop; |
||||
using ICSharpCode.SharpDevelop.Dom; |
||||
using ICSharpCode.SharpDevelop.Dom.Refactoring; |
||||
using ICSharpCode.SharpDevelop.Editor; |
||||
|
||||
namespace SharpRefactoring.Gui |
||||
{ |
||||
public class OverrideToStringMethodDialogOld : AbstractInlineRefactorDialog |
||||
{ |
||||
ListBox listBox; |
||||
List<Wrapper<IField>> fields; |
||||
|
||||
public OverrideToStringMethodDialogOld(ITextEditor editor, ITextAnchor anchor, IList<IField> fields) |
||||
: base(editor, anchor) |
||||
{ |
||||
this.fields = fields.Select(f => new Wrapper<IField>() { Entity = f }).ToList(); |
||||
this.listBox.ItemsSource = this.fields.Select(i => i.Create(null)); |
||||
} |
||||
|
||||
protected override UIElement CreateContentElement() |
||||
{ |
||||
TextBlock block = new TextBlock() { |
||||
Text = StringParser.Parse("${res:AddIns.SharpRefactoring.OverrideToStringMethod.Description}"), |
||||
Margin = new Thickness(3), |
||||
TextWrapping = TextWrapping.Wrap |
||||
}; |
||||
|
||||
listBox = new ListBox() { |
||||
Margin = new Thickness(3) |
||||
}; |
||||
|
||||
block.SetValue(DockPanel.DockProperty, Dock.Top); |
||||
|
||||
return new DockPanel() { |
||||
Children = { |
||||
block, |
||||
listBox |
||||
} |
||||
}; |
||||
} |
||||
|
||||
protected override string GenerateCode(CodeGenerator generator, IClass currentClass) |
||||
{ |
||||
var fields = this.fields |
||||
.Where(f => f.IsChecked) |
||||
.Select(f2 => f2.Entity.Name) |
||||
.ToArray(); |
||||
|
||||
if (fields.Any()) { |
||||
StringBuilder formatString = new StringBuilder("[" + currentClass.Name + " "); |
||||
|
||||
for (int i = 0; i < fields.Length; i++) { |
||||
if (i != 0) |
||||
formatString.Append(", "); |
||||
formatString.AppendFormat("{0}={{{1}}}", generator.GetPropertyName(fields[i]), i); |
||||
} |
||||
|
||||
formatString.Append("]"); |
||||
|
||||
return "return string.Format(\"" + formatString.ToString() + "\", " + string.Join(", ", fields) + ");"; |
||||
} |
||||
|
||||
return "return string.Format(\"[" + currentClass.Name + "]\");"; |
||||
} |
||||
} |
||||
|
||||
/* List<Wrapper<IField>> checkedItems = new List<Wrapper<IField>>(); |
||||
|
||||
void CheckChange(Wrapper<IField> field) |
||||
{ |
||||
if (field.IsChecked) |
||||
checkedItems.Add(field); |
||||
else |
||||
checkedItems.Remove(field); |
||||
|
||||
string text = string.Join(", ", this.checkedItems.Select(f2 => PrintVariableDeclaration(f2.Entity))); |
||||
|
||||
editor.Document.Replace(parameterListAnchorStart.Offset, parameterListAnchorEnd.Offset - parameterListAnchorStart.Offset, text); |
||||
} |
||||
|
||||
string PrintVariableDeclaration(IField field) |
||||
{ |
||||
if (field.ReturnType == null) |
||||
return "? " + field.Name; |
||||
else { |
||||
TypeReference type = CodeGenerator.ConvertType(field.ReturnType, new ClassFinder(field)); |
||||
return ((type.IsKeyword) ? TypeReference.PrimitiveTypesCSharpReverse[type.Type] : type.Type) + " " + field.Name; |
||||
} |
||||
} |
||||
|
||||
Statement CreateAssignment(string memberName, string parameter) |
||||
{ |
||||
return new ExpressionStatement( |
||||
new AssignmentExpression( |
||||
new MemberReferenceExpression(new ThisReferenceExpression(), memberName), |
||||
AssignmentOperatorType.Assign, |
||||
new IdentifierExpression(parameter) |
||||
) |
||||
); |
||||
} |
||||
*/ |
||||
} |
||||
@ -0,0 +1,49 @@
@@ -0,0 +1,49 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Siegfried Pammer" email="siegfriedpammer@gmail.com" />
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using ICSharpCode.SharpDevelop; |
||||
using ICSharpCode.SharpDevelop.Dom; |
||||
using ICSharpCode.SharpDevelop.Dom.Refactoring; |
||||
using ICSharpCode.SharpDevelop.Editor; |
||||
using ICSharpCode.SharpDevelop.Refactoring; |
||||
using SharpRefactoring.Gui; |
||||
|
||||
namespace SharpRefactoring |
||||
{ |
||||
/// <summary>
|
||||
/// Description of InsertCtorCommand
|
||||
/// </summary>
|
||||
public class InsertCtorCommand : AbstractRefactoringCommand |
||||
{ |
||||
protected override void Run(ITextEditor textEditor, RefactoringProvider provider) |
||||
{ |
||||
IEditorUIService uiService = textEditor.GetService(typeof(IEditorUIService)) as IEditorUIService; |
||||
|
||||
if (uiService == null) |
||||
return; |
||||
|
||||
ParseInformation parseInfo = ParserService.GetParseInformation(textEditor.FileName); |
||||
|
||||
if (parseInfo == null) |
||||
return; |
||||
|
||||
CodeGenerator generator = parseInfo.CompilationUnit.Language.CodeGenerator; |
||||
IClass current = parseInfo.CompilationUnit.GetInnermostClass(textEditor.Caret.Line, textEditor.Caret.Column); |
||||
|
||||
if (current == null) |
||||
return; |
||||
|
||||
ITextAnchor anchor = textEditor.Document.CreateAnchor(textEditor.Caret.Offset); |
||||
anchor.MovementType = AnchorMovementType.AfterInsertion; |
||||
|
||||
AbstractInlineRefactorDialog dialog = new InsertCtorDialog(textEditor, anchor, current); |
||||
|
||||
dialog.Element = uiService.CreateInlineUIElement(anchor, dialog); |
||||
} |
||||
} |
||||
} |
||||
@ -1,65 +0,0 @@
@@ -1,65 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Collections; |
||||
using System.Collections.Generic; |
||||
|
||||
using ICSharpCode.NRefactory.Ast; |
||||
using ICSharpCode.SharpDevelop.Dom; |
||||
using ICSharpCode.SharpDevelop.Dom.Refactoring; |
||||
|
||||
namespace ICSharpCode.SharpDevelop.DefaultEditor.Commands |
||||
{ |
||||
public class AbstractClassImplementorCodeGenerator : InterfaceOrAbstractClassCodeGenerator |
||||
{ |
||||
public override string CategoryName { |
||||
get { |
||||
return "${res:ICSharpCode.SharpDevelop.CodeGenerator.AbstractClass}"; |
||||
} |
||||
} |
||||
|
||||
public override string Hint { |
||||
get { |
||||
return "${res:ICSharpCode.SharpDevelop.CodeGenerator.AbstractClass.Hint}"; |
||||
} |
||||
} |
||||
|
||||
public override void GenerateCode(List<AbstractNode> nodes, IList items) |
||||
{ |
||||
foreach (IProperty property in currentClass.DefaultReturnType.GetProperties()) { |
||||
if (property.IsAbstract) { |
||||
AttributedNode node = CodeGenerator.ConvertMember(property, classFinderContext); |
||||
node.Modifier &= ~(Modifiers.Abstract | Modifiers.Virtual); |
||||
node.Modifier |= Modifiers.Override; |
||||
nodes.Add(node); |
||||
} |
||||
} |
||||
foreach (IMethod method in currentClass.DefaultReturnType.GetMethods()) { |
||||
if (method.IsAbstract) { |
||||
AttributedNode node = CodeGenerator.ConvertMember(method, classFinderContext); |
||||
node.Modifier &= ~(Modifiers.Abstract | Modifiers.Virtual); |
||||
node.Modifier |= Modifiers.Override; |
||||
nodes.Add(node); |
||||
} |
||||
} |
||||
} |
||||
|
||||
protected override void InitContent() |
||||
{ |
||||
if (currentClass.ClassType != ICSharpCode.SharpDevelop.Dom.ClassType.Class) |
||||
return; |
||||
for (int i = 0; i < currentClass.BaseTypes.Count; i++) { |
||||
IReturnType baseType = currentClass.GetBaseType(i); |
||||
IClass baseClass = (baseType != null) ? baseType.GetUnderlyingClass() : null; |
||||
if (baseClass != null && baseClass.ClassType == ICSharpCode.SharpDevelop.Dom.ClassType.Class && baseClass.IsAbstract) { |
||||
Content.Add(new ClassWrapper(baseType)); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
@ -1,45 +0,0 @@
@@ -1,45 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using ICSharpCode.SharpDevelop.Dom; |
||||
|
||||
namespace ICSharpCode.SharpDevelop.DefaultEditor.Commands |
||||
{ |
||||
public abstract class AbstractFieldCodeGenerator : CodeGeneratorBase |
||||
{ |
||||
protected override void InitContent() |
||||
{ |
||||
foreach (IField field in currentClass.Fields) { |
||||
Content.Add(new FieldWrapper(field)); |
||||
} |
||||
} |
||||
|
||||
public class FieldWrapper |
||||
{ |
||||
IField field; |
||||
|
||||
public IField Field { |
||||
get { |
||||
return field; |
||||
} |
||||
} |
||||
|
||||
public FieldWrapper(IField field) |
||||
{ |
||||
this.field = field; |
||||
} |
||||
|
||||
public override string ToString() |
||||
{ |
||||
IAmbience ambience = AmbienceService.GetCurrentAmbience(); |
||||
ambience.ConversionFlags = ConversionFlags.ShowReturnType | ConversionFlags.ShowModifiers; |
||||
return ambience.Convert(field); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
@ -1,20 +0,0 @@
@@ -1,20 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.SharpDevelop.DefaultEditor.Commands |
||||
{ |
||||
public abstract class AbstractPropertyCodeGenerator : AbstractFieldCodeGenerator |
||||
{ |
||||
public override int ImageIndex { |
||||
get { |
||||
return ClassBrowserIconService.Property.ImageIndex; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
@ -1,268 +0,0 @@
@@ -1,268 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Collections; |
||||
using System.Drawing; |
||||
using System.Windows.Forms; |
||||
|
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.SharpDevelop.Dom; |
||||
using ICSharpCode.TextEditor; |
||||
|
||||
namespace ICSharpCode.SharpDevelop.DefaultEditor.Commands |
||||
{ |
||||
public class CodeGenerationForm : Form |
||||
{ |
||||
private System.Windows.Forms.ListView categoryListView; |
||||
private System.Windows.Forms.Label statusLabel; |
||||
private System.Windows.Forms.CheckedListBox selectionListBox; |
||||
|
||||
TextEditorControl textEditorControl; |
||||
|
||||
CodeGeneratorBase SelectedCodeGenerator { |
||||
get { |
||||
if (categoryListView.SelectedItems.Count <= 0) { |
||||
return null; |
||||
} |
||||
return (CodeGeneratorBase)categoryListView.SelectedItems[0].Tag; |
||||
} |
||||
} |
||||
|
||||
public CodeGenerationForm(TextEditorControl textEditorControl, CodeGeneratorBase[] codeGenerators, IClass currentClass) |
||||
{ |
||||
this.textEditorControl = textEditorControl; |
||||
|
||||
foreach (CodeGeneratorBase generator in codeGenerators) { |
||||
generator.Initialize(currentClass); |
||||
} |
||||
|
||||
// Must be called for initialization
|
||||
this.InitializeComponents(); |
||||
|
||||
okButton.Text = ResourceService.GetString("Global.OKButtonText"); |
||||
cancelButton.Text = ResourceService.GetString("Global.CancelButtonText"); |
||||
|
||||
// selectionListBox.Sorted = true;
|
||||
TextLocation caretPos = textEditorControl.ActiveTextAreaControl.Caret.Position; |
||||
TextArea textArea = textEditorControl.ActiveTextAreaControl.TextArea; |
||||
TextView textView = textArea.TextView; |
||||
Point visualPos; |
||||
int physicalline = textView.Document.GetVisibleLine(caretPos.Y); |
||||
visualPos = new Point(textView.GetDrawingXPos(caretPos.Y, caretPos.X) + |
||||
textView.DrawingPosition.X, |
||||
(int)((1 + physicalline) * textView.FontHeight) - |
||||
textArea.VirtualTop.Y - 1 + textView.DrawingPosition.Y); |
||||
|
||||
Point tempLocation = textEditorControl.ActiveTextAreaControl.TextArea.PointToScreen(visualPos); |
||||
tempLocation.Y = (tempLocation.Y + Height) > Screen.FromPoint(tempLocation).WorkingArea.Bottom ? |
||||
Screen.FromPoint(tempLocation).WorkingArea.Bottom - Height : tempLocation.Y; |
||||
tempLocation.X = (tempLocation.X + Width) > Screen.FromPoint(tempLocation).WorkingArea.Right ? |
||||
Screen.FromPoint(tempLocation).WorkingArea.Right - Width : tempLocation.X; |
||||
Location = tempLocation; |
||||
|
||||
StartPosition = FormStartPosition.Manual; |
||||
|
||||
|
||||
categoryListView.SmallImageList = categoryListView.LargeImageList = ClassBrowserIconService.ImageList; |
||||
|
||||
foreach (CodeGeneratorBase codeGenerator in codeGenerators) { |
||||
if (codeGenerator.IsActive) { |
||||
ListViewItem newItem = new ListViewItem(StringParser.Parse(codeGenerator.CategoryName)); |
||||
newItem.ImageIndex = codeGenerator.ImageIndex; |
||||
newItem.Tag = codeGenerator; |
||||
categoryListView.Items.Add(newItem); |
||||
} |
||||
} |
||||
|
||||
categoryListView.SelectedIndexChanged += new EventHandler(CategoryListViewItemChanged); |
||||
} |
||||
protected override void OnActivated(EventArgs e) |
||||
{ |
||||
base.OnActivated(e); |
||||
if (categoryListView.Items.Count > 0) { |
||||
categoryListView.Select(); |
||||
categoryListView.Focus(); |
||||
categoryListView.Items[0].Focused = categoryListView.Items[0].Selected = true; |
||||
} else { |
||||
Close(); |
||||
} |
||||
} |
||||
|
||||
protected override bool ProcessDialogKey(Keys keyData) |
||||
{ |
||||
switch (keyData) { |
||||
case Keys.Escape: |
||||
Close(); |
||||
return true; |
||||
case Keys.Back: |
||||
categoryListView.Focus(); |
||||
return true; |
||||
case Keys.Return: |
||||
if (SelectedCodeGenerator != null) { |
||||
if (categoryListView.Focused && SelectedCodeGenerator.Content.Count > 0) { |
||||
selectionListBox.Focus(); |
||||
} else { |
||||
Close(); |
||||
SelectedCodeGenerator.GenerateCode(textEditorControl.ActiveTextAreaControl.TextArea, selectionListBox.CheckedItems.Count > 0 ? (IList)selectionListBox.CheckedItems : (IList)selectionListBox.SelectedItems); |
||||
} |
||||
return true; |
||||
} else { |
||||
return false; |
||||
} |
||||
} |
||||
return base.ProcessDialogKey(keyData); |
||||
} |
||||
|
||||
void CategoryListViewItemChanged(object sender, EventArgs e) |
||||
{ |
||||
CodeGeneratorBase codeGenerator = SelectedCodeGenerator; |
||||
if (codeGenerator == null) { |
||||
return; |
||||
} |
||||
|
||||
statusLabel.Text = StringParser.Parse(codeGenerator.Hint); |
||||
selectionListBox.BeginUpdate(); |
||||
selectionListBox.Items.Clear(); |
||||
if (codeGenerator.Content.Count > 0) { |
||||
Hashtable objs = new Hashtable(); |
||||
// selectionListBox.Sorted = codeGenerator.Content.Count > 1;
|
||||
foreach (object o in codeGenerator.Content) { |
||||
if (!objs.Contains(o.ToString())) { |
||||
selectionListBox.Items.Add(o); |
||||
objs.Add(o.ToString(), ""); |
||||
} |
||||
} |
||||
selectionListBox.SelectedIndex = 0; |
||||
} |
||||
selectionListBox.EndUpdate(); |
||||
selectionListBox.Refresh(); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// This method was autogenerated - do not change the contents manually
|
||||
/// </summary>
|
||||
private void InitializeComponents() |
||||
{ |
||||
System.Windows.Forms.ColumnHeader columnHeader1; |
||||
System.Windows.Forms.Panel panel1; |
||||
this.okButton = new System.Windows.Forms.Button(); |
||||
this.cancelButton = new System.Windows.Forms.Button(); |
||||
this.selectionListBox = new System.Windows.Forms.CheckedListBox(); |
||||
this.statusLabel = new System.Windows.Forms.Label(); |
||||
this.categoryListView = new System.Windows.Forms.ListView(); |
||||
columnHeader1 = new System.Windows.Forms.ColumnHeader(); |
||||
panel1 = new System.Windows.Forms.Panel(); |
||||
panel1.SuspendLayout(); |
||||
this.SuspendLayout(); |
||||
//
|
||||
// columnHeader1
|
||||
//
|
||||
columnHeader1.Width = 258; |
||||
//
|
||||
// panel1
|
||||
//
|
||||
panel1.BackColor = System.Drawing.SystemColors.Control; |
||||
panel1.Controls.Add(this.okButton); |
||||
panel1.Controls.Add(this.cancelButton); |
||||
panel1.Dock = System.Windows.Forms.DockStyle.Bottom; |
||||
panel1.Location = new System.Drawing.Point(1, 309); |
||||
panel1.Name = "panel1"; |
||||
panel1.Size = new System.Drawing.Size(262, 29); |
||||
panel1.TabIndex = 3; |
||||
//
|
||||
// okButton
|
||||
//
|
||||
this.okButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); |
||||
this.okButton.Location = new System.Drawing.Point(94, 3); |
||||
this.okButton.Name = "okButton"; |
||||
this.okButton.Size = new System.Drawing.Size(75, 23); |
||||
this.okButton.TabIndex = 0; |
||||
this.okButton.Text = "OK"; |
||||
this.okButton.UseCompatibleTextRendering = true; |
||||
this.okButton.UseVisualStyleBackColor = true; |
||||
this.okButton.Click += new System.EventHandler(this.OkButtonClick); |
||||
//
|
||||
// cancelButton
|
||||
//
|
||||
this.cancelButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); |
||||
this.cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel; |
||||
this.cancelButton.Location = new System.Drawing.Point(175, 3); |
||||
this.cancelButton.Name = "cancelButton"; |
||||
this.cancelButton.Size = new System.Drawing.Size(75, 23); |
||||
this.cancelButton.TabIndex = 1; |
||||
this.cancelButton.Text = "Cancel"; |
||||
this.cancelButton.UseCompatibleTextRendering = true; |
||||
this.cancelButton.UseVisualStyleBackColor = true; |
||||
this.cancelButton.Click += new System.EventHandler(this.CancelButtonClick); |
||||
//
|
||||
// selectionListBox
|
||||
//
|
||||
this.selectionListBox.Dock = System.Windows.Forms.DockStyle.Fill; |
||||
this.selectionListBox.IntegralHeight = false; |
||||
this.selectionListBox.Location = new System.Drawing.Point(1, 129); |
||||
this.selectionListBox.Name = "selectionListBox"; |
||||
this.selectionListBox.Size = new System.Drawing.Size(262, 180); |
||||
this.selectionListBox.TabIndex = 2; |
||||
this.selectionListBox.UseCompatibleTextRendering = true; |
||||
//
|
||||
// statusLabel
|
||||
//
|
||||
this.statusLabel.BackColor = System.Drawing.SystemColors.Control; |
||||
this.statusLabel.Dock = System.Windows.Forms.DockStyle.Top; |
||||
this.statusLabel.Location = new System.Drawing.Point(1, 113); |
||||
this.statusLabel.Name = "statusLabel"; |
||||
this.statusLabel.Size = new System.Drawing.Size(262, 16); |
||||
this.statusLabel.TabIndex = 1; |
||||
this.statusLabel.Text = "statusLabel"; |
||||
this.statusLabel.UseCompatibleTextRendering = true; |
||||
//
|
||||
// categoryListView
|
||||
//
|
||||
this.categoryListView.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { |
||||
columnHeader1}); |
||||
this.categoryListView.Dock = System.Windows.Forms.DockStyle.Top; |
||||
this.categoryListView.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.None; |
||||
this.categoryListView.Location = new System.Drawing.Point(1, 1); |
||||
this.categoryListView.MultiSelect = false; |
||||
this.categoryListView.Name = "categoryListView"; |
||||
this.categoryListView.Size = new System.Drawing.Size(262, 112); |
||||
this.categoryListView.TabIndex = 0; |
||||
this.categoryListView.UseCompatibleStateImageBehavior = false; |
||||
this.categoryListView.View = System.Windows.Forms.View.Details; |
||||
//
|
||||
// CodeGenerationForm
|
||||
//
|
||||
this.AcceptButton = this.okButton; |
||||
this.BackColor = System.Drawing.SystemColors.ControlDarkDark; |
||||
this.CancelButton = this.cancelButton; |
||||
this.ClientSize = new System.Drawing.Size(264, 339); |
||||
this.Controls.Add(this.selectionListBox); |
||||
this.Controls.Add(this.statusLabel); |
||||
this.Controls.Add(this.categoryListView); |
||||
this.Controls.Add(panel1); |
||||
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; |
||||
this.Name = "CodeGenerationForm"; |
||||
this.Padding = new System.Windows.Forms.Padding(1); |
||||
this.ShowInTaskbar = false; |
||||
panel1.ResumeLayout(false); |
||||
this.ResumeLayout(false); |
||||
} |
||||
private System.Windows.Forms.Button cancelButton; |
||||
private System.Windows.Forms.Button okButton; |
||||
|
||||
void CancelButtonClick(object sender, EventArgs e) |
||||
{ |
||||
ProcessDialogKey(Keys.Escape); |
||||
} |
||||
|
||||
void OkButtonClick(object sender, EventArgs e) |
||||
{ |
||||
ProcessDialogKey(Keys.Return); |
||||
} |
||||
} |
||||
} |
||||
@ -1,98 +0,0 @@
@@ -1,98 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using ICSharpCode.SharpDevelop.Editor; |
||||
using System; |
||||
using System.Collections; |
||||
using System.Collections.Generic; |
||||
using ICSharpCode.NRefactory.Ast; |
||||
using ICSharpCode.SharpDevelop.Dom; |
||||
using ICSharpCode.SharpDevelop.Dom.Refactoring; |
||||
using ICSharpCode.SharpDevelop.Refactoring; |
||||
using ICSharpCode.TextEditor; |
||||
|
||||
namespace ICSharpCode.SharpDevelop.DefaultEditor.Commands |
||||
{ |
||||
public abstract class CodeGeneratorBase |
||||
{ |
||||
ArrayList content = new ArrayList(); |
||||
|
||||
protected ICSharpCode.SharpDevelop.Dom.Refactoring.CodeGenerator codeGen; |
||||
protected ClassFinder classFinderContext; |
||||
|
||||
// This is the compound class created from the class selected
|
||||
// when the code generator was created.
|
||||
protected IClass currentClass; |
||||
|
||||
// This is class that was selected when the code generator was
|
||||
// created and will be the class that the generated code is inserted
|
||||
// into.
|
||||
IClass selectedClass; |
||||
|
||||
public void Initialize(IClass currentClass) |
||||
{ |
||||
selectedClass = currentClass; |
||||
this.currentClass = currentClass.GetCompoundClass(); |
||||
this.codeGen = currentClass.ProjectContent.Language.CodeGenerator; |
||||
this.classFinderContext = new ClassFinder(currentClass, currentClass.Region.BeginLine + 1, 0); |
||||
this.InitContent(); |
||||
} |
||||
|
||||
protected virtual void InitContent() |
||||
{ |
||||
} |
||||
|
||||
public abstract string CategoryName { |
||||
get; |
||||
} |
||||
|
||||
public virtual string Hint { |
||||
get { |
||||
return "no hint"; |
||||
} |
||||
} |
||||
|
||||
public abstract int ImageIndex { |
||||
get; |
||||
} |
||||
|
||||
public virtual bool IsActive { |
||||
get { |
||||
return content.Count > 0; |
||||
} |
||||
} |
||||
|
||||
public ArrayList Content { |
||||
get { |
||||
return content; |
||||
} |
||||
} |
||||
|
||||
protected TypeReference ConvertType(IReturnType type) |
||||
{ |
||||
return CodeGenerator.ConvertType(type, classFinderContext); |
||||
} |
||||
|
||||
public virtual void GenerateCode(IDocument document) |
||||
{ |
||||
List<AbstractNode> nodes = new List<AbstractNode>(); |
||||
GenerateCode(nodes, this.Content); |
||||
codeGen.InsertCodeInClass(selectedClass, new RefactoringDocumentAdapter(document), selectedClass.Region.EndLine - 1, nodes.ToArray()); |
||||
ParserService.ParseCurrentViewContent(); |
||||
} |
||||
|
||||
public virtual void GenerateCode(TextArea textArea, IList items) |
||||
{ |
||||
List<AbstractNode> nodes = new List<AbstractNode>(); |
||||
GenerateCode(nodes, items); |
||||
codeGen.InsertCodeInClass(selectedClass, new RefactoringDocumentAdapter(new TextEditorDocument(textArea.Document)), textArea.Caret.Line, nodes.ToArray()); |
||||
ParserService.ParseCurrentViewContent(); |
||||
} |
||||
|
||||
public abstract void GenerateCode(List<AbstractNode> nodes, IList items); |
||||
} |
||||
} |
||||
@ -1,61 +0,0 @@
@@ -1,61 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using ICSharpCode.SharpDevelop.Dom; |
||||
using System; |
||||
using System.Collections; |
||||
using System.Collections.Generic; |
||||
using ICSharpCode.NRefactory.Ast; |
||||
|
||||
namespace ICSharpCode.SharpDevelop.DefaultEditor.Commands |
||||
{ |
||||
public class ConstructorCodeGenerator : AbstractFieldCodeGenerator |
||||
{ |
||||
public override string CategoryName { |
||||
get { |
||||
return "${res:ICSharpCode.SharpDevelop.CodeGenerator.Constructor}"; |
||||
} |
||||
} |
||||
|
||||
public override string Hint { |
||||
get { |
||||
return "${res:ICSharpCode.SharpDevelop.CodeGenerator.Constructor.Hint}"; |
||||
} |
||||
} |
||||
|
||||
public override int ImageIndex { |
||||
get { |
||||
return ClassBrowserIconService.Method.ImageIndex; |
||||
} |
||||
} |
||||
|
||||
public override void GenerateCode(List<AbstractNode> nodes, IList items) |
||||
{ |
||||
ConstructorDeclaration ctor = new ConstructorDeclaration(currentClass.Name, Modifiers.Public, null, null); |
||||
ctor.Body = new BlockStatement(); |
||||
foreach (FieldWrapper w in items) { |
||||
string parameterName = codeGen.GetParameterName(w.Field.Name); |
||||
ctor.Parameters.Add(new ParameterDeclarationExpression(ConvertType(w.Field.ReturnType), |
||||
parameterName)); |
||||
Expression left = new MemberReferenceExpression(new ThisReferenceExpression(), w.Field.Name); |
||||
Expression right = new IdentifierExpression(parameterName); |
||||
Expression expr = new AssignmentExpression(left, AssignmentOperatorType.Assign, right); |
||||
ctor.Body.AddChild(new ExpressionStatement(expr)); |
||||
} |
||||
nodes.Add(ctor); |
||||
} |
||||
|
||||
protected override void InitContent() |
||||
{ |
||||
foreach (IField field in currentClass.Fields) { |
||||
if (!field.IsStatic) { |
||||
Content.Add(new FieldWrapper(field)); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
@ -1,37 +0,0 @@
@@ -1,37 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Collections; |
||||
using System.Collections.Generic; |
||||
|
||||
using ICSharpCode.NRefactory.Ast; |
||||
|
||||
namespace ICSharpCode.SharpDevelop.DefaultEditor.Commands |
||||
{ |
||||
public class GetterAndSetterCodeGenerator : AbstractPropertyCodeGenerator |
||||
{ |
||||
public override string CategoryName { |
||||
get { |
||||
return "${res:ICSharpCode.SharpDevelop.CodeGenerator.GetterAndSetter}"; |
||||
} |
||||
} |
||||
|
||||
public override string Hint { |
||||
get { |
||||
return "${res:ICSharpCode.SharpDevelop.CodeGenerator.GetterAndSetter.Hint}"; |
||||
} |
||||
} |
||||
|
||||
public override void GenerateCode(List<AbstractNode> nodes, IList items) |
||||
{ |
||||
foreach (FieldWrapper w in items) { |
||||
nodes.Add(codeGen.CreateProperty(w.Field, true, true)); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
@ -1,36 +0,0 @@
@@ -1,36 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Collections; |
||||
using System.Collections.Generic; |
||||
using ICSharpCode.NRefactory.Ast; |
||||
|
||||
namespace ICSharpCode.SharpDevelop.DefaultEditor.Commands |
||||
{ |
||||
public class GetterCodeGenerator : AbstractPropertyCodeGenerator |
||||
{ |
||||
public override string CategoryName { |
||||
get { |
||||
return "${res:ICSharpCode.SharpDevelop.CodeGenerator.Getter}"; |
||||
} |
||||
} |
||||
|
||||
public override string Hint { |
||||
get { |
||||
return "${res:ICSharpCode.SharpDevelop.CodeGenerator.Getter.Hint}"; |
||||
} |
||||
} |
||||
|
||||
public override void GenerateCode(List<AbstractNode> nodes, IList items) |
||||
{ |
||||
foreach (FieldWrapper w in items) { |
||||
nodes.Add(codeGen.CreateProperty(w.Field, true, false)); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
@ -1,81 +0,0 @@
@@ -1,81 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Collections; |
||||
using System.Collections.Generic; |
||||
|
||||
using ICSharpCode.SharpDevelop.Dom; |
||||
using ICSharpCode.NRefactory.Ast; |
||||
|
||||
namespace ICSharpCode.SharpDevelop.DefaultEditor.Commands |
||||
{ |
||||
public abstract class InterfaceOrAbstractClassCodeGenerator : CodeGeneratorBase |
||||
{ |
||||
public override int ImageIndex { |
||||
get { |
||||
return ClassBrowserIconService.Interface.ImageIndex; |
||||
} |
||||
} |
||||
|
||||
protected class ClassWrapper |
||||
{ |
||||
IReturnType c; |
||||
public IReturnType ClassType { |
||||
get { |
||||
return c; |
||||
} |
||||
} |
||||
public ClassWrapper(IReturnType c) |
||||
{ |
||||
this.c = c; |
||||
} |
||||
|
||||
public override string ToString() |
||||
{ |
||||
IAmbience ambience = AmbienceService.GetCurrentAmbience(); |
||||
ambience.ConversionFlags = ConversionFlags.ShowTypeParameterList; |
||||
return ambience.Convert(c); |
||||
} |
||||
} |
||||
} |
||||
|
||||
public class InterfaceImplementorCodeGenerator : InterfaceOrAbstractClassCodeGenerator |
||||
{ |
||||
public override string CategoryName { |
||||
get { |
||||
return "${res:ICSharpCode.SharpDevelop.CodeGenerator.ImplementInterface}"; |
||||
} |
||||
} |
||||
|
||||
public override string Hint { |
||||
get { |
||||
return "${res:ICSharpCode.SharpDevelop.CodeGenerator.ImplementInterface.Hint}"; |
||||
} |
||||
} |
||||
|
||||
public override void GenerateCode(List<AbstractNode> nodes, IList items) |
||||
{ |
||||
foreach (ClassWrapper w in items) { |
||||
codeGen.ImplementInterface(nodes, w.ClassType, |
||||
!currentClass.ProjectContent.Language.SupportsImplicitInterfaceImplementation, |
||||
currentClass); |
||||
} |
||||
} |
||||
|
||||
protected override void InitContent() |
||||
{ |
||||
for (int i = 0; i < currentClass.BaseTypes.Count; i++) { |
||||
IReturnType baseType = currentClass.GetBaseType(i); |
||||
IClass baseClass = (baseType != null) ? baseType.GetUnderlyingClass() : null; |
||||
if (baseClass != null && baseClass.ClassType == ICSharpCode.SharpDevelop.Dom.ClassType.Interface) { |
||||
Content.Add(new ClassWrapper(baseType)); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
@ -1,72 +0,0 @@
@@ -1,72 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Collections; |
||||
using System.Collections.Generic; |
||||
|
||||
using ICSharpCode.SharpDevelop.Dom; |
||||
using ICSharpCode.NRefactory.Ast; |
||||
|
||||
namespace ICSharpCode.SharpDevelop.DefaultEditor.Commands |
||||
{ |
||||
public class OnXXXMethodsCodeGenerator : CodeGeneratorBase |
||||
{ |
||||
public override string CategoryName { |
||||
get { |
||||
return "${res:ICSharpCode.SharpDevelop.CodeGenerator.EventOnXXX}"; |
||||
} |
||||
} |
||||
|
||||
public override string Hint { |
||||
get { |
||||
return "${res:ICSharpCode.SharpDevelop.CodeGenerator.EventOnXXX.Hint}"; |
||||
} |
||||
} |
||||
|
||||
public override int ImageIndex { |
||||
get { |
||||
return ClassBrowserIconService.Event.ImageIndex; |
||||
} |
||||
} |
||||
|
||||
protected override void InitContent() |
||||
{ |
||||
foreach (IEvent evt in currentClass.Events) { |
||||
Content.Add(new EventWrapper(evt)); |
||||
} |
||||
} |
||||
|
||||
public override void GenerateCode(List<AbstractNode> nodes, IList items) |
||||
{ |
||||
foreach (EventWrapper ev in items) { |
||||
nodes.Add(codeGen.CreateOnEventMethod(ev.Event)); |
||||
} |
||||
} |
||||
|
||||
class EventWrapper |
||||
{ |
||||
IEvent evt; |
||||
public IEvent Event { |
||||
get { |
||||
return evt; |
||||
} |
||||
} |
||||
public EventWrapper(IEvent evt) |
||||
{ |
||||
this.evt = evt; |
||||
} |
||||
|
||||
public override string ToString() |
||||
{ |
||||
IAmbience ambience = AmbienceService.GetCurrentAmbience(); |
||||
ambience.ConversionFlags = ConversionFlags.None; |
||||
return ambience.Convert(evt); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
@ -1,100 +0,0 @@
@@ -1,100 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using ICSharpCode.SharpDevelop.Editor.CodeCompletion; |
||||
using System; |
||||
using System.Collections; |
||||
using System.Collections.Generic; |
||||
using ICSharpCode.NRefactory.Ast; |
||||
using ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor; |
||||
using ICSharpCode.SharpDevelop.Dom; |
||||
using ICSharpCode.SharpDevelop.Editor; |
||||
|
||||
namespace ICSharpCode.SharpDevelop.DefaultEditor.Commands |
||||
{ |
||||
public class OverrideMethodsCodeGenerator : CodeGeneratorBase |
||||
{ |
||||
public override string CategoryName { |
||||
get { |
||||
return "${res:ICSharpCode.SharpDevelop.CodeGenerator.OverrideMethods}"; |
||||
} |
||||
} |
||||
|
||||
public override string Hint { |
||||
get { |
||||
return "${res:ICSharpCode.SharpDevelop.CodeGenerator.OverrideMethods.Hint}"; |
||||
} |
||||
} |
||||
|
||||
public override int ImageIndex { |
||||
get { |
||||
return ClassBrowserIconService.Method.ImageIndex; |
||||
} |
||||
} |
||||
|
||||
protected override void InitContent() |
||||
{ |
||||
foreach (IMethod m in OverrideCompletionItemProvider.GetOverridableMethods(currentClass)) { |
||||
Content.Add(new MethodWrapper(m)); |
||||
} |
||||
Content.Sort(); |
||||
} |
||||
|
||||
public override void GenerateCode(List<AbstractNode> nodes, IList items) |
||||
{ |
||||
foreach (MethodWrapper wrapper in items) { |
||||
nodes.Add(codeGen.GetOverridingMethod(wrapper.Method, this.classFinderContext)); |
||||
} |
||||
} |
||||
|
||||
class MethodWrapper : IComparable |
||||
{ |
||||
IMethod method; |
||||
|
||||
public IMethod Method { |
||||
get { |
||||
return method; |
||||
} |
||||
} |
||||
|
||||
public int CompareTo(object other) |
||||
{ |
||||
return ToString().CompareTo(((MethodWrapper)other).ToString()); |
||||
} |
||||
|
||||
public MethodWrapper(IMethod method) |
||||
{ |
||||
this.method = method; |
||||
} |
||||
|
||||
public override bool Equals(object obj) |
||||
{ |
||||
MethodWrapper other = (MethodWrapper)obj; |
||||
if (method.Name != other.method.Name) |
||||
return false; |
||||
return 0 == DiffUtility.Compare(method.Parameters, other.method.Parameters); |
||||
} |
||||
|
||||
public override int GetHashCode() |
||||
{ |
||||
return ToString().GetHashCode(); |
||||
} |
||||
|
||||
string cachedStringRepresentation; |
||||
|
||||
public override string ToString() |
||||
{ |
||||
if (cachedStringRepresentation == null) { |
||||
IAmbience ambience = AmbienceService.GetCurrentAmbience(); |
||||
ambience.ConversionFlags = ConversionFlags.ShowParameterNames; |
||||
cachedStringRepresentation = ambience.Convert(method); |
||||
} |
||||
return cachedStringRepresentation; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
@ -1,83 +0,0 @@
@@ -1,83 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using ICSharpCode.SharpDevelop.Editor.CodeCompletion; |
||||
using System; |
||||
using System.Collections; |
||||
using System.Collections.Generic; |
||||
using ICSharpCode.NRefactory.Ast; |
||||
using ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor; |
||||
using ICSharpCode.SharpDevelop.Dom; |
||||
using ICSharpCode.SharpDevelop.Editor; |
||||
|
||||
namespace ICSharpCode.SharpDevelop.DefaultEditor.Commands |
||||
{ |
||||
public class OverridePropertiesCodeGenerator : CodeGeneratorBase |
||||
{ |
||||
public override string CategoryName { |
||||
get { |
||||
return "${res:ICSharpCode.SharpDevelop.CodeGenerator.OverrideProperties}"; |
||||
} |
||||
} |
||||
|
||||
public override string Hint { |
||||
get { |
||||
return "${res:ICSharpCode.SharpDevelop.CodeGenerator.OverrideProperties.Hint}"; |
||||
} |
||||
} |
||||
|
||||
public override int ImageIndex { |
||||
get { |
||||
return ClassBrowserIconService.Property.ImageIndex; |
||||
} |
||||
} |
||||
|
||||
protected override void InitContent() |
||||
{ |
||||
foreach (IProperty p in OverrideCompletionItemProvider.GetOverridableProperties(currentClass)) { |
||||
Content.Add(new PropertyWrapper(p)); |
||||
} |
||||
Content.Sort(); |
||||
} |
||||
|
||||
public override void GenerateCode(List<AbstractNode> nodes, IList items) |
||||
{ |
||||
foreach (PropertyWrapper wrapper in items) { |
||||
nodes.Add(codeGen.GetOverridingMethod(wrapper.Property, this.classFinderContext)); |
||||
} |
||||
} |
||||
|
||||
class PropertyWrapper : IComparable |
||||
{ |
||||
IProperty property; |
||||
|
||||
public IProperty Property { |
||||
get { |
||||
return property; |
||||
} |
||||
} |
||||
|
||||
public int CompareTo(object other) |
||||
{ |
||||
return property.Name.CompareTo(((PropertyWrapper)other).property.Name); |
||||
} |
||||
|
||||
|
||||
public PropertyWrapper(IProperty property) |
||||
{ |
||||
this.property = property; |
||||
} |
||||
|
||||
public override string ToString() |
||||
{ |
||||
IAmbience ambience = AmbienceService.GetCurrentAmbience(); |
||||
ambience.ConversionFlags = ConversionFlags.ShowParameterNames; |
||||
return ambience.Convert(property); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
@ -1,37 +0,0 @@
@@ -1,37 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Collections; |
||||
using System.Collections.Generic; |
||||
|
||||
using ICSharpCode.NRefactory.Ast; |
||||
|
||||
namespace ICSharpCode.SharpDevelop.DefaultEditor.Commands |
||||
{ |
||||
public class SetterCodeGenerator : AbstractPropertyCodeGenerator |
||||
{ |
||||
public override string CategoryName { |
||||
get { |
||||
return "${res:ICSharpCode.SharpDevelop.CodeGenerator.Setter}"; |
||||
} |
||||
} |
||||
|
||||
public override string Hint { |
||||
get { |
||||
return "${res:ICSharpCode.SharpDevelop.CodeGenerator.Setter.Hint}"; |
||||
} |
||||
} |
||||
|
||||
public override void GenerateCode(List<AbstractNode> nodes, IList items) |
||||
{ |
||||
foreach (FieldWrapper w in items) { |
||||
nodes.Add(codeGen.CreateProperty(w.Field, false, true)); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
@ -1,67 +0,0 @@
@@ -1,67 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Collections; |
||||
using System.Collections.Generic; |
||||
using System.Text; |
||||
|
||||
using ICSharpCode.NRefactory.Ast; |
||||
|
||||
namespace ICSharpCode.SharpDevelop.DefaultEditor.Commands |
||||
{ |
||||
public class ToStringCodeGenerator : AbstractFieldCodeGenerator |
||||
{ |
||||
public override void GenerateCode(List<AbstractNode> nodes, IList items) |
||||
{ |
||||
TypeReference stringReference = new TypeReference("System.String", true); |
||||
MethodDeclaration method = new MethodDeclaration { |
||||
Name = "ToString", |
||||
Modifier = Modifiers.Public | Modifiers.Override, |
||||
TypeReference = stringReference, |
||||
}; |
||||
method.Body = new BlockStatement(); |
||||
Expression target = new MemberReferenceExpression(new TypeReferenceExpression(stringReference), |
||||
"Format"); |
||||
InvocationExpression methodCall = new InvocationExpression(target); |
||||
StringBuilder formatString = new StringBuilder(); |
||||
formatString.Append('['); |
||||
formatString.Append(currentClass.Name); |
||||
for (int i = 0; i < items.Count; i++) { |
||||
formatString.Append(' '); |
||||
formatString.Append(codeGen.GetPropertyName(((FieldWrapper)items[i]).Field.Name)); |
||||
formatString.Append("={"); |
||||
formatString.Append(i); |
||||
formatString.Append('}'); |
||||
} |
||||
formatString.Append(']'); |
||||
methodCall.Arguments.Add(new PrimitiveExpression(formatString.ToString(), formatString.ToString())); |
||||
foreach (FieldWrapper w in items) { |
||||
methodCall.Arguments.Add(new MemberReferenceExpression(new ThisReferenceExpression(), w.Field.Name)); |
||||
} |
||||
method.Body.AddChild(new ReturnStatement(methodCall)); |
||||
nodes.Add(method); |
||||
} |
||||
|
||||
public override string CategoryName { |
||||
get { |
||||
return "${res:ICSharpCode.SharpDevelop.CodeGenerator.ToString}"; |
||||
} |
||||
} |
||||
|
||||
public override string Hint { |
||||
get { |
||||
return "${res:ICSharpCode.SharpDevelop.CodeGenerator.ToString.Hint}"; |
||||
} |
||||
} |
||||
public override int ImageIndex { |
||||
get { |
||||
return ClassBrowserIconService.Method.ImageIndex; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
@ -1,84 +0,0 @@
@@ -1,84 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Collections; |
||||
using System.Collections.Generic; |
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor; |
||||
using ICSharpCode.SharpDevelop.Dom; |
||||
using ICSharpCode.SharpDevelop.Gui; |
||||
using ICSharpCode.TextEditor; |
||||
using ICSharpCode.TextEditor.Actions; |
||||
using ICSharpCode.TextEditor.Document; |
||||
|
||||
namespace ICSharpCode.SharpDevelop.DefaultEditor.Commands |
||||
{ |
||||
[Obsolete] |
||||
public class GenerateCodeAction : AbstractMenuCommand |
||||
{ |
||||
public override void Run() |
||||
{ |
||||
IViewContent viewContent = WorkbenchSingleton.Workbench.ActiveViewContent; |
||||
|
||||
if (viewContent == null || !(viewContent is ITextEditorControlProvider)) { |
||||
return; |
||||
} |
||||
TextEditorControl textEditorControl = ((ITextEditorControlProvider)viewContent).TextEditorControl; |
||||
|
||||
ParseInformation parseInformation; |
||||
|
||||
if (viewContent.PrimaryFile.IsUntitled) { |
||||
parseInformation = ParserService.ParseFile(textEditorControl.FileName, new StringTextBuffer(textEditorControl.Document.TextContent)); |
||||
} else { |
||||
parseInformation = ParserService.GetParseInformation(textEditorControl.FileName); |
||||
} |
||||
|
||||
if (parseInformation == null) { |
||||
return; |
||||
} |
||||
|
||||
ICompilationUnit cu = parseInformation.CompilationUnit as ICompilationUnit; |
||||
if (cu == null) { |
||||
return; |
||||
} |
||||
IClass currentClass = GetCurrentClass(textEditorControl, cu, textEditorControl.FileName); |
||||
|
||||
if (currentClass != null) { |
||||
var generators = AddInTree.BuildItems<CodeGeneratorBase>("/AddIns/DefaultTextEditor/CodeGenerator", this, true); |
||||
using (CodeGenerationForm form = new CodeGenerationForm(textEditorControl, generators.ToArray(), currentClass)) { |
||||
form.ShowDialog(ICSharpCode.SharpDevelop.Gui.WorkbenchSingleton.MainWin32Window); |
||||
} |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Returns the class in which the carret currently is, returns null
|
||||
/// if the carret is outside the class boundaries.
|
||||
/// </summary>
|
||||
IClass GetCurrentClass(TextEditorControl textEditorControl, ICompilationUnit cu, string fileName) |
||||
{ |
||||
IDocument document = textEditorControl.Document; |
||||
if (cu != null) { |
||||
int caretLineNumber = document.GetLineNumberForOffset(textEditorControl.ActiveTextAreaControl.Caret.Offset) + 1; |
||||
int caretColumn = textEditorControl.ActiveTextAreaControl.Caret.Offset - document.GetLineSegment(caretLineNumber - 1).Offset + 1; |
||||
return FindClass(cu.Classes, caretLineNumber, caretColumn); |
||||
} |
||||
return null; |
||||
} |
||||
IClass FindClass(ICollection<IClass> classes, int lineNr, int column) |
||||
{ |
||||
foreach (IClass c in classes) { |
||||
if (c.Region.IsInside(lineNr, column)) { |
||||
IClass inner = FindClass(c.InnerClasses, lineNr, column); |
||||
return inner == null ? c : inner; |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
} |
||||
} |
||||
Loading…
Reference in new issue