~ubuntu-branches/ubuntu/saucy/monodevelop/saucy

« back to all changes in this revision

Viewing changes to contrib/ICSharpCode.NRefactory/TypeSystem/Implementation/TypeParameterReference.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2012-05-27 18:08:20 UTC
  • mfrom: (1.8.5) (1.5.8 sid)
  • Revision ID: package-import@ubuntu.com-20120527180820-f1ub6lhg0s50wci1
Tags: 3.0.2+dfsg-3
* [fcecfe7] Fix monodevelop-core-addins.pc.in to point to actual 
  installed location of assemblies.
* [26e1a07] DebSrc 3.0 does not support Quilt's -p parameter, so 
  manually adjust the path in the patch file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team
 
2
// 
 
3
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
 
4
// software and associated documentation files (the "Software"), to deal in the Software
 
5
// without restriction, including without limitation the rights to use, copy, modify, merge,
 
6
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
 
7
// to whom the Software is furnished to do so, subject to the following conditions:
 
8
// 
 
9
// The above copyright notice and this permission notice shall be included in all copies or
 
10
// substantial portions of the Software.
 
11
// 
 
12
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
 
13
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 
14
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
 
15
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
 
16
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 
17
// DEALINGS IN THE SOFTWARE.
 
18
 
 
19
using System;
 
20
using System.Globalization;
 
21
 
 
22
namespace ICSharpCode.NRefactory.TypeSystem.Implementation
 
23
{
 
24
        [Serializable]
 
25
        public sealed class TypeParameterReference : ITypeReference, ISupportsInterning
 
26
        {
 
27
                readonly EntityType ownerType;
 
28
                readonly int index;
 
29
                
 
30
                public TypeParameterReference(EntityType ownerType, int index)
 
31
                {
 
32
                        this.ownerType = ownerType;
 
33
                        this.index = index;
 
34
                }
 
35
                
 
36
                public IType Resolve(ITypeResolveContext context)
 
37
                {
 
38
                        if (ownerType == EntityType.Method) {
 
39
                                IMethod method = context.CurrentMember as IMethod;
 
40
                                if (method != null && index < method.TypeParameters.Count) {
 
41
                                        return method.TypeParameters[index];
 
42
                                }
 
43
                                return DummyTypeParameter.GetMethodTypeParameter(index);
 
44
                        } else if (ownerType == EntityType.TypeDefinition) {
 
45
                                ITypeDefinition typeDef = context.CurrentTypeDefinition;
 
46
                                if (typeDef != null && index < typeDef.TypeParameters.Count) {
 
47
                                        return typeDef.TypeParameters[index];
 
48
                                }
 
49
                                return DummyTypeParameter.GetClassTypeParameter(index);
 
50
                        } else {
 
51
                                return SpecialType.UnknownType;
 
52
                        }
 
53
                }
 
54
                
 
55
                void ISupportsInterning.PrepareForInterning(IInterningProvider provider)
 
56
                {
 
57
                }
 
58
                
 
59
                int ISupportsInterning.GetHashCodeForInterning()
 
60
                {
 
61
                        return index * 33 + (int)ownerType;
 
62
                }
 
63
                
 
64
                bool ISupportsInterning.EqualsForInterning(ISupportsInterning other)
 
65
                {
 
66
                        TypeParameterReference r = other as TypeParameterReference;
 
67
                        return r != null && index == r.index && ownerType == r.ownerType;
 
68
                }
 
69
                
 
70
                public override string ToString()
 
71
                {
 
72
                        if (ownerType == EntityType.Method)
 
73
                                return "!!" + index.ToString(CultureInfo.InvariantCulture);
 
74
                        else
 
75
                                return "!" + index.ToString(CultureInfo.InvariantCulture);
 
76
                }
 
77
        }
 
78
}