Skip to content

Commit 624fe86

Browse files
author
Andy Goryachev
committedSep 11, 2023
8313651: Add 'final' keyword to public property methods in controls
Reviewed-by: jhendrikx, nlisker, kcr
1 parent 325be56 commit 624fe86

File tree

8 files changed

+266
-44
lines changed

8 files changed

+266
-44
lines changed
 

‎modules/javafx.controls/src/main/java/javafx/scene/control/ChoiceBox.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2010, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2010, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -315,8 +315,8 @@ public String getName() {
315315
* @return the string converter property
316316
* @since JavaFX 2.1
317317
*/
318-
public ObjectProperty<StringConverter<T>> converterProperty() { return converter; }
319-
private ObjectProperty<StringConverter<T>> converter =
318+
public final ObjectProperty<StringConverter<T>> converterProperty() { return converter; }
319+
private final ObjectProperty<StringConverter<T>> converter =
320320
new SimpleObjectProperty<>(this, "converter", null);
321321
public final void setConverter(StringConverter<T> value) { converterProperty().set(value); }
322322
public final StringConverter<T> getConverter() {return converterProperty().get(); }
@@ -329,8 +329,8 @@ public String getName() {
329329
* @return the value property
330330
* @since JavaFX 2.1
331331
*/
332-
public ObjectProperty<T> valueProperty() { return value; }
333-
private ObjectProperty<T> value = new SimpleObjectProperty<>(this, "value") {
332+
public final ObjectProperty<T> valueProperty() { return value; }
333+
private final ObjectProperty<T> value = new SimpleObjectProperty<>(this, "value") {
334334
@Override protected void invalidated() {
335335
super.invalidated();
336336
fireEvent(new ActionEvent());

‎modules/javafx.controls/src/main/java/javafx/scene/control/ComboBox.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -308,10 +308,10 @@ public ComboBox(ObservableList<T> items) {
308308
/**
309309
* The list of items to show within the ComboBox popup.
310310
*/
311-
private ObjectProperty<ObservableList<T>> items = new SimpleObjectProperty<>(this, "items");
311+
private final ObjectProperty<ObservableList<T>> items = new SimpleObjectProperty<>(this, "items");
312312
public final void setItems(ObservableList<T> value) { itemsProperty().set(value); }
313313
public final ObservableList<T> getItems() {return items.get(); }
314-
public ObjectProperty<ObservableList<T>> itemsProperty() { return items; }
314+
public final ObjectProperty<ObservableList<T>> itemsProperty() { return items; }
315315

316316

317317
// --- string converter
@@ -321,8 +321,8 @@ public ComboBox(ObservableList<T> items) {
321321
* the input may be retrieved via the {@link #valueProperty() value} property.
322322
* @return the converter property
323323
*/
324-
public ObjectProperty<StringConverter<T>> converterProperty() { return converter; }
325-
private ObjectProperty<StringConverter<T>> converter =
324+
public final ObjectProperty<StringConverter<T>> converterProperty() { return converter; }
325+
private final ObjectProperty<StringConverter<T>> converter =
326326
new SimpleObjectProperty<>(this, "converter", ComboBox.<T>defaultStringConverter());
327327
public final void setConverter(StringConverter<T> value) { converterProperty().set(value); }
328328
public final StringConverter<T> getConverter() {return converterProperty().get(); }
@@ -334,11 +334,11 @@ public ComboBox(ObservableList<T> items) {
334334
* rendering of items in the ComboBox. Refer to the {@link Cell} javadoc
335335
* for more information on cell factories.
336336
*/
337-
private ObjectProperty<Callback<ListView<T>, ListCell<T>>> cellFactory =
337+
private final ObjectProperty<Callback<ListView<T>, ListCell<T>>> cellFactory =
338338
new SimpleObjectProperty<>(this, "cellFactory");
339339
public final void setCellFactory(Callback<ListView<T>, ListCell<T>> value) { cellFactoryProperty().set(value); }
340340
public final Callback<ListView<T>, ListCell<T>> getCellFactory() {return cellFactoryProperty().get(); }
341-
public ObjectProperty<Callback<ListView<T>, ListCell<T>>> cellFactoryProperty() { return cellFactory; }
341+
public final ObjectProperty<Callback<ListView<T>, ListCell<T>>> cellFactoryProperty() { return cellFactory; }
342342

343343

344344
// --- button cell
@@ -350,8 +350,8 @@ public ComboBox(ObservableList<T> items) {
350350
* @return the button cell property
351351
* @since JavaFX 2.2
352352
*/
353-
public ObjectProperty<ListCell<T>> buttonCellProperty() { return buttonCell; }
354-
private ObjectProperty<ListCell<T>> buttonCell =
353+
public final ObjectProperty<ListCell<T>> buttonCellProperty() { return buttonCell; }
354+
private final ObjectProperty<ListCell<T>> buttonCell =
355355
new SimpleObjectProperty<>(this, "buttonCell");
356356
public final void setButtonCell(ListCell<T> value) { buttonCellProperty().set(value); }
357357
public final ListCell<T> getButtonCell() {return buttonCellProperty().get(); }

‎modules/javafx.controls/src/main/java/javafx/scene/control/ComboBoxBase.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2010, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2010, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -145,8 +145,8 @@ public ComboBoxBase() {
145145
* either the value input by the user, or the last selected item.
146146
* @return the value property
147147
*/
148-
public ObjectProperty<T> valueProperty() { return value; }
149-
private ObjectProperty<T> value = new SimpleObjectProperty<>(this, "value");
148+
public final ObjectProperty<T> valueProperty() { return value; }
149+
private final ObjectProperty<T> value = new SimpleObjectProperty<>(this, "value");
150150

151151
public final void setValue(T value) { valueProperty().set(value); }
152152
public final T getValue() { return valueProperty().get(); }
@@ -162,10 +162,10 @@ public ComboBoxBase() {
162162
* reset, along with any other relevant state.
163163
* @return the editable property
164164
*/
165-
public BooleanProperty editableProperty() { return editable; }
165+
public final BooleanProperty editableProperty() { return editable; }
166166
public final void setEditable(boolean value) { editableProperty().set(value); }
167167
public final boolean isEditable() { return editableProperty().get(); }
168-
private BooleanProperty editable = new SimpleBooleanProperty(this, "editable", false) {
168+
private final BooleanProperty editable = new SimpleBooleanProperty(this, "editable", false) {
169169
@Override protected void invalidated() {
170170
pseudoClassStateChanged(PSEUDO_CLASS_EDITABLE, get());
171171
}
@@ -178,7 +178,7 @@ public ComboBoxBase() {
178178
* currently visible on screen (although it may be hidden behind other windows).
179179
*/
180180
private ReadOnlyBooleanWrapper showing;
181-
public ReadOnlyBooleanProperty showingProperty() { return showingPropertyImpl().getReadOnlyProperty(); }
181+
public final ReadOnlyBooleanProperty showingProperty() { return showingPropertyImpl().getReadOnlyProperty(); }
182182
public final boolean isShowing() { return showingPropertyImpl().get(); }
183183
private void setShowing(boolean value) {
184184
// these events will not fire if the showing property is bound
@@ -245,10 +245,10 @@ public String getName() {
245245
* ComboBox and pressed.
246246
* @return the armed property
247247
*/
248-
public BooleanProperty armedProperty() { return armed; }
248+
public final BooleanProperty armedProperty() { return armed; }
249249
private final void setArmed(boolean value) { armedProperty().set(value); }
250250
public final boolean isArmed() { return armedProperty().get(); }
251-
private BooleanProperty armed = new SimpleBooleanProperty(this, "armed", false) {
251+
private final BooleanProperty armed = new SimpleBooleanProperty(this, "armed", false) {
252252
@Override protected void invalidated() {
253253
pseudoClassStateChanged(PSEUDO_CLASS_ARMED, get());
254254
}

‎modules/javafx.controls/src/main/java/javafx/scene/control/Label.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2010, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2010, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -113,7 +113,7 @@ private void initialize() {
113113
* This allows setting of the target Node.
114114
* @return the Node that this label is to be associated with
115115
*/
116-
public ObjectProperty<Node> labelForProperty() {
116+
public final ObjectProperty<Node> labelForProperty() {
117117
if (labelFor == null) {
118118
labelFor = new ObjectPropertyBase<>() {
119119
Node oldValue = null;

‎modules/javafx.controls/src/main/java/javafx/scene/control/ListView.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -996,18 +996,18 @@ public void scrollTo(T object) {
996996
*/
997997
private ObjectProperty<EventHandler<ScrollToEvent<Integer>>> onScrollTo;
998998

999-
public void setOnScrollTo(EventHandler<ScrollToEvent<Integer>> value) {
999+
public final void setOnScrollTo(EventHandler<ScrollToEvent<Integer>> value) {
10001000
onScrollToProperty().set(value);
10011001
}
10021002

1003-
public EventHandler<ScrollToEvent<Integer>> getOnScrollTo() {
1003+
public final EventHandler<ScrollToEvent<Integer>> getOnScrollTo() {
10041004
if( onScrollTo != null ) {
10051005
return onScrollTo.get();
10061006
}
10071007
return null;
10081008
}
10091009

1010-
public ObjectProperty<EventHandler<ScrollToEvent<Integer>>> onScrollToProperty() {
1010+
public final ObjectProperty<EventHandler<ScrollToEvent<Integer>>> onScrollToProperty() {
10111011
if( onScrollTo == null ) {
10121012
onScrollTo = new ObjectPropertyBase<>() {
10131013
@Override protected void invalidated() {

‎modules/javafx.controls/src/main/java/javafx/scene/control/TableView.java

+9-9
Original file line numberDiff line numberDiff line change
@@ -1406,18 +1406,18 @@ public final ObjectProperty<Callback<TableView<S>, Boolean>> sortPolicyProperty(
14061406
*/
14071407
private ObjectProperty<EventHandler<SortEvent<TableView<S>>>> onSort;
14081408

1409-
public void setOnSort(EventHandler<SortEvent<TableView<S>>> value) {
1409+
public final void setOnSort(EventHandler<SortEvent<TableView<S>>> value) {
14101410
onSortProperty().set(value);
14111411
}
14121412

1413-
public EventHandler<SortEvent<TableView<S>>> getOnSort() {
1413+
public final EventHandler<SortEvent<TableView<S>>> getOnSort() {
14141414
if( onSort != null ) {
14151415
return onSort.get();
14161416
}
14171417
return null;
14181418
}
14191419

1420-
public ObjectProperty<EventHandler<SortEvent<TableView<S>>>> onSortProperty() {
1420+
public final ObjectProperty<EventHandler<SortEvent<TableView<S>>>> onSortProperty() {
14211421
if( onSort == null ) {
14221422
onSort = new ObjectPropertyBase<>() {
14231423
@Override protected void invalidated() {
@@ -1507,18 +1507,18 @@ public void scrollTo(S object) {
15071507
*/
15081508
private ObjectProperty<EventHandler<ScrollToEvent<Integer>>> onScrollTo;
15091509

1510-
public void setOnScrollTo(EventHandler<ScrollToEvent<Integer>> value) {
1510+
public final void setOnScrollTo(EventHandler<ScrollToEvent<Integer>> value) {
15111511
onScrollToProperty().set(value);
15121512
}
15131513

1514-
public EventHandler<ScrollToEvent<Integer>> getOnScrollTo() {
1514+
public final EventHandler<ScrollToEvent<Integer>> getOnScrollTo() {
15151515
if( onScrollTo != null ) {
15161516
return onScrollTo.get();
15171517
}
15181518
return null;
15191519
}
15201520

1521-
public ObjectProperty<EventHandler<ScrollToEvent<Integer>>> onScrollToProperty() {
1521+
public final ObjectProperty<EventHandler<ScrollToEvent<Integer>>> onScrollToProperty() {
15221522
if( onScrollTo == null ) {
15231523
onScrollTo = new ObjectPropertyBase<>() {
15241524
@Override
@@ -1566,18 +1566,18 @@ public void scrollToColumnIndex(int columnIndex) {
15661566
*/
15671567
private ObjectProperty<EventHandler<ScrollToEvent<TableColumn<S, ?>>>> onScrollToColumn;
15681568

1569-
public void setOnScrollToColumn(EventHandler<ScrollToEvent<TableColumn<S, ?>>> value) {
1569+
public final void setOnScrollToColumn(EventHandler<ScrollToEvent<TableColumn<S, ?>>> value) {
15701570
onScrollToColumnProperty().set(value);
15711571
}
15721572

1573-
public EventHandler<ScrollToEvent<TableColumn<S, ?>>> getOnScrollToColumn() {
1573+
public final EventHandler<ScrollToEvent<TableColumn<S, ?>>> getOnScrollToColumn() {
15741574
if( onScrollToColumn != null ) {
15751575
return onScrollToColumn.get();
15761576
}
15771577
return null;
15781578
}
15791579

1580-
public ObjectProperty<EventHandler<ScrollToEvent<TableColumn<S, ?>>>> onScrollToColumnProperty() {
1580+
public final ObjectProperty<EventHandler<ScrollToEvent<TableColumn<S, ?>>>> onScrollToColumnProperty() {
15811581
if( onScrollToColumn == null ) {
15821582
onScrollToColumn = new ObjectPropertyBase<>() {
15831583
@Override protected void invalidated() {

‎modules/javafx.controls/src/main/java/javafx/scene/control/TreeTableView.java

+9-9
Original file line numberDiff line numberDiff line change
@@ -1632,18 +1632,18 @@ public final ObjectProperty<Callback<TreeTableView<S>, Boolean>> sortPolicyPrope
16321632
*/
16331633
private ObjectProperty<EventHandler<SortEvent<TreeTableView<S>>>> onSort;
16341634

1635-
public void setOnSort(EventHandler<SortEvent<TreeTableView<S>>> value) {
1635+
public final void setOnSort(EventHandler<SortEvent<TreeTableView<S>>> value) {
16361636
onSortProperty().set(value);
16371637
}
16381638

1639-
public EventHandler<SortEvent<TreeTableView<S>>> getOnSort() {
1639+
public final EventHandler<SortEvent<TreeTableView<S>>> getOnSort() {
16401640
if( onSort != null ) {
16411641
return onSort.get();
16421642
}
16431643
return null;
16441644
}
16451645

1646-
public ObjectProperty<EventHandler<SortEvent<TreeTableView<S>>>> onSortProperty() {
1646+
public final ObjectProperty<EventHandler<SortEvent<TreeTableView<S>>>> onSortProperty() {
16471647
if( onSort == null ) {
16481648
onSort = new ObjectPropertyBase<>() {
16491649
@Override protected void invalidated() {
@@ -1698,18 +1698,18 @@ public void scrollTo(int index) {
16981698
*/
16991699
private ObjectProperty<EventHandler<ScrollToEvent<Integer>>> onScrollTo;
17001700

1701-
public void setOnScrollTo(EventHandler<ScrollToEvent<Integer>> value) {
1701+
public final void setOnScrollTo(EventHandler<ScrollToEvent<Integer>> value) {
17021702
onScrollToProperty().set(value);
17031703
}
17041704

1705-
public EventHandler<ScrollToEvent<Integer>> getOnScrollTo() {
1705+
public final EventHandler<ScrollToEvent<Integer>> getOnScrollTo() {
17061706
if( onScrollTo != null ) {
17071707
return onScrollTo.get();
17081708
}
17091709
return null;
17101710
}
17111711

1712-
public ObjectProperty<EventHandler<ScrollToEvent<Integer>>> onScrollToProperty() {
1712+
public final ObjectProperty<EventHandler<ScrollToEvent<Integer>>> onScrollToProperty() {
17131713
if( onScrollTo == null ) {
17141714
onScrollTo = new ObjectPropertyBase<>() {
17151715
@Override protected void invalidated() {
@@ -1752,18 +1752,18 @@ public void scrollToColumnIndex(int columnIndex) {
17521752
*/
17531753
private ObjectProperty<EventHandler<ScrollToEvent<TreeTableColumn<S, ?>>>> onScrollToColumn;
17541754

1755-
public void setOnScrollToColumn(EventHandler<ScrollToEvent<TreeTableColumn<S, ?>>> value) {
1755+
public final void setOnScrollToColumn(EventHandler<ScrollToEvent<TreeTableColumn<S, ?>>> value) {
17561756
onScrollToColumnProperty().set(value);
17571757
}
17581758

1759-
public EventHandler<ScrollToEvent<TreeTableColumn<S, ?>>> getOnScrollToColumn() {
1759+
public final EventHandler<ScrollToEvent<TreeTableColumn<S, ?>>> getOnScrollToColumn() {
17601760
if( onScrollToColumn != null ) {
17611761
return onScrollToColumn.get();
17621762
}
17631763
return null;
17641764
}
17651765

1766-
public ObjectProperty<EventHandler<ScrollToEvent<TreeTableColumn<S, ?>>>> onScrollToColumnProperty() {
1766+
public final ObjectProperty<EventHandler<ScrollToEvent<TreeTableColumn<S, ?>>>> onScrollToColumnProperty() {
17671767
if( onScrollToColumn == null ) {
17681768
onScrollToColumn = new ObjectPropertyBase<>() {
17691769
@Override
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
1+
/*
2+
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation. Oracle designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Oracle in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
* or visit www.oracle.com if you need additional information or have any
23+
* questions.
24+
*/
25+
package test.javafx.scene.control;
26+
27+
import java.lang.reflect.Method;
28+
import java.lang.reflect.Modifier;
29+
import java.util.Set;
30+
import javafx.scene.control.Accordion;
31+
import javafx.scene.control.Button;
32+
import javafx.scene.control.ButtonBar;
33+
import javafx.scene.control.ButtonBase;
34+
import javafx.scene.control.Cell;
35+
import javafx.scene.control.CheckBox;
36+
import javafx.scene.control.ChoiceBox;
37+
import javafx.scene.control.ColorPicker;
38+
import javafx.scene.control.ComboBox;
39+
import javafx.scene.control.ComboBoxBase;
40+
import javafx.scene.control.DateCell;
41+
import javafx.scene.control.DatePicker;
42+
import javafx.scene.control.Hyperlink;
43+
import javafx.scene.control.IndexedCell;
44+
import javafx.scene.control.Label;
45+
import javafx.scene.control.Labeled;
46+
import javafx.scene.control.ListCell;
47+
import javafx.scene.control.ListView;
48+
import javafx.scene.control.MenuBar;
49+
import javafx.scene.control.MenuButton;
50+
import javafx.scene.control.Pagination;
51+
import javafx.scene.control.PasswordField;
52+
import javafx.scene.control.ProgressIndicator;
53+
import javafx.scene.control.RadioButton;
54+
import javafx.scene.control.ScrollBar;
55+
import javafx.scene.control.ScrollPane;
56+
import javafx.scene.control.Separator;
57+
import javafx.scene.control.SeparatorMenuItem;
58+
import javafx.scene.control.Slider;
59+
import javafx.scene.control.Spinner;
60+
import javafx.scene.control.SplitPane;
61+
import javafx.scene.control.TabPane;
62+
import javafx.scene.control.TableRow;
63+
import javafx.scene.control.TableView;
64+
import javafx.scene.control.TextArea;
65+
import javafx.scene.control.TextField;
66+
import javafx.scene.control.TitledPane;
67+
import javafx.scene.control.ToggleButton;
68+
import javafx.scene.control.TreeCell;
69+
import javafx.scene.control.TreeTableCell;
70+
import javafx.scene.control.TreeTableRow;
71+
import javafx.scene.control.TreeTableView;
72+
import javafx.scene.control.cell.CheckBoxListCell;
73+
import javafx.scene.control.cell.CheckBoxTableCell;
74+
import javafx.scene.control.cell.CheckBoxTreeCell;
75+
import javafx.scene.control.cell.CheckBoxTreeTableCell;
76+
import javafx.scene.control.cell.ChoiceBoxTreeCell;
77+
import javafx.scene.control.cell.ChoiceBoxTreeTableCell;
78+
import javafx.scene.control.cell.ComboBoxTreeCell;
79+
import javafx.scene.control.cell.ComboBoxTreeTableCell;
80+
import javafx.scene.control.cell.ProgressBarTreeTableCell;
81+
import javafx.scene.control.cell.TextFieldTreeCell;
82+
import javafx.scene.control.cell.TextFieldTreeTableCell;
83+
import org.junit.jupiter.api.Test;
84+
import com.sun.javafx.scene.control.DoubleField;
85+
import com.sun.javafx.scene.control.InputField;
86+
import com.sun.javafx.scene.control.IntegerField;
87+
import com.sun.javafx.scene.control.WebColorField;
88+
import com.sun.javafx.scene.control.skin.FXVK;
89+
90+
/**
91+
* Tests contract for properties and their accessors and mutators
92+
* in the Control type hierarchy.
93+
*
94+
* Currently uses a list of classes, so any new Controls must be added manually.
95+
* Perhaps the test should scan modulepath and find all the Controls automagically.
96+
*/
97+
public class ControlPropertiesTest {
98+
/**
99+
* controls whether the test fails with assertion (true, default) or
100+
* outputs all violations to stderr (false).
101+
*/
102+
private static final boolean FAIL_FAST = true;
103+
104+
// list all current descendants of Control class.
105+
private Set<Class<?>> allControlClasses() {
106+
return Set.of(
107+
Accordion.class,
108+
ButtonBar.class,
109+
ButtonBase.class,
110+
Button.class,
111+
Cell.class,
112+
CheckBox.class,
113+
CheckBoxListCell.class,
114+
CheckBoxTableCell.class,
115+
CheckBoxTreeCell.class,
116+
CheckBoxTreeTableCell.class,
117+
ChoiceBox.class,
118+
ChoiceBoxTreeCell.class,
119+
ChoiceBoxTreeTableCell.class,
120+
ColorPicker.class,
121+
ComboBox.class,
122+
ComboBoxBase.class,
123+
ComboBoxTreeCell.class,
124+
ComboBoxTreeTableCell.class,
125+
DateCell.class,
126+
DatePicker.class,
127+
DoubleField.class,
128+
FXVK.class,
129+
//HTMLEditor.class,
130+
Hyperlink.class,
131+
IndexedCell.class,
132+
InputField.class,
133+
IntegerField.class,
134+
Labeled.class,
135+
Label.class,
136+
ListCell.class,
137+
ListView.class,
138+
MenuBar.class,
139+
MenuButton.class,
140+
Pagination.class,
141+
PasswordField.class,
142+
ProgressIndicator.class,
143+
ProgressBarTreeTableCell.class,
144+
RadioButton.class,
145+
ScrollBar.class,
146+
ScrollPane.class,
147+
Separator.class,
148+
SeparatorMenuItem.class,
149+
Slider.class,
150+
Spinner.class,
151+
SplitPane.class,
152+
TableRow.class,
153+
TableView.class,
154+
TabPane.class,
155+
TextArea.class,
156+
TextField.class,
157+
TextFieldTreeCell.class,
158+
TextFieldTreeTableCell.class,
159+
TitledPane.class,
160+
ToggleButton.class,
161+
TreeCell.class,
162+
TreeTableCell.class,
163+
TreeTableRow.class,
164+
TreeTableView.class,
165+
WebColorField.class
166+
);
167+
}
168+
169+
/**
170+
* Tests for missing final keyword in Control properties and their accessors/mutators.
171+
*/
172+
@Test
173+
public void testMissingFinalMethods() {
174+
for (Class<?> c : allControlClasses()) {
175+
check(c);
176+
}
177+
}
178+
179+
private void check(Class<?> cls) {
180+
Method[] publicMethods = cls.getMethods();
181+
for (Method m : publicMethods) {
182+
String name = m.getName();
183+
if (name.endsWith("Property") && (m.getParameterCount() == 0)) {
184+
checkModifiers(m);
185+
186+
String propName = name.substring(0, name.length() - "Property".length());
187+
check(publicMethods, propName, "get", 0);
188+
check(publicMethods, propName, "set", 1);
189+
check(publicMethods, propName, "is", 0);
190+
}
191+
}
192+
}
193+
194+
private void check(Method[] methods, String propName, String prefix, int numArgs) {
195+
StringBuilder sb = new StringBuilder(64);
196+
sb.append(prefix);
197+
sb.append(Character.toUpperCase(propName.charAt(0)));
198+
sb.append(propName, 1, propName.length());
199+
200+
String name = sb.toString();
201+
for (Method m : methods) {
202+
if (m.getParameterCount() == numArgs) {
203+
if (name.equals(m.getName())) {
204+
checkModifiers(m);
205+
return;
206+
}
207+
}
208+
}
209+
}
210+
211+
private void checkModifiers(Method m) {
212+
int mod = m.getModifiers();
213+
if (Modifier.isPublic(mod) && !Modifier.isFinal(mod)) {
214+
String msg = m + " is not final.";
215+
if (FAIL_FAST) {
216+
throw new AssertionError(msg);
217+
} else {
218+
System.err.println(msg);
219+
}
220+
}
221+
}
222+
}

0 commit comments

Comments
 (0)
Please sign in to comment.