// Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using ICSharpCode.Decompiler.TypeSystem;
namespace ICSharpCode.Decompiler.CSharp.Syntax
{
///
/// Represents a 'cref' reference in XML documentation.
///
public class DocumentationReference : AstNode
{
public static readonly Role DeclaringTypeRole = new Role("DeclaringType", AstType.Null);
public static readonly Role ConversionOperatorReturnTypeRole = new Role("ConversionOperatorReturnType", AstType.Null);
SymbolKind symbolKind;
OperatorType operatorType;
bool hasParameterList;
///
/// Gets/Sets the entity type.
/// Possible values are:
/// SymbolKind.Operator for operators,
/// SymbolKind.Indexer for indexers,
/// SymbolKind.TypeDefinition for references to primitive types,
/// and SymbolKind.None for everything else.
///
public SymbolKind SymbolKind {
get { return symbolKind; }
set {
ThrowIfFrozen();
symbolKind = value;
}
}
///
/// Gets/Sets the operator type.
/// This property is only used when SymbolKind==Operator.
///
public OperatorType OperatorType {
get { return operatorType; }
set {
ThrowIfFrozen();
operatorType = value;
}
}
///
/// Gets/Sets whether a parameter list was provided.
///
public bool HasParameterList {
get { return hasParameterList; }
set {
ThrowIfFrozen();
hasParameterList = value;
}
}
public override NodeType NodeType {
get { return NodeType.Unknown; }
}
///
/// Gets/Sets the declaring type.
///
public AstType DeclaringType {
get { return GetChildByRole(DeclaringTypeRole); }
set { SetChildByRole(DeclaringTypeRole, value); }
}
///
/// Gets/sets the member name.
/// This property is only used when SymbolKind==None.
///
public string MemberName {
get { return GetChildByRole(Roles.Identifier).Name; }
set { SetChildByRole(Roles.Identifier, Identifier.Create(value)); }
}
///
/// Gets/Sets the return type of conversion operators.
/// This property is only used when SymbolKind==Operator and OperatorType is explicit or implicit.
///
public AstType ConversionOperatorReturnType {
get { return GetChildByRole(ConversionOperatorReturnTypeRole); }
set { SetChildByRole(ConversionOperatorReturnTypeRole, value); }
}
public AstNodeCollection TypeArguments {
get { return GetChildrenByRole(Roles.TypeArgument); }
}
public AstNodeCollection Parameters {
get { return GetChildrenByRole(Roles.Parameter); }
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
DocumentationReference o = other as DocumentationReference;
if (!(o != null && this.SymbolKind == o.SymbolKind && this.HasParameterList == o.HasParameterList))
return false;
if (this.SymbolKind == SymbolKind.Operator)
{
if (this.OperatorType != o.OperatorType)
return false;
if (this.OperatorType == OperatorType.Implicit || this.OperatorType == OperatorType.Explicit)
{
if (!this.ConversionOperatorReturnType.DoMatch(o.ConversionOperatorReturnType, match))
return false;
}
}
else if (this.SymbolKind == SymbolKind.None)
{
if (!MatchString(this.MemberName, o.MemberName))
return false;
if (!this.TypeArguments.DoMatch(o.TypeArguments, match))
return false;
}
return this.Parameters.DoMatch(o.Parameters, match);
}
public override void AcceptVisitor(IAstVisitor visitor)
{
visitor.VisitDocumentationReference(this);
}
public override T AcceptVisitor(IAstVisitor visitor)
{
return visitor.VisitDocumentationReference(this);
}
public override S AcceptVisitor(IAstVisitor visitor, T data)
{
return visitor.VisitDocumentationReference(this, data);
}
}
}