~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to contrib/ICSharpCode.NRefactory.CSharp/TypeSystem/MemberTypeOrNamespaceReference.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
Import upstream version 4.0.5+dfsg

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.Collections.Generic;
21
 
using System.Collections.ObjectModel;
22
 
using ICSharpCode.NRefactory.CSharp.Resolver;
23
 
using ICSharpCode.NRefactory.Semantics;
24
 
using ICSharpCode.NRefactory.TypeSystem;
25
 
using ICSharpCode.NRefactory.Utils;
26
 
 
27
 
namespace ICSharpCode.NRefactory.CSharp.TypeSystem
28
 
{
29
 
        /// <summary>
30
 
        /// Reference to a qualified type or namespace name.
31
 
        /// </summary>
32
 
        [Serializable]
33
 
        public sealed class MemberTypeOrNamespaceReference : TypeOrNamespaceReference, ISupportsInterning
34
 
        {
35
 
                TypeOrNamespaceReference target;
36
 
                string identifier;
37
 
                IList<ITypeReference> typeArguments;
38
 
                readonly NameLookupMode lookupMode;
39
 
                
40
 
                public MemberTypeOrNamespaceReference(TypeOrNamespaceReference target, string identifier, IList<ITypeReference> typeArguments, NameLookupMode lookupMode = NameLookupMode.Type)
41
 
                {
42
 
                        if (target == null)
43
 
                                throw new ArgumentNullException("target");
44
 
                        if (identifier == null)
45
 
                                throw new ArgumentNullException("identifier");
46
 
                        this.target = target;
47
 
                        this.identifier = identifier;
48
 
                        this.typeArguments = typeArguments ?? EmptyList<ITypeReference>.Instance;
49
 
                        this.lookupMode = lookupMode;
50
 
                }
51
 
                
52
 
                public string Identifier {
53
 
                        get { return identifier; }
54
 
                }
55
 
                
56
 
                public TypeOrNamespaceReference Target {
57
 
                        get { return target; }
58
 
                }
59
 
                
60
 
                public IList<ITypeReference> TypeArguments {
61
 
                        get { return new ReadOnlyCollection<ITypeReference>(typeArguments); }
62
 
                }
63
 
                
64
 
                /// <summary>
65
 
                /// Adds a suffix to the identifier.
66
 
                /// Does not modify the existing type reference, but returns a new one.
67
 
                /// </summary>
68
 
                public MemberTypeOrNamespaceReference AddSuffix(string suffix)
69
 
                {
70
 
                        return new MemberTypeOrNamespaceReference(target, identifier + suffix, typeArguments);
71
 
                }
72
 
                
73
 
                public override ResolveResult Resolve(CSharpResolver resolver)
74
 
                {
75
 
                        ResolveResult targetRR = target.Resolve(resolver);
76
 
                        if (targetRR.IsError)
77
 
                                return targetRR;
78
 
                        IList<IType> typeArgs = typeArguments.Resolve(resolver.CurrentTypeResolveContext);
79
 
                        using (var busyLock = BusyManager.Enter(this)) {
80
 
                                if (busyLock.Success) {
81
 
                                        return resolver.ResolveMemberAccess(targetRR, identifier, typeArgs, lookupMode);
82
 
                                } else {
83
 
                                        // This can happen for "class Test : $Test.Base$ { public class Base {} }":
84
 
                                        return ErrorResolveResult.UnknownError; // don't cache this error
85
 
                                }
86
 
                        }
87
 
                }
88
 
                
89
 
                public override string ToString()
90
 
                {
91
 
                        if (typeArguments.Count == 0)
92
 
                                return target.ToString() + "." + identifier;
93
 
                        else
94
 
                                return target.ToString() + "." + identifier + "<" + string.Join(",", typeArguments) + ">";
95
 
                }
96
 
                
97
 
                void ISupportsInterning.PrepareForInterning(IInterningProvider provider)
98
 
                {
99
 
                        target = provider.Intern(target);
100
 
                        identifier = provider.Intern(identifier);
101
 
                        typeArguments = provider.InternList(typeArguments);
102
 
                }
103
 
                
104
 
                int ISupportsInterning.GetHashCodeForInterning()
105
 
                {
106
 
                        int hashCode = 0;
107
 
                        unchecked {
108
 
                                hashCode += 1000000007 * target.GetHashCode();
109
 
                                hashCode += 1000000033 * identifier.GetHashCode();
110
 
                                hashCode += 1000000087 * typeArguments.GetHashCode();
111
 
                                hashCode += 1000000021 * (int)lookupMode;
112
 
                        }
113
 
                        return hashCode;
114
 
                }
115
 
                
116
 
                bool ISupportsInterning.EqualsForInterning(ISupportsInterning other)
117
 
                {
118
 
                        MemberTypeOrNamespaceReference o = other as MemberTypeOrNamespaceReference;
119
 
                        return o != null && this.target == o.target
120
 
                                && this.identifier == o.identifier && this.typeArguments == o.typeArguments
121
 
                                && this.lookupMode == o.lookupMode;
122
 
                }
123
 
        }
124
 
}