~halega/+junk/sharpdevelop

« back to all changes in this revision

Viewing changes to src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/GenericReturnType.cs

  • Committer: sk
  • Date: 2011-09-10 05:17:57 UTC
  • Revision ID: halega@halega.com-20110910051757-qfouz1llya9m6boy
4.1.0.7915 Release Candidate 1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
 
2
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
 
3
 
 
4
using System;
 
5
using System.Collections.Generic;
 
6
 
 
7
namespace ICSharpCode.SharpDevelop.Dom
 
8
{
 
9
        /// <summary>
 
10
        /// GenericReturnType is a reference to a type parameter.
 
11
        /// </summary>
 
12
        public sealed class GenericReturnType : DecoratingReturnType
 
13
        {
 
14
                ITypeParameter typeParameter;
 
15
                
 
16
                public ITypeParameter TypeParameter {
 
17
                        get {
 
18
                                return typeParameter;
 
19
                        }
 
20
                }
 
21
                
 
22
                public override bool Equals(IReturnType rt)
 
23
                {
 
24
                        if (rt == null || !rt.IsGenericReturnType)
 
25
                                return false;
 
26
                        GenericReturnType grt = rt.CastToGenericReturnType();
 
27
                        if ((typeParameter.Method == null) != (grt.typeParameter.Method == null))
 
28
                                return false;
 
29
                        return typeParameter.Index == grt.typeParameter.Index;
 
30
                }
 
31
                
 
32
                public override int GetHashCode()
 
33
                {
 
34
                        if (typeParameter.Method != null)
 
35
                                return 17491 + typeParameter.Index;
 
36
                        else
 
37
                                return 81871 + typeParameter.Index;
 
38
                }
 
39
                
 
40
                public override T CastToDecoratingReturnType<T>()
 
41
                {
 
42
                        if (typeof(T) == typeof(GenericReturnType)) {
 
43
                                return (T)(object)this;
 
44
                        } else {
 
45
                                return null;
 
46
                        }
 
47
                }
 
48
                
 
49
                public GenericReturnType(ITypeParameter typeParameter)
 
50
                {
 
51
                        if (typeParameter == null)
 
52
                                throw new ArgumentNullException("typeParameter");
 
53
                        this.typeParameter = typeParameter;
 
54
                }
 
55
                
 
56
                public override string FullyQualifiedName {
 
57
                        get {
 
58
                                return typeParameter.Name;
 
59
                        }
 
60
                }
 
61
                
 
62
                public override string Name {
 
63
                        get {
 
64
                                return typeParameter.Name;
 
65
                        }
 
66
                }
 
67
                
 
68
                public override string Namespace {
 
69
                        get {
 
70
                                return "";
 
71
                        }
 
72
                }
 
73
                
 
74
                public override string DotNetName {
 
75
                        get {
 
76
                                if (typeParameter.Method != null)
 
77
                                        return "``" + typeParameter.Index;
 
78
                                else
 
79
                                        return "`" + typeParameter.Index;
 
80
                        }
 
81
                }
 
82
                
 
83
                public override IClass GetUnderlyingClass()
 
84
                {
 
85
                        return null;
 
86
                }
 
87
                
 
88
                public override IReturnType BaseType {
 
89
                        get {
 
90
                                int count = typeParameter.Constraints.Count;
 
91
                                if (count == 0)
 
92
                                        return typeParameter.Class.ProjectContent.SystemTypes.Object;
 
93
                                if (count == 1)
 
94
                                        return typeParameter.Constraints[0];
 
95
                                return new CombinedReturnType(typeParameter.Constraints,
 
96
                                                              FullyQualifiedName,
 
97
                                                              Name, Namespace,
 
98
                                                              DotNetName);
 
99
                        }
 
100
                }
 
101
                
 
102
                // remove static methods (T.ReferenceEquals() is not possible)
 
103
                public override List<IMethod> GetMethods()
 
104
                {
 
105
                        List<IMethod> list = base.GetMethods();
 
106
                        if (list != null) {
 
107
                                list.RemoveAll(delegate(IMethod m) { return m.IsStatic || m.IsConstructor; });
 
108
                                if (typeParameter.HasConstructableConstraint || typeParameter.HasValueTypeConstraint) {
 
109
                                        list.Add(new Constructor(ModifierEnum.Public, this,
 
110
                                                                 DefaultTypeParameter.GetDummyClassForTypeParameter(typeParameter)));
 
111
                                }
 
112
                        }
 
113
                        return list;
 
114
                }
 
115
                
 
116
                public override Nullable<bool> IsReferenceType {
 
117
                        get { return null; }
 
118
                }
 
119
                
 
120
                public override string ToString()
 
121
                {
 
122
                        return String.Format("[GenericReturnType: {0}]", typeParameter);
 
123
                }
 
124
        }
 
125
}