* CodeGeneratorFromCompileUnitTest.cs: Removed last usage of Assertion class.
* CodeGeneratorFromTypeTest.cs: Added tests for method, property and
parameter level attributes.
* CodeMemberProperty.cs: Default value of Type is empty CodeTypeReference.
* System_test.dll.sources: Added CodeMemberPropertyTest.cs from System.CodeDom.
* VBCodeGenerator.cs: Fixed generated code for method, property and parameter
level attributes. Fixed code generated for FieldDirection.
svn path=/trunk/mcs/; revision=46516
+2005-06-26 Gert Driesen <drieseng@users.sourceforge.net>
+
+ * System_test.dll.sources: Added CodeMemberPropertyTest.cs from
+ System.CodeDom.
+
2005-06-25 Gert Driesen <drieseng@users.sourceforge.net>
* System_test.dll.sources: Added CodeMemberFieldTest.cs from
+2005-06-26 Gert Driesen <drieseng@users.sourceforge.net>
+
+ * VBCodeGenerator.cs: Fixed generated code for method, property
+ and parameter level attributes. Fixed code generated for
+ FieldDirection.
+
2005-06-25 Gert Driesen <drieseng@users.sourceforge.net>
* VBCodeGenerator.cs: Removed type shortcuts that are not valid for
{\r
GenerateCompileUnitStart (compileUnit);\r
\r
- OutputAttributes (compileUnit.AssemblyCustomAttributes, \r
- "Assembly: ", false);\r
+ OutputAttributes (compileUnit.AssemblyCustomAttributes,\r
+ "Assembly: ", LineHandling.NewLine);\r
\r
GenerateNamespaces (compileUnit);\r
\r
\r
protected override void GenerateParameterDeclarationExpression (CodeParameterDeclarationExpression e)\r
{\r
- if (e.CustomAttributes != null && e.CustomAttributes.Count > 0)\r
- OutputAttributeDeclarations (e.CustomAttributes);\r
+ if (e.CustomAttributes.Count > 0)\r
+ OutputAttributes (e.CustomAttributes, null,\r
+ LineHandling.InLine);\r
OutputDirection (e.Direction);\r
OutputTypeNamePair (e.Type, e.Name);\r
}\r
TextWriter output = Output;\r
\r
if (eventRef.CustomAttributes.Count > 0)\r
- OutputAttributes (eventRef.CustomAttributes, null, true);\r
+ OutputAttributes (eventRef.CustomAttributes, null, \r
+ LineHandling.ContinueLine);\r
\r
MemberAttributes attributes = eventRef.Attributes;\r
\r
TextWriter output = Output;\r
\r
if (field.CustomAttributes.Count > 0)\r
- OutputAttributes (field.CustomAttributes, null, true);\r
+ OutputAttributes (field.CustomAttributes, null, \r
+ LineHandling.ContinueLine);\r
\r
MemberAttributes attributes = field.Attributes;\r
OutputMemberAccessModifier (attributes);\r
TextWriter output = Output;\r
\r
if (method.CustomAttributes.Count > 0)\r
- OutputAttributeDeclarations (method.CustomAttributes);\r
+ OutputAttributes (method.CustomAttributes, null, \r
+ LineHandling.ContinueLine);\r
\r
MemberAttributes attributes = method.Attributes;\r
\r
TextWriter output = Output;\r
\r
if (property.CustomAttributes.Count > 0)\r
- OutputAttributeDeclarations (property.CustomAttributes);\r
+ OutputAttributes (property.CustomAttributes, null, \r
+ LineHandling.ContinueLine);\r
\r
MemberAttributes attributes = property.Attributes;\r
OutputMemberAccessModifier (attributes);\r
{\r
TextWriter output = Output;\r
\r
- OutputAttributes (declaration.CustomAttributes, null, true);\r
+ OutputAttributes (declaration.CustomAttributes, null, \r
+ LineHandling.ContinueLine);\r
TypeAttributes attributes = declaration.TypeAttributes;\r
OutputTypeAttributes (attributes,\r
declaration.IsStruct,\r
Output.Write (">");\r
}\r
\r
- private void OutputAttributes (CodeAttributeDeclarationCollection attributes, string prefix, bool continueLine) {\r
+ private void OutputAttributes (CodeAttributeDeclarationCollection attributes, string prefix, LineHandling lineHandling) {\r
if (attributes.Count != 0) {\r
GenerateAttributeDeclarationsStart (attributes);\r
\r
OutputAttributeDeclaration (att);\r
\r
while (enumerator.MoveNext ()) {\r
- ContinueOnNewLine (", ");\r
- Output.Write (" ");\r
+ Output.Write (", ");\r
+ if (lineHandling != LineHandling.InLine) {\r
+ ContinueOnNewLine ("");\r
+ Output.Write (" ");\r
+ }\r
att = (CodeAttributeDeclaration) enumerator.Current;\r
if (prefix != null) {\r
Output.Write (prefix);\r
}\r
GenerateAttributeDeclarationsEnd (attributes);\r
Output.Write (" ");\r
- if (continueLine) {\r
- ContinueOnNewLine ("");\r
- } else {\r
- Output.WriteLine ();\r
+\r
+ switch (lineHandling) {\r
+ case LineHandling.ContinueLine:\r
+ ContinueOnNewLine ("");\r
+ break;\r
+ case LineHandling.NewLine:\r
+ Output.WriteLine ();\r
+ break;\r
}\r
}\r
}\r
{\r
switch (direction) {\r
case FieldDirection.In:\r
- //there is no "In"\r
- break;\r
- case FieldDirection.Out:\r
Output.Write ("ByVal ");\r
break;\r
+ case FieldDirection.Out:\r
case FieldDirection.Ref:\r
Output.Write ("ByRef ");\r
break;\r
{\r
return true;\r
}\r
+\r
+ private enum LineHandling\r
+ {\r
+ InLine,\r
+ ContinueLine,\r
+ NewLine\r
+ }\r
}\r
}\r
+2005-06-26 Gert Driesen <drieseng@users.sourceforge.net>
+
+ * CodeMemberProperty.cs: Default value of Type is empty
+ CodeTypeReference.
+
2005-06-25 Gert Driesen <drieseng@users.sourceforge.net>
* CodeMemberField.cs: Default value of Type is empty CodeTypeReference.
public CodeTypeReference Type {
get {
+ if (type == null) {
+ type = new CodeTypeReference(string.Empty);
+ }
return type;
}
set {
System/UriTest.cs
System/UriTest2.cs
System.CodeDom/CodeMemberFieldTest.cs
+System.CodeDom/CodeMemberPropertyTest.cs
System.CodeDom.Compiler/IndentedTextWriterTest.cs
System.Collections.Generic/QueueTest.cs
System.Collections.Generic/StackTest.cs
+2005-06-26 Gert Driesen <drieseng@users.sourceforge.net>
+
+ * CodeGeneratorFromCompileUnitTest.cs: Removed last usage of
+ Assertion class.
+ * CodeGeneratorFromTypeTest.cs: Added tests for method, property and
+ parameter level attributes.
+
2005-06-25 Gert Driesen <drieseng@users.sourceforge.net>
* CodeGeneratorFromCompileUnitTest.cs: Added test for assembly-level
codeUnit.AssemblyCustomAttributes.Add (attrDec);
Generate ();
- Assertion.AssertEquals (string.Format (CultureInfo.InvariantCulture,
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
"<Assembly: A()> {0}", writer.NewLine), Code);
}
+ "Public Name As Integer{0}"
+ "End Class{0}", writer.NewLine), Code);
}
+
+ [Test]
+ public void PropertyMembersTypeTest1 ()
+ {
+ type.Name = "Test1";
+
+ CodeMemberProperty property = new CodeMemberProperty ();
+
+ CodeAttributeDeclaration attrDec = new CodeAttributeDeclaration ();
+ attrDec.Name = "A";
+ property.CustomAttributes.Add (attrDec);
+
+ attrDec = new CodeAttributeDeclaration ();
+ attrDec.Name = "B";
+ property.CustomAttributes.Add (attrDec);
+
+ type.Members.Add (property);
+
+ Generate ();
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "Public Class Test1{0} {0} <A(), _{0} B()> _{0} "
+ + "Private Property As System.Void{0} End Property{0}"
+ + "End Class{0}", writer.NewLine), Code);
+ }
+
+ [Test]
+ public void PropertyMembersTypeTest2 ()
+ {
+ type.Name = "Test1";
+
+ CodeMemberProperty property = new CodeMemberProperty ();
+ property.Name = "Name";
+ property.Attributes = MemberAttributes.Public;
+ property.Type = new CodeTypeReference (typeof (int));
+ type.Members.Add (property);
+
+ Generate ();
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "Public Class Test1{0}"
+ + " {0}"
+ + " Public Overridable Property Name As Integer{0}"
+ + " End Property{0}"
+ + "End Class{0}", writer.NewLine), Code);
+ }
+
+ [Test]
+ public void MethodMembersTypeTest1 ()
+ {
+ type.Name = "Test1";
+
+ CodeMemberMethod method = new CodeMemberMethod ();
+
+ CodeAttributeDeclaration attrDec = new CodeAttributeDeclaration ();
+ attrDec.Name = "A";
+ method.CustomAttributes.Add (attrDec);
+
+ attrDec = new CodeAttributeDeclaration ();
+ attrDec.Name = "B";
+ method.CustomAttributes.Add (attrDec);
+
+ type.Members.Add (method);
+
+ Generate ();
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "Public Class Test1{0}"
+ + " {0}"
+ + " <A(), _{0}"
+ + " B()> _{0}"
+ + " Private Sub (){0}"
+ + " End Sub{0}"
+ + "End Class{0}", writer.NewLine), Code);
+ }
+
+ [Test]
+ public void MethodMembersTypeTest2 ()
+ {
+ type.Name = "Test1";
+
+ CodeMemberMethod method = new CodeMemberMethod ();
+ method.Name = "Something";
+ method.Attributes = MemberAttributes.Public;
+ method.ReturnType = new CodeTypeReference (typeof (int));
+
+ CodeParameterDeclarationExpression param = new CodeParameterDeclarationExpression (
+ typeof(object), "value1");
+ method.Parameters.Add (param);
+
+ param = new CodeParameterDeclarationExpression (
+ typeof (object), "value2");
+ param.Direction = FieldDirection.In;
+ method.Parameters.Add (param);
+
+ param = new CodeParameterDeclarationExpression (typeof (int), "index");
+ param.Direction = FieldDirection.Out;
+ method.Parameters.Add (param);
+
+ param = new CodeParameterDeclarationExpression (typeof (int), "count");
+ param.Direction = FieldDirection.Ref;
+ method.Parameters.Add (param);
+
+ type.Members.Add (method);
+
+ Generate ();
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "Public Class Test1{0}"
+ + " {0}"
+ + " Public Overridable Function Something(ByVal value1 As Object, ByVal value2 As Object, ByRef index As Integer, ByRef count As Integer) As Integer{0}"
+ + " End Function{0}"
+ + "End Class{0}", writer.NewLine), Code);
+ }
+
+ [Test]
+ public void MethodMembersTypeTest3 ()
+ {
+ type.Name = "Test1";
+
+ CodeMemberMethod method = new CodeMemberMethod ();
+ method.Name = "Something";
+ method.Attributes = MemberAttributes.Public;
+ method.ReturnType = new CodeTypeReference (typeof (int));
+
+ // first parameter
+ CodeParameterDeclarationExpression param = new CodeParameterDeclarationExpression (
+ typeof (object), "value");
+
+ CodeAttributeDeclaration attrDec = new CodeAttributeDeclaration ();
+ attrDec.Name = "A";
+ param.CustomAttributes.Add (attrDec);
+
+ attrDec = new CodeAttributeDeclaration ();
+ attrDec.Name = "B";
+ param.CustomAttributes.Add (attrDec);
+
+ method.Parameters.Add (param);
+
+ // second parameter
+ param = new CodeParameterDeclarationExpression (typeof (int), "index");
+ param.Direction = FieldDirection.Out;
+ method.Parameters.Add (param);
+
+ attrDec = new CodeAttributeDeclaration ();
+ attrDec.Name = "C";
+ attrDec.Arguments.Add (new CodeAttributeArgument ("A1",
+ new CodePrimitiveExpression (false)));
+ attrDec.Arguments.Add (new CodeAttributeArgument ("A2",
+ new CodePrimitiveExpression (true)));
+ param.CustomAttributes.Add (attrDec);
+
+ attrDec = new CodeAttributeDeclaration ();
+ attrDec.Name = "D";
+ param.CustomAttributes.Add (attrDec);
+
+ type.Members.Add (method);
+
+ Generate ();
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "Public Class Test1{0}"
+ + " {0}"
+ + " Public Overridable Function Something(<A(), B()> ByVal value As Object, <C(A1:=false, A2:=true), D()> ByRef index As Integer) As Integer{0}"
+ + " End Function{0}"
+ + "End Class{0}", writer.NewLine), Code);
+ }
}
}
+2005-06-26 Gert Driesen <drieseng@users.sourceforge.net>
+
+ * CodeMemberPropertyTest.cs: Test for default value of Type property.
+
2005-06-25 Gert Driesen <drieseng@users.sourceforge.net>
* CodeMemberFieldTest.cs: Test for default value of Type property.