Author: atsushi
Date: 2007-01-18 05:23:33 -0500 (Thu, 18 Jan 2007)
New Revision: 71244

Modified:
   trunk/mcs/class/System/Microsoft.CSharp/CSharpCodeGenerator.cs
   trunk/mcs/class/System/Microsoft.CSharp/ChangeLog
   trunk/mcs/class/System/System.CodeDom/ChangeLog
   trunk/mcs/class/System/System.CodeDom/CodeTypeReference.cs
   trunk/mcs/class/System/Test/Microsoft.CSharp/ChangeLog
   trunk/mcs/class/System/Test/Microsoft.CSharp/CodeGeneratorFromTypeTest.cs
   trunk/mcs/class/System/Test/System.CodeDom.Compiler/ChangeLog
   
trunk/mcs/class/System/Test/System.CodeDom.Compiler/CodeGeneratorFromTypeTestBase.cs
   trunk/mcs/class/System/Test/System.CodeDom/ChangeLog
   trunk/mcs/class/System/Test/System.CodeDom/CodeTypeReferenceTest.cs
Log:
2007-01-18  Atsushi Enomoto  <[EMAIL PROTECTED]>

        * CodeTypeReference.cs :
          Support generic type definition in .ctor(Type)
          Handle generic type in straightforward way in .ctor(Type), no need
          to do ToString() and Parse().
          Supply "`n" in .ctor(string,params CodeTypeReference[]).

        * CSharpCodeGenerator.cs : for GenericTypeParameter, GetTypeOutput()
          should just print its name.
          For generic type definition, print "<>". OutputTypeArguments() was
          also causing IndexOutOfRangeException.

        * CodeGeneratorFromTypeTestBase.cs :
          added GenerateGenericCodeTypeReferences() for generic type test.

        * CodeGeneratorFromTypeTest.cs :
          Added test for generic type references output.

        * CodeTypeReferenceTest.cs :
          Fixed generic type tests and let them involved in the actual tests.
          Added some more generic type tests, including generic type
          definition.



Modified: trunk/mcs/class/System/Microsoft.CSharp/CSharpCodeGenerator.cs
===================================================================
--- trunk/mcs/class/System/Microsoft.CSharp/CSharpCodeGenerator.cs      
2007-01-18 10:19:58 UTC (rev 71243)
+++ trunk/mcs/class/System/Microsoft.CSharp/CSharpCodeGenerator.cs      
2007-01-18 10:23:33 UTC (rev 71244)
@@ -1244,6 +1244,11 @@
     
                protected override string GetTypeOutput (CodeTypeReference type)
                {
+#if NET_2_0
+                       if ((type.Options & 
CodeTypeReferenceOptions.GenericTypeParameter) != 0)
+                               return type.BaseType;
+#endif
+
                        string typeOutput = null;
 
                        if (type.ArrayElementType != null) {
@@ -1260,6 +1265,7 @@
                                }
                                typeOutput += ']';
                        }
+
                        return typeOutput;
                }
 
