26 changed files with 992 additions and 93 deletions
@ -0,0 +1,117 @@
@@ -0,0 +1,117 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
||||
// software and associated documentation files (the "Software"), to deal in the Software
|
||||
// without restriction, including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
|
||||
// to whom the Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all copies or
|
||||
// substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
||||
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
|
||||
using System; |
||||
using ICSharpCode.NRefactory.TypeSystem; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp |
||||
{ |
||||
/// <summary>
|
||||
/// Represents a 'cref' reference in XML documentation.
|
||||
/// </summary>
|
||||
public class DocumentationReference : AstNode |
||||
{ |
||||
public static readonly Role<AstType> DeclaringTypeRole = new Role<AstType>("DeclaringType", AstType.Null); |
||||
public static readonly Role<AstType> ConversionOperatorReturnTypeRole = new Role<AstType>("ConversionOperatorReturnType", AstType.Null); |
||||
|
||||
/// <summary>
|
||||
/// Gets/Sets the entity type.
|
||||
/// Possible values are:
|
||||
/// <c>EntityType.Operator</c> for operators,
|
||||
/// <c>EntityType.Indexer</c> for indexers,
|
||||
/// <c>EntityType.TypeDefinition</c> for references to primitive types,
|
||||
/// and <c>EntityType.None</c> for everything else.
|
||||
/// </summary>
|
||||
public EntityType EntityType { get; set; } |
||||
|
||||
/// <summary>
|
||||
/// Gets/Sets the operator type.
|
||||
/// This property is only used when EntityType==Operator.
|
||||
/// </summary>
|
||||
public OperatorType OperatorType { get; set; } |
||||
|
||||
/// <summary>
|
||||
/// Gets/Sets whether a parameter list was provided.
|
||||
/// </summary>
|
||||
public bool HasParameterList { get; set; } |
||||
|
||||
public override NodeType NodeType { |
||||
get { return NodeType.Unknown; } |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets/Sets the declaring type.
|
||||
/// </summary>
|
||||
public AstType DeclaringType { |
||||
get { return GetChildByRole(DeclaringTypeRole); } |
||||
set { SetChildByRole(DeclaringTypeRole, value); } |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets/sets the member name.
|
||||
/// This property is only used when EntityType==None.
|
||||
/// </summary>
|
||||
public string MemberName { |
||||
get { return GetChildByRole(Roles.Identifier).Name; } |
||||
set { SetChildByRole(Roles.Identifier, Identifier.Create(value)); } |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets/Sets the return type of conversion operators.
|
||||
/// This property is only used when EntityType==Operator and OperatorType is explicit or implicit.
|
||||
/// </summary>
|
||||
public AstType ConversionOperatorReturnType { |
||||
get { return GetChildByRole(ConversionOperatorReturnTypeRole); } |
||||
set { SetChildByRole(ConversionOperatorReturnTypeRole, value); } |
||||
} |
||||
|
||||
public AstNodeCollection<AstType> TypeArguments { |
||||
get { return GetChildrenByRole (Roles.TypeArgument); } |
||||
} |
||||
|
||||
public AstNodeCollection<ParameterDeclaration> Parameters { |
||||
get { return GetChildrenByRole (Roles.Parameter); } |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) |
||||
{ |
||||
DocumentationReference o = other as DocumentationReference; |
||||
if (!(o != null && this.EntityType == o.EntityType && this.HasParameterList == o.HasParameterList)) |
||||
return false; |
||||
if (this.EntityType == EntityType.Operator) { |
||||
if (this.OperatorType != o.OperatorType) |
||||
return false; |
||||
if (this.OperatorType == OperatorType.Implicit || this.OperatorType == OperatorType.Explicit) { |
||||
if (!this.ConversionOperatorReturnType.DoMatch(o.ConversionOperatorReturnType, match)) |
||||
return false; |
||||
} |
||||
} else if (this.EntityType == EntityType.None) { |
||||
if (!MatchString(this.MemberName, o.MemberName)) |
||||
return false; |
||||
if (!this.TypeArguments.DoMatch(o.TypeArguments, match)) |
||||
return false; |
||||
} |
||||
return this.Parameters.DoMatch(o.Parameters, match); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitDocumentationReference(this, data); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,43 @@
@@ -0,0 +1,43 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
||||
// software and associated documentation files (the "Software"), to deal in the Software
|
||||
// without restriction, including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
|
||||
// to whom the Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all copies or
|
||||
// substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
||||
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
|
||||
using System; |
||||
using ICSharpCode.NRefactory.Documentation; |
||||
using ICSharpCode.NRefactory.TypeSystem; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp.TypeSystem |
||||
{ |
||||
/// <summary>
|
||||
/// DocumentationComment with C# cref lookup.
|
||||
/// </summary>
|
||||
sealed class CSharpDocumentationComment : DocumentationComment |
||||
{ |
||||
public CSharpDocumentationComment(string xmlDoc, ITypeResolveContext context) : base(xmlDoc, context) |
||||
{ |
||||
} |
||||
|
||||
public override IEntity ResolveCref(string cref) |
||||
{ |
||||
if (cref.Length > 2 && cref[1] == ':') { |
||||
// resolve ID string
|
||||
return base.ResolveCref(cref); |
||||
} |
||||
return null; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,185 @@
@@ -0,0 +1,185 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
||||
// software and associated documentation files (the "Software"), to deal in the Software
|
||||
// without restriction, including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
|
||||
// to whom the Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all copies or
|
||||
// substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
||||
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using System.Linq; |
||||
using ICSharpCode.NRefactory.CSharp; |
||||
using ICSharpCode.NRefactory.TypeSystem; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.Documentation |
||||
{ |
||||
[TestFixture] |
||||
[Ignore("Cref parsing not yet implemented")] |
||||
public class CSharpCrefLookupTests |
||||
{ |
||||
IEntity Lookup(string cref) |
||||
{ |
||||
string program = @"using System;
|
||||
using System.Collections.Generic; |
||||
/// <summary/>
|
||||
class Test { |
||||
int @int; |
||||
void M(int a) {} |
||||
|
||||
void Overloaded(int a) {} |
||||
void Overloaded(string a) {} |
||||
void Overloaded(ref int a) {} |
||||
|
||||
public int this[int index] { get { return 0; } } |
||||
|
||||
public static int operator +(Test a, int b) { return 0; } |
||||
public static implicit operator Test(int a) { return 0; } |
||||
public static implicit operator int(Test a) { return 0; } |
||||
} |
||||
interface IGeneric<A, B> { |
||||
void Test<T>(ref T[,] a); |
||||
} |
||||
class Impl<T> : IGeneric<List<string>[,], T> { |
||||
void IGeneric<List<string>[,], T>.Test<X>(ref X[,] a) {} |
||||
}";
|
||||
|
||||
var pc = new CSharpProjectContent().AddAssemblyReferences(new[] { CecilLoaderTests.Mscorlib }); |
||||
var cu = new CSharpParser().Parse(new StringReader(program), "program.cs"); |
||||
var compilation = pc.UpdateProjectContent(null, cu.ToTypeSystem()).CreateCompilation(); |
||||
var typeDefinition = compilation.MainAssembly.TopLevelTypeDefinitions.Single(); |
||||
IEntity entity = typeDefinition.Documentation.ResolveCref(cref); |
||||
Assert.IsNotNull(entity, "ResolveCref() returned null."); |
||||
return entity; |
||||
} |
||||
|
||||
[Test] |
||||
public void String() |
||||
{ |
||||
Assert.AreEqual("System.String", |
||||
Lookup("string").ReflectionName); |
||||
} |
||||
|
||||
[Test] |
||||
public void IntParse() |
||||
{ |
||||
Assert.AreEqual("M:System.Int32.Parse(System.String)", |
||||
IDStringProvider.GetIDString(Lookup("int.Parse(string)"))); |
||||
} |
||||
|
||||
[Test] |
||||
public void IntField() |
||||
{ |
||||
Assert.AreEqual("Test.int", |
||||
Lookup("@int").ReflectionName); |
||||
} |
||||
|
||||
[Test] |
||||
public void ListOfT() |
||||
{ |
||||
Assert.AreEqual("System.Collections.Generic.List`1", |
||||
Lookup("List{T}").ReflectionName); |
||||
} |
||||
|
||||
[Test] |
||||
public void ListOfTEnumerator() |
||||
{ |
||||
Assert.AreEqual("System.Collections.Generic.List`1+Enumerator", |
||||
Lookup("List{T}.Enumerator").ReflectionName); |
||||
} |
||||
|
||||
[Test] |
||||
public void IDString() |
||||
{ |
||||
Assert.AreEqual("System.Collections.Generic.List`1+Enumerator", |
||||
Lookup("T:System.Collections.Generic.List`1.Enumerator").ReflectionName); |
||||
} |
||||
|
||||
[Test] |
||||
public void M() |
||||
{ |
||||
Assert.AreEqual("M:Test.M(System.String[0:,0:])", |
||||
IDStringProvider.GetIDString(Lookup("M"))); |
||||
} |
||||
|
||||
[Test] |
||||
public void CurrentType() |
||||
{ |
||||
Assert.AreEqual("T:Test", |
||||
IDStringProvider.GetIDString(Lookup("Test"))); |
||||
} |
||||
|
||||
[Test] |
||||
public void Constructor() |
||||
{ |
||||
Assert.AreEqual("M:Test.#ctor", |
||||
IDStringProvider.GetIDString(Lookup("Test()"))); |
||||
} |
||||
|
||||
[Test] |
||||
public void Overloaded() |
||||
{ |
||||
Assert.AreEqual("M:Test.Overloaded(System.Int32)", |
||||
IDStringProvider.GetIDString(Lookup("Overloaded(int)"))); |
||||
Assert.AreEqual("M:Test.Overloaded(System.String)", |
||||
IDStringProvider.GetIDString(Lookup("Overloaded(string)"))); |
||||
Assert.AreEqual("M:Test.Overloaded(System.Int32@)", |
||||
IDStringProvider.GetIDString(Lookup("Overloaded(ref int)"))); |
||||
} |
||||
|
||||
[Test] |
||||
public void MethodInGenericInterface() |
||||
{ |
||||
Assert.AreEqual("M:XmlDocTest.IGeneric`2.Test``1(``0[0:,0:]@)", |
||||
IDStringProvider.GetIDString(Lookup("IGeneric{X, Y}.Test"))); |
||||
Assert.AreEqual("M:XmlDocTest.IGeneric`2.Test``1(``0[0:,0:]@)", |
||||
IDStringProvider.GetIDString(Lookup("IGeneric{X, Y}.Test{Z}"))); |
||||
Assert.AreEqual("M:XmlDocTest.IGeneric`2.Test``1(``0[0:,0:]@)", |
||||
IDStringProvider.GetIDString(Lookup("IGeneric{X, Y}.Test{Z}(ref Z[,])"))); |
||||
} |
||||
|
||||
[Test] |
||||
public void Indexer() |
||||
{ |
||||
Assert.AreEqual("P:Test.Item(System.Int32)", |
||||
IDStringProvider.GetIDString(Lookup("this"))); |
||||
Assert.AreEqual("P:Test.Item(System.Int32)", |
||||
IDStringProvider.GetIDString(Lookup("Test.this"))); |
||||
Assert.AreEqual("P:Test.Item(System.Int32)", |
||||
IDStringProvider.GetIDString(Lookup("Test.this[int]"))); |
||||
} |
||||
|
||||
[Test] |
||||
public void OperatorPlus() |
||||
{ |
||||
Assert.AreEqual("M:Test.op_Addition(Test,System.Int32)", |
||||
IDStringProvider.GetIDString(Lookup("operator +"))); |
||||
Assert.AreEqual("M:Test.op_Addition(Test,System.Int32)", |
||||
IDStringProvider.GetIDString(Lookup("operator +(Test, int)"))); |
||||
Assert.AreEqual("M:Test.op_Addition(Test,System.Int32)", |
||||
IDStringProvider.GetIDString(Lookup("Test.operator +(Test, int)"))); |
||||
} |
||||
|
||||
[Test] |
||||
public void ImplicitOperator() |
||||
{ |
||||
Assert.AreEqual("M:Test.op_Implicit(Test)~System.Int32", |
||||
IDStringProvider.GetIDString(Lookup("implicit operator int(Test)"))); |
||||
Assert.AreEqual("M:Test.op_Implicit(System.Int32)~Test", |
||||
IDStringProvider.GetIDString(Lookup("implicit operator Test(int)"))); |
||||
Assert.AreEqual("M:Test.op_Implicit(System.Int32)~Test", |
||||
IDStringProvider.GetIDString(Lookup("Test.implicit operator Test(int)"))); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,264 @@
@@ -0,0 +1,264 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
||||
// software and associated documentation files (the "Software"), to deal in the Software
|
||||
// without restriction, including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
|
||||
// to whom the Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all copies or
|
||||
// substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
||||
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
|
||||
using System; |
||||
using ICSharpCode.NRefactory.CSharp; |
||||
using ICSharpCode.NRefactory.CSharp.Parser; |
||||
using ICSharpCode.NRefactory.TypeSystem; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.Documentation |
||||
{ |
||||
[TestFixture] |
||||
[Ignore("Cref parsing not yet implemented")] |
||||
public class CSharpCrefParserTests |
||||
{ |
||||
[Test] |
||||
public void M() |
||||
{ |
||||
ParseUtilCSharp.AssertDocumentationReference( |
||||
"M", |
||||
new DocumentationReference { |
||||
MemberName = "M" |
||||
}); |
||||
} |
||||
|
||||
[Test] |
||||
public void This() |
||||
{ |
||||
ParseUtilCSharp.AssertDocumentationReference( |
||||
"this", |
||||
new DocumentationReference { |
||||
EntityType = EntityType.Indexer |
||||
}); |
||||
} |
||||
|
||||
[Test] |
||||
public void ThisWithParameter() |
||||
{ |
||||
ParseUtilCSharp.AssertDocumentationReference( |
||||
"this[int]", |
||||
new DocumentationReference { |
||||
EntityType = EntityType.Indexer, |
||||
HasParameterList = true, |
||||
Parameters = { new ParameterDeclaration { Type = new PrimitiveType("int") } } |
||||
}); |
||||
} |
||||
|
||||
[Test] |
||||
public void ThisWithDeclaringType() |
||||
{ |
||||
ParseUtilCSharp.AssertDocumentationReference( |
||||
"List{T}.this", |
||||
new DocumentationReference { |
||||
EntityType = EntityType.Indexer, |
||||
DeclaringType = new SimpleType("List", new SimpleType("T")) |
||||
}); |
||||
} |
||||
|
||||
[Test] |
||||
public void NestedTypeInGenericType() |
||||
{ |
||||
ParseUtilCSharp.AssertDocumentationReference( |
||||
"List{T}.Enumerator", |
||||
new DocumentationReference { |
||||
DeclaringType = new SimpleType("List", new SimpleType("T")), |
||||
MemberName = "Enumerator" |
||||
}); |
||||
} |
||||
|
||||
[Test] |
||||
public void GenericTypeWithFullNamespace() |
||||
{ |
||||
ParseUtilCSharp.AssertDocumentationReference( |
||||
"System.Collections.Generic.List{T}", |
||||
new DocumentationReference { |
||||
DeclaringType = new SimpleType("System").MemberType("Collections").MemberType("Generic"), |
||||
MemberName = "List", |
||||
TypeArguments = { new SimpleType("T") } |
||||
}); |
||||
} |
||||
|
||||
[Test] |
||||
public void PrimitiveType() |
||||
{ |
||||
ParseUtilCSharp.AssertDocumentationReference( |
||||
"int", |
||||
new DocumentationReference { |
||||
EntityType = EntityType.TypeDefinition, |
||||
DeclaringType = new PrimitiveType("int") |
||||
}); |
||||
} |
||||
|
||||
[Test] |
||||
public void VerbatimIdentifier() |
||||
{ |
||||
ParseUtilCSharp.AssertDocumentationReference( |
||||
"@int", |
||||
new DocumentationReference { |
||||
MemberName = "int" |
||||
}); |
||||
} |
||||
|
||||
[Test] |
||||
public void Generic() |
||||
{ |
||||
ParseUtilCSharp.AssertDocumentationReference( |
||||
"IGeneric{X, Y}", |
||||
new DocumentationReference { |
||||
MemberName = "IGeneric", |
||||
TypeArguments = { new SimpleType("X"), new SimpleType("Y") } |
||||
}); |
||||
} |
||||
|
||||
[Test] |
||||
public void MethodInGeneric() |
||||
{ |
||||
ParseUtilCSharp.AssertDocumentationReference( |
||||
"IGeneric{X, Y}.Test", |
||||
new DocumentationReference { |
||||
DeclaringType = new SimpleType("IGeneric", new SimpleType("X"), new SimpleType("Y")), |
||||
MemberName = "Test" |
||||
}); |
||||
} |
||||
|
||||
[Test] |
||||
public void GenericMethodInGeneric() |
||||
{ |
||||
ParseUtilCSharp.AssertDocumentationReference( |
||||
"IGeneric{X, Y}.Test{Z}", |
||||
new DocumentationReference { |
||||
DeclaringType = new SimpleType("IGeneric", new SimpleType("X"), new SimpleType("Y")), |
||||
MemberName = "Test", |
||||
TypeArguments = { new SimpleType("Z") } |
||||
}); |
||||
} |
||||
|
||||
[Test] |
||||
public void GenericMethodInGenericWithParameterList() |
||||
{ |
||||
ParseUtilCSharp.AssertDocumentationReference( |
||||
"IGeneric{X, Y}.Test{Z}(ref Z[,])", |
||||
new DocumentationReference { |
||||
DeclaringType = new SimpleType("IGeneric", new SimpleType("X"), new SimpleType("Y")), |
||||
MemberName = "Test", |
||||
TypeArguments = { new SimpleType("Z") }, |
||||
HasParameterList = true, |
||||
Parameters = { |
||||
new ParameterDeclaration { |
||||
ParameterModifier = ParameterModifier.Ref, |
||||
Type = new SimpleType("Z").MakeArrayType(2) |
||||
} |
||||
}}); |
||||
} |
||||
|
||||
[Test] |
||||
public void EmptyParameterList() |
||||
{ |
||||
ParseUtilCSharp.AssertDocumentationReference( |
||||
"Window1()", |
||||
new DocumentationReference { |
||||
MemberName = "Window1", |
||||
HasParameterList = true |
||||
}); |
||||
} |
||||
|
||||
[Test] |
||||
public void OperatorPlus() |
||||
{ |
||||
ParseUtilCSharp.AssertDocumentationReference( |
||||
"operator +", |
||||
new DocumentationReference { |
||||
EntityType = EntityType.Operator, |
||||
OperatorType = OperatorType.Addition |
||||
}); |
||||
} |
||||
|
||||
[Test] |
||||
public void OperatorPlusWithDeclaringType() |
||||
{ |
||||
ParseUtilCSharp.AssertDocumentationReference( |
||||
"Test.operator +", |
||||
new DocumentationReference { |
||||
DeclaringType = new SimpleType("Test"), |
||||
EntityType = EntityType.Operator, |
||||
OperatorType = OperatorType.Addition |
||||
}); |
||||
} |
||||
|
||||
[Test] |
||||
public void OperatorPlusWithParameterList() |
||||
{ |
||||
ParseUtilCSharp.AssertDocumentationReference( |
||||
"operator +(Test, int)", |
||||
new DocumentationReference { |
||||
EntityType = EntityType.Operator, |
||||
OperatorType = OperatorType.Addition, |
||||
HasParameterList = true, |
||||
Parameters = { |
||||
new ParameterDeclaration { Type = new SimpleType("Test") }, |
||||
new ParameterDeclaration { Type = new PrimitiveType("int") } |
||||
}}); |
||||
} |
||||
|
||||
[Test] |
||||
public void ImplicitOperator() |
||||
{ |
||||
ParseUtilCSharp.AssertDocumentationReference( |
||||
"implicit operator int", |
||||
new DocumentationReference { |
||||
EntityType = EntityType.Operator, |
||||
OperatorType = OperatorType.Implicit, |
||||
ConversionOperatorReturnType = new PrimitiveType("int") |
||||
}); |
||||
} |
||||
|
||||
[Test] |
||||
public void ExplicitOperatorWithParameterList() |
||||
{ |
||||
ParseUtilCSharp.AssertDocumentationReference( |
||||
"explicit operator int(Test)", |
||||
new DocumentationReference { |
||||
EntityType = EntityType.Operator, |
||||
OperatorType = OperatorType.Explicit, |
||||
ConversionOperatorReturnType = new PrimitiveType("int"), |
||||
HasParameterList = true, |
||||
Parameters = { |
||||
new ParameterDeclaration { Type = new SimpleType("Test") }, |
||||
} |
||||
}); |
||||
} |
||||
|
||||
[Test] |
||||
public void ExplicitOperatorWithParameterListAndDeclaringType() |
||||
{ |
||||
ParseUtilCSharp.AssertDocumentationReference( |
||||
"Test.explicit operator int(Test)", |
||||
new DocumentationReference { |
||||
EntityType = EntityType.Operator, |
||||
OperatorType = OperatorType.Explicit, |
||||
DeclaringType = new SimpleType("Test"), |
||||
ConversionOperatorReturnType = new PrimitiveType("int"), |
||||
HasParameterList = true, |
||||
Parameters = { |
||||
new ParameterDeclaration { Type = new SimpleType("Test") }, |
||||
} |
||||
}); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,62 @@
@@ -0,0 +1,62 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
||||
// software and associated documentation files (the "Software"), to deal in the Software
|
||||
// without restriction, including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
|
||||
// to whom the Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all copies or
|
||||
// substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
||||
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using System.Linq; |
||||
using ICSharpCode.NRefactory.CSharp; |
||||
using ICSharpCode.NRefactory.TypeSystem; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.Documentation |
||||
{ |
||||
[TestFixture] |
||||
public class CSharpDocumentationTests |
||||
{ |
||||
ICompilation compilation; |
||||
ITypeDefinition typeDefinition; |
||||
|
||||
void Init(string program) |
||||
{ |
||||
var pc = new CSharpProjectContent().AddAssemblyReferences(new[] { CecilLoaderTests.Mscorlib }); |
||||
var cu = new CSharpParser().Parse(new StringReader(program), "program.cs"); |
||||
compilation = pc.UpdateProjectContent(null, cu.ToTypeSystem()).CreateCompilation(); |
||||
typeDefinition = compilation.MainAssembly.TopLevelTypeDefinitions.FirstOrDefault(); |
||||
} |
||||
|
||||
[Test] |
||||
public void TypeDocumentationLookup() |
||||
{ |
||||
Init(@"using System;
|
||||
/// <summary/>
|
||||
class Test { }");
|
||||
Assert.AreEqual(" <summary/>", typeDefinition.Documentation.Xml); |
||||
} |
||||
|
||||
[Test] |
||||
public void MultilineTypeDocumentationLookup() |
||||
{ |
||||
Init(@"using System;
|
||||
/// <summary>
|
||||
/// Documentation
|
||||
/// </summary>
|
||||
class Test { }");
|
||||
Assert.AreEqual(" <summary>" + Environment.NewLine + " Documentation" + Environment.NewLine + " </summary>", typeDefinition.Documentation.Xml); |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue