Skip to content

Commit

Permalink
refact: remove unnecessary else clause
Browse files Browse the repository at this point in the history
  • Loading branch information
sebthom committed Mar 1, 2024
1 parent 6d45bcb commit 6e9fc55
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/******************************************************************************
* Copyright (c) 2016-2018 TypeFox and others.
*
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0,
* or the Eclipse Distribution License v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
******************************************************************************/
package org.eclipse.lsp4j.jsonrpc.debug;
Expand Down Expand Up @@ -38,7 +38,7 @@
* and an output stream.
*/
public final class DebugLauncher {

private DebugLauncher() {}

/**
Expand Down Expand Up @@ -191,22 +191,21 @@ public static <T> Launcher<T> createIoLauncher(Object localService, Class<T> rem
.configureGson(configureGson)
.create();
}

/**
* Launcher builder for the debug protocol. Adapts the JSON-RPC message classes to the JSON format used
* by the debug protocol.
*/
public static class Builder<T> extends Launcher.Builder<T> {

@Override
protected MessageJsonHandler createJsonHandler() {
Map<String, JsonRpcMethod> supportedMethods = getSupportedMethods();
if (configureGson != null)
return new DebugMessageJsonHandler(supportedMethods, configureGson);
else
return new DebugMessageJsonHandler(supportedMethods);
return new DebugMessageJsonHandler(supportedMethods);
}

@Override
protected RemoteEndpoint createRemoteEndpoint(MessageJsonHandler jsonHandler) {
MessageConsumer outgoingMessageStream = new StreamMessageConsumer(output, jsonHandler);
Expand All @@ -221,6 +220,6 @@ protected RemoteEndpoint createRemoteEndpoint(MessageJsonHandler jsonHandler) {
remoteEndpoint.setJsonHandler(jsonHandler);
return remoteEndpoint;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,8 @@ public Message read(JsonReader in) throws IOException {
Message resultMessage = createMessage(messageType, seq, request_seq, method, success, message, rawParams, rawBody);
MessageIssue issue = new MessageIssue("Message could not be parsed.", ResponseErrorCode.ParseError.getValue(), exception);
throw new MessageIssueException(resultMessage, issue);
} else {
throw exception;
}
throw exception;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,7 @@ protected MessageJsonHandler createJsonHandler() {
Map<String, JsonRpcMethod> supportedMethods = getSupportedMethods();
if (configureGson != null)
return new MessageJsonHandler(supportedMethods, configureGson);
else
return new MessageJsonHandler(supportedMethods);
return new MessageJsonHandler(supportedMethods);
}

/**
Expand All @@ -366,9 +365,8 @@ protected RemoteEndpoint createRemoteEndpoint(MessageJsonHandler jsonHandler) {
protected T createProxy(RemoteEndpoint remoteEndpoint) {
if (localServices.size() == 1 && remoteInterfaces.size() == 1) {
return ServiceEndpoints.toServiceObject(remoteEndpoint, remoteInterfaces.iterator().next());
} else {
return (T) ServiceEndpoints.toServiceObject(remoteEndpoint, (Collection<Class<?>>) (Object) remoteInterfaces, classLoader);
}
return (T) ServiceEndpoints.toServiceObject(remoteEndpoint, (Collection<Class<?>>) (Object) remoteInterfaces, classLoader);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,8 @@ protected boolean handleCancellation(NotificationMessage notificationMessage) {
LOG.warning("Unmatched cancel notification for request id " + id);
}
return true;
} else {
LOG.warning("Cancellation support is disabled, since the '" + MessageJsonHandler.CANCEL_METHOD.getMethodName() + "' method has been registered explicitly.");
}
LOG.warning("Cancellation support is disabled, since the '" + MessageJsonHandler.CANCEL_METHOD.getMethodName() + "' method has been registered explicitly.");
} else {
LOG.warning("Missing 'params' attribute of cancel notification.");
}
Expand All @@ -279,8 +278,7 @@ protected void handleRequest(RequestMessage requestMessage) {
out.consume(createErrorResponseMessage(requestMessage, errorObject));
if (throwable instanceof Error)
throw (Error) throwable;
else
return;
return;
}

final String messageId = requestMessage.getId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,8 @@ public Message read(JsonReader in) throws IOException, JsonIOException, JsonSynt
Message message = createMessage(jsonrpc, id, method, rawParams, rawResult, responseError);
final var issue = new MessageIssue("Message could not be parsed.", ResponseErrorCode.ParseError.getValue(), exception);
throw new MessageIssueException(message, issue);
} else {
throw exception;
}
throw exception;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ private static <T> Map<String, Type> createVariableMapping(Type type, Class<T> r
private static int capacity(int expectedSize) {
if (expectedSize < 3)
return expectedSize + 1;
else
return expectedSize + expectedSize / 3;
return expectedSize + expectedSize / 3;
}

private static Type getMappedType(Type type, Map<String, Type> varMapping) {
Expand Down Expand Up @@ -178,8 +177,7 @@ public String toString() {
private String toString(Type type) {
if (type instanceof Class<?>)
return ((Class<?>) type).getName();
else
return String.valueOf(type);
return String.valueOf(type);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,14 @@ public T2 getSecond() {
Either<T2, T3> right = getRight();
if (right == null)
return null;
else
return right.getLeft();
return right.getLeft();
}

public T3 getThird() {
Either<T2, T3> right = getRight();
if (right == null)
return null;
else
return right.getRight();
return right.getRight();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,7 @@ protected String getPropertyName(Method method) {
String methodName = method.getName();
if (methodName.startsWith("get") && methodName.length() > 3)
return methodName.substring(3, 4).toLowerCase() + methodName.substring(4);
else
return methodName;
return methodName;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,8 @@ public WorkDoneProgressNotification read(JsonReader in) throws IOException {
} catch (JsonSyntaxException | MalformedJsonException | EOFException exception) {
if (kind != null) {
throw new JsonParseException(exception);
} else {
throw exception;
}
throw exception;
}
}

Expand Down

0 comments on commit 6e9fc55

Please sign in to comment.