Browse Source

patch from Luc Morin: support for overriding virtual base class properties with the alt-ins mechanism

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@699 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Markus Palme 20 years ago
parent
commit
d45bf1135e
  1. 1
      src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj
  2. 192
      src/Main/Base/Project/Src/TextEditor/Commands/CodeGenerators/OverridePropertiesCodeGenerator.cs
  3. 1
      src/Main/Base/Project/Src/TextEditor/Commands/GenerateCodeCommand.cs

1
src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj

@ -507,6 +507,7 @@ @@ -507,6 +507,7 @@
<Compile Include="Src\TextEditor\Commands\CodeGenerators\InterfaceImplementorCodeGenerator.cs" />
<Compile Include="Src\TextEditor\Commands\CodeGenerators\OnXXXMethodsCodeGenerator.cs" />
<Compile Include="Src\TextEditor\Commands\CodeGenerators\OverrideMethodsCodeGenerator.cs" />
<Compile Include="Src\TextEditor\Commands\CodeGenerators\OverridePropertiesCodeGenerator.cs" />
<Compile Include="Src\TextEditor\Commands\CodeGenerators\SetterCodeGenerator.cs" />
<Compile Include="Src\TextEditor\Commands\CodeGenerators\ToStringCodeGenerator.cs" />
<Compile Include="Src\TextEditor\Commands\CommentRegionCommand.cs" />

192
src/Main/Base/Project/Src/TextEditor/Commands/CodeGenerators/OverridePropertiesCodeGenerator.cs

@ -0,0 +1,192 @@ @@ -0,0 +1,192 @@
// <file>
// <copyright see="prj:///doc/copyright.txt">2002-2005 AlphaSierraPapa</copyright>
// <license see="prj:///doc/license.txt">GNU General Public License</license>
// <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
// <version>$Revision: 607 $</version>
// </file>
using System;
using System.Collections;
using ICSharpCode.TextEditor;
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.Core;
namespace ICSharpCode.SharpDevelop.DefaultEditor.Commands
{
public class OverridePropertiesCodeGenerator : OldCodeGeneratorBase
{
public override string CategoryName {
get {
return "Override properties";
}
}
public override string Hint {
get {
return "Choose properties to override";
}
}
public override int ImageIndex {
get {
return ClassBrowserIconService.PropertyIndex;
}
}
public OverridePropertiesCodeGenerator(IClass currentClass) : base(currentClass)
{
foreach (IClass c in currentClass.ClassInheritanceTree) {
if (c.FullyQualifiedName != currentClass.FullyQualifiedName) {
foreach (IProperty property in c.Properties) {
if (!property.IsPrivate && (property.IsAbstract || property.IsVirtual || property.IsOverride)) {
Content.Add(new PropertyWrapper(property));
}
}
}
}
Content.Sort();
}
protected override void StartGeneration(IList items, string fileExtension)
{
for (int i = 0; i < items.Count; ++i) {
PropertyWrapper pw = (PropertyWrapper)items[i];
string parameters = String.Empty;
string paramList = String.Empty;
string returnType = (fileExtension == ".vb" ? vba : csa).Convert(pw.Property.ReturnType);
for (int j = 0; j < pw.Property.Parameters.Count; ++j) {
paramList += pw.Property.Parameters[j].Name;
parameters += (fileExtension == ".vb" ? vba : csa).Convert(pw.Property.Parameters[j]);
if (j + 1 < pw.Property.Parameters.Count) {
parameters += ", ";
paramList += ", ";
}
}
if (fileExtension == ".vb"){
editActionHandler.InsertString(vba.Convert(pw.Property.Modifiers) + "Overrides ");++numOps;
editActionHandler.InsertString("Property ");++numOps;
editActionHandler.InsertString(pw.Property.Name + "()");++numOps;
} else {
editActionHandler.InsertString(csa.Convert(pw.Property.Modifiers) + "override " + returnType + " " + pw.Property.Name);++numOps;
if (StartCodeBlockInSameLine) {
editActionHandler.InsertString(" {");
} else {
Return();
editActionHandler.InsertString("{");
}
++numOps;
}
Return();
if(fileExtension == ".vb") {
editActionHandler.InsertString("Get");++numOps;
} else {
editActionHandler.InsertString("get");++numOps;
if (StartCodeBlockInSameLine) {
editActionHandler.InsertString(" {");
} else {
Return();
editActionHandler.InsertString("{");
}
++numOps;
}
Return();
if(fileExtension == ".vb") {
editActionHandler.InsertString("Return MyBase." + pw.Property.Name); ++numOps;
} else {
editActionHandler.InsertString("return base." + pw.Property.Name); ++numOps;
}
Return();
if(fileExtension == ".vb") {
editActionHandler.InsertString("End Get"); ++numOps;
} else {
editActionHandler.InsertChar('}'); ++numOps;
}
Return();
if(fileExtension == ".vb") {
editActionHandler.InsertString("Set");++numOps;
} else {
editActionHandler.InsertString("set");++numOps;
if (StartCodeBlockInSameLine) {
editActionHandler.InsertString(" {");
} else {
Return();
editActionHandler.InsertString("{");
}
++numOps;
}
Return();
if(fileExtension == ".vb") {
editActionHandler.InsertString("MyBase." + pw.Property.Name + " = value"); ++numOps;
} else {
editActionHandler.InsertString("base." + pw.Property.Name + " = value"); ++numOps;
}
Return();
if(fileExtension == ".vb") {
editActionHandler.InsertString("End Set"); ++numOps;
} else {
editActionHandler.InsertChar('}'); ++numOps;
}
Return();
if(fileExtension == ".vb") {
editActionHandler.InsertString("End Property"); ++numOps;
} else {
editActionHandler.InsertChar('}'); ++numOps;
}
Return();
Return();
IndentLine();
}
}
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.CurrentAmbience;
ambience.ConversionFlags = ConversionFlags.ShowParameterNames;
return ambience.Convert(property);
}
}
}
}

1
src/Main/Base/Project/Src/TextEditor/Commands/GenerateCodeCommand.cs

@ -64,6 +64,7 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Commands @@ -64,6 +64,7 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Commands
new GetterAndSetterCodeGenerator(currentClass),
new OnXXXMethodsCodeGenerator(currentClass),
new OverrideMethodsCodeGenerator(currentClass),
new OverridePropertiesCodeGenerator(currentClass),
new InterfaceImplementorCodeGenerator(currentClass),
new AbstractClassImplementorCodeGenerator(currentClass),
new ToStringCodeGenerator(currentClass),

Loading…
Cancel
Save