Skip to content

Commit

Permalink
8297412: Remove easy warnings in javafx.fxml, javafx.media, javafx.sw…
Browse files Browse the repository at this point in the history
…ing, javafx.swt and javafx.web

Reviewed-by: angorya, nlisker
  • Loading branch information
hjohn authored and nlisker committed Nov 30, 2022
1 parent fbad15d commit 7cb408b
Show file tree
Hide file tree
Showing 145 changed files with 576 additions and 467 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class JavaFXSceneBuilder implements Builder<Scene> {
private double width = -1;
private double height = -1;
private Paint fill = Color.WHITE;
private ArrayList<String> stylesheets = new ArrayList<String>();
private ArrayList<String> stylesheets = new ArrayList<>();

public Parent getRoot() {
return root;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,7 @@ public Setter(Method m, Class<?> t) {
super(m, t);
}

@Override
public void invoke(Object obj, Object argStr) throws Exception {
Object arg[] = new Object[]{BeanAdapter.coerce(argStr, type)};
ModuleHelper.invoke(method, obj, arg);
Expand Down Expand Up @@ -631,7 +632,7 @@ private static HashMap<String, LinkedList<Method>> getClassMethodCache(Class<?>
// it assumes that localType is array
private static Object[] convertListToArray(Object userValue, Class<?> localType) {
Class<?> arrayType = localType.getComponentType();
List l = (List) BeanAdapter.coerce(userValue, List.class);
List l = BeanAdapter.coerce(userValue, List.class);

return l.toArray((Object[]) Array.newInstance(arrayType, 0));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public enum TokenType {
public Expression parse(Reader reader) throws IOException {
LinkedList<Token> tokens = tokenize(new PushbackReader(reader, PUSHBACK_BUFFER_SIZE));

LinkedList<Expression> stack = new LinkedList<Expression>();
LinkedList<Expression> stack = new LinkedList<>();

for (Token token : tokens) {
Expression<?> expression;
Expand Down Expand Up @@ -193,8 +193,8 @@ public Expression parse(Reader reader) throws IOException {

private LinkedList<Token> tokenize(PushbackReader reader) throws IOException {
// Read the string into a postfix list of tokens
LinkedList<Token> tokens = new LinkedList<Token>();
LinkedList<Token> stack = new LinkedList<Token>();
LinkedList<Token> tokens = new LinkedList<>();
LinkedList<Token> stack = new LinkedList<>();

c = reader.read();
boolean unary = true;
Expand Down Expand Up @@ -547,7 +547,7 @@ private boolean readKeyword(PushbackReader reader, String keyword) throws IOExce
* Returns a list of arguments to this expression.
*/
public List<KeyPath> getArguments() {
ArrayList<KeyPath> arguments = new ArrayList<KeyPath>();
ArrayList<KeyPath> arguments = new ArrayList<>();
getArguments(arguments);

return arguments;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import java.util.List;

import javafx.beans.InvalidationListener;
import javafx.beans.property.ReadOnlyProperty;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.beans.value.ObservableValueBase;
Expand All @@ -52,7 +51,7 @@ private class KeyPathMonitor {

private Object namespace = null;

private ListChangeListener<Object> listChangeListener = new ListChangeListener<Object>() {
private ListChangeListener<Object> listChangeListener = new ListChangeListener<>() {
@Override
public void onChanged(Change<? extends Object> change) {
while (change.next()) {
Expand All @@ -66,7 +65,7 @@ public void onChanged(Change<? extends Object> change) {
}
};

private MapChangeListener<String, Object> mapChangeListener = new MapChangeListener<String, Object>() {
private MapChangeListener<String, Object> mapChangeListener = new MapChangeListener<>() {
@Override
public void onChanged(Change<? extends String, ? extends Object> change) {
if (key.equals(change.getKey())) {
Expand All @@ -76,7 +75,7 @@ public void onChanged(Change<? extends String, ? extends Object> change) {
}
};

private ChangeListener<Object> propertyChangeListener = new ChangeListener<Object>() {
private ChangeListener<Object> propertyChangeListener = new ChangeListener<>() {
@Override
public void changed(ObservableValue<? extends Object> observable, Object oldValue, Object newValue) {
fireValueChangedEvent();
Expand Down Expand Up @@ -180,7 +179,7 @@ public ExpressionValue(Object namespace, Expression expression, Class<?> type) {
this.type = type;

List<KeyPath> arguments = expression.getArguments();
argumentMonitors = new ArrayList<KeyPathMonitor>(arguments.size());
argumentMonitors = new ArrayList<>(arguments.size());

for (KeyPath argument : arguments) {
argumentMonitors.add(new KeyPathMonitor(argument.iterator()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public static KeyPath parse(String value) {
* The resulting key path.
*/
protected static KeyPath parse(PushbackReader reader) throws IOException {
ArrayList<String> elements = new ArrayList<String>();
ArrayList<String> elements = new ArrayList<>();

int c = reader.read();

Expand Down
37 changes: 19 additions & 18 deletions modules/javafx.fxml/src/main/java/javafx/fxml/FXMLLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@ private abstract class Element {
public Object value = null;
private BeanAdapter valueAdapter = null;

public final LinkedList<Attribute> eventHandlerAttributes = new LinkedList<Attribute>();
public final LinkedList<Attribute> instancePropertyAttributes = new LinkedList<Attribute>();
public final LinkedList<Attribute> staticPropertyAttributes = new LinkedList<Attribute>();
public final LinkedList<PropertyElement> staticPropertyElements = new LinkedList<PropertyElement>();
public final LinkedList<Attribute> eventHandlerAttributes = new LinkedList<>();
public final LinkedList<Attribute> instancePropertyAttributes = new LinkedList<>();
public final LinkedList<Attribute> staticPropertyAttributes = new LinkedList<>();
public final LinkedList<PropertyElement> staticPropertyElements = new LinkedList<>();

public Element() {
parent = current;
Expand All @@ -153,7 +153,7 @@ public boolean isCollection() {
}

@SuppressWarnings("unchecked")
public void add(Object element) throws LoadException {
public void add(Object element) {
// If value is a list, add element to it; otherwise, get the value
// of the default property, which is assumed to be a list and add
// to that (coerce to the appropriate type)
Expand Down Expand Up @@ -231,6 +231,9 @@ public void processStartElement() throws IOException {
}
}

/**
* @throws IOException when I/O by implementation fails
*/
public void processEndElement() throws IOException {
// No-op
}
Expand Down Expand Up @@ -294,7 +297,6 @@ public void processAttribute(String prefix, String localName, String value)
}
}

@SuppressWarnings("unchecked")
public void processPropertyAttribute(Attribute attribute) throws IOException {
String value = attribute.value;
if (isBindingExpression(value)) {
Expand Down Expand Up @@ -495,7 +497,7 @@ private void populateListFromString(
// Split the string and add the values to the list
List<Object> list = (List<Object>)valueAdapter.get(listPropertyName);
Type listType = valueAdapter.getGenericType(listPropertyName);
Type itemType = (Class<?>)BeanAdapter.getGenericListItemType(listType);
Type itemType = BeanAdapter.getGenericListItemType(listType);

if (itemType instanceof ParameterizedType) {
itemType = ((ParameterizedType)itemType).getRawType();
Expand Down Expand Up @@ -962,7 +964,7 @@ private class InstanceDeclarationElement extends ValueElement {
public String constant = null;
public String factory = null;

public InstanceDeclarationElement(Class<?> type) throws LoadException {
public InstanceDeclarationElement(Class<?> type) {
this.type = type;
}

Expand Down Expand Up @@ -1033,8 +1035,8 @@ private class UnknownTypeElement extends ValueElement {
// Map type representing an unknown value
@DefaultProperty("items")
public class UnknownValueMap extends AbstractMap<String, Object> {
private ArrayList<?> items = new ArrayList<Object>();
private HashMap<String, Object> values = new HashMap<String, Object>();
private ArrayList<?> items = new ArrayList<>();
private HashMap<String, Object> values = new HashMap<>();

@Override
public Object get(Object key) {
Expand Down Expand Up @@ -1401,7 +1403,7 @@ public boolean isCollection() {
}

@Override
public void add(Object element) throws LoadException {
public void add(Object element) {
// Coerce the element to the list item type
if (parent.isTyped()) {
Type listType = parent.getValueAdapter().getGenericType(name);
Expand Down Expand Up @@ -1781,7 +1783,6 @@ public ObservableListChangeAdapter(MethodHandler handler) {
}

@Override
@SuppressWarnings("unchecked")
public void onChanged(Change change) {
if (handler != null) {
handler.invoke(change);
Expand Down Expand Up @@ -1887,8 +1888,8 @@ public void invoke(Object... params) {
private ScriptEngine scriptEngine = null;
private static boolean compileScript = true;

private List<String> packages = new LinkedList<String>();
private Map<String, Class<?>> classes = new HashMap<String, Class<?>>();
private List<String> packages = new LinkedList<>();
private Map<String, Class<?>> classes = new HashMap<>();

private ScriptEngineManager scriptEngineManager = null;

Expand Down Expand Up @@ -2562,7 +2563,7 @@ private <T> T loadImpl(final Class<?> callerClass) throws IOException {
return value;
}

@SuppressWarnings({ "dep-ann", "unchecked" })
@SuppressWarnings("unchecked")
private <T> T loadImpl(InputStream inputStream,
Class<?> callerClass) throws IOException {
if (inputStream == null) {
Expand Down Expand Up @@ -2801,7 +2802,7 @@ private void processImport() throws LoadException {
}
}

private void processComment() throws LoadException {
private void processComment() {
if (loadListener != null) {
loadListener.readComment(xmlStreamReader.getText());
}
Expand Down Expand Up @@ -2945,7 +2946,7 @@ private void processCharacters() throws IOException {
}
}

private void importPackage(String name) throws LoadException {
private void importPackage(String name) {
packages.add(name);
}

Expand All @@ -2957,7 +2958,7 @@ private void importClass(String name) throws LoadException {
}
}

private Class<?> getType(String name) throws LoadException {
private Class<?> getType(String name) {
Class<?> type = null;

if (Character.isLowerCase(name.charAt(0))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,12 @@ private static final class ObjectBuilderWrapper {
private final Class<?> builderClass;
private final Method createMethod;
private final Method buildMethod;
private final Map<String,Method> methods = new HashMap<String, Method>();
private final Map<String,Method> getters = new HashMap<String,Method>();
private final Map<String,Method> setters = new HashMap<String,Method>();
private final Map<String,Method> methods = new HashMap<>();
private final Map<String,Method> getters = new HashMap<>();
private final Map<String,Method> setters = new HashMap<>();

final class ObjectBuilder extends AbstractMap<String, Object> implements Builder<Object> {
private final Map<String,Object> containers = new HashMap<String,Object>();
private final Map<String,Object> containers = new HashMap<>();
private Object builder = null;
private Map<Object,Object> properties;

Expand Down Expand Up @@ -361,15 +361,15 @@ Object getReadOnlyProperty(String propName) {
}

if (ObservableMap.class.isAssignableFrom(type)) {
return FXCollections.observableMap(new HashMap<Object, Object>());
return FXCollections.observableMap(new HashMap<>());
} else if (Map.class.isAssignableFrom(type)) {
return new HashMap<Object, Object>();
return new HashMap<>();
} else if (ObservableList.class.isAssignableFrom(type)) {
return FXCollections.observableArrayList();
} else if (List.class.isAssignableFrom(type)) {
return new ArrayList<Object>();
return new ArrayList<>();
} else if (Set.class.isAssignableFrom(type)) {
return new HashSet<Object>();
return new HashSet<>();
}
return null;
}
Expand Down Expand Up @@ -429,7 +429,7 @@ public Set<Entry<String, Object>> entrySet() {
buildMethod = null;
}

ObjectBuilderWrapper(Class<?> builderClass) throws NoSuchMethodException, InstantiationException, IllegalAccessException {
ObjectBuilderWrapper(Class<?> builderClass) throws NoSuchMethodException {
this.builderClass = builderClass;
createMethod = MethodUtil.getMethod(builderClass, "create", NO_SIG);
buildMethod = MethodUtil.getMethod(builderClass, "build", NO_SIG);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class ClassWithCollection {
public double a;
public double b;
public List<Integer> list;
ObservableList<Integer> propertyList = new TrackableObservableList<Integer>() {
ObservableList<Integer> propertyList = new TrackableObservableList<>() {
@Override
protected void onChanged(ListChangeListener.Change<Integer> c) {}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,11 @@
import javafx.collections.ListChangeListener;
import javafx.collections.ObservableList;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class ClassWithReadOnlyCollection {
public double a;
ObservableList<Integer> propertyList = new TrackableObservableList<Integer>() {
ObservableList<Integer> propertyList = new TrackableObservableList<>() {
@Override
protected void onChanged(ListChangeListener.Change<Integer> c) {}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,14 @@

package test.javafx.fxml;

import java.io.IOException;
import javafx.fxml.FXMLLoaderShim;
import org.junit.Test;

import static org.junit.Assert.*;

public class CompareVersionsTest {
@Test
public void testCompareJFXVersions() throws IOException {
public void testCompareJFXVersions() {
assertTrue(FXMLLoaderShim.compareJFXVersions("1.1", "1.0") > 0);
assertTrue(FXMLLoaderShim.compareJFXVersions("1.1", "0.9.9") > 0);
assertTrue(FXMLLoaderShim.compareJFXVersions("2", "1.0") > 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.shape.Rectangle;
import org.junit.Assert;
import org.junit.Test;

import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.stage.Stage;
import javafx.util.Callback;
import org.junit.Test;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,12 @@ public void testParseExpression4() {

@Test
public void testParseExpression5() {
HashMap<String, Object> namespace = new HashMap<String, Object>();
HashMap<String, Object> namespace = new HashMap<>();

HashMap<String, Object> a = new HashMap<String, Object>();
HashMap<String, Object> a = new HashMap<>();
namespace.put("a", a);

HashMap<String, Object> b = new HashMap<String, Object>();
HashMap<String, Object> b = new HashMap<>();
a.put("b", b);

b.put("c", 5);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@

public class FXMLLoader_ScriptTest {
@Test
@SuppressWarnings("deprecation")
public void testStaticScriptLoad() throws IOException {
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("static_script_load.fxml"));
FXMLLoaderHelper.setStaticLoad(fxmlLoader, true);
Expand Down

0 comments on commit 7cb408b

Please sign in to comment.