From d9b5d221775ce1cf9d95fbdb6af8f2fcce9b475f Mon Sep 17 00:00:00 2001 From: Vladimir Piskarev Date: Tue, 13 Feb 2024 15:32:41 +0300 Subject: [PATCH] Supply a Preconditions in common location This is a follow-up to #798, which handles `Preconditions` similarly to `ToStringBuilder`. See #742 for detailed discussion. --- CHANGELOG.md | 7 ++-- .../lsp4j/debug/util/Preconditions.java | 34 ------------------- .../generator/JsonRpcDataProcessor.xtend | 5 +-- .../lsp4j/jsonrpc}/util/Preconditions.java | 2 +- .../java/org/eclipse/lsp4j/Protocol.xtend | 2 +- .../eclipse/lsp4j/util/DocumentSymbols.java | 1 + .../org/eclipse/lsp4j/util/Positions.java | 1 + .../java/org/eclipse/lsp4j/util/Ranges.java | 1 + 8 files changed, 10 insertions(+), 43 deletions(-) delete mode 100644 org.eclipse.lsp4j.debug/src/main/java/org/eclipse/lsp4j/debug/util/Preconditions.java rename {org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j => org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc}/util/Preconditions.java (96%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0a6bf328..f8ec63c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,9 +11,10 @@ Breaking API changes: * See [#768](https://github.com/eclipse-lsp4j/lsp4j/issues/768) for detailed discussion. * The name field in WorkspaceFolder is no longer optional according to the specification. * See [#741](https://github.com/eclipse-lsp4j/lsp4j/issues/741) for detailed discussion. - * The LSP4J generator when applied to `@JsonRpcData` annotated classes generates a dependency on package `org.eclipse.lsp4j.jsonrpc.util` in the `org.eclipse.lsp4j.jsonrpc` bundle to provide an implementation of `ToStringBuilder`. - * This removes the implied requirement in LSP4J 0.21.0 that there is a class called `ToStringBuilder` in a sub-package called `util`. - * This also removes the duplicated class `ToStringBuilder` in packages `org.eclipse.lsp4j.debug.util` and `org.eclipse.lsp4j.util`. + * The LSP4J generator when applied to `@JsonRpcData` annotated classes generates a dependency on package `org.eclipse.lsp4j.jsonrpc.util` in the `org.eclipse.lsp4j.jsonrpc` bundle. + * This removes the implied requirement in LSP4J 0.21.0 that there are classes called `ToStringBuilder` and `Preconditions` in a sub-package called `util`; + instead, the generator now uses classes `ToStringBuilder` and `Preconditions` in package `org.eclipse.lsp4j.jsonrpc.util`. + * Duplicate classes `ToStringBuilder` and `Preconditions` have been removed from `org.eclipse.lsp4j.util` and `org.eclipse.lsp4j.debug.util` packages. * See [#742](https://github.com/eclipse-lsp4j/lsp4j/issues/742) for detailed discussion. Nightly japicmp report: diff --git a/org.eclipse.lsp4j.debug/src/main/java/org/eclipse/lsp4j/debug/util/Preconditions.java b/org.eclipse.lsp4j.debug/src/main/java/org/eclipse/lsp4j/debug/util/Preconditions.java deleted file mode 100644 index 6892a646..00000000 --- a/org.eclipse.lsp4j.debug/src/main/java/org/eclipse/lsp4j/debug/util/Preconditions.java +++ /dev/null @@ -1,34 +0,0 @@ -/****************************************************************************** - * Copyright (c) 2019 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.debug.util; - -/** - * Utilities for checking method and constructor arguments. - */ -public final class Preconditions { - - private Preconditions() {} - - private static boolean nullChecks = true; - - public static void enableNullChecks(boolean enable) { - Preconditions.nullChecks = enable; - } - - public static T checkNotNull(T object, String propertyName) { - if (nullChecks && object == null) { - throw new IllegalArgumentException("Property must not be null: " + propertyName); - } - return object; - } - -} diff --git a/org.eclipse.lsp4j.generator/src/main/java/org/eclipse/lsp4j/generator/JsonRpcDataProcessor.xtend b/org.eclipse.lsp4j.generator/src/main/java/org/eclipse/lsp4j/generator/JsonRpcDataProcessor.xtend index 19e32d42..fd226bbb 100644 --- a/org.eclipse.lsp4j.generator/src/main/java/org/eclipse/lsp4j/generator/JsonRpcDataProcessor.xtend +++ b/org.eclipse.lsp4j.generator/src/main/java/org/eclipse/lsp4j/generator/JsonRpcDataProcessor.xtend @@ -172,10 +172,7 @@ class JsonRpcDataProcessor extends AbstractClassProcessor { } private def getPreconditionsUtil(Type type, extension TransformationContext context) { - if (type.qualifiedName.startsWith('org.eclipse.lsp4j.debug')) - newTypeReference('org.eclipse.lsp4j.debug.util.Preconditions') - else - newTypeReference('org.eclipse.lsp4j.util.Preconditions') + newTypeReference('org.eclipse.lsp4j.jsonrpc.util.Preconditions') } } diff --git a/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/util/Preconditions.java b/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/util/Preconditions.java similarity index 96% rename from org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/util/Preconditions.java rename to org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/util/Preconditions.java index 2319b7dd..c9f5d361 100644 --- a/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/util/Preconditions.java +++ b/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/util/Preconditions.java @@ -9,7 +9,7 @@ * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause ******************************************************************************/ -package org.eclipse.lsp4j.util; +package org.eclipse.lsp4j.jsonrpc.util; /** * Utilities for checking method and constructor arguments. diff --git a/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/Protocol.xtend b/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/Protocol.xtend index 4a270611..4ceed372 100644 --- a/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/Protocol.xtend +++ b/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/Protocol.xtend @@ -34,8 +34,8 @@ import org.eclipse.lsp4j.jsonrpc.messages.Either import org.eclipse.lsp4j.jsonrpc.messages.Either3 import org.eclipse.lsp4j.jsonrpc.messages.ResponseErrorCode import org.eclipse.lsp4j.jsonrpc.messages.Tuple +import org.eclipse.lsp4j.jsonrpc.util.Preconditions import org.eclipse.lsp4j.jsonrpc.validation.NonNull -import org.eclipse.lsp4j.util.Preconditions @JsonRpcData class DynamicRegistrationCapabilities { diff --git a/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/util/DocumentSymbols.java b/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/util/DocumentSymbols.java index 0763b028..30b16397 100644 --- a/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/util/DocumentSymbols.java +++ b/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/util/DocumentSymbols.java @@ -16,6 +16,7 @@ import java.util.Queue; import org.eclipse.lsp4j.DocumentSymbol; +import org.eclipse.lsp4j.jsonrpc.util.Preconditions; /** * Utilities for {@link DocumentSymbol document symbols}. diff --git a/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/util/Positions.java b/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/util/Positions.java index a4affc7f..0623fab2 100644 --- a/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/util/Positions.java +++ b/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/util/Positions.java @@ -12,6 +12,7 @@ package org.eclipse.lsp4j.util; import org.eclipse.lsp4j.Position; +import org.eclipse.lsp4j.jsonrpc.util.Preconditions; /** * Utilities for the {@link Position}. diff --git a/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/util/Ranges.java b/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/util/Ranges.java index ebd4e698..246d72f8 100644 --- a/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/util/Ranges.java +++ b/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/util/Ranges.java @@ -13,6 +13,7 @@ import org.eclipse.lsp4j.Position; import org.eclipse.lsp4j.Range; +import org.eclipse.lsp4j.jsonrpc.util.Preconditions; /** * Utility class for {@link Range}.