Skip to content

Commit f4904d0

Browse files
committed
minor: Refactor 'Token.equals' operands order
For consistency reasons, move 'this' to the LHS and 'other' to the RHS in 'Token.equals' method.
1 parent d20c912 commit f4904d0

File tree

4 files changed

+58
-4
lines changed

4 files changed

+58
-4
lines changed

langkit/templates/java_api/main_class.mako

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2685,9 +2685,9 @@ public final class ${ctx.lib_name.camel} {
26852685
if(o == this) return true;
26862686
if(!(o instanceof Token)) return false;
26872687
final Token other = (Token) o;
2688-
return other.tokenDataHandler.equals(this.tokenDataHandler) &&
2689-
other.tokenIndex == this.tokenIndex &&
2690-
other.triviaIndex == this.triviaIndex;
2688+
return this.tokenDataHandler.equals(other.tokenDataHandler) &&
2689+
this.tokenIndex == other.tokenIndex &&
2690+
this.triviaIndex == other.triviaIndex;
26912691
}
26922692

26932693
// ----- Inner classes -----

testsuite/tests/java_api/general/common/BindingsTests.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ private static void testTokens() {
168168
System.out.println("Text range with a NO_TOKEN = " +
169169
Token.textRange(first, none));
170170

171-
// Test the token equivalence
171+
// Test the token equivalence and equality
172172
AnalysisUnit eqUnit = context.getUnitFromBuffer(
173173
"null identifier example identifier example",
174174
"foo.txt"
@@ -189,6 +189,20 @@ private static void testTokens() {
189189
}
190190
current = current.next();
191191
}
192+
193+
Token left = eqUnit.getFirstToken();
194+
Token right = eqUnit.getFirstToken();
195+
while(!(left.isNone() || right.isNone())) {
196+
System.out.println(
197+
left.toString() + " != " + right + " = " + (left != right)
198+
);
199+
System.out.println(
200+
left.toString() + ".equals(" + right + ") = " +
201+
left.equals(right)
202+
);
203+
left = left.next();
204+
right = right.next();
205+
}
192206
}
193207

194208
// Display the footer

testsuite/tests/java_api/general/graal_c_api/test.out

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,26 @@ The NO_TOKEN = <Token Kind=No_Token Text="">
4343
Text range with a NO_TOKEN =
4444
Equivalent tokens : <Token Kind=Identifier Text="identifier"> and <Token Kind=Identifier Text="identifier">
4545
Equivalent tokens : <Token Kind=Example Text="example"> and <Token Kind=Example Text="example">
46+
<Token Kind=Null_Tok Text="null"> != <Token Kind=Null_Tok Text="null"> = true
47+
<Token Kind=Null_Tok Text="null">.equals(<Token Kind=Null_Tok Text="null">) = true
48+
<Token Kind=Whitespace Text=" "> != <Token Kind=Whitespace Text=" "> = true
49+
<Token Kind=Whitespace Text=" ">.equals(<Token Kind=Whitespace Text=" ">) = true
50+
<Token Kind=Identifier Text="identifier"> != <Token Kind=Identifier Text="identifier"> = true
51+
<Token Kind=Identifier Text="identifier">.equals(<Token Kind=Identifier Text="identifier">) = true
52+
<Token Kind=Whitespace Text=" "> != <Token Kind=Whitespace Text=" "> = true
53+
<Token Kind=Whitespace Text=" ">.equals(<Token Kind=Whitespace Text=" ">) = true
54+
<Token Kind=Example Text="example"> != <Token Kind=Example Text="example"> = true
55+
<Token Kind=Example Text="example">.equals(<Token Kind=Example Text="example">) = true
56+
<Token Kind=Whitespace Text=" "> != <Token Kind=Whitespace Text=" "> = true
57+
<Token Kind=Whitespace Text=" ">.equals(<Token Kind=Whitespace Text=" ">) = true
58+
<Token Kind=Identifier Text="identifier"> != <Token Kind=Identifier Text="identifier"> = true
59+
<Token Kind=Identifier Text="identifier">.equals(<Token Kind=Identifier Text="identifier">) = true
60+
<Token Kind=Whitespace Text=" "> != <Token Kind=Whitespace Text=" "> = true
61+
<Token Kind=Whitespace Text=" ">.equals(<Token Kind=Whitespace Text=" ">) = true
62+
<Token Kind=Example Text="example"> != <Token Kind=Example Text="example"> = true
63+
<Token Kind=Example Text="example">.equals(<Token Kind=Example Text="example">) = true
64+
<Token Kind=Termination Text=""> != <Token Kind=Termination Text=""> = true
65+
<Token Kind=Termination Text="">.equals(<Token Kind=Termination Text="">) = true
4666
--------------
4767

4868
--- Nodes ---

testsuite/tests/java_api/general/jni/test.out

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,26 @@ The NO_TOKEN = <Token Kind=No_Token Text="">
4343
Text range with a NO_TOKEN =
4444
Equivalent tokens : <Token Kind=Identifier Text="identifier"> and <Token Kind=Identifier Text="identifier">
4545
Equivalent tokens : <Token Kind=Example Text="example"> and <Token Kind=Example Text="example">
46+
<Token Kind=Null_Tok Text="null"> != <Token Kind=Null_Tok Text="null"> = true
47+
<Token Kind=Null_Tok Text="null">.equals(<Token Kind=Null_Tok Text="null">) = true
48+
<Token Kind=Whitespace Text=" "> != <Token Kind=Whitespace Text=" "> = true
49+
<Token Kind=Whitespace Text=" ">.equals(<Token Kind=Whitespace Text=" ">) = true
50+
<Token Kind=Identifier Text="identifier"> != <Token Kind=Identifier Text="identifier"> = true
51+
<Token Kind=Identifier Text="identifier">.equals(<Token Kind=Identifier Text="identifier">) = true
52+
<Token Kind=Whitespace Text=" "> != <Token Kind=Whitespace Text=" "> = true
53+
<Token Kind=Whitespace Text=" ">.equals(<Token Kind=Whitespace Text=" ">) = true
54+
<Token Kind=Example Text="example"> != <Token Kind=Example Text="example"> = true
55+
<Token Kind=Example Text="example">.equals(<Token Kind=Example Text="example">) = true
56+
<Token Kind=Whitespace Text=" "> != <Token Kind=Whitespace Text=" "> = true
57+
<Token Kind=Whitespace Text=" ">.equals(<Token Kind=Whitespace Text=" ">) = true
58+
<Token Kind=Identifier Text="identifier"> != <Token Kind=Identifier Text="identifier"> = true
59+
<Token Kind=Identifier Text="identifier">.equals(<Token Kind=Identifier Text="identifier">) = true
60+
<Token Kind=Whitespace Text=" "> != <Token Kind=Whitespace Text=" "> = true
61+
<Token Kind=Whitespace Text=" ">.equals(<Token Kind=Whitespace Text=" ">) = true
62+
<Token Kind=Example Text="example"> != <Token Kind=Example Text="example"> = true
63+
<Token Kind=Example Text="example">.equals(<Token Kind=Example Text="example">) = true
64+
<Token Kind=Termination Text=""> != <Token Kind=Termination Text=""> = true
65+
<Token Kind=Termination Text="">.equals(<Token Kind=Termination Text="">) = true
4666
--------------
4767

4868
--- Nodes ---

0 commit comments

Comments
 (0)