Browse Source

Added support for default parameters and variance annotations to C# parser.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@5507 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
pull/1/head
Daniel Grunwald 16 years ago
parent
commit
84f0895b3b
  1. 5
      samples/NRefactoryDemo/NRefactoryDemo.csproj
  2. 2
      src/Libraries/NRefactory/NRefactory.sln
  3. 4
      src/Libraries/NRefactory/NRefactoryASTGenerator/AST/GlobalLevel.cs
  4. 5
      src/Libraries/NRefactory/NRefactoryASTGenerator/NRefactoryASTGenerator.csproj
  5. 5
      src/Libraries/NRefactory/Project/NRefactory.csproj
  6. 3
      src/Libraries/NRefactory/Project/NRefactory.csproj.user
  7. 7
      src/Libraries/NRefactory/Project/Src/Ast/Enums.cs
  8. 21
      src/Libraries/NRefactory/Project/Src/Ast/Generated.cs
  9. 2
      src/Libraries/NRefactory/Project/Src/IAstVisitor.cs
  10. 12
      src/Libraries/NRefactory/Project/Src/Lexer/CSharp/Lexer.cs
  11. 2331
      src/Libraries/NRefactory/Project/Src/Parser/CSharp/Parser.cs
  12. 51
      src/Libraries/NRefactory/Project/Src/Parser/CSharp/cs.ATG
  13. 3
      src/Libraries/NRefactory/Project/Src/Parser/VBNet/Parser.cs
  14. 21
      src/Libraries/NRefactory/Project/Src/PrettyPrinter/CSharp/CSharpOutputVisitor.cs
  15. 2
      src/Libraries/NRefactory/Project/Src/Visitors/AbstractASTVisitor.cs
  16. 2
      src/Libraries/NRefactory/Project/Src/Visitors/AbstractAstTransformer.cs
  17. 2
      src/Libraries/NRefactory/Project/Src/Visitors/NodeTrackingAstVisitor.cs
  18. 2
      src/Libraries/NRefactory/Project/Src/Visitors/NotImplementedAstVisitor.cs
  19. 4
      src/Libraries/NRefactory/Test/Lexer/CSharp/PreprocessingTests.cs
  20. 5
      src/Libraries/NRefactory/Test/NRefactoryTests.csproj
  21. 12
      src/Libraries/NRefactory/Test/Output/CSharp/CSharpOutputTest.cs
  22. 19
      src/Libraries/NRefactory/Test/Parser/TypeLevel/MethodDeclarationTests.cs

5
samples/NRefactoryDemo/NRefactoryDemo.csproj

@ -1,4 +1,5 @@ @@ -1,4 +1,5 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<RootNamespace>NRefactoryDemo</RootNamespace>
@ -7,7 +8,7 @@ @@ -7,7 +8,7 @@
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{63199047-9D5D-474C-B3CC-62ABBB071B67}</ProjectGuid>
<SourceAnalysisOverrideSettingsFile>C:\Users\Siegfried\AppData\Roaming\ICSharpCode/SharpDevelop3.0\Settings.SourceAnalysis</SourceAnalysisOverrideSettingsFile>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<BaseIntermediateOutputPath>obj\</BaseIntermediateOutputPath>

2
src/Libraries/NRefactory/NRefactory.sln

@ -1,7 +1,7 @@ @@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Studio 2008
# SharpDevelop 3.0.0.3337
# SharpDevelop 4.0.0.5490
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NRefactory", "Project\NRefactory.csproj", "{3A9AE6AA-BC07-4A2F-972C-581E3AE2F195}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NRefactoryTests", "Test\NRefactoryTests.csproj", "{870115DD-960A-4406-A6B9-600BCDC36A03}"

4
src/Libraries/NRefactory/NRefactoryASTGenerator/AST/GlobalLevel.cs

@ -21,12 +21,16 @@ namespace NRefactoryASTGenerator.Ast @@ -21,12 +21,16 @@ namespace NRefactoryASTGenerator.Ast
public NamespaceDeclaration(string name) {}
}
enum VarianceModifier { Invariant, Covariant, Contravariant };
class TemplateDefinition : AttributedNode
{
[QuestionMarkDefault]
string name;
VarianceModifier varianceModifier;
List<TypeReference> bases;
public TemplateDefinition() {}
public TemplateDefinition(string name, List<AttributeSection> attributes) : base(attributes) {}
}

5
src/Libraries/NRefactory/NRefactoryASTGenerator/NRefactoryASTGenerator.csproj