@@ -1521,6 +1527,10 @@
                {
                        if (count == 0) {
                                return;
+                       } else if (typeArguments.Count == 0) {
+                               // generic type definition
+                               sb.Append ("<>");
+                               return;
                        }
 
                        sb.Append ('<');

Modified: trunk/mcs/class/System/Microsoft.CSharp/ChangeLog
===================================================================
--- trunk/mcs/class/System/Microsoft.CSharp/ChangeLog   2007-01-18 10:19:58 UTC 
(rev 71243)
+++ trunk/mcs/class/System/Microsoft.CSharp/ChangeLog   2007-01-18 10:23:33 UTC 
(rev 71244)
@@ -1,3 +1,10 @@
+2007-01-18  Atsushi Enomoto  <[EMAIL PROTECTED]>
+
+       * CSharpCodeGenerator.cs : for GenericTypeParameter, GetTypeOutput()
+         should just print its name.
+         For generic type definition, print "<>". OutputTypeArguments() was
+         also causing IndexOutOfRangeException.
+
 2006-12-30  Marek Habersack  <[EMAIL PROTECTED]>
 
        * CSharpCodeGenerator.cs: implement actual identifier syntax correctness

Modified: trunk/mcs/class/System/System.CodeDom/ChangeLog
===================================================================
--- trunk/mcs/class/System/System.CodeDom/ChangeLog     2007-01-18 10:19:58 UTC 
(rev 71243)
+++ trunk/mcs/class/System/System.CodeDom/ChangeLog     2007-01-18 10:23:33 UTC 
(rev 71244)
@@ -1,3 +1,11 @@
+2007-01-18  Atsushi Enomoto  <[EMAIL PROTECTED]>
+
+       * CodeTypeReference.cs :
+         Support generic type definition in .ctor(Type)
+         Handle generic type in straightforward way in .ctor(Type), no need
+         to do ToString() and Parse().
+         Supply "`n" in .ctor(string,params CodeTypeReference[]).
+
 2006-03-11  Miguel de Icaza  <[EMAIL PROTECTED]>
 
        * CodeNamespaceImportCollection.cs: It turns out that a lot of the

Modified: trunk/mcs/class/System/System.CodeDom/CodeTypeReference.cs
===================================================================
--- trunk/mcs/class/System/System.CodeDom/CodeTypeReference.cs  2007-01-18 
10:19:58 UTC (rev 71243)
+++ trunk/mcs/class/System/System.CodeDom/CodeTypeReference.cs  2007-01-18 
10:23:33 UTC (rev 71244)
@@ -76,6 +76,23 @@
                        if (baseType == null) {
                                throw new ArgumentNullException ("baseType");
                        }
+
+                       if (baseType.IsGenericParameter) {
+                               this.baseType = baseType.Name;
+                               this.codeTypeReferenceOption = 
CodeTypeReferenceOptions.GenericTypeParameter;
+                       }
+                       else if (baseType.IsGenericTypeDefinition)
+                               this.baseType = baseType.FullName;
+                       else if (baseType.IsGenericType) {
+                               this.baseType = 
baseType.GetGenericTypeDefinition ().FullName;
+                               foreach (Type arg in 
baseType.GetGenericArguments ()) {
+                                       if (arg.IsGenericParameter)
+                                               TypeArguments.Add (new 
CodeTypeReference (new CodeTypeParameter (arg.Name)));
+                                       else
+                                               TypeArguments.Add (new 
CodeTypeReference (arg));
+                               }
+                       }
+                       else
 #endif
                        if (baseType.IsArray) {
                                this.rank = baseType.GetArrayRank ();
@@ -125,6 +142,8 @@
                        this (typeName)
                {
                        TypeArguments.AddRange (typeArguments);
+                       if (this.baseType.IndexOf ('`') < 0)
+                               this.baseType += "`" + TypeArguments.Count;
                }
 #endif
 

Modified: trunk/mcs/class/System/Test/Microsoft.CSharp/ChangeLog
===================================================================
--- trunk/mcs/class/System/Test/Microsoft.CSharp/ChangeLog      2007-01-18 
10:19:58 UTC (rev 71243)
+++ trunk/mcs/class/System/Test/Microsoft.CSharp/ChangeLog      2007-01-18 
10:23:33 UTC (rev 71244)
@@ -1,3 +1,8 @@
+2007-01-18  Atsushi Enomoto  <[EMAIL PROTECTED]>
+
+       * CodeGeneratorFromTypeTest.cs :
+         Added test for generic type references output.
+
 2006-12-30  Marek Habersack  <[EMAIL PROTECTED]>
 
        * CodeGeneratorIdentifierTest.cs: added tests for C# code generator

Modified: 
trunk/mcs/class/System/Test/Microsoft.CSharp/CodeGeneratorFromTypeTest.cs
===================================================================
--- trunk/mcs/class/System/Test/Microsoft.CSharp/CodeGeneratorFromTypeTest.cs   
2007-01-18 10:19:58 UTC (rev 71243)
+++ trunk/mcs/class/System/Test/Microsoft.CSharp/CodeGeneratorFromTypeTest.cs   
2007-01-18 10:23:33 UTC (rev 71244)
@@ -921,6 +921,21 @@
                }
 
                #endregion Override implementation of 
CodeGeneratorFromTypeTestBase
+
+#if NET_2_0
+               [Test]
+               public void GenericCodeTypeReferencesTest ()
+               {
+                       string code = GenerateGenericCodeTypeReferences 
(Options);
+                       Assert.AreEqual (string.Format 
(CultureInfo.InvariantCulture,
+                               "public class Test {{{0}" +
+                               "    {0}" +
+                               "    private System.Nullable<int> Foo;{0}" +
+                               "    {0}" +
+                               "    private System.Nullable<> Bar;{0}" +
+                               "}}{0}", NewLine), code);
+               }
+#endif
        }
 
        [TestFixture]

Modified: trunk/mcs/class/System/Test/System.CodeDom/ChangeLog
===================================================================
--- trunk/mcs/class/System/Test/System.CodeDom/ChangeLog        2007-01-18 
10:19:58 UTC (rev 71243)
+++ trunk/mcs/class/System/Test/System.CodeDom/ChangeLog        2007-01-18 
10:23:33 UTC (rev 71244)
@@ -1,3 +1,10 @@
+2007-01-18  Atsushi Enomoto  <[EMAIL PROTECTED]>
+
+       * CodeTypeReferenceTest.cs :
+         Fixed generic type tests and let them involved in the actual tests.
+         Added some more generic type tests, including generic type
+         definition.
+
 2005-11-30  Gert Driesen  <[EMAIL PROTECTED]>
 
        * CodeRemoveEventStatementTest.cs: Added tests for ctors.

