Browse Source

[VB9] Set Dom.IMethodOrProperty.IsExtensionMethod to True if <Extension> is used on VB methods.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@5693 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
pull/1/head
Siegfried Pammer 16 years ago
parent
commit
db2ee49105
  1. 3
      src/Libraries/NRefactory/Test/NRefactoryTests.csproj
  2. 3
      src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/NRefactoryResolver/NRefactoryASTConvertVisitor.cs
  3. 31
      src/Main/ICSharpCode.SharpDevelop.Dom/Tests/ICSharpCode.SharpDevelop.Dom.Tests/NRefactoryAstConverterTests.cs

3
src/Libraries/NRefactory/Test/NRefactoryTests.csproj

@ -15,7 +15,7 @@
<OutputType>Library</OutputType> <OutputType>Library</OutputType>
<OutputPath>..\..\..\..\bin\UnitTests\</OutputPath> <OutputPath>..\..\..\..\bin\UnitTests\</OutputPath>
<AllowUnsafeBlocks>False</AllowUnsafeBlocks> <AllowUnsafeBlocks>False</AllowUnsafeBlocks>
<PlatformTarget>AnyCPU</PlatformTarget> <PlatformTarget>x86</PlatformTarget>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion> <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors> <TreatWarningsAsErrors>false</TreatWarningsAsErrors>
@ -32,6 +32,7 @@
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' "> <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<DebugType>Full</DebugType> <DebugType>Full</DebugType>
<DebugSymbols>true</DebugSymbols> <DebugSymbols>true</DebugSymbols>
<StartAction>Project</StartAction>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' "> <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<DebugSymbols>False</DebugSymbols> <DebugSymbols>False</DebugSymbols>

3
src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/NRefactoryResolver/NRefactoryASTConvertVisitor.cs

@ -549,11 +549,12 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
DefaultClass currentClass = GetCurrentClass(); DefaultClass currentClass = GetCurrentClass();
DefaultMethod method = new DefaultMethod(methodDeclaration.Name, null, ConvertModifier(methodDeclaration.Modifier), region, bodyRegion, currentClass); DefaultMethod method = new DefaultMethod(methodDeclaration.Name, null, ConvertModifier(methodDeclaration.Modifier), region, bodyRegion, currentClass);
method.IsExtensionMethod = methodDeclaration.IsExtensionMethod;
method.Documentation = GetDocumentation(region.BeginLine, methodDeclaration.Attributes); method.Documentation = GetDocumentation(region.BeginLine, methodDeclaration.Attributes);
ConvertTemplates(methodDeclaration.Templates, method); ConvertTemplates(methodDeclaration.Templates, method);
method.ReturnType = CreateReturnType(methodDeclaration.TypeReference, method, TypeVisitor.ReturnTypeOptions.None); method.ReturnType = CreateReturnType(methodDeclaration.TypeReference, method, TypeVisitor.ReturnTypeOptions.None);
ConvertAttributes(methodDeclaration, method); ConvertAttributes(methodDeclaration, method);
method.IsExtensionMethod = methodDeclaration.IsExtensionMethod
|| method.Attributes.Any(att => att.AttributeType != null && att.AttributeType.FullyQualifiedName == "System.Runtime.CompilerServices.ExtensionAttribute");
if (methodDeclaration.Parameters.Count > 0) { if (methodDeclaration.Parameters.Count > 0) {
foreach (AST.ParameterDeclarationExpression par in methodDeclaration.Parameters) { foreach (AST.ParameterDeclarationExpression par in methodDeclaration.Parameters) {
method.Parameters.Add(CreateParameter(par, method)); method.Parameters.Add(CreateParameter(par, method));

31
src/Main/ICSharpCode.SharpDevelop.Dom/Tests/ICSharpCode.SharpDevelop.Dom.Tests/NRefactoryAstConverterTests.cs

@ -18,12 +18,15 @@ namespace ICSharpCode.SharpDevelop.Dom.Tests
[TestFixture] [TestFixture]
public class NRefactoryAstConverterTests public class NRefactoryAstConverterTests
{ {
ICompilationUnit Parse(string code, SupportedLanguage language, bool referenceMscorlib) ICompilationUnit Parse(string code, SupportedLanguage language, bool referenceMscorlib, params IProjectContent[] references)
{ {
DefaultProjectContent pc = new DefaultProjectContent(); DefaultProjectContent pc = new DefaultProjectContent();
if (referenceMscorlib) { if (referenceMscorlib) {
pc.AddReferencedContent(SharedProjectContentRegistryForTests.Instance.Mscorlib); pc.AddReferencedContent(SharedProjectContentRegistryForTests.Instance.Mscorlib);
} }
foreach (var reference in references) {
pc.AddReferencedContent(reference);
}
NRefactoryASTConvertVisitor visitor = new NRefactoryASTConvertVisitor(pc); NRefactoryASTConvertVisitor visitor = new NRefactoryASTConvertVisitor(pc);
using (IParser p = ParserFactory.CreateParser(language, new StringReader(code))) { using (IParser p = ParserFactory.CreateParser(language, new StringReader(code))) {
p.ParseMethodBodies = false; p.ParseMethodBodies = false;
@ -35,6 +38,11 @@ namespace ICSharpCode.SharpDevelop.Dom.Tests
return visitor.Cu; return visitor.Cu;
} }
ICompilationUnit Parse(string code, SupportedLanguage language, bool referenceMscorlib)
{
return Parse(code, language, referenceMscorlib, new IProjectContent[0]);
}
ICompilationUnit Parse(string code, SupportedLanguage language) ICompilationUnit Parse(string code, SupportedLanguage language)
{ {
return Parse(code, language, false); return Parse(code, language, false);
@ -305,5 +313,26 @@ class Outer<T1> where T1 : IDisposable {
Assert.AreEqual(0, cu.Classes[0].Methods.Count); Assert.AreEqual(0, cu.Classes[0].Methods.Count);
Assert.IsFalse(cu.Classes[0].DefaultReturnType.GetMethods().Any(m => m.IsConstructor)); Assert.IsFalse(cu.Classes[0].DefaultReturnType.GetMethods().Any(m => m.IsConstructor));
} }
[Test]
public void VBNetIsExtensionMethodTest()
{
string code = @"Imports System.Runtime.CompilerServices
Module StringExtensions
<Extension> _
Sub Print(s As String)
End Sub
End Module";
ICompilationUnit cu = Parse(code, SupportedLanguage.VBNet, true,
SharedProjectContentRegistryForTests.Instance.GetProjectContentForReference("System.Core", "System.Core"));
Assert.Greater(cu.Classes.Count, 0);
Assert.AreEqual("StringExtensions", cu.Classes[0].Name);
Assert.AreEqual(ClassType.Module, cu.Classes[0].ClassType);
Assert.Greater(cu.Classes[0].Methods.Count, 0);
Assert.IsTrue(cu.Classes[0].Methods[0].IsExtensionMethod);
Assert.AreEqual("Print", cu.Classes[0].Methods[0].Name);
}
} }
} }

Loading…
Cancel
Save