Browse Source

Allow generating interface implementations using the new CodeGenerator.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@614 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 20 years ago
parent
commit
85a45ca2ab
  1. 7
      src/AddIns/BackendBindings/Boo/BooBinding/Project/Src/BooCodeGenerator.cs
  2. 6
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/CSharpCompletionBinding.cs
  3. 1
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/Parser/ExpressionFinder.cs
  4. 6
      src/AddIns/BackendBindings/VBNetBinding/Project/Src/VBNetCompletionBinding.cs
  5. 2
      src/Libraries/NRefactory/Project/Src/Output/AbstractOutputFormatter.cs
  6. 6
      src/Libraries/NRefactory/Project/Src/Output/CSharp/CSharpOutputVisitor.cs
  7. 16
      src/Libraries/NRefactory/Project/Src/Output/IOutputASTVisitor.cs
  8. 4
      src/Libraries/NRefactory/Project/Src/Output/SpecialNodesInserter.cs
  9. 2
      src/Libraries/NRefactory/Project/Src/Output/VBNet/VBNetOutputVisitor.cs
  10. 14
      src/Main/Base/Project/Src/Dom/ClassFinder.cs
  11. 2
      src/Main/Base/Project/Src/Dom/ITypeParameter.cs
  12. 6
      src/Main/Base/Project/Src/Dom/Implementations/DefaultTypeParameter.cs
  13. 14
      src/Main/Base/Project/Src/Gui/Workbench/Layouts/SdiWorkspaceLayout.cs
  14. 287
      src/Main/Base/Project/Src/Services/RefactoringService/CodeGenerator.cs
  15. 9
      src/Main/Base/Project/Src/Services/RefactoringService/NRefactoryCodeGenerator.cs
  16. 44
      src/Main/Base/Project/Src/TextEditor/Commands/ClassBookmarkMenuBuilder.cs
  17. 8
      src/Main/Core/Project/Src/AddInTree/AddIn/DefaultDoozers/MenuItem/Gui/Menu.cs
  18. 5
      src/Main/Core/Project/Src/Services/MessageService/MessageService.cs
  19. BIN
      src/Main/StartUp/Project/Resources/StringResources.resources

7
src/AddIns/BackendBindings/Boo/BooBinding/Project/Src/BooCodeGenerator.cs