Modified: trunk/mcs/class/System/Test/System.CodeDom/CodeTypeReferenceTest.cs
===================================================================
--- trunk/mcs/class/System/Test/System.CodeDom/CodeTypeReferenceTest.cs 
2007-01-18 10:19:58 UTC (rev 71243)
+++ trunk/mcs/class/System/Test/System.CodeDom/CodeTypeReferenceTest.cs 
2007-01-18 10:23:33 UTC (rev 71244)
@@ -468,13 +468,14 @@
                        Assert.AreEqual (0, reference.TypeArguments.Count, 
"#6");
                }
 
+               [Test]
                public void GenericTypeTest1 () {
                        CodeTypeReference reference = new CodeTypeReference (
                                typeof (Dictionary<int,string>));
                        Assert.AreEqual 
("System.Collections.Generic.Dictionary`2", reference.BaseType, "#1");
                        Assert.AreEqual (0, reference.ArrayRank, "#2");
                        Assert.IsNull (reference.ArrayElementType, "#3");
-                       Assert.AreEqual 
(CodeTypeReferenceOptions.GenericTypeParameter, reference.Options, "#4");
+                       Assert.AreEqual (0, (int) reference.Options, "#4");
                        Assert.IsNotNull (reference.TypeArguments, "#5");
                        Assert.AreEqual (2, reference.TypeArguments.Count, 
"#6");
 
@@ -495,13 +496,14 @@
                        Assert.AreEqual (0, typeArgument.TypeArguments.Count, 
"#18");
                }
 
+               [Test]
                public void GenericTypeTest2 () {
                        CodeTypeReference reference = new CodeTypeReference (
                                typeof (Dictionary<List<int>, string>));
                        Assert.AreEqual 
("System.Collections.Generic.Dictionary`2", reference.BaseType, "#1");
                        Assert.AreEqual (0, reference.ArrayRank, "#2");
                        Assert.IsNull (reference.ArrayElementType, "#3");
-                       Assert.AreEqual 
(CodeTypeReferenceOptions.GenericTypeParameter, reference.Options, "#4");
+                       Assert.AreEqual (0, (int) reference.Options, "#4");
                        Assert.IsNotNull (reference.TypeArguments, "#5");
                        Assert.AreEqual (2, reference.TypeArguments.Count, 
"#6");
 
@@ -509,7 +511,7 @@
                        Assert.AreEqual ("System.Collections.Generic.List`1", 
typeArgument.BaseType, "#7");
                        Assert.AreEqual (0, typeArgument.ArrayRank, "#8");
                        Assert.IsNull (typeArgument.ArrayElementType, "#9");
-                       Assert.AreEqual 
(CodeTypeReferenceOptions.GenericTypeParameter, typeArgument.Options, "#10");
+                       Assert.AreEqual (0, (int) typeArgument.Options, "#10");
                        Assert.IsNotNull (typeArgument.TypeArguments, "#11");
                        Assert.AreEqual (1, typeArgument.TypeArguments.Count, 
"#12");
 
@@ -529,6 +531,61 @@
                        Assert.IsNotNull (typeArgument.TypeArguments, "#23");
                        Assert.AreEqual (0, typeArgument.TypeArguments.Count, 
"#24");
                }
