Browse Source

[VB10]

- removed returnTypeAttributes from OperatorDeclaration
- implemented automatic properties in Parser
- added Initializer property
- added Unit Tests

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/vbnet@5783 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
pull/1/head
Siegfried Pammer 16 years ago
parent
commit
bb59db87f2
  1. 2
      src/Libraries/NRefactory/NRefactoryASTGenerator/AST/TypeLevel.cs
  2. 38
      src/Libraries/NRefactory/Project/Src/Ast/Generated.cs
  3. 2580
      src/Libraries/NRefactory/Project/Src/Parser/VBNet/Parser.cs
  4. 62
      src/Libraries/NRefactory/Project/Src/Parser/VBNet/VBNET.ATG
  5. 53
      src/Libraries/NRefactory/Project/Src/Parser/VBNet/VBNetParser.cs
  6. 9
      src/Libraries/NRefactory/Project/Src/Visitors/AbstractASTVisitor.cs
  7. 16
      src/Libraries/NRefactory/Project/Src/Visitors/AbstractAstTransformer.cs
  8. 74
      src/Libraries/NRefactory/Test/Parser/TypeLevel/PropertyDeclarationTests.cs

2
src/Libraries/NRefactory/NRefactoryASTGenerator/AST/TypeLevel.cs

@ -159,7 +159,6 @@ namespace NRefactoryASTGenerator.Ast @@ -159,7 +159,6 @@ namespace NRefactoryASTGenerator.Ast
class OperatorDeclaration : MethodDeclaration
{
ConversionType conversionType;
List<AttributeSection> returnTypeAttributes;
OverloadableOperatorType overloadableOperator;
}
@ -185,6 +184,7 @@ namespace NRefactoryASTGenerator.Ast @@ -185,6 +184,7 @@ namespace NRefactoryASTGenerator.Ast
Location bodyEnd;
PropertyGetRegion getRegion;
PropertySetRegion setRegion;
Expression initializer;
public PropertyDeclaration(Modifiers modifier, List<AttributeSection> attributes,
string name, List<ParameterDeclarationExpression> parameters)

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

