diff options
author | Anna Koskinen <Ansku@users.noreply.github.com> | 2021-07-08 12:04:58 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-08 12:04:58 +0300 |
commit | 3afe45849edc79f0e7b371a7fd3ef209292dce79 (patch) | |
tree | 2934d3ca30286b3480d7c6b4c5d5bfc99aa196db /server | |
parent | 347d36dcbccb07f1dd46f17ea5be6fceecc755cb (diff) | |
download | vaadin-framework-3afe45849edc79f0e7b371a7fd3ef209292dce79.tar.gz vaadin-framework-3afe45849edc79f0e7b371a7fd3ef209292dce79.zip |
Code cleanup (#12333)
- removed unused private methods
- removed unused private variables
- removed unnecessary initializations
- removed unnecessary substring(0)
- removed inner assignments
- renamed private methods that started with upper case
- renamed static final variables to use upper case
- converted to use non-deprecated options
- suppressed unavoidable warnings
- divided long Strings to multiple lines
- added missing types
- added missing JavaDoc parameters
- formatting
- updated comments & JavaDocs
Diffstat (limited to 'server')
17 files changed, 188 insertions, 121 deletions
diff --git a/server/src/main/java/com/vaadin/server/DragAndDropService.java b/server/src/main/java/com/vaadin/server/DragAndDropService.java index 9d8ddf018e..903860c077 100644 --- a/server/src/main/java/com/vaadin/server/DragAndDropService.java +++ b/server/src/main/java/com/vaadin/server/DragAndDropService.java @@ -133,8 +133,7 @@ public class DragAndDropService implements VariableOwner, ClientConnector { * operation based on the info passed from the client widgets (drag * source for Transferable, drop target for DragDropDetails). */ - Transferable transferable = constructTransferable(dropTarget, - variables); + Transferable transferable = constructTransferable(variables); TargetDetails dropData = constructDragDropDetails(dropTarget, variables); DragAndDropEvent dropEvent = new DragAndDropEvent(transferable, @@ -161,8 +160,7 @@ public class DragAndDropService implements VariableOwner, ClientConnector { * operation based on the info passed from the client widgets (drag * source for Transferable, current target for DragDropDetails). */ - Transferable transferable = constructTransferable(dropTarget, - variables); + Transferable transferable = constructTransferable(variables); TargetDetails dragDropDetails = constructDragDropDetails(dropTarget, variables); @@ -207,8 +205,7 @@ public class DragAndDropService implements VariableOwner, ClientConnector { } @SuppressWarnings("unchecked") - private Transferable constructTransferable(DropTarget dropHandlerOwner, - Map<String, Object> variables) { + private Transferable constructTransferable(Map<String, Object> variables) { final Component sourceComponent = (Component) variables .get("component"); diff --git a/server/src/main/java/com/vaadin/server/JsonCodec.java b/server/src/main/java/com/vaadin/server/JsonCodec.java index 3d1d5af5e2..fffb560738 100644 --- a/server/src/main/java/com/vaadin/server/JsonCodec.java +++ b/server/src/main/java/com/vaadin/server/JsonCodec.java @@ -412,7 +412,7 @@ public class JsonCodec implements Serializable { // Arrays if (JsonConstants.VTYPE_ARRAY.equals(transportType)) { - return decodeObjectArray(targetType, (JsonArray) encodedJsonValue, + return decodeObjectArray((JsonArray) encodedJsonValue, connectorTracker); } else if (JsonConstants.VTYPE_STRINGARRAY.equals(transportType)) { @@ -625,13 +625,14 @@ public class JsonCodec implements Serializable { } } + @SuppressWarnings({ "rawtypes", "unchecked" }) private static Object decodeEnum(Class<? extends Enum> cls, JsonString value) { return Enum.valueOf(cls, value.getString()); } - private static Object[] decodeObjectArray(Type targetType, - JsonArray jsonArray, ConnectorTracker connectorTracker) { + private static Object[] decodeObjectArray(JsonArray jsonArray, + ConnectorTracker connectorTracker) { List<Object> list = decodeList(List.class, true, jsonArray, connectorTracker); return list.toArray(new Object[list.size()]); @@ -685,6 +686,7 @@ public class JsonCodec implements Serializable { } } + @SuppressWarnings("deprecation") public static EncodeResult encode(Object value, JsonValue diffState, Type valueType, ConnectorTracker connectorTracker) { @@ -1000,6 +1002,7 @@ public class JsonCodec implements Serializable { /* * Encodes a connector map. Invisible connectors are skipped. */ + @SuppressWarnings("deprecation") private static JsonObject encodeConnectorMap(Type valueType, Map<?, ?> map, ConnectorTracker connectorTracker) { JsonObject jsonMap = Json.createObject(); @@ -1040,6 +1043,7 @@ public class JsonCodec implements Serializable { return TYPE_TO_TRANSPORT_TYPE.get(getClassForType(valueType)); } + @SuppressWarnings({ "rawtypes", "unchecked" }) private static JsonValue serializeJson(Object value, ConnectorTracker connectorTracker) { JSONSerializer serializer = CUSTOM_SERIALIZERS.get(value.getClass()); diff --git a/server/src/main/java/com/vaadin/server/JsonPaintTarget.java b/server/src/main/java/com/vaadin/server/JsonPaintTarget.java index 4a247981f4..8c498e0ea2 100644 --- a/server/src/main/java/com/vaadin/server/JsonPaintTarget.java +++ b/server/src/main/java/com/vaadin/server/JsonPaintTarget.java @@ -45,7 +45,7 @@ import com.vaadin.ui.CustomLayout; * @author Vaadin Ltd. * @since 5.0 */ -@SuppressWarnings("serial") +@SuppressWarnings({ "deprecation", "serial" }) public class JsonPaintTarget implements PaintTarget { /* Document type declarations */ @@ -82,6 +82,7 @@ public class JsonPaintTarget implements PaintTarget { * Creates a new JsonPaintTarget. * * @param manager + * communication manager * @param outWriter * A character-output stream. * @param cachingRequired @@ -124,6 +125,8 @@ public class JsonPaintTarget implements PaintTarget { * * @param tagName * the name of the start tag. + * @param isChildNode + * {@code true} if child node, {@code false} otherwise * @throws PaintException * if the paint operation failed. * @@ -181,9 +184,7 @@ public class JsonPaintTarget implements PaintTarget { if (!openJsonTags.isEmpty()) { final JsonTag parent = openJsonTags.pop(); - String lastTag = ""; - - lastTag = mOpenTags.pop(); + String lastTag = mOpenTags.pop(); if (!tagName.equalsIgnoreCase(lastTag)) { throw new PaintException("Invalid UIDL: wrong ending tag: '" + tagName + "' expected: '" + lastTag + "'."); diff --git a/server/src/main/java/com/vaadin/server/VaadinServlet.java b/server/src/main/java/com/vaadin/server/VaadinServlet.java index 3ddbd956e9..f0ec0427bf 100644 --- a/server/src/main/java/com/vaadin/server/VaadinServlet.java +++ b/server/src/main/java/com/vaadin/server/VaadinServlet.java @@ -78,7 +78,7 @@ import elemental.json.Json; import elemental.json.JsonArray; import elemental.json.JsonObject; -@SuppressWarnings("serial") +@SuppressWarnings({ "deprecation", "serial" }) public class VaadinServlet extends HttpServlet implements Constants { private class ScssCacheEntry implements Serializable { @@ -197,9 +197,13 @@ public class VaadinServlet extends HttpServlet implements Constants { private VaadinServletService servletService; - // Mapped uri is for the jar file - static final Map<URI, Integer> openFileSystems = new HashMap<>(); - private static final Object fileSystemLock = new Object(); + /** + * Mapped uri is for the jar file. + * <p> + * FOR INTERNAL USE ONLY, may get renamed or removed. + */ + static final Map<URI, Integer> OPEN_FILE_SYSTEMS = new HashMap<>(); + private static final Object FILE_SYSTEM_LOCK = new Object(); /** * Called by the servlet container to indicate to a servlet that the servlet @@ -696,6 +700,7 @@ public class VaadinServlet extends HttpServlet implements Constants { * servers). * * @param servletContext + * the {@link ServletContext} in which this servlet is running * @param path * the resource path. * @return the resource path. @@ -706,8 +711,7 @@ public class VaadinServlet extends HttpServlet implements Constants { @Deprecated protected static String getResourcePath(ServletContext servletContext, String path) { - String resultPath = null; - resultPath = servletContext.getRealPath(path); + String resultPath = servletContext.getRealPath(path); if (resultPath != null) { return resultPath; } else { @@ -729,7 +733,8 @@ public class VaadinServlet extends HttpServlet implements Constants { * e.g. '(' and ')', so values should be safe in javascript too. * * @param themeName - * @return + * name of the theme + * @return name of the theme without special characters * * @deprecated As of 7.0. Will likely change or be removed in a future * version @@ -782,7 +787,7 @@ public class VaadinServlet extends HttpServlet implements Constants { /** * Returns the default theme. Must never return null. * - * @return + * @return default theme name */ public static String getDefaultTheme() { return DEFAULT_THEME_NAME; @@ -825,7 +830,9 @@ public class VaadinServlet extends HttpServlet implements Constants { * @param response * The response * @throws IOException + * if an I/O exception occurs * @throws ServletException + * if a servlet exception occurs * * @since 8.5 */ @@ -971,6 +978,7 @@ public class VaadinServlet extends HttpServlet implements Constants { * @param resourceUrl * The url to send * @throws IOException + * if an I/O exception occurs */ protected void writeStaticResourceResponse(HttpServletRequest request, HttpServletResponse response, URL resourceUrl) throws IOException { @@ -1228,8 +1236,11 @@ public class VaadinServlet extends HttpServlet implements Constants { * outside the VAADIN directory if the method is overridden. * * @param request + * current request * @param resourceUrl - * @return + * URL of the resource to validate + * @return {@code true} if the resource is a valid VAADIN resource, + * {@code false} otherwise * * @since 6.6.7 * @@ -1356,7 +1367,7 @@ public class VaadinServlet extends HttpServlet implements Constants { // Package protected for feature verification purpose FileSystem getFileSystem(URI resourceURI) throws IOException { - synchronized (fileSystemLock) { + synchronized (FILE_SYSTEM_LOCK) { URI fileURI = getFileURI(resourceURI); if (!fileURI.getScheme().equals("file")) { throw new IOException("Can not read scheme '" @@ -1364,7 +1375,7 @@ public class VaadinServlet extends HttpServlet implements Constants { + " and will determine this as not a folder"); } - Integer locks = openFileSystems.computeIfPresent(fileURI, + Integer locks = OPEN_FILE_SYSTEMS.computeIfPresent(fileURI, (key, value) -> value + 1); if (locks != null) { // Get filesystem is for the file to get the correct provider @@ -1373,20 +1384,20 @@ public class VaadinServlet extends HttpServlet implements Constants { // Opened filesystem is for the file to get the correct provider FileSystem fileSystem = FileSystems.newFileSystem(resourceURI, Collections.emptyMap()); - openFileSystems.put(fileURI, 1); + OPEN_FILE_SYSTEMS.put(fileURI, 1); return fileSystem; } } // Package protected for feature verification purpose void closeFileSystem(URI resourceURI) { - synchronized (fileSystemLock) { + synchronized (FILE_SYSTEM_LOCK) { try { URI fileURI = getFileURI(resourceURI); - Integer locks = openFileSystems.computeIfPresent(fileURI, + Integer locks = OPEN_FILE_SYSTEMS.computeIfPresent(fileURI, (key, value) -> value - 1); if (locks != null && locks == 0) { - openFileSystems.remove(fileURI); + OPEN_FILE_SYSTEMS.remove(fileURI); // Get filesystem is for the file to get the correct // provider FileSystems.getFileSystem(resourceURI).close(); @@ -1459,7 +1470,8 @@ public class VaadinServlet extends HttpServlet implements Constants { /** * @param request - * @return + * the request that is to be evaluated + * @return request type * * @deprecated As of 7.0. This is no longer used and only provided for * backwards compatibility. Each {@link RequestHandler} can @@ -1574,6 +1586,7 @@ public class VaadinServlet extends HttpServlet implements Constants { * * @param request * the HTTP request. + * @return current application URL * @throws MalformedURLException * if the application is denied access to the persistent data * store represented by the given URL. @@ -1687,6 +1700,7 @@ public class VaadinServlet extends HttpServlet implements Constants { * characters" to keep the text somewhat readable. * * @param unsafe + * the string that needs to be made safe * @return a safe string to be added inside an html tag * * @deprecated As of 7.0. Will likely change or be removed in a future @@ -1714,10 +1728,9 @@ public class VaadinServlet extends HttpServlet implements Constants { private static boolean isSafe(char c) { return // - c > 47 && c < 58 || // alphanum - c > 64 && c < 91 || // A-Z - c > 96 && c < 123 // a-z - ; + (c > 47 && c < 58) || // alphanum + (c > 64 && c < 91) || // A-Z + (c > 96 && c < 123); // a-z } private static final Logger getLogger() { diff --git a/server/src/main/java/com/vaadin/server/communication/ResourceWriter.java b/server/src/main/java/com/vaadin/server/communication/ResourceWriter.java index 9ae5fd41fd..f9b687b567 100644 --- a/server/src/main/java/com/vaadin/server/communication/ResourceWriter.java +++ b/server/src/main/java/com/vaadin/server/communication/ResourceWriter.java @@ -26,7 +26,6 @@ import java.util.logging.Level; import java.util.logging.Logger; import com.vaadin.server.JsonPaintTarget; -import com.vaadin.server.LegacyCommunicationManager; import com.vaadin.ui.CustomLayout; import com.vaadin.ui.UI; @@ -53,10 +52,6 @@ public class ResourceWriter implements Serializable { public void write(UI ui, Writer writer, JsonPaintTarget target) throws IOException { - // TODO PUSH Refactor so that this is not needed - LegacyCommunicationManager manager = ui.getSession() - .getCommunicationManager(); - // Precache custom layouts // TODO We should only precache the layouts that are not diff --git a/server/src/main/java/com/vaadin/server/communication/ServerRpcHandler.java b/server/src/main/java/com/vaadin/server/communication/ServerRpcHandler.java index 2c9d15bdd3..460e458aba 100644 --- a/server/src/main/java/com/vaadin/server/communication/ServerRpcHandler.java +++ b/server/src/main/java/com/vaadin/server/communication/ServerRpcHandler.java @@ -31,7 +31,6 @@ import java.util.logging.Logger; import com.vaadin.server.ClientConnector; import com.vaadin.server.Constants; import com.vaadin.server.JsonCodec; -import com.vaadin.server.LegacyCommunicationManager; import com.vaadin.server.LegacyCommunicationManager.InvalidUIDLSecurityKeyException; import com.vaadin.server.ServerRpcManager; import com.vaadin.server.ServerRpcManager.RpcInvocationException; @@ -64,6 +63,7 @@ import elemental.json.impl.JsonUtil; * @author Vaadin Ltd * @since 7.1 */ +@SuppressWarnings("deprecation") public class ServerRpcHandler implements Serializable { /** @@ -212,6 +212,7 @@ public class ServerRpcHandler implements Serializable { * @param reader * The {@link Reader} used to read the JSON. * @param request + * The {@link VaadinRequest} to handle. * @throws IOException * If reading the message fails. * @throws InvalidUIDLSecurityKeyException @@ -332,8 +333,7 @@ public class ServerRpcHandler implements Serializable { Set<Connector> enabledConnectors = new HashSet<>(); List<MethodInvocation> invocations = parseInvocations( - ui.getConnectorTracker(), invocationsData, - lastSyncIdSeenByClient); + ui.getConnectorTracker(), invocationsData); for (MethodInvocation invocation : invocations) { final ClientConnector connector = connectorTracker .getConnector(invocation.getConnectorId()); @@ -489,14 +489,10 @@ public class ServerRpcHandler implements Serializable { * @param invocationsJson * JSON containing all information needed to execute all * requested RPC calls. - * @param lastSyncIdSeenByClient - * the most recent sync id the client has seen at the time the - * request was sent * @return list of MethodInvocation to perform */ private List<MethodInvocation> parseInvocations( - ConnectorTracker connectorTracker, JsonArray invocationsJson, - int lastSyncIdSeenByClient) { + ConnectorTracker connectorTracker, JsonArray invocationsJson) { int invocationCount = invocationsJson.length(); List<MethodInvocation> invocations = new ArrayList<>(invocationCount); @@ -507,8 +503,7 @@ public class ServerRpcHandler implements Serializable { JsonArray invocationJson = invocationsJson.getArray(i); MethodInvocation invocation = parseInvocation(invocationJson, - previousInvocation, connectorTracker, - lastSyncIdSeenByClient); + previousInvocation, connectorTracker); if (invocation != null) { // Can be null if the invocation was a legacy invocation and it // was merged with the previous one or if the invocation was @@ -522,7 +517,7 @@ public class ServerRpcHandler implements Serializable { private MethodInvocation parseInvocation(JsonArray invocationJson, MethodInvocation previousInvocation, - ConnectorTracker connectorTracker, long lastSyncIdSeenByClient) { + ConnectorTracker connectorTracker) { String connectorId = invocationJson.getString(0); String interfaceName = invocationJson.getString(1); String methodName = invocationJson.getString(2); @@ -536,7 +531,6 @@ public class ServerRpcHandler implements Serializable { } return parseLegacyChangeVariablesInvocation(connectorId, - interfaceName, methodName, (LegacyChangeVariablesInvocation) previousInvocation, parametersJson, connectorTracker); } else { @@ -547,7 +541,7 @@ public class ServerRpcHandler implements Serializable { } private LegacyChangeVariablesInvocation parseLegacyChangeVariablesInvocation( - String connectorId, String interfaceName, String methodName, + String connectorId, LegacyChangeVariablesInvocation previousInvocation, JsonArray parametersJson, ConnectorTracker connectorTracker) { if (parametersJson.length() != 2) { @@ -643,10 +637,12 @@ public class ServerRpcHandler implements Serializable { } /** - * Generates an error message when the client is trying to to something + * Generates an error message when the client is trying to do something * ('what') with a connector which is disabled or invisible. * * @since 7.1.8 + * @param what + * the ignored operation * @param connector * the connector which is disabled (or invisible) * @return an error message diff --git a/server/src/main/java/com/vaadin/server/communication/UidlRequestHandler.java b/server/src/main/java/com/vaadin/server/communication/UidlRequestHandler.java index 43a3e0d664..b0e779ad5e 100644 --- a/server/src/main/java/com/vaadin/server/communication/UidlRequestHandler.java +++ b/server/src/main/java/com/vaadin/server/communication/UidlRequestHandler.java @@ -46,6 +46,7 @@ import elemental.json.JsonException; * @author Vaadin Ltd * @since 7.1 */ +@SuppressWarnings("deprecation") public class UidlRequestHandler extends SynchronizedRequestHandler implements SessionExpiredHandler { @@ -89,7 +90,7 @@ public class UidlRequestHandler extends SynchronizedRequestHandler try { rpcHandler.handleRpc(uI, request.getReader(), request); - writeUidl(request, response, uI, stringWriter); + writeUidl(response, uI, stringWriter); } catch (JsonException e) { getLogger().log(Level.SEVERE, "Error writing JSON to response", e); // Refresh on client side @@ -117,8 +118,8 @@ public class UidlRequestHandler extends SynchronizedRequestHandler UIInitHandler.commitJsonResponse(request, response, json); } - private void writeUidl(VaadinRequest request, VaadinResponse response, - UI ui, Writer writer) throws IOException { + private void writeUidl(VaadinResponse response, UI ui, Writer writer) + throws IOException { openJsonMessage(writer, response); new UidlWriter().write(ui, writer, false); diff --git a/server/src/main/java/com/vaadin/server/widgetsetutils/ClassPathExplorer.java b/server/src/main/java/com/vaadin/server/widgetsetutils/ClassPathExplorer.java index 4d51d288c5..1aec57c1a4 100644 --- a/server/src/main/java/com/vaadin/server/widgetsetutils/ClassPathExplorer.java +++ b/server/src/main/java/com/vaadin/server/widgetsetutils/ClassPathExplorer.java @@ -52,8 +52,6 @@ import java.util.jar.Manifest; */ public class ClassPathExplorer { - private static final String VAADIN_ADDON_VERSION_ATTRIBUTE = "Vaadin-Package-Version"; - /** * File filter that only accepts directories. */ diff --git a/server/src/main/java/com/vaadin/ui/AbstractDateField.java b/server/src/main/java/com/vaadin/ui/AbstractDateField.java index d194363b94..c22aff114d 100644 --- a/server/src/main/java/com/vaadin/ui/AbstractDateField.java +++ b/server/src/main/java/com/vaadin/ui/AbstractDateField.java @@ -427,7 +427,7 @@ public abstract class AbstractDateField<T extends Temporal & TemporalAdjuster & } /** - * Parses string representaion of date range limit into date type + * Parses string representation of date range limit into date type. * * @param temporalStr * the string representation @@ -1005,7 +1005,7 @@ public abstract class AbstractDateField<T extends Temporal & TemporalAdjuster & .orElse(null)); } - private Iterable<R> getResolutionsHigherOrEqualTo(R resoution) { + private Iterable<R> getResolutionsHigherOrEqualTo(R resolution) { return getResolutions().skip(resolution.ordinal()) .collect(Collectors.toList()); } @@ -1141,10 +1141,11 @@ public abstract class AbstractDateField<T extends Temporal & TemporalAdjuster & } /** - * Control whether value change event is emitted when user input value - * does not meet the integrated range validator. + * Control whether value change event is emitted when user input value does + * not meet the integrated range validator. * - * @param preventInvalidInput Set to false to disable the value change event. + * @param preventInvalidInput + * Set to false to disable the value change event. * * @since 8.13 */ @@ -1153,8 +1154,8 @@ public abstract class AbstractDateField<T extends Temporal & TemporalAdjuster & } /** - * Check whether value change is emitted when user input value does - * not meet integrated range validator. The default is false. + * Check whether value change is emitted when user input value does not meet + * integrated range validator. The default is false. * * @return a Boolean value * diff --git a/server/src/main/java/com/vaadin/ui/Grid.java b/server/src/main/java/com/vaadin/ui/Grid.java index 7ffd333430..137f947401 100644 --- a/server/src/main/java/com/vaadin/ui/Grid.java +++ b/server/src/main/java/com/vaadin/ui/Grid.java @@ -275,7 +275,7 @@ public class Grid<T> extends AbstractListing<T> implements HasComponents, * <code>true</code> if event is a result of user * interaction, <code>false</code> if from API call */ - public ColumnReorderEvent(Grid source, boolean userOriginated) { + public ColumnReorderEvent(Grid<?> source, boolean userOriginated) { super(source); this.userOriginated = userOriginated; } @@ -306,6 +306,8 @@ public class Grid<T> extends AbstractListing<T> implements HasComponents, * * @param source * the grid where the event originated from + * @param column + * the column that was resized * @param userOriginated * <code>true</code> if event is a result of user * interaction, <code>false</code> if from API call @@ -356,6 +358,16 @@ public class Grid<T> extends AbstractListing<T> implements HasComponents, * Creates a new {@code ItemClick} event containing the given item and * Column originating from the given Grid. * + * @param source + * the grid where the event originated from + * @param column + * the column that contains the clicked cell + * @param item + * the item that was clicked + * @param mouseEventDetails + * mouse event details about the click + * @param rowIndex + * the index of the row that contains the clicked cell */ public ItemClick(Grid<T> source, Column<T, ?> column, T item, MouseEventDetails mouseEventDetails, int rowIndex) { @@ -390,6 +402,7 @@ public class Grid<T> extends AbstractListing<T> implements HasComponents, * @return the grid */ @Override + @SuppressWarnings("unchecked") public Grid<T> getSource() { return (Grid<T>) super.getSource(); } @@ -501,6 +514,7 @@ public class Grid<T> extends AbstractListing<T> implements HasComponents, } @Override + @SuppressWarnings("unchecked") public Grid<T> getComponent() { return (Grid<T>) super.getComponent(); } @@ -849,18 +863,18 @@ public class Grid<T> extends AbstractListing<T> implements HasComponents, public static class Column<T, V> extends AbstractExtension { /** - * behavior when parsing nested properties which may contain - * <code>null</code> values in the property chain + * Behavior when parsing nested properties which may contain + * <code>null</code> values in the property chain. */ public enum NestedNullBehavior { /** - * throw a NullPointerException if there is a nested - * <code>null</code> value + * Throw a NullPointerException if there is a nested + * <code>null</code> value. */ THROW, /** - * silently ignore any exceptions caused by nested <code>null</code> - * values + * Silently ignore any exceptions caused by nested <code>null</code> + * values. */ ALLOW_NULLS } @@ -1578,6 +1592,7 @@ public class Grid<T> extends AbstractListing<T> implements HasComponents, * the expand ratio of this column. {@code 0} to not have it * expand at all. A negative number to clear the expand * value. + * @return this column * @throws IllegalStateException * if the column is no longer attached to any grid * @see #setWidth(double) @@ -1607,6 +1622,7 @@ public class Grid<T> extends AbstractListing<T> implements HasComponents, * <p> * Equal to calling {@link #setExpandRatio(int) setExpandRatio(-1)} * + * @return this column * @throws IllegalStateException * if the column is no longer attached to any grid */ @@ -1790,6 +1806,7 @@ public class Grid<T> extends AbstractListing<T> implements HasComponents, * * @param pixels * the maximum width + * @return this column * @throws IllegalStateException * if the column is no longer attached to any grid * @see #setExpandRatio(int) @@ -1826,6 +1843,7 @@ public class Grid<T> extends AbstractListing<T> implements HasComponents, * @param resizable * {@code true} if this column should be resizable, * {@code false} otherwise + * @return this column * @throws IllegalStateException * if the column is no longer attached to any grid */ @@ -1961,8 +1979,8 @@ public class Grid<T> extends AbstractListing<T> implements HasComponents, * {@code true} if column is editable; {@code false} if not * @return this column * @throws IllegalStateException - * if editable is true and column has no editor binding or - * component defined + * if editable is true and column has no editor binding or + * component defined * * @see #setEditorComponent(HasValue, Setter) * @see #setEditorBinding(Binding) @@ -2045,6 +2063,9 @@ public class Grid<T> extends AbstractListing<T> implements HasComponents, * <strong>Note:</strong> The same component cannot be used for multiple * columns. * + * @param <C> + * a class that extends both {@link HasValue} and + * {@link Component} * @param editorComponent * the editor component * @param setter @@ -2081,6 +2102,11 @@ public class Grid<T> extends AbstractListing<T> implements HasComponents, * <strong>Note:</strong> The same component cannot be used for multiple * columns. * + * @param <F> + * a value type + * @param <C> + * a class that extends both {@link HasValue} (for type + * {@code <F>}) and {@link Component} * @param editorComponent * the editor component * @return this column @@ -2113,8 +2139,8 @@ public class Grid<T> extends AbstractListing<T> implements HasComponents, * all currently available row data to be recreated and sent to the * client. * - * Note: Setting a new renderer will reset presentation provider if - * it exists. + * Note: Setting a new renderer will reset presentation provider if it + * exists. * * @param renderer * the new renderer @@ -2660,6 +2686,8 @@ public class Grid<T> extends AbstractListing<T> implements HasComponents, * @see Grid#Grid() * @see Grid#Grid(Class) * + * @param <BEAN> + * the grid bean type * @param propertySet * the property set implementation to use, not <code>null</code>. * @return a new grid using the provided property set, not <code>null</code> @@ -2875,6 +2903,8 @@ public class Grid<T> extends AbstractListing<T> implements HasComponents, * * @param valueProvider * the value provider + * @param <V> + * the column value type * * @return the new column */ @@ -3061,8 +3091,8 @@ public class Grid<T> extends AbstractListing<T> implements HasComponents, /** * Removes the given column from this {@link Grid}. * - * Note: If you have Editor with binding in this Grid to this property, you need to remove that - * using removeBinding method provided by Binder. + * Note: If you have Editor with binding in this Grid to this property, you + * need to remove that using removeBinding method provided by Binder. * * @param column * the column to remove @@ -4014,6 +4044,7 @@ public class Grid<T> extends AbstractListing<T> implements HasComponents, * * @see Column#setId(String) */ + @SuppressWarnings("unchecked") public void setColumns(String... columnIds) { // Must extract to an explicitly typed variable because otherwise javac // cannot determine which overload of setColumnOrder to use @@ -4068,6 +4099,7 @@ public class Grid<T> extends AbstractListing<T> implements HasComponents, * @param columns * the columns in the order they should be */ + @SuppressWarnings("unchecked") public void setColumnOrder(Column<T, ?>... columns) { setColumnOrder(Stream.of(columns)); } @@ -4133,6 +4165,11 @@ public class Grid<T> extends AbstractListing<T> implements HasComponents, return new GridSingleSelect<>(this); } + /** + * Returns the {@link Editor} for this grid. + * + * @return the editor, not null + */ public Editor<T> getEditor() { return editor; } @@ -4223,6 +4260,7 @@ public class Grid<T> extends AbstractListing<T> implements HasComponents, * * @see #getSelectionModel() * @see GridSelectionModel + * @return the items in the current selection, not null */ public Set<T> getSelectedItems() { return getSelectionModel().getSelectedItems(); @@ -4234,6 +4272,8 @@ public class Grid<T> extends AbstractListing<T> implements HasComponents, * * @see #getSelectionModel() * @see GridSelectionModel + * @param item + * the item to select, not null */ public void select(T item) { getSelectionModel().select(item); @@ -4245,6 +4285,8 @@ public class Grid<T> extends AbstractListing<T> implements HasComponents, * * @see #getSelectionModel() * @see GridSelectionModel + * @param item + * the item to deselect, not null */ public void deselect(T item) { getSelectionModel().deselect(item); @@ -4849,10 +4891,10 @@ public class Grid<T> extends AbstractListing<T> implements HasComponents, */ protected void writeData(Element body, DesignContext designContext) { getDataProvider().fetch(new Query<>()) - .forEach(item -> writeRow(body, item, designContext)); + .forEach(item -> writeRow(body, item)); } - private void writeRow(Element container, T item, DesignContext context) { + private void writeRow(Element container, T item) { Element tableRow = container.appendElement("tr"); tableRow.attr("item", serializeDeclarativeRepresentation(item)); if (getSelectionModel().isSelected(item)) { diff --git a/server/src/main/java/com/vaadin/ui/GridLayout.java b/server/src/main/java/com/vaadin/ui/GridLayout.java index 42886fd650..a65a3717c0 100644 --- a/server/src/main/java/com/vaadin/ui/GridLayout.java +++ b/server/src/main/java/com/vaadin/ui/GridLayout.java @@ -641,6 +641,7 @@ public class GridLayout extends AbstractLayout * Constructs an <code>OverlapsException</code>. * * @param existingArea + * the existing area that needs overlapping */ public OverlapsException(Area existingArea) { this.existingArea = existingArea; @@ -698,6 +699,7 @@ public class GridLayout extends AbstractLayout * detail message. * * @param areaOutOfBounds + * the area that exceeds the bounds of the grid */ public OutOfBoundsException(Area areaOutOfBounds) { super(String.format("%s, layout dimension: %sx%s", areaOutOfBounds, @@ -837,6 +839,7 @@ public class GridLayout extends AbstractLayout * by GridLayout. * * @param cursorX + * current cursor x-position */ public void setCursorX(int cursorX) { this.cursorX = cursorX; @@ -1058,7 +1061,9 @@ public class GridLayout extends AbstractLayout * @see #setWidth(float, Unit) * * @param columnIndex + * The column index, starting from 0 for the leftmost row. * @param ratio + * the expand ratio */ public void setColumnExpandRatio(int columnIndex, float ratio) { columnExpandRatio.put(columnIndex, ratio); @@ -1072,6 +1077,7 @@ public class GridLayout extends AbstractLayout * @see #setColumnExpandRatio(int, float) * * @param columnIndex + * The column index, starting from 0 for the leftmost row. * @return the expand ratio, 0.0f by default */ public float getColumnExpandRatio(int columnIndex) { @@ -1103,6 +1109,7 @@ public class GridLayout extends AbstractLayout * @param rowIndex * The row index, starting from 0 for the topmost row. * @param ratio + * the expand ratio */ public void setRowExpandRatio(int rowIndex, float ratio) { rowExpandRatio.put(rowIndex, ratio); @@ -1195,6 +1202,7 @@ public class GridLayout extends AbstractLayout * MarginInfo ) */ @Override + @SuppressWarnings("deprecation") public void setMargin(MarginInfo marginInfo) { getState().marginsBitmask = marginInfo.getBitMask(); } @@ -1205,6 +1213,7 @@ public class GridLayout extends AbstractLayout * @see com.vaadin.ui.Layout.MarginHandler#getMargin() */ @Override + @SuppressWarnings("deprecation") public MarginInfo getMargin() { return new MarginInfo(getState(false).marginsBitmask); } @@ -1430,7 +1439,7 @@ public class GridLayout extends AbstractLayout } if (components.isEmpty()) { - writeEmptyColsAndRows(design, designContext); + writeEmptyColsAndRows(design); return; } @@ -1566,10 +1575,8 @@ public class GridLayout extends AbstractLayout * components in the {@link GridLayout} * * @param design - * @param designContext */ - private void writeEmptyColsAndRows(Element design, - DesignContext designContext) { + private void writeEmptyColsAndRows(Element design) { int rowCount = getState(false).rows; int colCount = getState(false).columns; diff --git a/server/src/main/java/com/vaadin/ui/Panel.java b/server/src/main/java/com/vaadin/ui/Panel.java index 750652653f..6c3df6e291 100644 --- a/server/src/main/java/com/vaadin/ui/Panel.java +++ b/server/src/main/java/com/vaadin/ui/Panel.java @@ -334,7 +334,7 @@ public class Panel extends AbstractSingleComponentContainer public void writeDesign(Element design, DesignContext designContext) { super.writeDesign(design, designContext); // handle tabindex - Panel def = designContext.getDefaultInstance(this); + designContext.getDefaultInstance(this); } } diff --git a/server/src/main/java/com/vaadin/ui/TabSheet.java b/server/src/main/java/com/vaadin/ui/TabSheet.java index 04c700e64e..64719e23a9 100644 --- a/server/src/main/java/com/vaadin/ui/TabSheet.java +++ b/server/src/main/java/com/vaadin/ui/TabSheet.java @@ -140,7 +140,7 @@ public class TabSheet extends AbstractComponentContainer registerRpc(new FocusAndBlurServerRpcDecorator(this, this::fireEvent)); // expand horizontally by default - setWidth(100, UNITS_PERCENTAGE); + setWidth(100, Unit.PERCENTAGE); setCloseHandler(TabSheet::removeComponent); } @@ -450,8 +450,7 @@ public class TabSheet extends AbstractComponentContainer @Override public void moveComponentsFrom(ComponentContainer source) { - for (final Iterator<Component> i = source.getComponentIterator(); i - .hasNext();) { + for (final Iterator<Component> i = source.iterator(); i.hasNext();) { final Component c = i.next(); String caption = null; Resource icon = null; @@ -644,8 +643,7 @@ public class TabSheet extends AbstractComponentContainer */ private boolean updateSelection() { Component originalSelection = selected; - for (final Iterator<Component> i = getComponentIterator(); i - .hasNext();) { + for (final Iterator<Component> i = iterator(); i.hasNext();) { final Component component = i.next(); Tab tab = tabs.get(component); @@ -851,7 +849,8 @@ public class TabSheet extends AbstractComponentContainer * @since 3.0 */ @FunctionalInterface - public interface SelectedTabChangeListener extends SerializableEventListener { + public interface SelectedTabChangeListener + extends SerializableEventListener { /** * Selected (shown) tab in tab sheet has has been changed. @@ -1015,11 +1014,15 @@ public class TabSheet extends AbstractComponentContainer /** * Gets the caption for the tab. + * + * @return the caption */ public String getCaption(); /** * Gets the icon for the tab. + * + * @return tue icon resource */ public Resource getIcon(); @@ -1036,6 +1039,8 @@ public class TabSheet extends AbstractComponentContainer * * @param icon * the icon to set + * @param iconAltText + * the alt text */ public void setIcon(Resource icon, String iconAltText); @@ -1043,6 +1048,8 @@ public class TabSheet extends AbstractComponentContainer * Gets the icon alt text for the tab. * * @since 7.2 + * + * @return the alt text */ public String getIconAlternateText(); @@ -1114,11 +1121,15 @@ public class TabSheet extends AbstractComponentContainer * TODO currently not sent to the client * * @see AbstractComponent#setComponentError(ErrorMessage) + * + * @return the error message */ public ErrorMessage getComponentError(); /** * Get the component related to the Tab. + * + * @return the component */ public Component getComponent(); @@ -1407,6 +1418,7 @@ public class TabSheet extends AbstractComponentContainer * The default CloseHandler for TabSheet will only remove the tab. * * @param handler + * the close handler that should be used */ public void setCloseHandler(CloseHandler handler) { closeHandler = handler; @@ -1434,7 +1446,8 @@ public class TabSheet extends AbstractComponentContainer * * @param tab * The tab - * @return + * @return the index of the given tab, or -1 if there is no such tab in this + * tabsheet */ public int getTabPosition(Tab tab) { return components.indexOf(tab.getComponent()); @@ -1659,7 +1672,7 @@ public class TabSheet extends AbstractComponentContainer public void writeDesign(Element design, DesignContext designContext) { super.writeDesign(design, designContext); TabSheet def = designContext.getDefaultInstance(this); - Attributes attr = design.attributes(); + design.attributes(); // write tabs if (!designContext.shouldWriteChildren(this, def)) { diff --git a/server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerPopup.java b/server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerPopup.java index 409c930e1b..29925126cb 100644 --- a/server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerPopup.java +++ b/server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerPopup.java @@ -15,7 +15,6 @@ */ package com.vaadin.ui.components.colorpicker; -import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; import java.util.List; @@ -28,19 +27,19 @@ import com.vaadin.data.HasValue; import com.vaadin.shared.Registration; import com.vaadin.shared.ui.MarginInfo; import com.vaadin.shared.ui.colorpicker.Color; -import com.vaadin.ui.TabSheet; -import com.vaadin.ui.Window; -import com.vaadin.ui.VerticalLayout; -import com.vaadin.ui.HorizontalLayout; -import com.vaadin.ui.Component; -import com.vaadin.ui.Slider; -import com.vaadin.ui.Layout; +import com.vaadin.ui.AbstractColorPicker.Coordinates2Color; import com.vaadin.ui.Alignment; import com.vaadin.ui.Button; -import com.vaadin.ui.HasComponents; -import com.vaadin.ui.AbstractColorPicker.Coordinates2Color; import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.Component; +import com.vaadin.ui.HasComponents; +import com.vaadin.ui.HorizontalLayout; +import com.vaadin.ui.Layout; +import com.vaadin.ui.Slider; import com.vaadin.ui.Slider.ValueOutOfBoundsException; +import com.vaadin.ui.TabSheet; +import com.vaadin.ui.VerticalLayout; +import com.vaadin.ui.Window; /** * A component that represents color selection popup within a color picker. @@ -206,11 +205,6 @@ public class ColorPickerPopup extends Window implements HasValue<Color> { history.setWidth("97%"); history.setHeight("22px"); - // Create the default colors - List<Color> defaultColors = new ArrayList<>(); - defaultColors.add(Color.BLACK); - defaultColors.add(Color.WHITE); - // Create the history VerticalLayout innerContainer = new VerticalLayout(); innerContainer.setWidth("100%"); @@ -503,6 +497,7 @@ public class ColorPickerPopup extends Window implements HasValue<Color> { } @Override + @SuppressWarnings("deprecation") public Registration addValueChangeListener( ValueChangeListener<Color> listener) { Objects.requireNonNull(listener, "listener cannot be null"); diff --git a/server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerPreview.java b/server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerPreview.java index 8782a5aa39..d70cf60313 100644 --- a/server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerPreview.java +++ b/server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerPreview.java @@ -49,8 +49,6 @@ public class ColorPickerPreview extends CssLayout implements HasValue<Color> { /** The field. */ private final TextField field; - /** The old value. */ - private String oldValue; private Registration valueChangeListenerRegistration = null; private boolean readOnly; @@ -96,8 +94,6 @@ public class ColorPickerPreview extends CssLayout implements HasValue<Color> { field.setValue(colorCSS); field.setComponentError(null); - oldValue = colorCSS; - // Re-register listener valueChangeListenerRegistration = field .addValueChangeListener(this::valueChange); @@ -121,6 +117,7 @@ public class ColorPickerPreview extends CssLayout implements HasValue<Color> { } @Override + @SuppressWarnings("deprecation") public Registration addValueChangeListener( ValueChangeListener<Color> listener) { Objects.requireNonNull(listener, "listener cannot be null"); @@ -141,7 +138,6 @@ public class ColorPickerPreview extends CssLayout implements HasValue<Color> { */ color = ColorUtil.stringToColor(value); - oldValue = value; fireEvent(new ValueChangeEvent<>(this, oldColor, event.isUserOriginated())); } catch (NumberFormatException e) { diff --git a/server/src/main/java/com/vaadin/ui/declarative/DesignContext.java b/server/src/main/java/com/vaadin/ui/declarative/DesignContext.java index b8f355d4a2..29efe4f7b4 100644 --- a/server/src/main/java/com/vaadin/ui/declarative/DesignContext.java +++ b/server/src/main/java/com/vaadin/ui/declarative/DesignContext.java @@ -354,10 +354,14 @@ public class DesignContext implements Serializable { * Returns the default instance for the given class. The instance must not * be modified by the caller. * + * @param <T> + * a component class * @param component + * the component that determines the class * @return the default instance for the given class. The return value must * not be modified by the caller */ + @SuppressWarnings("unchecked") public <T> T getDefaultInstance(Component component) { // If the root is a @DesignRoot component, it can't use itself as a // reference or the written design will be empty @@ -385,6 +389,9 @@ public class DesignContext implements Serializable { /** * Reads and stores the mappings from prefixes to package names from meta * tags located under <head> in the html document. + * + * @param doc + * the document */ protected void readPackageMappings(Document doc) { Element head = doc.head(); @@ -848,7 +855,8 @@ public class DesignContext implements Serializable { String value) { Map<String, String> map = customAttributes.get(component); if (map == null) { - customAttributes.put(component, map = new HashMap<>()); + map = new HashMap<>(); + customAttributes.put(component, map); } map.put(attribute, value); } diff --git a/server/src/test/java/com/vaadin/server/VaadinServletTest.java b/server/src/test/java/com/vaadin/server/VaadinServletTest.java index 006872b212..2c318e0897 100644 --- a/server/src/test/java/com/vaadin/server/VaadinServletTest.java +++ b/server/src/test/java/com/vaadin/server/VaadinServletTest.java @@ -233,7 +233,7 @@ public class VaadinServletTest { public void isAllowedVAADINResource_jarWarFileScheme_detectsAsStaticResources() throws IOException, URISyntaxException, ServletException { assertTrue("Can not run concurrently with other test", - VaadinServlet.openFileSystems.isEmpty()); + VaadinServlet.OPEN_FILE_SYSTEMS.isEmpty()); VaadinServlet servlet = new VaadinServlet(); servlet.init(new MockServletConfig()); @@ -276,7 +276,7 @@ public class VaadinServletTest { public void isAllowedVAADINResource_jarInAJar_detectsAsStaticResources() throws IOException, URISyntaxException, ServletException { assertTrue("Can not run concurrently with other test", - VaadinServlet.openFileSystems.isEmpty()); + VaadinServlet.OPEN_FILE_SYSTEMS.isEmpty()); VaadinServlet servlet = new VaadinServlet(); servlet.init(new MockServletConfig()); @@ -325,7 +325,7 @@ public class VaadinServletTest { public void openingJarFileSystemForDifferentFilesInSameJar_existingFileSystemIsUsed() throws IOException, URISyntaxException, ServletException { assertTrue("Can not run concurrently with other test", - VaadinServlet.openFileSystems.isEmpty()); + VaadinServlet.OPEN_FILE_SYSTEMS.isEmpty()); VaadinServlet servlet = new VaadinServlet(); servlet.init(new MockServletConfig()); @@ -348,15 +348,15 @@ public class VaadinServletTest { servlet.getFileSystem(fileResourceURL.toURI()); assertEquals("Same file should be marked for both resources", - (Integer) 2, VaadinServlet.openFileSystems.entrySet() + (Integer) 2, VaadinServlet.OPEN_FILE_SYSTEMS.entrySet() .iterator().next().getValue()); servlet.closeFileSystem(folderResourceURL.toURI()); assertEquals("Closing resource should be removed from jar uri", - (Integer) 1, VaadinServlet.openFileSystems.entrySet() + (Integer) 1, VaadinServlet.OPEN_FILE_SYSTEMS.entrySet() .iterator().next().getValue()); servlet.closeFileSystem(fileResourceURL.toURI()); assertTrue("Closing last resource should clear marking", - VaadinServlet.openFileSystems.isEmpty()); + VaadinServlet.OPEN_FILE_SYSTEMS.isEmpty()); try { FileSystems.getFileSystem(folderResourceURL.toURI()); @@ -375,7 +375,7 @@ public class VaadinServletTest { throws IOException, InterruptedException, ExecutionException, URISyntaxException, ServletException { assertTrue("Can not run concurrently with other test", - VaadinServlet.openFileSystems.isEmpty()); + VaadinServlet.OPEN_FILE_SYSTEMS.isEmpty()); VaadinServlet servlet = new VaadinServlet(); servlet.init(new MockServletConfig()); @@ -547,7 +547,7 @@ public class VaadinServletTest { private void ensureFileSystemsCleared(URL fileResourceURL) throws URISyntaxException { assertFalse("URI should have been cleared", - VaadinServlet.openFileSystems + VaadinServlet.OPEN_FILE_SYSTEMS .containsKey(fileResourceURL.toURI())); try { FileSystems.getFileSystem(fileResourceURL.toURI()); |