Browse Source

Fixed VB interface implementation code generator.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@945 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 20 years ago
parent
commit
de20032c48
  1. 6
      src/AddIns/BackendBindings/Boo/BooBinding.sln
  2. 1
      src/AddIns/BackendBindings/Boo/BooBinding/Project/Src/BooCodeGenerator.cs
  3. 23
      src/AddIns/BackendBindings/Boo/NRefactoryToBooConverter/Project/ConvertVisitorTypeMembers.cs
  4. 6
      src/AddIns/BackendBindings/Boo/NRefactoryToBooConverter/Test/MemberTests.cs
  5. 26
      src/Libraries/NRefactory/Project/Src/Output/VBNet/VBNetOutputVisitor.cs
  6. 7
      src/Libraries/NRefactory/Test/Output/VBNet/VBNetOutputTest.cs
  7. 15
      src/Main/Base/Project/Src/Dom/LanguageProperties.cs
  8. 30
      src/Main/Base/Project/Src/Services/RefactoringService/CodeGenerator.cs
  9. 25
      src/Main/Base/Project/Src/TextEditor/Commands/ClassBookmarkMenuBuilder.cs

6
src/AddIns/BackendBindings/Boo/BooBinding.sln

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
Microsoft Visual Studio Solution File, Format Version 9.00
# SharpDevelop 2.0.0.851
# SharpDevelop 2.0.0.940
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NRefactoryToBooConverter", "NRefactoryToBooConverter\Project\NRefactoryToBooConverter.csproj", "{DBCF20A1-BA13-4582-BFA9-74DE4D987B73}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NRefactoryToBooConverter.Tests", "NRefactoryToBooConverter\Test\NRefactoryToBooConverter.Tests.csproj", "{C9DE556D-325C-4544-B29F-16A9EB7C9830}"
@ -22,10 +22,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ICSharpCode.SharpDevelop", @@ -22,10 +22,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ICSharpCode.SharpDevelop",
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WinFormsUI", "..\..\..\Libraries\DockPanel_Src\WinFormsUI\WinFormsUI.csproj", "{D3C782BA-178E-4235-A3BA-8C11DEBB6BEE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FormDesigner", "..\..\DisplayBindings\FormDesigner\Project\FormDesigner.csproj", "{7D7E92DF-ACEB-4B69-92C8-8AC7A703CD57}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "nunit.framework.dll", "..\..\..\Libraries\NUnit.Framework\nunit.framework.dll.csproj", "{83DD7E12-A705-4DBA-9D71-09C8973D9382}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FormsDesigner", "..\..\DisplayBindings\FormsDesigner\Project\FormsDesigner.csproj", "{7D7E92DF-ACEB-4B69-92C8-8AC7A703CD57}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU

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

@ -49,6 +49,7 @@ namespace Grunwald.BooBinding @@ -49,6 +49,7 @@ namespace Grunwald.BooBinding
errorBuilder.AppendLine(warning.ToString());
}
}
booNode.Accept(new RemoveRedundantTypeReferencesVisitor());
using (StringWriter w = new StringWriter()) {
BooPrinterVisitor printer = new BooPrinterVisitor(w);
int indentCount = 0;

23
src/AddIns/BackendBindings/Boo/NRefactoryToBooConverter/Project/ConvertVisitorTypeMembers.cs

@ -59,24 +59,30 @@ namespace NRefactoryToBooConverter @@ -59,24 +59,30 @@ namespace NRefactoryToBooConverter
return b;
}
B.ExplicitMemberInfo ConvertInterfaceImplementations(List<InterfaceImplementation> implementations, AttributedNode node, string name)
B.ExplicitMemberInfo ConvertInterfaceImplementations(List<InterfaceImplementation> implementations, AttributedNode node, B.TypeMember targetMember)
{
if (implementations.Count == 0)
return null;
if (implementations.Count > 1) {
AddError(node, "Multiple explicit interface implementations are not supported");
}
if (implementations[0].MemberName != name) {
if (implementations[0].MemberName != targetMember.Name) {
AddError(node, "Explicit interface implementation: Implementing member with different name is not supported");
}
if (targetMember.Modifiers == B.TypeMemberModifiers.Private) {
targetMember.Modifiers = B.TypeMemberModifiers.None;
} else {
AddError(node, "Explicit interface implementation: Only private methods can explicitly implement interfaces");
}
B.TypeReference tr = ConvertTypeReference(implementations[0].InterfaceType);
if (tr is B.SimpleTypeReference) {
B.ExplicitMemberInfo explicitInfo = new B.ExplicitMemberInfo(GetLexicalInfo(node));
explicitInfo.InterfaceType = (B.SimpleTypeReference)tr;
return explicitInfo;
} else {
AddError(node, "Explicit interface implementation: invalid base type, expecting SimpleTypeReference");
return null;
}
AddError(node, "Explicit interface implementation: invalid base type, expecting SimpleTypeReference");
return null;
}
B.Method entryPointMethod;
@ -92,7 +98,7 @@ namespace NRefactoryToBooConverter @@ -92,7 +98,7 @@ namespace NRefactoryToBooConverter
// TODO: Convert handles clauses to [Handles] attribute
AddError(methodDeclaration, "Handles-clause is not supported.");
}
m.ExplicitInfo = ConvertInterfaceImplementations(methodDeclaration.InterfaceImplementations, methodDeclaration, methodDeclaration.Name);
m.ExplicitInfo = ConvertInterfaceImplementations(methodDeclaration.InterfaceImplementations, methodDeclaration, m);
if (methodDeclaration.Templates.Count > 0) {
AddError(methodDeclaration, "Declaring generic methods is not supported.");
}
@ -186,7 +192,7 @@ namespace NRefactoryToBooConverter @@ -186,7 +192,7 @@ namespace NRefactoryToBooConverter
ConvertParameters(propertyDeclaration.Parameters, m.Parameters);
m.EndSourceLocation = GetLocation(propertyDeclaration.EndLocation);
m.Type = ConvertTypeReference(propertyDeclaration.TypeReference);
m.ExplicitInfo = ConvertInterfaceImplementations(propertyDeclaration.InterfaceImplementations, propertyDeclaration, propertyDeclaration.Name);
m.ExplicitInfo = ConvertInterfaceImplementations(propertyDeclaration.InterfaceImplementations, propertyDeclaration, m);
if (!propertyDeclaration.IsWriteOnly) {
m.Getter = new B.Method(GetLexicalInfo(propertyDeclaration.GetRegion));
if (propertyDeclaration.GetRegion != null) {
@ -214,14 +220,15 @@ namespace NRefactoryToBooConverter @@ -214,14 +220,15 @@ namespace NRefactoryToBooConverter
indexerDeclaration.Modifier |= Modifier.Default;
B.Property m = new B.Property(GetLexicalInfo(indexerDeclaration));
m.Name = DefaultIndexerName;
m.Modifiers = ConvertModifier(indexerDeclaration, B.TypeMemberModifiers.Private);
ConvertAttributes(indexerDeclaration.Attributes, m.Attributes);
if (currentType != null) currentType.Members.Add(m);
ConvertParameters(indexerDeclaration.Parameters, m.Parameters);
m.EndSourceLocation = GetLocation(indexerDeclaration.EndLocation);
m.Type = ConvertTypeReference(indexerDeclaration.TypeReference);
m.ExplicitInfo = ConvertInterfaceImplementations(indexerDeclaration.InterfaceImplementations, indexerDeclaration, "this");
m.Name = "this";
m.ExplicitInfo = ConvertInterfaceImplementations(indexerDeclaration.InterfaceImplementations, indexerDeclaration, m);
m.Name = DefaultIndexerName;
if (!indexerDeclaration.IsWriteOnly) {
m.Getter = new B.Method(GetLexicalInfo(indexerDeclaration.GetRegion));
if (indexerDeclaration.GetRegion != null) {

6
src/AddIns/BackendBindings/Boo/NRefactoryToBooConverter/Test/MemberTests.cs

@ -92,6 +92,12 @@ namespace NRefactoryToBooConverter.Tests @@ -92,6 +92,12 @@ namespace NRefactoryToBooConverter.Tests
TestInClass("void Main() {}", "private def Main() as System.Void:\n\tpass");
}
[Test]
public void ExplicitInterfaceImplementationMethod()
{
TestInClass("void IDisposable.Dispose() {}", "def IDisposable.Dispose() as System.Void:\n\tpass");
}
[Test]
public void MethodWithAttribute()
{

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

@ -552,6 +552,8 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -552,6 +552,8 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
outputFormatter.Space();
nodeTracker.TrackedVisit(propertyDeclaration.TypeReference, data);
PrintInterfaceImplementations(propertyDeclaration.InterfaceImplementations);
outputFormatter.NewLine();
if (!IsAbstract(propertyDeclaration)) {
@ -635,6 +637,8 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -635,6 +637,8 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
outputFormatter.PrintToken(Tokens.As);
outputFormatter.Space();
nodeTracker.TrackedVisit(eventDeclaration.TypeReference, data);
PrintInterfaceImplementations(eventDeclaration.InterfaceImplementations);
outputFormatter.NewLine();
if (customEvent) {
@ -655,6 +659,22 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -655,6 +659,22 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
return null;
}
void PrintInterfaceImplementations(IList<InterfaceImplementation> list)
{
if (list == null || list.Count == 0)
return;
outputFormatter.Space();
outputFormatter.PrintToken(Tokens.Implements);
for (int i = 0; i < list.Count; i++) {
if (i > 0)
outputFormatter.PrintToken(Tokens.Comma);
outputFormatter.Space();
nodeTracker.TrackedVisit(list[i].InterfaceType, null);
outputFormatter.PrintToken(Tokens.Dot);
outputFormatter.PrintIdentifier(list[i].MemberName);
}
}
public object Visit(EventAddRegion eventAddRegion, object data)
{
VisitAttributes(eventAddRegion.Attributes, data);
@ -791,6 +811,9 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -791,6 +811,9 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
outputFormatter.Space();
nodeTracker.TrackedVisit(methodDeclaration.TypeReference, data);
}
PrintInterfaceImplementations(methodDeclaration.InterfaceImplementations);
outputFormatter.NewLine();
if (!IsAbstract(methodDeclaration)) {
@ -896,6 +919,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -896,6 +919,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
outputFormatter.PrintToken(Tokens.As);
outputFormatter.Space();
nodeTracker.TrackedVisit(indexerDeclaration.TypeReference, data);
PrintInterfaceImplementations(indexerDeclaration.InterfaceImplementations);
outputFormatter.NewLine();
++outputFormatter.IndentationLevel;
@ -1024,7 +1048,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -1024,7 +1048,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
break;
case OverloadableOperatorType.IsFalse:
outputFormatter.PrintText("IsFalse");
break;
break;
case OverloadableOperatorType.Like:
op = Tokens.Like;
break;

7
src/Libraries/NRefactory/Test/Output/VBNet/VBNetOutputTest.cs

@ -214,6 +214,13 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter @@ -214,6 +214,13 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter
TestTypeMember("Public MustOverride Function Run() As Boolean");
}
[Test]
public void InterfaceImplementingMethod()
{
TestTypeMember("Public Sub Run() Implements SomeInterface.Run\nEnd Sub");
TestTypeMember("Public Function Run() As Boolean Implements SomeInterface.Bla\nEnd Function");
}
[Test]
public void Interface()
{

15
src/Main/Base/Project/Src/Dom/LanguageProperties.cs

@ -106,6 +106,15 @@ namespace ICSharpCode.SharpDevelop.Dom @@ -106,6 +106,15 @@ namespace ICSharpCode.SharpDevelop.Dom
}
}
/// <summary>
/// Gets if the language supports implicit interface implementations.
/// </summary>
public virtual bool SupportsImplicitInterfaceImplementation {
get {
return true;
}
}
public virtual bool ShowInNamespaceCompletion(IClass c)
{
return true;
@ -166,6 +175,12 @@ namespace ICSharpCode.SharpDevelop.Dom @@ -166,6 +175,12 @@ namespace ICSharpCode.SharpDevelop.Dom
}
}
public override bool SupportsImplicitInterfaceImplementation {
get {
return false;
}
}
public override bool CanImportClasses {
get {
return true;

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

@ -361,20 +361,20 @@ namespace ICSharpCode.SharpDevelop.Refactoring @@ -361,20 +361,20 @@ namespace ICSharpCode.SharpDevelop.Refactoring
return member.DeclaringType.FullyQualifiedName;
}
public virtual void ImplementInterface(IReturnType interf, IDocument document, bool explicitImpl, IClass targetClass)
public virtual void ImplementInterface(IReturnType interf, IDocument document, bool explicitImpl, ModifierEnum implModifier, IClass targetClass)
{
ClassFinder context = new ClassFinder(targetClass, targetClass.Region.BeginLine + 1, 0);
TypeReference interfaceReference = ConvertType(interf, context);
Modifier modifier = ConvertModifier(implModifier);
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;
ed.InterfaceImplementations.Add(new InterfaceImplementation(interfaceReference, ed.Name));
}
ed.Modifier = modifier;
nodes.Add(ed);
}
}
@ -383,16 +383,14 @@ namespace ICSharpCode.SharpDevelop.Refactoring @@ -383,16 +383,14 @@ namespace ICSharpCode.SharpDevelop.Refactoring
if (targetClassProperties.Find(delegate(IProperty tp) { return p.Name == tp.Name; }) == null) {
AttributedNode pd = ConvertMember(p, context);
if (explicitImpl) {
InterfaceImplementation impl = new InterfaceImplementation(ConvertType(interf, context), p.Name);
InterfaceImplementation impl = new InterfaceImplementation(interfaceReference, p.Name);
if (pd is IndexerDeclaration) {
((IndexerDeclaration)pd).InterfaceImplementations.Add(impl);
} else {
((PropertyDeclaration)pd).InterfaceImplementations.Add(impl);
}
pd.Modifier = Modifier.None;
} else {
pd.Modifier = Modifier.Public;
}
pd.Modifier = modifier;
nodes.Add(pd);
}
}
@ -402,14 +400,14 @@ namespace ICSharpCode.SharpDevelop.Refactoring @@ -402,14 +400,14 @@ namespace ICSharpCode.SharpDevelop.Refactoring
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;
MethodDeclaration md = ConvertMember(m, context) as MethodDeclaration;
if (md != null) {
if (explicitImpl) {
md.InterfaceImplementations.Add(new InterfaceImplementation(interfaceReference, md.Name));
}
md.Modifier = modifier;
nodes.Add(md);
}
nodes.Add(md);
}
}
InsertCodeInClass(targetClass, document, nodes.ToArray());

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

