From: Kevin Lamonte Date: Thu, 2 Apr 2015 17:44:56 +0000 (-0400) Subject: checkstyle sweep X-Git-Url: https://git.nikiroo.be/?a=commitdiff_plain;h=329fd62e4acdaa8e9f4cccd518d47c0b07e79f51;p=nikiroo-utils.git checkstyle sweep --- diff --git a/src/jexer/TApplication.java b/src/jexer/TApplication.java index 5156628..d06d0d6 100644 --- a/src/jexer/TApplication.java +++ b/src/jexer/TApplication.java @@ -89,7 +89,7 @@ public class TApplication implements Runnable { ECMA48, /** - * Synonym for ECMA48 + * Synonym for ECMA48. */ XTERM } @@ -518,6 +518,10 @@ public class TApplication implements Runnable { // Fall through... case ECMA48: backend = new ECMA48Backend(this, null, null); + break; + default: + throw new IllegalArgumentException("Invalid backend type: " + + backendType); } TApplicationImpl(); } @@ -1003,7 +1007,7 @@ public class TApplication implements Runnable { // secondary thread locks again. When it gives up, we have the // single lock back. boolean oldLock = unlockHandleEvent(); - assert (oldLock == true); + assert (oldLock); while (secondaryEventReceiver != null) { synchronized (primaryEventHandler) { @@ -1905,6 +1909,7 @@ public class TApplication implements Runnable { * * @param path path of selected file * @return the result of the new file open box + * @throws IOException if java.io operation throws */ public final String fileOpenBox(final String path) throws IOException { @@ -1918,6 +1923,7 @@ public class TApplication implements Runnable { * @param path path of selected file * @param type one of the Type constants * @return the result of the new file open box + * @throws IOException if java.io operation throws */ public final String fileOpenBox(final String path, final TFileOpenBox.Type type) throws IOException { diff --git a/src/jexer/TButton.java b/src/jexer/TButton.java index fb8c08e..064e927 100644 --- a/src/jexer/TButton.java +++ b/src/jexer/TButton.java @@ -56,7 +56,7 @@ public final class TButton extends TWidget { * * @return mnemonic string */ - public final MnemonicString getMnemonic() { + public MnemonicString getMnemonic() { return mnemonic; } diff --git a/src/jexer/TCheckbox.java b/src/jexer/TCheckbox.java index 816138b..6819bcd 100644 --- a/src/jexer/TCheckbox.java +++ b/src/jexer/TCheckbox.java @@ -51,7 +51,7 @@ public final class TCheckbox extends TWidget { * * @return if true, this is checked */ - public final boolean isChecked() { + public boolean isChecked() { return checked; } @@ -60,7 +60,7 @@ public final class TCheckbox extends TWidget { * * @param checked new checked value. */ - public final void setChecked(final boolean checked) { + public void setChecked(final boolean checked) { this.checked = checked; } diff --git a/src/jexer/TDirectoryList.java b/src/jexer/TDirectoryList.java index 1b94a18..50cc88b 100644 --- a/src/jexer/TDirectoryList.java +++ b/src/jexer/TDirectoryList.java @@ -64,7 +64,7 @@ public final class TDirectoryList extends TWidget { * * @param path new path to list files for */ - public void setPath(String path) { + public void setPath(final String path) { this.path = new File(path); reflow(); } @@ -115,7 +115,7 @@ public final class TDirectoryList extends TWidget { * @param index index into files * @return the line to draw */ - private String renderFile(int index) { + private String renderFile(final int index) { File file = files.get(index); String name = file.getName(); if (name.length() > 20) { diff --git a/src/jexer/TDirectoryTreeItem.java b/src/jexer/TDirectoryTreeItem.java index 0d02232..456ad92 100644 --- a/src/jexer/TDirectoryTreeItem.java +++ b/src/jexer/TDirectoryTreeItem.java @@ -60,7 +60,7 @@ public class TDirectoryTreeItem extends TTreeItem { * true if this item was just expanded from a mouse click or keypress. */ @Override - public void onExpand() { + public final void onExpand() { // System.err.printf("onExpand() %s\n", file); if (file == null) { @@ -77,7 +77,7 @@ public class TDirectoryTreeItem extends TTreeItem { assert (file.isDirectory()); setExpandable(true); - if ((isExpanded() == false) || (isExpandable() == false)) { + if (!isExpanded() || !isExpandable()) { getTreeView().reflow(); return; } @@ -118,7 +118,9 @@ public class TDirectoryTreeItem extends TTreeItem { * @throws IllegalArgumentException if this function is called */ @Override - public final TTreeItem addChild(final String text, final boolean expanded) { + public final TTreeItem addChild(final String text, + final boolean expanded) throws IllegalArgumentException { + throw new IllegalArgumentException("Do not call addChild(), use onExpand() instead"); } @@ -127,6 +129,7 @@ public class TDirectoryTreeItem extends TTreeItem { * * @param view root TTreeView * @param text text for this item + * @throws IOException if a java.io operation throws */ public TDirectoryTreeItem(final TTreeView view, final String text) throws IOException { @@ -140,6 +143,7 @@ public class TDirectoryTreeItem extends TTreeItem { * @param view root TTreeView * @param text text for this item * @param expanded if true, have it expanded immediately + * @throws IOException if a java.io operation throws */ public TDirectoryTreeItem(final TTreeView view, final String text, final boolean expanded) throws IOException { @@ -155,6 +159,7 @@ public class TDirectoryTreeItem extends TTreeItem { * @param expanded if true, have it expanded immediately * @param openParents if true, expand all paths up the root path and * return the root path entry + * @throws IOException if a java.io operation throws */ public TDirectoryTreeItem(final TTreeView view, final String text, final boolean expanded, final boolean openParents) throws IOException { @@ -168,7 +173,7 @@ public class TDirectoryTreeItem extends TTreeItem { File rootFile = new File(text); rootFile = rootFile.getCanonicalFile(); - if (openParents == true) { + if (openParents) { setExpanded(true); // Go up the directory tree @@ -186,12 +191,12 @@ public class TDirectoryTreeItem extends TTreeItem { } else { // This is a relative path. We got here because openParents was // false. - assert (openParents == false); + assert (!openParents); setText(rootFile.getName()); } onExpand(); - if (openParents == true) { + if (openParents) { TDirectoryTreeItem childFile = this; Collections.reverse(parentFiles); for (String p: parentFiles) { diff --git a/src/jexer/TFileOpenBox.java b/src/jexer/TFileOpenBox.java index 96085b8..9a0437c 100644 --- a/src/jexer/TFileOpenBox.java +++ b/src/jexer/TFileOpenBox.java @@ -59,7 +59,14 @@ public final class TFileOpenBox extends TWindow { * TFileOpenBox can be called for either Open or Save actions. */ public enum Type { + /** + * Button will be labeled "Open". + */ OPEN, + + /** + * Button will be labeled "Save". + */ SAVE } @@ -107,6 +114,7 @@ public final class TFileOpenBox extends TWindow { * directory, then * * @param newFilename the filename to check and return + * @throws IOException of a java.io operation throws */ private void checkFilename(final String newFilename) throws IOException { File newFile = new File(newFilename); @@ -133,6 +141,7 @@ public final class TFileOpenBox extends TWindow { * @param application the TApplication that manages this window * @param path path of selected file * @param type one of the Type constants + * @throws IOException of a java.io operation throws */ public TFileOpenBox(final TApplication application, final String path, final Type type) throws IOException { diff --git a/src/jexer/THScroller.java b/src/jexer/THScroller.java index eb7256b..54f3c0b 100644 --- a/src/jexer/THScroller.java +++ b/src/jexer/THScroller.java @@ -297,7 +297,8 @@ public final class THScroller extends TWidget { && (mouse.getX() < getWidth() - 1) ) { // Recompute value based on new box position - value = (rightValue - leftValue) * (mouse.getX()) / (getWidth() - 3) + leftValue; + value = (rightValue - leftValue) + * (mouse.getX()) / (getWidth() - 3) + leftValue; return; } inScroll = false; diff --git a/src/jexer/TMessageBox.java b/src/jexer/TMessageBox.java index 9de90dc..eac37aa 100644 --- a/src/jexer/TMessageBox.java +++ b/src/jexer/TMessageBox.java @@ -88,7 +88,7 @@ public class TMessageBox extends TWindow { /** * My buttons. */ - List buttons; + private List buttons; /** * Message boxes have these possible results. diff --git a/src/jexer/TTreeItem.java b/src/jexer/TTreeItem.java index 2770c46..e6bf279 100644 --- a/src/jexer/TTreeItem.java +++ b/src/jexer/TTreeItem.java @@ -101,7 +101,7 @@ public class TTreeItem extends TWidget { * * @param expanded new value */ - public final void setExpanded(boolean expanded) { + public final void setExpanded(final boolean expanded) { this.expanded = expanded; } @@ -124,7 +124,7 @@ public class TTreeItem extends TWidget { * * @param expandable new value */ - public final void setExpandable(boolean expandable) { + public final void setExpandable(final boolean expandable) { this.expandable = expandable; } @@ -162,7 +162,7 @@ public class TTreeItem extends TWidget { * * @param invisible new value */ - public final void setInvisible(boolean invisible) { + public final void setInvisible(final boolean invisible) { this.invisible = invisible; } @@ -185,7 +185,7 @@ public class TTreeItem extends TWidget { * * @param selected new value */ - public final void setSelected(boolean selected) { + public final void setSelected(final boolean selected) { this.selected = selected; } @@ -199,7 +199,7 @@ public class TTreeItem extends TWidget { * * @param selectable new value */ - public final void setSelectable(boolean selectable) { + public final void setSelectable(final boolean selectable) { this.selectable = selectable; } @@ -276,7 +276,7 @@ public class TTreeItem extends TWidget { this.prefix = prefix; array.add(this); - if ((getChildren().size() == 0) || (expanded == false)) { + if ((getChildren().size() == 0) || !expanded) { return array; } diff --git a/src/jexer/TTreeView.java b/src/jexer/TTreeView.java index 7aaee43..aaed4d1 100644 --- a/src/jexer/TTreeView.java +++ b/src/jexer/TTreeView.java @@ -52,6 +52,8 @@ public class TTreeView extends TWidget { /** * Get the horizontal scrollbar. This is used by TTreeItem.draw(), and * potentially subclasses. + * + * @return the horizontal scrollbar */ public final THScroller getHScroller() { return hScroller; @@ -94,7 +96,7 @@ public class TTreeView extends TWidget { * If true, move the window to put the selected item in view. This * normally only happens once after setting treeRoot. */ - public boolean centerWindow = false; + private boolean centerWindow = false; /** * The action to perform when the user selects an item. @@ -107,7 +109,9 @@ public class TTreeView extends TWidget { * @param treeRoot ultimate root of tree * @param centerWindow if true, move the window to put the root in view */ - public void setTreeRoot(final TTreeItem treeRoot, final boolean centerWindow) { + public void setTreeRoot(final TTreeItem treeRoot, + final boolean centerWindow) { + this.treeRoot = treeRoot; this.centerWindow = centerWindow; } @@ -239,12 +243,12 @@ public class TTreeView extends TWidget { if (item == selectedItem) { foundSelectedRow = true; } - if (foundSelectedRow == false) { + if (!foundSelectedRow) { selectedRow++; } int lineWidth = item.getText().length() - + item.getPrefix().length() + 4; + + item.getPrefix().length() + 4; if (lineWidth > maxLineWidth) { maxLineWidth = lineWidth; } @@ -360,7 +364,7 @@ public class TTreeView extends TWidget { * @param mouse mouse button release event */ @Override - public void onMouseUp(TMouseEvent mouse) { + public void onMouseUp(final TMouseEvent mouse) { // Pass to children super.onMouseDown(mouse); diff --git a/src/jexer/TVScroller.java b/src/jexer/TVScroller.java index 681a123..9b69f69 100644 --- a/src/jexer/TVScroller.java +++ b/src/jexer/TVScroller.java @@ -328,13 +328,14 @@ public final class TVScroller extends TWidget { return; } - if ((mouse.isMouse1()) && - (inScroll) && - (mouse.getY() > 0) && - (mouse.getY() < getHeight() - 1) + if ((mouse.isMouse1()) + && (inScroll) + && (mouse.getY() > 0) + && (mouse.getY() < getHeight() - 1) ) { // Recompute value based on new box position - value = (bottomValue - topValue) * (mouse.getY()) / (getHeight() - 3) + topValue; + value = (bottomValue - topValue) + * (mouse.getY()) / (getHeight() - 3) + topValue; return; } diff --git a/src/jexer/TWidget.java b/src/jexer/TWidget.java index 85910ab..564cc52 100644 --- a/src/jexer/TWidget.java +++ b/src/jexer/TWidget.java @@ -371,7 +371,7 @@ public abstract class TWidget implements Comparable { } /** - * Comparison operator sorts on: + * Comparison operator. For various subclasses it sorts on: *
    *
  • tabOrder for TWidgets
  • *
  • z for TWindows
  • @@ -1289,6 +1289,7 @@ public abstract class TWidget implements Comparable { * @param y row relative to parent * @param width width of tree view * @param height height of tree view + * @return the new tree view */ public final TTreeView addTreeView(final int x, final int y, final int width, final int height) { @@ -1304,6 +1305,7 @@ public abstract class TWidget implements Comparable { * @param width width of tree view * @param height height of tree view * @param action action to perform when an item is selected + * @return the new tree view */ public final TTreeView addTreeView(final int x, final int y, final int width, final int height, final TAction action) { @@ -1316,6 +1318,7 @@ public abstract class TWidget implements Comparable { * * @param path path of selected file * @return the result of the new file open box + * @throws IOException if a java.io operation throws */ public final String fileOpenBox(final String path) throws IOException { return getApplication().fileOpenBox(path); @@ -1327,6 +1330,7 @@ public abstract class TWidget implements Comparable { * @param path path of selected file * @param type one of the Type constants * @return the result of the new file open box + * @throws IOException if a java.io operation throws */ public final String fileOpenBox(final String path, final TFileOpenBox.Type type) throws IOException { @@ -1341,6 +1345,7 @@ public abstract class TWidget implements Comparable { * @param y row relative to parent * @param width width of text area * @param height height of text area + * @return the new directory list */ public final TDirectoryList addDirectoryList(final String path, final int x, final int y, final int width, final int height) { @@ -1357,6 +1362,7 @@ public abstract class TWidget implements Comparable { * @param width width of text area * @param height height of text area * @param action action to perform when an item is selected + * @return the new directory list */ public final TDirectoryList addDirectoryList(final String path, final int x, final int y, final int width, final int height, final TAction action) { diff --git a/src/jexer/bits/MnemonicString.java b/src/jexer/bits/MnemonicString.java index 08770ac..2cfe125 100644 --- a/src/jexer/bits/MnemonicString.java +++ b/src/jexer/bits/MnemonicString.java @@ -79,7 +79,7 @@ public final class MnemonicString { public String getRawLabel() { return rawLabel; } - + /** * Public constructor. * diff --git a/src/jexer/demos/DemoApplication.java b/src/jexer/demos/DemoApplication.java index d9bbeb7..f0bdacd 100644 --- a/src/jexer/demos/DemoApplication.java +++ b/src/jexer/demos/DemoApplication.java @@ -104,7 +104,7 @@ public class DemoApplication extends TApplication { * a window */ @Override - public boolean onMenu(TMenuEvent menu) { + public boolean onMenu(final TMenuEvent menu) { if (menu.getId() == TMenu.MID_OPEN_FILE) { try { String filename = fileOpenBox("."); @@ -116,7 +116,7 @@ public class DemoApplication extends TApplication { String EOL = System.getProperty("line.separator"); try { - while(scanner.hasNextLine()) { + while (scanner.hasNextLine()) { fileContents.append(scanner.nextLine() + EOL); } new DemoTextWindow(this, filename, @@ -142,7 +142,7 @@ public class DemoApplication extends TApplication { * @param backendType one of the TApplication.BackendType values * @throws Exception if TApplication can't instantiate the Backend. */ - public DemoApplication(BackendType backendType) throws Exception { + public DemoApplication(final BackendType backendType) throws Exception { super(backendType); addAllWidgets(); } diff --git a/src/jexer/demos/DemoTreeViewWindow.java b/src/jexer/demos/DemoTreeViewWindow.java index 0fc5dfe..6101d27 100644 --- a/src/jexer/demos/DemoTreeViewWindow.java +++ b/src/jexer/demos/DemoTreeViewWindow.java @@ -49,8 +49,9 @@ public class DemoTreeViewWindow extends TWindow { * Public constructor. * * @param parent the main application + * @throws IOException if a java.io operation throws */ - public DemoTreeViewWindow(TApplication parent) throws IOException { + public DemoTreeViewWindow(final TApplication parent) throws IOException { super(parent, "Tree View", 0, 0, 44, 16, TWindow.RESIZABLE); // Load the treeview with "stuff" @@ -64,7 +65,7 @@ public class DemoTreeViewWindow extends TWindow { * @param resize resize event */ @Override - public void onResize(TResizeEvent resize) { + public void onResize(final TResizeEvent resize) { if (resize.getType() == TResizeEvent.Type.WIDGET) { // Resize the text field treeView.setWidth(resize.getWidth() - 4); diff --git a/src/jexer/io/SwingScreen.java b/src/jexer/io/SwingScreen.java index 3c949c1..cdca714 100644 --- a/src/jexer/io/SwingScreen.java +++ b/src/jexer/io/SwingScreen.java @@ -519,6 +519,8 @@ public final class SwingScreen extends Screen { Cell lCell = screen.logical[cursorX][cursorY]; gr.setColor(attrToForegroundColor(lCell)); switch (cursorStyle) { + default: + // Fall through... case UNDERLINE: gr.fillRect(xPixel, yPixel + textHeight - 2, textWidth, 2); @@ -571,7 +573,7 @@ public final class SwingScreen extends Screen { SwingScreen.this.frame.resizeToScreen(); SwingScreen.this.frame.setVisible(true); } - } ); + }); } catch (Exception e) { e.printStackTrace(); } diff --git a/src/jexer/menu/TMenu.java b/src/jexer/menu/TMenu.java index 6dfb5fc..c1509d5 100644 --- a/src/jexer/menu/TMenu.java +++ b/src/jexer/menu/TMenu.java @@ -315,7 +315,7 @@ public final class TMenu extends TWindow { * @param label menu item label * @return the new menu item */ - public final TMenuItem addItem(final int id, final String label) { + public TMenuItem addItem(final int id, final String label) { assert (id >= 1024); return addItemInternal(id, label, null); } @@ -328,7 +328,7 @@ public final class TMenu extends TWindow { * @param key global keyboard accelerator * @return the new menu item */ - public final TMenuItem addItem(final int id, final String label, + public TMenuItem addItem(final int id, final String label, final TKeypress key) { assert (id >= 1024); @@ -371,7 +371,7 @@ public final class TMenu extends TWindow { * (inclusive). * @return the new menu item */ - public final TMenuItem addDefaultItem(final int id) { + public TMenuItem addDefaultItem(final int id) { assert (id >= 0); assert (id < 1024); @@ -451,7 +451,7 @@ public final class TMenu extends TWindow { /** * Convenience function to add a menu separator. */ - public final void addSeparator() { + public void addSeparator() { int newY = getChildren().size() + 1; assert (newY < getHeight()); @@ -468,7 +468,7 @@ public final class TMenu extends TWindow { * denoted by prefixing a letter with "&", e.g. "&File" * @return the new sub-menu */ - public final TSubMenu addSubMenu(final String title) { + public TSubMenu addSubMenu(final String title) { int newY = getChildren().size() + 1; assert (newY < getHeight()); diff --git a/src/jexer/menu/TMenuItem.java b/src/jexer/menu/TMenuItem.java index e3600bc..0898870 100644 --- a/src/jexer/menu/TMenuItem.java +++ b/src/jexer/menu/TMenuItem.java @@ -196,6 +196,7 @@ public class TMenuItem extends TWidget { * Returns true if the mouse is currently on the menu item. * * @param mouse mouse event + * @return if true then the mouse is currently on this item */ private boolean mouseOnMenuItem(final TMouseEvent mouse) { if ((mouse.getY() == 0) @@ -262,21 +263,6 @@ public class TMenuItem extends TWidget { } } - /** - * Handle mouse button presses. - * - * @param event mouse button press event - */ - /* TODO: this was commented out in d-tui, why? - @Override - public void onMouseDown(final TMouseEvent event) { - if ((mouseOnMenuItem(event)) && (event.mouse1)) { - dispatch(); - return; - } - } - */ - /** * Handle mouse button releases. * diff --git a/src/jexer/tterminal/ECMA48.java b/src/jexer/tterminal/ECMA48.java index 80f733b..ca3ce5c 100644 --- a/src/jexer/tterminal/ECMA48.java +++ b/src/jexer/tterminal/ECMA48.java @@ -2185,8 +2185,9 @@ public class ECMA48 implements Runnable { } /** - * Set or unset a toggle. value is 'true' for set ('h'), false for reset - * ('l'). + * Set or unset a toggle. + * + * @param value true for set ('h'), false for reset ('l') */ private void setToggle(final boolean value) { boolean decPrivateModeFlag = false; @@ -5534,8 +5535,8 @@ public class ECMA48 implements Runnable { collect(ch); } if (ch == 0x5C) { - if ((collectBuffer.length() > 0) && - (collectBuffer.charAt(collectBuffer.length() - 1) == 0x1B) + if ((collectBuffer.length() > 0) + && (collectBuffer.charAt(collectBuffer.length() - 1) == 0x1B) ) { toGround(); } @@ -5566,8 +5567,8 @@ public class ECMA48 implements Runnable { collect(ch); } if (ch == 0x5C) { - if ((collectBuffer.length() > 0) && - (collectBuffer.charAt(collectBuffer.length() - 1) == 0x1B) + if ((collectBuffer.length() > 0) + && (collectBuffer.charAt(collectBuffer.length() - 1) == 0x1B) ) { toGround(); } @@ -5719,7 +5720,7 @@ public class ECMA48 implements Runnable { /** * Read function runs on a separate thread. */ - public void run() { + public final void run() { boolean utf8 = false; boolean done = false;