forked from Unity-Technologies/UnityCsReference
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSearchQueryError.cs
More file actions
112 lines (97 loc) · 3.82 KB
/
Copy pathSearchQueryError.cs
File metadata and controls
112 lines (97 loc) · 3.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// Unity C# reference source
// Copyright (c) Unity Technologies. For terms of use, see
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License
using System.Collections.Generic;
namespace UnityEditor.Search
{
/// <summary>
/// Enum representing the possible types of query errors.
/// </summary>
public enum SearchQueryErrorType
{
/// <summary>
/// Represents an error.
/// </summary>
Error,
/// <summary>
/// Represents a warning.
/// </summary>
Warning
}
/// <summary>
/// Class that represents a query parsing error.
/// </summary>
public class SearchQueryError
{
/// <summary>
/// Index where the error happened.
/// </summary>
public int index { get; }
/// <summary>
/// Length of the block that was being parsed.
/// </summary>
public int length { get; }
/// <summary>
/// The type of this query error.
/// </summary>
public SearchQueryErrorType type { get; }
/// <summary>
/// The context on which this error was logged.
/// </summary>
public SearchContext context { get; }
/// <summary>
/// Which provider logged this error.
/// </summary>
public SearchProvider provider { get; }
/// <summary>
/// What is the reason for the error.
/// </summary>
public string reason { get; }
/// <summary>
/// Creates a new SearchQueryError.
/// </summary>
/// <param name="index">Index where the error happened.</param>
/// <param name="length">Length of the block that was being parsed.</param>
/// <param name="reason">What is the reason for the error.</param>
/// <param name="context">The context on which this error was logged.</param>
/// <param name="provider">Which provider logged this error.</param>
/// <param name="fromSearchQuery">Set to true if this error comes from parsing the searchQuery. This will correctly offset the index with respect to the raw text.</param>
/// <param name="type">The type of this query error.</param>
public SearchQueryError(int index, int length, string reason, SearchContext context, SearchProvider provider, bool fromSearchQuery = true, SearchQueryErrorType type = SearchQueryErrorType.Error)
{
this.index = fromSearchQuery ? index + context.searchQueryOffset : index;
this.length = length;
this.reason = reason;
this.type = type;
this.context = context;
this.provider = provider;
}
public SearchQueryError(QueryError error, SearchContext context, SearchProvider provider, bool fromSearchQuery = true)
: this(error.index, error.length, error.reason, context, provider, fromSearchQuery, error.type)
{}
/// <summary>
/// Get the hashcode of this error.
/// </summary>
/// <returns>The hashcode of this error.</returns>
public override int GetHashCode()
{
return (index.GetHashCode() * 397) ^ length.GetHashCode();
}
internal static int Compare(SearchQueryError x, SearchQueryError y)
{
if (x.type == SearchQueryErrorType.Error && y.type == SearchQueryErrorType.Warning)
return -1;
if (x.type == SearchQueryErrorType.Warning && y.type == SearchQueryErrorType.Error)
return 1;
return x.length.CompareTo(y.length);
}
internal bool Overlaps(SearchQueryError other)
{
if (index + length <= other.index)
return false;
if (other.index + other.length <= index)
return false;
return true;
}
}
}