@ -9,6 +9,8 @@ using System; @@ -9,6 +9,8 @@ using System;
using System.IO;
using System.Text;
using ICSharpCode.Core;
using ICSharpCode.TextEditor.Document;
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.SharpDevelop.Refactoring;
using ICSharpCode.NRefactory.Parser.AST;
using NRefactoryToBooConverter;
@ -23,6 +25,11 @@ namespace Grunwald.BooBinding @@ -23,6 +25,11 @@ namespace Grunwald.BooBinding
/// </summary>
public class BooCodeGenerator : CodeGenerator
{
public override void InsertCodeInClass(IClass c, IDocument document, params AbstractNode[] nodes)
{
InsertCodeAfter(c.Region.BeginLine, document, true, nodes);
}
public override string GenerateCode(AbstractNode node, string indentation)
{
StringBuilder errorBuilder = new StringBuilder();

6
src/AddIns/BackendBindings/CSharpBinding/Project/Src/CSharpCompletionBinding.cs

@ -141,7 +141,11 @@ namespace CSharpBinding @@ -141,7 +141,11 @@ namespace CSharpBinding
t.col, editor.FileName,
editor.Document.TextContent);
if (rr != null && rr.ResolvedType != null) {
CSharpAmbience.Instance.ConversionFlags = ConversionFlags.ShowReturnType;
ClassFinder context = new ClassFinder(editor.FileName, editor.ActiveTextAreaControl.Caret.Line, t.col);
if (ICSharpCode.SharpDevelop.Refactoring.CodeGenerator.CanUseShortTypeName(rr.ResolvedType, context))
CSharpAmbience.Instance.ConversionFlags = ConversionFlags.None;
else
CSharpAmbience.Instance.ConversionFlags = ConversionFlags.UseFullyQualifiedNames;
string typeName = CSharpAmbience.Instance.Convert(rr.ResolvedType);
editor.Document.Replace(curLine.Offset + typeToken.col - 1, 1, typeName);
editor.ActiveTextAreaControl.Caret.Column += typeName.Length - 1;

1
src/AddIns/BackendBindings/CSharpBinding/Project/Src/Parser/ExpressionFinder.cs

@ -672,6 +672,7 @@ namespace CSharpBinding.Parser @@ -672,6 +672,7 @@ namespace CSharpBinding.Parser
case "return":
case "throw":
case "in":
case "else":
// treat as error / end of expression
break;
default:

6
src/AddIns/BackendBindings/VBNetBinding/Project/Src/VBNetCompletionBinding.cs

@ -222,7 +222,11 @@ namespace VBNetBinding @@ -222,7 +222,11 @@ namespace VBNetBinding
t2.col, editor.FileName,
editor.Document.TextContent);
if (rr != null && rr.ResolvedType != null) {
VBNetAmbience.Instance.ConversionFlags = ConversionFlags.ShowReturnType;
ClassFinder context = new ClassFinder(editor.FileName, editor.ActiveTextAreaControl.Caret.Line, t1.col);
if (ICSharpCode.SharpDevelop.Refactoring.CodeGenerator.CanUseShortTypeName(rr.ResolvedType, context))
VBNetAmbience.Instance.ConversionFlags = ConversionFlags.None;
else
VBNetAmbience.Instance.ConversionFlags = ConversionFlags.UseFullyQualifiedNames;
string typeName = VBNetAmbience.Instance.Convert(rr.ResolvedType);
editor.Document.Replace(curLine.Offset + t1.col - 1, 1, typeName);
editor.ActiveTextAreaControl.Caret.Column += typeName.Length - 1;

2
src/Libraries/NRefactory/Project/Src/Output/AbstractOutputFormatter.cs

@ -19,7 +19,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -19,7 +19,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
/// <summary>
/// Base class of output formatters.
/// </summary>
public abstract class AbstractOutputFormatter
public abstract class AbstractOutputFormatter : IOutputFormatter
{
int indentationLevel = 0;
StringBuilder text = new StringBuilder();

6
src/Libraries/NRefactory/Project/Src/Output/CSharp/CSharpOutputVisitor.cs

@ -48,7 +48,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -48,7 +48,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
}
}
public CSharpOutputFormatter OutputFormatter {
public IOutputFormatter OutputFormatter {
get {
return outputFormatter;
}
@ -1894,9 +1894,9 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -1894,9 +1894,9 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
nodeTracker.TrackedVisit(invocationExpression.TargetObject, data);
if (invocationExpression.TypeArguments != null && invocationExpression.TypeArguments.Count > 0) {
OutputFormatter.PrintToken(Tokens.LessThan);
outputFormatter.PrintToken(Tokens.LessThan);
AppendCommaSeparatedList(invocationExpression.TypeArguments);
OutputFormatter.PrintToken(Tokens.GreaterThan);
outputFormatter.PrintToken(Tokens.GreaterThan);
}
if (prettyPrintOptions.BeforeMethodCallParentheses) {

16
src/Libraries/NRefactory/Project/Src/Output/IOutputASTVisitor.cs

@ -33,5 +33,21 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -33,5 +33,21 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
get;
set;
}
IOutputFormatter OutputFormatter {
get;
}
}
public interface IOutputFormatter
{
int IndentationLevel {
get;
set;
}
string Text {
get;
}
void NewLine();
void PrintComment(Comment comment);
void PrintPreProcessingDirective(PreProcessingDirective directive);
}
}

4
src/Libraries/NRefactory/Project/Src/Output/SpecialNodesInserter.cs

@ -15,9 +15,9 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -15,9 +15,9 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
{
public class SpecialOutputVisitor : ISpecialVisitor
{
AbstractOutputFormatter formatter;
IOutputFormatter formatter;
public SpecialOutputVisitor(AbstractOutputFormatter formatter)
public SpecialOutputVisitor(IOutputFormatter formatter)
{
this.formatter = formatter;
}

2
src/Libraries/NRefactory/Project/Src/Output/VBNet/VBNetOutputVisitor.cs

@ -55,7 +55,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -55,7 +55,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
}
}
public VBNetOutputFormatter OutputFormatter {
public IOutputFormatter OutputFormatter {
get {
return outputFormatter;
}

14
src/Main/Base/Project/Src/Dom/ClassFinder.cs

@ -43,6 +43,20 @@ namespace ICSharpCode.SharpDevelop.Dom @@ -43,6 +43,20 @@ namespace ICSharpCode.SharpDevelop.Dom
Init(fileName);
}
public ClassFinder(IMember classMember)
: this(classMember.DeclaringType, classMember.Region.BeginLine, classMember.Region.BeginColumn)
{
}
public ClassFinder(IClass callingClass, int caretLine, int caretColumn)
{
this.caretLine = caretLine;
this.caretColumn = caretColumn;
this.callingClass = callingClass;
this.cu = callingClass.CompilationUnit;
this.projectContent = cu.ProjectContent;
}
void Init(string fileName)
{
ParseInformation parseInfo = ParserService.GetParseInformation(fileName);

2
src/Main/Base/Project/Src/Dom/ITypeParameter.cs

@ -23,6 +23,8 @@ namespace ICSharpCode.SharpDevelop.Dom @@ -23,6 +23,8 @@ namespace ICSharpCode.SharpDevelop.Dom
int Index { get; }
IList<IAttribute> Attributes { get; }
/// <summary>
/// The method this type parameter is defined for.
/// This property is null when the type parameter is for a class.

6
src/Main/Base/Project/Src/Dom/Implementations/DefaultTypeParameter.cs

@ -54,6 +54,12 @@ namespace ICSharpCode.SharpDevelop.Dom @@ -54,6 +54,12 @@ namespace ICSharpCode.SharpDevelop.Dom
}
}
public IList<IAttribute> Attributes {
get {
return DefaultAttribute.EmptyAttributeList;
}
}
bool hasConstructableContraint = false;
/// <summary>

14
src/Main/Base/Project/Src/Gui/Workbench/Layouts/SdiWorkspaceLayout.cs

@ -113,12 +113,6 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -113,12 +113,6 @@ namespace ICSharpCode.SharpDevelop.Gui
LoadLayoutConfiguration();
ShowPads();
// ShowPads could create new pads if new addins have been installed, so we
// need to call AllowInitialize again
foreach (PadContentWrapper content in contentHash.Values) {
content.AllowInitialize();
}
ShowViewContents();
RedrawAllComponents();
@ -170,6 +164,11 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -170,6 +164,11 @@ namespace ICSharpCode.SharpDevelop.Gui
ShowPad(content);
}
}
// ShowPads could create new pads if new addins have been installed, so we
// need to call AllowInitialize here instead of in LoadLayoutConfiguration
foreach (PadContentWrapper content in contentHash.Values) {
content.AllowInitialize();
}
}
void ShowViewContents()
{
@ -189,9 +188,6 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -189,9 +188,6 @@ namespace ICSharpCode.SharpDevelop.Gui
} catch {
// ignore errors loading configuration
}
foreach (PadContentWrapper content in contentHash.Values) {
content.AllowInitialize();
}
}
void LoadDefaultLayoutConfiguration()

