Skip to content

Commit 6eeee4c

Browse files
authored
Merge pull request #140 from eclipse/msp_issue123
Added equals and hashCode implementations to message types
2 parents ac3b8cf + 8541ca6 commit 6eeee4c

File tree

8 files changed

+267
-12
lines changed

8 files changed

+267
-12
lines changed

org.eclipse.lsp4j.jsonrpc.debug/src/main/java/org/eclipse/lsp4j/jsonrpc/debug/messages/DebugNotificationMessage.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,31 @@ public void setId(String id) {
3232
this.id = id;
3333
}
3434

35+
@Override
36+
public boolean equals(final Object obj) {
37+
if (this == obj)
38+
return true;
39+
if (obj == null)
40+
return false;
41+
if (getClass() != obj.getClass())
42+
return false;
43+
if (!super.equals(obj))
44+
return false;
45+
DebugNotificationMessage other = (DebugNotificationMessage) obj;
46+
if (this.id == null) {
47+
if (other.id != null)
48+
return false;
49+
} else if (!this.id.equals(other.id))
50+
return false;
51+
return true;
52+
}
53+
54+
@Override
55+
public int hashCode() {
56+
final int prime = 31;
57+
int result = super.hashCode();
58+
result = prime * result + ((this.id == null) ? 0 : this.id.hashCode());
59+
return result;
60+
}
61+
3562
}

org.eclipse.lsp4j.jsonrpc.debug/src/main/java/org/eclipse/lsp4j/jsonrpc/debug/messages/DebugResponseMessage.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,37 @@ public void setMethod(String method) {
4848
this.method = method;
4949
}
5050

51+
@Override
52+
public boolean equals(final Object obj) {
53+
if (this == obj)
54+
return true;
55+
if (obj == null)
56+
return false;
57+
if (getClass() != obj.getClass())
58+
return false;
59+
if (!super.equals(obj))
60+
return false;
61+
DebugResponseMessage other = (DebugResponseMessage) obj;
62+
if (this.responseId == null) {
63+
if (other.responseId != null)
64+
return false;
65+
} else if (!this.responseId.equals(other.responseId))
66+
return false;
67+
if (this.method == null) {
68+
if (other.method != null)
69+
return false;
70+
} else if (!this.method.equals(other.method))
71+
return false;
72+
return true;
73+
}
74+
75+
@Override
76+
public int hashCode() {
77+
final int prime = 31;
78+
int result = super.hashCode();
79+
result = prime * result + ((this.responseId == null) ? 0 : this.responseId.hashCode());
80+
result = prime * result + ((this.method == null) ? 0 : this.method.hashCode());
81+
return result;
82+
}
83+
5184
}

org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/messages/CancelParams.java

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,30 @@ public void setId(String id) {
3333
public String toString() {
3434
return MessageJsonHandler.toString(this);
3535
}
36-
36+
37+
@Override
38+
public boolean equals(final Object obj) {
39+
if (this == obj)
40+
return true;
41+
if (obj == null)
42+
return false;
43+
if (getClass() != obj.getClass())
44+
return false;
45+
CancelParams other = (CancelParams) obj;
46+
if (this.id == null) {
47+
if (other.id != null)
48+
return false;
49+
} else if (!this.id.equals(other.id))
50+
return false;
51+
return true;
52+
}
53+
54+
@Override
55+
public int hashCode() {
56+
final int prime = 31;
57+
int result = 1;
58+
result = prime * result + ((this.id == null) ? 0 : this.id.hashCode());
59+
return result;
60+
}
61+
3762
}