@ -69,7 +69,7 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Commands @@ -69,7 +69,7 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Commands
return list.ToArray();
}
void AddImplementInterfaceCommandItems(List<ToolStripItem> subItems, IClass c, bool explicitImpl)
void AddImplementInterfaceCommandItems(List<ToolStripItem> subItems, IClass c, bool explicitImpl, ModifierEnum modifier)
{
CodeGenerator codeGen = c.ProjectContent.Language.CodeGenerator;
foreach (IReturnType rt in c.BaseTypes) {
@ -78,7 +78,7 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Commands @@ -78,7 +78,7 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Commands
EventHandler eh = delegate {
IDocument d = GetDocument(c);
if (d != null)
codeGen.ImplementInterface(rt, d, explicitImpl, c);
codeGen.ImplementInterface(rt, d, explicitImpl, modifier, c);
ParserService.ParseCurrentViewContent();
};
subItems.Add(new MenuCommand(interf.Name, eh));
@ -91,14 +91,23 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Commands @@ -91,14 +91,23 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Commands
CodeGenerator codeGen = c.ProjectContent.Language.CodeGenerator;
if (codeGen == null) return;
List<ToolStripItem> subItems = new List<ToolStripItem>();
AddImplementInterfaceCommandItems(subItems, c, false);
if (subItems.Count > 0) {
list.Add(new ICSharpCode.Core.Menu("${res:SharpDevelop.Refactoring.ImplementInterfaceImplicit}", subItems.ToArray()));
subItems = new List<ToolStripItem>();
if (c.ProjectContent.Language.SupportsImplicitInterfaceImplementation) {
AddImplementInterfaceCommandItems(subItems, c, false, ModifierEnum.Public);
if (subItems.Count > 0) {
list.Add(new ICSharpCode.Core.Menu("${res:SharpDevelop.Refactoring.ImplementInterfaceImplicit}", subItems.ToArray()));
subItems = new List<ToolStripItem>();
}
AddImplementInterfaceCommandItems(subItems, c, true, ModifierEnum.None);
} else {
AddImplementInterfaceCommandItems(subItems, c, true, ModifierEnum.Public);
}
AddImplementInterfaceCommandItems(subItems, c, true);
if (subItems.Count > 0) {
list.Add(new ICSharpCode.Core.Menu("${res:SharpDevelop.Refactoring.ImplementInterfaceExplicit}", subItems.ToArray()));
if (c.ProjectContent.Language.SupportsImplicitInterfaceImplementation) {
list.Add(new ICSharpCode.Core.Menu("${res:SharpDevelop.Refactoring.ImplementInterfaceExplicit}", subItems.ToArray()));
} else {
list.Add(new ICSharpCode.Core.Menu("${res:SharpDevelop.Refactoring.ImplementInterface}", subItems.ToArray()));
}
}
}

Loading…
Cancel
Save