This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 152770 - GUI Builder should remove unused imports
Summary: GUI Builder should remove unused imports
Status: NEW
Alias: None
Product: guibuilder
Classification: Unclassified
Component: Code (show other bugs)
Version: 6.x
Hardware: All All
: P3 blocker (vote)
Assignee: issues@guibuilder
URL:
Keywords:
: 124244 231161 (view as bug list)
Depends on:
Blocks:
 
Reported: 2008-11-08 11:07 UTC by alexandros
Modified: 2013-06-18 17:36 UTC (History)
2 users (show)

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description alexandros 2008-11-08 11:07:43 UTC
The GUI Builder should remove imports that are not used in the java.awt and javax.swing packages and subpackages.
Comment 1 alexandros 2008-11-08 11:11:50 UTC
--For instance:
--Before:
import java.awt.BorderLayout;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.SwingUtilities;

public class Main extends JFrame {

    /** Creates new form Main */
    public Main() {
        initComponents();
        setVisible(true);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        jScrollPane1 = new JScrollPane();
        jTextArea1 = new JTextArea();

        setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);

        jTextArea1.setColumns(20);
        jTextArea1.setRows(5);
        jScrollPane1.setViewportView(jTextArea1);

        getContentPane().add(jScrollPane1, BorderLayout.CENTER);
    }// </editor-fold>

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                new Main();
            }
        });
    }

    // Variables declaration - do not modify
    private JScrollPane jScrollPane1;
    private JTextArea jTextArea1;
    // End of variables declaration

}
--After:

import java.awt.BorderLayout;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.SwingUtilities;

public class Main extends JFrame {

    /** Creates new form Main */
    public Main() {
        initComponents();
        setVisible(true);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
    }// </editor-fold>

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                new Main();
            }
        });
    }

    // Variables declaration - do not modify
    // End of variables declaration

}

--Unused imports should be removed:
----java.awt.BorderLayout
----import javax.swing.JScrollPane
----import javax.swing.JTextArea
Comment 2 Jiri Vagner 2008-11-10 08:22:02 UTC
Thank you for your report. Maybe it will be possible to remove automatically unused import of xyz component, while
removing that component. Also we could automatically remove unused beansbinding imports if its possible.
Comment 3 Tomas Pavek 2013-06-18 17:32:52 UTC
*** Bug 124244 has been marked as a duplicate of this bug. ***
Comment 4 Tomas Pavek 2013-06-18 17:36:14 UTC
Trying to "fix imports" might have sense when "Generate Full Classnames" option is off, in which case the GUI builder adds imports -- so could also remove them.
Comment 5 Tomas Pavek 2013-06-18 17:36:36 UTC
*** Bug 231161 has been marked as a duplicate of this bug. ***