Browse Source

- updated parser to support automatic properties

- updated output visitors, converters
- removed returnTypeAttributes from OperatorDeclaration
- added support for Initializers in automatic properties

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/vbnet@5784 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
pull/1/head
Siegfried Pammer 16 years ago
parent
commit
782a0cb08d
  1. 3
      src/Libraries/NRefactory/Project/Src/Parser/CSharp/Parser.cs
  2. 2004
      src/Libraries/NRefactory/Project/Src/Parser/VBNet/Parser.cs
  3. 5
      src/Libraries/NRefactory/Project/Src/Parser/VBNet/VBNET.ATG
  4. 29
      src/Libraries/NRefactory/Project/Src/PrettyPrinter/VBNet/VBNetOutputVisitor.cs
  5. 5
      src/Libraries/NRefactory/Project/Src/Visitors/ToCSharpConvertVisitor.cs
  6. 9
      src/Libraries/NRefactory/Test/Output/VBNet/VBNetOutputTest.cs
  7. 6
      src/Libraries/NRefactory/Test/Parser/TypeLevel/PropertyDeclarationTests.cs

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

@ -2223,7 +2223,8 @@ out getRegion, out setRegion); @@ -2223,7 +2223,8 @@ out getRegion, out setRegion);
#line 1074 "cs.ATG"
TypeReference type;
AttributeSection section;
AttributeSection section;
Modifiers mod = Modifiers.None;
List<AttributeSection> attributes = new List<AttributeSection>();
List<ParameterDeclarationExpression> parameters = new List<ParameterDeclarationExpression>();

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

File diff suppressed because it is too large Load Diff

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

@ -1094,11 +1094,6 @@ StructureMemberDecl<ModifierList m, List<AttributeSection> attributes> @@ -1094,11 +1094,6 @@ StructureMemberDecl<ModifierList m, List<AttributeSection> attributes>
TypeName<out type>
)
]
(.
if(type == null) {
type = new TypeReference("System.Object", true);
}
.)
[ "=" VariableInitializer<out initializer> ]
[ ImplementsClause<out implementsClause> ]
EndOfStmt

29
src/Libraries/NRefactory/Project/Src/PrettyPrinter/VBNet/VBNetOutputVisitor.cs

@ -571,17 +571,34 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -571,17 +571,34 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
outputFormatter.PrintToken(Tokens.OpenParenthesis);
AppendCommaSeparatedList(propertyDeclaration.Parameters);
outputFormatter.PrintToken(Tokens.CloseParenthesis);
outputFormatter.Space();
outputFormatter.PrintToken(Tokens.As);
outputFormatter.Space();
VisitReturnTypeAttributes(propertyDeclaration.Attributes, data);
TrackedVisit(propertyDeclaration.TypeReference, data);
if (!propertyDeclaration.TypeReference.IsNull) {
outputFormatter.Space();
outputFormatter.PrintToken(Tokens.As);
outputFormatter.Space();
VisitReturnTypeAttributes(propertyDeclaration.Attributes, data);
ObjectCreateExpression init = propertyDeclaration.Initializer as ObjectCreateExpression;
if (init != null && TypeReference.AreEqualReferences(init.CreateType, propertyDeclaration.TypeReference)) {
TrackedVisit(propertyDeclaration.Initializer, data);
} else {
TrackedVisit(propertyDeclaration.TypeReference, data);
}
}
PrintInterfaceImplementations(propertyDeclaration.InterfaceImplementations);
if (!propertyDeclaration.Initializer.IsNull && !(propertyDeclaration.Initializer is ObjectCreateExpression)) {
outputFormatter.Space();
outputFormatter.PrintToken(Tokens.Assign);
outputFormatter.Space();
TrackedVisit(propertyDeclaration.Initializer, data);
}
outputFormatter.NewLine();
if (!IsAbstract(propertyDeclaration)) {
if (!IsAbstract(propertyDeclaration) && (propertyDeclaration.GetRegion.Block != NullBlockStatement.Instance || propertyDeclaration.SetRegion.Block != NullBlockStatement.Instance)) {
outputFormatter.IsInMemberBody = true;
++outputFormatter.IndentationLevel;
exitTokenStack.Push(Tokens.Property);

5
src/Libraries/NRefactory/Project/Src/Visitors/ToCSharpConvertVisitor.cs

@ -26,6 +26,7 @@ namespace ICSharpCode.NRefactory.Visitors @@ -26,6 +26,7 @@ namespace ICSharpCode.NRefactory.Visitors
// or convert to implicit interface implementation
// Modules: make all members static
// Use Convert.ToInt32 for VB casts
// Add System.Object-TypeReference to properties without TypeReference
public override object VisitTypeDeclaration(TypeDeclaration typeDeclaration, object data)
{
@ -104,6 +105,10 @@ namespace ICSharpCode.NRefactory.Visitors @@ -104,6 +105,10 @@ namespace ICSharpCode.NRefactory.Visitors
public override object VisitPropertyDeclaration(PropertyDeclaration propertyDeclaration, object data)
{
ConvertInterfaceImplementation(propertyDeclaration);
if (propertyDeclaration.TypeReference.IsNull)
propertyDeclaration.TypeReference = new TypeReference("object", true);
return base.VisitPropertyDeclaration(propertyDeclaration, data);
}

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

@ -286,6 +286,15 @@ End Using"); @@ -286,6 +286,15 @@ End Using");
"End Property");
}
[Test]
public void AutoProperty()
{
TestTypeMember("Public Property Value()");
TestTypeMember("Public Property Value() As Integer");
TestTypeMember("Public Property Value() As Integer = 5");
TestTypeMember("Public Property Value() As New List()");
}
[Test]
public void AbstractProperty()
{

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

@ -122,7 +122,6 @@ namespace ICSharpCode.NRefactory.Tests.Ast @@ -122,7 +122,6 @@ namespace ICSharpCode.NRefactory.Tests.Ast
{
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);
@ -133,7 +132,6 @@ namespace ICSharpCode.NRefactory.Tests.Ast @@ -133,7 +132,6 @@ namespace ICSharpCode.NRefactory.Tests.Ast
{
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);
@ -144,7 +142,6 @@ namespace ICSharpCode.NRefactory.Tests.Ast @@ -144,7 +142,6 @@ namespace ICSharpCode.NRefactory.Tests.Ast
{
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);
@ -155,7 +152,6 @@ namespace ICSharpCode.NRefactory.Tests.Ast @@ -155,7 +152,6 @@ namespace ICSharpCode.NRefactory.Tests.Ast
{
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);
@ -166,7 +162,6 @@ namespace ICSharpCode.NRefactory.Tests.Ast @@ -166,7 +162,6 @@ namespace ICSharpCode.NRefactory.Tests.Ast
{
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);
@ -177,7 +172,6 @@ namespace ICSharpCode.NRefactory.Tests.Ast @@ -177,7 +172,6 @@ namespace ICSharpCode.NRefactory.Tests.Ast
{
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());

Loading…
Cancel
Save