@ -1,4 +1,5 @@ @@ -1,4 +1,5 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
<PropertyGroup>
<OutputType>Exe</OutputType>
<RootNamespace>NRefactoryASTGenerator</RootNamespace>
@ -16,7 +17,7 @@ @@ -16,7 +17,7 @@
<WarningLevel>4</WarningLevel>
<NoWarn>0169</NoWarn>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<OutputPath>bin\Debug\</OutputPath>

5
src/Libraries/NRefactory/Project/NRefactory.csproj

@ -1,4 +1,5 @@ @@ -1,4 +1,5 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
@ -23,7 +24,7 @@ @@ -23,7 +24,7 @@
<FileAlignment>4096</FileAlignment>
<RunCodeAnalysis>False</RunCodeAnalysis>
<CodeAnalysisRules>-Microsoft.Design#CA1002;-Microsoft.Design#CA1020;-Microsoft.Design#CA1051;-Microsoft.Design#CA1062;-Microsoft.Globalization#CA1303;-Microsoft.Globalization#CA1305;-Microsoft.Naming#CA1704;-Microsoft.Performance#CA1800;-Microsoft.Performance#CA1805;-Microsoft.Usage#CA2211;-Microsoft.Usage#CA2227</CodeAnalysisRules>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<Optimize>False</Optimize>

3
src/Libraries/NRefactory/Project/NRefactory.csproj.user

@ -1,4 +1,5 @@ @@ -1,4 +1,5 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
<PropertyGroup>
<LastOpenVersion>8.0.41115</LastOpenVersion>
<ProjectView>ShowAllFiles</ProjectView>

7
src/Libraries/NRefactory/Project/Src/Ast/Enums.cs

@ -119,6 +119,13 @@ namespace ICSharpCode.NRefactory.Ast @@ -119,6 +119,13 @@ namespace ICSharpCode.NRefactory.Ast
Optional = 16
}
public enum VarianceModifier
{
Invariant,
Covariant,
Contravariant
};
public enum AssignmentOperatorType
{
None,

21
src/Libraries/NRefactory/Project/Src/Ast/Generated.cs

@ -1,7 +1,7 @@ @@ -1,7 +1,7 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.20506.1
// Runtime Version:2.0.50727.4927
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
@ -4740,6 +4740,8 @@ public Location ExtendedEndLocation { get; set; } @@ -4740,6 +4740,8 @@ public Location ExtendedEndLocation { get; set; }
string name;
VarianceModifier varianceModifier;
List<TypeReference> bases;
public string Name {
@ -4751,6 +4753,15 @@ public Location ExtendedEndLocation { get; set; } @@ -4751,6 +4753,15 @@ public Location ExtendedEndLocation { get; set; }
}
}
public VarianceModifier VarianceModifier {
get {
return varianceModifier;
}
set {
varianceModifier = value;
}
}
public List<TypeReference> Bases {
get {
return bases;
@ -4760,6 +4771,11 @@ public Location ExtendedEndLocation { get; set; } @@ -4760,6 +4771,11 @@ public Location ExtendedEndLocation { get; set; }
}
}
public TemplateDefinition() {
name = "?";
bases = new List<TypeReference>();
}
public TemplateDefinition(string name, List<AttributeSection> attributes) {
Name = name;
Attributes = attributes;
@ -4771,7 +4787,8 @@ public Location ExtendedEndLocation { get; set; } @@ -4771,7 +4787,8 @@ public Location ExtendedEndLocation { get; set; }
}
public override string ToString() {
return string.Format("[TemplateDefinition Name={0} Bases={1} Attributes={2} Modifier={3}]", Name, GetCollectionString(Bases), GetCollectionString(Attributes), Modifier);
return string.Format("[TemplateDefinition Name={0} VarianceModifier={1} Bases={2} Attributes={3} Modifi" +
"er={4}]", Name, VarianceModifier, GetCollectionString(Bases), GetCollectionString(Attributes), Modifier);
}
}

2
src/Libraries/NRefactory/Project/Src/IAstVisitor.cs

@ -1,7 +1,7 @@ @@ -1,7 +1,7 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.20506.1
// Runtime Version:2.0.50727.4927
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.

12
src/Libraries/NRefactory/Project/Src/Lexer/CSharp/Lexer.cs

