0

Should I ignore automated code review errors for GUI class? This class was generated by Windowbuilder. Should I make it differently so it has A grade in automated code reviews, and how should I do it, or should I ignored them because this types of classes don't have real complexity? The only describe window components and nothing else. Code reviews show me:

  • Assignment Branch Condition
  • Too many instance variables
  • Function too long
  • Total complexity too high

This is the code

package gui.dialogs;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import data.elements.Property;
import data.elements.Model;
import gui.text.DeviceDefaultTextUtils;

import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JTextField;
import java.awt.Font;
import java.awt.Button;
import java.awt.Dialog;

import javax.swing.SwingConstants;

public class DeviceDialog extends JDialog
{
    private static final long serialVersionUID = -7176709114506808074L;
    public JPanel contentPane = new JPanel();
    public JLabel lblDeviceIDValue = new JLabel();
    public Button btnAddNewModel;
    public JTextField textFieldSerial = new JTextField();
    public Button btnAdd;
    public Button btnCancel;

    /**
     * Creates frame "Device Registration Form".
     */
    public DeviceDialog(Dialog parentWindow)
    {
        createJDialogView();
        createDeviceIDView();
        createDeviceTypeView();
        createDeviceManufacturerView();
        createDeviceModelView();
        createDeviceSerialView();
        createButtonsView();
    }

    private void createJDialogView()
    {
        setTitle(DeviceDefaultTextUtils.TITLE);
        setResizable(false);
        setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        setBounds(100, 100, 300, 420);

        contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
        setContentPane(contentPane);
        contentPane.setLayout(null);
    }

    private void createDeviceIDView()
    {
        JLabel lblDeviceID = new JLabel(DeviceDefaultTextUtils.DEVICE_ID_LABEL);
        lblDeviceID.setFont(new Font("Tahoma", Font.PLAIN, 15));
        lblDeviceID.setBounds(20, 10, 75, 25);
        contentPane.add(lblDeviceID);

        lblDeviceIDValue.setHorizontalAlignment(SwingConstants.CENTER);
        lblDeviceIDValue.setFont(new Font("Segoe UI Symbol", Font.BOLD, 15));
        lblDeviceIDValue.setBounds(200, 10, 75, 25);
        contentPane.add(lblDeviceIDValue);
    }

    private void createDeviceTypeView()
    {
        JLabel lblDeviceType = new JLabel(DeviceDefaultTextUtils.DEVICE_TYPE_LABEL);
        lblDeviceType.setBounds(20, 50, 255, 15);
        contentPane.add(lblDeviceType);

        JComboBox<Property> comboBoxDeviceType = new JComboBox<Property>();
        comboBoxDeviceType.setBounds(20, 75, 255, 25);
        contentPane.add(comboBoxDeviceType);
    }

    private void createDeviceManufacturerView()
    {
        JLabel lblManufacturer = new JLabel(DeviceDefaultTextUtils.MANUFACTURER_LABEL);
        lblManufacturer.setBounds(20, 115, 255, 15);
        contentPane.add(lblManufacturer);

        JComboBox<Property> comboBoxManufacturer = new JComboBox<Property>();
        comboBoxManufacturer.setBounds(20, 140, 255, 25);
        contentPane.add(comboBoxManufacturer);
    }

    private void createDeviceModelView()
    {
        JLabel lblModel = new JLabel("Model");
        lblModel.setBounds(20, 175, 255, 15);
        contentPane.add(lblModel);

        JComboBox<Model> comboBoxModel = new JComboBox<Model>();
        comboBoxModel.setBounds(20, 200, 255, 25);
        contentPane.add(comboBoxModel);

        btnAddNewModel = new Button(DeviceDefaultTextUtils.ADD_NEW_MODEL_BUTTON);
        btnAddNewModel.setBounds(95, 234, 110, 25);
        contentPane.add(btnAddNewModel);
    }

    private void createDeviceSerialView()
    {
        JLabel lblSerial = new JLabel(DeviceDefaultTextUtils.SERIAL_NUMBER_LABEL);
        lblSerial.setBounds(20, 265, 255, 14);
        contentPane.add(lblSerial);

        textFieldSerial.setBounds(20, 290, 255, 25);
        contentPane.add(textFieldSerial);
        textFieldSerial.setColumns(10);
    }

    private void createButtonsView()
    {
        btnAdd = new Button(DeviceDefaultTextUtils.ADD_DEVICE_BUTTON);
        btnAdd.setFont(new Font("Dialog", Font.PLAIN, 15));
        btnAdd.setBounds(20, 345, 110, 25);
        contentPane.add(btnAdd);

        btnCancel = new Button(DeviceDefaultTextUtils.CANCEL_BUTTON);
        btnCancel.setFont(new Font("Dialog", Font.PLAIN, 15));
        btnCancel.setBounds(165, 345, 110, 25);
        contentPane.add(btnCancel);
    }
}
vincenzopalazzo
  • 1,037
  • 2
  • 5
  • 25
Zoran Jankov
  • 228
  • 2
  • 3
  • 15

1 Answers1

1

Generally all generated code should be excluded from automated code reviews.

Of course this implies that any custom code you make does NOT exist within the same source file as the generated code. If you're modifying the generated code before offering it to your review process, you should count this file as not being generated in its entirety, unless you mark the generated sections explicitly and your tooling allows excluding only sections of files (e.g. in Sonar you can mark things as "won't fix" and give a reason of "generated code" as a comment in such cases).

jwenting
  • 4,890
  • 2
  • 22
  • 28