Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented equality for ScalarDefinitionNode. #4940

Merged
merged 9 commits into from
Apr 7, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,28 @@ public override bool Equals(object? obj)
public override int GetHashCode()
=> HashCode.Combine(base.GetHashCode(), Description);

/// <summary>
/// The equal operator.
/// </summary>
/// <param name="left">The left parameter</param>
/// <param name="right">The right parameter</param>
/// <returns>
/// <c>true</c> if <paramref name="left"/> and <paramref name="right"/> are equal.
/// </returns>

public static bool operator ==(
InputObjectTypeDefinitionNode? left,
InputObjectTypeDefinitionNode? right)
=> Equals(left, right);

/// <summary>
/// The not equal operator.
/// </summary>
/// <param name="left">The left parameter</param>
/// <param name="right">The right parameter</param>
/// <returns>
/// <c>true</c> if <paramref name="left"/> and <paramref name="right"/> are not equal.
/// </returns>
public static bool operator !=(
InputObjectTypeDefinitionNode? left,
InputObjectTypeDefinitionNode? right)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,22 @@

namespace HotChocolate.Language;

/// <summary>
/// Represents the required modifier syntax.
/// </summary>
public sealed class RequiredModifierNode
: INullabilityModifierNode
, IEquatable<RequiredModifierNode>
{
/// <summary>
/// Initializes a new instance of <see cref="RequiredModifierNode"/>.
/// </summary>
/// <param name="location">
/// The location of the syntax node within the original source text.
/// </param>
/// <param name="element">
/// The list nullability modifier.
/// </param>
public RequiredModifierNode(Location? location, ListNullabilityNode? element)
{
Location = location;
Expand Down Expand Up @@ -55,9 +67,19 @@ public IEnumerable<ISyntaxNode> GetNodes()
/// </returns>
public string ToString(bool indented) => SyntaxPrinter.Print(this, indented);

/// <summary>
/// Indicates whether the current object is equal to another object of the same type.
/// </summary>
/// <param name="other">
/// An object to compare with this object.
/// </param>
/// <returns>
/// true if the current object is equal to the <paramref name="other" /> parameter;
/// otherwise, false.
/// </returns>
public bool Equals(RequiredModifierNode? other)
{
if (ReferenceEquals(null, other))
if (other is null)
{
return false;
}
Expand All @@ -70,16 +92,47 @@ public bool Equals(RequiredModifierNode? other)
return Equals(Element, other.Element);
}

/// <summary>
/// Determines whether the specified object is equal to the current object.
/// </summary>
/// <param name="obj">
/// The object to compare with the current object.
/// </param>
/// <returns>
/// true if the specified object is equal to the current object; otherwise, false.
/// </returns>
public override bool Equals(object? obj)
=> ReferenceEquals(this, obj) ||
(obj is RequiredModifierNode other && Equals(other));

/// <summary>
/// Serves as the default hash function.
/// </summary>
/// <returns>
/// A hash code for the current object.
/// </returns>
public override int GetHashCode()
=> HashCode.Combine(Kind, Element);

/// <summary>
/// The equal operator.
/// </summary>
/// <param name="left">The left parameter</param>
/// <param name="right">The right parameter</param>
/// <returns>
/// <c>true</c> if <paramref name="left"/> and <paramref name="right"/> are equal.
/// </returns>
public static bool operator ==(RequiredModifierNode? left, RequiredModifierNode? right)
=> Equals(left, right);

/// <summary>
/// The not equal operator.
/// </summary>
/// <param name="left">The left parameter</param>
/// <param name="right">The right parameter</param>
/// <returns>
/// <c>true</c> if <paramref name="left"/> and <paramref name="right"/> are not equal.
/// </returns>
public static bool operator !=(RequiredModifierNode? left, RequiredModifierNode? right)
=> !Equals(left, right);
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,38 @@
using System;
using System.Collections.Generic;
using HotChocolate.Language.Utilities;

namespace HotChocolate.Language;

/// <summary>
/// <para>Represents the scalar definition syntax.</para>
/// <para>
/// Scalar types represent primitive leaf values in a GraphQL type system.
/// GraphQL responses take the form of a hierarchical tree;
/// the leaves of this tree are typically GraphQL Scalar types
/// (but may also be Enum types or null values).
/// </para>
/// </summary>
public sealed class ScalarTypeDefinitionNode
: ScalarTypeDefinitionNodeBase
: NamedSyntaxNode
, ITypeDefinitionNode
, IEquatable<ScalarTypeDefinitionNode>
{
/// <summary>
/// Initializes a new instance of <see cref="ScalarTypeDefinitionNode"/>.
/// </summary>
/// <param name="location">
/// The location of the syntax node within the original source text.
/// </param>
/// <param name="name">
/// The name of the scalar.
/// </param>
/// <param name="description">
/// The description of the scalar.
/// </param>
/// <param name="directives">
/// The applied directives.
/// </param>
public ScalarTypeDefinitionNode(
Location? location,
NameNode name,
Expand All @@ -17,10 +43,16 @@ public ScalarTypeDefinitionNode(
Description = description;
}

public override SyntaxKind Kind { get; } = SyntaxKind.ScalarTypeDefinition;
/// <inheritdoc />
public override SyntaxKind Kind => SyntaxKind.ScalarTypeDefinition;

/// <summary>
/// Gets the scalar description.
/// </summary>
/// <value></value>
public StringValueNode? Description { get; }

/// <inheritdoc />
public override IEnumerable<ISyntaxNode> GetNodes()
{
if (Description is { })
Expand Down Expand Up @@ -57,33 +89,124 @@ public override IEnumerable<ISyntaxNode> GetNodes()
/// </returns>
public override string ToString(bool indented) => SyntaxPrinter.Print(this, indented);

/// <summary>
/// Creates a new node from the current instance and replaces the
/// <see cref="Location" /> with <paramref name="location" />.
/// </summary>
/// <param name="location">
/// The location that shall be used to replace the current location.
/// </param>
/// <returns>
/// Returns the new node with the new <paramref name="location" />.
/// </returns>
public ScalarTypeDefinitionNode WithLocation(Location? location)
{
return new ScalarTypeDefinitionNode(
location, Name, Description,
Directives);
}
=> new(location, Name, Description, Directives);

/// <summary>
/// Creates a new node from the current instance and replaces the
/// <see cref="Name" /> with <paramref name="name" />.
/// </summary>
/// <param name="name">
/// The name that shall be used to replace the current name.
/// </param>
/// <returns>
/// Returns the new node with the new <paramref name="name" />.
/// </returns>
public ScalarTypeDefinitionNode WithName(NameNode name)
{
return new ScalarTypeDefinitionNode(
Location, name, Description,
Directives);
}
=> new(Location, name, Description, Directives);

public ScalarTypeDefinitionNode WithDescription(
StringValueNode? description)
{
return new ScalarTypeDefinitionNode(
Location, Name, description,
Directives);
}
/// <summary>
/// Creates a new node from the current instance and replaces the
/// <see cref="Description" /> with <paramref name="description" />.
/// </summary>
/// <param name="description">
/// The description that shall be used to replace the current description.
/// </param>
/// <returns>
/// Returns the new node with the new <paramref name="description" />.
/// </returns>
public ScalarTypeDefinitionNode WithDescription(StringValueNode? description)
=> new(Location, Name, description, Directives);

public ScalarTypeDefinitionNode WithDirectives(
IReadOnlyList<DirectiveNode> directives)
{
return new ScalarTypeDefinitionNode(
Location, Name, Description,
directives);
}
/// <summary>
/// Creates a new node from the current instance and replaces the
/// <see cref="NamedSyntaxNode.Directives" /> with <paramref name="directives" />.
/// </summary>
/// <param name="directives">
/// The directives that shall be used to replace the current
/// <see cref="NamedSyntaxNode.Directives" />.
/// </param>
/// <returns>
/// Returns the new node with the new <paramref name="directives" />.
/// </returns>
public ScalarTypeDefinitionNode WithDirectives(IReadOnlyList<DirectiveNode> directives)
=> new(Location, Name, Description, directives);

/// <summary>
/// Determines whether the specified <see cref="ScalarTypeDefinitionNode"/>
/// is equal to the current <see cref="ScalarTypeDefinitionNode"/>.
/// </summary>
/// <param name="other">
/// The <see cref="ScalarTypeDefinitionNode"/> to compare with the current
/// <see cref="ScalarTypeDefinitionNode"/>.
/// </param>
/// <returns>
/// <c>true</c> if the specified <see cref="ScalarTypeDefinitionNode"/> is equal
/// to the current <see cref="ScalarTypeDefinitionNode"/>;
/// otherwise, <c>false</c>.
/// </returns>
public bool Equals(ScalarTypeDefinitionNode? other)
=> base.Equals(other) && Description.IsEqualTo(other.Description);

/// <summary>
/// Determines whether the specified <see cref="object"/> is equal to
/// the current <see cref="ScalarTypeDefinitionNode"/>.
/// </summary>
/// <param name="obj">
/// The <see cref="object"/> to compare with the current
/// <see cref="ScalarTypeDefinitionNode"/>.
/// </param>
/// <returns>
/// <c>true</c> if the specified <see cref="object"/> is equal to the
/// current <see cref="ScalarTypeDefinitionNode"/>; otherwise, <c>false</c>.
/// </returns>
public override bool Equals(object? obj)
=> Equals(obj as ScalarTypeDefinitionNode);

/// <summary>
/// Serves as a hash function for a <see cref="ScalarTypeDefinitionNode"/>
/// object.
/// </summary>
/// <returns>
/// A hash code for this instance that is suitable for use in
/// hashing algorithms and data structures such as a hash table.
/// </returns>
public override int GetHashCode()
=> HashCode.Combine(base.GetHashCode(), Kind, Description?.GetHashCode());

/// <summary>
/// The equal operator.
/// </summary>
/// <param name="left">The left parameter</param>
/// <param name="right">The right parameter</param>
/// <returns>
/// <c>true</c> if <paramref name="left"/> and <paramref name="right"/> are equal.
/// </returns>
public static bool operator ==(
ScalarTypeDefinitionNode? left,
ScalarTypeDefinitionNode? right)
=> Equals(left, right);

/// <summary>
/// The not equal operator.
/// </summary>
/// <param name="left">The left parameter</param>
/// <param name="right">The right parameter</param>
/// <returns>
/// <c>true</c> if <paramref name="left"/> and <paramref name="right"/> are not equal.
/// </returns>
public static bool operator !=(
ScalarTypeDefinitionNode? left,
ScalarTypeDefinitionNode? right)
=> !Equals(left, right);
}

This file was deleted.

Loading