@ -23,7 +23,6 @@ namespace ICSharpCode.NRefactory.Parser.CSharp @@ -23,7 +23,6 @@ namespace ICSharpCode.NRefactory.Parser.CSharp
protected override Token Next()
{
int nextChar;
char ch;
bool hadLineEnd = false;
if (Line == 1 && Col == 1) {
@ -31,7 +30,12 @@ namespace ICSharpCode.NRefactory.Parser.CSharp @@ -31,7 +30,12 @@ namespace ICSharpCode.NRefactory.Parser.CSharp
hadLineEnd = true; // beginning of document
}
while ((nextChar = ReaderRead()) != -1) {
while (true) {
Location startLocation = new Location(Col, Line);
int nextChar = ReaderRead();
if (nextChar == -1)
break;
Token token;
switch (nextChar) {
@ -40,12 +44,12 @@ namespace ICSharpCode.NRefactory.Parser.CSharp @@ -40,12 +44,12 @@ namespace ICSharpCode.NRefactory.Parser.CSharp
continue;
case '\r':
case '\n':
HandleLineEnd((char)nextChar);
if (hadLineEnd) {
// second line end before getting to a token
// -> here was a blank line
specialTracker.AddEndOfLine(new Location(Col, Line));
specialTracker.AddEndOfLine(startLocation);
}
HandleLineEnd((char)nextChar);
hadLineEnd = true;
isAtLineBegin = true;
continue;

2331
src/Libraries/NRefactory/Project/Src/Parser/CSharp/Parser.cs

File diff suppressed because it is too large Load Diff

51
src/Libraries/NRefactory/Project/Src/Parser/CSharp/cs.ATG

@ -636,21 +636,14 @@ FormalParameterList<List<ParameterDeclarationExpression> parameter> @@ -636,21 +636,14 @@ FormalParameterList<List<ParameterDeclarationExpression> parameter>
.)
=
{ AttributeSection<out section> (.attributes.Add(section); .) }
(
FixedParameter<out p> (. bool paramsFound = false;
p.Attributes = attributes;
FixedParameter<out p> (. p.Attributes = attributes;
parameter.Add(p);
.)
{
"," (. attributes = new List<AttributeSection>(); if (paramsFound) Error("params array must be at end of parameter list"); .)
"," (. attributes = new List<AttributeSection>(); .)
{ AttributeSection<out section> (.attributes.Add(section); .) }
(
FixedParameter<out p> (. p.Attributes = attributes; parameter.Add(p); .)
| ParameterArray<out p> (. paramsFound = true; p.Attributes = attributes; parameter.Add(p); .)
)
}
| ParameterArray<out p> (. p.Attributes = attributes; parameter.Add(p); .)
)
.
FixedParameter<out ParameterDeclarationExpression p>
@ -658,19 +651,18 @@ FixedParameter<out ParameterDeclarationExpression p> @@ -658,19 +651,18 @@ FixedParameter<out ParameterDeclarationExpression p>
TypeReference type;
ParameterModifiers mod = ParameterModifiers.In;
Location start = la.Location;
Expression expr;
.)
=
[
"ref" (. mod = ParameterModifiers.Ref; .)
| "out" (. mod = ParameterModifiers.Out; .)
| "params" (. mod = ParameterModifiers.Params; .)
]
Type<out type> Identifier (. p = new ParameterDeclarationExpression(type, t.val, mod); p.StartLocation = start; p.EndLocation = t.Location; .)
.
ParameterArray<out ParameterDeclarationExpression p>
(. TypeReference type; .)
=
"params" Type<out type> Identifier (. p = new ParameterDeclarationExpression(type, t.val, ParameterModifiers.Params); .)
Type<out type>
Identifier (. p = new ParameterDeclarationExpression(type, t.val, mod); .)
[ "=" Expr<out expr> (. p.DefaultValue = expr; p.ParamModifier |= ParameterModifiers.Optional; .) ]
(. p.StartLocation = start; p.EndLocation = t.EndLocation; .)
.
AccessorModifiers<out ModifierList m>
@ -2343,17 +2335,32 @@ TypeArgumentList<out List<TypeReference> types, bool canBeUnbound> @@ -2343,17 +2335,32 @@ TypeArgumentList<out List<TypeReference> types, bool canBeUnbound>
TypeParameterList<List<TemplateDefinition> templates>
(.
AttributeSection section;
List<AttributeSection> attributes = new List<AttributeSection>();
TemplateDefinition template;
.)
=
"<" { AttributeSection<out section> (. attributes.Add(section); .) }
Identifier (. templates.Add(new TemplateDefinition(t.val, attributes)); .)
{ "," { AttributeSection<out section> (. attributes.Add(section); .) }
Identifier (. templates.Add(new TemplateDefinition(t.val, attributes)); .)}
"<"
VariantTypeParameter<out template> (. templates.Add(template); .)
{ ","
VariantTypeParameter<out template> (. templates.Add(template); .)
}
">"
.
VariantTypeParameter<out TemplateDefinition typeParameter>
(.
typeParameter = new TemplateDefinition();
AttributeSection section;
.)
=
{ AttributeSection<out section> (. typeParameter.Attributes.Add(section); .) }
[
"in" (. typeParameter.VarianceModifier = VarianceModifier.Contravariant; .)
| "out" (. typeParameter.VarianceModifier = VarianceModifier.Covariant; .)
]
Identifier (. typeParameter.Name = t.val; typeParameter.StartLocation = t.Location; .)
(. typeParameter.EndLocation = t.EndLocation; .)
.
TypeParameterConstraintsClause<List<TemplateDefinition> templates>
(. string name = ""; TypeReference type; .)
=

3
src/Libraries/NRefactory/Project/Src/Parser/VBNet/Parser.cs

@ -1688,7 +1688,6 @@ IsMustOverride(m)) { @@ -1688,7 +1688,6 @@ IsMustOverride(m)) {
}
compilationUnit.AddChild(methodDeclaration);
if (ParseMethodBodies) {
Block(
#line 946 "VBNET.ATG"
@ -2068,7 +2067,6 @@ out eventAccessorDeclaration); @@ -2068,7 +2067,6 @@ out eventAccessorDeclaration);
{
Error("Need to provide RaiseEvent accessor.");
}
EventDeclaration decl = new EventDeclaration {
TypeReference = type, Name = customEventName, Modifier = m.Modifier,
Attributes = attributes,
@ -6809,7 +6807,6 @@ out goToStatement); @@ -6809,7 +6807,6 @@ out goToStatement);
#line 3099 "VBNET.ATG"
string val = goToStatement.Label;
// if value is numeric, make sure that is 0
try {
long intLabel = Int64.Parse(val);

21
src/Libraries/NRefactory/Project/Src/PrettyPrinter/CSharp/CSharpOutputVisitor.cs

@ -119,6 +119,13 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -119,6 +119,13 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
outputFormatter.PrintToken(Tokens.LessThan);
for (int i = 0; i < templates.Count; i++) {
if (i > 0) PrintFormattedComma();
if (templates[i].VarianceModifier == VarianceModifier.Contravariant) {
outputFormatter.PrintToken(Tokens.In);
outputFormatter.Space();
} else if (templates[i].VarianceModifier == VarianceModifier.Covariant) {
outputFormatter.PrintToken(Tokens.Out);
outputFormatter.Space();
}
outputFormatter.PrintIdentifier(templates[i].Name);
}
outputFormatter.PrintToken(Tokens.GreaterThan);
@ -741,17 +748,18 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -741,17 +748,18 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
public override object TrackedVisitParameterDeclarationExpression(ParameterDeclarationExpression parameterDeclarationExpression, object data)
{
VisitAttributes(parameterDeclarationExpression.Attributes, data);
if (!parameterDeclarationExpression.DefaultValue.IsNull) {
outputFormatter.PrintText("[System.Runtime.InteropServices.OptionalAttribute, System.Runtime.InteropServices.DefaultParameterValueAttribute(");
TrackVisit(parameterDeclarationExpression.DefaultValue, data);
outputFormatter.PrintText(")] ");
}
OutputModifier(parameterDeclarationExpression.ParamModifier, parameterDeclarationExpression);
if (!parameterDeclarationExpression.TypeReference.IsNull) {
TrackVisit(parameterDeclarationExpression.TypeReference, data);
outputFormatter.Space();
}
outputFormatter.PrintIdentifier(parameterDeclarationExpression.ParameterName);
if (!parameterDeclarationExpression.DefaultValue.IsNull) {
outputFormatter.Space();
outputFormatter.PrintToken(Tokens.Assign);
outputFormatter.Space();
TrackVisit(parameterDeclarationExpression.DefaultValue, data);
}
return null;
}
@ -2939,9 +2947,6 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -2939,9 +2947,6 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
outputFormatter.PrintToken(Tokens.Params);
outputFormatter.Space();
}
if ((modifier & ParameterModifiers.Optional) == ParameterModifiers.Optional) {
Error(node, String.Format("Optional parameters aren't supported in C#"));
}
}
void OutputModifier(Modifiers modifier)

