Fixed a bunch of code inspection warnings

This commit is contained in:
Federico Fissore 2015-03-24 10:54:06 +01:00
parent ed3d467329
commit 24b32422e2
31 changed files with 82 additions and 92 deletions

View File

@ -353,7 +353,7 @@ public class ContributedLibraryTableCell extends InstallerTableCell {
String sentence = selected.getSentence(); String sentence = selected.getSentence();
String paragraph = selected.getParagraph(); String paragraph = selected.getParagraph();
// String availableVer = selectedLib.getVersion(); // String availableVer = selectedLib.getVersion();
String url = selected.getUrl(); // String url = selected.getUrl();
String midcolor = isSelected ? "#000000" : "#888888"; String midcolor = isSelected ? "#000000" : "#888888";
@ -379,8 +379,6 @@ public class ContributedLibraryTableCell extends InstallerTableCell {
} else { } else {
desc += " " + format(_("Version <b>{0}</b>"), installedVer); desc += " " + format(_("Version <b>{0}</b>"), installedVer);
} }
} else {
// not installed...
} }
desc += "</font>"; desc += "</font>";

View File

@ -44,9 +44,9 @@ public class LibrariesIndexTableModel extends FilteredAbstractTableModel<Contrib
public final static int DESCRIPTION_COL = 0; public final static int DESCRIPTION_COL = 0;
public static class ContributedLibraryReleases implements Comparable<ContributedLibraryReleases> { public static class ContributedLibraryReleases implements Comparable<ContributedLibraryReleases> {
public String name; public final String name;
public List<ContributedLibrary> releases = new ArrayList<ContributedLibrary>(); public final List<ContributedLibrary> releases = new ArrayList<ContributedLibrary>();
public List<String> versions = new ArrayList<String>(); public final List<String> versions = new ArrayList<String>();
public ContributedLibrary selected = null; public ContributedLibrary selected = null;
public ContributedLibraryReleases(ContributedLibrary library) { public ContributedLibraryReleases(ContributedLibrary library) {
@ -122,11 +122,11 @@ public class LibrariesIndexTableModel extends FilteredAbstractTableModel<Contrib
} }
} }
private List<ContributedLibraryReleases> contributions = new ArrayList<ContributedLibraryReleases>(); private final List<ContributedLibraryReleases> contributions = new ArrayList<ContributedLibraryReleases>();
private String[] columnNames = {"Description"}; private final String[] columnNames = {"Description"};
private Class<?>[] columnTypes = {ContributedPlatform.class}; private final Class<?>[] columnTypes = {ContributedPlatform.class};
private LibrariesIndexer indexer; private LibrariesIndexer indexer;

View File

