diff --git a/BinaryInternalsViewer/src/main/java/org/freeinternals/binaryviewer/DataViewer.java b/BinaryInternalsViewer/src/main/java/org/freeinternals/binaryviewer/DataViewer.java index 6720237..0e3f166 100644 --- a/BinaryInternalsViewer/src/main/java/org/freeinternals/binaryviewer/DataViewer.java +++ b/BinaryInternalsViewer/src/main/java/org/freeinternals/binaryviewer/DataViewer.java @@ -31,7 +31,7 @@ public abstract class DataViewer extends JTextPane { /** * Constructor. */ - public DataViewer() { + DataViewer() { super(); this.setEditable(false); this.setBorder(null); diff --git a/BinaryInternalsViewer/src/main/java/org/freeinternals/binaryviewer/JBinaryViewer.java b/BinaryInternalsViewer/src/main/java/org/freeinternals/binaryviewer/JBinaryViewer.java index 040e896..cb193a2 100644 --- a/BinaryInternalsViewer/src/main/java/org/freeinternals/binaryviewer/JBinaryViewer.java +++ b/BinaryInternalsViewer/src/main/java/org/freeinternals/binaryviewer/JBinaryViewer.java @@ -8,7 +8,6 @@ import java.awt.BorderLayout; import java.awt.event.AdjustmentEvent; -import java.awt.event.AdjustmentListener; import java.awt.event.ComponentAdapter; import java.awt.event.ComponentEvent; import java.awt.event.KeyEvent; @@ -103,19 +102,12 @@ public final class JBinaryViewer extends JPanel { */ public JBinaryViewer() { this.setLayout(new BorderLayout()); - // this.setFont(JBinaryViewer.FONT); this.addComponentListener(new ComponentResizedAdapter()); this.addMouseWheelListener(new MouseWheelAdapter()); // Vertical Bar this.vBar = new JScrollBar(); - this.vBar.addAdjustmentListener(new AdjustmentListener() { - - @Override - public void adjustmentValueChanged(final AdjustmentEvent e) { - updateViewContent(); - } - }); + this.vBar.addAdjustmentListener((final AdjustmentEvent e) -> updateViewContent()); this.vBar.setVisible(false); this.add(this.vBar, BorderLayout.EAST); @@ -219,12 +211,7 @@ private void updateViewContent() { diff = (diff > 0) ? diff : 0; this.vBar.setValue(diff); } - - if (extent > this.rowMax + JBinaryViewer.ROW_EMPTYROW_COUNT) { - this.vBar.setVisible(false); - } else { - this.vBar.setVisible(true); - } + this.vBar.setVisible(extent < this.rowMax + JBinaryViewer.ROW_EMPTYROW_COUNT); // Revise row viewer, raw data viewer, ASCII data viewer this.rowViewer.setData(this.vBar.getValue(), extent, this.rowMax); @@ -339,6 +326,7 @@ public void mouseWheelMoved(final MouseWheelEvent e) { class KeyboardAdapter implements KeyListener { @Override + @SuppressWarnings("java:S1186") // Methods should not be empty --- Ignore this rule public void keyTyped(final KeyEvent e) { } @@ -377,6 +365,7 @@ public void keyPressed(final KeyEvent e) { } @Override + @SuppressWarnings("java:S1186") // Methods should not be empty --- Ignore this rule public void keyReleased(final KeyEvent e) { } } diff --git a/BinaryInternalsViewer/src/main/java/org/freeinternals/biv/JDialogAbout.java b/BinaryInternalsViewer/src/main/java/org/freeinternals/biv/JDialogAbout.java index 89109de..072877e 100644 --- a/BinaryInternalsViewer/src/main/java/org/freeinternals/biv/JDialogAbout.java +++ b/BinaryInternalsViewer/src/main/java/org/freeinternals/biv/JDialogAbout.java @@ -18,9 +18,9 @@ import javax.swing.BoxLayout; import javax.swing.JButton; import javax.swing.JDialog; -import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; +import javax.swing.WindowConstants; /** * @@ -37,7 +37,7 @@ class JDialogAbout extends JDialog { */ JDialogAbout(final Frame owner, final String title) { super(owner, title); - this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); this.setModal(true); this.initComponents(); @@ -49,9 +49,7 @@ private void initComponents() { this.setLayout(new FlowLayout()); final JButton buttonClose = new JButton("Close"); - buttonClose.addActionListener((final ActionEvent e) -> { - buttonOK_Clicked(); - }); + buttonClose.addActionListener((final ActionEvent e) -> buttonOKClicked()); // Lay out the labels from top to bottom. final JPanel listPane = new JPanel(); @@ -88,7 +86,7 @@ private void initComponents() { } - private void buttonOK_Clicked() { + private void buttonOKClicked() { this.setVisible(false); } } diff --git a/BinaryInternalsViewer/src/main/java/org/freeinternals/biv/JDialogPlugins.java b/BinaryInternalsViewer/src/main/java/org/freeinternals/biv/JDialogPlugins.java index 23b0eb4..9984d70 100644 --- a/BinaryInternalsViewer/src/main/java/org/freeinternals/biv/JDialogPlugins.java +++ b/BinaryInternalsViewer/src/main/java/org/freeinternals/biv/JDialogPlugins.java @@ -19,10 +19,10 @@ import javax.swing.BoxLayout; import javax.swing.JButton; import javax.swing.JDialog; -import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable; +import javax.swing.WindowConstants; import javax.swing.table.AbstractTableModel; import javax.swing.table.TableCellRenderer; import javax.swing.table.TableColumnModel; @@ -44,7 +44,7 @@ class JDialogPlugins extends JDialog { */ JDialogPlugins(final Frame owner, final String title) { super(owner, title); - this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); this.setModal(true); this.initComponents(); @@ -56,9 +56,7 @@ private void initComponents() { this.setLayout(new BorderLayout()); final JButton buttonClose = new JButton("Close"); - buttonClose.addActionListener((final ActionEvent e) -> { - buttonOK_Clicked(); - }); + buttonClose.addActionListener((final ActionEvent e) -> buttonOKClicked()); // Lay out the labels from top to bottom. final JTable table = new JTable(new PluginsModel()); @@ -84,7 +82,7 @@ private void initComponents() { contentPane.add(buttonPane, BorderLayout.PAGE_END); } - private void buttonOK_Clicked() { + private void buttonOKClicked() { this.setVisible(false); } @@ -103,8 +101,8 @@ private void resizeColumnWidth(JTable table) { public static class PluginsModel extends AbstractTableModel { - List columnNames = new LinkedList<>(); - List> rowData = new LinkedList<>(); + transient List columnNames = new LinkedList<>(); + transient List> rowData = new LinkedList<>(); PluginsModel() { Map plugins = PluginManager.getPlugins(); @@ -115,10 +113,10 @@ public static class PluginsModel extends AbstractTableModel { this.columnNames.add("Extension Description"); // Row Data - for (Map.Entry pair : plugins.entrySet()) { + for (Map.Entry pair : plugins.entrySet()) { PluginDescriptor value = (PluginDescriptor) pair.getValue(); List row = new LinkedList<>(); - row.add(pair.getKey().toString()); + row.add(pair.getKey()); row.add(value.getFileFormatClass().getName()); row.add(value.getExtensionDescription()); this.rowData.add(row); diff --git a/BinaryInternalsViewer/src/main/java/org/freeinternals/biv/JPanelForTree.java b/BinaryInternalsViewer/src/main/java/org/freeinternals/biv/JPanelForTree.java index ca687ee..39acc82 100644 --- a/BinaryInternalsViewer/src/main/java/org/freeinternals/biv/JPanelForTree.java +++ b/BinaryInternalsViewer/src/main/java/org/freeinternals/biv/JPanelForTree.java @@ -10,7 +10,6 @@ import java.awt.Component; import java.awt.Dimension; import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; import javax.swing.Box; import javax.swing.BoxLayout; import javax.swing.JButton; @@ -73,7 +72,7 @@ public final class JPanelForTree extends JPanel { * @param jTree The tree to be contained * @param frame The parent window */ - @edu.umd.cs.findbugs.annotations.SuppressFBWarnings(value="EI_EXPOSE_REP2", justification="We need it") + @edu.umd.cs.findbugs.annotations.SuppressFBWarnings(value = "EI_EXPOSE_REP2", justification = "We need it") public JPanelForTree(final JTree jTree, final JFrame frame) { if (jTree == null) { throw new IllegalArgumentException("[tree] cannot be null."); @@ -81,9 +80,7 @@ public JPanelForTree(final JTree jTree, final JFrame frame) { this.tree = jTree; this.topLevelFrame = frame; - this.tree.addTreeSelectionListener((final javax.swing.event.TreeSelectionEvent evt) -> { - treeSelectionChanged(evt); - }); + this.tree.addTreeSelectionListener(this::treeSelectionChanged); this.toolbar = new JToolBar(); this.toolbarbtnDetails = new JButton("Details"); @@ -122,43 +119,21 @@ private void layoutComponents() { private void initToolbar() { this.toolbar.setRollover(true); - //this.toolbar.setFloatable(false); // Button: Expand All final JButton buttonExpandAll = new JButton("Expand All"); - buttonExpandAll.addActionListener(new ActionListener() { - - @Override - public void actionPerformed(final ActionEvent e) { - toolbarExpandAll(); - } - }); + buttonExpandAll.addActionListener((final ActionEvent e) -> toolbarExpandAll()); this.toolbar.add(buttonExpandAll); // Button: Collapse All final JButton buttonCollapseAll = new JButton("Collapse All"); - buttonCollapseAll.addActionListener(new ActionListener() { - - @Override - public void actionPerformed(final ActionEvent e) { - toolbarCollapseAll(); - } - }); + buttonCollapseAll.addActionListener((final ActionEvent e) -> toolbarCollapseAll()); this.toolbar.add(buttonCollapseAll); // Button: Details this.toolbarbtnDetails.setVisible(false); - this.toolbarbtnDetails.addActionListener(new ActionListener() { - - public void actionPerformed(final ActionEvent e) { - toolbarShowDetails(); - } - }); - //this.toolbar.addSeparator(); + this.toolbarbtnDetails.addActionListener((final ActionEvent e) -> toolbarShowDetails()); this.toolbar.add(this.toolbarbtnDetails); - - // Button: Find - //this.toolbar.add(new JButton("Find")); } private void toolbarExpandAll() { diff --git a/BinaryInternalsViewer/src/main/java/org/freeinternals/biv/JSplitPaneFile.java b/BinaryInternalsViewer/src/main/java/org/freeinternals/biv/JSplitPaneFile.java index 565b510..2338011 100644 --- a/BinaryInternalsViewer/src/main/java/org/freeinternals/biv/JSplitPaneFile.java +++ b/BinaryInternalsViewer/src/main/java/org/freeinternals/biv/JSplitPaneFile.java @@ -57,6 +57,7 @@ public JSplitPaneFile(final File file, final JFrame frame) throws FileFormatExce this.createAndShowGUI(); } + @SuppressWarnings("java:S3776") // Cognitive Complexity of methods should not be too high private void createAndShowGUI() { final DefaultMutableTreeNode root = new DefaultMutableTreeNode(new JTreeNodeFileComponent( diff --git a/BinaryInternalsViewer/src/main/java/org/freeinternals/biv/Main.java b/BinaryInternalsViewer/src/main/java/org/freeinternals/biv/Main.java index c8a7d8a..05e7cdf 100644 --- a/BinaryInternalsViewer/src/main/java/org/freeinternals/biv/Main.java +++ b/BinaryInternalsViewer/src/main/java/org/freeinternals/biv/Main.java @@ -41,6 +41,7 @@ import javax.swing.KeyStroke; import javax.swing.SwingUtilities; import javax.swing.UIManager; +import javax.swing.WindowConstants; import org.freeinternals.biv.plugin.PluginManager; import org.freeinternals.commonlib.ui.UITool; @@ -53,20 +54,21 @@ public class Main extends JFrame { private static final long serialVersionUID = 4876543219876500000L; private static final Logger LOGGER = Logger.getLogger(Main.class.getName()); + private static final String URI_HOMEPAGE = "https://github.com/amosshi/freeinternals"; private static final String TITLE = "Binary Internals Viewer "; private static final String TITLE_EXT = " - " + TITLE; private static final String MASS_TEST_MODE_PROPERTY = "org.freeinternals.masstestmode"; private final JPanel filedropPanel = new JPanel(); private final Set recentFiles = new HashSet<>(); - private final JMenu menu_FileRecentFile = new JMenu("Recent Files"); + private final JMenu menuFileRecentFile = new JMenu("Recent Files"); private JSplitPaneFile contentPane = null; @SuppressWarnings("LeakingThisInConstructor") - @SuppressFBWarnings(value="DM_EXIT", justification="This is desigend for mass test mode") + @SuppressFBWarnings(value = "DM_EXIT", justification = "This is desigend for mass test mode") private Main(final String[] args) { this.setTitle(TITLE + PluginManager.getPlugedExtensions()); - this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); this.centerJFrame(); this.createMenu(); @@ -86,14 +88,14 @@ private Main(final String[] args) { try { this.openFile(file); } catch (Exception e) { - LOGGER.log(Level.SEVERE, "Failed to open the file. filename=" + fileName, e); + LOGGER.log(Level.SEVERE, String.format("Failed to open the file. filename=%s", fileName), e); } } else { LOGGER.log(Level.WARNING, "The provided file does not exist: filename={0}", fileName); } // Exit immediately for mass test mode - if (Boolean.valueOf(System.getProperty(Main.MASS_TEST_MODE_PROPERTY, "false"))) { + if (Boolean.TRUE.equals(Boolean.valueOf(System.getProperty(Main.MASS_TEST_MODE_PROPERTY, "false")))) { System.exit(0); } } @@ -103,9 +105,7 @@ private Main(final String[] args) { * @param args the command line arguments */ public static void main(String[] args) { - SwingUtilities.invokeLater(() -> { - new Main(args).setVisible(true); - }); + SwingUtilities.invokeLater(() -> new Main(args).setVisible(true)); } /** @@ -132,41 +132,37 @@ private void createMenu() { menuBar.add(menuFile); // File --> Open - final JMenuItem menuItem_FileOpen = new JMenuItem("Open...", UIManager.getIcon("FileView.directoryIcon")); - menuItem_FileOpen.setMnemonic(KeyEvent.VK_O); - menuItem_FileOpen.setAccelerator(KeyStroke.getKeyStroke( + final JMenuItem menuItemFileOpen = new JMenuItem("Open...", UIManager.getIcon("FileView.directoryIcon")); + menuItemFileOpen.setMnemonic(KeyEvent.VK_O); + menuItemFileOpen.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_O, ActionEvent.CTRL_MASK)); - menuItem_FileOpen.addActionListener((final ActionEvent e) -> { - menu_FileOpen(); - }); - menuFile.add(menuItem_FileOpen); + menuItemFileOpen.addActionListener((final ActionEvent e) -> menuFileOpen()); + menuFile.add(menuItemFileOpen); // File --> Close - final JMenuItem menuItem_FileClose = new JMenuItem("Close", UIManager.getIcon("InternalFrame.iconifyIcon")); - menuItem_FileClose.setMnemonic(KeyEvent.VK_C); - menuItem_FileClose.addActionListener((final ActionEvent e) -> { - closeFile(); - }); - menuFile.add(menuItem_FileClose); + final JMenuItem menuItemFileClose = new JMenuItem("Close", UIManager.getIcon("InternalFrame.iconifyIcon")); + menuItemFileClose.setMnemonic(KeyEvent.VK_C); + menuItemFileClose.addActionListener((final ActionEvent e) -> closeFile()); + menuFile.add(menuItemFileClose); menuFile.addSeparator(); // File --> Recent Files - this.menu_FileRecentFile.setMnemonic(KeyEvent.VK_R); - menuFile.add(this.menu_FileRecentFile); + this.menuFileRecentFile.setMnemonic(KeyEvent.VK_R); + menuFile.add(this.menuFileRecentFile); // menuFile.addSeparator(); // File --> Exit - final JMenuItem menuItem_FileExit = new JMenuItem("Exit", UIManager.getIcon("Table.ascendingSortIcon")); - menuItem_FileExit.setMnemonic(KeyEvent.VK_X); - menuItem_FileExit.setAccelerator(KeyStroke.getKeyStroke( + final JMenuItem menuItemFileExit = new JMenuItem("Exit", UIManager.getIcon("Table.ascendingSortIcon")); + menuItemFileExit.setMnemonic(KeyEvent.VK_X); + menuItemFileExit.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_X, ActionEvent.ALT_MASK)); - menuItem_FileExit.addActionListener((final ActionEvent e) -> { - Main.this.dispatchEvent((new WindowEvent(Main.this, WindowEvent.WINDOW_CLOSING))); - }); - menuFile.add(menuItem_FileExit); + menuItemFileExit.addActionListener((final ActionEvent e) + -> Main.this.dispatchEvent((new WindowEvent(Main.this, WindowEvent.WINDOW_CLOSING))) + ); + menuFile.add(menuItemFileExit); // Help final JMenu menuHelp = new JMenu("Help"); @@ -174,28 +170,22 @@ private void createMenu() { menuBar.add(menuHelp); // Help --> Homepage - final JMenuItem menuItem_HelpHomepage = new JMenuItem("Homepage", UIManager.getIcon("FileView.computerIcon")); - menuItem_HelpHomepage.setMnemonic(KeyEvent.VK_P); - menuItem_HelpHomepage.addActionListener((final ActionEvent e) -> { - menu_HelpHomepage(); - }); - menuHelp.add(menuItem_HelpHomepage); + final JMenuItem menuItemHelpHomepage = new JMenuItem("Homepage", UIManager.getIcon("FileView.computerIcon")); + menuItemHelpHomepage.setMnemonic(KeyEvent.VK_P); + menuItemHelpHomepage.addActionListener((final ActionEvent e) -> menuHelpHomepage()); + menuHelp.add(menuItemHelpHomepage); // Help --> Plugins - final JMenuItem menuItem_HelpPlugins = new JMenuItem("Plug-ins"); - menuItem_HelpPlugins.setMnemonic(KeyEvent.VK_A); - menuItem_HelpPlugins.addActionListener((final ActionEvent e) -> { - menu_HelpPlugins(); - }); - menuHelp.add(menuItem_HelpPlugins); + final JMenuItem menuItemHelpPlugins = new JMenuItem("Plug-ins"); + menuItemHelpPlugins.setMnemonic(KeyEvent.VK_A); + menuItemHelpPlugins.addActionListener((final ActionEvent e) -> menuHelpPlugins()); + menuHelp.add(menuItemHelpPlugins); // Help --> About - final JMenuItem menuItem_HelpAbout = new JMenuItem("About"); - menuItem_HelpAbout.setMnemonic(KeyEvent.VK_A); - menuItem_HelpAbout.addActionListener((final ActionEvent e) -> { - menu_HelpAbout(); - }); - menuHelp.add(menuItem_HelpAbout); + final JMenuItem menuItemHelpAbout = new JMenuItem("About"); + menuItemHelpAbout.setMnemonic(KeyEvent.VK_A); + menuItemHelpAbout.addActionListener((final ActionEvent e) -> menuHelpAbout()); + menuHelp.add(menuItemHelpAbout); } /** @@ -217,7 +207,7 @@ public synchronized void drop(DropTargetDropEvent evt) { }); } - private void menu_FileOpen() { + private void menuFileOpen() { final JFileChooser chooser = new JFileChooser(); PluginManager.initChooseFilters(chooser); @@ -227,21 +217,22 @@ private void menu_FileOpen() { } } + @SuppressWarnings("java:S1181") // Throwable and Error should not be caught --- We need to cache all exception here private void openFile(final File file) { // Close any open file first if exists this.closeFile(); // Update Recent files menu item - this.menu_FileRecentFile.removeAll(); + this.menuFileRecentFile.removeAll(); this.recentFiles.add(file); - this.recentFiles.forEach(recent -> { - this.menu_FileRecentFile.add(new JMenuItem(new AbstractAction(recent.getAbsolutePath()) { - @Override - public void actionPerformed(ActionEvent e) { - openFile(recent); - } - })); - }); + this.recentFiles.forEach(recent + -> this.menuFileRecentFile.add(new JMenuItem(new AbstractAction(recent.getAbsolutePath()) { + @Override + public void actionPerformed(ActionEvent e) { + openFile(recent); + } + })) + ); // Add the file to UI try { @@ -267,7 +258,6 @@ private void closeFile() { this.setTitle(TITLE + PluginManager.getPlugedExtensions()); // Clear Content if (this.contentPane != null) { - //this.remove(this.contentPane); this.filedropPanel.remove(this.contentPane); this.validate(); } @@ -277,21 +267,21 @@ private void closeFile() { this.setSize(this.getWidth() - 1, this.getHeight()); } - private void menu_HelpPlugins() { + private void menuHelpPlugins() { final JDialogPlugins plugins = new JDialogPlugins(this, "Plug-ins"); plugins.setLocationRelativeTo(this); plugins.setVisible(true); } - private void menu_HelpAbout() { + private void menuHelpAbout() { final JDialogAbout about = new JDialogAbout(this, "About"); about.setLocationRelativeTo(this); about.setVisible(true); } - private void menu_HelpHomepage() { + private void menuHelpHomepage() { try { - Desktop.getDesktop().browse(new URI("https://github.com/amosshi/freeinternals")); + Desktop.getDesktop().browse(new URI(URI_HOMEPAGE)); } catch (URISyntaxException | IOException ex) { JOptionPane.showMessageDialog( this, diff --git a/BinaryInternalsViewer/src/main/java/org/freeinternals/biv/plugin/DefaultFileFormat.java b/BinaryInternalsViewer/src/main/java/org/freeinternals/biv/plugin/DefaultFileFormat.java index e8b2f9b..c0f2c2d 100644 --- a/BinaryInternalsViewer/src/main/java/org/freeinternals/biv/plugin/DefaultFileFormat.java +++ b/BinaryInternalsViewer/src/main/java/org/freeinternals/biv/plugin/DefaultFileFormat.java @@ -29,6 +29,7 @@ public String getContentTabName() { } @Override + @SuppressWarnings("java:S1186") // Methods should not be empty --- Ignore this rule public void generateTreeNode(DefaultMutableTreeNode parentNode) { } } diff --git a/BinaryInternalsViewer/src/main/java/org/freeinternals/biv/plugin/PluginManager.java b/BinaryInternalsViewer/src/main/java/org/freeinternals/biv/plugin/PluginManager.java index fdf652f..c08f58c 100644 --- a/BinaryInternalsViewer/src/main/java/org/freeinternals/biv/plugin/PluginManager.java +++ b/BinaryInternalsViewer/src/main/java/org/freeinternals/biv/plugin/PluginManager.java @@ -45,11 +45,18 @@ public class PluginManager { private PluginManager() { } + /** + *
+     * java:S135 - Loops should not contain more than a single "break" or "continue" statement --- multiple "continue" make code more readable
+     * java:S3776 - Cognitive Complexity of methods should not be too high
+     * 
+ */ + @SuppressWarnings({"java:S135", "java:S3776"}) private static void loadPlugins() { File pluginFolder = new File(PLUGIN_DIR); String pluginDescClassName; - if (pluginFolder.exists() == false) { + if (!pluginFolder.exists()) { // The plugin folder does not exist return; } @@ -96,7 +103,7 @@ public static String getPlugedExtensions() { StringBuilder builder = new StringBuilder(16); if (!PLUGINS.isEmpty()) { builder.append(" - "); - PLUGINS.values().stream().map((plugin) -> plugin.getExtensions()).forEachOrdered((exts) -> { + PLUGINS.values().stream().map(plugin -> plugin.getExtensions()).forEachOrdered(exts -> { for (String ext : exts) { builder.append(ext); builder.append(", "); diff --git a/CommonLib/src/main/java/org/freeinternals/commonlib/core/PosDataInputStream.java b/CommonLib/src/main/java/org/freeinternals/commonlib/core/PosDataInputStream.java index f8c59dc..2766e1e 100644 --- a/CommonLib/src/main/java/org/freeinternals/commonlib/core/PosDataInputStream.java +++ b/CommonLib/src/main/java/org/freeinternals/commonlib/core/PosDataInputStream.java @@ -207,8 +207,15 @@ public int readUnsignedShortInLittleEndian() throws IOException { return (ch2 << SHIFT_8) + (ch1); } + /** + * @throws IOException + * + *
+     * java:S1110 - Redundant parenthesis --- Redundant parenthesis is needed for readability
+     * 
+ */ @Override - @SuppressWarnings("java:S1110") // Redundant parenthesis is needed for readability + @SuppressWarnings("java:S1110") public int readIntInLittleEndian() throws IOException { int ch1 = this.in.read(); int ch2 = this.in.read(); @@ -220,8 +227,15 @@ public int readIntInLittleEndian() throws IOException { return (((ch4 << SHIFT_24) + (ch3 << SHIFT_16) + (ch2 << SHIFT_8) + (ch1))); } + /** + * @throws IOException + * + *
+     * java:S1110 - Redundant parenthesis --- Redundant parenthesis is needed for readability
+     * 
+ */ @Override - @SuppressWarnings("java:S1110") // Redundant parenthesis is needed for readability + @SuppressWarnings("java:S1110") public long readUnsignedInt() throws IOException { final byte[] readBuffer = new byte[BYTE_LENGTH_8]; @@ -241,8 +255,15 @@ public long readUnsignedInt() throws IOException { + ((readBuffer[BYTE_OFFSET_7] & BYTE_MAX_255))); } + /** + * @throws IOException + * + *
+     * java:S1110 - Redundant parenthesis --- Redundant parenthesis is needed for readability
+     * 
+ */ @Override - @SuppressWarnings("java:S1110") // Redundant parenthesis is needed for readability + @SuppressWarnings("java:S1110") public long readUnsignedIntInLittleEndian() throws IOException { final byte[] readBuffer = new byte[BYTE_LENGTH_8]; @@ -266,8 +287,15 @@ public long readUnsignedIntInLittleEndian() throws IOException { + ((readBuffer[BYTE_OFFSET_7] & BYTE_MAX_255))); } + /** + * @throws IOException + * + *
+     * java:S1110 - Redundant parenthesis --- Redundant parenthesis is needed for readability
+     * 
+ */ @Override - @SuppressWarnings("java:S1110") // Redundant parenthesis is needed for readability + @SuppressWarnings("java:S1110") public long readLongInLittleEndian() throws IOException { final byte[] readBuffer = new byte[BYTE_LENGTH_8]; super.readFully(readBuffer, 0, 8); @@ -330,9 +358,13 @@ public String readASCII() throws IOException { * * @param end * @throws java.io.IOException + * + *
+     * java:S135 - Loops should not contain more than a single "break" or "continue" statement --- We need it in this method
+     * 
*/ @Override - @SuppressWarnings("java:S135") // Loops should not contain more than a single "break" or "continue" statement + @SuppressWarnings("java:S135") public String readASCIIUntil(final byte end) throws IOException { byte b; StringBuilder sb = new StringBuilder(); @@ -359,8 +391,12 @@ public String readASCIIUntil(final byte end) throws IOException { * @param end End value for the ASCII string * @return ASCII as string * @throws java.io.IOException Read failed + * + *
+     * java:S135 - Loops should not contain more than a single "break" or "continue" statement --- We need it in this method
+     * 
*/ - @SuppressWarnings("java:S135") // Loops should not contain more than a single "break" or "continue" statement + @SuppressWarnings("java:S135") public String readASCIIUntil(byte... end) throws IOException { if (end == null || end.length < 1) { throw new IllegalArgumentException("Inalid parameter 'end'."); @@ -417,8 +453,13 @@ private boolean contains(final byte v, final byte[] list) { return result; } + /** + *
+     * java:S135 - Loops should not contain more than a single "break" or "continue" statement --- We need it in this method
+     * 
+ */ @Override - @SuppressWarnings("java:S135") // Loops should not contain more than a single "break" or "continue" statement + @SuppressWarnings("java:S135") public byte[] readBinary() throws IOException { int size = this.getBuf().length - this.getPos() + this.offset + 1; byte[] big = new byte[size]; diff --git a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/AccessFlag.java b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/AccessFlag.java index d3c902b..3bb1bcb 100644 --- a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/AccessFlag.java +++ b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/AccessFlag.java @@ -14,7 +14,12 @@ /** * * @author Amos Shi + * + *
+ * java:S2386 - Mutable fields should not be "public static" --- We keep the simplied public variable
+ * 
*/ +@SuppressWarnings("java:S2386") public enum AccessFlag { /** diff --git a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/ClassFile.java b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/ClassFile.java index 186b5a4..44fd49e 100644 --- a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/ClassFile.java +++ b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/ClassFile.java @@ -55,7 +55,12 @@ * @see * VM Spec: The ClassFile Structure + * + *
+ * java:S116 - Field names should comply with a naming convention --- We respect the name from JVM Spec instead
+ * 
*/ +@SuppressWarnings("java:S116") public class ClassFile extends FileFormat { /** @@ -232,8 +237,8 @@ public ClassFile(final byte[] classFileBytes) throws IOException, FileFormatExce this(classFileBytes, null, null); } - // java:S127 - "for" loop stop conditions should be invariant --> No we need it because Long/Double type occupies two Constant Pool index - // java:S3776 - Cognitive Complexity of methods should not be too high --> No, it is not high + // java:S127 - "for" loop stop conditions should be invariant --- No we need it because Long/Double type occupies two Constant Pool index + // java:S3776 - Cognitive Complexity of methods should not be too high --- No, it is not high @SuppressWarnings({"java:S127", "java:S3776"}) public ClassFile(final byte[] classFileBytes, final String fileName, final String filePath) throws IOException, FileFormatException { super(classFileBytes, fileName, filePath); diff --git a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/FieldInfo.java b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/FieldInfo.java index 6ff2dd4..8196c3c 100644 --- a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/FieldInfo.java +++ b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/FieldInfo.java @@ -32,7 +32,12 @@ * * VM Spec: Fields * + * + *
+ * java:S116 - Field names should comply with a naming convention --- We respect the name from JVM Spec instead
+ * 
*/ +@SuppressWarnings("java:S116") public class FieldInfo extends FileComponent { public final u2 access_flags; @@ -139,7 +144,7 @@ private void parse(final CPInfo[] cpInfo) throws FileFormatException { String type; try { - type = SignatureConvertor.FieldDescriptorExtractor(this.descriptor).toString(); + type = SignatureConvertor.fieldDescriptorExtractor(this.descriptor).toString(); } catch (FileFormatException se) { type = "[Unexpected signature type]: " + this.descriptor; } diff --git a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/JTreeClassFile.java b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/JTreeClassFile.java index 2768e6f..589ac3f 100644 --- a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/JTreeClassFile.java +++ b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/JTreeClassFile.java @@ -91,55 +91,55 @@ private void generateConstantPool() { startPos += u2.LENGTH; final CPInfo[] cp = this.classFile.constant_pool; - final DefaultMutableTreeNode constant_pool = new DefaultMutableTreeNode(new JTreeNodeFileComponent( + final DefaultMutableTreeNode constantPool = new DefaultMutableTreeNode(new JTreeNodeFileComponent( startPos, cp[cpCount - 1].getStartPos() + cp[cpCount - 1].getLength() - startPos, CP_PREFIX + cpCount + "]", MESSAGES.getString("msg_constant_pool_table") )); - this.root.add(constant_pool); + this.root.add(constantPool); - DefaultMutableTreeNode cp_info_node; + DefaultMutableTreeNode cpInfoNode; for (int i = 1; i < cpCount; i++) { if (cp[i] != null) { - cp_info_node = new DefaultMutableTreeNode(new JTreeNodeFileComponent(cp[i].getStartPos(), cp[i].getLength(), i + ". " + cp[i].getName())); - cp_info_node.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent( + cpInfoNode = new DefaultMutableTreeNode(new JTreeNodeFileComponent(cp[i].getStartPos(), cp[i].getLength(), i + ". " + cp[i].getName())); + cpInfoNode.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent( cp[i].getStartPos(), 1, "tag: " + cp[i].tag.value, MESSAGES.getString("msg_cp_tag") ))); - cp[i].generateTreeNode(cp_info_node, this.classFile); + cp[i].generateTreeNode(cpInfoNode, this.classFile); } else { - cp_info_node = new DefaultMutableTreeNode(new JTreeNodeFileComponent(0, 0, i + ". [Empty Item]", - MESSAGES.getString("msg_cp_empty"))); + cpInfoNode = new DefaultMutableTreeNode(new JTreeNodeFileComponent(0, 0, i + ". [Empty Item]", + MESSAGES.getString("msg_cp_empty"))); } - constant_pool.add(cp_info_node); + constantPool.add(cpInfoNode); } } private void generateClassDeclaration() { final StringBuilder sb = new StringBuilder(); - final DefaultMutableTreeNode access_flags = new DefaultMutableTreeNode(new JTreeNodeFileComponent( + final DefaultMutableTreeNode accessFlags = new DefaultMutableTreeNode(new JTreeNodeFileComponent( this.classFile.access_flags.getStartPos(), this.classFile.access_flags.getLength(), MESSAGE_ACCESS_FLAGS + this.classFile.getModifiers(), MESSAGES.getString("msg_access_flags") )); - this.root.add(access_flags); + this.root.add(accessFlags); sb.append("this_class: "); sb.append(this.classFile.this_class.getValue()); sb.append(String.format(" - %s", this.classFile.getCPDescription(this.classFile.this_class.getValue()))); - final DefaultMutableTreeNode this_class = new DefaultMutableTreeNode(new JTreeNodeFileComponent( + final DefaultMutableTreeNode thisClass = new DefaultMutableTreeNode(new JTreeNodeFileComponent( this.classFile.this_class.getStartPos(), this.classFile.this_class.getLength(), sb.toString(), MESSAGES.getString("msg_this_class") )); - this.root.add(this_class); + this.root.add(thisClass); final int superClassValue = this.classFile.super_class.getValue(); sb.setLength(0); @@ -149,22 +149,22 @@ private void generateClassDeclaration() { if (superClassValue > 0) { sb.append(String.format(" - %s", this.classFile.getCPDescription(this.classFile.super_class.getValue()))); } - final DefaultMutableTreeNode super_class = new DefaultMutableTreeNode(new JTreeNodeFileComponent( + final DefaultMutableTreeNode superClass = new DefaultMutableTreeNode(new JTreeNodeFileComponent( this.classFile.super_class.getStartPos(), this.classFile.super_class.getLength(), sb.toString(), MESSAGES.getString("msg_super_class") )); - this.root.add(super_class); + this.root.add(superClass); final int interfaceCount = this.classFile.interfaces_count.getValue(); - final DefaultMutableTreeNode interfaces_count = new DefaultMutableTreeNode(new JTreeNodeFileComponent( + final DefaultMutableTreeNode interfacesCount = new DefaultMutableTreeNode(new JTreeNodeFileComponent( this.classFile.interfaces_count.getStartPos(), this.classFile.interfaces_count.getLength(), "interfaces_count: " + interfaceCount, MESSAGES.getString("msg_interfaces_count") )); - this.root.add(interfaces_count); + this.root.add(interfacesCount); if (this.classFile.interfaces_count.getValue() > 0) { final U2ClassComponent[] interfaces = this.classFile.interfaces; @@ -197,13 +197,13 @@ private void generateClassDeclaration() { private void generateFields() { final int fieldCount = this.classFile.fields_count.getValue(); - final DefaultMutableTreeNode fields_count = new DefaultMutableTreeNode(new JTreeNodeFileComponent( + final DefaultMutableTreeNode fieldsCount = new DefaultMutableTreeNode(new JTreeNodeFileComponent( this.classFile.fields_count.getStartPos(), this.classFile.fields_count.getLength(), "fields_count: " + fieldCount, MESSAGES.getString("msg_fields_count") )); - this.root.add(fields_count); + this.root.add(fieldsCount); if (fieldCount > 0) { final FieldInfo[] fields = this.classFile.fields; @@ -228,30 +228,30 @@ private void generateFields() { } } - private void generateField(final DefaultMutableTreeNode rootNode, final FieldInfo field_info, final ClassFile classFile) { - if (field_info == null) { + private void generateField(final DefaultMutableTreeNode rootNode, final FieldInfo fieldInfo, final ClassFile classFile) { + if (fieldInfo == null) { return; } - final int startPos = field_info.getStartPos(); - final int attributesCount = field_info.attributes_count.value; + final int startPos = fieldInfo.getStartPos(); + final int attributesCount = fieldInfo.attributes_count.value; rootNode.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent( startPos, 2, - MESSAGE_ACCESS_FLAGS + field_info.access_flags.value + ", " + field_info.getModifiers() + MESSAGE_ACCESS_FLAGS + fieldInfo.access_flags.value + ", " + fieldInfo.getModifiers() ))); - int name_index = field_info.name_index.value; + int nameIndex = fieldInfo.name_index.value; rootNode.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent( startPos + 2, 2, - "name_index: " + name_index + " - " + classFile.getCPDescription(name_index) + "name_index: " + nameIndex + " - " + classFile.getCPDescription(nameIndex) ))); - int descriptor_index = field_info.descriptor_index.value; + int descriptorIndex = fieldInfo.descriptor_index.value; rootNode.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent( startPos + 4, 2, - "descriptor_index: " + descriptor_index + " - " + classFile.getCPDescription(descriptor_index) + "descriptor_index: " + descriptorIndex + " - " + classFile.getCPDescription(descriptorIndex) ))); rootNode.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent( startPos + 6, @@ -260,7 +260,7 @@ private void generateField(final DefaultMutableTreeNode rootNode, final FieldInf ))); if (attributesCount > 0) { - final AttributeInfo lastAttr = field_info.getAttribute(attributesCount - 1); + final AttributeInfo lastAttr = fieldInfo.getAttribute(attributesCount - 1); final DefaultMutableTreeNode treeNodeAttr = new DefaultMutableTreeNode(new JTreeNodeFileComponent( startPos + 8, lastAttr.getStartPos() + lastAttr.getLength() - startPos - 8, @@ -270,7 +270,7 @@ private void generateField(final DefaultMutableTreeNode rootNode, final FieldInf DefaultMutableTreeNode treeNodeAttrItem; AttributeInfo attr; for (int i = 0; i < attributesCount; i++) { - attr = field_info.getAttribute(i); + attr = fieldInfo.getAttribute(i); treeNodeAttrItem = new DefaultMutableTreeNode(new JTreeNodeFileComponent( attr.getStartPos(), @@ -287,13 +287,13 @@ private void generateField(final DefaultMutableTreeNode rootNode, final FieldInf private void generateMethods() { final int methodCount = this.classFile.methods_count.getValue(); - final DefaultMutableTreeNode methods_count = new DefaultMutableTreeNode(new JTreeNodeFileComponent( + final DefaultMutableTreeNode methodsCount = new DefaultMutableTreeNode(new JTreeNodeFileComponent( this.classFile.methods_count.getStartPos(), this.classFile.methods_count.getLength(), "methods_count: " + methodCount, MESSAGES.getString("msg_methods_count") )); - this.root.add(methods_count); + this.root.add(methodsCount); if (methodCount > 0) { final MethodInfo[] methods = this.classFile.methods; @@ -318,31 +318,31 @@ private void generateMethods() { } } - private void generateMethod(final DefaultMutableTreeNode rootNode, final MethodInfo method_info, final ClassFile classFile) { - if (method_info == null) { + private void generateMethod(final DefaultMutableTreeNode rootNode, final MethodInfo methodInfo, final ClassFile classFile) { + if (methodInfo == null) { return; } - final int startPos = method_info.getStartPos(); - final int attributesCount = method_info.attributes_count.value; - int cp_index; + final int startPos = methodInfo.getStartPos(); + final int attributesCount = methodInfo.attributes_count.value; + int cpIndex; rootNode.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent( startPos, 2, - MESSAGE_ACCESS_FLAGS + method_info.access_flags.value + ", " + method_info.getModifiers() + MESSAGE_ACCESS_FLAGS + methodInfo.access_flags.value + ", " + methodInfo.getModifiers() ))); - cp_index = method_info.name_index.value; + cpIndex = methodInfo.name_index.value; rootNode.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent( startPos + 2, 2, - String.format("name_index: %d - %s", cp_index, classFile.getCPDescription(cp_index)) + String.format("name_index: %d - %s", cpIndex, classFile.getCPDescription(cpIndex)) ))); - cp_index = method_info.descriptor_index.value; + cpIndex = methodInfo.descriptor_index.value; rootNode.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent( startPos + 4, 2, - String.format("descriptor_index: %d - %s", cp_index, classFile.getCPDescription(cp_index)) + String.format("descriptor_index: %d - %s", cpIndex, classFile.getCPDescription(cpIndex)) ))); rootNode.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent( startPos + 6, @@ -350,7 +350,7 @@ private void generateMethod(final DefaultMutableTreeNode rootNode, final MethodI MESSAGE_ATTR_COUNT + attributesCount))); if (attributesCount > 0) { - final AttributeInfo lastAttr = method_info.getAttribute(attributesCount - 1); + final AttributeInfo lastAttr = methodInfo.getAttribute(attributesCount - 1); final DefaultMutableTreeNode treeNodeAttr = new DefaultMutableTreeNode(new JTreeNodeFileComponent( startPos + 8, lastAttr.getStartPos() + lastAttr.getLength() - startPos - 8, @@ -360,7 +360,7 @@ private void generateMethod(final DefaultMutableTreeNode rootNode, final MethodI DefaultMutableTreeNode treeNodeAttrItem; AttributeInfo attr; for (int i = 0; i < attributesCount; i++) { - attr = method_info.getAttribute(i); + attr = methodInfo.getAttribute(i); treeNodeAttrItem = new DefaultMutableTreeNode(new JTreeNodeFileComponent( attr.getStartPos(), attr.getLength(), @@ -376,13 +376,13 @@ private void generateMethod(final DefaultMutableTreeNode rootNode, final MethodI private void generateAttributes() { final int attrCount = this.classFile.attributes_count.getValue(); - final DefaultMutableTreeNode attrs_count = new DefaultMutableTreeNode(new JTreeNodeFileComponent( + final DefaultMutableTreeNode attrsCount = new DefaultMutableTreeNode(new JTreeNodeFileComponent( this.classFile.attributes_count.getStartPos(), this.classFile.attributes_count.getLength(), MESSAGE_ATTR_COUNT + attrCount, MESSAGES.getString("msg_attributes_count") )); - this.root.add(attrs_count); + this.root.add(attrsCount); if (attrCount > 0) { final AttributeInfo[] attrs = this.classFile.attributes; @@ -431,10 +431,10 @@ StringBuilder generateOpcodeParseResult(byte[] opcodeData) { // The Reference Object if (cpindexCounter > 0) { sb.append(HTML_OL_BEGIN); - codeResult.stream().filter((iResult) -> (iResult.getCpindex() != null)).forEachOrdered((Opcode.InstructionParsed iResult) -> { - sb.append(String.format(HTML_LI, HTMLKit.escapeFilter( - this.classFile.getCPDescription(iResult.getCpindex())))); - }); + codeResult.stream().filter(iResult -> (iResult.getCpindex() != null)).forEachOrdered( + (Opcode.InstructionParsed iResult) -> sb.append(String.format(HTML_LI, HTMLKit.escapeFilter( + this.classFile.getCPDescription(iResult.getCpindex())))) + ); sb.append(HTML_OL_END); } @@ -453,15 +453,15 @@ StringBuilder generateReport2CP() { sb.append(String.format("Constant Pool Count: %d", count)); sb.append(HTMLKit.NEW_LINE); if (count > 0) { - CPInfo[] CPInfoList = this.classFile.constant_pool; + CPInfo[] cpInfoList = this.classFile.constant_pool; // Constant Pool - by Type sb.append("Constant Pool - Class"); - this.generateReport4CPType(sb, CPInfoList, count, CPInfo.ConstantType.CONSTANT_Class.tag); + this.generateReport4CPType(sb, cpInfoList, count, CPInfo.ConstantType.CONSTANT_Class.tag); sb.append("Constant Pool - Field"); - this.generateReport4CPType(sb, CPInfoList, count, CPInfo.ConstantType.CONSTANT_Fieldref.tag); + this.generateReport4CPType(sb, cpInfoList, count, CPInfo.ConstantType.CONSTANT_Fieldref.tag); sb.append("Constant Pool - Method"); - this.generateReport4CPType(sb, CPInfoList, count, CPInfo.ConstantType.CONSTANT_Methodref.tag); + this.generateReport4CPType(sb, cpInfoList, count, CPInfo.ConstantType.CONSTANT_Methodref.tag); // Constant Pool Object List sb.append("Constant Pool Object List"); @@ -478,11 +478,11 @@ StringBuilder generateReport2CP() { return sb; } - private void generateReport4CPType(StringBuilder sb, CPInfo[] CPInfoList, int count, short tag) { + private void generateReport4CPType(StringBuilder sb, CPInfo[] cpInfoList, int count, short tag) { sb.append(HTMLKit.NEW_LINE); sb.append("
    "); for (int i = 1; i < count; i++) { - if (CPInfoList[i] != null && CPInfoList[i].tag.value == tag) { + if (cpInfoList[i] != null && cpInfoList[i].tag.value == tag) { sb.append(String.format("
  • %d. %s
  • ", i, HTMLKit.escapeFilter(this.classFile.getCPDescription(i)))); } diff --git a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/MethodInfo.java b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/MethodInfo.java index 5a8ef95..99d92c1 100644 --- a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/MethodInfo.java +++ b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/MethodInfo.java @@ -32,7 +32,12 @@ * * VM Spec: Methods * + * + *
    + * java:S116 - Field names should comply with a naming convention --- We respect the name from JVM Spec instead
    + * 
    */ +@SuppressWarnings("java:S116") public class MethodInfo extends FileComponent { public final u2 access_flags; @@ -141,12 +146,12 @@ private void parse(final CPInfo[] cpInfo) throws FileFormatException { String parameters; try { - returnType = SignatureConvertor.MethodReturnTypeExtractor(this.descriptor).toString(); + returnType = SignatureConvertor.methodReturnTypeExtractor(this.descriptor).toString(); } catch (FileFormatException se) { returnType = String.format("[Unexpected method return type: %s]", this.descriptor); } try { - parameters = SignatureConvertor.MethodParameters2Readable(this.descriptor); + parameters = SignatureConvertor.methodParameters2Readable(this.descriptor); } catch (FileFormatException se) { parameters = String.format("[Unexpected method parameters: %s]", this.descriptor); } diff --git a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/Opcode.java b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/Opcode.java index fd54dea..30141dc 100755 --- a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/Opcode.java +++ b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/Opcode.java @@ -10,6 +10,7 @@ import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; +import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; import org.freeinternals.commonlib.core.BytesTool; @@ -24,7 +25,12 @@ * @see * VM * Spec: The Java Virtual Machine Instruction Set + * + *
    + * java:S116 - Field names should comply with a naming convention --- We respect the name from JVM Spec instead
    + * 
    */ +@SuppressWarnings("java:S116") public final class Opcode { private static final Logger LOG = Logger.getLogger(Opcode.class.getName()); @@ -48,9 +54,13 @@ private Opcode() { * * VM Spec: Instructions * + * + *
    +     * java:S115 - Constant names should comply with a naming convention --- We respect the name from JVM Spec instead
    +     * 
    */ - @SuppressWarnings("java:S115") // Constant names should comply with a naming convention --> We respect the name from JVM Spec instead - public static enum Instruction { + @SuppressWarnings("java:S115") + public enum Instruction { /** * Do nothing. @@ -223,7 +233,7 @@ protected InstructionParsed parse(final int curPos, final PosDataInputStream pdi iload(21) { @Override protected InstructionParsed parse(final int curPos, final PosDataInputStream pdis) throws IOException { - return super.parse_Lvindex_UnsignedByte(curPos, pdis); + return super.parseLvindexUnsignedByte(curPos, pdis); } }, /** @@ -237,7 +247,7 @@ protected InstructionParsed parse(final int curPos, final PosDataInputStream pdi lload(22) { @Override protected InstructionParsed parse(final int curPos, final PosDataInputStream pdis) throws IOException { - return super.parse_Lvindex_UnsignedByte(curPos, pdis); + return super.parseLvindexUnsignedByte(curPos, pdis); } }, /** @@ -251,7 +261,7 @@ protected InstructionParsed parse(final int curPos, final PosDataInputStream pdi fload(23) { @Override protected InstructionParsed parse(final int curPos, final PosDataInputStream pdis) throws IOException { - return super.parse_Lvindex_UnsignedByte(curPos, pdis); + return super.parseLvindexUnsignedByte(curPos, pdis); } }, /** @@ -265,7 +275,7 @@ protected InstructionParsed parse(final int curPos, final PosDataInputStream pdi dload(24) { @Override protected InstructionParsed parse(final int curPos, final PosDataInputStream pdis) throws IOException { - return super.parse_Lvindex_UnsignedByte(curPos, pdis); + return super.parseLvindexUnsignedByte(curPos, pdis); } }, /** @@ -279,7 +289,7 @@ protected InstructionParsed parse(final int curPos, final PosDataInputStream pdi aload(25) { @Override protected InstructionParsed parse(final int curPos, final PosDataInputStream pdis) throws IOException { - return super.parse_Lvindex_UnsignedByte(curPos, pdis); + return super.parseLvindexUnsignedByte(curPos, pdis); } }, /** @@ -530,7 +540,7 @@ protected InstructionParsed parse(final int curPos, final PosDataInputStream pdi istore(54) { @Override protected InstructionParsed parse(final int curPos, final PosDataInputStream pdis) throws IOException { - return super.parse_Lvindex_UnsignedByte(curPos, pdis); + return super.parseLvindexUnsignedByte(curPos, pdis); } }, /** @@ -546,7 +556,7 @@ protected InstructionParsed parse(final int curPos, final PosDataInputStream pdi lstore(55) { @Override protected InstructionParsed parse(final int curPos, final PosDataInputStream pdis) throws IOException { - return super.parse_Lvindex_UnsignedByte(curPos, pdis); + return super.parseLvindexUnsignedByte(curPos, pdis); } }, /** @@ -561,7 +571,7 @@ protected InstructionParsed parse(final int curPos, final PosDataInputStream pdi fstore(56) { @Override protected InstructionParsed parse(final int curPos, final PosDataInputStream pdis) throws IOException { - return super.parse_Lvindex_UnsignedByte(curPos, pdis); + return super.parseLvindexUnsignedByte(curPos, pdis); } }, /** @@ -578,7 +588,7 @@ protected InstructionParsed parse(final int curPos, final PosDataInputStream pdi dstore(57) { @Override protected InstructionParsed parse(final int curPos, final PosDataInputStream pdis) throws IOException { - return super.parse_Lvindex_UnsignedByte(curPos, pdis); + return super.parseLvindexUnsignedByte(curPos, pdis); } }, /** @@ -593,7 +603,7 @@ protected InstructionParsed parse(final int curPos, final PosDataInputStream pdi astore(58) { @Override protected InstructionParsed parse(final int curPos, final PosDataInputStream pdis) throws IOException { - return super.parse_Lvindex_UnsignedByte(curPos, pdis); + return super.parseLvindexUnsignedByte(curPos, pdis); } }, /** @@ -1317,85 +1327,85 @@ protected InstructionParsed parse(final int curPos, final PosDataInputStream pdi ifeq(153) { @Override protected InstructionParsed parse(final int curPos, final PosDataInputStream pdis) throws IOException { - return super.parse_Branchbyte_Short(curPos, pdis); + return super.parseBranchbyteShort(curPos, pdis); } }, ifne(154) { @Override protected InstructionParsed parse(final int curPos, final PosDataInputStream pdis) throws IOException { - return super.parse_Branchbyte_Short(curPos, pdis); + return super.parseBranchbyteShort(curPos, pdis); } }, iflt(155) { @Override protected InstructionParsed parse(final int curPos, final PosDataInputStream pdis) throws IOException { - return super.parse_Branchbyte_Short(curPos, pdis); + return super.parseBranchbyteShort(curPos, pdis); } }, ifge(156) { @Override protected InstructionParsed parse(final int curPos, final PosDataInputStream pdis) throws IOException { - return super.parse_Branchbyte_Short(curPos, pdis); + return super.parseBranchbyteShort(curPos, pdis); } }, ifgt(157) { @Override protected InstructionParsed parse(final int curPos, final PosDataInputStream pdis) throws IOException { - return super.parse_Branchbyte_Short(curPos, pdis); + return super.parseBranchbyteShort(curPos, pdis); } }, ifle(158) { @Override protected InstructionParsed parse(final int curPos, final PosDataInputStream pdis) throws IOException { - return super.parse_Branchbyte_Short(curPos, pdis); + return super.parseBranchbyteShort(curPos, pdis); } }, if_icmpeq(159) { @Override protected InstructionParsed parse(final int curPos, final PosDataInputStream pdis) throws IOException { - return super.parse_Branchbyte_Short(curPos, pdis); + return super.parseBranchbyteShort(curPos, pdis); } }, if_icmpne(160) { @Override protected InstructionParsed parse(final int curPos, final PosDataInputStream pdis) throws IOException { - return super.parse_Branchbyte_Short(curPos, pdis); + return super.parseBranchbyteShort(curPos, pdis); } }, if_icmplt(161) { @Override protected InstructionParsed parse(final int curPos, final PosDataInputStream pdis) throws IOException { - return super.parse_Branchbyte_Short(curPos, pdis); + return super.parseBranchbyteShort(curPos, pdis); } }, if_icmpge(162) { @Override protected InstructionParsed parse(final int curPos, final PosDataInputStream pdis) throws IOException { - return super.parse_Branchbyte_Short(curPos, pdis); + return super.parseBranchbyteShort(curPos, pdis); } }, if_icmpgt(163) { @Override protected InstructionParsed parse(final int curPos, final PosDataInputStream pdis) throws IOException { - return super.parse_Branchbyte_Short(curPos, pdis); + return super.parseBranchbyteShort(curPos, pdis); } }, if_icmple(164) { @Override protected InstructionParsed parse(final int curPos, final PosDataInputStream pdis) throws IOException { - return super.parse_Branchbyte_Short(curPos, pdis); + return super.parseBranchbyteShort(curPos, pdis); } }, if_acmpeq(165) { @Override protected InstructionParsed parse(final int curPos, final PosDataInputStream pdis) throws IOException { - return super.parse_Branchbyte_Short(curPos, pdis); + return super.parseBranchbyteShort(curPos, pdis); } }, if_acmpne(166) { @Override protected InstructionParsed parse(final int curPos, final PosDataInputStream pdis) throws IOException { - return super.parse_Branchbyte_Short(curPos, pdis); + return super.parseBranchbyteShort(curPos, pdis); } }, /** @@ -1421,7 +1431,7 @@ protected InstructionParsed parse(final int curPos, final PosDataInputStream pdi jsr(168) { @Override protected InstructionParsed parse(final int curPos, final PosDataInputStream pdis) throws IOException { - return super.parse_Branchbyte_Short(curPos, pdis); + return super.parseBranchbyteShort(curPos, pdis); } }, /** @@ -1436,7 +1446,7 @@ protected InstructionParsed parse(final int curPos, final PosDataInputStream pdi ret(169) { @Override protected InstructionParsed parse(final int curPos, final PosDataInputStream pdis) throws IOException { - return super.parse_Lvindex_UnsignedByte(curPos, pdis); + return super.parseLvindexUnsignedByte(curPos, pdis); } }, /** @@ -1557,7 +1567,7 @@ protected InstructionParsed parse(final int curPos, final PosDataInputStream pdi getstatic(178) { @Override protected InstructionParsed parse(final int curPos, final PosDataInputStream pdis) throws IOException { - return super.parse_Cpindex_UnsignedShort(curPos, pdis); + return super.parseCpindexUnsignedShort(curPos, pdis); } }, /** @@ -1570,7 +1580,7 @@ protected InstructionParsed parse(final int curPos, final PosDataInputStream pdi putstatic(179) { @Override protected InstructionParsed parse(final int curPos, final PosDataInputStream pdis) throws IOException { - return super.parse_Cpindex_UnsignedShort(curPos, pdis); + return super.parseCpindexUnsignedShort(curPos, pdis); } }, /** @@ -1579,7 +1589,7 @@ protected InstructionParsed parse(final int curPos, final PosDataInputStream pdi getfield(180) { @Override protected InstructionParsed parse(final int curPos, final PosDataInputStream pdis) throws IOException { - return super.parse_Cpindex_UnsignedShort(curPos, pdis); + return super.parseCpindexUnsignedShort(curPos, pdis); } }, /** @@ -1588,7 +1598,7 @@ protected InstructionParsed parse(final int curPos, final PosDataInputStream pdi putfield(181) { @Override protected InstructionParsed parse(final int curPos, final PosDataInputStream pdis) throws IOException { - return super.parse_Cpindex_UnsignedShort(curPos, pdis); + return super.parseCpindexUnsignedShort(curPos, pdis); } }, /** @@ -1597,7 +1607,7 @@ protected InstructionParsed parse(final int curPos, final PosDataInputStream pdi invokevirtual(182) { @Override protected InstructionParsed parse(final int curPos, final PosDataInputStream pdis) throws IOException { - return super.parse_Cpindex_UnsignedShort(curPos, pdis); + return super.parseCpindexUnsignedShort(curPos, pdis); } }, /** @@ -1607,7 +1617,7 @@ protected InstructionParsed parse(final int curPos, final PosDataInputStream pdi invokespecial(183) { @Override protected InstructionParsed parse(final int curPos, final PosDataInputStream pdis) throws IOException { - return super.parse_Cpindex_UnsignedShort(curPos, pdis); + return super.parseCpindexUnsignedShort(curPos, pdis); } }, /** @@ -1616,7 +1626,7 @@ protected InstructionParsed parse(final int curPos, final PosDataInputStream pdi invokestatic(184) { @Override protected InstructionParsed parse(final int curPos, final PosDataInputStream pdis) throws IOException { - return super.parse_Cpindex_UnsignedShort(curPos, pdis); + return super.parseCpindexUnsignedShort(curPos, pdis); } }, /** @@ -1692,7 +1702,7 @@ protected InstructionParsed parse(final int curPos, final PosDataInputStream pdi anewarray(189) { @Override protected InstructionParsed parse(final int curPos, final PosDataInputStream pdis) throws IOException { - return super.parse_Cpindex_UnsignedShort(curPos, pdis); + return super.parseCpindexUnsignedShort(curPos, pdis); } }, /** @@ -1709,7 +1719,7 @@ protected InstructionParsed parse(final int curPos, final PosDataInputStream pdi checkcast(192) { @Override protected InstructionParsed parse(final int curPos, final PosDataInputStream pdis) throws IOException { - return super.parse_Cpindex_UnsignedShort(curPos, pdis); + return super.parseCpindexUnsignedShort(curPos, pdis); } }, /** @@ -1753,22 +1763,6 @@ protected InstructionParsed parse(final int curPos, final PosDataInputStream pdi * Extend local variable index by additional bytes. */ wide(196) { - private List WIDE_SINGLE_OPCODES = new ArrayList() { - { - add(Opcode.Instruction.iload.code); - add(Opcode.Instruction.lload.code); - add(Opcode.Instruction.fload.code); - add(Opcode.Instruction.dload.code); - add(Opcode.Instruction.aload.code); - add(Opcode.Instruction.istore.code); - add(Opcode.Instruction.lstore.code); - add(Opcode.Instruction.fstore.code); - add(Opcode.Instruction.dstore.code); - add(Opcode.Instruction.astore.code); - add(Opcode.Instruction.ret.code); - } - }; - /** * The opcode with wide targets. */ @@ -1781,7 +1775,7 @@ protected InstructionParsed parse(final int curPos, final PosDataInputStream pdi parsed.isWide = true; String opCodeText; - if (this.WIDE_SINGLE_OPCODES.contains(wide_opcode)) { + if (WIDE_SINGLE_OPCODES.contains(wide_opcode)) { parsed.lvIndex = pdis.readUnsignedShort(); opCodeText = String.format(FORMAT_OPCODE_NUMBER, getWideName(Opcode.Instruction.valueOf(wide_opcode).name()), parsed.lvIndex); } else if (wide_opcode == Opcode.Instruction.iinc.code) { @@ -1889,6 +1883,20 @@ protected InstructionParsed parse(final int curPos, final PosDataInputStream pdi UNKNOWN(-1, true); public static final String OPCODE_NAME_RESERVED_PREFIX = "[Reserved] "; + private static final List WIDE_SINGLE_OPCODES = new ArrayList<>(); + static { + WIDE_SINGLE_OPCODES.add(Opcode.Instruction.iload.code); + WIDE_SINGLE_OPCODES.add(Opcode.Instruction.lload.code); + WIDE_SINGLE_OPCODES.add(Opcode.Instruction.fload.code); + WIDE_SINGLE_OPCODES.add(Opcode.Instruction.dload.code); + WIDE_SINGLE_OPCODES.add(Opcode.Instruction.aload.code); + WIDE_SINGLE_OPCODES.add(Opcode.Instruction.istore.code); + WIDE_SINGLE_OPCODES.add(Opcode.Instruction.lstore.code); + WIDE_SINGLE_OPCODES.add(Opcode.Instruction.fstore.code); + WIDE_SINGLE_OPCODES.add(Opcode.Instruction.dstore.code); + WIDE_SINGLE_OPCODES.add(Opcode.Instruction.astore.code); + WIDE_SINGLE_OPCODES.add(Opcode.Instruction.ret.code); + } /** * Internal code for an Instruction. @@ -1951,28 +1959,34 @@ public static Instruction valueOf(int opcode) { return result; } - @SuppressWarnings("java:S1172") // Unused method parameters should be removed --> `pdis` is used by children classes + /** + *
    +         * java:S1130 - "throws" declarations should not be superfluous --- The subclass throws IOException
    +         * java:S1172 - Unused method parameters should be removed --- `pdis` is used by children classes
    +         * 
    + */ + @SuppressWarnings({"java:S1130", "java:S1172"}) protected InstructionParsed parse(final int curPos, final PosDataInputStream pdis) throws IOException { InstructionParsed parsed = new InstructionParsed(curPos, this.code); parsed.opCodeText = this.name(); return parsed; } - private InstructionParsed parse_Branchbyte_Short(final int curPos, final PosDataInputStream pdis) throws IOException { + private InstructionParsed parseBranchbyteShort(final int curPos, final PosDataInputStream pdis) throws IOException { InstructionParsed parsed = new InstructionParsed(curPos, this.code); parsed.branchbyte = Integer.valueOf(pdis.readShort()); parsed.opCodeText = this.name(); return parsed; } - private InstructionParsed parse_Cpindex_UnsignedShort(final int curPos, final PosDataInputStream pdis) throws IOException { + private InstructionParsed parseCpindexUnsignedShort(final int curPos, final PosDataInputStream pdis) throws IOException { InstructionParsed parsed = new InstructionParsed(curPos, this.code); parsed.cpIndex = pdis.readUnsignedShort(); parsed.opCodeText = this.name(); return parsed; } - private InstructionParsed parse_Lvindex_UnsignedByte(final int curPos, final PosDataInputStream pdis) throws IOException { + private InstructionParsed parseLvindexUnsignedByte(final int curPos, final PosDataInputStream pdis) throws IOException { InstructionParsed parsed = new InstructionParsed(curPos, this.code); parsed.lvIndex = pdis.readUnsignedByte(); parsed.opCodeText = String.format(FORMAT_OPCODE_NUMBER, this.name(), parsed.lvIndex); @@ -2004,7 +2018,7 @@ private void skipPad(final PosDataInputStream pdis) throws IOException { * VM Spec: Table 6.5.newarray-A. Array type codes * */ - public static enum NewarrayType { + public enum NewarrayType { T_UNKNOWN(-1), T_BOOLEAN(4), @@ -2078,7 +2092,7 @@ public static class LookupSwitch { public final int defaultbyte; public final int npairs; - public final LinkedHashMap mapoffsets = new LinkedHashMap<>(); + public final Map mapoffsets = new LinkedHashMap<>(); LookupSwitch(int defaultByte, int nPairs) { this.defaultbyte = defaultByte; @@ -2088,7 +2102,7 @@ public static class LookupSwitch { public String toString(int currentOffset) { final StringBuilder sb = new StringBuilder(256); sb.append('(').append(this.npairs).append(" Pairs)"); - this.mapoffsets.keySet().forEach((key) -> { + this.mapoffsets.keySet().forEach(key -> { Integer value = this.mapoffsets.get(key); sb.append(String.format("%n case %d. jump to %d (relative offset = %d)", key, value + currentOffset, value)); }); @@ -2111,7 +2125,7 @@ public static class TableSwitch { public final int defaultbyte; public final int lowbyte; public final int highbyte; - public final LinkedHashMap jumpoffsets = new LinkedHashMap<>(); + public final Map jumpoffsets = new LinkedHashMap<>(); TableSwitch(int defaultByte, int lowByte, int highByte) { this.defaultbyte = defaultByte; @@ -2122,7 +2136,7 @@ public static class TableSwitch { public String toString(int currentOffset) { final StringBuilder sb = new StringBuilder(256); sb.append(" (from ").append(this.lowbyte).append(" to ").append(this.highbyte).append(')'); - this.jumpoffsets.keySet().forEach((key) -> { + this.jumpoffsets.keySet().forEach(key -> { Integer value = this.jumpoffsets.get(key); sb.append(String.format("%n case %d. jump to %d (relative offset = %d) ", key, value + currentOffset, value)); }); diff --git a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/SignatureConvertor.java b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/SignatureConvertor.java index fb878e6..ace7de1 100644 --- a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/SignatureConvertor.java +++ b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/SignatureConvertor.java @@ -21,8 +21,13 @@ * * VM Spec: The Internal Form of Names * + * + *
    + * java:S116 - Field names should comply with a naming convention --- We respect the name from JVM Spec instead
    + * 
    */ -final public class SignatureConvertor { +@SuppressWarnings("java:S116") +public final class SignatureConvertor { /** * @@ -67,7 +72,7 @@ private SignatureConvertor() { * VM Spec: Method Descriptors * */ - public static SignatureResult MethodReturnTypeExtractor(final String signature) + public static SignatureResult methodReturnTypeExtractor(final String signature) throws FileFormatException { if (signature == null) { throw new IllegalArgumentException("'signature' should not be null."); @@ -86,7 +91,7 @@ public static SignatureResult MethodReturnTypeExtractor(final String signature) if ("V".equals(returnType)) { returnValue = new SignatureResult(0, returnType, JavaLangSpec.Keyword.VOID.text); } else { - returnValue = SignatureConvertor.FieldDescriptorExtractor(returnType); + returnValue = SignatureConvertor.fieldDescriptorExtractor(returnType); } return returnValue; @@ -104,9 +109,9 @@ public static SignatureResult MethodReturnTypeExtractor(final String signature) * @return Java Language Specification (JLS) format of parameters * @throws FileFormatException Invalid signature string found */ - public static String MethodParameters2Readable(final String signature) + public static String methodParameters2Readable(final String signature) throws FileFormatException { - List paramters = MethodParametersSplit(signature); + List paramters = methodParametersSplit(signature); StringBuilder result = new StringBuilder(); result.append(METHODDESCRIPTOR_LEFT); @@ -125,7 +130,7 @@ public static String MethodParameters2Readable(final String signature) } // (com/sun/java/accessibility/AccessBridge;Ljavax/accessibility/AccessibleContext;)V - public static List MethodParametersSplit(final String signature) + public static List methodParametersSplit(final String signature) throws FileFormatException { // check parameter if (signature == null) { @@ -173,9 +178,9 @@ public static List MethodParametersSplit(final String signature } } - if (parameters.size() > 0) { + if (!parameters.isEmpty()) { for (String s : parameters) { - parametersResult.add(FieldDescriptorExtractor(s)); + parametersResult.add(fieldDescriptorExtractor(s)); } } @@ -199,7 +204,7 @@ public static List MethodParametersSplit(final String signature * VM Spec: Field Descriptors * */ - public static SignatureResult FieldDescriptorExtractor(final String signature) + public static SignatureResult fieldDescriptorExtractor(final String signature) throws FileFormatException { if ((signature == null) || signature.isEmpty()) { @@ -224,7 +229,7 @@ public static SignatureResult FieldDescriptorExtractor(final String signature) sig = sig.substring(1, sigLength - 1); } - sigJls = ParseClassSignature(sig); + sigJls = parseClassSignature(sig); } return new SignatureResult(arrayCount, sig, sigJls); @@ -241,7 +246,7 @@ public static SignatureResult FieldDescriptorExtractor(final String signature) * @param classSignature JVM internal format of class signature * @return Java Language Specification (JLS) format of class signature */ - public static String ParseClassSignature(final String classSignature) + public static String parseClassSignature(final String classSignature) throws IllegalArgumentException { if (classSignature == null) { throw new IllegalArgumentException("'ClassSignature' should not be null."); @@ -256,7 +261,7 @@ public static String ParseClassSignature(final String classSignature) * @param classSignature JVM internal format of class signature * @return Package name of class signature, or null if the class not in any package */ - public static String ParsePackage(final String classSignature){ + public static String parsePackage(final String classSignature){ if (classSignature == null) { throw new IllegalArgumentException("'ClassSignature' should not be null."); } @@ -265,7 +270,7 @@ public static String ParsePackage(final String classSignature){ if (lastIndex == -1) { return null; } else { - return SignatureConvertor.ParseClassSignature(classSignature.substring(0, lastIndex)).toLowerCase(); + return SignatureConvertor.parseClassSignature(classSignature.substring(0, lastIndex)).toLowerCase(); } } @@ -293,7 +298,7 @@ public static class SignatureResult { this.ArrayDimension = count; this.TypeBinaryName = bin; this.TypeJLSName = jls; - this.TypePackage = ParsePackage(bin); + this.TypePackage = parsePackage(bin); } /** diff --git a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/Annotation.java b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/Annotation.java index 60212d5..3ceb540 100644 --- a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/Annotation.java +++ b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/Annotation.java @@ -31,8 +31,13 @@ * href="https://docs.oracle.com/javase/specs/jvms/se12/html/jvms-4.html#jvms-4.7.16"> * VM Spec: annotation structure * + * + *
    + * java:S1104 - Class variable fields should not have public accessibility --- No, we like the simplified final value manner
    + * java:S116  - Field names should comply with a naming convention --- We respect the name from JVM Spec instead
    + * 
    */ -@SuppressWarnings("java:S116") // Class variable fields should not have public accessibility --> No, we like the simplifed final value manner +@SuppressWarnings({"java:S1104", "java:S116"}) public class Annotation extends FileComponent { public u2 type_index; @@ -99,19 +104,19 @@ protected static void generateSubnode(final DefaultMutableTreeNode rootNode, fin "const_value_index: " + constValueIndex + " - " + classFile.getCPDescription(constValueIndex) ))); } else if (elementValue.union_enum_const_value != null) { - int cp_index = elementValue.union_enum_const_value.type_name_index.value; + int cpIndex = elementValue.union_enum_const_value.type_name_index.value; rootNode.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent( startPosMoving, u2.LENGTH, - "type_name_index: " + cp_index + " - " + classFile.getCPDescription(cp_index) + "type_name_index: " + cpIndex + " - " + classFile.getCPDescription(cpIndex) ))); startPosMoving += u2.LENGTH; - cp_index = elementValue.union_enum_const_value.const_name_index.value; + cpIndex = elementValue.union_enum_const_value.const_name_index.value; rootNode.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent( startPosMoving, u2.LENGTH, - "const_name_index: " + cp_index + " - " + classFile.getCPDescription(cp_index) + "const_name_index: " + cpIndex + " - " + classFile.getCPDescription(cpIndex) ))); } else if (elementValue.union_class_info_index != null) { int classInfoIndex = elementValue.union_class_info_index.value; @@ -123,11 +128,11 @@ protected static void generateSubnode(final DefaultMutableTreeNode rootNode, fin } else if (elementValue.union_annotation_value != null) { generateSubnode(rootNode, elementValue.union_annotation_value, classFile); } else if (elementValue.union_array_value != null) { - int num_values = elementValue.union_array_value.num_values.value; + int numValues = elementValue.union_array_value.num_values.value; rootNode.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent( startPosMoving, u2.LENGTH, - "num_values: " + num_values + "num_values: " + numValues ))); startPosMoving += u2.LENGTH; @@ -136,7 +141,7 @@ protected static void generateSubnode(final DefaultMutableTreeNode rootNode, fin DefaultMutableTreeNode values = new DefaultMutableTreeNode(new JTreeNodeFileComponent( startPosMoving, elementValue.getLength() - 3, - "values: " + num_values + "values: " + numValues )); rootNode.add(values); @@ -196,23 +201,23 @@ protected static void generateSubnode(final DefaultMutableTreeNode rootNode, fin currentPos += u2.LENGTH; if (a.num_element_value_pairs.value > 0) { - DefaultMutableTreeNode element_value_pairs = new DefaultMutableTreeNode(new JTreeNodeFileComponent( + DefaultMutableTreeNode elementValuePairs = new DefaultMutableTreeNode(new JTreeNodeFileComponent( currentPos, a.getStartPos() + a.getLength() - currentPos, "element_value_pairs" )); - rootNode.add(element_value_pairs); + rootNode.add(elementValuePairs); for (int i = 0; i < a.num_element_value_pairs.value; i++) { Annotation.ElementValuePair pair = a.getElementvaluePair(i); - DefaultMutableTreeNode element_value_pair_node = new DefaultMutableTreeNode(new JTreeNodeFileComponent( + DefaultMutableTreeNode elementValuePairNode = new DefaultMutableTreeNode(new JTreeNodeFileComponent( pair.getStartPos(), pair.getLength(), String.format("element_value_pair %d", i + 1) )); - element_value_pairs.add(element_value_pair_node); + elementValuePairs.add(elementValuePairNode); - generateSubnode(element_value_pair_node, pair, classFile); + generateSubnode(elementValuePairNode, pair, classFile); } } } @@ -384,8 +389,12 @@ protected ElementValue(final PosDataInputStream posDataInputStream) throws IOExc * * VM Spec: The element_value structure * + * + *
    +         * java:S115 - Constant names should comply with a naming convention --- We respect the name from JVM Spec instead
    +         * 
    */ - @SuppressWarnings("java:S115") // Constant names should comply with a naming convention --> We respect the name from JVM Spec instead + @SuppressWarnings("java:S115") public enum TagEnum { /** diff --git a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeAnnotationDefault.java b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeAnnotationDefault.java index 58d96c4..a04ab93 100644 --- a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeAnnotationDefault.java +++ b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeAnnotationDefault.java @@ -37,7 +37,12 @@ * href="https://docs.oracle.com/javase/specs/jvms/se12/html/jvms-4.html#jvms-4.7.22"> * VM Spec: The AnnotationDefault attribute * + * + *
    + * java:S116 - Field names should comply with a naming convention --- We respect the name from JVM Spec instead
    + * 
    */ +@SuppressWarnings("java:S116") public class AttributeAnnotationDefault extends AttributeInfo { /** @@ -55,13 +60,13 @@ public class AttributeAnnotationDefault extends AttributeInfo { @Override public void generateTreeNode(DefaultMutableTreeNode parentNode, ClassFile classFile) { - DefaultMutableTreeNode default_value_node = new DefaultMutableTreeNode(new JTreeNodeFileComponent( + DefaultMutableTreeNode defaultValueNode = new DefaultMutableTreeNode(new JTreeNodeFileComponent( super.startPos + 6, this.getLength() - 6, "default_value" )); - parentNode.add(default_value_node); + parentNode.add(defaultValueNode); - Annotation.generateSubnode(default_value_node, this.default_value, classFile); + Annotation.generateSubnode(defaultValueNode, this.default_value, classFile); } } diff --git a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeBootstrapMethods.java b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeBootstrapMethods.java index f5a7067..e3cec46 100644 --- a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeBootstrapMethods.java +++ b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeBootstrapMethods.java @@ -28,8 +28,12 @@ * href="https://docs.oracle.com/javase/specs/jvms/se12/html/jvms-4.html#jvms-4.7.23"> * VM Spec: The BootstrapMethods Attribute * + * + *
    + * java:S116 - Field names should comply with a naming convention --- We respect the name from JVM Spec instead
    + * 
    */ -@SuppressWarnings("java:S116") // Class variable fields should not have public accessibility --> No, we like the simplifed final value manner +@SuppressWarnings("java:S116") public class AttributeBootstrapMethods extends AttributeInfo { /** @@ -73,21 +77,21 @@ public void generateTreeNode(DefaultMutableTreeNode parentNode, final ClassFile ))); if (this.bootstrap_methods != null && this.bootstrap_methods.length > 0) { - DefaultMutableTreeNode bootstrap_methods_node = new DefaultMutableTreeNode(new JTreeNodeFileComponent( + DefaultMutableTreeNode bootstrapMethodsNode = new DefaultMutableTreeNode(new JTreeNodeFileComponent( startPosMoving + 8, this.getLength() - 8, "bootstrap_methods")); - parentNode.add(bootstrap_methods_node); + parentNode.add(bootstrapMethodsNode); for (int i = 0; i < this.bootstrap_methods.length; i++) { BootstrapMethod m = this.bootstrap_methods[i]; - DefaultMutableTreeNode bootstrap_method = new DefaultMutableTreeNode(new JTreeNodeFileComponent( + DefaultMutableTreeNode bootstrapMethod = new DefaultMutableTreeNode(new JTreeNodeFileComponent( m.getStartPos(), m.getLength(), String.format("bootstrap_method %d", i + 1) )); - bootstrap_methods_node.add(bootstrap_method); - this.generateSubnode(bootstrap_method, m, classFile); + bootstrapMethodsNode.add(bootstrapMethod); + this.generateSubnode(bootstrapMethod, m, classFile); } } } @@ -114,20 +118,20 @@ private void generateSubnode(final DefaultMutableTreeNode rootNode, final Bootst startPosMoving += u2.LENGTH; if (m.bootstrap_arguments != null && m.bootstrap_arguments.length > 0) { - DefaultMutableTreeNode bootstrap_arguments = new DefaultMutableTreeNode(new JTreeNodeFileComponent( + DefaultMutableTreeNode bootstrapArguments = new DefaultMutableTreeNode(new JTreeNodeFileComponent( startPosMoving, m.bootstrap_arguments.length * u2.LENGTH, "bootstrap_arguments")); - rootNode.add(bootstrap_arguments); + rootNode.add(bootstrapArguments); for (int i = 0; i < m.bootstrap_arguments.length; i++) { - DefaultMutableTreeNode bootstrap_method = new DefaultMutableTreeNode(new JTreeNodeFileComponent( + DefaultMutableTreeNode bootstrapMethod = new DefaultMutableTreeNode(new JTreeNodeFileComponent( startPosMoving, u2.LENGTH, "argument " + (i + 1) + ": " + m.bootstrap_arguments[i].value + " - " + classFile.getCPDescription(m.bootstrap_arguments[i].value) )); startPosMoving += u2.LENGTH; - bootstrap_arguments.add(bootstrap_method); + bootstrapArguments.add(bootstrapMethod); } } } diff --git a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeCode.java b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeCode.java index e6293ea..abc6d6a 100644 --- a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeCode.java +++ b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeCode.java @@ -53,7 +53,13 @@ * * VM Spec: The Code Attribute * + * + *
    + * java:S1104 - Class variable fields should not have public accessibility --- No, we like the simplified final value manner
    + * java:S116  - Field names should comply with a naming convention --- We respect the name from JVM Spec instead
    + * 
    */ +@SuppressWarnings({"java:S1104", "java:S116"}) public class AttributeCode extends AttributeInfo { public static final String ATTRIBUTE_CODE_NODE = "code"; @@ -266,11 +272,11 @@ private void generateSubnode(final DefaultMutableTreeNode rootNode, final Attrib "handler_pc: " + et.handler_pc.value ))); final int catch_type = et.catch_type.value; - String catch_type_desc = (catch_type == 0) ? "" : " - " + classFile.getCPDescription(catch_type); + String catchTypeDesc = (catch_type == 0) ? "" : " - " + classFile.getCPDescription(catch_type); rootNode.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent( startPosMoving + 6, 2, - "catch_type: " + catch_type + catch_type_desc + "catch_type: " + catch_type + catchTypeDesc ))); } diff --git a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeConstantValue.java b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeConstantValue.java index fabac20..9b6718f 100644 --- a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeConstantValue.java +++ b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeConstantValue.java @@ -34,7 +34,12 @@ * * VM Spec: The ConstantValue Attribute * + * + *
    + * java:S116 - Field names should comply with a naming convention --- We respect the name from JVM Spec instead
    + * 
    */ +@SuppressWarnings("java:S116") public class AttributeConstantValue extends AttributeInfo { /** diff --git a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeEnclosingMethod.java b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeEnclosingMethod.java index 678fa13..efe95d5 100644 --- a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeEnclosingMethod.java +++ b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeEnclosingMethod.java @@ -27,7 +27,12 @@ * href="https://docs.oracle.com/javase/specs/jvms/se12/html/jvms-4.html#jvms-4.7.7"> * VM Spec: The EnclosingMethod Attribute * + * + *
    + * java:S116 - Field names should comply with a naming convention --- We respect the name from JVM Spec instead
    + * 
    */ +@SuppressWarnings("java:S116") public class AttributeEnclosingMethod extends AttributeInfo { /** diff --git a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeExceptions.java b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeExceptions.java index 533d6f7..f2a1fff 100644 --- a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeExceptions.java +++ b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeExceptions.java @@ -35,7 +35,12 @@ * * VM Spec: The Exceptions Attribute * + * + *
    + * java:S116 - Field names should comply with a naming convention --- We respect the name from JVM Spec instead
    + * 
    */ +@SuppressWarnings("java:S116") public class AttributeExceptions extends AttributeInfo { /** @@ -103,11 +108,11 @@ public void generateTreeNode(DefaultMutableTreeNode parentNode, ClassFile classF "exceptions")); for (i = 0; i < numOfExceptions; i++) { - int cp_index = this.getExceptionIndexTableItem(i); + int cpIndex = this.getExceptionIndexTableItem(i); treeNodeExceptions.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent( startPos + 10 + i * 2, 2, - String.format("exception_index_table[%d]: cp_index=%d - %s", i, cp_index, classFile.getCPDescription(cp_index)) + String.format("exception_index_table[%d]: cp_index=%d - %s", i, cpIndex, classFile.getCPDescription(cpIndex)) ))); } diff --git a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeInfo.java b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeInfo.java index b814b75..1ec3d50 100644 --- a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeInfo.java +++ b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeInfo.java @@ -44,7 +44,12 @@ * * VM Spec: Attributes * + * + *
    + * java:S116 - Field names should comply with a naming convention --- We respect the name from JVM Spec instead
    + * 
    */ +@SuppressWarnings("java:S116") public abstract class AttributeInfo extends FileComponent implements GenerateClassfileTreeNode { private static final Logger LOG = Logger.getLogger(AttributeInfo.class.getName()); @@ -110,8 +115,12 @@ public abstract class AttributeInfo extends FileComponent implements GenerateCla * @throws java.io.IOException Input Stream read fail * @throws org.freeinternals.commonlib.core.FileFormatException Class file format * error + * + *
    +     * java:S3776 - Cognitive Complexity of methods should not be too high --- No, it is not high
    +     * 
    */ - @SuppressWarnings("java:S3776") // Cognitive Complexity of methods should not be too high --> No, it is not high + @SuppressWarnings("java:S3776") public static AttributeInfo parse(final PosDataInputStream posDataInputStream, final CPInfo[] cp) throws IOException, FileFormatException { AttributeInfo attr = null; @@ -123,7 +132,7 @@ public static AttributeInfo parse(final PosDataInputStream posDataInputStream, f for (AttributeTypes attrType : AttributeTypes.values()) { if (attrType.name().equals(type) && attrType.clazz != null) { // There is only 1 constructor in the JVM Attributes - Constructor cons = attrType.clazz.getDeclaredConstructors()[0]; + Constructor cons = attrType.clazz.getDeclaredConstructors()[0]; try { switch (cons.getParameterCount()) { @@ -144,7 +153,7 @@ public static AttributeInfo parse(final PosDataInputStream posDataInputStream, f } } } - if (matched == false) { + if (!matched) { LOG.log(Level.WARNING, "Un-recognized Attribute Found !!! Type = {0}", type); attr = new AttributeUnrecognized(attrNameIndex, UNRECOGNIZED + type, posDataInputStream); } @@ -188,24 +197,24 @@ public String getName() { return (this.name != null) ? this.name : ""; } - public static void generateTreeNode(final DefaultMutableTreeNode rootNode, final AttributeInfo attribute_info, final ClassFile classFile) { - if (attribute_info == null) { + public static void generateTreeNode(final DefaultMutableTreeNode rootNode, final AttributeInfo attributeInfo, final ClassFile classFile) { + if (attributeInfo == null) { return; } - int startPosMoving = attribute_info.getStartPos(); + int startPosMoving = attributeInfo.getStartPos(); rootNode.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent( startPosMoving, u2.LENGTH, - "attribute_name_index: " + attribute_info.attribute_name_index.value + ", name=" + attribute_info.getName()))); + "attribute_name_index: " + attributeInfo.attribute_name_index.value + ", name=" + attributeInfo.getName()))); startPosMoving += u2.LENGTH; rootNode.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent( startPosMoving, u4.LENGTH, - "attribute_length: " + attribute_info.attribute_length.value))); + "attribute_length: " + attributeInfo.attribute_length.value))); - attribute_info.generateTreeNode(rootNode, classFile); + attributeInfo.generateTreeNode(rootNode, classFile); } @@ -215,8 +224,12 @@ public static void generateTreeNode(final DefaultMutableTreeNode rootNode, final * @see * * VM Spec: Attributes + * + *
    +     * java:S115 - Constant names should comply with a naming convention --- We respect the name from JVM Spec instead
    +     * 
    */ - @SuppressWarnings("java:S115") // Constant names should comply with a naming convention --> We respect the name from JVM Spec instead + @SuppressWarnings("java:S115") public enum AttributeTypes { /** @@ -503,7 +516,7 @@ public enum AttributeTypes { */ final Class clazz; - AttributeTypes(Class clazz) { + AttributeTypes(Class clazz) { this.clazz = clazz; } diff --git a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeInnerClasses.java b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeInnerClasses.java index 1a063c4..1f392de 100644 --- a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeInnerClasses.java +++ b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeInnerClasses.java @@ -41,7 +41,12 @@ * * VM Spec: The InnerClasses Attribute * + * + *
    + * java:S116 - Field names should comply with a naming convention --- We respect the name from JVM Spec instead
    + * 
    */ +@SuppressWarnings("java:S116") public class AttributeInnerClasses extends AttributeInfo { public final u2 number_of_classes; @@ -116,27 +121,27 @@ public void generateTreeNode(DefaultMutableTreeNode parentNode, final ClassFile private void generateSubnode(final DefaultMutableTreeNode rootNode, final AttributeInnerClasses.Class innerClass, final ClassFile classFile) { final int startPosMoving = innerClass.getStartPos(); - int cp_index = innerClass.inner_class_info_index.value; + int cpIndex = innerClass.inner_class_info_index.value; rootNode.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent( startPosMoving, 2, - "inner_class_info_index: " + cp_index + " - " + classFile.getCPDescription(cp_index) + "inner_class_info_index: " + cpIndex + " - " + classFile.getCPDescription(cpIndex) ))); - cp_index = innerClass.outer_class_info_index.value; - final String outer_class_info_index_desc = (cp_index == 0) ? "" : " - " + classFile.getCPDescription(cp_index); + cpIndex = innerClass.outer_class_info_index.value; + final String outer_class_info_index_desc = (cpIndex == 0) ? "" : " - " + classFile.getCPDescription(cpIndex); rootNode.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent( startPosMoving + 2, 2, - "outer_class_info_index: " + cp_index + outer_class_info_index_desc + "outer_class_info_index: " + cpIndex + outer_class_info_index_desc ))); - cp_index = innerClass.inner_name_index.value; - final String inner_name_index_desc = (cp_index == 0) ? "" : " - " + classFile.getCPDescription(cp_index); + cpIndex = innerClass.inner_name_index.value; + final String inner_name_index_desc = (cpIndex == 0) ? "" : " - " + classFile.getCPDescription(cpIndex); rootNode.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent( startPosMoving + 4, 2, - "inner_name_index: " + cp_index + inner_name_index_desc + "inner_name_index: " + cpIndex + inner_name_index_desc ))); rootNode.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent( diff --git a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeLineNumberTable.java b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeLineNumberTable.java index 4c86072..c40389f 100644 --- a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeLineNumberTable.java +++ b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeLineNumberTable.java @@ -38,7 +38,12 @@ * * VM Spec: The LineNumberTable Attribute * + * + *
    + * java:S116 - Field names should comply with a naming convention --- We respect the name from JVM Spec instead
    + * 
    */ +@SuppressWarnings("java:S116") public class AttributeLineNumberTable extends AttributeInfo { public final u2 line_number_table_length; diff --git a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeLocalVariableTable.java b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeLocalVariableTable.java index d7dcf2a..1ae448f 100644 --- a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeLocalVariableTable.java +++ b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeLocalVariableTable.java @@ -41,7 +41,12 @@ * * VM Spec: The LocalVariableTable Attribute * + * + *
    + * java:S116 - Field names should comply with a naming convention --- We respect the name from JVM Spec instead
    + * 
    */ +@SuppressWarnings("java:S116") public class AttributeLocalVariableTable extends AttributeInfo { public final u2 local_variable_table_length; @@ -119,7 +124,7 @@ private void generateSubnode(final DefaultMutableTreeNode rootNode, final Attrib } final int pos = lvt.getStartPos(); - int cp_index; + int cpIndex; rootNode.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent( pos, @@ -131,17 +136,17 @@ private void generateSubnode(final DefaultMutableTreeNode rootNode, final Attrib 2, "length: " + lvt.length_code.value ))); - cp_index = lvt.name_index.value; + cpIndex = lvt.name_index.value; rootNode.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent( pos + 4, 2, - String.format("name_index: %d - %s", cp_index, classFile.getCPDescription(cp_index)) + String.format("name_index: %d - %s", cpIndex, classFile.getCPDescription(cpIndex)) ))); - cp_index = lvt.descriptor_index.value; + cpIndex = lvt.descriptor_index.value; rootNode.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent( pos + 6, 2, - String.format("descriptor_index: %d - %s", cp_index, classFile.getCPDescription(cp_index)) + String.format("descriptor_index: %d - %s", cpIndex, classFile.getCPDescription(cpIndex)) ))); rootNode.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent( pos + 8, @@ -160,7 +165,7 @@ private void generateSubnode(final DefaultMutableTreeNode rootNode, final Attrib */ public static final class LocalVariableTable extends FileComponent { - public final static int LENGTH = 10; + public static final int LENGTH = 10; /** * The given local variable must have a value at indices into the * {@link AttributeCode#code} array in the interval diff --git a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeLocalVariableTypeTable.java b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeLocalVariableTypeTable.java index ecafffc..5b3086c 100644 --- a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeLocalVariableTypeTable.java +++ b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeLocalVariableTypeTable.java @@ -45,7 +45,12 @@ * href="https://docs.oracle.com/javase/specs/jvms/se12/html/jvms-4.html#jvms-4.7.14"> * VM Spec: The LocalVariableTypeTable Attribute * + * + *
    + * java:S116 - Field names should comply with a naming convention --- We respect the name from JVM Spec instead
    + * 
    */ +@SuppressWarnings("java:S116") public class AttributeLocalVariableTypeTable extends AttributeInfo { /** @@ -85,45 +90,45 @@ public void generateTreeNode(DefaultMutableTreeNode parentNode, ClassFile classF ))); if (this.local_variable_type_table_length.value > 0) { - DefaultMutableTreeNode lvtt_nodes = new DefaultMutableTreeNode(new JTreeNodeFileComponent( + DefaultMutableTreeNode lvttNodes = new DefaultMutableTreeNode(new JTreeNodeFileComponent( super.startPos + 8, this.local_variable_type_table_length.value * LocalVariableTypeTable.LENGTH, "local_variable_type_table" )); - parentNode.add(lvtt_nodes); + parentNode.add(lvttNodes); for (int i = 0; i < this.local_variable_type_table_length.value; i++) { LocalVariableTypeTable item = this.local_variable_type_table[i]; - int item_startPos = item.getStartPos(); - DefaultMutableTreeNode lvtt_node = new DefaultMutableTreeNode(new JTreeNodeFileComponent( - item_startPos, + int itemStartPos = item.getStartPos(); + DefaultMutableTreeNode lvttNode = new DefaultMutableTreeNode(new JTreeNodeFileComponent( + itemStartPos, item.getLength(), "local_variable_type_table " + (i + 1) )); - lvtt_nodes.add(lvtt_node); + lvttNodes.add(lvttNode); - lvtt_node.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent( - item_startPos, + lvttNode.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent( + itemStartPos, 2, "start_pc: " + item.start_pc.value ))); - lvtt_node.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent( - item_startPos + 2, + lvttNode.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent( + itemStartPos + 2, 2, "length: " + item.lvtt_length.value ))); - lvtt_node.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent( - item_startPos + 4, + lvttNode.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent( + itemStartPos + 4, 2, "signature_index: " + item.signature_index.value + " - " + classFile.getCPDescription(item.signature_index.value) ))); - lvtt_node.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent( - item_startPos + 6, + lvttNode.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent( + itemStartPos + 6, 2, "name_index: " + item.name_index.value + " - " + classFile.getCPDescription(item.name_index.value) ))); - lvtt_node.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent( - item_startPos + 8, + lvttNode.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent( + itemStartPos + 8, 2, "index: " + item.index.value ))); @@ -138,7 +143,7 @@ public void generateTreeNode(DefaultMutableTreeNode parentNode, ClassFile classF * which that local variable can be found. Each entry must contain the * following five items (the 5 instance fields of current class). */ - public final static class LocalVariableTypeTable extends FileComponent { + public static final class LocalVariableTypeTable extends FileComponent { public static final int LENGTH = 10; public final u2 start_pc; diff --git a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeMethodParameters.java b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeMethodParameters.java index 2ec1390..8be22e9 100644 --- a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeMethodParameters.java +++ b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeMethodParameters.java @@ -47,7 +47,12 @@ * * VM Spec: The MethodParameters Attribute * + * + *
    + * java:S116 - Field names should comply with a naming convention --- We respect the name from JVM Spec instead
    + * 
    */ +@SuppressWarnings("java:S116") public class AttributeMethodParameters extends AttributeInfo { /** @@ -123,7 +128,7 @@ public void generateTreeNode(DefaultMutableTreeNode parentNode, ClassFile classF } } - public final static class Parameter extends FileComponent { + public static final class Parameter extends FileComponent { /** * The value of the name_index item must either be zero or a valid index diff --git a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeModule.java b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeModule.java index ceb8202..912a3d1 100644 --- a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeModule.java +++ b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeModule.java @@ -72,9 +72,14 @@ * @see * * VM Spec: The Module Attribute + * + *
    + * java:S116 - Field names should comply with a naming convention --- We respect the name from JVM Spec instead
    + * 
    */ +@SuppressWarnings("java:S116") public class AttributeModule extends AttributeInfo { - private final String MESSAGE_ETI = "exports_to_index["; + private static final String MESSAGE_ETI = "exports_to_index["; public final u2 module_name_index; public final u2 module_flags; @@ -95,7 +100,12 @@ public class AttributeModule extends AttributeInfo { public final u2 provides_count; public final Provides[] provides; - @SuppressWarnings("java:S3776") // Cognitive Complexity of methods should not be too high --> No, it is not high + /** + *
    +     * java:S3776 - Cognitive Complexity of methods should not be too high --- No, it is not high
    +     * 
    + */ + @SuppressWarnings("java:S3776") AttributeModule(final u2 nameIndex, final String type, final PosDataInputStream posDataInputStream) throws IOException, FileFormatException { super(nameIndex, type, posDataInputStream, ClassFile.Version.FORMAT_53_0, JavaSEVersion.VERSION_9); @@ -171,8 +181,16 @@ public String getModuleFlags() { return AccessFlag.getModifier(this.module_flags.value, AccessFlag.ForModule); } + /** + * @param parentNode Parent JTree node + * @param classFile Current class file object + * + *
    +     * java:S3776 - Cognitive Complexity of methods should not be too high --- No, it is not high
    +     * 
    + */ @Override - @SuppressWarnings("java:S3776") // Cognitive Complexity of methods should not be too high --> No, it is not high + @SuppressWarnings("java:S3776") public void generateTreeNode(DefaultMutableTreeNode parentNode, final ClassFile classFile) { int startPosMoving = super.startPos + 6; @@ -194,14 +212,14 @@ public void generateTreeNode(DefaultMutableTreeNode parentNode, final ClassFile startPosMoving += u2.LENGTH; // module_version_index - String module_version = (this.module_version_index.value == 0) + String moduleVersion = (this.module_version_index.value == 0) ? "no version information" : classFile.getCPDescription(this.module_version_index.value); parentNode.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent( startPosMoving, u2.LENGTH, - "module_version_index: " + this.module_version_index.value + " - " + module_version + "module_version_index: " + this.module_version_index.value + " - " + moduleVersion ))); startPosMoving += u2.LENGTH; @@ -490,7 +508,7 @@ private void generateSubnode(final DefaultMutableTreeNode rootNode, final Attrib int startPosMoving = require.getStartPos(); // requires_version_index - String requires_version_index = (require.requires_version_index.value == 0) + String requiresVersionIndex = (require.requires_version_index.value == 0) ? "no version information" : classFile.getCPDescription(require.requires_version_index.value); @@ -511,7 +529,7 @@ private void generateSubnode(final DefaultMutableTreeNode rootNode, final Attrib rootNode.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent( startPosMoving, u2.LENGTH, - "requires_version_index: " + require.requires_version_index.value + " - " + requires_version_index + "requires_version_index: " + require.requires_version_index.value + " - " + requiresVersionIndex ))); } @@ -522,7 +540,7 @@ private void generateSubnode(final DefaultMutableTreeNode rootNode, final Attrib * @since Java 9 * @see Module */ - public final static class Requires extends FileComponent { + public static final class Requires extends FileComponent { public static final int LENGTH = 6; public final u2 requires_index; @@ -556,7 +574,7 @@ public String getRequiresFlags() { * @since Java 9 * @see Module */ - public final static class Exports extends FileComponent { + public static final class Exports extends FileComponent { public final u2 exports_index; public final u2 exports_flags; @@ -598,7 +616,7 @@ public String getExportFlags() { * @since Java 9 * @see Module */ - public final static class Opens extends FileComponent { + public static final class Opens extends FileComponent { public final u2 opens_index; public final u2 opens_flags; @@ -640,7 +658,7 @@ public String getOpenFlags() { * @since Java 9 * @see Module */ - public final static class Provides extends FileComponent { + public static final class Provides extends FileComponent { public final u2 provides_index; public final u2 provides_with_count; diff --git a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeModuleHashes.java b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeModuleHashes.java index b1fc64d..9b9e02a 100644 --- a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeModuleHashes.java +++ b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeModuleHashes.java @@ -48,7 +48,12 @@ * @see * * ModuleHashes attribute. + * + *
    + * java:S116 - Field names should comply with a naming convention --- We respect the name from JVM Spec instead
    + * 
    */ +@SuppressWarnings("java:S116") public class AttributeModuleHashes extends AttributeInfo { /** @@ -152,7 +157,7 @@ private void generateSubnode(final DefaultMutableTreeNode rootNode, final Attrib * @since OpenJDK 9 * @see Module */ - public final static class Hashes extends FileComponent { + public static final class Hashes extends FileComponent { /** * Index to CONSTANT_Module_info structure. diff --git a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeModuleMainClass.java b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeModuleMainClass.java index db61de5..fbf21af 100644 --- a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeModuleMainClass.java +++ b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeModuleMainClass.java @@ -34,7 +34,12 @@ * * VM Spec: The ModuleMainClass Attribute * + * + *
    + * java:S116 - Field names should comply with a naming convention --- We respect the name from JVM Spec instead
    + * 
    */ +@SuppressWarnings("java:S116") public class AttributeModuleMainClass extends AttributeInfo { /** diff --git a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeModulePackages.java b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeModulePackages.java index 3222bf5..a30493f 100644 --- a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeModulePackages.java +++ b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeModulePackages.java @@ -36,7 +36,12 @@ * * VM Spec: The ModulePackages Attribute * + * + *
    + * java:S116 - Field names should comply with a naming convention --- We respect the name from JVM Spec instead
    + * 
    */ +@SuppressWarnings("java:S116") public class AttributeModulePackages extends AttributeInfo { /** diff --git a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeModuleTarget.java b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeModuleTarget.java index 4535678..3588507 100644 --- a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeModuleTarget.java +++ b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeModuleTarget.java @@ -33,7 +33,12 @@ * @since JDK 9 * @see * JEP 261: Module System + * + *
    + * java:S116 - Field names should comply with a naming convention --- We respect the name from JVM Spec instead
    + * 
    */ +@SuppressWarnings("java:S116") public class AttributeModuleTarget extends AttributeInfo { /** diff --git a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeNestHost.java b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeNestHost.java index 7d5b5a4..748db89 100644 --- a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeNestHost.java +++ b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeNestHost.java @@ -35,7 +35,12 @@ * * VM Spec: The NestHost Attribute * + * + *
    + * java:S116 - Field names should comply with a naming convention --- We respect the name from JVM Spec instead
    + * 
    */ +@SuppressWarnings("java:S116") public class AttributeNestHost extends AttributeInfo { /** diff --git a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeNestMembers.java b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeNestMembers.java index 9793c7d..cf8fe20 100644 --- a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeNestMembers.java +++ b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeNestMembers.java @@ -36,7 +36,12 @@ * * VM Spec: The NestMembers Attribute * + * + *
    + * java:S116 - Field names should comply with a naming convention --- We respect the name from JVM Spec instead
    + * 
    */ +@SuppressWarnings("java:S116") public class AttributeNestMembers extends AttributeInfo { /** diff --git a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeRuntimeAnnotations.java b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeRuntimeAnnotations.java index 0649ab2..8dfedf2 100644 --- a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeRuntimeAnnotations.java +++ b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeRuntimeAnnotations.java @@ -11,7 +11,12 @@ /** * * @author Amos Shi + * + *
    + * java:S116 - Field names should comply with a naming convention --- We respect the name from JVM Spec instead
    + * 
    */ +@SuppressWarnings("java:S116") public class AttributeRuntimeAnnotations extends AttributeInfo { public final u2 num_annotations; diff --git a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeRuntimeParameterAnnotations.java b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeRuntimeParameterAnnotations.java index 4ec16b0..e5652e8 100644 --- a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeRuntimeParameterAnnotations.java +++ b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeRuntimeParameterAnnotations.java @@ -15,7 +15,12 @@ * The Runtime(In)VisibleParameterAnnotations Attribute. * * @author Amos Shi + * + *
    + * java:S116 - Field names should comply with a naming convention --- We respect the name from JVM Spec instead
    + * 
    */ +@SuppressWarnings("java:S116") public class AttributeRuntimeParameterAnnotations extends AttributeInfo { public final u1 num_parameters; @@ -49,21 +54,21 @@ public void generateTreeNode(DefaultMutableTreeNode parentNode, ClassFile classF ))); if (this.parameter_annotations != null && this.parameter_annotations.length > 0) { - DefaultMutableTreeNode parameter_annotations_node = new DefaultMutableTreeNode(new JTreeNodeFileComponent( + DefaultMutableTreeNode parameterAnnotationsNode = new DefaultMutableTreeNode(new JTreeNodeFileComponent( startPosMoving + 7, this.getLength() - 7, "parameter_annotations" )); - parentNode.add(parameter_annotations_node); + parentNode.add(parameterAnnotationsNode); for (int i = 0; i < this.parameter_annotations.length; i++) { - DefaultMutableTreeNode parameter_annotation = new DefaultMutableTreeNode(new JTreeNodeFileComponent( + DefaultMutableTreeNode parameterAnnotation = new DefaultMutableTreeNode(new JTreeNodeFileComponent( this.parameter_annotations[i].getStartPos(), this.parameter_annotations[i].getLength(), String.format("parameter_annotation %d", i + 1) )); - parameter_annotations_node.add(parameter_annotation); - this.generateSubnode(parameter_annotation, this.parameter_annotations[i], classFile); + parameterAnnotationsNode.add(parameterAnnotation); + this.generateSubnode(parameterAnnotation, this.parameter_annotations[i], classFile); } } } diff --git a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeRuntimeTypeAnnotations.java b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeRuntimeTypeAnnotations.java index f29bb0c..31077ef 100644 --- a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeRuntimeTypeAnnotations.java +++ b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeRuntimeTypeAnnotations.java @@ -15,7 +15,12 @@ * The Runtime(In)VisibleTypeAnnotations Attribute. * * @author Amos Shi + * + *
    + * java:S116 - Field names should comply with a naming convention --- We respect the name from JVM Spec instead
    + * 
    */ +@SuppressWarnings("java:S116") public class AttributeRuntimeTypeAnnotations extends AttributeInfo { public final u2 num_annotations; @@ -78,15 +83,14 @@ private void generateSubnode(final DefaultMutableTreeNode rootNode, final Attrib "target_type: 0x" + String.format("%02X", ta.target_type.value) ))); startPosMoving += u1.LENGTH; - // TODO - Refactor as JTreeNodeFileComponent to set description if (ta.union_type_parameter_target != null) { - DefaultMutableTreeNode type_parameter_target = new DefaultMutableTreeNode(new JTreeNodeFileComponent( + DefaultMutableTreeNode typeParameterTarget = new DefaultMutableTreeNode(new JTreeNodeFileComponent( startPosMoving, ta.union_type_parameter_target.getLength(), TypeAnnotation.TypeParameterTarget.UNION_NAME)); - rootNode.add(type_parameter_target); - type_parameter_target.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent( + rootNode.add(typeParameterTarget); + typeParameterTarget.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent( startPosMoving, u1.LENGTH, "type_parameter_index: " + ta.union_type_parameter_target.type_parameter_index.value @@ -94,13 +98,13 @@ private void generateSubnode(final DefaultMutableTreeNode rootNode, final Attrib startPosMoving += u1.LENGTH; } else if (ta.union_supertype_target != null) { - DefaultMutableTreeNode supertype_target = new DefaultMutableTreeNode(new JTreeNodeFileComponent( + DefaultMutableTreeNode supertypeTarget = new DefaultMutableTreeNode(new JTreeNodeFileComponent( startPosMoving, ta.union_supertype_target.getLength(), TypeAnnotation.SupertypeTarget.UNION_NAME )); - rootNode.add(supertype_target); - supertype_target.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent( + rootNode.add(supertypeTarget); + supertypeTarget.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent( startPosMoving, u2.LENGTH, "supertype_index: " + ta.union_supertype_target.supertype_index.value @@ -108,19 +112,19 @@ private void generateSubnode(final DefaultMutableTreeNode rootNode, final Attrib startPosMoving += u2.LENGTH; } else if (ta.union_type_parameter_bound_target != null) { - DefaultMutableTreeNode type_parameter_bound_target = new DefaultMutableTreeNode(new JTreeNodeFileComponent( + DefaultMutableTreeNode typeParameterBoundTarget = new DefaultMutableTreeNode(new JTreeNodeFileComponent( startPosMoving, ta.union_type_parameter_bound_target.getLength(), TypeAnnotation.TypeParameterBoundTarget.UNION_NAME )); - rootNode.add(type_parameter_bound_target); - type_parameter_bound_target.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent( + rootNode.add(typeParameterBoundTarget); + typeParameterBoundTarget.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent( startPosMoving, u1.LENGTH, "type_parameter_index: " + ta.union_type_parameter_bound_target.type_parameter_index.value ))); startPosMoving += u1.LENGTH; - type_parameter_bound_target.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent( + typeParameterBoundTarget.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent( startPosMoving, u1.LENGTH, "bound_index: " + ta.union_type_parameter_bound_target.bound_index.value @@ -130,13 +134,13 @@ private void generateSubnode(final DefaultMutableTreeNode rootNode, final Attrib } else if (ta.union_empty_target != null) { // Do nothing since it is empty } else if (ta.union_method_formal_parameter_target != null) { - DefaultMutableTreeNode formal_parameter_target = new DefaultMutableTreeNode(new JTreeNodeFileComponent( + DefaultMutableTreeNode formalParameterTarget = new DefaultMutableTreeNode(new JTreeNodeFileComponent( startPosMoving, ta.union_method_formal_parameter_target.getLength(), "formal_parameter_target" )); - rootNode.add(formal_parameter_target); - formal_parameter_target.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent( + rootNode.add(formalParameterTarget); + formalParameterTarget.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent( startPosMoving, u1.LENGTH, "formal_parameter_index: " + ta.union_method_formal_parameter_target.formal_parameter_index.value @@ -144,13 +148,13 @@ private void generateSubnode(final DefaultMutableTreeNode rootNode, final Attrib startPosMoving += u1.LENGTH; } else if (ta.union_throws_target != null) { - DefaultMutableTreeNode throws_target = new DefaultMutableTreeNode(new JTreeNodeFileComponent( + DefaultMutableTreeNode throwsTarget = new DefaultMutableTreeNode(new JTreeNodeFileComponent( startPosMoving, ta.union_throws_target.getLength(), TypeAnnotation.ThrowsTarget.UNION_NAME )); - rootNode.add(throws_target); - throws_target.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent( + rootNode.add(throwsTarget); + throwsTarget.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent( startPosMoving, u2.LENGTH, "throws_type_index: " + ta.union_throws_target.throws_type_index.value @@ -158,23 +162,23 @@ private void generateSubnode(final DefaultMutableTreeNode rootNode, final Attrib startPosMoving += u2.LENGTH; } else if (ta.union_localvar_target != null) { - DefaultMutableTreeNode localvar_target = new DefaultMutableTreeNode(new JTreeNodeFileComponent( + DefaultMutableTreeNode localvarTarget = new DefaultMutableTreeNode(new JTreeNodeFileComponent( startPosMoving, ta.union_localvar_target.getLength(), TypeAnnotation.LocalvarTarget.UNION_NAME )); startPosMoving += ta.union_localvar_target.getLength(); - rootNode.add(localvar_target); - this.generateSubnode(localvar_target, ta.union_localvar_target); + rootNode.add(localvarTarget); + this.generateSubnode(localvarTarget, ta.union_localvar_target); } else if (ta.union_catch_target != null) { - DefaultMutableTreeNode catch_target = new DefaultMutableTreeNode(new JTreeNodeFileComponent( + DefaultMutableTreeNode catchTarget = new DefaultMutableTreeNode(new JTreeNodeFileComponent( startPosMoving, ta.union_catch_target.getLength(), TypeAnnotation.CatchTarget.UNION_NAME )); - rootNode.add(catch_target); - catch_target.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent( + rootNode.add(catchTarget); + catchTarget.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent( startPosMoving, u2.LENGTH, "exception_table_index: " + ta.union_catch_target.exception_table_index.value @@ -182,13 +186,13 @@ private void generateSubnode(final DefaultMutableTreeNode rootNode, final Attrib startPosMoving += u2.LENGTH; } else if (ta.union_offset_target != null) { - DefaultMutableTreeNode offset_target = new DefaultMutableTreeNode(new JTreeNodeFileComponent( + DefaultMutableTreeNode offsetTarget = new DefaultMutableTreeNode(new JTreeNodeFileComponent( startPosMoving, ta.union_offset_target.getLength(), TypeAnnotation.OffsetTarget.UNION_NAME )); - rootNode.add(offset_target); - offset_target.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent( + rootNode.add(offsetTarget); + offsetTarget.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent( startPosMoving, u2.LENGTH, "offset: " + ta.union_offset_target.offset.value @@ -196,19 +200,19 @@ private void generateSubnode(final DefaultMutableTreeNode rootNode, final Attrib startPosMoving += u2.LENGTH; } else if (ta.union_type_argument_target != null) { - DefaultMutableTreeNode type_argument_target = new DefaultMutableTreeNode(new JTreeNodeFileComponent( + DefaultMutableTreeNode typeArgumentTarget = new DefaultMutableTreeNode(new JTreeNodeFileComponent( startPosMoving, ta.union_type_argument_target.getLength(), TypeAnnotation.TypeArgumentTarget.UNION_NAME )); - rootNode.add(type_argument_target); - type_argument_target.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent( + rootNode.add(typeArgumentTarget); + typeArgumentTarget.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent( startPosMoving, u2.LENGTH, "offset: " + ta.union_type_argument_target.offset.value ))); startPosMoving += u2.LENGTH; - type_argument_target.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent( + typeArgumentTarget.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent( startPosMoving, u1.LENGTH, "type_argument_index: " + ta.union_type_argument_target.type_argument_index.value @@ -217,14 +221,14 @@ private void generateSubnode(final DefaultMutableTreeNode rootNode, final Attrib } // target_path - DefaultMutableTreeNode target_path = new DefaultMutableTreeNode(new JTreeNodeFileComponent( + DefaultMutableTreeNode targetPath = new DefaultMutableTreeNode(new JTreeNodeFileComponent( startPosMoving, ta.target_path.getLength(), "target_path" )); startPosMoving += ta.target_path.getLength(); - rootNode.add(target_path); - this.generateSubnode(target_path, ta.target_path); + rootNode.add(targetPath); + this.generateSubnode(targetPath, ta.target_path); // Annotation Annotation.generateSubnode(rootNode, ta, startPosMoving, classFile); @@ -340,7 +344,12 @@ public static class TypeAnnotation extends Annotation { public final TypeArgumentTarget union_type_argument_target; public final TypePath target_path; - @SuppressWarnings("java:S3776") // Cognitive Complexity of methods should not be too high --> No, it is not high + /** + *
    +         * java:S3776 - Cognitive Complexity of methods should not be too high --- No, it is not high
    +         * 
    + */ + @SuppressWarnings("java:S3776") public TypeAnnotation(PosDataInputStream posDataInputStream) throws IOException, FileFormatException { super(posDataInputStream, false); @@ -591,8 +600,8 @@ public enum TargetType { */ public final short value; - TargetType(int v) { - this.value = Integer.valueOf(v).shortValue(); + TargetType(Integer v) { + this.value = v.shortValue(); } /** @@ -600,8 +609,12 @@ public enum TargetType { * * @param v {@link #value} of {@link TargetType} * @return type_annotation structure union name + * + *
    +             * java:S3776 - Cognitive Complexity of methods should not be too high --- No, it is not high
    +             * 
    */ - @SuppressWarnings("java:S3776") // Cognitive Complexity of methods should not be too high --> No, it is not high + @SuppressWarnings("java:S3776") public static String getTargetUnionName(short v) { String unionName; @@ -656,7 +669,7 @@ public static String getTargetUnionName(short v) { * VM Spec: The target_info union - type_parameter_target * */ - public final static class TypeParameterTarget extends FileComponent { + public static final class TypeParameterTarget extends FileComponent { public static final String UNION_NAME = "type_parameter_target"; @@ -684,7 +697,7 @@ protected TypeParameterTarget(final PosDataInputStream posDataInputStream) throw * VM Spec: The target_info union - supertype_target * */ - public final static class SupertypeTarget extends FileComponent { + public static final class SupertypeTarget extends FileComponent { public static final String UNION_NAME = "supertype_target"; @@ -713,7 +726,7 @@ protected SupertypeTarget(final PosDataInputStream posDataInputStream) throws IO } } - public final static class TypeParameterBoundTarget extends FileComponent { + public static final class TypeParameterBoundTarget extends FileComponent { public static final String UNION_NAME = "type_parameter_bound_target"; public final u1 type_parameter_index; @@ -727,7 +740,7 @@ protected TypeParameterBoundTarget(final PosDataInputStream posDataInputStream) } } - public final static class EmptyTarget extends FileComponent { + public static final class EmptyTarget extends FileComponent { public static final String UNION_NAME = "empty_target"; @@ -737,7 +750,7 @@ protected EmptyTarget(final PosDataInputStream posDataInputStream) throws IOExce } } - public final static class FormalParameterTarget extends FileComponent { + public static final class FormalParameterTarget extends FileComponent { public static final String UNION_NAME = "method_formal_parameter_target"; public final u1 formal_parameter_index; @@ -749,7 +762,7 @@ protected FormalParameterTarget(final PosDataInputStream posDataInputStream) thr } } - public final static class ThrowsTarget extends FileComponent { + public static final class ThrowsTarget extends FileComponent { public static final String UNION_NAME = "throws_target"; public final u2 throws_type_index; @@ -776,7 +789,7 @@ protected ThrowsTarget(final PosDataInputStream posDataInputStream) throws IOExc * } * */ - public final static class LocalvarTarget extends FileComponent { + public static final class LocalvarTarget extends FileComponent { public static final String UNION_NAME = "localvar_target"; public final u2 table_length; @@ -796,7 +809,7 @@ protected LocalvarTarget(final PosDataInputStream posDataInputStream) throws IOE super.length = posDataInputStream.getPos() - super.startPos; } - public final static class Table extends FileComponent { + public static final class Table extends FileComponent { public final u2 start_pc; public final u2 length_code; @@ -813,7 +826,7 @@ protected Table(final PosDataInputStream posDataInputStream) throws IOException } } - public final static class CatchTarget extends FileComponent { + public static final class CatchTarget extends FileComponent { public static final String UNION_NAME = "catch_target"; public final u2 exception_table_index; @@ -825,7 +838,7 @@ protected CatchTarget(final PosDataInputStream posDataInputStream) throws IOExce } } - public final static class OffsetTarget extends FileComponent { + public static final class OffsetTarget extends FileComponent { public static final String UNION_NAME = "offset_target"; public final u2 offset; @@ -912,8 +925,8 @@ public enum TypePathKind { */ public final String description; - TypePathKind(int v, String d) { - this.value = Integer.valueOf(v).shortValue(); + TypePathKind(Integer v, String d) { + this.value = v.shortValue(); this.description = d; } diff --git a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeSignature.java b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeSignature.java index 74689b3..d298d34 100644 --- a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeSignature.java +++ b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeSignature.java @@ -26,12 +26,22 @@ * href="https://docs.oracle.com/javase/specs/jvms/se12/html/jvms-4.html#jvms-4.7.9"> * VM Spec: The Signature Attribute * + * + *
    + * java:S116 - Field names should comply with a naming convention --- We respect the name from JVM Spec instead
    + * 
    */ +@SuppressWarnings("java:S116") public class AttributeSignature extends AttributeInfo { public final u2 signature_index; - @SuppressWarnings("java:S1172") // Unused method parameters should be removed --> `cp` is used by children classes + /** + *
    +     * java:S1172 - Unused method parameters should be removed --- `cp` is used by children classes
    +     * 
    + */ + @SuppressWarnings("java:S1172") AttributeSignature(final u2 nameIndex, final String type, final PosDataInputStream posDataInputStream, final CPInfo[] cp) throws java.io.IOException, FileFormatException { super(nameIndex, type, posDataInputStream, ClassFile.Version.FORMAT_49_0, JavaSEVersion.VERSION_5_0); this.signature_index = new u2(posDataInputStream); @@ -148,8 +158,12 @@ public static Boolean isPrimitiveType(final char typeSignature) { * href="https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.7.9.1"> * VM Spec: Reference Type Signature * + * + *
    +     * java:S115 - Constant names should comply with a naming convention --- We respect the name from JVM Spec instead
    +     * 
    */ - @SuppressWarnings("java:S115") // Constant names should comply with a naming convention --> We respect the name from JVM Spec instead + @SuppressWarnings("java:S115") public enum ReferenceType { ClassTypeSignature('L'), diff --git a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeSourceDebugExtension.java b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeSourceDebugExtension.java index b023f03..c019a5b 100644 --- a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeSourceDebugExtension.java +++ b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeSourceDebugExtension.java @@ -37,8 +37,13 @@ * href="https://docs.oracle.com/javase/specs/jvms/se12/html/jvms-4.html#jvms-4.7.11"> * VM Spec: The Signature Attribute * + * + *
    + * java:S116 - Field names should comply with a naming convention --- We respect the name from JVM Spec instead
    + * 
    */ // TODO - This Attribute is not tested - since no test case found +@SuppressWarnings("java:S116") public class AttributeSourceDebugExtension extends AttributeInfo { /** diff --git a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeSourceFile.java b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeSourceFile.java index b813799..1fd1091 100644 --- a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeSourceFile.java +++ b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeSourceFile.java @@ -34,7 +34,12 @@ * * VM Spec: The SourceFile Attribute * + * + *
    + * java:S116 - Field names should comply with a naming convention --- We respect the name from JVM Spec instead
    + * 
    */ +@SuppressWarnings("java:S116") public class AttributeSourceFile extends AttributeInfo { public final u2 sourcefile_index; @@ -53,11 +58,11 @@ public class AttributeSourceFile extends AttributeInfo { @Override public void generateTreeNode(DefaultMutableTreeNode parentNode, ClassFile classFile) { - int cp_index = this.sourcefile_index.value; + int cpIndex = this.sourcefile_index.value; parentNode.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent( super.startPos + 6, 2, - String.format("sourcefile_index: %d [%s]", cp_index, classFile.getCPDescription(cp_index)) + String.format("sourcefile_index: %d [%s]", cpIndex, classFile.getCPDescription(cpIndex)) ))); } diff --git a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeStackMapTable.java b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeStackMapTable.java index 5a941ba..5c48477 100644 --- a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeStackMapTable.java +++ b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeStackMapTable.java @@ -27,9 +27,15 @@ * href="https://docs.oracle.com/javase/specs/jvms/se12/html/jvms-4.html#jvms-4.7.4"> * VM Spec: The StackMapTable Attribute * + * + *
    + * java:S116 - Field names should comply with a naming convention --- We respect the name from JVM Spec instead
    + * 
    */ +@SuppressWarnings("java:S116") public class AttributeStackMapTable extends AttributeInfo { - private final String MESSAGE_OFFSET_DELTA = "offset_delta: "; + + private static final String MESSAGE_OFFSET_DELTA = "offset_delta: "; /** * Gives the number of {@link StackMapFrame} entries in the {@link #entries} @@ -87,11 +93,15 @@ public void generateTreeNode(DefaultMutableTreeNode parentNode, ClassFile classF } } } - + /** * Generate Tree Node for {@link StackMapFrame}. + * + *
    +     * java:S3776 - Cognitive Complexity of methods should not be too high --- No, it is not high
    +     * 
    */ - @SuppressWarnings("java:S3776") // Cognitive Complexity of methods should not be too high --> No, it is not high + @SuppressWarnings("java:S3776") private void generateSubnode(final DefaultMutableTreeNode rootNode, final StackMapFrame smf, final ClassFile classFile) { int startPosMoving = smf.getStartPos(); @@ -169,14 +179,14 @@ private void generateSubnode(final DefaultMutableTreeNode rootNode, final StackM ))); startPosMoving += 2; - int size_locals = 0; + int sizeLocals = 0; if (smf.union_append_frame.locals.length > 0) { for (VerificationTypeInfo local : smf.union_append_frame.locals) { - size_locals += local.getLength(); + sizeLocals += local.getLength(); } DefaultMutableTreeNode locals = new DefaultMutableTreeNode(new JTreeNodeFileComponent( startPosMoving, - size_locals, + sizeLocals, "locals[" + smf.union_append_frame.locals.length + "]" )); // startPosMoving += size_locals; // Not needed for now, keep here in case the StackMapTable struture could be extended later @@ -209,17 +219,17 @@ private void generateSubnode(final DefaultMutableTreeNode rootNode, final StackM ))); startPosMoving += u2.LENGTH; - int size_locals = 0; + int sizeLocals = 0; if (smf.union_full_frame.number_of_locals.value > 0) { for (int i = 0; i < smf.union_full_frame.number_of_locals.value; i++) { - size_locals += smf.union_full_frame.locals[i].getLength(); + sizeLocals += smf.union_full_frame.locals[i].getLength(); } DefaultMutableTreeNode locals = new DefaultMutableTreeNode(new JTreeNodeFileComponent( startPosMoving, - size_locals, + sizeLocals, "locals[" + smf.union_full_frame.number_of_locals.value + "]" )); - startPosMoving += size_locals; + startPosMoving += sizeLocals; rootNode.add(locals); for (int i = 0; i < smf.union_full_frame.locals.length; i++) { @@ -240,15 +250,15 @@ private void generateSubnode(final DefaultMutableTreeNode rootNode, final StackM ))); startPosMoving += 2; - int size_stack = 0; + int sizeStack = 0; if (smf.union_full_frame.number_of_stack_items.value > 0) { for (int i = 0; i < smf.union_full_frame.number_of_stack_items.value; i++) { - size_stack += smf.union_full_frame.stack[i].getLength(); + sizeStack += smf.union_full_frame.stack[i].getLength(); } DefaultMutableTreeNode stacks = new DefaultMutableTreeNode(new JTreeNodeFileComponent( startPosMoving, - size_stack, + sizeStack, "stack[" + smf.union_full_frame.number_of_stack_items.value + "]" )); rootNode.add(stacks); @@ -305,7 +315,12 @@ public static final class StackMapFrame extends FileComponent { public final AppendFrame union_append_frame; public final FullFrame union_full_frame; - @SuppressWarnings("java:S1871") // Two branches in a conditional structure should not have exactly the same implementation --> We need it to make code more readable + /** + *
    +         * java:S1871 - Two branches in a conditional structure should not have exactly the same implementation --- We need it to make code more readable
    +         * 
    + */ + @SuppressWarnings("java:S1871") private StackMapFrame(final PosDataInputStream posDataInputStream) throws IOException { super.startPos = posDataInputStream.getPos(); @@ -564,6 +579,12 @@ public static final class ObjectVariableInfo { } } + /** + *
    +         * java:S1104 - Class variable fields should not have public accessibility --- No, we like the simplified final value manner
    +         * 
    + */ + @SuppressWarnings("java:S1104") public static final class UninitializedVariableInfo { public u2 offset; @@ -573,7 +594,12 @@ public static final class UninitializedVariableInfo { } } - @SuppressWarnings("java:S115") // Constant names should comply with a naming convention --> We respect the name from JVM Spec instead + /** + *
    +         * java:S115 - Constant names should comply with a naming convention --- We respect the name from JVM Spec instead
    +         * 
    + */ + @SuppressWarnings("java:S115") public enum TagEnum { ITEM_Top(0), diff --git a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/constant/CPInfo.java b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/constant/CPInfo.java index cc51e17..a9c6cc1 100644 --- a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/constant/CPInfo.java +++ b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/constant/CPInfo.java @@ -6,7 +6,6 @@ */ package org.freeinternals.format.classfile.constant; -import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.util.logging.Level; import java.util.logging.Logger; @@ -99,10 +98,10 @@ public abstract class CPInfo extends FileComponent implements GenerateClassfileT /** * Get a human reader friendly of current constant pool item. * - * @param constant_pool Constant Pool items needed + * @param constantPool Constant Pool items needed * @return Reader friendly string */ - public abstract String toString(CPInfo[] constant_pool); + public abstract String toString(CPInfo[] constantPool); /** * Constant pool tags. @@ -111,8 +110,12 @@ public abstract class CPInfo extends FileComponent implements GenerateClassfileT * * VM Spec: The Constant Pool * + * + *
    +     * java:S115 - Constant names should comply with a naming convention --- We respect the name from JVM Spec instead
    +     * 
    */ - @SuppressWarnings("java:S115") // Constant names should comply with a naming convention --> We respect the name from JVM Spec instead + @SuppressWarnings("java:S115") public enum ConstantType { /** @@ -322,10 +325,9 @@ public static CPInfo parse(int tag, final PosDataInputStream posDataInputStream) for (ConstantType item : ConstantType.values()) { if (item.tag == tag) { - // There is only 1 constructor in the JVM Attributes - Constructor cons = item.clazz.getDeclaredConstructors()[0]; try { - cpInfo = (CPInfo) cons.newInstance(posDataInputStream); + // There is only 1 constructor in the JVM Attributes + cpInfo = (CPInfo) item.clazz.getDeclaredConstructors()[0].newInstance(posDataInputStream); } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { Log.log(Level.SEVERE, "Failed to parse the JVM Constant Tag at position {0}, {1}", new Object[]{posDataInputStream.getPos() - 1, ex.toString()}); } diff --git a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/constant/ConstantClassInfo.java b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/constant/ConstantClassInfo.java index bac78a1..4cfc477 100644 --- a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/constant/ConstantClassInfo.java +++ b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/constant/ConstantClassInfo.java @@ -31,7 +31,12 @@ * * VM Spec: The CONSTANT_Class_info Structure * + * + *
    + * java:S116 - Field names should comply with a naming convention --- We respect the name from JVM Spec instead
    + * 
    */ +@SuppressWarnings("java:S116") public class ConstantClassInfo extends CPInfo { public static final int LENGTH = 3; @@ -57,11 +62,11 @@ public String getDescription() { } @Override - public String toString(CPInfo[] constant_pool) { + public String toString(CPInfo[] constantPool) { // The value of the name_index item must be a valid index into the constant_pool table. // The constant_pool entry at that index must be a CONSTANT_Utf8_info structure // representing a valid fully qualified class or interface name encoded in internal form. - return SignatureConvertor.ParseClassSignature(((ConstantUtf8Info) constant_pool[this.name_index.value]).getValue()); + return SignatureConvertor.parseClassSignature(((ConstantUtf8Info) constantPool[this.name_index.value]).getValue()); } @Override diff --git a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/constant/ConstantDoubleInfo.java b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/constant/ConstantDoubleInfo.java index 8c3fe6f..0b02a99 100644 --- a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/constant/ConstantDoubleInfo.java +++ b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/constant/ConstantDoubleInfo.java @@ -65,7 +65,7 @@ public String getDescription() { } @Override - public String toString(CPInfo[] constant_pool) { + public String toString(CPInfo[] constantPool) { return String.valueOf(this.doubleValue); } diff --git a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/constant/ConstantDynamicInfo.java b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/constant/ConstantDynamicInfo.java index f24f30c..4c33ca9 100644 --- a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/constant/ConstantDynamicInfo.java +++ b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/constant/ConstantDynamicInfo.java @@ -36,7 +36,12 @@ * href="https://docs.oracle.com/javase/specs/jvms/se12/html/jvms-4.html#jvms-4.4.10"> * VM Spec: he CONSTANT_Dynamic_info and CONSTANT_InvokeDynamic_info Structures * + * + *
    + * java:S116 - Field names should comply with a naming convention --- We respect the name from JVM Spec instead
    + * 
    */ +@SuppressWarnings("java:S116") public class ConstantDynamicInfo extends CPInfo { public static final int LENGTH = 5; @@ -85,12 +90,10 @@ public String getDescription() { } @Override - public String toString(CPInfo[] constant_pool) { - // TODO Improve this logic with test case - final StringBuilder sb = new StringBuilder(64); - sb.append("bootstrap_method_attr_index = ").append(this.bootstrap_method_attr_index.value); - sb.append(", name_and_type_index = ").append(constant_pool[this.name_and_type_index.value].toString(constant_pool)); - return sb.toString(); + public String toString(CPInfo[] constantPool) { + return String.format("bootstrap_method_attr_index=%d name_and_type_index=%s", + this.bootstrap_method_attr_index.value, + constantPool[this.name_and_type_index.value].toString(constantPool)); } @Override diff --git a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/constant/ConstantFieldrefInfo.java b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/constant/ConstantFieldrefInfo.java index 42c66c0..030f0b4 100644 --- a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/constant/ConstantFieldrefInfo.java +++ b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/constant/ConstantFieldrefInfo.java @@ -47,18 +47,18 @@ public String getName() { } @Override - public String toString(CPInfo[] constant_pool) { + public String toString(CPInfo[] constantPool) { // Class - String clazz = constant_pool[this.class_index.value].toString(constant_pool); + String clazz = constantPool[this.class_index.value].toString(constantPool); // Name and Type - ConstantNameAndTypeInfo nameType = (ConstantNameAndTypeInfo) constant_pool[this.name_and_type_index.value]; - String name = constant_pool[nameType.name_index.value].toString(constant_pool); - String type = constant_pool[nameType.descriptor_index.value].toString(constant_pool); + ConstantNameAndTypeInfo nameType = (ConstantNameAndTypeInfo) constantPool[this.name_and_type_index.value]; + String name = constantPool[nameType.name_index.value].toString(constantPool); + String type = constantPool[nameType.descriptor_index.value].toString(constantPool); String typeDesc; try { - typeDesc = SignatureConvertor.FieldDescriptorExtractor(type).toString(); + typeDesc = SignatureConvertor.fieldDescriptorExtractor(type).toString(); } catch (FileFormatException ex) { typeDesc = type + UNRECOGNIZED_TYPE; Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, "Failed to parse the field type: " + type, ex); diff --git a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/constant/ConstantFloatInfo.java b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/constant/ConstantFloatInfo.java index 7bfd866..cbc269f 100644 --- a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/constant/ConstantFloatInfo.java +++ b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/constant/ConstantFloatInfo.java @@ -60,7 +60,7 @@ public String getDescription() { } @Override - public String toString(CPInfo[] constant_pool) { + public String toString(CPInfo[] constantPool) { return String.valueOf(this.floatValue); } diff --git a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/constant/ConstantIntegerInfo.java b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/constant/ConstantIntegerInfo.java index c2dcc7e..21e4f88 100644 --- a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/constant/ConstantIntegerInfo.java +++ b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/constant/ConstantIntegerInfo.java @@ -59,7 +59,7 @@ public String getDescription() { } @Override - public String toString(CPInfo[] constant_pool) { + public String toString(CPInfo[] constantPool) { return String.valueOf(this.integerValue); } diff --git a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/constant/ConstantInterfaceMethodrefInfo.java b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/constant/ConstantInterfaceMethodrefInfo.java index 517c39d..c31ad01 100644 --- a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/constant/ConstantInterfaceMethodrefInfo.java +++ b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/constant/ConstantInterfaceMethodrefInfo.java @@ -45,8 +45,8 @@ public String getName() { } @Override - public String toString(CPInfo[] constant_pool) { - return super.toString4Method(constant_pool); + public String toString(CPInfo[] constantPool) { + return super.toString4Method(constantPool); } @Override diff --git a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/constant/ConstantInvokeDynamicInfo.java b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/constant/ConstantInvokeDynamicInfo.java index a95d82e..f42d189 100644 --- a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/constant/ConstantInvokeDynamicInfo.java +++ b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/constant/ConstantInvokeDynamicInfo.java @@ -36,7 +36,12 @@ * href="https://docs.oracle.com/javase/specs/jvms/se12/html/jvms-4.html#jvms-4.4.10"> * VM Spec: The CONSTANT_InvokeDynamic_info Structure * + * + *
    + * java:S116 - Field names should comply with a naming convention --- We respect the name from JVM Spec instead
    + * 
    */ +@SuppressWarnings("java:S116") public class ConstantInvokeDynamicInfo extends CPInfo { public static final int LENGTH = 5; @@ -79,12 +84,10 @@ public String getDescription() { } @Override - public String toString(CPInfo[] constant_pool) { - // TODO Improve this logic with test case - final StringBuilder sb = new StringBuilder(64); - sb.append("bootstrap_method_attr_index = ").append(this.bootstrap_method_attr_index.value); - sb.append(", name_and_type_index = ").append(constant_pool[this.name_and_type_index.value].toString(constant_pool)); - return sb.toString(); + public String toString(CPInfo[] constantPool) { + return String.format("bootstrap_method_attr_index=%d name_and_type_index=%s", + this.bootstrap_method_attr_index.value, + constantPool[this.name_and_type_index.value].toString(constantPool)); } @Override diff --git a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/constant/ConstantLongInfo.java b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/constant/ConstantLongInfo.java index eb1a19c..03aa4a9 100644 --- a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/constant/ConstantLongInfo.java +++ b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/constant/ConstantLongInfo.java @@ -65,7 +65,7 @@ public String getDescription() { } @Override - public String toString(CPInfo[] constant_pool) { + public String toString(CPInfo[] constantPool) { return String.valueOf(this.longValue); } diff --git a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/constant/ConstantMethodHandleInfo.java b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/constant/ConstantMethodHandleInfo.java index e5b6066..d17955c 100644 --- a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/constant/ConstantMethodHandleInfo.java +++ b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/constant/ConstantMethodHandleInfo.java @@ -34,7 +34,12 @@ * href="https://docs.oracle.com/javase/specs/jvms/se12/html/jvms-4.html#jvms-4.4.8"> * VM Spec: The CONSTANT_MethodHandle_info Structure * + * + *
    + * java:S116 - Field names should comply with a naming convention --- We respect the name from JVM Spec instead
    + * 
    */ +@SuppressWarnings("java:S116") public class ConstantMethodHandleInfo extends CPInfo { public static final int LENGTH = 5; @@ -72,12 +77,10 @@ public String getDescription() { } @Override - public String toString(CPInfo[] constant_pool) { - // TODO Improve this logic with test case - final StringBuilder sb = new StringBuilder(64); - sb.append("reference_kind = ").append(ReferenceKind.name(this.reference_kind.value)); - sb.append(", reference_index = ").append(constant_pool[this.reference_index.value].toString(constant_pool)); - return sb.toString(); + public String toString(CPInfo[] constantPool) { + return String.format("reference_kind=%s reference_index=%s", + ReferenceKind.name(this.reference_kind.value), + constantPool[this.reference_index.value].toString(constantPool)); } @Override @@ -102,9 +105,13 @@ public void generateTreeNode(DefaultMutableTreeNode parentNode, ClassFile classF * href="http://docs.oracle.com/javase/specs/jvms/se7/html/jvms-5.html#jvms-5.4.3.5"> * VM Spec: Method Type and Method Handle Resolution * + * + *
    +     * java:S115 - Constant names should comply with a naming convention --- We respect the name from JVM Spec instead
    +     * 
    */ - @SuppressWarnings("java:S115") // Constant names should comply with a naming convention --> We respect the name from JVM Spec instead - public static enum ReferenceKind { + @SuppressWarnings("java:S115") + public enum ReferenceKind { REF_getField(1), REF_getStatic(2), diff --git a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/constant/ConstantMethodTypeInfo.java b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/constant/ConstantMethodTypeInfo.java index c3a4c5e..07a5e30 100644 --- a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/constant/ConstantMethodTypeInfo.java +++ b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/constant/ConstantMethodTypeInfo.java @@ -35,7 +35,12 @@ * href="https://docs.oracle.com/javase/specs/jvms/se12/html/jvms-4.html#jvms-4.4.9"> * VM Spec: The CONSTANT_MethodType_info Structure * + * + *
    + * java:S116 - Field names should comply with a naming convention --- We respect the name from JVM Spec instead
    + * 
    */ +@SuppressWarnings("java:S116") public class ConstantMethodTypeInfo extends CPInfo { public static final int LENGTH = 3; @@ -66,19 +71,20 @@ public String getDescription() { } @Override - public String toString(CPInfo[] constant_pool) { - String descriptor = constant_pool[this.descriptor_index.value].toString(constant_pool); - String parameters, returnType; + public String toString(CPInfo[] constantPool) { + String descriptor = constantPool[this.descriptor_index.value].toString(constantPool); + String parameters; + String returnType; try { - parameters = SignatureConvertor.MethodParameters2Readable(descriptor); + parameters = SignatureConvertor.methodParameters2Readable(descriptor); } catch (FileFormatException ex) { parameters = descriptor + UNRECOGNIZED_TYPE; Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, "Failed to parse the method parameters: " + descriptor, ex); } try { - returnType = SignatureConvertor.MethodReturnTypeExtractor(descriptor).toString(); + returnType = SignatureConvertor.methodReturnTypeExtractor(descriptor).toString(); } catch (FileFormatException ex) { returnType = descriptor + UNRECOGNIZED_TYPE; Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, "Failed to parse the method return type: " + descriptor, ex); diff --git a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/constant/ConstantMethodrefInfo.java b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/constant/ConstantMethodrefInfo.java index ac3e347..48116d6 100644 --- a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/constant/ConstantMethodrefInfo.java +++ b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/constant/ConstantMethodrefInfo.java @@ -44,8 +44,8 @@ public String getName() { } @Override - public String toString(CPInfo[] constant_pool) { - return super.toString4Method(constant_pool); + public String toString(CPInfo[] constantPool) { + return super.toString4Method(constantPool); } @Override diff --git a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/constant/ConstantModuleInfo.java b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/constant/ConstantModuleInfo.java index 2e64d77..a7e73e6 100644 --- a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/constant/ConstantModuleInfo.java +++ b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/constant/ConstantModuleInfo.java @@ -32,7 +32,12 @@ * * VM Spec: The CONSTANT_Module_info Structure * + * + *
    + * java:S116 - Field names should comply with a naming convention --- We respect the name from JVM Spec instead
    + * 
    */ +@SuppressWarnings("java:S116") public class ConstantModuleInfo extends CPInfo { public static final int LENGTH = 3; @@ -64,8 +69,8 @@ public String getDescription() { } @Override - public String toString(CPInfo[] constant_pool) { - return ((ConstantUtf8Info) constant_pool[this.name_index.value]).getValue(); + public String toString(CPInfo[] constantPool) { + return ((ConstantUtf8Info) constantPool[this.name_index.value]).getValue(); } @Override diff --git a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/constant/ConstantNameAndTypeInfo.java b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/constant/ConstantNameAndTypeInfo.java index cb1f924..efabeb1 100644 --- a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/constant/ConstantNameAndTypeInfo.java +++ b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/constant/ConstantNameAndTypeInfo.java @@ -33,7 +33,12 @@ * * VM Spec: The CONSTANT_NameAndType_info Structure * + * + *
    + * java:S116 - Field names should comply with a naming convention --- We respect the name from JVM Spec instead
    + * 
    */ +@SuppressWarnings("java:S116") public class ConstantNameAndTypeInfo extends CPInfo { public static final int LENGTH = 5; @@ -61,9 +66,9 @@ public String getDescription() { } @Override - public String toString(CPInfo[] constant_pool) { - String nameStr = constant_pool[this.name_index.value].toString(constant_pool); - String typeStr = constant_pool[this.descriptor_index.value].toString(constant_pool); + public String toString(CPInfo[] constantPool) { + String nameStr = constantPool[this.name_index.value].toString(constantPool); + String typeStr = constantPool[this.descriptor_index.value].toString(constantPool); return String.format("name=%s, type=%s", nameStr, typeStr); } diff --git a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/constant/ConstantPackageInfo.java b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/constant/ConstantPackageInfo.java index c6890c0..f397bfd 100644 --- a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/constant/ConstantPackageInfo.java +++ b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/constant/ConstantPackageInfo.java @@ -32,7 +32,12 @@ * * VM Spec: The CONSTANT_Package_info Structure * + * + *
    + * java:S116 - Field names should comply with a naming convention --- We respect the name from JVM Spec instead
    + * 
    */ +@SuppressWarnings("java:S116") public class ConstantPackageInfo extends CPInfo { public static final int LENGTH = 3; @@ -65,8 +70,8 @@ public String getDescription() { } @Override - public String toString(CPInfo[] constant_pool) { - return ((ConstantUtf8Info) constant_pool[this.name_index.value]).getValue(); + public String toString(CPInfo[] constantPool) { + return ((ConstantUtf8Info) constantPool[this.name_index.value]).getValue(); } @Override diff --git a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/constant/ConstantRefInfo.java b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/constant/ConstantRefInfo.java index 4bbd109..a22f710 100644 --- a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/constant/ConstantRefInfo.java +++ b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/constant/ConstantRefInfo.java @@ -13,7 +13,12 @@ /** * * @author Amos Shi + * + *
    + * java:S116 - Field names should comply with a naming convention --- We respect the name from JVM Spec instead
    + * 
    */ +@SuppressWarnings("java:S116") public abstract class ConstantRefInfo extends CPInfo { public static final int LENGTH = 5; @@ -39,28 +44,29 @@ public String getDescription() { /** * Shared {@link #toString(org.freeinternals.format.classfile.constant.CPInfo[])} method for methods. * - * @param constant_pool Constant pool of current class file. + * @param constantPool Constant pool of current class file. * @return Reader friendly string of current object */ - protected String toString4Method(CPInfo[] constant_pool) { + protected String toString4Method(CPInfo[] constantPool) { // Class - String clazz = constant_pool[this.class_index.value].toString(constant_pool); + String clazz = constantPool[this.class_index.value].toString(constantPool); // Name and Type - ConstantNameAndTypeInfo nameType = (ConstantNameAndTypeInfo) constant_pool[this.name_and_type_index.value]; - String nameStr = constant_pool[nameType.name_index.value].toString(constant_pool); - String typeStr = constant_pool[nameType.descriptor_index.value].toString(constant_pool); - String parameters, returnType; + ConstantNameAndTypeInfo nameType = (ConstantNameAndTypeInfo) constantPool[this.name_and_type_index.value]; + String nameStr = constantPool[nameType.name_index.value].toString(constantPool); + String typeStr = constantPool[nameType.descriptor_index.value].toString(constantPool); + String parameters; + String returnType; try { - parameters = SignatureConvertor.MethodParameters2Readable(typeStr); + parameters = SignatureConvertor.methodParameters2Readable(typeStr); } catch (FileFormatException ex) { parameters = typeStr + UNRECOGNIZED_TYPE; Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, "Failed to parse the method parameters: " + typeStr, ex); } try { - returnType = SignatureConvertor.MethodReturnTypeExtractor(typeStr).toString(); + returnType = SignatureConvertor.methodReturnTypeExtractor(typeStr).toString(); } catch (FileFormatException ex) { returnType = typeStr + UNRECOGNIZED_TYPE; Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, "Failed to parse the method return type: " + typeStr, ex); diff --git a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/constant/ConstantStringInfo.java b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/constant/ConstantStringInfo.java index 549c1ab..b37108a 100644 --- a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/constant/ConstantStringInfo.java +++ b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/constant/ConstantStringInfo.java @@ -31,7 +31,12 @@ * * VM Spec: The CONSTANT_String_info Structure * + * + *
    + * java:S116 - Field names should comply with a naming convention --- We respect the name from JVM Spec instead
    + * 
    */ +@SuppressWarnings("java:S116") public class ConstantStringInfo extends CPInfo { public static final int LENGTH = 3; @@ -56,11 +61,11 @@ public String getDescription() { } @Override - public String toString(CPInfo[] constant_pool) { + public String toString(CPInfo[] constantPool) { // The value of the string_index item must be a valid index into the constant_pool table. // The constant_pool entry at that index must be a CONSTANT_Utf8_info structure // representing the sequence of characters to which the String object is to be initialized. - return ((ConstantUtf8Info) constant_pool[this.string_index.value]).getValue(); + return ((ConstantUtf8Info) constantPool[this.string_index.value]).getValue(); } @Override diff --git a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/constant/ConstantUtf8Info.java b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/constant/ConstantUtf8Info.java index 80b5e04..e28b6ac 100644 --- a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/constant/ConstantUtf8Info.java +++ b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/constant/ConstantUtf8Info.java @@ -34,7 +34,12 @@ * * VM Spec: The CONSTANT_Utf8_info Structure * + * + *
    + * java:S116 - Field names should comply with a naming convention --- We respect the name from JVM Spec instead
    + * 
    */ +@SuppressWarnings("java:S116") public class ConstantUtf8Info extends CPInfo { public final u2 length_utf8; @@ -84,7 +89,7 @@ public String getValue() { } @Override - public String toString(CPInfo[] constant_pool) { + public String toString(CPInfo[] constantPool) { return this.getValue(); } diff --git a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/u1.java b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/u1.java index 6e2a1f6..8cfec4b 100644 --- a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/u1.java +++ b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/u1.java @@ -11,10 +11,14 @@ import org.freeinternals.commonlib.core.PosDataInputStream; /** - * * @author Amos Shi + * + *
    + * java:S101 - Class names should comply with a naming convention --- We respect the name from JVM Spec instead
    + * 
    */ @SuppressFBWarnings(value="NM_CLASS_NAMING_CONVENTION", justification="Use the type name from JVM Spec") +@SuppressWarnings("java:S101") public class u1 { /** @@ -49,6 +53,6 @@ public u1(final PosDataInputStream posDataInputStream, boolean unsigned) throws * @return The {@link #value} as int */ public int intValue() { - return Short.valueOf(this.value).intValue(); + return this.value; } } diff --git a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/u2.java b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/u2.java index 64fd6f2..891f0c3 100644 --- a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/u2.java +++ b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/u2.java @@ -13,8 +13,13 @@ /** * * @author Amos Shi + * + *
    + * java:S101 - Class names should comply with a naming convention --- We respect the name from JVM Spec instead
    + * 
    */ @SuppressFBWarnings(value="NM_CLASS_NAMING_CONVENTION", justification="Use the type name from JVM Spec") +@SuppressWarnings("java:S101") public class u2 { /** diff --git a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/u4.java b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/u4.java index e01fa06..5f32436 100644 --- a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/u4.java +++ b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/u4.java @@ -13,8 +13,13 @@ /** * * @author Amos Shi + * + *
    + * java:S101 - Class names should comply with a naming convention --- We respect the name from JVM Spec instead
    + * 
    */ @SuppressFBWarnings(value="NM_CLASS_NAMING_CONVENTION", justification="Use the type name from JVM Spec") +@SuppressWarnings("java:S101") public class u4 { /** diff --git a/FormatDEX/src/main/java/org/freeinternals/biv/ui/dex/TreeNodeGenerator.java b/FormatDEX/src/main/java/org/freeinternals/biv/ui/dex/TreeNodeGenerator.java index ff18aff..f792fe0 100644 --- a/FormatDEX/src/main/java/org/freeinternals/biv/ui/dex/TreeNodeGenerator.java +++ b/FormatDEX/src/main/java/org/freeinternals/biv/ui/dex/TreeNodeGenerator.java @@ -29,7 +29,7 @@ * @author Amos Shi */ public class TreeNodeGenerator { - + private static final String MESSAGE_CLASS_IDX = "class_idx"; private final DexFile dexFile; private final DefaultMutableTreeNode rootNode; @@ -141,7 +141,7 @@ private void generateHeaderItem() { nodeTemp = this.addNode(headerNode, startPos, Dex_uint.LENGTH, "proto_ids_size", header.proto_ids_size); startPos = ((JTreeNodeFileComponent)nodeTemp.getUserObject()).getLastPosPlus1(); - nodeTemp = this.addNode(headerNode, startPos, Dex_uint.LENGTH, "proto_ids_off ", header.proto_ids_off); + nodeTemp = this.addNode(headerNode, startPos, Dex_uint.LENGTH, "proto_ids_off", header.proto_ids_off); startPos = ((JTreeNodeFileComponent)nodeTemp.getUserObject()).getLastPosPlus1(); nodeTemp = this.addNode(headerNode, startPos, Dex_uint.LENGTH, "field_ids_size", header.field_ids_size); @@ -165,7 +165,7 @@ private void generateHeaderItem() { nodeTemp = this.addNode(headerNode, startPos, Dex_uint.LENGTH, "data_size", header.data_size); startPos = ((JTreeNodeFileComponent)nodeTemp.getUserObject()).getLastPosPlus1(); - nodeTemp = this.addNode(headerNode, startPos, Dex_uint.LENGTH, "data_off", header.data_off); + this.addNode(headerNode, startPos, Dex_uint.LENGTH, "data_off", header.data_off); } private void generateStringIds() { @@ -258,7 +258,6 @@ private void generateProtoIds() { this.addNode(nodeTemp, 0, 0, "Value", this.dexFile.getString(item.shorty_idx.intValue())); nodeTemp = this.addNode(itemNode, startPos, Dex_uint.LENGTH, "return_type_idx", item.return_type_idx); - startPos = ((JTreeNodeFileComponent)nodeTemp.getUserObject()).getLastPosPlus1(); this.addNode(nodeTemp, 0, 0, "Value", this.dexFile.getTypeDescriptor(item.return_type_idx.intValue())); } } @@ -286,14 +285,13 @@ private void generateFieldIds() { "proto_id_item[" + String.format("%,d", i) + "]")); node.add(itemNode); - nodeTemp = this.addNode(itemNode, startPos, Dex_ushort.LENGTH, "class_idx", item.class_idx); + nodeTemp = this.addNode(itemNode, startPos, Dex_ushort.LENGTH, MESSAGE_CLASS_IDX, item.class_idx); startPos = ((JTreeNodeFileComponent)nodeTemp.getUserObject()).getLastPosPlus1(); nodeTemp = this.addNode(itemNode, startPos, Dex_ushort.LENGTH, "type_idx", item.type_idx); startPos = ((JTreeNodeFileComponent)nodeTemp.getUserObject()).getLastPosPlus1(); - nodeTemp = this.addNode(itemNode, startPos, Dex_uint.LENGTH, "name_idx", item.name_idx); - startPos = ((JTreeNodeFileComponent)nodeTemp.getUserObject()).getLastPosPlus1(); + this.addNode(itemNode, startPos, Dex_uint.LENGTH, "name_idx", item.name_idx); } } @@ -320,13 +318,13 @@ private void generateMethodIds() { "method_id_item[" + String.format("%,d", i) + "]")); node.add(itemNode); - nodeTemp = this.addNode(itemNode, startPos, Dex_ushort.LENGTH, "class_idx", item.class_idx); + nodeTemp = this.addNode(itemNode, startPos, Dex_ushort.LENGTH, MESSAGE_CLASS_IDX, item.class_idx); startPos = ((JTreeNodeFileComponent)nodeTemp.getUserObject()).getLastPosPlus1(); nodeTemp = this.addNode(itemNode, startPos, Dex_ushort.LENGTH, "proto_idx", item.proto_idx); startPos = ((JTreeNodeFileComponent)nodeTemp.getUserObject()).getLastPosPlus1(); - nodeTemp = this.addNode(itemNode, startPos, Dex_uint.LENGTH, "name_idx", item.name_idx); + this.addNode(itemNode, startPos, Dex_uint.LENGTH, "name_idx", item.name_idx); } } @@ -353,7 +351,7 @@ private void generateClassDefs() { "class_def_item[" + String.format("%,d", i) + "]")); node.add(itemNode); - nodeTemp = this.addNode(itemNode, startPos, Dex_uint.LENGTH, "class_idx", item.class_idx); + nodeTemp = this.addNode(itemNode, startPos, Dex_uint.LENGTH, MESSAGE_CLASS_IDX, item.class_idx); startPos = ((JTreeNodeFileComponent)nodeTemp.getUserObject()).getLastPosPlus1(); nodeTemp = this.addNode(itemNode, startPos, Dex_uint.LENGTH, "access_flags", item.access_flags); @@ -374,7 +372,7 @@ private void generateClassDefs() { nodeTemp = this.addNode(itemNode, startPos, Dex_uint.LENGTH, "class_data_off", item.class_data_off); startPos = ((JTreeNodeFileComponent)nodeTemp.getUserObject()).getLastPosPlus1(); - nodeTemp = this.addNode(itemNode, startPos, Dex_uint.LENGTH, "static_values_off", item.static_values_off); + this.addNode(itemNode, startPos, Dex_uint.LENGTH, "static_values_off", item.static_values_off); } } @@ -408,11 +406,11 @@ private void generateData() { private void generateData(DefaultMutableTreeNode parentNode, StringDataItem item) { DefaultMutableTreeNode nodeTemp; int startPos = item.getStartPos(); - int utf16_size = item.utf16_size.value; + int utf16Size = item.utf16_size.value; - nodeTemp = this.addNode(parentNode, startPos, item.utf16_size.length, "utf16_size", utf16_size); + nodeTemp = this.addNode(parentNode, startPos, item.utf16_size.length, "utf16_size", utf16Size); startPos = ((JTreeNodeFileComponent)nodeTemp.getUserObject()).getLastPosPlus1(); - if (utf16_size > 0) { + if (utf16Size > 0) { this.addNode(parentNode, startPos, item.data.length, "data", item.getString()); } } diff --git a/FormatDEX/src/main/java/org/freeinternals/format/dex/ClassDefItem.java b/FormatDEX/src/main/java/org/freeinternals/format/dex/ClassDefItem.java index 3428ddf..e01d4c2 100644 --- a/FormatDEX/src/main/java/org/freeinternals/format/dex/ClassDefItem.java +++ b/FormatDEX/src/main/java/org/freeinternals/format/dex/ClassDefItem.java @@ -12,7 +12,13 @@ /** * * @author Amos Shi + * + *
    + * java:S116 - Field names should comply with a naming convention --- We respect the DEX spec name instead
    + * java:S1104 - Class variable fields should not have public accessibility --- No, we like the simplified final value manner
    + * 
    */ +@SuppressWarnings({"java:S116", "java:S1104"}) public class ClassDefItem extends FileComponent { /** diff --git a/FormatDEX/src/main/java/org/freeinternals/format/dex/DexFile.java b/FormatDEX/src/main/java/org/freeinternals/format/dex/DexFile.java index 1af2f03..c0ffef6 100644 --- a/FormatDEX/src/main/java/org/freeinternals/format/dex/DexFile.java +++ b/FormatDEX/src/main/java/org/freeinternals/format/dex/DexFile.java @@ -30,7 +30,13 @@ * @see * * Dalvik Executable (DEX) format + * + *
    + * java:S116 - Field names should comply with a naming convention --- We respect the DEX spec name instead
    + * java:S1104 - Class variable fields should not have public accessibility --- No, we like the simplified final value manner
    + * 
    */ +@SuppressWarnings({"java:S116", "java:S1104"}) public class DexFile extends FileFormat { /** @@ -79,8 +85,8 @@ public DexFile(File file) throws IOException, FileFormatException { System.arraycopy(super.fileByteArray, 0, magic1, 0, DEX_FILE_MAGIC1.size()); System.arraycopy(super.fileByteArray, 4, magic2, 0, DEX_FILE_MAGIC2.size()); - byte[] magic1Const = new byte[]{DEX_FILE_MAGIC1.get(0).byteValue(), DEX_FILE_MAGIC1.get(1).byteValue(), DEX_FILE_MAGIC1.get(2).byteValue(), DEX_FILE_MAGIC1.get(3).byteValue()}; - if (BytesTool.isByteArraySame(magic1Const, magic1) == false + byte[] magic1Const = new byte[]{DEX_FILE_MAGIC1.get(0), DEX_FILE_MAGIC1.get(1), DEX_FILE_MAGIC1.get(2), DEX_FILE_MAGIC1.get(3)}; + if ( !BytesTool.isByteArraySame(magic1Const, magic1) || magic2[DEX_FILE_MAGIC2.size() - 1] != DEX_FILE_MAGIC2.get(DEX_FILE_MAGIC2.size() - 1)) { throw new FileFormatException("This is not a valid DEX file, because the DEX file signature does not exist at the beginning of this file."); } @@ -116,6 +122,12 @@ public String getTypeDescriptor(int index) { return this.getString(this.type_ids[index].descriptor_idx.intValue()); } + /** + *
    +     * java:S3776 - Cognitive Complexity of methods should not be too high - We need this logic together
    +     * 
    + */ + @SuppressWarnings("java:S3776") private void parse() throws IOException, FileFormatException { PosDataInputStream parseEndian = new PosDataInputStream(new PosByteArrayInputStream(super.fileByteArray)); @@ -146,7 +158,7 @@ private void parse() throws IOException, FileFormatException { PosDataInputStreamDex stream = new PosDataInputStreamDex(new PosByteArrayInputStream(super.fileByteArray), endian); - SortedMap todoData = new TreeMap<>(); + SortedMap> todoData = new TreeMap<>(); // Header BytesTool.skip(stream, DEX_FILE_MAGIC1.size()); @@ -221,7 +233,7 @@ private void parse() throws IOException, FileFormatException { } // data - for (Map.Entry todoItem : todoData.entrySet()) { + for (Map.Entry> todoItem : todoData.entrySet()) { if (todoItem.getValue() == StringDataItem.class) { stream.flyTo(todoItem.getKey().intValue()); this.data.put(todoItem.getKey(), new StringDataItem(stream)); diff --git a/FormatDEX/src/main/java/org/freeinternals/format/dex/Dex_byte.java b/FormatDEX/src/main/java/org/freeinternals/format/dex/Dex_byte.java index 5cb56f9..719d232 100644 --- a/FormatDEX/src/main/java/org/freeinternals/format/dex/Dex_byte.java +++ b/FormatDEX/src/main/java/org/freeinternals/format/dex/Dex_byte.java @@ -13,7 +13,12 @@ * @see * * Dalvik Executable (DEX) format + * + *
    + * java:S101 - Class names should comply with a naming convention --- We need different Name convesins for readability
    + * 
    */ +@SuppressWarnings("java:S101") public class Dex_byte { /** diff --git a/FormatDEX/src/main/java/org/freeinternals/format/dex/Dex_int.java b/FormatDEX/src/main/java/org/freeinternals/format/dex/Dex_int.java index 35e9462..a4c3451 100644 --- a/FormatDEX/src/main/java/org/freeinternals/format/dex/Dex_int.java +++ b/FormatDEX/src/main/java/org/freeinternals/format/dex/Dex_int.java @@ -13,7 +13,12 @@ * @see * * Dalvik Executable (DEX) format + * + *
    + * java:S101 - Class names should comply with a naming convention --- We need different Name convesins for readability
    + * 
    */ +@SuppressWarnings("java:S101") public class Dex_int { /** * Length of the type in bytes. diff --git a/FormatDEX/src/main/java/org/freeinternals/format/dex/Dex_long.java b/FormatDEX/src/main/java/org/freeinternals/format/dex/Dex_long.java index 16787f6..a0fd94b 100644 --- a/FormatDEX/src/main/java/org/freeinternals/format/dex/Dex_long.java +++ b/FormatDEX/src/main/java/org/freeinternals/format/dex/Dex_long.java @@ -13,7 +13,12 @@ * @see * * Dalvik Executable (DEX) format + * + *
    + * java:S101 - Class names should comply with a naming convention --- We need different Name convesins for readability
    + * 
    */ +@SuppressWarnings("java:S101") public class Dex_long { /** diff --git a/FormatDEX/src/main/java/org/freeinternals/format/dex/Dex_short.java b/FormatDEX/src/main/java/org/freeinternals/format/dex/Dex_short.java index 6b4f37b..caa9ab7 100644 --- a/FormatDEX/src/main/java/org/freeinternals/format/dex/Dex_short.java +++ b/FormatDEX/src/main/java/org/freeinternals/format/dex/Dex_short.java @@ -13,7 +13,12 @@ * @see * * Dalvik Executable (DEX) format + * + *
    + * java:S101 - Class names should comply with a naming convention --- We need different Name convesins for readability
    + * 
    */ +@SuppressWarnings("java:S101") public class Dex_short { /** diff --git a/FormatDEX/src/main/java/org/freeinternals/format/dex/Dex_sleb128.java b/FormatDEX/src/main/java/org/freeinternals/format/dex/Dex_sleb128.java index 379c34d..54aec69 100644 --- a/FormatDEX/src/main/java/org/freeinternals/format/dex/Dex_sleb128.java +++ b/FormatDEX/src/main/java/org/freeinternals/format/dex/Dex_sleb128.java @@ -13,7 +13,12 @@ * @see * * Dalvik Executable (DEX) format + * + *
    + * java:S101 - Class names should comply with a naming convention --- We need different Name convesins for readability
    + * 
    */ +@SuppressWarnings("java:S101") public class Dex_sleb128 { /** diff --git a/FormatDEX/src/main/java/org/freeinternals/format/dex/Dex_ubyte.java b/FormatDEX/src/main/java/org/freeinternals/format/dex/Dex_ubyte.java index 21a0267..0d7ae8a 100644 --- a/FormatDEX/src/main/java/org/freeinternals/format/dex/Dex_ubyte.java +++ b/FormatDEX/src/main/java/org/freeinternals/format/dex/Dex_ubyte.java @@ -13,7 +13,12 @@ * @see * * Dalvik Executable (DEX) format + * + *
    + * java:S101 - Class names should comply with a naming convention --- We need different Name convesins for readability
    + * 
    */ +@SuppressWarnings("java:S101") public class Dex_ubyte { /** diff --git a/FormatDEX/src/main/java/org/freeinternals/format/dex/Dex_uint.java b/FormatDEX/src/main/java/org/freeinternals/format/dex/Dex_uint.java index a4c14bd..5bad7f0 100644 --- a/FormatDEX/src/main/java/org/freeinternals/format/dex/Dex_uint.java +++ b/FormatDEX/src/main/java/org/freeinternals/format/dex/Dex_uint.java @@ -13,7 +13,12 @@ * @see * * Dalvik Executable (DEX) format + * + *
    + * java:S101 - Class names should comply with a naming convention --- We need different Name convesins for readability
    + * 
    */ +@SuppressWarnings("java:S101") public class Dex_uint { /** diff --git a/FormatDEX/src/main/java/org/freeinternals/format/dex/Dex_uleb128.java b/FormatDEX/src/main/java/org/freeinternals/format/dex/Dex_uleb128.java index 69d816a..04a1106 100644 --- a/FormatDEX/src/main/java/org/freeinternals/format/dex/Dex_uleb128.java +++ b/FormatDEX/src/main/java/org/freeinternals/format/dex/Dex_uleb128.java @@ -13,7 +13,12 @@ * @see * * Dalvik Executable (DEX) format + * + *
    + * java:S101 - Class names should comply with a naming convention --- We need different Name convesins for readability
    + * 
    */ +@SuppressWarnings("java:S101") public class Dex_uleb128 { /** diff --git a/FormatDEX/src/main/java/org/freeinternals/format/dex/Dex_uleb128p1.java b/FormatDEX/src/main/java/org/freeinternals/format/dex/Dex_uleb128p1.java index 03f96c1..f822bfd 100644 --- a/FormatDEX/src/main/java/org/freeinternals/format/dex/Dex_uleb128p1.java +++ b/FormatDEX/src/main/java/org/freeinternals/format/dex/Dex_uleb128p1.java @@ -13,7 +13,12 @@ * @see * * Dalvik Executable (DEX) format + * + *
    + * java:S101 - Class names should comply with a naming convention --- We need different Name convesins for readability
    + * 
    */ +@SuppressWarnings("java:S101") public class Dex_uleb128p1 { /** diff --git a/FormatDEX/src/main/java/org/freeinternals/format/dex/Dex_ulong.java b/FormatDEX/src/main/java/org/freeinternals/format/dex/Dex_ulong.java index 49a5c60..3c1e42d 100644 --- a/FormatDEX/src/main/java/org/freeinternals/format/dex/Dex_ulong.java +++ b/FormatDEX/src/main/java/org/freeinternals/format/dex/Dex_ulong.java @@ -15,7 +15,12 @@ * @see * * Dalvik Executable (DEX) format + * + *
    + * java:S101 - Class names should comply with a naming convention --- We need different Name convesins for readability
    + * 
    */ +@SuppressWarnings("java:S101") public class Dex_ulong { /** diff --git a/FormatDEX/src/main/java/org/freeinternals/format/dex/Dex_ushort.java b/FormatDEX/src/main/java/org/freeinternals/format/dex/Dex_ushort.java index 8be3552..56fd9af 100644 --- a/FormatDEX/src/main/java/org/freeinternals/format/dex/Dex_ushort.java +++ b/FormatDEX/src/main/java/org/freeinternals/format/dex/Dex_ushort.java @@ -13,7 +13,12 @@ * @see * * Dalvik Executable (DEX) format + * + *
    + * java:S101 - Class names should comply with a naming convention --- We need different Name convesins for readability
    + * 
    */ +@SuppressWarnings("java:S101") public class Dex_ushort { /** diff --git a/FormatDEX/src/main/java/org/freeinternals/format/dex/FieldIdItem.java b/FormatDEX/src/main/java/org/freeinternals/format/dex/FieldIdItem.java index 49d1aea..9f70400 100644 --- a/FormatDEX/src/main/java/org/freeinternals/format/dex/FieldIdItem.java +++ b/FormatDEX/src/main/java/org/freeinternals/format/dex/FieldIdItem.java @@ -12,7 +12,13 @@ /** * * @author Amos Shi + * + *
    + * java:S116 - Field names should comply with a naming convention --- We respect the DEX spec name instead
    + * java:S1104 - Class variable fields should not have public accessibility --- No, we like the simplified final value manner
    + * 
    */ +@SuppressWarnings({"java:S116", "java:S1104"}) public class FieldIdItem extends FileComponent { /** diff --git a/FormatDEX/src/main/java/org/freeinternals/format/dex/HeaderItem.java b/FormatDEX/src/main/java/org/freeinternals/format/dex/HeaderItem.java index 7a8ec66..2a9db5e 100644 --- a/FormatDEX/src/main/java/org/freeinternals/format/dex/HeaderItem.java +++ b/FormatDEX/src/main/java/org/freeinternals/format/dex/HeaderItem.java @@ -14,7 +14,13 @@ * The header_item structure of the DEX file. * * @author Amos Shi + * + *
    + * java:S116 - Field names should comply with a naming convention --- We respect the DEX spec name instead
    + * java:S1104 - Class variable fields should not have public accessibility --- No, we like the simplified final value manner
    + * 
    */ +@SuppressWarnings({"java:S116", "java:S1104"}) public class HeaderItem extends FileComponent { /** @@ -78,13 +84,13 @@ public class HeaderItem extends FileComponent { HeaderItem(PosDataInputStreamDex stream) throws IOException { super.startPos = stream.getPos(); - this.checksum = stream.Dex_uint(); // new Dex_uint(stream.readUnsignedInt()); + this.checksum = stream.Dex_uint(); for (int i = 0; i < this.signature.length; i++) { - this.signature[i] = stream.Dex_ubyte(); // new Dex_ubyte(stream.readUnsignedByte()); + this.signature[i] = stream.Dex_ubyte(); } - this.file_size = stream.Dex_uint(); // new Dex_uint(stream.readUnsignedInt_LittleEndian()); - BytesTool.skip(stream, Dex_uint.LENGTH); // header_item-header_size - constant value 0x70 - this.endian_tag = new Dex_uint(stream.readUnsignedInt()); // Always read from left to right + this.file_size = stream.Dex_uint(); + BytesTool.skip(stream, Dex_uint.LENGTH); + this.endian_tag = new Dex_uint(stream.readUnsignedInt()); // Always read from left to right this.link_size = stream.Dex_uint(); this.link_off = stream.Dex_uint(); this.map_off = stream.Dex_uint(); @@ -115,7 +121,7 @@ public class HeaderItem extends FileComponent { * {@link Endian#ENDIAN_CONSTANT}, it would know that the file has been * byte-swapped from the expected form. */ - public static enum Endian { + public enum Endian { /** * Little-endian, which is DEX standard. diff --git a/FormatDEX/src/main/java/org/freeinternals/format/dex/MethodIdItem.java b/FormatDEX/src/main/java/org/freeinternals/format/dex/MethodIdItem.java index edc2c89..ec3791b 100644 --- a/FormatDEX/src/main/java/org/freeinternals/format/dex/MethodIdItem.java +++ b/FormatDEX/src/main/java/org/freeinternals/format/dex/MethodIdItem.java @@ -12,7 +12,13 @@ /** * * @author Amos Shi + * + *
    + * java:S116 - Field names should comply with a naming convention --- We respect the DEX spec name instead
    + * java:S1104 - Class variable fields should not have public accessibility --- No, we like the simplified final value manner
    + * 
    */ +@SuppressWarnings({"java:S116", "java:S1104"}) public class MethodIdItem extends FileComponent{ /** * Item Size In Bytes. diff --git a/FormatDEX/src/main/java/org/freeinternals/format/dex/PosDataInputStreamDex.java b/FormatDEX/src/main/java/org/freeinternals/format/dex/PosDataInputStreamDex.java index 80423e5..9d109ca 100644 --- a/FormatDEX/src/main/java/org/freeinternals/format/dex/PosDataInputStreamDex.java +++ b/FormatDEX/src/main/java/org/freeinternals/format/dex/PosDataInputStreamDex.java @@ -15,7 +15,12 @@ /** * * @author Amos Shi + * + *
    + * java:S100 - Method names should comply with a naming convention --- We use different naming convention for better readablity
    + * 
    */ +@SuppressWarnings("java:S100") public class PosDataInputStreamDex extends PosDataInputStream { /** diff --git a/FormatDEX/src/main/java/org/freeinternals/format/dex/ProtoIdItem.java b/FormatDEX/src/main/java/org/freeinternals/format/dex/ProtoIdItem.java index 2a9adb5..49afc51 100644 --- a/FormatDEX/src/main/java/org/freeinternals/format/dex/ProtoIdItem.java +++ b/FormatDEX/src/main/java/org/freeinternals/format/dex/ProtoIdItem.java @@ -12,7 +12,13 @@ /** * * @author Amos Shi + * + *
    + * java:S116 - Field names should comply with a naming convention --- We respect the DEX spec name instead
    + * java:S1104 - Class variable fields should not have public accessibility --- No, we like the simplified final value manner
    + * 
    */ +@SuppressWarnings({"java:S116", "java:S1104"}) public class ProtoIdItem extends FileComponent { /** diff --git a/FormatDEX/src/main/java/org/freeinternals/format/dex/StringDataItem.java b/FormatDEX/src/main/java/org/freeinternals/format/dex/StringDataItem.java index a77e0e7..5d6da38 100644 --- a/FormatDEX/src/main/java/org/freeinternals/format/dex/StringDataItem.java +++ b/FormatDEX/src/main/java/org/freeinternals/format/dex/StringDataItem.java @@ -7,7 +7,6 @@ package org.freeinternals.format.dex; import java.io.IOException; -import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import org.freeinternals.commonlib.core.FileComponent; import org.freeinternals.commonlib.core.FileFormatException; @@ -15,7 +14,13 @@ /** * * @author Amos Shi + * + *
    + * java:S116 - Field names should comply with a naming convention --- We respect the DEX spec name instead
    + * java:S1104 - Class variable fields should not have public accessibility --- No, we like the simplified final value manner
    + * 
    */ +@SuppressWarnings({"java:S116", "java:S1104"}) public class StringDataItem extends FileComponent { /** diff --git a/FormatDEX/src/main/java/org/freeinternals/format/dex/StringIdItem.java b/FormatDEX/src/main/java/org/freeinternals/format/dex/StringIdItem.java index b6bba09..d5ce970 100644 --- a/FormatDEX/src/main/java/org/freeinternals/format/dex/StringIdItem.java +++ b/FormatDEX/src/main/java/org/freeinternals/format/dex/StringIdItem.java @@ -12,7 +12,13 @@ /** * * @author Amos Shi + * + *
    + * java:S116 - Field names should comply with a naming convention --- We respect the DEX spec name instead
    + * java:S1104 - Class variable fields should not have public accessibility --- No, we like the simplified final value manner
    + * 
    */ +@SuppressWarnings({"java:S116", "java:S1104"}) public class StringIdItem extends FileComponent { /** diff --git a/FormatDEX/src/main/java/org/freeinternals/format/dex/TypeIdItem.java b/FormatDEX/src/main/java/org/freeinternals/format/dex/TypeIdItem.java index 8ac50c4..437db09 100644 --- a/FormatDEX/src/main/java/org/freeinternals/format/dex/TypeIdItem.java +++ b/FormatDEX/src/main/java/org/freeinternals/format/dex/TypeIdItem.java @@ -12,7 +12,13 @@ /** * * @author Amos Shi + * + *
    + * java:S116 - Field names should comply with a naming convention --- We respect the DEX spec name instead
    + * java:S1104 - Class variable fields should not have public accessibility --- No, we like the simplified final value manner
    + * 
    */ +@SuppressWarnings({"java:S116", "java:S1104"}) public class TypeIdItem extends FileComponent { /** diff --git a/FormatELF/src/main/java/org/freeinternals/biv/ui/elf/TreeNodeGenerator.java b/FormatELF/src/main/java/org/freeinternals/biv/ui/elf/TreeNodeGenerator.java deleted file mode 100644 index 6e7fde4..0000000 --- a/FormatELF/src/main/java/org/freeinternals/biv/ui/elf/TreeNodeGenerator.java +++ /dev/null @@ -1,15 +0,0 @@ -/* - * TreeNodeGenerator.java June 23, 2015, 21:51 - * - * Copyright 2015, FreeInternals.org. All rights reserved. - * Use is subject to license terms. - */ -package org.freeinternals.biv.ui.elf; - -/** - * - * @author Amos Shi - */ -public class TreeNodeGenerator { - -} diff --git a/FormatELF/src/main/java/org/freeinternals/format/elf/Elf64Type.java b/FormatELF/src/main/java/org/freeinternals/format/elf/Elf64Type.java index 5de73e6..63542de 100644 --- a/FormatELF/src/main/java/org/freeinternals/format/elf/Elf64Type.java +++ b/FormatELF/src/main/java/org/freeinternals/format/elf/Elf64Type.java @@ -25,9 +25,17 @@ * @author Amos Shi * @see * include/uapi/linux/elf.h + * + *
    + * java:S101 - Class names should comply with a naming convention --- We respect the name from ELF C programming language source code
    + * 
    */ +@SuppressWarnings("java:S101") public class Elf64Type { + private Elf64Type() { + } + /** * typedef __u64 Elf64_Addr;. */ diff --git a/FormatELF/src/main/java/org/freeinternals/format/elf/Elf64_Ehdr.java b/FormatELF/src/main/java/org/freeinternals/format/elf/Elf64_Ehdr.java index 702c09b..d0f30d1 100644 --- a/FormatELF/src/main/java/org/freeinternals/format/elf/Elf64_Ehdr.java +++ b/FormatELF/src/main/java/org/freeinternals/format/elf/Elf64_Ehdr.java @@ -44,7 +44,13 @@ * * @see * include/uapi/linux/elf.h + * + *
    + * java:S101 - Class names should comply with a naming convention --- We respect the name from ELF C programming language source code
    + * java:S116 - Field names should comply with a naming convention --- We respect the name from ELF C programming language source code
    + * 
    */ +@SuppressWarnings({"java:S101", "java:S116"}) public class Elf64_Ehdr extends FileComponent implements GenerateTreeNode { /** @@ -171,7 +177,12 @@ public static String nameOf(int v) { * @see * Executable * and Linkable Format + * + *
    +     * java:S115 - Constant names should comply with a naming convention --> We respect the name from ELF Spec instead
    +     * 
    */ + @SuppressWarnings("java:S115") public enum ELF_Machine { /** * No specific instruction set. @@ -297,15 +308,15 @@ public static String nameOf(int v) { @Override public void generateTreeNode(DefaultMutableTreeNode parentNode) { - DefaultMutableTreeNode node; int currentPos = this.startPos; - parentNode.add(node = new DefaultMutableTreeNode(new JTreeNodeFileComponent( + DefaultMutableTreeNode node = new DefaultMutableTreeNode(new JTreeNodeFileComponent( this.startPos, this.length, String.format("ELF64 Header [0x%08X, %d]", this.startPos, this.length), "The ELF header on 64-bit CPU architecture." - ))); + )); + parentNode.add(node); // e_type node.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent( diff --git a/FormatELF/src/main/java/org/freeinternals/format/elf/Identification.java b/FormatELF/src/main/java/org/freeinternals/format/elf/Identification.java index 46571f1..be9a1cd 100644 --- a/FormatELF/src/main/java/org/freeinternals/format/elf/Identification.java +++ b/FormatELF/src/main/java/org/freeinternals/format/elf/Identification.java @@ -25,7 +25,12 @@ * include/linux/elfcore.h * @see * arch/powerpc/boot/elf.h + * + *
    + * java:S116 - Field names should comply with a naming convention --- We respect the name from ELF C programming language source code
    + * 
    */ +@SuppressWarnings("java:S116") public class Identification extends FileComponent implements GenerateTreeNode { /** @@ -108,28 +113,28 @@ public class Identification extends FileComponent implements GenerateTreeNode { // ELF Class: 32-/64-bit int value = input.readUnsignedByte(); - if (ElfClass.contains(value) == false) { + if (!ElfClass.contains(value)) { throw new FileFormatException("Unrecognized EI_CLASS value in ELF file header. value=" + value); } this.EI_CLASS = ElfClass.valueOf(value); // Endianness value = input.readUnsignedByte(); - if (Endianness.contains(value) == false) { + if (!Endianness.contains(value)) { throw new FileFormatException("Unrecognized EI_DATA value in ELF file header. value=" + value); } this.EI_DATA = Endianness.valueOf(value); // Version value = input.readUnsignedByte(); - if (Version.contains(value) == false) { + if (!Version.contains(value)) { throw new FileFormatException("Unrecognized EI_VERSION value in ELF file header. value=" + value); } this.EI_VERSION = Version.valueOf(value); // EI_OSABI value = input.readUnsignedByte(); - if (OSAbi.contains(value) == false) { + if (!OSAbi.contains(value)) { throw new FileFormatException("Unrecognized EI_OSABI value in ELF file header. value=" + value); } this.EI_OSABI = OSAbi.valueOf(value); @@ -152,15 +157,15 @@ public class Identification extends FileComponent implements GenerateTreeNode { @Override public void generateTreeNode(DefaultMutableTreeNode parentNode) { - DefaultMutableTreeNode node; int currentPos = this.startPos; - parentNode.add(node = new DefaultMutableTreeNode(new JTreeNodeFileComponent( + DefaultMutableTreeNode node = new DefaultMutableTreeNode(new JTreeNodeFileComponent( this.startPos, this.length, String.format("ELF File Header [0x%08X, %d]", this.startPos, this.length), "The ELF header defines whether to use 32-bit or 64-bit addresses. The header contains three fields that are affected by this setting and offset other fields that follow them." - ))); + )); + parentNode.add(node); // EI_MAG node.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent( @@ -445,7 +450,12 @@ public static Version valueOf(int v) { * and Linkable Format * @see * include/uapi/linux/elf.h + * + *
    +     * java:S115 - Constant names should comply with a naming convention --> We respect the name from ELF Spec instead
    +     * 
    */ + @SuppressWarnings("java:S115") public enum OSAbi { /** * Regardless of the target platform. The value 0 could be diff --git a/FormatELF/src/main/java/org/freeinternals/format/elf/PosDataInputStreamElf.java b/FormatELF/src/main/java/org/freeinternals/format/elf/PosDataInputStreamElf.java index f4c328f..16a0fbe 100644 --- a/FormatELF/src/main/java/org/freeinternals/format/elf/PosDataInputStreamElf.java +++ b/FormatELF/src/main/java/org/freeinternals/format/elf/PosDataInputStreamElf.java @@ -25,7 +25,12 @@ * Extended reader for ELF format. * * @author Amos Shi + * + *
    + * java:S100 - Method names should comply with a naming convention --- We respect the name from ELF spec instead
    + * 
    */ +@SuppressWarnings("java:S100") public class PosDataInputStreamElf extends PosDataInputStream { protected final Endianness endian;