2
src/Libraries/NRefactory/Project/Src/Visitors/AbstractASTVisitor.cs

@ -1,7 +1,7 @@ @@ -1,7 +1,7 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.20506.1
// Runtime Version:2.0.50727.4927
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.

2
src/Libraries/NRefactory/Project/Src/Visitors/AbstractAstTransformer.cs

@ -1,7 +1,7 @@ @@ -1,7 +1,7 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.20506.1
// Runtime Version:2.0.50727.4927
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.

2
src/Libraries/NRefactory/Project/Src/Visitors/NodeTrackingAstVisitor.cs

@ -1,7 +1,7 @@ @@ -1,7 +1,7 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.20506.1
// Runtime Version:2.0.50727.4927
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.

2
src/Libraries/NRefactory/Project/Src/Visitors/NotImplementedAstVisitor.cs

@ -1,7 +1,7 @@ @@ -1,7 +1,7 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.20506.1
// Runtime Version:2.0.50727.4927
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.

4
src/Libraries/NRefactory/Test/Lexer/CSharp/PreprocessingTests.cs

@ -152,8 +152,8 @@ namespace ICSharpCode.NRefactory.Tests.Lexer.CSharp @@ -152,8 +152,8 @@ namespace ICSharpCode.NRefactory.Tests.Lexer.CSharp
List<ISpecial> specials = lexer.SpecialTracker.RetrieveSpecials();
Assert.IsTrue(specials[0] is BlankLine);
Assert.AreEqual(new Location(2, 1), specials[0].StartPosition);
Assert.AreEqual(new Location(2, 1), specials[0].EndPosition);
Assert.AreEqual(new Location(1, 1), specials[0].StartPosition);
Assert.AreEqual(new Location(1, 1), specials[0].EndPosition);
Assert.AreEqual("#region", (specials[1] as PreprocessingDirective).Cmd);
Assert.AreEqual("Region Title", (specials[1] as PreprocessingDirective).Arg);

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

