Free cookie consent management tool by TermsFeed Policy Generator

source: tags/3.3.13/HeuristicLab.ExtLibs/HeuristicLab.NRefactory/5.5.0/NRefactory-5.5.0/TypeSystem/Implementation/DefaultUnresolvedProperty.cs @ 18242

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

#2077: created branch and added first version

File size: 3.9 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.Linq;
22
23namespace ICSharpCode.NRefactory.TypeSystem.Implementation
24{
25  /// <summary>
26  /// Default implementation of <see cref="IUnresolvedProperty"/>.
27  /// </summary>
28  [Serializable]
29  public class DefaultUnresolvedProperty : AbstractUnresolvedMember, IUnresolvedProperty
30  {
31    IUnresolvedMethod getter, setter;
32    IList<IUnresolvedParameter> parameters;
33   
34    protected override void FreezeInternal()
35    {
36      parameters = FreezableHelper.FreezeListAndElements(parameters);
37      FreezableHelper.Freeze(getter);
38      FreezableHelper.Freeze(setter);
39      base.FreezeInternal();
40    }
41   
42    public override object Clone()
43    {
44      var copy = (DefaultUnresolvedProperty)base.Clone();
45      if (parameters != null)
46        copy.parameters = new List<IUnresolvedParameter>(parameters);
47      return copy;
48    }
49   
50    public override void ApplyInterningProvider(InterningProvider provider)
51    {
52      base.ApplyInterningProvider(provider);
53      parameters = provider.InternList(parameters);
54    }
55   
56    public DefaultUnresolvedProperty()
57    {
58      this.SymbolKind = SymbolKind.Property;
59    }
60   
61    public DefaultUnresolvedProperty(IUnresolvedTypeDefinition declaringType, string name)
62    {
63      this.SymbolKind = SymbolKind.Property;
64      this.DeclaringTypeDefinition = declaringType;
65      this.Name = name;
66      if (declaringType != null)
67        this.UnresolvedFile = declaringType.UnresolvedFile;
68    }
69   
70    public bool IsIndexer {
71      get { return this.SymbolKind == SymbolKind.Indexer; }
72    }
73   
74    public IList<IUnresolvedParameter> Parameters {
75      get {
76        if (parameters == null)
77          parameters = new List<IUnresolvedParameter>();
78        return parameters;
79      }
80    }
81   
82    public bool CanGet {
83      get { return getter != null; }
84    }
85   
86    public bool CanSet {
87      get { return setter != null; }
88    }
89   
90    public IUnresolvedMethod Getter {
91      get { return getter; }
92      set {
93        ThrowIfFrozen();
94        getter = value;
95      }
96    }
97   
98    public IUnresolvedMethod Setter {
99      get { return setter; }
100      set {
101        ThrowIfFrozen();
102        setter = value;
103      }
104    }
105   
106    public override IMember CreateResolved(ITypeResolveContext context)
107    {
108      return new DefaultResolvedProperty(this, context);
109    }
110   
111    public override IMember Resolve(ITypeResolveContext context)
112    {
113      ITypeReference interfaceTypeReference = null;
114      if (this.IsExplicitInterfaceImplementation && this.ExplicitInterfaceImplementations.Count == 1)
115        interfaceTypeReference = this.ExplicitInterfaceImplementations[0].DeclaringTypeReference;
116      return Resolve(ExtendContextForType(context, this.DeclaringTypeDefinition),
117                     this.SymbolKind, this.Name, interfaceTypeReference,
118                     parameterTypeReferences: this.Parameters.Select(p => p.Type).ToList());
119    }
120   
121    IProperty IUnresolvedProperty.Resolve(ITypeResolveContext context)
122    {
123      return (IProperty)Resolve(context);
124    }
125  }
126}
Note: See TracBrowser for help on using the repository browser.