@ -2991,8 +2991,6 @@ public Location ExtendedEndLocation { get; set; } @@ -2991,8 +2991,6 @@ public Location ExtendedEndLocation { get; set; }
ConversionType conversionType;
List<AttributeSection> returnTypeAttributes;
OverloadableOperatorType overloadableOperator;
public ConversionType ConversionType {
@ -3004,15 +3002,6 @@ public Location ExtendedEndLocation { get; set; } @@ -3004,15 +3002,6 @@ public Location ExtendedEndLocation { get; set; }
}
}
public List<AttributeSection> ReturnTypeAttributes {
get {
return returnTypeAttributes;
}
set {
returnTypeAttributes = value ?? new List<AttributeSection>();
}
}
public OverloadableOperatorType OverloadableOperator {
get {
return overloadableOperator;
@ -3023,7 +3012,6 @@ public Location ExtendedEndLocation { get; set; } @@ -3023,7 +3012,6 @@ public Location ExtendedEndLocation { get; set; }
}
public OperatorDeclaration() {
returnTypeAttributes = new List<AttributeSection>();
}
public bool IsConversionOperator {
@ -3037,10 +3025,9 @@ public Location ExtendedEndLocation { get; set; } @@ -3037,10 +3025,9 @@ public Location ExtendedEndLocation { get; set; }
}
public override string ToString() {
return string.Format("[OperatorDeclaration ConversionType={0} ReturnTypeAttributes={1} OverloadableOper" +
"ator={2} Body={3} HandlesClause={4} Templates={5} IsExtensionMethod={6} Interfac" +
"eImplementations={7} TypeReference={8} Name={9} Parameters={10} Attributes={11} " +
"Modifier={12}]", ConversionType, GetCollectionString(ReturnTypeAttributes), OverloadableOperator, Body, GetCollectionString(HandlesClause), GetCollectionString(Templates), IsExtensionMethod, GetCollectionString(InterfaceImplementations), TypeReference, Name, GetCollectionString(Parameters), GetCollectionString(Attributes), Modifier);
return string.Format("[OperatorDeclaration ConversionType={0} OverloadableOperator={1} Body={2} Handles" +
"Clause={3} Templates={4} IsExtensionMethod={5} InterfaceImplementations={6} Type" +
"Reference={7} Name={8} Parameters={9} Attributes={10} Modifier={11}]", ConversionType, OverloadableOperator, Body, GetCollectionString(HandlesClause), GetCollectionString(Templates), IsExtensionMethod, GetCollectionString(InterfaceImplementations), TypeReference, Name, GetCollectionString(Parameters), GetCollectionString(Attributes), Modifier);
}
}
@ -3299,6 +3286,8 @@ public Location ExtendedEndLocation { get; set; } @@ -3299,6 +3286,8 @@ public Location ExtendedEndLocation { get; set; }
PropertySetRegion setRegion;
Expression initializer;
public Location BodyStart {
get {
return bodyStart;
@ -3337,6 +3326,16 @@ public Location ExtendedEndLocation { get; set; } @@ -3337,6 +3326,16 @@ public Location ExtendedEndLocation { get; set; }
}
}
public Expression Initializer {
get {
return initializer;
}
set {
initializer = value ?? Expression.Null;
if (!initializer.IsNull) initializer.Parent = this;
}
}
public PropertyDeclaration(Modifiers modifier, List<AttributeSection> attributes, string name, List<ParameterDeclarationExpression> parameters) {
Modifier = modifier;
Attributes = attributes;
@ -3346,6 +3345,7 @@ public Location ExtendedEndLocation { get; set; } @@ -3346,6 +3345,7 @@ public Location ExtendedEndLocation { get; set; }
bodyEnd = Location.Empty;
getRegion = PropertyGetRegion.Null;
setRegion = PropertySetRegion.Null;
initializer = Expression.Null;
}
public bool HasGetRegion {
@ -3395,9 +3395,9 @@ public Location ExtendedEndLocation { get; set; } @@ -3395,9 +3395,9 @@ public Location ExtendedEndLocation { get; set; }
}
public override string ToString() {
return string.Format("[PropertyDeclaration BodyStart={0} BodyEnd={1} GetRegion={2} SetRegion={3} Interf" +
"aceImplementations={4} TypeReference={5} Name={6} Parameters={7} Attributes={8} " +
"Modifier={9}]", BodyStart, BodyEnd, GetRegion, SetRegion, GetCollectionString(InterfaceImplementations), TypeReference, Name, GetCollectionString(Parameters), GetCollectionString(Attributes), Modifier);
return string.Format("[PropertyDeclaration BodyStart={0} BodyEnd={1} GetRegion={2} SetRegion={3} Initia" +
"lizer={4} InterfaceImplementations={5} TypeReference={6} Name={7} Parameters={8}" +
" Attributes={9} Modifier={10}]", BodyStart, BodyEnd, GetRegion, SetRegion, Initializer, GetCollectionString(InterfaceImplementations), TypeReference, Name, GetCollectionString(Parameters), GetCollectionString(Attributes), Modifier);
}
}

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

File diff suppressed because it is too large Load Diff

62
src/Libraries/NRefactory/Project/Src/Parser/VBNet/VBNET.ATG

