Skip to content

Feature/java21 code cleanup #573

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Mar 10, 2024
5 changes: 3 additions & 2 deletions ant-jme/src/com/jme/ant/LoadWikiImages.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.InputStream;
import java.net.URI;
import java.net.URL;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;
Expand Down Expand Up @@ -48,7 +49,7 @@ public void execute() throws BuildException {
name = name.substring(0, markIdx);
}
name = name.replaceAll(":", "/");
URL url = new URL(host + link);
URL url = URI.create(host + link).toURL();
InputStream in = null;
FileOutputStream out = null;
try {
Expand Down Expand Up @@ -83,7 +84,7 @@ public void execute() throws BuildException {
}
//make external folder and clean filename
name = "external/" + name.replaceAll("[_[^\\w\\däüöÄÜÖ\\/\\+\\-\\. ]]", "_");
URL url = new URL(host + link);
URL url = URI.create((host + link)).toURL();
InputStream in = url.openStream();
File file = new File(getLocation().getFileName().replaceAll("build.xml", "") + File.separator + targetFolder + File.separator + name.replaceAll("/", File.separator));
log("Getting external image: " + host + link);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public Node[] getNodes(Project project) {
} catch (DataObjectNotFoundException ex) {
Exceptions.printStackTrace(ex);
}
return list.toArray(new Node[list.size()]);
return list.toArray(Node[]::new);
}

@Override
Expand Down
6 changes: 3 additions & 3 deletions jme3-android/src/com/jme3/gde/android/Installer.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

