FindReplacePanel.java

Index Score
edu.rice.cs.drjava.ui
DrJava

View: Reasons, Metrics, Source Code

These are the metrics that contribute to the Enerjy Score for this file, ranked by impact. So the metrics listed at the top influence the score to a greater extent that the metrics listed at the bottom.

MetricDescription
LINE_COMMENTNumber of line comments
DECL_COMMENTSComments in declarations
EXEC_COMMENTSComments in executable code
JAVA0020JAVA0020 Field name does not have required form
LOGICAL_LINESNumber of statements
SIZESize of the file in bytes
JAVA0034JAVA0034 Missing braces in if statement
EXITSProcedure exits
OPERANDSNumber of operands
PROGRAM_LENGTHHalstead program length
OPERATORSNumber of operators
UNIQUE_OPERANDSNumber of unique operands
ELOCEffective lines of code
PROGRAM_VOCABHalstead program vocabulary
LINESNumber of lines in the source file
LOCLines of code
JAVA0108JAVA0108 Incorrect javadoc: no @param tag for 'parameter'
FUNCTIONSNumber of function declarations
COMMENTSComment lines
CYCLOMATICCyclomatic complexity
BLOCKSNumber of blocks
JAVA0081JAVA0081 Boolean literal in comparison
INTERFACE_COMPLEXITYInterface complexity
RETURNSNumber of return points from functions
JAVA0018JAVA0018 Method name does not have required form
JAVA0177JAVA0177 Variable declaration missing initializer
PARAMSNumber of formal parameter declarations
WHITESPACENumber of whitespace lines
JAVA0076JAVA0076 Use of magic number
JAVA0049JAVA0049 Nested block at depth N (maximum: M)
NEST_DEPTHMaximum nesting depth
JAVA0110JAVA0110 Incorrect javadoc: no @return tag
UNIQUE_OPERATORSNumber of unique operators
JAVA0080JAVA0080 Import declaration not used
COMPARISONSNumber of comparison operators
JAVA0128JAVA0128 Public constructor in non-public class
PROGRAM_VOLUMEHalstead program volume
JAVA0136JAVA0136 N methods defined in class (maximum: M)
JAVA0176JAVA0176 Local variable name does not have required form
JAVA0126JAVA0126 Method declares unchecked exception in throws
JAVA0100JAVA0100 Class contains N non-final fields (maximum: M)
LOOPSNumber of loops
JAVA0145JAVA0145 Tab character used in source file
/*BEGIN_COPYRIGHT_BLOCK * * Copyright (c) 2001-2008, JavaPLT group at Rice University (drjava@rice.edu) * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the names of DrJava, the JavaPLT group, Rice University, nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * This software is Open Source Initiative approved Open Source Software. * Open Source Initative Approved is a trademark of the Open Source Initiative. * * This file is part of DrJava. Download the current version of this project * from http://www.drjava.org/ or http://sourceforge.net/projects/drjava/ * * END_COPYRIGHT_BLOCK*/ package edu.rice.cs.drjava.ui; import java.awt.*; import java.awt.datatransfer.*; import java.awt.event.*; import java.io.File; import java.util.HashSet; import java.util.LinkedList; import java.lang.ref.WeakReference; import javax.swing.*; import javax.swing.event.*; import javax.swing.text.*; import edu.rice.cs.drjava.DrJava; import edu.rice.cs.drjava.config.*; import edu.rice.cs.drjava.model.AbstractDJDocument; import edu.rice.cs.drjava.model.SingleDisplayModel; import edu.rice.cs.drjava.model.OpenDefinitionsDocument; import edu.rice.cs.drjava.model.FindReplaceMachine; import edu.rice.cs.drjava.model.FindResult; import edu.rice.cs.drjava.model.ClipboardHistoryModel; import edu.rice.cs.drjava.model.OrderedDocumentRegion; import edu.rice.cs.drjava.model.MovingDocumentRegion; import edu.rice.cs.drjava.model.RegionManager; import edu.rice.cs.drjava.model.FileMovedException; import edu.rice.cs.plt.lambda.Runnable1; import edu.rice.cs.plt.lambda.Thunk; import edu.rice.cs.util.StringOps; import edu.rice.cs.util.UnexpectedException; import edu.rice.cs.util.swing.BorderlessScrollPane; import edu.rice.cs.util.swing.Utilities; import edu.rice.cs.util.text.AbstractDocumentInterface; import edu.rice.cs.util.text.SwingDocument; /** The tabbed panel that handles requests for finding and replacing text. * @version $Id: FindReplacePanel.java 4634 2008-08-07 23:20:47Z dlsmith $ */ class FindReplacePanel extends TabbedPanel implements ClipboardOwner { /* Other bracketing options: * solid circle u25CF or u26AB (fails) * half circles u25D6 (fails), u25D7 * diamond u2666 * block arrows u25BA, u25C4 * big block arrows u25B6, u25C0 * enclosing wedges u25E4, u25E5 * small solid square u25FE * fisheye u25C9 */ public static final char LEFT = '\u25FE'; public static final char RIGHT = '\u25FE'; private JButton _findNextButton; private JButton _findPreviousButton; private JButton _findAllButton; private JButton _replaceButton; private JButton _replaceFindNextButton; private JButton _replaceFindPreviousButton; private JButton _replaceAllButton; private JTextPane _findField; private JTextPane _replaceField; private JLabel _findLabelBot; // Dynamically updated private JCheckBox _ignoreCommentsAndStrings; private JCheckBox _matchCase; private JCheckBox _searchAllDocuments; private JCheckBox _matchWholeWord; private JCheckBox _ignoreTestCases; /* MainFrame _frame is inherited from TabbedPanel */ private FindReplaceMachine _machine; private SingleDisplayModel _model; private DefinitionsPane _defPane = null; private boolean _caretChanged; /** Listens for changes to the cursor position in order to reset the start position */ private CaretListener _caretListener = new CaretListener() { public void caretUpdate(CaretEvent e) { _replaceAction.setEnabled(false); _replaceFindNextAction.setEnabled(false); _replaceFindPreviousAction.setEnabled(false); _machine.positionChanged(); _caretChanged = true; } }; /** The action performed when searching forwards */ private Action _findNextAction = new AbstractAction("Find Next") { public void actionPerformed(ActionEvent e) { findNext(); } }; private Action _findPreviousAction = new AbstractAction("Find Previous") { public void actionPerformed(ActionEvent e) { findPrevious(); } }; private Action _findAllAction = new AbstractAction("Find All") { public void actionPerformed(final ActionEvent e) { _findAll(); } }; private Action _doFindAction = new AbstractAction("Do Find") { public void actionPerformed(ActionEvent e) { _doFind(); } }; private Action _replaceAction = new AbstractAction("Replace") { public void actionPerformed(ActionEvent e) { _replace(); } }; private Action _replaceFindNextAction = new AbstractAction("Replace/Find Next") { public void actionPerformed(ActionEvent e) { _replaceFindNext(); } }; private Action _replaceFindPreviousAction = new AbstractAction("Replace/Find Previous") { public void actionPerformed(ActionEvent e) { _replaceFindPrevious(); }; }; /** Replaces all occurences of the findfield text with that of the replacefield text both before and after the cursor * without prompting for wrapping around the end of the document. */ private Action _replaceAllAction = new AbstractAction("Replace All") { public void actionPerformed(ActionEvent e) { _replaceAll(); } }; // Inserts '\n' into a text field. (The default binding for "enter" is to insert // the system-specific newline string (I think), which causes trouble when finding // in files with different newline strings.) // TODO: Standardize on \n in a post-processing step, rather than mucking around // in the workings of a text editor field. (Notice, for example, that this // doesn't correctly handle an 'enter' pressed while some text is selected.) Action _standardNewlineAction = new TextAction("Newline Action") { public void actionPerformed(ActionEvent e) { JTextComponent c = getTextComponent(e); String text = c.getText(); int caretPos = c.getCaretPosition(); String textBeforeCaret = text.substring(0, caretPos); String textAfterCaret = text.substring(caretPos); c.setText(textBeforeCaret.concat("\n").concat(textAfterCaret)); c.setCaretPosition(caretPos+1); } }; /*private Action _closeAction = new AbstractAction("X") { public void actionPerformed(ActionEvent e) { // removeTab automatically calls show() _close(); } };*/ /** Standard Constructor. * @param frame the overall enclosing window * @param model the model containing the documents to search */ public FindReplacePanel(MainFrame frame, SingleDisplayModel model) { super(frame, "Find/Replace"); _model = model; _machine = new FindReplaceMachine(_model, _model.getDocumentIterator()); // _updateMachine(); /********* Button Initialization ********/ _findNextButton = new JButton(_findNextAction); _findPreviousButton = new JButton(_findPreviousAction); _findAllButton = new JButton(_findAllAction); _replaceButton = new JButton(_replaceAction); _replaceFindNextButton = new JButton(_replaceFindNextAction); _replaceFindPreviousButton = new JButton(_replaceFindPreviousAction); _replaceAllButton = new JButton(_replaceAllAction); _replaceAction.setEnabled(false); _replaceFindNextAction.setEnabled(false); _replaceFindPreviousAction.setEnabled(false); /********* Find/Replace Field Initialization **********/ _findField = new JTextPane(new DefaultStyledDocument()); _replaceField = new JTextPane(new SwingDocument()); // Ignore special treatment of 'tab' in text panes int tabForward = KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS; int tabBackward = KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS; _findField.setFocusTraversalKeys(tabForward, null); _replaceField.setFocusTraversalKeys(tabForward, null); _findField.setFocusTraversalKeys(tabBackward, null); _replaceField.setFocusTraversalKeys(tabBackward, null); // Define custom key bindings for 'enter' and 'tab' KeyStroke enter = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0); KeyStroke ctrlEnter = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, Event.CTRL_MASK); KeyStroke ctrlTab = KeyStroke.getKeyStroke(KeyEvent.VK_TAB, Event.CTRL_MASK); InputMap findIM = _findField.getInputMap(); InputMap replaceIM = _replaceField.getInputMap(); findIM.put(enter, "Do Find"); findIM.put(ctrlEnter, "Insert Newline"); findIM.put(ctrlTab, "Insert Tab"); findIM.put(DrJava.getConfig().getSetting(OptionConstants.KEY_CUT), "Cut"); findIM.put(DrJava.getConfig().getSetting(OptionConstants.KEY_COPY), "Copy"); replaceIM.put(enter, "Insert Newline"); replaceIM.put(ctrlEnter, "Insert Newline"); replaceIM.put(ctrlTab, "Insert Tab"); replaceIM.put(DrJava.getConfig().getSetting(OptionConstants.KEY_CUT), "Cut"); replaceIM.put(DrJava.getConfig().getSetting(OptionConstants.KEY_COPY), "Copy"); Action insertTabAction = new DefaultEditorKit.InsertTabAction(); ActionMap findAM = _findField.getActionMap(); ActionMap replaceAM = _replaceField.getActionMap(); findAM.put("Do Find", _doFindAction); findAM.put("Insert Newline", _standardNewlineAction); findAM.put("Insert Tab", insertTabAction); findAM.put("Cut", cutAction); findAM.put("Copy", copyAction); replaceAM.put("Insert Newline", _standardNewlineAction); replaceAM.put("Insert Tab", insertTabAction); replaceAM.put("Cut", cutAction); replaceAM.put("Copy", copyAction); // Setup color listeners. new ForegroundColorListener(_findField); new BackgroundColorListener(_findField); new ForegroundColorListener(_replaceField); new BackgroundColorListener(_replaceField); Font font = DrJava.getConfig().getSetting(OptionConstants.FONT_MAIN); setFieldFont(font); /******** Label Initializations ********/ // Create the Structure for the replace label JLabel _replaceLabelTop = new JLabel("Replace", SwingConstants.RIGHT); JLabel _replaceLabelBot = new JLabel("With", SwingConstants.RIGHT); JPanel replaceLabelPanelTop = new JPanel(new BorderLayout(5,5)); JPanel replaceLabelPanelBot = new JPanel(new BorderLayout(5,5)); JPanel replaceLabelPanel = new JPanel(new GridLayout(2,1)); replaceLabelPanelTop.add(_replaceLabelTop, BorderLayout.SOUTH); replaceLabelPanelBot.add(_replaceLabelBot, BorderLayout.NORTH); replaceLabelPanel.add(replaceLabelPanelTop); replaceLabelPanel.add(replaceLabelPanelBot); // Create the stucture for the find label JLabel _findLabelTop = new JLabel("Find", SwingConstants.RIGHT); _findLabelBot = new JLabel("Next", SwingConstants.RIGHT); JPanel findLabelPanelTop = new JPanel(new BorderLayout(5,5)); JPanel findLabelPanelBot = new JPanel(new BorderLayout(5,5)); JPanel findLabelPanel = new JPanel(new GridLayout(2,1)); findLabelPanelTop.add(_findLabelTop, BorderLayout.SOUTH); findLabelPanelBot.add(_findLabelBot, BorderLayout.NORTH); findLabelPanel.add(findLabelPanelTop); findLabelPanel.add(findLabelPanelBot); /******** Button Panel ********/ JPanel buttons = new JPanel(); buttons.setLayout(new GridLayout(1,0,5,0)); buttons.add(_findNextButton); buttons.add(_findPreviousButton); buttons.add(_findAllButton); buttons.add(_replaceFindNextButton); buttons.add(_replaceFindPreviousButton); buttons.add(_replaceButton); buttons.add(_replaceAllButton); /******** Listeners for the right-hand check boxes ********/ boolean matchCaseSelected = DrJava.getConfig().getSetting(OptionConstants.FIND_MATCH_CASE); _matchCase = new JCheckBox("Match Case", matchCaseSelected); _machine.setMatchCase(matchCaseSelected); _matchCase.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { boolean isSelected = (e.getStateChange() == ItemEvent.SELECTED); _machine.setMatchCase(isSelected); DrJava.getConfig().setSetting(OptionConstants.FIND_MATCH_CASE, isSelected); _findField.requestFocusInWindow(); } }); boolean searchAllSelected = DrJava.getConfig().getSetting(OptionConstants.FIND_ALL_DOCUMENTS); _searchAllDocuments = new JCheckBox("Search All Documents", searchAllSelected); _machine.setSearchAllDocuments(searchAllSelected); _searchAllDocuments.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { boolean isSelected = (e.getStateChange() == ItemEvent.SELECTED); _machine.setSearchAllDocuments(isSelected); DrJava.getConfig().setSetting(OptionConstants.FIND_ALL_DOCUMENTS, isSelected); _findField.requestFocusInWindow(); } }); boolean matchWordSelected = DrJava.getConfig().getSetting(OptionConstants.FIND_WHOLE_WORD); _matchWholeWord = new JCheckBox("Whole Word", matchWordSelected); if (matchWordSelected) { _machine.setMatchWholeWord(); } else { _machine.setFindAnyOccurrence(); } _matchWholeWord.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { boolean isSelected = (e.getStateChange() == ItemEvent.SELECTED); if (isSelected) { _machine.setMatchWholeWord(); } else { _machine.setFindAnyOccurrence(); } DrJava.getConfig().setSetting(OptionConstants.FIND_WHOLE_WORD, isSelected); _findField.requestFocusInWindow(); } }); boolean ignoreCommentsSelected = DrJava.getConfig().getSetting(OptionConstants.FIND_NO_COMMENTS_STRINGS); _ignoreCommentsAndStrings = new JCheckBox("No Comments/Strings", ignoreCommentsSelected); _machine.setIgnoreCommentsAndStrings(ignoreCommentsSelected); _ignoreCommentsAndStrings.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { boolean isSelected = (e.getStateChange() == ItemEvent.SELECTED); _machine.setIgnoreCommentsAndStrings(isSelected); DrJava.getConfig().setSetting(OptionConstants.FIND_NO_COMMENTS_STRINGS, isSelected); _findField.requestFocusInWindow(); } }); boolean ignoreTestCasesSelected = DrJava.getConfig().getSetting(OptionConstants.FIND_NO_TEST_CASES); _ignoreTestCases = new JCheckBox("No Test Cases", ignoreTestCasesSelected); _ignoreTestCases.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { boolean isSelected = (e.getStateChange() == ItemEvent.SELECTED); DrJava.getConfig().setSetting(OptionConstants.FIND_NO_TEST_CASES, isSelected); _findField.requestFocusInWindow(); } }); // We choose not to preserve backwards searching between sessions //_machine.setSearchBackwards(DrJava.getConfig().getSetting(OptionConstants.FIND_SEARCH_BACKWARDS)); /******** Initialize the panels containing the checkboxes ********/ this.removeAll(); // actually, override the behavior of TabbedPanel // remake closePanel _closePanel = new JPanel(new BorderLayout()); _closePanel.add(_closeButton, BorderLayout.NORTH); JPanel _lowerCheckPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0)); _lowerCheckPanel.add(_matchWholeWord); _lowerCheckPanel.add(_ignoreCommentsAndStrings); _lowerCheckPanel.setMaximumSize(new Dimension(200, 40)); JPanel _matchCaseAndAllDocsPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0)); _matchCase.setPreferredSize(_matchWholeWord.getPreferredSize()); _matchCaseAndAllDocsPanel.add(_matchCase); _matchCaseAndAllDocsPanel.add(_searchAllDocuments); _matchCaseAndAllDocsPanel.setMaximumSize(new Dimension(200, 40)); JPanel _ignoreTestCasesPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0)); _ignoreTestCasesPanel.add(_ignoreTestCases); _ignoreTestCasesPanel.setMaximumSize(new Dimension(200, 40)); BorderlessScrollPane _findPane = new BorderlessScrollPane(_findField); BorderlessScrollPane _replacePane = new BorderlessScrollPane(_replaceField); _findPane.setHorizontalScrollBarPolicy(BorderlessScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); _replacePane.setHorizontalScrollBarPolicy(BorderlessScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); JPanel findPanel = new JPanel(new BorderLayout(5,5)); findPanel.add(findLabelPanel, BorderLayout.WEST); findPanel.add(_findPane, BorderLayout.CENTER); JPanel replacePanel = new JPanel(new BorderLayout(5,5)); replacePanel.add(replaceLabelPanel, BorderLayout.WEST); replacePanel.add(_replacePane, BorderLayout.CENTER); /******** Set up the Panel containing the Text Fields ********/ JPanel leftPanel = new JPanel(new GridLayout(1,2,5,5)); leftPanel.add(findPanel); leftPanel.add(replacePanel); /******** Set up the Panel containing both rows of checkboxes ********/ GridBagLayout gbLayout = new GridBagLayout(); GridBagConstraints c = new GridBagConstraints(); JPanel emptyPanel = new JPanel(); JPanel optionsPanel = new JPanel(gbLayout); optionsPanel.setLayout(gbLayout); optionsPanel.add(_matchCaseAndAllDocsPanel); optionsPanel.add(_lowerCheckPanel); optionsPanel.add(_ignoreTestCasesPanel); optionsPanel.add(emptyPanel); c.fill = GridBagConstraints.HORIZONTAL; c.anchor = GridBagConstraints.NORTH; c.gridwidth = GridBagConstraints.REMAINDER; c.weightx = 1.0; gbLayout.setConstraints(_matchCaseAndAllDocsPanel, c); gbLayout.setConstraints(_lowerCheckPanel, c); gbLayout.setConstraints(_ignoreTestCasesPanel, c); c.fill = GridBagConstraints.BOTH; c.anchor = GridBagConstraints.SOUTH; c.gridheight = GridBagConstraints.REMAINDER; c.weighty = 1.0; gbLayout.setConstraints(emptyPanel, c); /******** Set up the Panel containing the two above main panels ********/ JPanel midPanel = new JPanel(new BorderLayout(5,5)); midPanel.add(leftPanel, BorderLayout.CENTER); midPanel.add(optionsPanel, BorderLayout.EAST); /******** Set up the Panel containing the midPanel and the closePanel ********/ JPanel _rightPanel = new JPanel(new BorderLayout(5, 5)); _rightPanel.add(midPanel, BorderLayout.CENTER); _rightPanel.add(_closePanel, BorderLayout.EAST); JPanel newPanel = new JPanel(); newPanel.setLayout(new BoxLayout(newPanel, BoxLayout.Y_AXIS)); newPanel.add(_rightPanel); newPanel.add(Box.createVerticalStrut(5)); newPanel.add(buttons); newPanel.add(Box.createVerticalStrut(5)); this.add(newPanel); /******** Document, Focus and Key Listeners ********/ // DocumentListener that keeps track of changes in the find field. _findField.getDocument().addDocumentListener(new DocumentListener() { /** If attributes in the find field have changed, gray out "Replace" & "Replace and Find Next" buttons. * Assumes all updates are performed in the event thread. * @param e the event caught by this listener */ public void changedUpdate(DocumentEvent e) { _updateHelper(); } /** If text has been changed in the find field, gray out "Replace" & "Replace and Find Next" buttons. * @param e the event caught by this listener */ public void insertUpdate(DocumentEvent e) { _updateHelper(); } /** If text has been changed in the find field, gray out "Replace" & "Replace and Find Next" buttons. * @param e the event caught by this listener */ public void removeUpdate(DocumentEvent e) { _updateHelper(); } private void _updateHelper() { // _machine.makeCurrentOffsetStart(); updateFirstDocInSearch(); _replaceAction.setEnabled(false); _replaceFindNextAction.setEnabled(false); _replaceFindPreviousAction.setEnabled(false); _machine.positionChanged(); if (_findField.getText().equals("")) _replaceAllAction.setEnabled(false); else _replaceAllAction.setEnabled(true); updateUI(); } }); } /** Focuses the find/replace dialog in the window, placing the focus on the _findField, and selecting all the text.*/ public boolean requestFocusInWindow() { super.requestFocusInWindow(); _findField.selectAll(); return _findField.requestFocusInWindow(); } /** Getter method for the _findField component */ JTextPane getFindField() { return _findField; } /** Performs "find all" command. */ private void _findAll() { _machine.setSearchBackwards(false); _findLabelBot.setText("Next"); String searchStr = _findField.getText(); String title = searchStr; OpenDefinitionsDocument startDoc = _defPane.getOpenDefDocument(); boolean searchAll = _machine.getSearchAllDocuments(); // StringBuilder tabLabel = new StringBuilder("Find: "); // if (title.length() <= 10) tabLabel.append(title); // else tabLabel.append(title.substring(0,10)).append("..."); String tabLabel = (title.length() <= 20) ? title : title.substring(0,20); RegionManager<MovingDocumentRegion> rm = _model.createFindResultsManager(); final FindResultsPanel panel = _frame.createFindResultsPanel(rm, tabLabel, searchStr, searchAll, _machine.getMatchCase(), _machine.getMatchWholeWord(), _machine.getIgnoreCommentsAndStrings(), _ignoreTestCases.isSelected(), new WeakReference<OpenDefinitionsDocument>(startDoc), this); findAll(searchStr, searchAll, _machine.getMatchCase(), _machine.getMatchWholeWord(), _machine.getIgnoreCommentsAndStrings(), _ignoreTestCases.isSelected(), startDoc, rm, panel); // _model.refreshActiveDocument(); // Rationale: a giant findAll left the definitions pane is a strange state panel.requestFocusInWindow(); EventQueue.invokeLater(new Runnable() { public void run() { panel._regTree.scrollRowToVisible(0); } }); } /** Performs "find all" with the specified options. */ public void findAll(String searchStr, final boolean searchAll, final boolean matchCase, final boolean wholeWord, final boolean noComments, final boolean noTestCases, final OpenDefinitionsDocument startDoc, final RegionManager<MovingDocumentRegion> rm, final FindResultsPanel panel) { int searchLen = searchStr.length(); if (searchLen == 0) return; _frame.updateStatusField("Finding All"); OpenDefinitionsDocument oldDoc = _machine.getDocument(); OpenDefinitionsDocument oldFirstDoc = _machine.getFirstDoc(); String oldFindWord = _machine.getFindWord(); boolean oldSearchAll = _machine.getSearchAllDocuments(); boolean oldMatchCase = _machine.getMatchCase(); boolean oldWholeWord = _machine.getMatchWholeWord(); boolean oldNoComments = _machine.getIgnoreCommentsAndStrings(); boolean oldNoTestCases = _machine.getIgnoreTestCases(); int oldPosition = _machine.getCurrentOffset(); // _updateMachine(); _machine.setDocument(startDoc); if (_machine.getFirstDoc() == null) _machine.setFirstDoc(startDoc); _machine.setSearchAllDocuments(searchAll); _machine.setMatchCase(matchCase); if (wholeWord) { _machine.setMatchWholeWord(); } else { _machine.setFindAnyOccurrence(); } _machine.setIgnoreCommentsAndStrings(noComments); _machine.setPosition(startDoc.getCurrentLocation()); _machine.setIgnoreTestCases(noTestCases); _machine.setFindWord(searchStr); String replaceStr = _replaceField.getText(); _machine.setReplaceWord(replaceStr); _frame.clearStatusMessage(); final LinkedList<FindResult> results = new LinkedList<FindResult>(); _frame.hourglassOn(); try { /* Accumulate all occurrences of searchStr in results. */ final int count = _machine.processAll(new Runnable1<FindResult>() { public void run(FindResult fr) { results.add(fr); } }); _machine.setDocument(oldDoc); _machine.setFirstDoc(oldFirstDoc); _machine.setFindWord(oldFindWord); _machine.setSearchAllDocuments(oldSearchAll); _machine.setMatchCase(oldMatchCase); if (oldWholeWord) { _machine.setMatchWholeWord(); } else { _machine.setFindAnyOccurrence(); } _machine.setIgnoreCommentsAndStrings(oldNoComments); _machine.setIgnoreTestCases(oldNoTestCases); _machine.setPosition(oldPosition); // Utilities.show("Searching complete"); // Set of documents that have been reverted in the process of "find all" // HashSet<OpenDefinitionsDocument> reverted = new HashSet<OpenDefinitionsDocument>(); // panel.startChanging(); for (FindResult fr: results) { // if (reverted.contains(fr.getDocument())) { // // skipping document because we have previously noticed that it has been modified, // // i.e. the document is in the reverted list // continue; // } // // get the original time stamp // long origts = fr.getDocument().getTimestamp(); final OpenDefinitionsDocument doc = fr.getDocument(); if (_model.getActiveDocument() != doc) _model.setActiveDocument(doc); else _model.refreshActiveDocument(); int end = fr.getFoundOffset(); int start = end - searchLen; try { final Position startPos = doc.createPosition(start); final Position endPos = doc.createPosition(end); // lazily create excerpt string Thunk<String> ss = new Thunk<String>() { public String value() { try { int endSel = endPos.getOffset(); int startSel = startPos.getOffset(); int selLength = endSel - startSel; if (selLength == 0) return ""; // excerpt has been deleted by prior editing assert selLength > 0; int excerptEnd = doc._getLineEndPos(endSel); int excerptStart = doc._getLineStartPos(startSel); assert excerptStart <= startSel; // the offsets within the excerpted string of the selection (figuratively in "Red") int startRed = startSel - excerptStart; int endRed = endSel - excerptStart; int excerptLength = Math.min(120, excerptEnd - excerptStart); String text = doc.getText(excerptStart, excerptLength); // Construct the matching string and compressed selection prefix and suffix strings within text String prefix = StringOps.compress(text.substring(0, startRed)); String match, suffix; if (excerptLength < startRed + selLength) { // selection extends beyond excerpt match = text.substring(startRed) + "..."; suffix = ""; } else { match = text.substring(startRed, endRed); suffix = StringOps.compress(text.substring(endRed, excerptLength)); } // COMMENT: We need a global invariant concerning non-displayable characters. // create the excerpt string StringBuilder sb = new StringBuilder(edu.rice.cs.plt.text.TextUtil.htmlEscape(prefix)); sb.append("<font color=#ff0000>"); // sb.append(LEFT); sb.append(edu.rice.cs.plt.text.TextUtil.htmlEscape(match)); sb.append("</font>"); // sb.append(RIGHT); sb.append(edu.rice.cs.plt.text.TextUtil.htmlEscape(suffix)); // sb.append("</html>"); // sb.append(StringOps.getBlankString(120 - sLength)); // move getBank to StringOps return sb.toString(); } catch(BadLocationException e) { return ""; /* Ignore the exception. */ } } }; rm.addRegion(new MovingDocumentRegion(doc, doc.getFile(), startPos, endPos, ss)); // rm.addRegion(new MovingDocumentRegion(doc, doc.getFile(), startPos, endPos, s)); } catch (FileMovedException fme) { throw new UnexpectedException(fme); } catch (BadLocationException ble) { throw new UnexpectedException(ble); } } // panel.finishChanging(); EventQueue.invokeLater(new Runnable() { public void run() { if (count > 0) _frame.showFindResultsPanel(panel); else { Toolkit.getDefaultToolkit().beep(); panel.freeResources(); } _frame.setStatusMessage("Found " + count + " occurrence" + ((count == 1) ? "" : "s") + "."); } }); } finally { _frame.hourglassOff(); // extracted from run() above because findAll occasionally left active document in inconsistent state _model.setActiveDocument(startDoc); } } /** Performs the "replace all" command. */ private void _replaceAll() { _frame.updateStatusField("Replacing All"); // _updateMachine(); _machine.setFindWord(_findField.getText()); _machine.setReplaceWord(_replaceField.getText()); _frame.clearStatusMessage(); int count = _machine.replaceAll(); Toolkit.getDefaultToolkit().beep(); _frame.setStatusMessage("Replaced " + count + " occurrence" + ((count == 1) ? "" : "s") + "."); _replaceAction.setEnabled(false); _replaceFindNextAction.setEnabled(false); _replaceFindPreviousAction.setEnabled(false); _model.refreshActiveDocument(); // Rationale: a giant replaceAll left the definitions pane is a strange state } private void _replaceFindNext() { _frame.updateStatusField("Replacing and Finding Next"); if (isSearchBackwards() == true) { _machine.positionChanged(); findNext(); } _updateMachine(); _machine.setFindWord(_findField.getText()); final String replaceWord = _replaceField.getText(); _machine.setReplaceWord(replaceWord); _frame.clearStatusMessage(); // _message.setText(""); // JL // replaces the occurrence at the current position boolean replaced = _machine.replaceCurrent(); // and finds the next word if (replaced) { _selectFoundOrReplacedItem(replaceWord.length()); findNext(); _replaceFindNextButton.requestFocusInWindow(); } else { _replaceAction.setEnabled(false); _replaceFindNextAction.setEnabled(false); _replaceFindPreviousAction.setEnabled(false); Toolkit.getDefaultToolkit().beep(); _frame.setStatusMessage("Replace failed."); } } private void _replaceFindPrevious() { _frame.updateStatusField("Replacing and Finding Previous"); if (isSearchBackwards() == false) { _machine.positionChanged(); findPrevious(); } _updateMachine(); _machine.setFindWord(_findField.getText()); final String replaceWord = _replaceField.getText(); _machine.setReplaceWord(replaceWord); _frame.clearStatusMessage(); // replaces the occurrence at the current position boolean replaced = _machine.replaceCurrent(); // and finds the previous word if (replaced) { _selectFoundOrReplacedItem(replaceWord.length()); findPrevious(); _replaceFindPreviousButton.requestFocusInWindow(); } else { _replaceAction.setEnabled(false); _replaceFindNextAction.setEnabled(false); _replaceFindPreviousAction.setEnabled(false); Toolkit.getDefaultToolkit().beep(); _frame.setStatusMessage("Replace failed."); } } /** Performs the "find next" command. Package visibility to accommodate calls from MainFrame. */ void findNext() { _frame.updateStatusField("Finding Next"); _machine.setSearchBackwards(false); _findLabelBot.setText("Next"); _doFind(); // updates position stored in machine before starting _defPane.requestFocusInWindow(); // moves focus to DefinitionsPane } /** Called when user the activates "find previous" command. Package visibility to accommodate calls from MainFrame. */ void findPrevious() { _frame.updateStatusField("Finding Previous"); _machine.setSearchBackwards(true); _findLabelBot.setText("Prev"); _doFind(); _defPane.requestFocusInWindow(); // moves focus to DefinitionsPane } private void _replace() { _frame.updateStatusField("Replacing"); // _updateMachine(); _machine.setFindWord(_findField.getText()); final String replaceWord = _replaceField.getText(); _machine.setReplaceWord(replaceWord); _frame.clearStatusMessage(); // replaces the occurrence at the current position boolean replaced = _machine.replaceCurrent(); if (replaced) _selectFoundOrReplacedItem(replaceWord.length()); _replaceAction.setEnabled(false); _replaceFindNextAction.setEnabled(false); _replaceFindPreviousAction.setEnabled(false); _replaceButton.requestFocusInWindow(); } /** Called from MainFrame in response to opening this or changes in the active document. */ void beginListeningTo(DefinitionsPane defPane) { if (_defPane == null) { // removed so it doesn't give the pane focus when switching documents // requestFocusInWindow(); _displayed = true; _defPane = defPane; _defPane.addCaretListener(_caretListener); _caretChanged = true; _updateMachine(); _machine.setFindWord(_findField.getText()); _machine.setReplaceWord(_replaceField.getText()); _frame.clearStatusMessage(); // _message.setText(""); // JL if (! _machine.onMatch() || _findField.getText().equals("")) { _replaceAction.setEnabled(false); _replaceFindNextAction.setEnabled(false); _replaceFindPreviousAction.setEnabled(false); } else { _replaceAction.setEnabled(true); _replaceFindNextAction.setEnabled(true); _replaceFindPreviousAction.setEnabled(true); _machine.setLastFindWord(); } if (_findField.getText().equals("")) _replaceAllAction.setEnabled(false); else _replaceAllAction.setEnabled(true); _frame.clearStatusMessage(); } else throw new UnexpectedException(new RuntimeException("FindReplacePanel should not be listening to anything")); } /** Called from MainFrame upon closing this Dialog or changes in the active document. */ public void stopListening() { if (_defPane != null) { _defPane.removeCaretListener(_caretListener); _defPane = null; _displayed = false; _frame.clearStatusMessage(); } } /** Abstracted out since this is called from findNext and findPrevious. */ private void _doFind() { if (_findField.getText().length() > 0) { _updateMachine(); final String findWord = _findField.getText(); _machine.setFindWord(findWord); _machine.setReplaceWord(_replaceField.getText()); _frame.clearStatusMessage(); // _message.setText(""); // JL final boolean searchAll = _machine.getSearchAllDocuments(); // FindResult contains the document that the result was found in, offset to the next occurrence of // the string, and a flag indicating whether the end of the document was wrapped around while searching // for the string. _frame.hourglassOn(); try { FindResult fr = _machine.findNext(); OpenDefinitionsDocument matchDoc = fr.getDocument(); // OpenDefinitionsDocument matchDoc = _model.getODDForDocument(doc); OpenDefinitionsDocument openDoc = _defPane.getOpenDefDocument(); final boolean docChanged = matchDoc != openDoc; final int pos = fr.getFoundOffset(); if (pos >= 0) _model.addToBrowserHistory(); // pos >= 0 <=> search succeeded if (searchAll) { // if search was global, reset the active document if (docChanged) _model.setActiveDocument(matchDoc); // set active doc if matchDoc != openDoc else _model.refreshActiveDocument(); // the unmodified active document may have been kicked out of the cache! } if (fr.getWrapped() && ! searchAll) { Toolkit.getDefaultToolkit().beep(); if (! _machine.isSearchBackwards()) _frame.setStatusMessage("Search wrapped to beginning."); else _frame.setStatusMessage("Search wrapped to end."); } if (fr.getAllWrapped() && searchAll) { Toolkit.getDefaultToolkit().beep(); _frame.setStatusMessage("Search wrapped around all documents."); } if (pos >= 0) { // found a match // Caret c = _defPane.getCaret(); // c.setDot(c.getDot()); _defPane.setCaretPosition(pos); _caretChanged = true; _updateMachine(); final Runnable command = new Runnable() { public void run() { _selectFoundOrReplacedItem(findWord.length()); _replaceAction.setEnabled(true); _replaceFindNextAction.setEnabled(true); _replaceFindPreviousAction.setEnabled(true); _machine.setLastFindWord(); _model.addToBrowserHistory(); } }; if (docChanged) // defer executing this code until after active document switch is complete EventQueue.invokeLater(command); else command.run(); } // else the entire document was searched and no instance of the string // was found. display at most 50 characters of the non-found string else { Toolkit.getDefaultToolkit().beep(); final StringBuilder statusMessage = new StringBuilder("Search text \""); if (findWord.length() <= 50) statusMessage.append(findWord); else statusMessage.append(findWord.substring(0, 49) + "..."); statusMessage.append("\" not found."); _frame.setStatusMessage(statusMessage.toString()); } } finally { _frame.hourglassOff(); } } if (! DrJava.getConfig().getSetting(OptionConstants.FIND_REPLACE_FOCUS_IN_DEFPANE).booleanValue()) { _findField.requestFocusInWindow(); } } protected void _close() { _defPane.requestFocusInWindow(); if (_displayed) stopListening(); super._close(); //_frame.uninstallFindReplaceDialog(this); } public void setSearchBackwards(boolean b) { _machine.setSearchBackwards(b); } public boolean isSearchBackwards() { return _machine.isSearchBackwards(); } /** Sets the font of the find and replace fields to f. */ public void setFieldFont(Font f) { _findField.setFont(f); _replaceField.setFont(f); } /** Updates the first document where the current all-document search began (called in two places: either when the * _findField is updated, or when the user changes documents. */ public void updateFirstDocInSearch() { _machine.setFirstDoc(_model.getActiveDocument()); } // private static Container wrap(JComponent comp) { // Container stretcher = Box.createHorizontalBox(); // stretcher.add(comp); // stretcher.add(Box.createHorizontalGlue()); // return stretcher; // } // // /** Consider a parent container. Change its layout to GridBagLayout // * with 2 columns, 2 rows. Consider them quadrants in a coordinate plain. // * put the arguments in their corresponding quadrants, ignoring q3. // */ // private static void hookComponents(Container parent, JComponent q1, // JComponent q2, JComponent q4) { // GridBagLayout gbl = new GridBagLayout(); // GridBagConstraints c = new GridBagConstraints(); // parent.setLayout(gbl); // c.fill = c.BOTH; // addComp(parent, q2, c, gbl, 0, 0, 0f, 0f, 1, 0); // addComp(parent, q1, c, gbl, 0, 1, 1f, 0f, 1, 0); // addComp(parent, new JPanel(), c, gbl, 1, 0, 1f, 1f, 2, 0); // addComp(parent, new JPanel(), c, gbl, 2, 0, 0f, 0f, 1, 0); // addComp(parent, q4, c, gbl, 2, 1, 1f, 0f, 1, 0); // } // private static void addComp(Container p, JComponent child, // GridBagConstraints c, GridBagLayout gbl, // int row, int col, // float weightx, float weighty, int gridw, // int ipady) { // c.gridx = col; c.gridy = row; // c.weightx = weightx; c.weighty = weighty; // c.gridwidth = gridw; // c.ipady = ipady; // gbl.setConstraints(child,c); // p.add(child); // } /** Sets appropriate variables in the FindReplaceMachine if the caret has been changed. */ private void _updateMachine() { if (_caretChanged) { OpenDefinitionsDocument doc = _model.getActiveDocument(); _machine.setDocument(doc); if (_machine.getFirstDoc() == null) _machine.setFirstDoc(doc); // _machine.setStart(_defPane.getCaretPosition()); _machine.setPosition(_defPane.getCaretPosition()); _caretChanged = false; } } // /** Shows the dialog and sets the focus appropriately. */ // public void show() { // //super.show(); // System.err.println("*** Called show ***"); //// if (!isVisible()) // _frame.installFindReplaceDialog(this); // _updateMachine(); // _findField.requestFocusInWindow(); // _findField.selectAll(); // } /** This method is used to select the item that has been inserted in a replacement. Assumes the current offset * identifies the found or replaced item. In a forward search, this offset is the RIGHT edge of the found/replaced * item; in a backwards search it is the LEFT edge. */ private void _selectFoundOrReplacedItem(int length) { int offset = _machine.getCurrentOffset(); int from, to; if (_machine.isSearchBackwards()) { from = offset + length; // "to" is the offset where the caret will be positioned // when searching backwards, "to" has to be the smaller offset to = offset; } else { from = offset - length; to = offset; } _selectFoundOrReplacedItem(from, to); } // /** Calls _selectFoundItem(from, to) with reasonable defaults. */ // private void _selectFoundItem() { // int position = _machine.getCurrentOffset(); // int to, from; // to = from = position; // if (! _machine.getSearchBackwards()) from = position - _machine.getFindWord().length(); // else to = position + _machine.getFindWord().length(); // _selectFoundItem(from, to); // } /** Will select the identified text (from, to). Note that positions are technically between characters, so there * is no distinction between open and closed intervals. Originally highlighted the text, but we ran into problems * with the document remove method changing the view to where the cursor was located, resulting in * replace constantly jumping from the replaced text back to the cursor. There was a * removePreviousHighlight method which was removed since selections are removed automatically upon * a caret change. */ private void _selectFoundOrReplacedItem(int from, int to) { _defPane.centerViewOnOffset(from); _defPane.select(from, to); // Found this little statement that will show the selected text in _defPane without giving _defPane // focus, allowing the user to hit enter repeatedly and change the document while finding next. EventQueue.invokeLater(new Runnable() { public void run() { _defPane.getCaret().setSelectionVisible(true); } }); // _defPane.centerViewOnOffset(from); } // private void _close() { hide(); } // public void hide() { // System.err.println("*** Called hide ***"); // if (_open) // _frame.uninstallFindReplaceDialog(this); // //super.hide(); // } // private ContinueCommand CONFIRM_CONTINUE = new ContinueCommand() { // public boolean shouldContinue() { // String text = "The search has reached the end of the document.\n" + // "Continue searching from the start?"; // int rc = JOptionPane.showConfirmDialog(FindReplacePanel.this, // text, // "Continue search?", // JOptionPane.YES_NO_OPTION); // // switch (rc) { // case JOptionPane.YES_OPTION: // return true; // case JOptionPane.NO_OPTION: // return false; // default: // throw new RuntimeException("Invalid rc: " + rc); // } // // } // }; /** We lost ownership of what we put in the clipboard. */ public void lostOwnership(Clipboard clipboard, Transferable contents) { // ignore } /** Default cut action. */ Action cutAction = new DefaultEditorKit.CutAction() { public void actionPerformed(ActionEvent e) { if (e.getSource() instanceof JTextComponent) { JTextComponent tc = (JTextComponent)e.getSource(); if (tc.getSelectedText() != null) { super.actionPerformed(e); String s = edu.rice.cs.util.swing.Utilities.getClipboardSelection(FindReplacePanel.this); if (s != null && s.length() != 0){ ClipboardHistoryModel.singleton().put(s); } } } } }; /** Default copy action. */ Action copyAction = new DefaultEditorKit.CopyAction() { public void actionPerformed(ActionEvent e) { if (e.getSource() instanceof JTextComponent) { JTextComponent tc = (JTextComponent)e.getSource(); if (tc.getSelectedText() != null) { super.actionPerformed(e); String s = edu.rice.cs.util.swing.Utilities.getClipboardSelection(FindReplacePanel.this); if (s != null && s.length() != 0) { ClipboardHistoryModel.singleton().put(s); } } } } }; /***************** METHODS FOR TESTING PURPOSES ONLY ***********************/ public DefinitionsPane getDefPane() { return _defPane; } public JButton getFindNextButton() {return _findNextButton; } }

The table below shows all metrics for FindReplacePanel.java.

MetricValueDescription
BLOCKS99.00Number of blocks
BLOCK_COMMENT53.00Number of block comment lines
COMMENTS267.00Comment lines
COMMENT_DENSITY 0.42Comment density
COMPARISONS44.00Number of comparison operators
CYCLOMATIC104.00Cyclomatic complexity
DECL_COMMENTS113.00Comments in declarations
DOC_COMMENT62.00Number of javadoc comment lines
ELOC640.00Effective lines of code
EXEC_COMMENTS70.00Comments in executable code
EXITS140.00Procedure exits
FUNCTIONS52.00Number of function declarations
HALSTEAD_DIFFICULTY94.79Halstead difficulty
HALSTEAD_EFFORT 0.00Halstead effort
INTERFACE_COMPLEXITY98.00Interface complexity
JAVA0001 0.00JAVA0001 Package name does not contain only lower case letters
JAVA0002 0.00JAVA0002 Package name does not begin with a top level domain name or country code
JAVA0003 0.00JAVA0003 Minimize use of on-demand (.*) imports
JAVA0004 0.00JAVA0004 Unnecessary import from java.lang
JAVA0005 1.00JAVA0005 Imports not in specified order
JAVA0006 0.00JAVA0006 Empty finally block
JAVA0007 0.00JAVA0007 Should not declare public field
JAVA0008 0.00JAVA0008 Empty catch block
JAVA0009 0.00JAVA0009 Protected member in final class
JAVA0010 0.00JAVA0010 Non-instantiable class does not contain a non-private static member
JAVA0011 0.00JAVA0011 Abstract class does not contain an abstract method
JAVA0012 0.00JAVA0012 Non-constructor method with same name as declaring class
JAVA0013 0.00JAVA0013 Non-blank final field is not static
JAVA0014 0.00JAVA0014 Class with only static members has non-private constructor
JAVA0015 0.00JAVA0015 Package class contains public nested type
JAVA0016 0.00JAVA0016 Abstract class contains public constructor
JAVA0017 0.00JAVA0017 Class name does not have required form
JAVA001811.00JAVA0018 Method name does not have required form
JAVA0019 0.00JAVA0019 Interface name does not have required form
JAVA002029.00JAVA0020 Field name does not have required form
JAVA0021 0.00JAVA0021 Interface method name does not have required form
JAVA0022 0.00JAVA0022 Static final field name does not have required form
JAVA0023 0.00JAVA0023 Empty finalize method
JAVA0024 0.00JAVA0024 Empty class
JAVA0025 0.00JAVA0025 Method override is empty
JAVA0026 0.00JAVA0026 Finalize method with parameters
JAVA0029 0.00JAVA0029 Private method not used
JAVA0030 0.00JAVA0030 Private field not used
JAVA0031 0.00JAVA0031 Case statement not properly closed
JAVA0032 0.00JAVA0032 Switch statement missing default
JAVA0033 0.00JAVA0033 default: not last case in switch statement
JAVA003423.00JAVA0034 Missing braces in if statement
JAVA0035 0.00JAVA0035 Missing braces in for statement
JAVA0036 0.00JAVA0036 Missing braces in while statement
JAVA0038 0.00JAVA0038 Non-case label in switch statement
JAVA0039 0.00JAVA0039 Break statement with label
JAVA0040 0.00JAVA0040 Switch statement contains N cases (maximum: M)
JAVA0041 0.00JAVA0041 Nested synchronized block
JAVA0042 0.00JAVA0042 Empty synchronized statement
JAVA0043 0.00JAVA0043 Inner class does not use outer class
JAVA0044 0.00JAVA0044 Serializable class with no instance variables
JAVA0045 0.00JAVA0045 Serializable class with only transient fields
JAVA0046 0.00JAVA0046 Name of class not derived from Exception ends with 'Exception'
JAVA0047 0.00JAVA0047 Serializable class derives from invalid base class
JAVA0048 0.00JAVA0048 Name of class derived from Exception does not end with 'Exception'
JAVA0049 2.00JAVA0049 Nested block at depth N (maximum: M)
JAVA0050 0.00JAVA0050 Class derives from java.lang.Error
JAVA0051 0.00JAVA0051 Class derives from java.lang.RuntimeException
JAVA0052 0.00JAVA0052 Class derives from java.lang.Throwable
JAVA0053 0.00JAVA0053 Unused label
JAVA0054 0.00JAVA0054 Inheritance depth N exceeds maximum M
JAVA0055 0.00JAVA0055 Class should be interface
JAVA0056 0.00JAVA0056 Unnecessary abstract modifier for interface or annotation
JAVA0057 0.00JAVA0057 Unnecessary default constructor
JAVA0058 0.00JAVA0058 Constructor calls super()
JAVA0059 0.00JAVA0059 Method override only calls super()
JAVA0061 0.00JAVA0061 Inaccessible member in anonymous class
JAVA0062 0.00JAVA0062 Public class missing public member or protected constructor
JAVA0063 0.00JAVA0063 Identifier name should not contain '$'
JAVA0064 0.00JAVA0064 N variations of identifier name (maximum: M)
JAVA0065 0.00JAVA0065 Unnecessary final modifier for method in final class
JAVA0066 0.00JAVA0066 Unnecessary modifier for interface nested type
JAVA0067 0.00JAVA0067 Array descriptor on identifier name
JAVA0068 0.00JAVA0068 Modifiers not declared in recommended order
JAVA0071 0.00JAVA0071 Strings compared with ==
JAVA0073 0.00JAVA0073 Integer division in floating-point context
JAVA0074 0.00JAVA0074 Use of Object.notify()
JAVA0075 0.00JAVA0075 Method parameter hides field
JAVA0076 8.00JAVA0076 Use of magic number
JAVA0077 0.00JAVA0077 Private field not used in declaring class
JAVA0078 0.00JAVA0078 Floating point values compared with ==
JAVA0079 0.00JAVA0079 Use of instance to reference static member
JAVA0080 5.00JAVA0080 Import declaration not used
JAVA0081 2.00JAVA0081 Boolean literal in comparison
JAVA0082 0.00JAVA0082 Unnecessary widening cast
JAVA0083 0.00JAVA0083 Unnecessary instanceof test
JAVA0084 0.00JAVA0084 Should use compound assignment operator
JAVA0085 0.00JAVA0085 Use of sun.* class
JAVA0087 0.00JAVA0087 Use of Thread.sleep()
JAVA0089 0.00JAVA0089 Use of restricted package
JAVA0092 0.00JAVA0092 Use of restricted type
JAVA0093 0.00JAVA0093 Redundant assignment
JAVA0094 0.00JAVA0094 Field hides a superclass field
JAVA0095 0.00JAVA0095 Uninitialized private field
JAVA0096 0.00JAVA0096 Field in nested class hides outer field
JAVA0098 0.00JAVA0098 Minimize use of implicit field initializers
JAVA0100 1.00JAVA0100 Class contains N non-final fields (maximum: M)
JAVA0101 0.00JAVA0101 Unnecessary modifier for field in interface
JAVA0102 0.00JAVA0102 Last statement in finalize() not super.finalize()
JAVA0103 0.00JAVA0103 Explicit call to finalize()
JAVA0104 0.00JAVA0104 finalize() only calls super.finalize()
JAVA0105 0.00JAVA0105 Duplicate import declaration
JAVA0106 0.00JAVA0106 Unnecessary import from current package
JAVA010814.00JAVA0108 Incorrect javadoc: no @param tag for 'parameter'
JAVA0109 0.00JAVA0109 Incorrect javadoc: no parameter 'parameter'
JAVA0110 3.00JAVA0110 Incorrect javadoc: no @return tag
JAVA0111 0.00JAVA0111 Incorrect javadoc: @return tag for void method
JAVA0112 0.00JAVA0112 Incorrect javadoc: no exception 'exception' in throws
JAVA0113 1.00JAVA0113 Incorrect javadoc: no @author tag
JAVA0114 0.00JAVA0114 Incorrect javadoc: no @version tag
JAVA0115 0.00JAVA0115 Incorrect javadoc: no @throws or @exception tag for 'exception'
JAVA0116 2.00JAVA0116 Missing javadoc: field 'field'
JAVA0117 3.00JAVA0117 Missing javadoc: method 'method'
JAVA0118 0.00JAVA0118 Missing javadoc: type 'type'
JAVA0119 0.00JAVA0119 Control variable changed within body of for loop
JAVA0123 0.00JAVA0123 Use all three components of for loop
JAVA0125 0.00JAVA0125 Continue statement with label
JAVA0126 0.00JAVA0126 Method declares unchecked exception in throws
JAVA0128 1.00JAVA0128 Public constructor in non-public class
JAVA0130 0.00JAVA0130 Non-static method does not use instance fields
JAVA0131 0.00JAVA0131 Compatible method does not override base
JAVA0132 0.00JAVA0132 Method overload with compatible signature
JAVA0133 0.00JAVA0133 Non-synchronized method overrides synchronized method
JAVA0135 0.00JAVA0135 Only one of Object.equals and Object.hashCode defined: missing 'method'
JAVA0136 1.00JAVA0136 N methods defined in class (maximum: M)
JAVA0137 0.00JAVA0137 Non-abstract class missing constructor
JAVA0138 1.00JAVA0138 N parameters defined for method (maximum: M)
JAVA0139 0.00JAVA0139 Definition of main other than public static void main(java.lang.String[])
JAVA0141 0.00JAVA0141 Unnecessary modifier for method in interface
JAVA0143 0.00JAVA0143 Synchronized method
JAVA0144 0.00JAVA0144 Line exceeds maximum M characters
JAVA0145 0.00JAVA0145 Tab character used in source file
JAVA0150 0.00JAVA0150 java.lang.Error (or subclass) thrown
JAVA0153 0.00JAVA0153 Inefficient conversion of integer to string
JAVA0159 0.00JAVA0159 Inefficient conversion of string to integer
JAVA0160 0.00JAVA0160 Method does not throw specified exception
JAVA0161 0.00JAVA0161 Conditional wait() not in loop
JAVA0163 0.00JAVA0163 Empty statement
JAVA0165 0.00JAVA0165 Conflicting return statement in finally block
JAVA0166 0.00JAVA0166 Generic exception caught
JAVA0167 0.00JAVA0167 ThreadDeath not rethrown
JAVA0169 0.00JAVA0169 Unnecessary catch block: exception 'exception'
JAVA0170 0.00JAVA0170 Caught exception not derived from java.lang.Exception
JAVA0171 0.00JAVA0171 Unused local variable
JAVA0173 0.00JAVA0173 Unused method parameter
JAVA0174 0.00JAVA0174 Assigned local variable never used
JAVA0175 0.00JAVA0175 Successive assignment to variable
JAVA0176 9.00JAVA0176 Local variable name does not have required form
JAVA0177 4.00JAVA0177 Variable declaration missing initializer
JAVA0179 0.00JAVA0179 Local variable hides visible field
JAVA0233 0.00JAVA0233 Definition of serialVersionUID other than 'private static final long serialVersionUID'
JAVA0234 1.00JAVA0234 Class is Serializable but does not define serialVersionUID
JAVA0235 0.00JAVA0235 Class defines serialVersionUID but does not implement Serializable
JAVA0236 0.00JAVA0236 Attempt to clone an object which does not implement Cloneable
JAVA0237 0.00JAVA0237 Class implements Cloneable but does not have public clone method
JAVA0238 0.00JAVA0238 Clone method does not call super.clone()
JAVA0239 0.00JAVA0239 Class declares 'readObject' or 'writeObject' but does not implement Serializable
JAVA0240 0.00JAVA0240 Serializable class which declares readObject or writeObject but not both
JAVA0241 0.00JAVA0241 'readObject' or 'writeObject' should be declared private in Serializable class
JAVA0242 0.00JAVA0242 Transient field in non-Serializable class
JAVA0243 0.00JAVA0243 'readResolve' or 'writeReplace' should be declared private or protected
JAVA0244 0.00JAVA0244 Field or method name in subclass differs only by case from inherited field or method
JAVA0245 0.00JAVA0245 JUnit TestCase with non-trivial constructor
JAVA0246 0.00JAVA0246 JUnit assertXXX statement missing message parameter
JAVA0247 0.00JAVA0247 JUnit 'setUp()' and 'tearDown()' should call super method
JAVA0248 0.00JAVA0248 JUnit method 'setUp' or 'tearDown' with incorrect signature
JAVA0249 0.00JAVA0249 JUnit TestCase 'suite()' should be declared static
JAVA0250 0.00JAVA0250 JUnit TestCase declares testXXX method with incorrect signature
JAVA0251 0.00JAVA0251 Use '%n' for line breaks in printf/format for platform independence
JAVA0252 0.00JAVA0252 'enum' is a Java 1.5 reserved word
JAVA0253 0.00JAVA0253 Not all enum constants consumed in switch statement
JAVA0254 0.00JAVA0254 Use enhanced for loop construct instead of Iterator
JAVA0255 0.00JAVA0255 Result of method invocation not used
JAVA0256 0.00JAVA0256 Assignment of external collection/array to field
JAVA0257 0.00JAVA0257 Use of 'Constant Interface' anti-pattern
JAVA0258 0.00JAVA0258 Implement Iterable for foreach compatibility
JAVA0259 0.00JAVA0259 Return of collection/array field
JAVA0260 0.00JAVA0260 Use 'enum' instead of Enumerated Type pattern
JAVA0261 0.00JAVA0261 Use specialized Enum collection types
JAVA0262 0.00JAVA0262 Use of char in integer context
JAVA0263 0.00JAVA0263 Long literal ends with 'l' instead of 'L'
JAVA0264 0.00JAVA0264 Integer math in long context - check for overflow
JAVA0265 0.00JAVA0265 Use of Throwable.printStackTrace()
JAVA0266 0.00JAVA0266 Use of System.out
JAVA0267 0.00JAVA0267 Use of System.err
JAVA0269 0.00JAVA0269 Contents of StringBuffer never used
JAVA0270 0.00JAVA0270 Use Java 5.0 enhanced for loop construct to iterate over all elements in an array
JAVA0271 0.00JAVA0271 Minimize use of on-demand (.*) static imports
JAVA0272 0.00JAVA0272 Thread.run() called
JAVA0273 0.00JAVA0273 Non-final derivative of Thread calls start() in constructor
JAVA0274 0.00JAVA0274 Serializable class has a synchronized readObject()
JAVA0275 0.00JAVA0275 Serializable class has a synchronized writeObject() and no other synchronized methods
JAVA0276 0.00JAVA0276 Unnecessary use of String constructor
JAVA0277 0.00JAVA0277 Iterator.next() implementation does not throw NoSuchElementException
JAVA0278 0.00JAVA0278 Unnecessary use of Boolean constructor
JAVA0279 0.00JAVA0279 Serialization method readObject or readObjectNoData calls an overridable method
JAVA0280 0.00JAVA0280 IllegalMonitorStateException caught
JAVA0281 0.00JAVA0281 Iterator.next() not called in loop
JAVA0282 0.00JAVA0282 Call to Iterator.next() in loop which does not test Iterator.hasNext()
JAVA0283 0.00JAVA0283 Control variable not updated in loop body
JAVA0284 0.00JAVA0284 Explicit garbage collection
JAVA0285 0.00JAVA0285 Dereference of potentially null variable
JAVA0286 0.00JAVA0286 Dereference of null variable
JAVA0287 0.00JAVA0287 Unnecessary null check
JAVA0288 0.00JAVA0288 Inconsistent null check
LINES1127.00Number of lines in the source file
LINE_COMMENT152.00Number of line comments
LOC706.00Lines of code
LOGICAL_LINES542.00Number of statements
LOOPS 0.00Number of loops
NEST_DEPTH 7.00Maximum nesting depth
OPERANDS2111.00Number of operands
OPERATORS3716.00Number of operators
PARAMS40.00Number of formal parameter declarations
PROGRAM_LENGTH5827.00Halstead program length
PROGRAM_VOCAB631.00Halstead program vocabulary
PROGRAM_VOLUME 0.00Halstead program volume
RETURNS58.00Number of return points from functions
SIZE47743.00Size of the file in bytes
UNIQUE_OPERANDS579.00Number of unique operands
UNIQUE_OPERATORS52.00Number of unique operators
WHITESPACE154.00Number of whitespace lines