Free cookie consent management tool by TermsFeed Policy Generator

source: stable/HeuristicLab.ExtLibs/HeuristicLab.NRefactory/5.5.0/NRefactory.CSharp-5.5.0/TypeSystem/MemberTypeOrNamespaceReference.cs @ 11937

Last change on this file since 11937 was 11700, checked in by jkarder, 10 years ago

#2077: created branch and added first version

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