@ -890,7 +890,16 @@ StructureMemberDecl<ModifierList m, List<AttributeSection> attributes> @@ -890,7 +890,16 @@ StructureMemberDecl<ModifierList m, List<AttributeSection> attributes>
Identifier (. name = t.val; .)
TypeParameterList<templates>
[ "(" [ FormalParameterList<p> ] ")" ]
["As" { AttributeSection<out returnTypeAttributeSection> } TypeName<out type> ]
["As" {
AttributeSection<out returnTypeAttributeSection>
(.
if (returnTypeAttributeSection != null) {
returnTypeAttributeSection.AttributeTarget = "return";
attributes.Add(returnTypeAttributeSection);
}
.)
}
TypeName<out type> ]
(.
if(type == null) {
type = new TypeReference("System.Object", true);
@ -918,10 +927,7 @@ StructureMemberDecl<ModifierList m, List<AttributeSection> attributes> @@ -918,10 +927,7 @@ StructureMemberDecl<ModifierList m, List<AttributeSection> attributes>
Templates = templates,
InterfaceImplementations = implementsClause
};
if (returnTypeAttributeSection != null) {
returnTypeAttributeSection.AttributeTarget = "return";
methodDeclaration.Attributes.Add(returnTypeAttributeSection);
}
compilationUnit.AddChild(methodDeclaration);
.)
|
@ -936,10 +942,6 @@ StructureMemberDecl<ModifierList m, List<AttributeSection> attributes> @@ -936,10 +942,6 @@ StructureMemberDecl<ModifierList m, List<AttributeSection> attributes>
HandlesClause = handlesClause,
InterfaceImplementations = implementsClause
};
if (returnTypeAttributeSection != null) {
returnTypeAttributeSection.AttributeTarget = "return";
methodDeclaration.Attributes.Add(returnTypeAttributeSection);
}
compilationUnit.AddChild(methodDeclaration);
@ -1064,20 +1066,45 @@ StructureMemberDecl<ModifierList m, List<AttributeSection> attributes> @@ -1064,20 +1066,45 @@ StructureMemberDecl<ModifierList m, List<AttributeSection> attributes>
m.Check(Modifiers.VBProperties);
Location startPos = t.Location;
List<InterfaceImplementation> implementsClause = null;
AttributeSection returnTypeAttributeSection = null;
Expression initializer = null;
.)
Identifier (. string propertyName = t.val; .)
[ "(" [ FormalParameterList<p> ] ")" ]
[ "As" TypeName<out type> ]
[
"As" {
AttributeSection<out returnTypeAttributeSection>
(.
if (returnTypeAttributeSection != null) {
returnTypeAttributeSection.AttributeTarget = "return";
attributes.Add(returnTypeAttributeSection);
}
.)
}
(
IF (IsNewExpression()) ObjectCreateExpression<out initializer>
(.
if (initializer is ObjectCreateExpression) {
type = ((ObjectCreateExpression)initializer).CreateType.Clone();
} else {
type = ((ArrayCreateExpression)initializer).CreateType.Clone();
}
.)
|
TypeName<out type>
)
]
(.
if(type == null) {
type = new TypeReference("System.Object", true);
}
.)
[ "=" VariableInitializer<out initializer> ]
[ ImplementsClause<out implementsClause> ]
EndOfStmt
(
/* abstract properties without a body */
IF(IsMustOverride(m))
IF(IsMustOverride(m) || IsAutomaticProperty())
(.
PropertyDeclaration pDecl = new PropertyDeclaration(propertyName, type, m.Modifier, attributes);
pDecl.StartLocation = m.GetDeclarationLocation(startPos);
@ -1085,6 +1112,8 @@ StructureMemberDecl<ModifierList m, List<AttributeSection> attributes> @@ -1085,6 +1112,8 @@ StructureMemberDecl<ModifierList m, List<AttributeSection> attributes>
pDecl.TypeReference = type;
pDecl.InterfaceImplementations = implementsClause;
pDecl.Parameters = p;
if (initializer != null)
pDecl.Initializer = initializer;
compilationUnit.AddChild(pDecl);
.)
|
@ -1105,7 +1134,7 @@ StructureMemberDecl<ModifierList m, List<AttributeSection> attributes> @@ -1105,7 +1134,7 @@ StructureMemberDecl<ModifierList m, List<AttributeSection> attributes>
(.
pDecl.GetRegion = getRegion;
pDecl.SetRegion = setRegion;
pDecl.BodyEnd = t.EndLocation;
pDecl.BodyEnd = t.Location; // t = EndOfStmt; not "Property"
compilationUnit.AddChild(pDecl);
.)
)
@ -1181,7 +1210,6 @@ StructureMemberDecl<ModifierList m, List<AttributeSection> attributes> @@ -1181,7 +1210,6 @@ StructureMemberDecl<ModifierList m, List<AttributeSection> attributes>
OverloadableOperatorType operatorType;
AttributeSection section;
List<ParameterDeclarationExpression> parameters = new List<ParameterDeclarationExpression>();
List<AttributeSection> returnTypeAttributes = new List<AttributeSection>();
.)
OverloadableOperator<out operatorType>
"(" [ "ByVal" ] Identifier (. operandName = t.val; .)
@ -1196,7 +1224,12 @@ StructureMemberDecl<ModifierList m, List<AttributeSection> attributes> @@ -1196,7 +1224,12 @@ StructureMemberDecl<ModifierList m, List<AttributeSection> attributes>
}
")"
(. Location endPos = t.EndLocation; .)
[ "As" { AttributeSection<out section> (. returnTypeAttributes.Add(section); .) } TypeName<out returnType> (. endPos = t.EndLocation; .) ]
[ "As" { AttributeSection<out section>
(. if (section != null) {
section.AttributeTarget = "return";
attributes.Add(section);
} .)
} TypeName<out returnType> (. endPos = t.EndLocation; .) ]
EOL
Block<out stmt> "End" "Operator" EndOfStmt
(.
@ -1207,7 +1240,6 @@ StructureMemberDecl<ModifierList m, List<AttributeSection> attributes> @@ -1207,7 +1240,6 @@ StructureMemberDecl<ModifierList m, List<AttributeSection> attributes>
TypeReference = returnType,
OverloadableOperator = operatorType,
ConversionType = opConversionType,
ReturnTypeAttributes = returnTypeAttributes,
Body = (BlockStatement)stmt,
StartLocation = m.GetDeclarationLocation(startPos),
EndLocation = endPos

53
src/Libraries/NRefactory/Project/Src/Parser/VBNet/VBNetParser.cs

@ -5,12 +5,14 @@ @@ -5,12 +5,14 @@
// <version>$Revision$</version>
// </file>
using ICSharpCode.NRefactory.Visitors;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using ICSharpCode.NRefactory.Ast;
using ICSharpCode.NRefactory.Visitors;
namespace ICSharpCode.NRefactory.Parser.VB
{
@ -173,6 +175,10 @@ namespace ICSharpCode.NRefactory.Parser.VB @@ -173,6 +175,10 @@ namespace ICSharpCode.NRefactory.Parser.VB
bool IsObjectCreation() {
return la.kind == Tokens.As && Peek(1).kind == Tokens.New;
}
bool IsNewExpression() {
return la.kind == Tokens.New;
}
/*
True, if "<" is followed by the ident "assembly" or "module"
@ -256,15 +262,52 @@ namespace ICSharpCode.NRefactory.Parser.VB @@ -256,15 +262,52 @@ namespace ICSharpCode.NRefactory.Parser.VB
int peek = Peek(1).kind;
return la.kind == Tokens.Resume && peek == Tokens.Next;
}
/*
True, if ident/literal integer is followed by ":"
*/
/// <summary>
/// Returns True, if ident/literal integer is followed by ":"
/// </summary>
bool IsLabel()
{
return (la.kind == Tokens.Identifier || la.kind == Tokens.LiteralInteger)
&& Peek(1).kind == Tokens.Colon;
}
/// <summary>
/// Returns true if a property declaration is an automatic property.
/// </summary>
bool IsAutomaticProperty()
{
lexer.StartPeek();
Token tn = la;
int braceCount = 0;
// look for attributes
while (tn.kind == Tokens.LessThan) {
while (braceCount > 0 || tn.kind != Tokens.GreaterThan) {
tn = lexer.Peek();
if (tn.kind == Tokens.OpenParenthesis)
braceCount++;
if (tn.kind == Tokens.CloseParenthesis)
braceCount--;
}
Debug.Assert(tn.kind == Tokens.GreaterThan);
tn = lexer.Peek();
}
// look for modifiers
var allowedTokens = new[] {
Tokens.Public, Tokens.Protected,
Tokens.Friend, Tokens.Private
};
while (allowedTokens.Contains(tn.kind))
tn = lexer.Peek();
if (tn.Kind != Tokens.Get && tn.Kind != Tokens.Set)
return true;
return false;
}
bool IsNotStatementSeparator()
{

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

@ -704,7 +704,6 @@ namespace ICSharpCode.NRefactory.Visitors { @@ -704,7 +704,6 @@ namespace ICSharpCode.NRefactory.Visitors {
Debug.Assert((operatorDeclaration.TypeReference != null));
Debug.Assert((operatorDeclaration.Body != null));
Debug.Assert((operatorDeclaration.Templates != null));
Debug.Assert((operatorDeclaration.ReturnTypeAttributes != null));
foreach (AttributeSection o in operatorDeclaration.Attributes) {
Debug.Assert(o != null);
o.AcceptVisitor(this, data);
@ -723,10 +722,6 @@ namespace ICSharpCode.NRefactory.Visitors { @@ -723,10 +722,6 @@ namespace ICSharpCode.NRefactory.Visitors {
Debug.Assert(o != null);
o.AcceptVisitor(this, data);
}
foreach (AttributeSection o in operatorDeclaration.ReturnTypeAttributes) {
Debug.Assert(o != null);
o.AcceptVisitor(this, data);
}
return null;
}
@ -779,6 +774,7 @@ namespace ICSharpCode.NRefactory.Visitors { @@ -779,6 +774,7 @@ namespace ICSharpCode.NRefactory.Visitors {
Debug.Assert((propertyDeclaration.TypeReference != null));
Debug.Assert((propertyDeclaration.GetRegion != null));
Debug.Assert((propertyDeclaration.SetRegion != null));
Debug.Assert((propertyDeclaration.Initializer != null));
foreach (AttributeSection o in propertyDeclaration.Attributes) {
Debug.Assert(o != null);
o.AcceptVisitor(this, data);
@ -793,7 +789,8 @@ namespace ICSharpCode.NRefactory.Visitors { @@ -793,7 +789,8 @@ namespace ICSharpCode.NRefactory.Visitors {
}
propertyDeclaration.TypeReference.AcceptVisitor(this, data);
propertyDeclaration.GetRegion.AcceptVisitor(this, data);
return propertyDeclaration.SetRegion.AcceptVisitor(this, data);
propertyDeclaration.SetRegion.AcceptVisitor(this, data);
return propertyDeclaration.Initializer.AcceptVisitor(this, data);
}
public virtual object VisitPropertyGetRegion(PropertyGetRegion propertyGetRegion, object data) {

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

@ -1269,7 +1269,6 @@ namespace ICSharpCode.NRefactory.Visitors { @@ -1269,7 +1269,6 @@ namespace ICSharpCode.NRefactory.Visitors {
Debug.Assert((operatorDeclaration.TypeReference != null));
Debug.Assert((operatorDeclaration.Body != null));
Debug.Assert((operatorDeclaration.Templates != null));
Debug.Assert((operatorDeclaration.ReturnTypeAttributes != null));
for (int i = 0; i < operatorDeclaration.Attributes.Count; i++) {
AttributeSection o = operatorDeclaration.Attributes[i];
Debug.Assert(o != null);
@ -1320,17 +1319,6 @@ namespace ICSharpCode.NRefactory.Visitors { @@ -1320,17 +1319,6 @@ namespace ICSharpCode.NRefactory.Visitors {
else
operatorDeclaration.Templates[i] = o;
}
for (int i = 0; i < operatorDeclaration.ReturnTypeAttributes.Count; i++) {
AttributeSection o = operatorDeclaration.ReturnTypeAttributes[i];
Debug.Assert(o != null);
nodeStack.Push(o);
o.AcceptVisitor(this, data);
o = (AttributeSection)nodeStack.Pop();
if (o == null)
operatorDeclaration.ReturnTypeAttributes.RemoveAt(i--);
else
operatorDeclaration.ReturnTypeAttributes[i] = o;
}
return null;
}
@ -1407,6 +1395,7 @@ namespace ICSharpCode.NRefactory.Visitors { @@ -1407,6 +1395,7 @@ namespace ICSharpCode.NRefactory.Visitors {
Debug.Assert((propertyDeclaration.TypeReference != null));
Debug.Assert((propertyDeclaration.GetRegion != null));
Debug.Assert((propertyDeclaration.SetRegion != null));
Debug.Assert((propertyDeclaration.Initializer != null));
for (int i = 0; i < propertyDeclaration.Attributes.Count; i++) {
AttributeSection o = propertyDeclaration.Attributes[i];
Debug.Assert(o != null);
@ -1449,6 +1438,9 @@ namespace ICSharpCode.NRefactory.Visitors { @@ -1449,6 +1438,9 @@ namespace ICSharpCode.NRefactory.Visitors {
nodeStack.Push(propertyDeclaration.SetRegion);
propertyDeclaration.SetRegion.AcceptVisitor(this, data);
propertyDeclaration.SetRegion = ((PropertySetRegion)(nodeStack.Pop()));
nodeStack.Push(propertyDeclaration.Initializer);
propertyDeclaration.Initializer.AcceptVisitor(this, data);
propertyDeclaration.Initializer = ((Expression)(nodeStack.Pop()));
return null;
}

74
src/Libraries/NRefactory/Test/Parser/TypeLevel/PropertyDeclarationTests.cs

@ -120,19 +120,89 @@ namespace ICSharpCode.NRefactory.Tests.Ast @@ -120,19 +120,89 @@ namespace ICSharpCode.NRefactory.Tests.Ast
[Test]
public void VBNetSimpleGetPropertyDeclarationTest()
{
PropertyDeclaration pd = ParseUtilVBNet.ParseTypeMember<PropertyDeclaration>("Property MyProperty \nGet\nEnd Get\nEnd Property");
PropertyDeclaration pd = ParseUtilVBNet.ParseTypeMember<PropertyDeclaration>("ReadOnly Property MyProperty \nGet\nEnd Get\nEnd Property");
Assert.AreEqual("MyProperty", pd.Name);
Assert.AreEqual("System.Object", pd.TypeReference.Type);
Assert.IsTrue(pd.HasGetRegion);
Assert.IsFalse(pd.HasSetRegion);
Assert.IsTrue((pd.Modifier & Modifiers.ReadOnly) == Modifiers.ReadOnly);
}
[Test]
public void VBNetSimpleSetPropertyDeclarationTest()
{
PropertyDeclaration pd = ParseUtilVBNet.ParseTypeMember<PropertyDeclaration>("Property MyProperty \n Set\nEnd Set\nEnd Property ");
PropertyDeclaration pd = ParseUtilVBNet.ParseTypeMember<PropertyDeclaration>("WriteOnly Property MyProperty \n Set\nEnd Set\nEnd Property ");
Assert.AreEqual("MyProperty", pd.Name);
Assert.AreEqual("System.Object", pd.TypeReference.Type);
Assert.IsFalse(pd.HasGetRegion);
Assert.IsTrue(pd.HasSetRegion);
Assert.IsTrue((pd.Modifier & Modifiers.WriteOnly) == Modifiers.WriteOnly);
}
[Test]
public void VBNetAutoPropertyTest()
{
PropertyDeclaration pd = ParseUtilVBNet.ParseTypeMember<PropertyDeclaration>("Property MyProperty");
Assert.AreEqual("MyProperty", pd.Name);
Assert.AreEqual("System.Object", pd.TypeReference.Type);
Assert.IsTrue(pd.HasGetRegion);
Assert.IsTrue(pd.HasSetRegion);
Assert.AreEqual(pd.Initializer, Expression.Null);
}
[Test]
public void VBNetReadOnlyAutoPropertyTest()
{
PropertyDeclaration pd = ParseUtilVBNet.ParseTypeMember<PropertyDeclaration>("ReadOnly Property MyProperty");
Assert.AreEqual("MyProperty", pd.Name);
Assert.AreEqual("System.Object", pd.TypeReference.Type);
Assert.IsTrue(pd.HasGetRegion);
Assert.IsFalse(pd.HasSetRegion);
Assert.AreEqual(pd.Initializer, Expression.Null);
}
[Test]
public void VBNetWriteOnlyAutoPropertyTest()
{
PropertyDeclaration pd = ParseUtilVBNet.ParseTypeMember<PropertyDeclaration>("WriteOnly Property MyProperty");
Assert.AreEqual("MyProperty", pd.Name);
Assert.AreEqual("System.Object", pd.TypeReference.Type);
Assert.IsFalse(pd.HasGetRegion);
Assert.IsTrue(pd.HasSetRegion);
Assert.AreEqual(pd.Initializer, Expression.Null);
}
[Test]
public void VBNetSimpleInitializerAutoPropertyTest()
{
PropertyDeclaration pd = ParseUtilVBNet.ParseTypeMember<PropertyDeclaration>("Property MyProperty = 5");
Assert.AreEqual("MyProperty", pd.Name);
Assert.AreEqual("System.Object", pd.TypeReference.Type);
Assert.IsTrue(pd.HasGetRegion);
Assert.IsTrue(pd.HasSetRegion);
Assert.AreEqual(pd.Initializer.ToString(), new PrimitiveExpression(5).ToString());
}
[Test]
public void VBNetSimpleInitializerAutoPropertyWithTypeTest()
{
PropertyDeclaration pd = ParseUtilVBNet.ParseTypeMember<PropertyDeclaration>("Property MyProperty As Integer = 5");
Assert.AreEqual("MyProperty", pd.Name);
Assert.AreEqual("System.Int32", pd.TypeReference.Type);
Assert.IsTrue(pd.HasGetRegion);
Assert.IsTrue(pd.HasSetRegion);
Assert.AreEqual(pd.Initializer.ToString(), new PrimitiveExpression(5).ToString());
}
[Test]
public void VBNetSimpleObjectInitializerAutoPropertyTest()
{
PropertyDeclaration pd = ParseUtilVBNet.ParseTypeMember<PropertyDeclaration>("Property MyProperty As New List");
Assert.AreEqual("MyProperty", pd.Name);
Assert.AreEqual("List", pd.TypeReference.Type);
Assert.IsTrue(pd.HasGetRegion);
Assert.IsTrue(pd.HasSetRegion);
Assert.AreEqual(pd.Initializer.ToString(), new ObjectCreateExpression(new TypeReference("List"), null).ToString());
}
#endregion
}

Loading…
Cancel
Save