import com.jme3.gde.core.errorreport.ExceptionUtils;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URI;
import org.netbeans.api.autoupdate.UpdateUnitProvider;
import org.netbeans.api.autoupdate.UpdateUnitProviderFactory;
import org.openide.modules.ModuleInstall;
Expand All @@ -55,9 +55,9 @@ public void restored() {
if (implVers != null) {
try {
UpdateUnitProvider updateUnitProvider = UpdateUnitProviderFactory.getDefault()
.create("NBANDROID", "NBANDROID Update Center", new URL(
.create("NBANDROID", "NBANDROID Update Center", URI.create(
String.format("http://server.arsi.sk:8080/updates/%s-updates.xml", implVers)
));
).toURL());
updateUnitProvider.setEnable(true);
} catch (MalformedURLException ex) {
ExceptionUtils.caughtException(ex, "Note: This could be a problem related to your internet connection/firewall etc.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
import com.jme3.gde.core.util.ProjectSelection;
import com.jme3.gde.materials.JMEMaterialDataObject;
import com.jme3.gde.materials.multiview.MaterialOpenSupport;
import com.jme3.gde.scenecomposer.OpenSceneComposer;
import com.jme3.gde.scenecomposer.SceneComposerTopComponent;
import com.jme3.gde.textureeditor.JmeTextureDataObject;
import com.jme3.gde.textureeditor.OpenTexture;
Expand All @@ -62,7 +61,6 @@
import java.util.List;
import java.util.stream.Collectors;
import javax.swing.JOptionPane;
import org.netbeans.api.project.Project;
import org.openide.DialogDisplayer;
import org.openide.NotifyDescriptor;
import org.openide.filesystems.FileAttributeEvent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import org.openide.awt.ActionReference;
import org.openide.util.NbBundle;
import org.openide.windows.TopComponent;
import org.openide.util.NbBundle.Messages;

/**
* Top component which displays something.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import com.jme3.gde.assetpack.actions.AddAssetAction;
import com.jme3.gde.assetpack.project.wizards.FileDescription;
import com.jme3.gde.core.assets.ProjectAssetManager;
import com.jme3.gde.core.scene.SceneApplication;
import com.jme3.material.Material;
import com.jme3.material.MaterialList;
import com.jme3.scene.Node;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URI;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand Down Expand Up @@ -43,7 +44,7 @@ public OnlineBrowser(AssetPackLibrary lib) {
this.lib = lib;
jEditorPane1.addHyperlinkListener(this);
try {
URL url = new URL("http://jmonkeyengine.org/assetpacks/list.php");
URL url = URI.create("http://jmonkeyengine.org/assetpacks/list.php").toURL();
jEditorPane1.setPage(url);
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.beans.PropertyEditor;
import java.util.Iterator;
import java.util.ArrayList;
import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static void upload(String urlString, String exsistingFileName, String use
int size = (int) FileUtil.toFileObject(file).getSize();
Logger.getLogger(OnlinePacksConnector.class.getName()).log(Level.FINE, "Upload file size: {0}", size);

URL url = new URL(urlString);
URL url = URI.create(urlString).toURL();
String boundary = MultiPartFormOutputStream.createBoundary();
URLConnection urlConn = MultiPartFormOutputStream.createConnection(url);
urlConn.setRequestProperty("Accept", "*/*");
Expand Down Expand Up @@ -77,7 +77,7 @@ public static void upload(String urlString, String exsistingFileName, String use

private static boolean test(String urlString, String user, String pass) {
try {
URL url = new URL(urlString);
URL url = URI.create(urlString).toURL();
String boundary = MultiPartFormOutputStream.createBoundary();
URLConnection urlConn = MultiPartFormOutputStream.createConnection(url);
urlConn.setRequestProperty("Accept", "*/*");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,12 +270,14 @@ public void invokeAction(String string, Lookup lookup) throws IllegalArgumentExc

@Override
public boolean isActionEnabled(String command, Lookup lookup) throws IllegalArgumentException {
if ((command.equals(ActionProvider.COMMAND_DELETE))) {
return true;
} else if ((command.equals(ActionProvider.COMMAND_COPY))) {
return true;
} else {
throw new IllegalArgumentException(command);
switch (command) {
case ActionProvider.COMMAND_DELETE -> {
return true;
}
case ActionProvider.COMMAND_COPY -> {
return true;
}
default -> throw new IllegalArgumentException(command);
}
}
}
Expand Down Expand Up @@ -352,16 +354,20 @@ public void showCustomizer() {

@Override
public JComponent create(Category category) {
if (category.getName().equals("General")) {
panel1 =
new GeneralSettingsPanel(project);
return panel1;
} else if (category.getName().equals("License")) {
panel2 =
new LicensePanel(project);
return panel2;
} else {
return new JPanel();
switch (category.getName()) {
case "General" -> {
panel1 =
new GeneralSettingsPanel(project);
return panel1;
}
case "License" -> {
panel2 =
new LicensePanel(project);
return panel2;
}
default -> {
return new JPanel();
}
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
package com.jme3.gde.assetpack.project.wizards;

import java.awt.Component;
import java.io.File;
import javax.swing.event.ChangeListener;
import org.openide.WizardDescriptor;
import org.openide.util.HelpCtx;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,15 @@ private void selectFile() {
private String pathString() {
String string = "";
String type = (String) wiz.getProperty("type");
if (type.equals("model")) {
string += "/Models/";
} else if (type.equals("scene")) {
string += "/Scenes/";
} else if (type.equals("texture")) {
string += "/Textures/";
} else if (type.equals("sound")) {
string += "/Sounds/";
} else if (type.equals("shader")) {
string += "/Shaders/";
} else if (type.equals("other")) {
string += "/Misc/";
switch (type) {
case "model" -> string += "/Models/";
case "scene" -> string += "/Scenes/";
case "texture" -> string += "/Textures/";
case "sound" -> string += "/Sounds/";
case "shader" -> string += "/Shaders/";
case "other" -> string += "/Misc/";
default -> {
}
}
String category = ((String) wiz.getProperty("categories")).split(",")[0].trim();
string += category + "/";
Expand Down
3 changes: 2 additions & 1 deletion jme3-blender/src/com/jme3/gde/blender/scripts/Scripts.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URI;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand Down Expand Up @@ -41,7 +42,7 @@ private static void checkScript(FileObject folder, String name) {
InputStream in = null;
OutputStream out = null;
try {
URL url = new URL("nbres:" + root + name);
URL url = URI.create("nbres:" + root + name).toURL();
file = FileUtil.createData(folder, name);
in = url.openStream();
out = file.getOutputStream();
Expand Down
12 changes: 6 additions & 6 deletions jme3-core/src/com/jme3/gde/core/appstates/AppStateNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -199,12 +199,12 @@ protected void createFields(Class c, Sheet.Set set, Object obj) throws SecurityE
}

public void propertyChange(final String type, final String name, final Object before, final Object after) {
if (SceneExplorerProperty.PROP_USER_CHANGE.equals(type)) {
firePropertyChange(name, before, after);
} else if (SceneExplorerProperty.PROP_SCENE_CHANGE.equals(type)) {
firePropertyChange(name, before, after);
} else if (SceneExplorerProperty.PROP_INIT_CHANGE.equals(type)) {
firePropertyChange(name, before, after);
if (null != type) switch (type) {
case SceneExplorerProperty.PROP_USER_CHANGE -> firePropertyChange(name, before, after);
case SceneExplorerProperty.PROP_SCENE_CHANGE -> firePropertyChange(name, before, after);
case SceneExplorerProperty.PROP_INIT_CHANGE -> firePropertyChange(name, before, after);
default -> {
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
*/
package com.jme3.gde.core.appstates;

import java.util.HashSet;
import java.util.EnumSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
Expand Down Expand Up @@ -92,8 +92,7 @@ private List<String> getSources() {
ClassPath.getClassPath(sourceGroup.getRootFolder(), ClassPath.COMPILE),
ClassPath.getClassPath(sourceGroup.getRootFolder(), ClassPath.SOURCE));

HashSet<SearchScope> set = new HashSet<SearchScope>();
set.add(ClassIndex.SearchScope.SOURCE);
Set<SearchScope> set = EnumSet.of(ClassIndex.SearchScope.SOURCE);
Set<ElementHandle<TypeElement>> types = cpInfo.getClassIndex().getDeclaredTypes("", NameKind.PREFIX, set);
for (Iterator<ElementHandle<TypeElement>> it = types.iterator(); it.hasNext();) {
final ElementHandle<TypeElement> elementHandle = it.next();
Expand Down
27 changes: 13 additions & 14 deletions jme3-core/src/com/jme3/gde/core/assets/ProjectAssetManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@

import com.jme3.asset.AssetEventListener;
import com.jme3.asset.AssetKey;
import com.jme3.asset.AssetManager;
import com.jme3.asset.DesktopAssetManager;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
Expand Down Expand Up @@ -87,12 +86,12 @@ public class ProjectAssetManager extends DesktopAssetManager {
private static final Logger logger = Logger.getLogger(ProjectAssetManager.class.getName());
private final Mutex mutex = new Mutex();
private final Project project;
private final List<ClassPathChangeListener> classPathListeners = Collections.synchronizedList(new LinkedList<ClassPathChangeListener>());
private final List<ClassPath> classPaths = Collections.synchronizedList(new LinkedList<ClassPath>());
private final List<ClassPathItem> classPathItems = Collections.synchronizedList(new LinkedList<ClassPathItem>());
private final List<AssetEventListener> assetEventListeners = Collections.synchronizedList(new LinkedList<AssetEventListener>());
private final List<String> folderNames = new LinkedList<String>();
private final List<FileObject> jarItems = new LinkedList<FileObject>();
private final List<ClassPathChangeListener> classPathListeners = Collections.synchronizedList(new LinkedList<>());
private final List<ClassPath> classPaths = Collections.synchronizedList(new LinkedList<>());
private final List<ClassPathItem> classPathItems = Collections.synchronizedList(new LinkedList<>());
private final List<AssetEventListener> assetEventListeners = Collections.synchronizedList(new LinkedList<>());
private final List<String> folderNames = new LinkedList<>();
private final List<FileObject> jarItems = new LinkedList<>();
private URLClassLoader loader;

public ProjectAssetManager(Project prj, String folderName) {
Expand Down Expand Up @@ -275,12 +274,12 @@ private void fireChange(FileEvent fe) {
private PropertyChangeListener classPathListener = new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent evt) {
logger.log(Level.FINE, "Classpath event: {0}", evt);
if (ClassPath.PROP_ROOTS.equals(evt.getPropertyName())) {
updateClassLoader();
} else if (ClassPath.PROP_ENTRIES.equals(evt.getPropertyName())) {
updateClassLoader();
} else if (ClassPath.PROP_INCLUDES.equals(evt.getPropertyName())) {
updateClassLoader();
if (null != evt.getPropertyName()) switch (evt.getPropertyName()) {
case ClassPath.PROP_ROOTS -> updateClassLoader();
case ClassPath.PROP_ENTRIES -> updateClassLoader();
case ClassPath.PROP_INCLUDES -> updateClassLoader();
default -> {
}
}
}
};
Expand Down Expand Up @@ -659,7 +658,7 @@ public String getAbsoluteAssetPath(String path) {
* @param folderName the folderName to set
*/
public void setFolderName(String folderName) {
if (folderNames.size() > 0) {
if (!folderNames.isEmpty()) {
this.folderNames.remove(0);
}
this.folderNames.add(0, folderName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
import org.openide.loaders.DataObject;
import org.openide.loaders.DataObjectExistsException;
import org.openide.loaders.MultiFileLoader;
import org.openide.util.Exceptions;

/**
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
package com.jme3.gde.core.assets.actions;

import com.jme3.export.Savable;
import com.jme3.gde.core.assets.AssetDataObject;
import com.jme3.gde.core.assets.BinaryModelDataObject;
import com.jme3.gde.core.assets.SpatialAssetDataObject;
import com.jme3.gde.core.util.notify.MessageUtil;
Expand All @@ -42,7 +41,6 @@
import java.util.logging.Level;
import java.util.logging.Logger;
import org.netbeans.api.progress.ProgressHandle;
import org.openide.util.Exceptions;

public final class ConvertModel implements ActionListener {
protected static final Logger logger = Logger.getLogger(ConvertModel.class.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ protected Node[] createNodes(Node object) {
}
}

return result.toArray(new Node[0]);
return result.toArray(Node[]::new);
}

private boolean accept(Node node) {
Expand Down
14 changes: 8 additions & 6 deletions jme3-core/src/com/jme3/gde/core/codeless/CodelessProject.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,14 @@ public void invokeAction(String string, Lookup lookup) throws IllegalArgumentExc

@Override
public boolean isActionEnabled(String command, Lookup lookup) throws IllegalArgumentException {
if ((command.equals(ActionProvider.COMMAND_DELETE))) {
return true;
} else if ((command.equals(ActionProvider.COMMAND_COPY))) {
return true;
} else {
throw new IllegalArgumentException(command);
switch (command) {
case ActionProvider.COMMAND_DELETE -> {
return true;
}
case ActionProvider.COMMAND_COPY -> {
return true;
}
default -> throw new IllegalArgumentException(command);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import org.openide.nodes.Children;
import org.openide.nodes.Node;
import org.openide.util.Exceptions;
import org.openide.util.ImageUtilities;
import org.openide.util.lookup.AbstractLookup;
import org.openide.util.lookup.InstanceContent;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import java.util.List;
import javax.swing.text.Document;
import javax.swing.text.JTextComponent;
import org.netbeans.api.editor.mimelookup.MimeRegistration;
import org.netbeans.spi.editor.codegen.CodeGenerator;
import org.netbeans.spi.editor.codegen.CodeGeneratorContextProvider;
import org.openide.util.Exceptions;
Expand Down
Loading