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/src/main/java/com/vaadin/ui | |
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/src/main/java/com/vaadin/ui')
8 files changed, 118 insertions, 56 deletions
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); } |