@ -1,4 +1,5 @@ @@ -1,4 +1,5 @@
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
@ -16,7 +17,7 @@ @@ -16,7 +17,7 @@
<AllowUnsafeBlocks>False</AllowUnsafeBlocks>
<PlatformTarget>AnyCPU</PlatformTarget>
<WarningLevel>4</WarningLevel>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">

12
src/Libraries/NRefactory/Test/Output/CSharp/CSharpOutputTest.cs

@ -777,5 +777,17 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter @@ -777,5 +777,17 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter
{
TestProgram("extern alias Name;");
}
[Test]
public void Variance()
{
TestProgram("interface C<out X, in Y, Z>\n{\n}");
}
[Test]
public void OptionalParameters()
{
TestTypeMember("void M(int x = 0);");
}
}
}

19
src/Libraries/NRefactory/Test/Parser/TypeLevel/MethodDeclarationTests.cs

@ -282,6 +282,25 @@ namespace ICSharpCode.NRefactory.Tests.Ast @@ -282,6 +282,25 @@ namespace ICSharpCode.NRefactory.Tests.Ast
Assert.AreEqual(new Location(1, 2), md.Body.StartLocation);
Assert.AreEqual(new Location(2, 5), md.Body.EndLocation);
}
[Test]
public void CSharpOptionalParameterTest()
{
MethodDeclaration md = ParseUtilCSharp.ParseTypeMember<MethodDeclaration>(
"public void Foo(string bar = null, int baz = 0) { }"
);
Assert.AreEqual("Foo", md.Name);
Assert.AreEqual("bar", md.Parameters[0].ParameterName);
Assert.AreEqual("System.String", md.Parameters[0].TypeReference.Type);
Assert.AreEqual(ParameterModifiers.In | ParameterModifiers.Optional, md.Parameters[0].ParamModifier);
Assert.IsNull(((PrimitiveExpression)md.Parameters[0].DefaultValue).Value);
Assert.AreEqual("baz", md.Parameters[1].ParameterName);
Assert.AreEqual("System.Int32", md.Parameters[1].TypeReference.Type);
Assert.AreEqual(ParameterModifiers.In | ParameterModifiers.Optional, md.Parameters[1].ParamModifier);
Assert.AreEqual(0, ((PrimitiveExpression)md.Parameters[1].DefaultValue).Value);
}
#endregion
#region VB.NET

Loading…
Cancel
Save