Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/HeuristicLab.ExtLibs/HeuristicLab.NRefactory/5.5.0/NRefactory.CSharp-5.5.0/Ast/DocumentationReference.cs @ 17578

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

#2077: created branch and added first version

File size: 5.0 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 ICSharpCode.NRefactory.TypeSystem;
21
22namespace ICSharpCode.NRefactory.CSharp
23{
24  /// <summary>
25  /// Represents a 'cref' reference in XML documentation.
26  /// </summary>
27  public class DocumentationReference : AstNode
28  {
29    public static readonly Role<AstType> DeclaringTypeRole = new Role<AstType>("DeclaringType", AstType.Null);
30    public static readonly Role<AstType> ConversionOperatorReturnTypeRole = new Role<AstType>("ConversionOperatorReturnType", AstType.Null);
31   
32    SymbolKind symbolKind;
33    OperatorType operatorType;
34    bool hasParameterList;
35   
36    /// <summary>
37    /// Gets/Sets the entity type.
38    /// Possible values are:
39    ///   <c>SymbolKind.Operator</c> for operators,
40    ///   <c>SymbolKind.Indexer</c> for indexers,
41    ///   <c>SymbolKind.TypeDefinition</c> for references to primitive types,
42    ///   and <c>SymbolKind.None</c> for everything else.
43    /// </summary>
44    public SymbolKind SymbolKind {
45      get { return symbolKind; }
46      set {
47        ThrowIfFrozen();
48        symbolKind = value;
49      }
50    }
51   
52    /// <summary>
53    /// Gets/Sets the operator type.
54    /// This property is only used when SymbolKind==Operator.
55    /// </summary>
56    public OperatorType OperatorType {
57      get { return operatorType; }
58      set {
59        ThrowIfFrozen();
60        operatorType = value;
61      }
62    }
63   
64    /// <summary>
65    /// Gets/Sets whether a parameter list was provided.
66    /// </summary>
67    public bool HasParameterList {
68      get { return hasParameterList; }
69      set {
70        ThrowIfFrozen();
71        hasParameterList = value;
72      }
73    }
74   
75    public override NodeType NodeType {
76      get { return NodeType.Unknown; }
77    }
78   
79    /// <summary>
80    /// Gets/Sets the declaring type.
81    /// </summary>
82    public AstType DeclaringType {
83      get { return GetChildByRole(DeclaringTypeRole); }
84      set { SetChildByRole(DeclaringTypeRole, value); }
85    }
86   
87    /// <summary>
88    /// Gets/sets the member name.
89    /// This property is only used when SymbolKind==None.
90    /// </summary>
91    public string MemberName {
92      get { return GetChildByRole(Roles.Identifier).Name; }
93      set { SetChildByRole(Roles.Identifier, Identifier.Create(value)); }
94    }
95   
96    /// <summary>
97    /// Gets/Sets the return type of conversion operators.
98    /// This property is only used when SymbolKind==Operator and OperatorType is explicit or implicit.
99    /// </summary>
100    public AstType ConversionOperatorReturnType {
101      get { return GetChildByRole(ConversionOperatorReturnTypeRole); }
102      set { SetChildByRole(ConversionOperatorReturnTypeRole, value); }
103    }
104   
105    public AstNodeCollection<AstType> TypeArguments {
106      get { return GetChildrenByRole (Roles.TypeArgument); }
107    }
108   
109    public AstNodeCollection<ParameterDeclaration> Parameters {
110      get { return GetChildrenByRole (Roles.Parameter); }
111    }
112   
113    protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match)
114    {
115      DocumentationReference o = other as DocumentationReference;
116      if (!(o != null && this.SymbolKind == o.SymbolKind && this.HasParameterList == o.HasParameterList))
117        return false;
118      if (this.SymbolKind == SymbolKind.Operator) {
119        if (this.OperatorType != o.OperatorType)
120          return false;
121        if (this.OperatorType == OperatorType.Implicit || this.OperatorType == OperatorType.Explicit) {
122          if (!this.ConversionOperatorReturnType.DoMatch(o.ConversionOperatorReturnType, match))
123            return false;
124        }
125      } else if (this.SymbolKind == SymbolKind.None) {
126        if (!MatchString(this.MemberName, o.MemberName))
127          return false;
128        if (!this.TypeArguments.DoMatch(o.TypeArguments, match))
129          return false;
130      }
131      return this.Parameters.DoMatch(o.Parameters, match);
132    }
133   
134    public override void AcceptVisitor (IAstVisitor visitor)
135    {
136      visitor.VisitDocumentationReference (this);
137    }
138   
139    public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
140    {
141      return visitor.VisitDocumentationReference (this);
142    }
143   
144    public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
145    {
146      return visitor.VisitDocumentationReference (this, data);
147    }
148  }
149}
Note: See TracBrowser for help on using the repository browser.