287
src/Main/Base/Project/Src/Services/RefactoringService/CodeGenerator.cs

@ -6,7 +6,9 @@ @@ -6,7 +6,9 @@
*/
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.TextEditor.Document;
using ICSharpCode.NRefactory.Parser.AST;
@ -18,12 +20,17 @@ namespace ICSharpCode.SharpDevelop.Refactoring @@ -18,12 +20,17 @@ namespace ICSharpCode.SharpDevelop.Refactoring
/// </summary>
public abstract class CodeGenerator
{
protected TypeReference ConvertType(IReturnType returnType)
#region DOM -> NRefactory conversion (static)
public static TypeReference ConvertType(IReturnType returnType, ClassFinder context)
{
if (returnType == null) return TypeReference.Null;
if (returnType is NullReturnType) return TypeReference.Null;
TypeReference typeRef = new TypeReference(returnType.FullyQualifiedName);
TypeReference typeRef;
if (context != null && CanUseShortTypeName(returnType, context))
typeRef = new TypeReference(returnType.Name);
else
typeRef = new TypeReference(returnType.FullyQualifiedName);
while (returnType.ArrayDimensions > 0) {
int[] rank = typeRef.RankSpecifier ?? new int[0];
Array.Resize(ref rank, rank.Length + 1);
@ -33,17 +40,211 @@ namespace ICSharpCode.SharpDevelop.Refactoring @@ -33,17 +40,211 @@ namespace ICSharpCode.SharpDevelop.Refactoring
}
if (returnType.TypeArguments != null) {
foreach (IReturnType typeArgument in returnType.TypeArguments) {
typeRef.GenericTypes.Add(ConvertType(typeArgument));
typeRef.GenericTypes.Add(ConvertType(typeArgument, context));
}
}
return typeRef;
}
protected Modifier ConvertModifier(ModifierEnum m)
/// <summary>
/// Returns true if the short name of a type is valid in the given context.
/// Returns false for primitive types because they should be passed around using their
/// fully qualified names to allow the ambience or output visitor to use the intrinsic
/// type name.
/// </summary>
public static bool CanUseShortTypeName(IReturnType returnType, ClassFinder context)
{
switch (returnType.FullyQualifiedName) {
case "System.Void":
case "System.String":
case "System.Char":
case "System.Boolean":
case "System.Single":
case "System.Double":
case "System.Decimal":
case "System.Byte":
case "System.SByte":
case "System.Int16":
case "System.Int32":
case "System.Int64":
case "System.UInt16":
case "System.UInt32":
case "System.UInt64":
return false;
}
int typeArgumentCount = (returnType.TypeArguments != null) ? returnType.TypeArguments.Count : 0;
IReturnType typeInTargetContext = context.SearchType(returnType.Name, typeArgumentCount);
return typeInTargetContext != null && typeInTargetContext.FullyQualifiedName == returnType.FullyQualifiedName;
}
public static Modifier ConvertModifier(ModifierEnum m)
{
return (Modifier)m;
}
public static ParamModifier ConvertModifier(ParameterModifiers m)
{
return (ParamModifier)m;
}
public static List<ParameterDeclarationExpression> ConvertParameters(IList<IParameter> parameters, ClassFinder targetContext)
{
List<ParameterDeclarationExpression> l = new List<ParameterDeclarationExpression>(parameters.Count);
foreach (IParameter p in parameters) {
ParameterDeclarationExpression pd = new ParameterDeclarationExpression(ConvertType(p.ReturnType, targetContext),
p.Name,
ConvertModifier(p.Modifiers));
pd.Attributes = ConvertAttributes(p.Attributes, targetContext);
l.Add(pd);
}
return l;
}
public static List<AttributeSection> ConvertAttributes(IList<IAttribute> attributes, ClassFinder targetContext)
{
AttributeSection sec = new AttributeSection();
foreach (IAttribute att in attributes) {
sec.Attributes.Add(new ICSharpCode.NRefactory.Parser.AST.Attribute(att.Name, null, null));
}
List<AttributeSection> resultList = new List<AttributeSection>(1);
if (sec.Attributes.Count > 0)
resultList.Add(sec);
return resultList;
}
public static List<TemplateDefinition> ConvertTemplates(IList<ITypeParameter> l, ClassFinder targetContext)
{
List<TemplateDefinition> o = new List<TemplateDefinition>(l.Count);
foreach (ITypeParameter p in l) {
TemplateDefinition td = new TemplateDefinition(p.Name, ConvertAttributes(p.Attributes, targetContext));
foreach (IReturnType rt in p.Constraints) {
td.Bases.Add(ConvertType(rt, targetContext));
}
o.Add(td);
}
return o;
}
public static BlockStatement CreateNotImplementedBlock()
{
BlockStatement b = new BlockStatement();
b.AddChild(new ThrowStatement(new ObjectCreateExpression(new TypeReference("NotImplementedException"), null)));
return b;
}
public static ParametrizedNode ConvertMember(IMethod m, ClassFinder targetContext)
{
if (m.IsConstructor) {
return new ConstructorDeclaration(m.Name,
ConvertModifier(m.Modifiers),
ConvertParameters(m.Parameters, targetContext),
ConvertAttributes(m.Attributes, targetContext));
} else {
MethodDeclaration md;
md = new MethodDeclaration(m.Name,
ConvertModifier(m.Modifiers),
ConvertType(m.ReturnType, targetContext),
ConvertParameters(m.Parameters, targetContext),
ConvertAttributes(m.Attributes, targetContext));
md.Templates = ConvertTemplates(m.TypeParameters, targetContext);
md.Body = CreateNotImplementedBlock();
return md;
}
}
public static AttributedNode ConvertMember(IMember m, ClassFinder targetContext)
{
if (m == null)
throw new ArgumentNullException("m");
if (m is IProperty)
return ConvertMember((IProperty)m, targetContext);
else if (m is IMethod)
return ConvertMember((IMethod)m, targetContext);
else if (m is IEvent)
return ConvertMember((IEvent)m, targetContext);
else if (m is IField)
return ConvertMember((IField)m, targetContext);
else
throw new ArgumentException("Unknown member: " + m.GetType().FullName);
}
public static AttributedNode ConvertMember(IProperty p, ClassFinder targetContext)
{
if (p.IsIndexer) {
return new IndexerDeclaration(ConvertType(p.ReturnType, targetContext),
ConvertParameters(p.Parameters, targetContext),
ConvertModifier(p.Modifiers),
ConvertAttributes(p.Attributes, targetContext));
} else {
PropertyDeclaration md;
md = new PropertyDeclaration(p.Name,
ConvertType(p.ReturnType, targetContext),
ConvertModifier(p.Modifiers),
ConvertAttributes(p.Attributes, targetContext));
md.Parameters = ConvertParameters(p.Parameters, targetContext);
if (p.CanGet) md.GetRegion = new PropertyGetRegion(CreateNotImplementedBlock(), null);
if (p.CanSet) md.SetRegion = new PropertySetRegion(CreateNotImplementedBlock(), null);
return md;
}
}
public static FieldDeclaration ConvertMember(IField f, ClassFinder targetContext)
{
TypeReference type = ConvertType(f.ReturnType, targetContext);
FieldDeclaration fd = new FieldDeclaration(ConvertAttributes(f.Attributes, targetContext),
type, ConvertModifier(f.Modifiers));
fd.Fields.Add(new VariableDeclaration(f.Name, null, type));
return fd;
}
public static EventDeclaration ConvertMember(IEvent e, ClassFinder targetContext)
{
return new EventDeclaration(ConvertType(e.ReturnType, targetContext),
e.Name,
ConvertModifier(e.Modifiers),
ConvertAttributes(e.Attributes, targetContext));
}
#endregion
#region Code generation / insertion
public virtual void InsertCodeAfter(IMember member, IDocument document, params AbstractNode[] nodes)
{
InsertCodeAfter(member.Region.EndLine, document, false, nodes);
}
public virtual void InsertCodeInClass(IClass c, IDocument document, params AbstractNode[] nodes)
{
InsertCodeAfter(c.Region.EndLine - 1, document, false, nodes);
}
/// <summary>
/// Generates code for <paramref name="nodes"/> and inserts it into <paramref name="document"/>
/// after the line <paramref name="insertLine"/>.
/// </summary>
public virtual void InsertCodeAfter(int insertLine, IDocument document, bool addIndentation, params AbstractNode[] nodes)
{
LineSegment lineSegment = document.GetLineSegment(insertLine - 1);
string lineText = document.GetText(lineSegment.Offset, lineSegment.Length);
string indentation = lineText.Substring(0, lineText.Length - lineText.TrimStart().Length);
if (addIndentation)
indentation += '\t';
// insert one line below field (text editor uses different coordinates)
lineSegment = document.GetLineSegment(insertLine);
StringBuilder b = new StringBuilder();
foreach (AbstractNode node in nodes) {
b.AppendLine(indentation);
b.Append(GenerateCode(node, indentation));
}
document.Insert(lineSegment.Offset, b.ToString());
}
/// <summary>
/// Generates code for the NRefactory node.
/// </summary>
public abstract string GenerateCode(AbstractNode node, string indentation);
#endregion
#region Generate property
public virtual string GetPropertyName(string fieldName)
{
if (fieldName.StartsWith("_") && fieldName.Length > 1)
@ -58,7 +259,7 @@ namespace ICSharpCode.SharpDevelop.Refactoring @@ -58,7 +259,7 @@ namespace ICSharpCode.SharpDevelop.Refactoring
{
string name = GetPropertyName(field.Name);
PropertyDeclaration property = new PropertyDeclaration(name,
ConvertType(field.ReturnType),
ConvertType(field.ReturnType, new ClassFinder(field)),
ConvertModifier(field.Modifiers), null);
if (createGetter) {
BlockStatement block = new BlockStatement();
@ -75,25 +276,69 @@ namespace ICSharpCode.SharpDevelop.Refactoring @@ -75,25 +276,69 @@ namespace ICSharpCode.SharpDevelop.Refactoring
InsertCodeAfter(field, document, property);
}
#endregion
/// <summary>
/// Generates code for <paramref name="node"/> and inserts it into <paramref name="document"/>
/// after <paramref name="position"/>.
/// </summary>
public virtual void InsertCodeAfter(IMember position, IDocument document, AbstractNode node)
#region Interface implementation
protected string GetInterfaceName(IReturnType interf, IMember member, ClassFinder context)
{
int insertLine = position.Region.EndLine;
LineSegment lineSegment = document.GetLineSegment(insertLine - 1);
string lineText = document.GetText(lineSegment.Offset, lineSegment.Length);
string indentation = lineText.Substring(0, lineText.Length - lineText.TrimStart().Length);
// insert one line below field (text editor uses different coordinates)
lineSegment = document.GetLineSegment(insertLine);
document.Insert(lineSegment.Offset, GenerateCode(node, indentation));
if (CanUseShortTypeName(member.DeclaringType.DefaultReturnType, context))
return member.DeclaringType.Name;
else
return member.DeclaringType.FullyQualifiedName;
}
/// <summary>
/// Generates code for the NRefactory node.
/// </summary>
public abstract string GenerateCode(AbstractNode node, string indentation);
public virtual void ImplementInterface(IReturnType interf, IDocument document, bool explicitImpl, IClass targetClass)
{
ClassFinder context = new ClassFinder(targetClass, targetClass.Region.BeginLine + 1, 0);
List<AbstractNode> nodes = new List<AbstractNode>();
List<IEvent> targetClassEvents = targetClass.DefaultReturnType.GetEvents();
foreach (IEvent e in interf.GetEvents()) {
if (targetClassEvents.Find(delegate(IEvent te) { return e.Name == te.Name; }) == null) {
EventDeclaration ed = ConvertMember(e, context);
if (explicitImpl) {
ed.Name = GetInterfaceName(interf, e, context) + "." + ed.Name;
ed.Modifier = Modifier.None;
} else {
ed.Modifier = Modifier.Public;
}
nodes.Add(ed);
}
}
List<IProperty> targetClassProperties = targetClass.DefaultReturnType.GetProperties();
foreach (IProperty p in interf.GetProperties()) {
if (targetClassProperties.Find(delegate(IProperty tp) { return p.Name == tp.Name; }) == null) {
AttributedNode pd = ConvertMember(p, context);
if (explicitImpl) {
if (pd is IndexerDeclaration) {
((IndexerDeclaration)pd).NamespaceName = GetInterfaceName(interf, p, context);
} else {
((PropertyDeclaration)pd).Name = GetInterfaceName(interf, p, context) + "." + ((PropertyDeclaration)pd).Name;
}
pd.Modifier = Modifier.None;
} else {
pd.Modifier = Modifier.Public;
}
nodes.Add(pd);
}
}
List<IMethod> targetClassMethods = targetClass.DefaultReturnType.GetMethods();
foreach (IMethod m in interf.GetMethods()) {
if (targetClassMethods.Find(delegate(IMethod mp) {
return m.Name == mp.Name && DiffUtility.Compare(m.Parameters, mp.Parameters) == 0;
}) == null)
{
ParametrizedNode md = ConvertMember(m, context);
if (explicitImpl) {
md.Name = GetInterfaceName(interf, m, context) + "." + md.Name;
md.Modifier = Modifier.None;
} else {
md.Modifier = Modifier.Public;
}
nodes.Add(md);
}
}
InsertCodeAfter(targetClass.Region.BeginLine, document, true, nodes.ToArray());
}
#endregion
}
}

9
src/Main/Base/Project/Src/Services/RefactoringService/NRefactoryCodeGenerator.cs

@ -20,7 +20,14 @@ namespace ICSharpCode.SharpDevelop.Refactoring @@ -20,7 +20,14 @@ namespace ICSharpCode.SharpDevelop.Refactoring
public override string GenerateCode(AbstractNode node, string indentation)
{
IOutputASTVisitor visitor = CreateOutputVisitor();
int indentCount = 0;
foreach (char c in indentation) {
if (c == '\t')
indentCount += 4;
else
indentCount += 1;
}
visitor.OutputFormatter.IndentationLevel = indentCount / 4;
node.AcceptVisitor(visitor, null);
return visitor.Text;
}

44
src/Main/Base/Project/Src/TextEditor/Commands/ClassBookmarkMenuBuilder.cs

@ -51,6 +51,9 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Commands @@ -51,6 +51,9 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Commands
cmd = new MenuCommand("${res:SharpDevelop.Refactoring.GoToBaseCommand}", GoToBase);
cmd.Tag = c;
list.Add(cmd);
if (c.ClassType != ClassType.Interface && !FindReferencesAndRenameHelper.IsReadOnly(c)) {
AddImplementInterfaceCommands(c, list);
}
}
if (!c.IsSealed && !c.IsStatic) {
cmd = new MenuCommand("${res:SharpDevelop.Refactoring.FindDerivedClassesCommand}", FindDerivedClasses);
@ -65,6 +68,47 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Commands @@ -65,6 +68,47 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Commands
return list.ToArray();
}
void AddImplementInterfaceCommands(IClass c, List<ToolStripItem> list)
{
CodeGenerator codeGen = c.ProjectContent.Language.CodeGenerator;
if (codeGen == null) return;
List<ToolStripItem> subItems = new List<ToolStripItem>();
foreach (IReturnType rt in c.BaseTypes) {
IClass interf = rt.GetUnderlyingClass();
if (interf != null && interf.ClassType == ClassType.Interface) {
EventHandler eh = delegate {
IDocument d = GetDocument(c);
if (d != null)
codeGen.ImplementInterface(rt, d, false, c);
};
subItems.Add(new MenuCommand(interf.Name, eh));
}
}
list.Add(new ICSharpCode.Core.Menu("${res:SharpDevelop.Refactoring.ImplementInterfaceImplicit}", subItems.ToArray()));
subItems = new List<ToolStripItem>();
foreach (IReturnType rt in c.BaseTypes) {
IClass interf = rt.GetUnderlyingClass();
if (interf != null && interf.ClassType == ClassType.Interface) {
EventHandler eh = delegate {
IDocument d = GetDocument(c);
if (d != null)
codeGen.ImplementInterface(rt, d, true, c);
};
subItems.Add(new MenuCommand(interf.Name, eh));
}
}
list.Add(new ICSharpCode.Core.Menu("${res:SharpDevelop.Refactoring.ImplementInterfaceExplicit}", subItems.ToArray()));
}
static IDocument GetDocument(IClass c)
{
IWorkbenchWindow win = FileService.OpenFile(c.CompilationUnit.FileName);
if (win == null) return null;
ITextEditorControlProvider tecp = win.ViewContent as ITextEditorControlProvider;
if (tecp == null) return null;
return tecp.TextEditorControl.Document;
}
void GoToBase(object sender, EventArgs e)
{
MenuCommand item = (MenuCommand)sender;

8
src/Main/Core/Project/Src/AddInTree/AddIn/DefaultDoozers/MenuItem/Gui/Menu.cs

@ -35,6 +35,12 @@ namespace ICSharpCode.Core @@ -35,6 +35,12 @@ namespace ICSharpCode.Core
}
}
public Menu(string text, params ToolStripItem[] subItems)
{
this.Text = StringParser.Parse(text);
this.DropDownItems.AddRange(subItems);
}
void CreateDropDownItems()
{
DropDownItems.Clear();
@ -53,7 +59,7 @@ namespace ICSharpCode.Core @@ -53,7 +59,7 @@ namespace ICSharpCode.Core
}
protected override void OnDropDownShow(EventArgs e)
{
if (!this.DropDown.Visible) {
if (codon != null && !this.DropDown.Visible) {
CreateDropDownItems();
}
base.OnDropDownShow(e);

5
src/Main/Core/Project/Src/Services/MessageService/MessageService.cs

@ -48,8 +48,9 @@ namespace ICSharpCode.Core @@ -48,8 +48,9 @@ namespace ICSharpCode.Core
static ShowErrorDelegate customErrorReporter;
/// <summary>
/// Gets/Sets the custom error reporter. If this property is null, a default
/// messagebox is used.
/// Gets/Sets the custom error reporter. If this property is null, the default
/// messagebox is used (except for debug builds of ICSharpCode.Core, where the
/// message is only logged to the LoggingService).
/// </summary>
public static ShowErrorDelegate CustomErrorReporter {
get {

BIN
src/Main/StartUp/Project/Resources/StringResources.resources

Binary file not shown.
Loading…
Cancel
Save