Skip to content

Commit 070aa55

Browse files
committed
JAVA-1960: Ensure type parameters have meaningful names
1 parent a559b4e commit 070aa55

25 files changed

Lines changed: 344 additions & 305 deletions

core/revapi.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@
514514
},
515515
{
516516
"code": "java.method.addedToInterface",
517-
"new": "method T com.datastax.oss.driver.api.core.cql.Statement<T extends com.datastax.oss.driver.api.core.cql.Statement<T extends com.datastax.oss.driver.api.core.cql.Statement<T>>>::setNode(com.datastax.oss.driver.api.core.metadata.Node)",
517+
"new": "method SelfT com.datastax.oss.driver.api.core.cql.Statement<SelfT extends com.datastax.oss.driver.api.core.cql.Statement<SelfT extends com.datastax.oss.driver.api.core.cql.Statement<SelfT>>>::setNode(com.datastax.oss.driver.api.core.metadata.Node)",
518518
"package": "com.datastax.oss.driver.api.core.cql",
519519
"classQualifiedName": "com.datastax.oss.driver.api.core.cql.Statement",
520520
"classSimpleName": "Statement",

core/src/main/java/com/datastax/oss/driver/api/core/cql/BatchableStatement.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
/**
1919
* A statement that can be added to a CQL batch.
2020
*
21-
* @param <T> the "self type" used for covariant returns in subtypes.
21+
* @param <SelfT> the "self type" used for covariant returns in subtypes.
2222
*/
23-
public interface BatchableStatement<T extends BatchableStatement<T>> extends Statement<T> {}
23+
public interface BatchableStatement<SelfT extends BatchableStatement<SelfT>>
24+
extends Statement<SelfT> {}

core/src/main/java/com/datastax/oss/driver/api/core/cql/Bindable.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
import edu.umd.cs.findbugs.annotations.NonNull;
2626

2727
/** A data container with the ability to unset values. */
28-
public interface Bindable<T extends Bindable<T>>
29-
extends GettableById, GettableByName, SettableById<T>, SettableByName<T> {
28+
public interface Bindable<SelfT extends Bindable<SelfT>>
29+
extends GettableById, GettableByName, SettableById<SelfT>, SettableByName<SelfT> {
3030
/**
3131
* Whether the {@code i}th value has been set.
3232
*
@@ -70,7 +70,7 @@ default boolean isSet(@NonNull String name) {
7070
* @throws IndexOutOfBoundsException if the index is invalid.
7171
*/
7272
@NonNull
73-
default T unset(int i) {
73+
default SelfT unset(int i) {
7474
return setBytesUnsafe(i, ProtocolConstants.UNSET_VALUE);
7575
}
7676

@@ -81,7 +81,7 @@ default T unset(int i) {
8181
* @throws IndexOutOfBoundsException if the id is invalid.
8282
*/
8383
@NonNull
84-
default T unset(@NonNull CqlIdentifier id) {
84+
default SelfT unset(@NonNull CqlIdentifier id) {
8585
return setBytesUnsafe(id, ProtocolConstants.UNSET_VALUE);
8686
}
8787

@@ -92,7 +92,7 @@ default T unset(@NonNull CqlIdentifier id) {
9292
* @throws IndexOutOfBoundsException if the name is invalid.
9393
*/
9494
@NonNull
95-
default T unset(@NonNull String name) {
95+
default SelfT unset(@NonNull String name) {
9696
return setBytesUnsafe(name, ProtocolConstants.UNSET_VALUE);
9797
}
9898
}

core/src/main/java/com/datastax/oss/driver/api/core/cql/Statement.java

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@
4141
/**
4242
* A request to execute a CQL query.
4343
*
44-
* @param <T> the "self type" used for covariant returns in subtypes.
44+
* @param <SelfT> the "self type" used for covariant returns in subtypes.
4545
*/
46-
public interface Statement<T extends Statement<T>> extends Request {
46+
public interface Statement<SelfT extends Statement<SelfT>> extends Request {
4747
// Implementation note: "CqlRequest" would be a better name, but we keep "Statement" to match
4848
// previous driver versions.
4949

@@ -76,7 +76,7 @@ public interface Statement<T extends Statement<T>> extends Request {
7676
* method. However custom implementations may choose to be mutable and return the same instance.
7777
*/
7878
@NonNull
79-
T setExecutionProfileName(@Nullable String newConfigProfileName);
79+
SelfT setExecutionProfileName(@Nullable String newConfigProfileName);
8080

8181
/**
8282
* Sets the execution profile to use for this statement.
@@ -85,7 +85,7 @@ public interface Statement<T extends Statement<T>> extends Request {
8585
* method. However custom implementations may choose to be mutable and return the same instance.
8686
*/
8787
@NonNull
88-
T setExecutionProfile(@Nullable DriverExecutionProfile newProfile);
88+
SelfT setExecutionProfile(@Nullable DriverExecutionProfile newProfile);
8989

9090
/**
9191
* Sets the keyspace to use for token-aware routing.
@@ -95,7 +95,7 @@ public interface Statement<T extends Statement<T>> extends Request {
9595
* @param newRoutingKeyspace The keyspace to use, or {@code null} to disable token-aware routing.
9696
*/
9797
@NonNull
98-
T setRoutingKeyspace(@Nullable CqlIdentifier newRoutingKeyspace);
98+
SelfT setRoutingKeyspace(@Nullable CqlIdentifier newRoutingKeyspace);
9999

100100
/**
101101
* Sets the {@link Node} that should handle this query.
@@ -119,7 +119,7 @@ public interface Statement<T extends Statement<T>> extends Request {
119119
* delegate to the configured load balancing policy.
120120
*/
121121
@NonNull
122-
T setNode(@Nullable Node node);
122+
SelfT setNode(@Nullable Node node);
123123

124124
/**
125125
* Shortcut for {@link #setRoutingKeyspace(CqlIdentifier)
@@ -129,7 +129,7 @@ public interface Statement<T extends Statement<T>> extends Request {
129129
* routing.
130130
*/
131131
@NonNull
132-
default T setRoutingKeyspace(@Nullable String newRoutingKeyspaceName) {
132+
default SelfT setRoutingKeyspace(@Nullable String newRoutingKeyspaceName) {
133133
return setRoutingKeyspace(
134134
newRoutingKeyspaceName == null ? null : CqlIdentifier.fromCql(newRoutingKeyspaceName));
135135
}
@@ -142,7 +142,7 @@ default T setRoutingKeyspace(@Nullable String newRoutingKeyspaceName) {
142142
* @param newRoutingKey The routing key to use, or {@code null} to disable token-aware routing.
143143
*/
144144
@NonNull
145-
T setRoutingKey(@Nullable ByteBuffer newRoutingKey);
145+
SelfT setRoutingKey(@Nullable ByteBuffer newRoutingKey);
146146

147147
/**
148148
* Sets the key to use for token-aware routing, when the partition key has multiple components.
@@ -152,7 +152,7 @@ default T setRoutingKeyspace(@Nullable String newRoutingKeyspaceName) {
152152
* can be {@code null}.
153153
*/
154154
@NonNull
155-
default T setRoutingKey(@NonNull ByteBuffer... newRoutingKeyComponents) {
155+
default SelfT setRoutingKey(@NonNull ByteBuffer... newRoutingKeyComponents) {
156156
return setRoutingKey(RoutingKey.compose(newRoutingKeyComponents));
157157
}
158158

@@ -165,7 +165,7 @@ default T setRoutingKey(@NonNull ByteBuffer... newRoutingKeyComponents) {
165165
* routing.
166166
*/
167167
@NonNull
168-
T setRoutingToken(@Nullable Token newRoutingToken);
168+
SelfT setRoutingToken(@Nullable Token newRoutingToken);
169169

170170
/**
171171
* Sets the custom payload to use for execution.
@@ -179,7 +179,7 @@ default T setRoutingKey(@NonNull ByteBuffer... newRoutingKeyComponents) {
179179
* it's never modified after being set on the statement).
180180
*/
181181
@NonNull
182-
T setCustomPayload(@NonNull Map<String, ByteBuffer> newCustomPayload);
182+
SelfT setCustomPayload(@NonNull Map<String, ByteBuffer> newCustomPayload);
183183

184184
/**
185185
* Sets the idempotence to use for execution.
@@ -191,7 +191,7 @@ default T setRoutingKey(@NonNull ByteBuffer... newRoutingKeyComponents) {
191191
* use the default idempotence defined in the configuration.
192192
*/
193193
@NonNull
194-
T setIdempotent(@Nullable Boolean newIdempotence);
194+
SelfT setIdempotent(@Nullable Boolean newIdempotence);
195195

196196
/**
197197
* Sets tracing for execution.
@@ -200,7 +200,7 @@ default T setRoutingKey(@NonNull ByteBuffer... newRoutingKeyComponents) {
200200
* method. However custom implementations may choose to be mutable and return the same instance.
201201
*/
202202
@NonNull
203-
T setTracing(boolean newTracing);
203+
SelfT setTracing(boolean newTracing);
204204

205205
/**
206206
* Returns the query timestamp, in microseconds, to send with the statement.
@@ -224,7 +224,7 @@ default T setRoutingKey(@NonNull ByteBuffer... newRoutingKeyComponents) {
224224
* @see TimestampGenerator
225225
*/
226226
@NonNull
227-
T setTimestamp(long newTimestamp);
227+
SelfT setTimestamp(long newTimestamp);
228228

229229
/**
230230
* Sets how long to wait for this request to complete. This is a global limit on the duration of a
@@ -235,7 +235,7 @@ default T setRoutingKey(@NonNull ByteBuffer... newRoutingKeyComponents) {
235235
* @see DefaultDriverOption#REQUEST_TIMEOUT
236236
*/
237237
@NonNull
238-
T setTimeout(@Nullable Duration newTimeout);
238+
SelfT setTimeout(@Nullable Duration newTimeout);
239239

240240
/**
241241
* Returns the paging state to send with the statement, or {@code null} if this statement has no
@@ -265,7 +265,7 @@ default T setRoutingKey(@NonNull ByteBuffer... newRoutingKeyComponents) {
265265
* if you do so, you must override {@link #copy(ByteBuffer)}.
266266
*/
267267
@NonNull
268-
T setPagingState(@Nullable ByteBuffer newPagingState);
268+
SelfT setPagingState(@Nullable ByteBuffer newPagingState);
269269

270270
/**
271271
* Returns the page size to use for the statement.
@@ -285,7 +285,7 @@ default T setRoutingKey(@NonNull ByteBuffer... newRoutingKeyComponents) {
285285
* @see DefaultDriverOption#REQUEST_PAGE_SIZE
286286
*/
287287
@NonNull
288-
T setPageSize(int newPageSize);
288+
SelfT setPageSize(int newPageSize);
289289

290290
/**
291291
* Returns the {@link ConsistencyLevel} to use for the statement.
@@ -304,7 +304,7 @@ default T setRoutingKey(@NonNull ByteBuffer... newRoutingKeyComponents) {
304304
* defined in the configuration.
305305
* @see DefaultDriverOption#REQUEST_CONSISTENCY
306306
*/
307-
T setConsistencyLevel(@Nullable ConsistencyLevel newConsistencyLevel);
307+
SelfT setConsistencyLevel(@Nullable ConsistencyLevel newConsistencyLevel);
308308

309309
/**
310310
* Returns the serial {@link ConsistencyLevel} to use for the statement.
@@ -324,7 +324,7 @@ default T setRoutingKey(@NonNull ByteBuffer... newRoutingKeyComponents) {
324324
* @see DefaultDriverOption#REQUEST_SERIAL_CONSISTENCY
325325
*/
326326
@NonNull
327-
T setSerialConsistencyLevel(@Nullable ConsistencyLevel newSerialConsistencyLevel);
327+
SelfT setSerialConsistencyLevel(@Nullable ConsistencyLevel newSerialConsistencyLevel);
328328

329329
/** Whether tracing information should be recorded for this statement. */
330330
boolean isTracing();
@@ -351,7 +351,7 @@ default T setRoutingKey(@NonNull ByteBuffer... newRoutingKeyComponents) {
351351
* your own mutable implementation, make sure it returns a different instance.
352352
*/
353353
@NonNull
354-
default T copy(@Nullable ByteBuffer newPagingState) {
354+
default SelfT copy(@Nullable ByteBuffer newPagingState) {
355355
return setPagingState(newPagingState);
356356
}
357357
}

core/src/main/java/com/datastax/oss/driver/api/core/cql/StatementBuilder.java

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,11 @@
3636
* @see PreparedStatement#boundStatementBuilder(Object...)
3737
*/
3838
@NotThreadSafe
39-
public abstract class StatementBuilder<T extends StatementBuilder<T, S>, S extends Statement<S>> {
39+
public abstract class StatementBuilder<
40+
SelfT extends StatementBuilder<SelfT, StatementT>, StatementT extends Statement<StatementT>> {
4041

4142
@SuppressWarnings("unchecked")
42-
private final T self = (T) this;
43+
private final SelfT self = (SelfT) this;
4344

4445
@Nullable protected String executionProfileName;
4546
@Nullable protected DriverExecutionProfile executionProfile;
@@ -61,7 +62,7 @@ protected StatementBuilder() {
6162
// nothing to do
6263
}
6364

64-
protected StatementBuilder(S template) {
65+
protected StatementBuilder(StatementT template) {
6566
this.executionProfileName = template.getExecutionProfileName();
6667
this.executionProfile = template.getExecutionProfile();
6768
this.routingKeyspace = template.getRoutingKeyspace();
@@ -85,22 +86,22 @@ protected StatementBuilder(S template) {
8586

8687
/** @see Statement#setExecutionProfileName(String) */
8788
@NonNull
88-
public T withExecutionProfileName(@Nullable String executionProfileName) {
89+
public SelfT withExecutionProfileName(@Nullable String executionProfileName) {
8990
this.executionProfileName = executionProfileName;
9091
return self;
9192
}
9293

9394
/** @see Statement#setExecutionProfile(DriverExecutionProfile) */
9495
@NonNull
95-
public T withExecutionProfile(@Nullable DriverExecutionProfile executionProfile) {
96+
public SelfT withExecutionProfile(@Nullable DriverExecutionProfile executionProfile) {
9697
this.executionProfile = executionProfile;
9798
this.executionProfileName = null;
9899
return self;
99100
}
100101

101102
/** @see Statement#setRoutingKeyspace(CqlIdentifier) */
102103
@NonNull
103-
public T withRoutingKeyspace(@Nullable CqlIdentifier routingKeyspace) {
104+
public SelfT withRoutingKeyspace(@Nullable CqlIdentifier routingKeyspace) {
104105
this.routingKeyspace = routingKeyspace;
105106
return self;
106107
}
@@ -110,28 +111,28 @@ public T withRoutingKeyspace(@Nullable CqlIdentifier routingKeyspace) {
110111
* withRoutingKeyspace(CqlIdentifier.fromCql(routingKeyspaceName))}.
111112
*/
112113
@NonNull
113-
public T withRoutingKeyspace(@Nullable String routingKeyspaceName) {
114+
public SelfT withRoutingKeyspace(@Nullable String routingKeyspaceName) {
114115
return withRoutingKeyspace(
115116
routingKeyspaceName == null ? null : CqlIdentifier.fromCql(routingKeyspaceName));
116117
}
117118

118119
/** @see Statement#setRoutingKey(ByteBuffer) */
119120
@NonNull
120-
public T withRoutingKey(@Nullable ByteBuffer routingKey) {
121+
public SelfT withRoutingKey(@Nullable ByteBuffer routingKey) {
121122
this.routingKey = routingKey;
122123
return self;
123124
}
124125

125126
/** @see Statement#setRoutingToken(Token) */
126127
@NonNull
127-
public T withRoutingToken(@Nullable Token routingToken) {
128+
public SelfT withRoutingToken(@Nullable Token routingToken) {
128129
this.routingToken = routingToken;
129130
return self;
130131
}
131132

132133
/** @see Statement#setCustomPayload(Map) */
133134
@NonNull
134-
public T addCustomPayload(@NonNull String key, @Nullable ByteBuffer value) {
135+
public SelfT addCustomPayload(@NonNull String key, @Nullable ByteBuffer value) {
135136
if (customPayloadBuilder == null) {
136137
customPayloadBuilder = NullAllowingImmutableMap.builder();
137138
}
@@ -141,69 +142,69 @@ public T addCustomPayload(@NonNull String key, @Nullable ByteBuffer value) {
141142

142143
/** @see Statement#setCustomPayload(Map) */
143144
@NonNull
144-
public T clearCustomPayload() {
145+
public SelfT clearCustomPayload() {
145146
customPayloadBuilder = null;
146147
return self;
147148
}
148149

149150
/** @see Statement#setIdempotent(Boolean) */
150151
@NonNull
151-
public T withIdempotence(@Nullable Boolean idempotent) {
152+
public SelfT withIdempotence(@Nullable Boolean idempotent) {
152153
this.idempotent = idempotent;
153154
return self;
154155
}
155156

156157
/** @see Statement#setTracing(boolean) */
157158
@NonNull
158-
public T withTracing() {
159+
public SelfT withTracing() {
159160
this.tracing = true;
160161
return self;
161162
}
162163

163164
/** @see Statement#setTimestamp(long) */
164165
@NonNull
165-
public T withTimestamp(long timestamp) {
166+
public SelfT withTimestamp(long timestamp) {
166167
this.timestamp = timestamp;
167168
return self;
168169
}
169170

170171
/** @see Statement#setPagingState(ByteBuffer) */
171172
@NonNull
172-
public T withPagingState(@Nullable ByteBuffer pagingState) {
173+
public SelfT withPagingState(@Nullable ByteBuffer pagingState) {
173174
this.pagingState = pagingState;
174175
return self;
175176
}
176177

177178
/** @see Statement#setPageSize(int) */
178179
@NonNull
179-
public T withPageSize(int pageSize) {
180+
public SelfT withPageSize(int pageSize) {
180181
this.pageSize = pageSize;
181182
return self;
182183
}
183184

184185
/** @see Statement#setConsistencyLevel(ConsistencyLevel) */
185186
@NonNull
186-
public T withConsistencyLevel(@Nullable ConsistencyLevel consistencyLevel) {
187+
public SelfT withConsistencyLevel(@Nullable ConsistencyLevel consistencyLevel) {
187188
this.consistencyLevel = consistencyLevel;
188189
return self;
189190
}
190191

191192
/** @see Statement#setSerialConsistencyLevel(ConsistencyLevel) */
192193
@NonNull
193-
public T withSerialConsistencyLevel(@Nullable ConsistencyLevel serialConsistencyLevel) {
194+
public SelfT withSerialConsistencyLevel(@Nullable ConsistencyLevel serialConsistencyLevel) {
194195
this.serialConsistencyLevel = serialConsistencyLevel;
195196
return self;
196197
}
197198

198199
/** @see Statement#setTimeout(Duration) */
199200
@NonNull
200-
public T withTimeout(@Nullable Duration timeout) {
201+
public SelfT withTimeout(@Nullable Duration timeout) {
201202
this.timeout = timeout;
202203
return self;
203204
}
204205

205206
/** @see Statement#setNode(Node) */
206-
public T withNode(@Nullable Node node) {
207+
public SelfT withNode(@Nullable Node node) {
207208
this.node = node;
208209
return self;
209210
}
@@ -216,5 +217,5 @@ protected Map<String, ByteBuffer> buildCustomPayload() {
216217
}
217218

218219
@NonNull
219-
public abstract S build();
220+
public abstract StatementT build();
220221
}

0 commit comments

Comments
 (0)