+
+               [Test]
+               public void GenericTypeTest3 () 
+               {
+                       CodeTypeReference reference = new CodeTypeReference (
+                               "System.Nullable", new CodeTypeReference 
(typeof (int)));
+                       Assert.AreEqual ("System.Nullable`1", 
reference.BaseType, "#1");
+                       Assert.AreEqual (0, reference.ArrayRank, "#2");
+                       Assert.IsNull (reference.ArrayElementType, "#3");
+                       Assert.AreEqual (0, (int) reference.Options, "#4");
+                       Assert.IsNotNull (reference.TypeArguments, "#5");
+                       Assert.AreEqual (1, reference.TypeArguments.Count, 
"#6");
+
+                       CodeTypeReference typeArgument = 
reference.TypeArguments[0];
+                       Assert.AreEqual ("System.Int32", typeArgument.BaseType, 
"#7");
+                       Assert.AreEqual (0, typeArgument.ArrayRank, "#8");
+                       Assert.IsNull (typeArgument.ArrayElementType, "#9");
+                       Assert.AreEqual ((CodeTypeReferenceOptions) 0, 
typeArgument.Options, "#10");
+                       Assert.IsNotNull (typeArgument.TypeArguments, "#11");
+                       Assert.AreEqual (0, typeArgument.TypeArguments.Count, 
"#12");
+               }
+
+               [Test]
+               public void GenericTypeTest4 () 
+               {
+                       CodeTypeReference reference = new CodeTypeReference (
+                               "System.Nullable`1", new CodeTypeReference 
(typeof (int)));
+                       Assert.AreEqual ("System.Nullable`1", 
reference.BaseType, "#1");
+                       Assert.AreEqual (0, reference.ArrayRank, "#2");
+                       Assert.IsNull (reference.ArrayElementType, "#3");
+                       Assert.AreEqual (0, (int) reference.Options, "#4");
+                       Assert.IsNotNull (reference.TypeArguments, "#5");
+                       Assert.AreEqual (1, reference.TypeArguments.Count, 
"#6");
+
+                       CodeTypeReference typeArgument = 
reference.TypeArguments[0];
+                       Assert.AreEqual ("System.Int32", typeArgument.BaseType, 
"#7");
+                       Assert.AreEqual (0, typeArgument.ArrayRank, "#8");
+                       Assert.IsNull (typeArgument.ArrayElementType, "#9");
+                       Assert.AreEqual ((CodeTypeReferenceOptions) 0, 
typeArgument.Options, "#10");
+                       Assert.IsNotNull (typeArgument.TypeArguments, "#11");
+                       Assert.AreEqual (0, typeArgument.TypeArguments.Count, 
"#12");
+               }
+
+               [Test]
+               public void GenericTypeTest5 () 
+               {
+                       CodeTypeReference reference = new CodeTypeReference (
+                               typeof (int?).GetGenericTypeDefinition ());
+                       Assert.AreEqual ("System.Nullable`1", 
reference.BaseType, "#1");
+                       Assert.AreEqual (0, reference.ArrayRank, "#2");
+                       Assert.IsNull (reference.ArrayElementType, "#3");
+                       Assert.AreEqual (0, (int) reference.Options, "#4");
+                       Assert.IsNotNull (reference.TypeArguments, "#5");
+                       Assert.AreEqual (0, reference.TypeArguments.Count, 
"#6");
+               }
 #endif
 
                // bug #76535

Modified: trunk/mcs/class/System/Test/System.CodeDom.Compiler/ChangeLog
===================================================================
--- trunk/mcs/class/System/Test/System.CodeDom.Compiler/ChangeLog       
2007-01-18 10:19:58 UTC (rev 71243)
+++ trunk/mcs/class/System/Test/System.CodeDom.Compiler/ChangeLog       
2007-01-18 10:23:33 UTC (rev 71244)
@@ -1,3 +1,8 @@
+2007-01-18  Atsushi Enomoto  <[EMAIL PROTECTED]>
+
+       * CodeGeneratorFromTypeTestBase.cs :
+         added GenerateGenericCodeTypeReferences() for generic type test.
+
 2005-11-30  Gert Driesen  <[EMAIL PROTECTED]>
 
        * IndentedTextWriterTest.cs: Added tests for Indent property.

Modified: 
trunk/mcs/class/System/Test/System.CodeDom.Compiler/CodeGeneratorFromTypeTestBase.cs
===================================================================
--- 
trunk/mcs/class/System/Test/System.CodeDom.Compiler/CodeGeneratorFromTypeTestBase.cs
        2007-01-18 10:19:58 UTC (rev 71243)
+++ 
trunk/mcs/class/System/Test/System.CodeDom.Compiler/CodeGeneratorFromTypeTestBase.cs
        2007-01-18 10:23:33 UTC (rev 71244)
@@ -1016,5 +1016,22 @@
 
                        return GenerateCodeFromType (TypeDeclaration, options);
                }
+
+#if NET_2_0
+               protected string GenerateGenericCodeTypeReferences 
(CodeGeneratorOptions options)
+               {
+                       CodeTypeDeclaration td = new CodeTypeDeclaration 
("Test");
+                       CodeMemberField f = new CodeMemberField (
+                       new CodeTypeReference ("System.Nullable",
+                       new CodeTypeReference (typeof (int))),
+                       "Foo");
+                       td.Members.Add (f);
+                       CodeMemberField f2 = new CodeMemberField (
+                       new CodeTypeReference (typeof 
(int?).GetGenericTypeDefinition ()),
+                       "Bar");
+                       td.Members.Add (f2);
+                       return GenerateCodeFromType (td, options);
+               }
+#endif
        }
 }

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to