org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/messages/Message.java

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* uses "2.0" as the jsonrpc version.
1717
*/
1818
public abstract class Message {
19-
19+
2020
@NonNull
2121
private String jsonrpc = MessageConstants.JSONRPC_VERSION;
2222

@@ -27,10 +27,35 @@ public String getJsonrpc() {
2727
public void setJsonrpc(String jsonrpc) {
2828
this.jsonrpc = jsonrpc;
2929
}
30-
30+
3131
@Override
3232
public String toString() {
3333
return MessageJsonHandler.toString(this);
3434
}
35-
35+
36+
@Override
37+
public boolean equals(final Object obj) {
38+
if (this == obj)
39+
return true;
40+
if (obj == null)
41+
return false;
42+
if (getClass() != obj.getClass())
43+
return false;
44+
Message other = (Message) obj;
45+
if (this.jsonrpc == null) {
46+
if (other.jsonrpc != null)
47+
return false;
48+
} else if (!this.jsonrpc.equals(other.jsonrpc))
49+
return false;
50+
return true;
51+
}
52+
53+
@Override
54+
public int hashCode() {
55+
final int prime = 31;
56+
int result = 1;
57+
result = prime * result + ((this.jsonrpc == null) ? 0 : this.jsonrpc.hashCode());
58+
return result;
59+
}
60+
3661
}

org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/messages/NotificationMessage.java

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,38 @@ public Object getParams() {
4141
public void setParams(Object params) {
4242
this.params = params;
4343
}
44-
44+
45+
@Override
46+
public boolean equals(final Object obj) {
47+
if (this == obj)
48+
return true;
49+
if (obj == null)
50+
return false;
51+
if (getClass() != obj.getClass())
52+
return false;
53+
if (!super.equals(obj))
54+
return false;
55+
NotificationMessage other = (NotificationMessage) obj;
56+
if (this.method == null) {
57+
if (other.method != null)
58+
return false;
59+
} else if (!this.method.equals(other.method))
60+
return false;
61+
if (this.params == null) {
62+
if (other.params != null)
63+
return false;
64+
} else if (!this.params.equals(other.params))
65+
return false;
66+
return true;
67+
}
68+
69+
@Override
70+
public int hashCode() {
71+
final int prime = 31;
72+
int result = super.hashCode();
73+
result = prime * result + ((this.method == null) ? 0 : this.method.hashCode());
74+
result = prime * result + ((this.params == null) ? 0 : this.params.hashCode());
75+
return result;
76+
}
77+
4578
}

org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/messages/RequestMessage.java

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,44 @@ public Object getParams() {
5656
public void setParams(Object params) {
5757
this.params = params;
5858
}
59-
59+
60+
@Override
61+
public boolean equals(final Object obj) {
62+
if (this == obj)
63+
return true;
64+
if (obj == null)
65+
return false;
66+
if (getClass() != obj.getClass())
67+
return false;
68+
if (!super.equals(obj))
69+
return false;
70+
RequestMessage other = (RequestMessage) obj;
71+
if (this.id == null) {
72+
if (other.id != null)
73+
return false;
74+
} else if (!this.id.equals(other.id))
75+
return false;
76+
if (this.method == null) {
77+
if (other.method != null)
78+
return false;
79+
} else if (!this.method.equals(other.method))
80+
return false;
81+
if (this.params == null) {
82+
if (other.params != null)
83+
return false;
84+
} else if (!this.params.equals(other.params))
85+
return false;
86+
return true;
87+
}
88+
89+
@Override
90+
public int hashCode() {
91+
final int prime = 31;
92+
int result = super.hashCode();
93+
result = prime * result + ((this.id == null) ? 0 : this.id.hashCode());
94+
result = prime * result + ((this.method == null) ? 0 : this.method.hashCode());
95+
result = prime * result + ((this.params == null) ? 0 : this.params.hashCode());
96+
return result;
97+
}
98+
6099
}

org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/messages/ResponseError.java

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import org.eclipse.lsp4j.jsonrpc.validation.NonNull;
1212

1313
public class ResponseError {
14-
14+
1515
/**
1616
* A number indicating the error type that occured.
1717
*/
@@ -60,20 +60,54 @@ public void setData(Object data) {
6060

6161
public ResponseError() {
6262
}
63-
63+
6464
public ResponseError(ResponseErrorCode code, String message, Object data) {
6565
this(code.getValue(), message, data);
6666
}
67-
67+
6868
public ResponseError(int code, String message, Object data) {
6969
this.code = code;
7070
this.message = message;
7171
this.data = data;
7272
}
73-
73+
7474
@Override
7575
public String toString() {
7676
return MessageJsonHandler.toString(this);
7777
}
78-
78+
79+
@Override
80+
public boolean equals(final Object obj) {
81+
if (this == obj)
82+
return true;
83+
if (obj == null)
84+
return false;
85+
if (getClass() != obj.getClass())
86+
return false;
87+
ResponseError other = (ResponseError) obj;
88+
if (other.code != this.code)
89+
return false;
90+
if (this.message == null) {
91+
if (other.message != null)
92+
return false;
93+
} else if (!this.message.equals(other.message))
94+
return false;
95+
if (this.data == null) {
96+
if (other.data != null)
97+
return false;
98+
} else if (!this.data.equals(other.data))
99+
return false;
100+
return true;
101+
}
102+
103+
@Override
104+
public int hashCode() {
105+
final int prime = 31;
106+
int result = 1;
107+
result = prime * result + this.code;
108+
result = prime * result + ((this.message == null) ? 0 : this.message.hashCode());
109+
result = prime * result + ((this.data == null) ? 0 : this.data.hashCode());
110+
return result;
111+
}
112+
79113
}

org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/messages/ResponseMessage.java

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,44 @@ public ResponseError getError() {
5757
public void setError(ResponseError error) {
5858
this.error = error;
5959
}
60-
60+
61+
@Override
62+
public boolean equals(final Object obj) {
63+
if (this == obj)
64+
return true;
65+
if (obj == null)
66+
return false;
67+
if (getClass() != obj.getClass())
68+
return false;
69+
if (!super.equals(obj))
70+
return false;
71+
ResponseMessage other = (ResponseMessage) obj;
72+
if (this.id == null) {
73+
if (other.id != null)
74+
return false;
75+
} else if (!this.id.equals(other.id))
76+
return false;
77+
if (this.result == null) {
78+
if (other.result != null)
79+
return false;
80+
} else if (!this.result.equals(other.result))
81+
return false;
82+
if (this.error == null) {
83+
if (other.error != null)
84+
return false;
85+
} else if (!this.error.equals(other.error))
86+
return false;
87+
return true;
88+
}
89+
90+
@Override
91+
public int hashCode() {
92+
final int prime = 31;
93+
int result = super.hashCode();
94+
result = prime * result + ((this.id == null) ? 0 : this.id.hashCode());
95+
result = prime * result + ((this.result == null) ? 0 : this.result.hashCode());
96+
result = prime * result + ((this.error == null) ? 0 : this.error.hashCode());
97+
return result;
98+
}
99+
61100
}

0 commit comments

Comments
 (0)