@ -55,18 +55,17 @@ public class LibraryInstaller {
} }
} }
private LibrariesIndexer indexer; private final LibrariesIndexer indexer;
private File stagingFolder; private final DownloadableContributionsDownloader downloader;
private DownloadableContributionsDownloader downloader;
public LibraryInstaller(LibrariesIndexer _indexer) { public LibraryInstaller(LibrariesIndexer _indexer) {
indexer = _indexer; indexer = _indexer;
stagingFolder = _indexer.getStagingFolder(); File stagingFolder = _indexer.getStagingFolder();
downloader = new DownloadableContributionsDownloader(stagingFolder) { downloader = new DownloadableContributionsDownloader(stagingFolder) {
@Override @Override
protected void onProgress(Progress progress) { protected void onProgress(Progress progress) {
LibraryInstaller.this.onProgress(progress); LibraryInstaller.this.onProgress(progress);
}; }
}; };
} }
@ -160,8 +159,7 @@ public class LibraryInstaller {
rescanLibraryIndex(progress); rescanLibraryIndex(progress);
} }
private void rescanLibraryIndex(MultiStepProgress progress) private void rescanLibraryIndex(MultiStepProgress progress) {
throws IOException {
progress.setStatus(_("Updating list of installed libraries")); progress.setStatus(_("Updating list of installed libraries"));
onProgress(progress); onProgress(progress);
indexer.rescanLibraries(); indexer.rescanLibraries();

View File

@ -61,9 +61,7 @@ public class ContributionIndexTableModel extends FilteredAbstractTableModel<Cont
public boolean shouldContain(ContributedPlatform platform) { public boolean shouldContain(ContributedPlatform platform) {
if (platform.getParentPackage() != packager) if (platform.getParentPackage() != packager)
return false; return false;
if (!platform.getArchitecture().equals(arch)) return platform.getArchitecture().equals(arch);
return false;
return true;
} }
public void add(ContributedPlatform platform) { public void add(ContributedPlatform platform) {

View File

@ -1,6 +1,5 @@
package cc.arduino.contributions.ui; package cc.arduino.contributions.ui;
import cc.arduino.contributions.libraries.ContributedLibrary;
import cc.arduino.contributions.filters.NoopPredicate; import cc.arduino.contributions.filters.NoopPredicate;
import cc.arduino.contributions.packages.DownloadableContribution; import cc.arduino.contributions.packages.DownloadableContribution;
import cc.arduino.contributions.ui.DropdownItem; import cc.arduino.contributions.ui.DropdownItem;

View File

@ -40,7 +40,7 @@ import javax.swing.event.DocumentListener;
@SuppressWarnings("serial") @SuppressWarnings("serial")
public class FilterJTextField extends JTextField { public class FilterJTextField extends JTextField {
private String filterHint; private final String filterHint;
private boolean showingHint; private boolean showingHint;

View File

@ -50,13 +50,13 @@ public abstract class InstallerJDialog<T> extends JDialog {
// Toolbar on top of the window: // Toolbar on top of the window:
// - Categories drop-down menu // - Categories drop-down menu
protected JLabel categoryLabel; protected final JLabel categoryLabel;
protected JComboBox categoryChooser; protected final JComboBox categoryChooser;
protected Component categoryStrut1; protected final Component categoryStrut1;
protected Component categoryStrut2; protected final Component categoryStrut2;
protected Component categoryStrut3; protected final Component categoryStrut3;
// - Search text-field // - Search text-field
protected FilterJTextField filterField; protected final FilterJTextField filterField;
// Currently selected category and filters // Currently selected category and filters
protected Predicate<T> categoryFilter; protected Predicate<T> categoryFilter;
protected String[] filters; protected String[] filters;
@ -75,9 +75,9 @@ public abstract class InstallerJDialog<T> extends JDialog {
// Bottom: // Bottom:
// - Progress bar // - Progress bar
protected ProgressJProgressBar progressBar; protected final ProgressJProgressBar progressBar;
protected Box progressBox; protected final Box progressBox;
protected Box errorMessageBox; protected final Box errorMessageBox;
private final JLabel errorMessage; private final JLabel errorMessage;
public InstallerJDialog(Frame parent, String title, ModalityType applicationModal, String noConnectionErrorMessage) { public InstallerJDialog(Frame parent, String title, ModalityType applicationModal, String noConnectionErrorMessage) {
@ -136,7 +136,7 @@ public abstract class InstallerJDialog<T> extends JDialog {
@Override @Override
public void keyReleased(KeyEvent keyEvent) { public void keyReleased(KeyEvent keyEvent) {
if (keyEvent.getKeyCode() != keyEvent.VK_DOWN && keyEvent.getKeyCode() != KeyEvent.VK_UP) { if (keyEvent.getKeyCode() != KeyEvent.VK_DOWN && keyEvent.getKeyCode() != KeyEvent.VK_UP) {
return; return;
} }
@ -263,7 +263,7 @@ public abstract class InstallerJDialog<T> extends JDialog {
} }
} }
protected ActionListener categoryChooserActionListener = new ActionListener() { protected final ActionListener categoryChooserActionListener = new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent event) { public void actionPerformed(ActionEvent event) {

View File

@ -42,7 +42,7 @@ import static processing.app.I18n._;
public class AStyle implements Tool { public class AStyle implements Tool {
private static String FORMATTER_CONF = "formatter.conf"; private static final String FORMATTER_CONF = "formatter.conf";
private final AStyleInterface aStyleInterface; private final AStyleInterface aStyleInterface;
private final String formatterConfiguration; private final String formatterConfiguration;

View File

@ -48,10 +48,7 @@ public class Event extends ActionEvent {
@Override @Override
public String toString() { public String toString() {
StringBuilder sb = new StringBuilder(); return super.toString() + "\n" + payload.toString();
sb.append(super.toString());
sb.append("\n").append(payload.toString());
return sb.toString();
} }
} }

View File

@ -38,7 +38,7 @@ import java.util.Map;
public class SplashScreenHelper { public class SplashScreenHelper {
private final Map desktopHints; private final Map desktopHints;
private SplashScreen splash; private final SplashScreen splash;
private Rectangle2D.Double splashTextArea; private Rectangle2D.Double splashTextArea;
private Graphics2D splashGraphics; private Graphics2D splashGraphics;

View File

@ -154,12 +154,12 @@ public abstract class ContributedLibrary extends DownloadableContribution {
String thisVersion = getVersion(); String thisVersion = getVersion();
String otherVersion = ((ContributedLibrary) obj).getVersion(); String otherVersion = ((ContributedLibrary) obj).getVersion();
boolean versionEquals = thisVersion == null || otherVersion == null || thisVersion == otherVersion || thisVersion.equals(otherVersion); boolean versionEquals = thisVersion == null || otherVersion == null || thisVersion.equals(otherVersion);
String thisName = getName(); String thisName = getName();
String otherName = ((ContributedLibrary) obj).getName(); String otherName = ((ContributedLibrary) obj).getName();
boolean nameEquals = thisName == null || otherName == null || thisName == otherName || thisName.equals(otherName); boolean nameEquals = thisName == null || otherName == null || thisName.equals(otherName);
return versionEquals && nameEquals; return versionEquals && nameEquals;
} }

View File

@ -51,10 +51,10 @@ import com.fasterxml.jackson.module.mrbean.MrBeanModule;
public class LibrariesIndexer { public class LibrariesIndexer {
private LibrariesIndex index; private LibrariesIndex index;
private LibraryList installedLibraries = new LibraryList(); private final LibraryList installedLibraries = new LibraryList();
private List<File> librariesFolders; private List<File> librariesFolders;
private File indexFile; private final File indexFile;
private File stagingFolder; private final File stagingFolder;
private File sketchbookLibrariesFolder; private File sketchbookLibrariesFolder;
public LibrariesIndexer(File preferencesFolder) { public LibrariesIndexer(File preferencesFolder) {
@ -84,13 +84,12 @@ public class LibrariesIndexer {
} }
} }
public void setLibrariesFolders(List<File> _librariesFolders) public void setLibrariesFolders(List<File> _librariesFolders) {
throws IOException {
librariesFolders = _librariesFolders; librariesFolders = _librariesFolders;
rescanLibraries(); rescanLibraries();
} }
public void rescanLibraries() throws IOException { public void rescanLibraries() {
// Clear all installed flags // Clear all installed flags
installedLibraries.clear(); installedLibraries.clear();
for (ContributedLibrary lib : index.getLibraries()) for (ContributedLibrary lib : index.getLibraries())

View File

@ -94,7 +94,7 @@ public abstract class ContributedPackage {
for (ContributedPlatform plat : getPlatforms()) { for (ContributedPlatform plat : getPlatforms()) {
res += "\n Plaform : name : " + plat.getName(); res += "\n Plaform : name : " + plat.getName();
if (plat.isInstalled()) { if (plat.isInstalled()) {
res += "\n " + ((DownloadableContribution) plat); res += "\n " + plat;
} }
res += "\n category : " + plat.getCategory(); res += "\n category : " + plat.getCategory();
res += "\n architecture : " + res += "\n architecture : " +

View File

@ -60,12 +60,13 @@ public abstract class ContributedPlatform extends DownloadableContribution {
return new LinkedList<ContributedTool>(resolvedTools); return new LinkedList<ContributedTool>(resolvedTools);
} }
public List<ContributedTool> resolveToolsDependencies(Collection<ContributedPackage> packages) { public void resolveToolsDependencies(Collection<ContributedPackage> packages) {
resolvedTools = new ArrayList<ContributedTool>(); resolvedTools = new ArrayList<ContributedTool>();
// If there are no dependencies return empty list // If there are no dependencies return empty list
if (getToolsDependencies() == null) if (getToolsDependencies() == null) {
return resolvedTools; return;
}
// For each tool dependency // For each tool dependency
for (ContributedToolReference dep : getToolsDependencies()) { for (ContributedToolReference dep : getToolsDependencies()) {
@ -76,7 +77,6 @@ public abstract class ContributedPlatform extends DownloadableContribution {
} }
resolvedTools.add(tool); resolvedTools.add(tool);
} }
return resolvedTools;
} }
public ContributedPackage getParentPackage() { public ContributedPackage getParentPackage() {

View File

@ -37,8 +37,8 @@ import processing.app.debug.TargetPlatform;
public class ContributedTargetPackage implements TargetPackage { public class ContributedTargetPackage implements TargetPackage {
private String id; private final String id;
private Map<String, TargetPlatform> platforms; private final Map<String, TargetPlatform> platforms;
public ContributedTargetPackage(String _id) { public ContributedTargetPackage(String _id) {
id = _id; id = _id;

View File

@ -65,12 +65,11 @@ public class ContributionInstaller {
} }
} }
private File stagingFolder; private final ContributionsIndexer indexer;
private ContributionsIndexer indexer; private final DownloadableContributionsDownloader downloader;
private DownloadableContributionsDownloader downloader;
public ContributionInstaller(ContributionsIndexer contributionsIndexer) { public ContributionInstaller(ContributionsIndexer contributionsIndexer) {
stagingFolder = contributionsIndexer.getStagingFolder(); File stagingFolder = contributionsIndexer.getStagingFolder();
indexer = contributionsIndexer; indexer = contributionsIndexer;
downloader = new DownloadableContributionsDownloader(stagingFolder) { downloader = new DownloadableContributionsDownloader(stagingFolder) {
@Override @Override

View File

@ -51,7 +51,7 @@ public abstract class ContributionsIndex {
return pack.findTool(name, version); return pack.findTool(name, version);
} }
private List<String> categories = new ArrayList<String>(); private final List<String> categories = new ArrayList<String>();
public List<String> getCategories() { public List<String> getCategories() {
return categories; return categories;

View File

@ -150,7 +150,6 @@ public class ContributionsIndexer {
} }
contrib.setInstalled(true); contrib.setInstalled(true);
contrib.setInstalledFolder(versionFolder); contrib.setInstalledFolder(versionFolder);
return;
} }
private void syncHardwareWithFilesystem(ContributedPackage pack, private void syncHardwareWithFilesystem(ContributedPackage pack,

View File

@ -80,14 +80,9 @@ public abstract class DownloadableContribution {
@Override @Override
public String toString() { public String toString() {
String chk = getChecksum();
if (chk.length() > 14)
chk = getChecksum().substring(0, 14);
String res = ""; String res = "";
// res += getUrl() + " (" + chk + ") ";
if (installed) { if (installed) {
res += "installed on " + installedFolder.getAbsolutePath() + " (" + res += "installed on " + installedFolder.getAbsolutePath() + " (" + getSize() + " bytes)";
getSize() + " bytes)";
} }
return res; return res;
} }

View File

@ -42,7 +42,7 @@ import static processing.app.I18n.format;
public class DownloadableContributionsDownloader { public class DownloadableContributionsDownloader {
private File stagingFolder; private final File stagingFolder;
public DownloadableContributionsDownloader(File _stagingFolder) { public DownloadableContributionsDownloader(File _stagingFolder) {
stagingFolder = _stagingFolder; stagingFolder = _stagingFolder;

View File

@ -28,7 +28,6 @@
*/ */
package cc.arduino.contributions.packages; package cc.arduino.contributions.packages;
import processing.app.BaseNoGui;
import processing.app.Platform; import processing.app.Platform;
public abstract class HostDependentDownloadableContribution extends DownloadableContribution { public abstract class HostDependentDownloadableContribution extends DownloadableContribution {

View File

@ -33,7 +33,7 @@ import java.io.IOException;
public class LinuxFileNativeUtils { public class LinuxFileNativeUtils {
public static LibCNative libc = LibCNative.libc; public static final LibCNative libc = LibCNative.libc;
public static void chmod(File file, int mode) throws IOException { public static void chmod(File file, int mode) throws IOException {
int res = libc.chmod(file.getAbsolutePath(), mode); int res = libc.chmod(file.getAbsolutePath(), mode);

View File

@ -29,11 +29,10 @@
package cc.arduino.os.windows; package cc.arduino.os.windows;
import java.io.File; import java.io.File;
import java.io.IOException;
public class WindowsFileNativeUtils { public class WindowsFileNativeUtils {
public static void chmod(File file, int mode) throws IOException { public static void chmod(File file, int mode) {
// Empty // Empty
} }

View File

@ -36,8 +36,9 @@ import processing.app.debug.TargetBoard;
public class UploaderFactory { public class UploaderFactory {
public Uploader newUploader(TargetBoard board, BoardPort port, boolean noUploadPort) { public Uploader newUploader(TargetBoard board, BoardPort port, boolean noUploadPort) {
if (noUploadPort) if (noUploadPort) {
return new SerialUploader(noUploadPort); return new SerialUploader(true);
}
if ("true".equals(board.getPreferences().get("upload.via_ssh")) && port != null && "network".equals(port.getProtocol())) { if ("true".equals(board.getPreferences().get("upload.via_ssh")) && port != null && "network".equals(port.getProtocol())) {
return new SSHUploader(port); return new SSHUploader(port);

View File

@ -58,8 +58,7 @@ public class ClearSignedVerifier {
* @throws FileNotFoundException * @throws FileNotFoundException
*/ */
public static VerifyResult verify(File signedTextFile, public static VerifyResult verify(File signedTextFile,
PGPPublicKeyRingCollection pubKeyRing) PGPPublicKeyRingCollection pubKeyRing) {
throws FileNotFoundException {
// Create the result object // Create the result object
VerifyResult result = new VerifyResult(); VerifyResult result = new VerifyResult();
result.clearText = null; result.clearText = null;

View File

@ -119,7 +119,10 @@ public class SSHUploader extends Uploader {
private boolean runAVRDude(SSH ssh) throws IOException, JSchException { private boolean runAVRDude(SSH ssh) throws IOException, JSchException {
TargetPlatform targetPlatform = BaseNoGui.getTargetPlatform(); TargetPlatform targetPlatform = BaseNoGui.getTargetPlatform();
PreferencesMap prefs = PreferencesData.getMap(); PreferencesMap prefs = PreferencesData.getMap();
prefs.putAll(BaseNoGui.getBoardPreferences()); PreferencesMap boardPreferences = BaseNoGui.getBoardPreferences();
if (boardPreferences != null) {
prefs.putAll(boardPreferences);
}
prefs.putAll(targetPlatform.getTool(prefs.get("upload.tool"))); prefs.putAll(targetPlatform.getTool(prefs.get("upload.tool")));
String additionalParams = verbose ? prefs.get("upload.params.verbose") : prefs.get("upload.params.quiet"); String additionalParams = verbose ? prefs.get("upload.params.verbose") : prefs.get("upload.params.quiet");

View File

@ -60,7 +60,10 @@ public class SerialUploader extends Uploader {
// FIXME: Preferences should be reorganized // FIXME: Preferences should be reorganized
TargetPlatform targetPlatform = BaseNoGui.getTargetPlatform(); TargetPlatform targetPlatform = BaseNoGui.getTargetPlatform();
PreferencesMap prefs = PreferencesData.getMap(); PreferencesMap prefs = PreferencesData.getMap();
prefs.putAll(BaseNoGui.getBoardPreferences()); PreferencesMap boardPreferences = BaseNoGui.getBoardPreferences();
if (boardPreferences != null) {
prefs.putAll(boardPreferences);
}
String tool = prefs.getOrExcept("upload.tool"); String tool = prefs.getOrExcept("upload.tool");
if (tool.contains(":")) { if (tool.contains(":")) {
String[] split = tool.split(":", 2); String[] split = tool.split(":", 2);
@ -242,7 +245,10 @@ public class SerialUploader extends Uploader {
} }
PreferencesMap prefs = PreferencesData.getMap(); PreferencesMap prefs = PreferencesData.getMap();
prefs.putAll(BaseNoGui.getBoardPreferences()); PreferencesMap boardPreferences = BaseNoGui.getBoardPreferences();
if (boardPreferences != null) {
prefs.putAll(boardPreferences);
}
PreferencesMap programmerPrefs = targetPlatform.getProgrammer(programmer); PreferencesMap programmerPrefs = targetPlatform.getProgrammer(programmer);
if (programmerPrefs == null) if (programmerPrefs == null)
throw new RunnerException( throw new RunnerException(
@ -295,7 +301,10 @@ public class SerialUploader extends Uploader {
// Build configuration for the current programmer // Build configuration for the current programmer
PreferencesMap prefs = PreferencesData.getMap(); PreferencesMap prefs = PreferencesData.getMap();
prefs.putAll(BaseNoGui.getBoardPreferences()); PreferencesMap boardPreferences = BaseNoGui.getBoardPreferences();
if (boardPreferences != null) {
prefs.putAll(boardPreferences);
}
prefs.putAll(programmerPrefs); prefs.putAll(programmerPrefs);
// Create configuration for bootloader tool // Create configuration for bootloader tool

View File

@ -30,10 +30,10 @@ package cc.arduino.utils;
public class MultiStepProgress implements Progress { public class MultiStepProgress implements Progress {
double steps; private final double steps;
double step; private double step;
double stepProgress; private double stepProgress;
String status; String status;

View File

@ -30,11 +30,11 @@ package cc.arduino.utils;
public interface Progress { public interface Progress {
public void setProgress(double progress); void setProgress(double progress);
double getProgress(); double getProgress();
public void setStatus(String _status); void setStatus(String _status);
String getStatus(); String getStatus();

View File

@ -55,9 +55,9 @@ public class FileDownloader extends Observable {
private long initialSize; private long initialSize;
private Long downloadSize = null; private Long downloadSize = null;
private long downloaded; private long downloaded;
private URL downloadUrl; private final URL downloadUrl;
private File outputFile; private final File outputFile;
private InputStream stream = null; private InputStream stream = null;
private Exception error; private Exception error;
@ -225,6 +225,7 @@ public class FileDownloader extends Observable {
try { try {
file.close(); file.close();
} catch (Exception e) { } catch (Exception e) {
//ignore
} }
} }
@ -233,6 +234,7 @@ public class FileDownloader extends Observable {
try { try {
stream.close(); stream.close();
} catch (Exception e) { } catch (Exception e) {
//ignore
} }
} }
} }

View File

@ -757,13 +757,9 @@ public class BaseNoGui {
// Scan for libraries in each library folder. // Scan for libraries in each library folder.
// Libraries located in the latest folders on the list can override // Libraries located in the latest folders on the list can override
// other libraries with the same name. // other libraries with the same name.
try { BaseNoGui.librariesIndexer.setSketchbookLibrariesFolder(getSketchbookLibrariesFolder());
BaseNoGui.librariesIndexer.setSketchbookLibrariesFolder(getSketchbookLibrariesFolder()); BaseNoGui.librariesIndexer.setLibrariesFolders(librariesFolders);
BaseNoGui.librariesIndexer.setLibrariesFolders(librariesFolders); BaseNoGui.librariesIndexer.rescanLibraries();
BaseNoGui.librariesIndexer.rescanLibraries();
} catch (IOException e) {
showWarning(_("Error"), _("Error loading libraries"), e);
}
populateImportToLibraryTable(); populateImportToLibraryTable();
} }