GlobalModelTestCase.java

Index Score
edu.rice.cs.drjava.model
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
FUNCTIONSNumber of function declarations
RETURNSNumber of return points from functions
INTERFACE_COMPLEXITYInterface complexity
PARAMSNumber of formal parameter declarations
LINE_COMMENTNumber of line comments
EXEC_COMMENTSComments in executable code
BLOCKSNumber of blocks
CYCLOMATICCyclomatic complexity
SIZESize of the file in bytes
UNIQUE_OPERANDSNumber of unique operands
JAVA0117JAVA0117 Missing javadoc: method 'method'
DECL_COMMENTSComments in declarations
PROGRAM_VOCABHalstead program vocabulary
LOGICAL_LINESNumber of statements
OPERATORSNumber of operators
PROGRAM_LENGTHHalstead program length
JAVA0115JAVA0115 Incorrect javadoc: no @throws or @exception tag for 'exception'
ELOCEffective lines of code
JAVA0020JAVA0020 Field name does not have required form
LOCLines of code
OPERANDSNumber of operands
LINESNumber of lines in the source file
EXITSProcedure exits
JAVA0034JAVA0034 Missing braces in if statement
JAVA0108JAVA0108 Incorrect javadoc: no @param tag for 'parameter'
JAVA0126JAVA0126 Method declares unchecked exception in throws
JAVA0160JAVA0160 Method does not throw specified exception
WHITESPACENumber of whitespace lines
JAVA0143JAVA0143 Synchronized method
JAVA0110JAVA0110 Incorrect javadoc: no @return tag
JAVA0266JAVA0266 Use of System.out
JAVA0245JAVA0245 JUnit TestCase with non-trivial constructor
COMMENTSComment lines
JAVA0036JAVA0036 Missing braces in while statement
JAVA0166JAVA0166 Generic exception caught
JAVA0051JAVA0051 Class derives from java.lang.RuntimeException
JAVA0136JAVA0136 N methods defined in class (maximum: M)
JAVA0024JAVA0024 Empty class
UNIQUE_OPERATORSNumber of unique operators
JAVA0118JAVA0118 Missing javadoc: type 'type'
JAVA0018JAVA0018 Method name does not have required form
PROGRAM_VOLUMEHalstead program volume
COMPARISONSNumber of comparison operators
JAVA0100JAVA0100 Class contains N non-final fields (maximum: M)
JAVA0074JAVA0074 Use of Object.notify()
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.model; import edu.rice.cs.drjava.DrJava; import edu.rice.cs.drjava.model.compiler.CompilerListener; import edu.rice.cs.drjava.model.repl.InteractionsDocument; import edu.rice.cs.drjava.model.junit.JUnitModel; import edu.rice.cs.drjava.ui.InteractionsController; import edu.rice.cs.util.FileOpenSelector; import edu.rice.cs.plt.io.IOUtil; import edu.rice.cs.util.FileOps; import edu.rice.cs.util.Log; import edu.rice.cs.util.OperationCanceledException; import edu.rice.cs.util.StringOps; import edu.rice.cs.util.UnexpectedException; import edu.rice.cs.util.classloader.ClassFileError; import edu.rice.cs.util.swing.Utilities; import edu.rice.cs.util.swing.AsyncTask; import edu.rice.cs.util.text.EditDocumentException; import edu.rice.cs.util.text.EditDocumentInterface; import javax.swing.text.BadLocationException; import java.io.File; import java.io.IOException; import java.rmi.UnmarshalException; import java.util.regex.*; import java.util.List; /** Base class for tests over the {@link GlobalModel}. * * This class provides a number of convenience methods for testing the GlobalModel. It also contains a model instance * (reset in {@link #setUp} and a temporary directory that's created per test invocation (and subsequently cleaned in * {@link #tearDown}. This reduces the burden for such file management stuff in the test cases themselves. * * @version $Id: GlobalModelTestCase.java 4636 2008-08-12 18:47:11Z mgricken $ */ public abstract class GlobalModelTestCase extends MultiThreadedTestCase { public static final Log _log = new Log("GlobalModel.txt", false); protected volatile DefaultGlobalModel _model; protected volatile InteractionsController _interactionsController; protected volatile File _tempDir; protected volatile OpenDefinitionsDocument _doc; // the working document in some shared set up routines protected static final String FOO_TEXT = "class DrJavaTestFoo {}"; protected static final String BAR_TEXT = "class DrJavaTestBar {}"; protected static final String BAZ_TEXT = "class DrJavaTestBaz extends DrJavaTestFoo { public static int x = 3; }"; protected static final String FOO_MISSING_CLOSE_TEXT = "class DrJavaTestFoo {"; protected static final String FOO_PACKAGE_AFTER_IMPORT = "import java.util.*;\npackage a;\n" + FOO_TEXT; protected static final String FOO_PACKAGE_INSIDE_CLASS = "class DrJavaTestFoo { package a; }"; protected static final String FOO_PACKAGE_AS_FIELD = "class DrJavaTestFoo { int package; }"; protected static final String FOO_PACKAGE_AS_FIELD_2 = "class DrJavaTestFoo { int package = 5; }"; protected static final String FOO_PACKAGE_AS_PART_OF_FIELD = "class DrJavaTestFoo { int cur_package = 5; }"; public GlobalModelTestCase() { _log.log("Constructing a " + this); } /** Setup for each test case, which does the following. * <OL> * <LI> * Creates a new GlobalModel in {@link #_model} for each test case run. * </LI> * <LI> * Creates a new temporary directory in {@link #_tempDir}. * </LI> * </OL> */ public void setUp() throws Exception { _log.log("Setting up " + this); super.setUp(); // declared to throw Exception _model = new TestGlobalModel(); // create an interactions pane which is essential to the function of the interactions model; _interactionsController = // InteractionsController constructor creates an interactions pane new InteractionsController(_model.getInteractionsModel(), _model.getSwingInteractionsDocument()); _log.log("Global model created for " + this); DrJava.getConfig().resetToDefaults(); String user = System.getProperty("user.name"); _tempDir = /* IOUtil.createAndMarkTempDirectory */ FileOps.createTempDirectory("DrJava-test-" + user /*, ""*/); // System.err.println("Temp Directory is " + _tempDir.getAbsolutePath()); // Wait until model has connected to slave JVM _log.log("Ensuring that interpreter is connected in " + this); _model._jvm.ensureInterpreterConnected(); _log.log("Ensured that intepreter is connected in " + this); _model.setResetAfterCompile(false); _log.log("Completed (GlobalModelTestCase) set up of " + this); // _model.getOpenDefinitionsDocuments().get(0).saveFile(new FileSelector(new File(_tempDir, "blank document"))); // super.setUp(); } /** Teardown for each test case, which recursively deletes the temporary directory created in setUp. */ public void tearDown() throws Exception { _log.log("Tearing down " + this); // System.err.println("Tearing down " + this); _model.dispose(); /*boolean ret =*/ IOUtil.deleteOnExitRecursively(_tempDir); //assertTrue("delete temp directory " + _tempDir, ret); _tempDir = null; _model = null; super.tearDown(); _log.log("Completed tear down of " + this); // System.err.println("Completed tear down of " + this); } /** Clear all old text and insert the given text. */ protected void changeDocumentText(final String s, final OpenDefinitionsDocument doc) /*throws BadLocationException */{ Utilities.invokeAndWait(new Runnable() { public void run() { try{ doc.clear(); assertLength(0, doc); doc.append(s, null); assertModified(true, doc); assertContents(s, doc); } catch(BadLocationException e) { throw new UnexpectedException(e); } } }); } /** Create a new temporary file in _tempDir. */ protected File tempFile() throws IOException { File f = File.createTempFile("DrJava-test", ".java", _tempDir).getCanonicalFile(); // System.err.println("temp file created with name " + f); return f; } /** Create a new temporary file in _tempDir. Calls with the same int will return the same filename, while calls * with different ints will return different filenames. */ protected File tempFile(int i) throws IOException { return File.createTempFile("DrJava-test" + i, ".java", _tempDir).getCanonicalFile(); } /** Create a new temporary directory in _tempDir. */ protected File tempDirectory() throws IOException { return IOUtil.createAndMarkTempDirectory("DrJava-test", "", _tempDir); } protected File createFile(String name) { return new File(_tempDir, name); } /** Given a .java file and a class file name, returns the corresponding .class file. */ protected File classForJava(File sourceFile, String className) { assertTrue(sourceFile.getName().endsWith(".java")); String cname = className + ".class"; return new File(sourceFile.getParent(), cname); } /** Creates a new temporary file and writes the given text to it. * The File object for the new file is returned. */ protected File writeToNewTempFile(String text) throws IOException { File temp = tempFile(); IOUtil.writeStringToFile(temp, text); return temp; } /** Creates and returns a new document, makes sure newFile is fired, and then adds some text. When this method is * done newCount is reset to 0. * @return the new modified document */ protected OpenDefinitionsDocument setupDocument(String text) throws BadLocationException { TestListener listener = new TestListener() { public synchronized void newFileCreated(OpenDefinitionsDocument doc) { newCount++; } }; _model.addListener(listener); // Open a new document int numOpen = _model.getOpenDefinitionsDocuments().size(); // Utilities.invokeAndWait(new Runnable() { public void run () { _doc = _model.newFile(); // } }); assertNumOpenDocs(numOpen + 1); listener.assertNewCount(1); assertLength(0, _doc); assertModified(false, _doc); changeDocumentText(text, _doc); assertModified(true, _doc); _model.removeListener(listener); return _doc; } protected void safeLoadHistory(final FileSelector fs) { Utilities.invokeAndWait(new Runnable() { public void run() { _model.loadHistory(fs); } }); } protected void safeSaveHistory(final FileSelector fs) { Utilities.invokeAndWait(new Runnable() { public void run() { try {_model.saveHistory(fs); } catch(IOException e) { throw new UnexpectedException(e); } } }); } /** Invokes startCompile on the given document in the event thread. */ protected static void testStartCompile(final OpenDefinitionsDocument doc) { Utilities.invokeLater(new Runnable() { public void run() { try { doc.startCompile(); } catch(IOException e) { throw new UnexpectedException(); } } }); } /** Compiles a new file with the given text. The compile is expected to succeed and it is checked to make sure it * worked reasonably. This method does not return until the Interactions JVM has reset and is ready to use. * @param text Code for the class to be compiled * @param file File to save the class in * @return Document after it has been saved and compiled */ protected synchronized OpenDefinitionsDocument doCompile(String text, File file) throws IOException, BadLocationException, InterruptedException { OpenDefinitionsDocument doc = setupDocument(text); doCompile(doc, file); return doc; } /** Saves to the given file, and then compiles the given document. The compile is expected to succeed and it is * checked to make sure it worked reasonably. This method does not return until the Interactions JVM has reset * and is ready to use. * @param doc Document containing the code to be compiled * @param file File to save the class in */ protected void doCompile(final OpenDefinitionsDocument doc, File file) throws IOException, InterruptedException { saveFile(doc, new FileSelector(file)); // Perform a mindless interpretation to force interactions to reset (only to simplify this method) try { interpret("0"); } catch (EditDocumentException e) { throw new UnexpectedException(e); } Utilities.clearEventQueue(); _model.setResetAfterCompile(true); CompileShouldSucceedListener listener = new CompileShouldSucceedListener(true); _model.addListener(listener); listener.logCompileStart(); testStartCompile(doc); // Utilities.clearEventQueue(); if (_model.getCompilerModel().getNumErrors() > 0) fail("compile failed: " + getCompilerErrorString()); listener.waitCompileDone(); listener.checkCompileOccurred(); assertCompileErrorsPresent(false); listener.waitResetDone(); Utilities.clearEventQueue(); _model.removeListener(listener); } /** Returns a string with all compiler errors. */ protected String getCompilerErrorString() { final StringBuilder buf = new StringBuilder(); buf.append(" compiler error(s):\n"); buf.append(_model.getCompilerModel().getCompilerErrorModel().toString()); return buf.toString(); } /** Puts the given input into the interactions document and then interprets it, returning the result that was put * into the interactions document. This assumes the interactions document is in a state with no text after the * prompt. To be sure this is the case, you can reset interactions first. This method provides its own listener * to synchronized with the completion of the interaction. * * @param input text to interpret * @return The output from this interpretation, in String form, as it was printed to the interactions document. */ protected String interpret(final String input) throws EditDocumentException { final InteractionsDocument interactionsDoc = _model.getInteractionsDocument(); InteractionListener listener = new InteractionListener(); _model.addListener(listener); // Set up the interaction Utilities.invokeAndWait(new Runnable() { public void run() { interactionsDoc.setInProgress(false); // for some reason, the inProgress state can be true when interpret is invoked interactionsDoc.append(input, InteractionsDocument.DEFAULT_STYLE); } }); // Record information about pending interaction final int newLineLen = 1; // Was StringOps.EOL.length(); but Swing uses '\n' for newLine final int resultsStartLocation = interactionsDoc.getLength() + newLineLen; // Utilities.clearEventQueue(); listener.logInteractionStart(); // Execute the interaction Utilities.invokeLater(new Runnable() { public void run() { _model.interpretCurrentInteraction(); } }); try { listener.waitInteractionDone(); } catch (InterruptedException ie) { throw new UnexpectedException(ie); } Utilities.clearEventQueue(); _model.removeListener(listener); listener.assertInteractionStartCount(1); listener.assertInteractionEndCount(1); // skip the right length for the newline final int resultsEndLocation = interactionsDoc.getLength() - newLineLen - interactionsDoc.getPrompt().length(); final int resultsLen = resultsEndLocation - resultsStartLocation; _log.log("resultsStartLoc = " + resultsStartLocation + " resultsEndLocation = " + resultsEndLocation); _log.log("Contents = '" + interactionsDoc.getDocText(0, resultsEndLocation+1) + "'"); if (resultsLen <= 0) return ""; return interactionsDoc.getDocText(resultsStartLocation, resultsLen); } /** Appends the input string to the interactions pane and interprets it. */ protected void interpretIgnoreResult(String input) throws EditDocumentException { InteractionsDocument interactionsDoc = _model.getInteractionsDocument(); interactionsDoc.append(input, InteractionsDocument.DEFAULT_STYLE); try { _model.interpretCurrentInteraction(); } catch(RuntimeException re) { // On Windows, UnmarshalExceptions are sometime thrown Throwable cause = re.getCause(); if (! (cause instanceof UnmarshalException)) throw re; // otherwise ignore } } /** Asserts that the given string exists in the Interactions Document. */ protected void assertInteractionsContains(String text) throws EditDocumentException { _assertInteractionContainsHelper(text, true); } /** Asserts that the given string does not exist in the Interactions Document. */ protected void assertInteractionsDoesNotContain(String text) throws EditDocumentException { _assertInteractionContainsHelper(text, false); } private void _assertInteractionContainsHelper(String text, boolean shouldContain) throws EditDocumentException { String interactText = getInteractionsText(); int contains = interactText.lastIndexOf(text); assertTrue("Interactions document should " + (shouldContain ? "" : "not ") + "contain:\n" + text + "\nActual contents of Interactions document:\n" + interactText, (contains != -1) == shouldContain); } /** Asserts that the text in the Interactions Document matches the given regex. */ protected void assertInteractionsMatches(String regex) throws EditDocumentException { _assertInteractionMatchesHelper(regex, true); } /** Asserts that the text in the Interactions Document does NOT match the given regex. */ protected void assertInteractionsDoesNotMatch(String regex) throws EditDocumentException { _assertInteractionMatchesHelper(regex, false); } private void _assertInteractionMatchesHelper(String regex, boolean shouldMatch) throws EditDocumentException { String interactText = getInteractionsText(); boolean matches = Pattern.compile(regex, Pattern.MULTILINE|Pattern.DOTALL).matcher(interactText).matches(); assertTrue("Interactions document should " + (shouldMatch ? "" : "not ") + "match:\n" + regex + "\nActual contents of Interactions document:\n" + interactText, matches == shouldMatch); } /** Returns the current contents of the interactions document */ protected String getInteractionsText() throws EditDocumentException { InteractionsDocument doc = _model.getInteractionsDocument(); return doc.getText(); } protected void assertNumOpenDocs(int num) { assertEquals("number of open documents", num, _model.getOpenDefinitionsDocuments().size()); } protected void assertModified(boolean b, OpenDefinitionsDocument doc) { assertEquals("document isModifiedSinceSave", b, doc.isModifiedSinceSave()); } protected void assertLength(int len, OpenDefinitionsDocument doc) { assertEquals("document length", len, doc.getLength()); } protected void assertContents(String s, OpenDefinitionsDocument doc) throws BadLocationException { assertEquals("document contents", s, doc.getText()); } /** Invokes doc.saveFile from within the event thread. */ protected void saveFile(final OpenDefinitionsDocument doc, final FileSaveSelector fss) { Utilities.invokeAndWait(new Runnable() { public void run() { try { doc.saveFile(fss); } catch(Exception e) { throw new UnexpectedException(e); } } }); } /** Invokes doc.saveFileAs from within the event thread. */ protected void saveFileAs(final OpenDefinitionsDocument doc, final FileSaveSelector fss) { Utilities.invokeAndWait(new Runnable() { public void run() { try { doc.saveFileAs(fss); } catch(Exception e) { throw new UnexpectedException(e); } } }); } protected void saveAllFiles(final GlobalModel model, final FileSaveSelector fs) { Utilities.invokeAndWait(new Runnable() { public void run() { try { model.saveAllFiles(fs); } // this should save the files as file1,file2,file3 respectively catch(Exception e) { throw new UnexpectedException(e); } } }); } protected void assertCompileErrorsPresent(boolean b) { assertCompileErrorsPresent("", b); } protected void assertCompileErrorsPresent(String name, boolean b) { //CompilerError[] errors = _model.getCompileErrors(); int numErrors = _model.getCompilerModel().getNumErrors(); if (name.length() > 0) name += ": "; //StringBuffer buf = new StringBuffer(); //for (int i = 0; i < errors.length; i++) { // buf.append("\nerror #" + i + ": " + errors[i]); //} assertEquals(name + "compile errors > 0? numErrors =" + numErrors, b, numErrors > 0); } // These exceptions are specially used only in this test case. // They are used to verify that the code blocks public static class OverwriteException extends RuntimeException{ } public static class OpenWarningException extends RuntimeException{ } public static class FileMovedWarningException extends RuntimeException{ } public static class WarningFileSelector implements FileOpenSelector, FileSaveSelector { private volatile File _file; public WarningFileSelector(File f) { _file = f; } public File getFile() throws OperationCanceledException { return _file; } public File[] getFiles() throws OperationCanceledException { return new File[] {_file}; } public boolean warnFileOpen(File f) { throw new OpenWarningException(); } public boolean verifyOverwrite() { throw new OverwriteException(); } public boolean shouldSaveAfterFileMoved(OpenDefinitionsDocument doc, File oldFile) { throw new FileMovedWarningException(); } } /** This class is used by several test cases in Compile Tests that expect incorrect behavior concerning the saving * of files. This special FileSelector is included to ensure compliance with these test cases, for which the * intricacies of saving files are unimportant. The only FileSelector that honest-to-supreme-deity matters is * is DefaultGlobalModel.ConcreteOpenDefDoc, which is much more like WarningFileSelector */ public static class FileSelector implements FileOpenSelector, FileSaveSelector { private volatile File _file1, _file2; public FileSelector(File f) { _file1 = f; } public FileSelector(File f1, File f2) { _file1 = f1; _file2 = f2; } public File getFile() throws OperationCanceledException { return _file1; } public File[] getFiles() throws OperationCanceledException { if (_file2 != null) return new File[] {_file1, _file2}; else return new File[] {_file1}; } public boolean warnFileOpen(File f) { return true; } public boolean verifyOverwrite() { return true; } public boolean shouldSaveAfterFileMoved(OpenDefinitionsDocument doc, File oldFile) { return true; } } public static class CancelingSelector implements FileOpenSelector, FileSaveSelector { public File getFile() throws OperationCanceledException { throw new OperationCanceledException(); } public File[] getFiles() throws OperationCanceledException { throw new OperationCanceledException(); } public boolean warnFileOpen(File f) { return true; } public boolean verifyOverwrite() {return true; } public boolean shouldSaveAfterFileMoved(OpenDefinitionsDocument doc, File oldFile) { return true; } } /** A GlobalModelListener for testing. By default it expects no events to be fired. To customize, * subclass and override one or more methods. */ public static class TestListener implements GlobalModelListener { /** Remembers when this listener was created. */ protected volatile Exception _startupTrace; protected volatile int fileNotFoundCount; protected volatile int newCount; protected volatile int openCount; protected volatile int closeCount; protected volatile int saveCount; protected volatile int canAbandonCount; protected volatile int quitFileCount; protected volatile int classFileErrorCount; protected volatile int compileStartCount; protected volatile int compileEndCount; protected volatile int activeCompilerChangedCount; protected volatile int runStartCount; protected volatile int junitStartCount; protected volatile int junitSuiteStartedCount; protected volatile int junitTestStartedCount; protected volatile int junitTestEndedCount; protected volatile int junitEndCount; protected volatile int interactionStartCount; protected volatile int interactionEndCount; protected volatile int interactionErrorCount; protected volatile int interpreterResettingCount; protected volatile int interpreterReadyCount; protected volatile int interpreterExitedCount; protected volatile int interpreterResetFailedCount; protected volatile int interpreterChangedCount; //protected int interactionCaretPositionChangedCount; protected volatile int consoleResetCount; protected volatile int saveBeforeCompileCount; //protected int saveBeforeRunCount; protected volatile int compileBeforeJUnitCount; protected volatile int saveBeforeJavadocCount; //protected int saveBeforeDebugCount; protected volatile int nonTestCaseCount; protected volatile int lastExitStatus; protected volatile int fileRevertedCount; protected volatile int shouldRevertFileCount; protected volatile int undoableEditCount; protected volatile int interactionIncompleteCount; protected volatile int filePathContainsPoundCount; public TestListener() { _startupTrace = new Exception(); resetCounts(); } public synchronized void resetCounts() { fileNotFoundCount = 0; newCount = 0; openCount = 0; closeCount = 0; saveCount = 0; canAbandonCount = 0; quitFileCount = 0; classFileErrorCount = 0; compileStartCount = 0; compileEndCount = 0; activeCompilerChangedCount = 0; runStartCount = 0; junitStartCount = 0; junitSuiteStartedCount = 0; junitTestStartedCount = 0; junitTestEndedCount = 0; junitEndCount = 0; interactionStartCount = 0; interactionEndCount = 0; interactionErrorCount = 0; interpreterChangedCount = 0; //interactionCaretPositionChangedCount = 0; consoleResetCount = 0; interpreterResettingCount = 0; interpreterReadyCount = 0; interpreterExitedCount = 0; interpreterResetFailedCount = 0; saveBeforeCompileCount = 0; //saveBeforeRunCount = 0; compileBeforeJUnitCount = 0; saveBeforeJavadocCount = 0; //saveBeforeDebugCount = 0; nonTestCaseCount = 0; lastExitStatus = 0; fileRevertedCount = 0; shouldRevertFileCount = 0; undoableEditCount = 0; interactionIncompleteCount = 0; filePathContainsPoundCount = 0; } public void projectModified() { } public void openProject(File pfile, FileOpenSelector files) { } public void projectClosed() { } public void projectBuildDirChanged() { } public void projectWorkDirChanged() { } public void projectRunnableChanged() { } public void currentDirectoryChanged(File dir) { } /** Appends the stack trace from the listener's creation to the end of the given failure message. */ public void listenerFail(String message) { String header = "\nTestListener creation stack trace:\n" + StringOps.getStackTrace(_startupTrace); MultiThreadedTestCase.listenerFail(message + header); } public void assertFileNotFoundCount(int i) { assertEquals("number of times fileNotFound fired", i, fileNotFoundCount); } public void assertAbandonCount(int i) { assertEquals("number of times canAbandon fired", i, canAbandonCount); } public void assertQuitFileCount(int i) { assertEquals("number of times quitFile fired", i, quitFileCount); } public void assertClassFileErrorCount(int i) { assertEquals("number of times classFileError fired", i, classFileErrorCount); } public void assertNewCount(int i) { assertEquals("number of times newFile fired", i, newCount); } public void assertOpenCount(int i) { assertEquals("number of times openFile fired", i, openCount); } public void assertCloseCount(int i) { assertEquals("number of times closeFile fired", i, closeCount); } public void assertSaveCount(int i) { assertEquals("number of times saveFile fired", i, saveCount); } public void assertJUnitStartCount(int i) { assertEquals("number of times junitStarted fired", i, junitStartCount); } public void assertJUnitSuiteStartedCount(int i) { assertEquals("number of times junitSuiteStarted fired", i, junitSuiteStartedCount); } public void assertJUnitTestStartedCount(int i) { assertEquals("number of times junitTestStarted fired", i, junitTestStartedCount); } public void assertJUnitTestEndedCount(int i) { assertEquals("number of times junitTestEnded fired", i, junitTestEndedCount); } public void assertJUnitEndCount(int i) { assertEquals("number of times junitEnded fired", i, junitEndCount); } public void assertInteractionStartCount(int i) { assertEquals("number of times interactionStarted fired", i, interactionStartCount); } public void assertInteractionEndCount(int i) { assertEquals("number of times interactionEnded fired", i, interactionEndCount); } public void assertInteractionErrorCount(int i) { assertEquals("number of times interactionError fired", i, interactionErrorCount ); } public void assertInterpreterChangedCount(int i) { assertEquals("number of times interpreterChanged fired", i, interpreterChangedCount); } // /** Not used */ // public void assertInteractionCaretPositionChangedCount(int i) { // assertEquals("number of times interactionCaretPositionChanged fired", i, interactionCaretPositionChangedCount); // } public void assertCompileStartCount(int i) { assertEquals("number of times compileStarted fired", i, compileStartCount); } public void assertCompileEndCount(int i) { assertEquals("number of times compileEnded fired", i, compileEndCount); } public void assertActiveCompilerChangedCount(int i) { assertEquals("number of times activeCompilerChanged fired", i, activeCompilerChangedCount); } public void assertRunStartCount(int i) { assertEquals("number of times prepareForRun fired", i, runStartCount); } public void assertInterpreterResettingCount(int i) { assertEquals("number of times interpreterResetting fired", i, interpreterResettingCount); } public void assertInterpreterReadyCount(int i) { assertEquals("number of times interpreterReady fired", i, interpreterReadyCount); } public void assertInterpreterResetFailedCount(int i) { assertEquals("number of times interpreterResetFailed fired", i, interpreterResetFailedCount); } public void assertInterpreterExitedCount(int i) { assertEquals("number of times interpreterExited fired", i, interpreterExitedCount); } public void assertInteractionsErrorCount(int i) { assertEquals("number of times interactionsError fired", i, interactionErrorCount); } public void assertConsoleResetCount(int i) { assertEquals("number of times consoleReset fired", i, consoleResetCount); } public void assertSaveBeforeCompileCount(int i) { assertEquals("number of times saveBeforeCompile fired", i, saveBeforeCompileCount); } // /** Not used.*/ // public void assertSaveBeforeRunCount(int i) { // assertEquals("number of times saveBeforeRun fired", i, saveBeforeRunCount); // } // public void assertCompileBeforeJUnitCount(int i) { assertEquals("number of times compileBeforeJUnit fired", i, compileBeforeJUnitCount); } public void assertSaveBeforeJavadocCount(int i) { assertEquals("number of times saveBeforeJavadoc fired", i, saveBeforeJavadocCount); } // /** Not used. */ // public void assertSaveBeforeDebugCount(int i) { // assertEquals("number of times saveBeforeDebug fired", // i, // saveBeforeDebugCount); // } public void assertNonTestCaseCount(int i) { assertEquals("number of times nonTestCase fired", i, nonTestCaseCount); } public void assertFileRevertedCount(int i) { assertEquals("number of times fileReverted fired", i, fileRevertedCount); } public void assertUndoableEditCount(int i) { assertEquals("number of times undoableEditHappened fired", i, undoableEditCount); } public void assertShouldRevertFileCount(int i) { assertEquals("number of times shouldRevertFile fired", i, shouldRevertFileCount); } public void assertInteractionIncompleteCount(int i) { assertEquals("number of times interactionIncomplete fired", i, interactionIncompleteCount); } public <P,R> void executeAsyncTask(AsyncTask<P,R> task, P param, boolean showProgress, boolean lockUI) { listenerFail("executeAswyncTask fired unexpectedly"); } public void handleAlreadyOpenDocument(OpenDefinitionsDocument doc) { listenerFail("handleAlreadyOpenDocument fired unexpectedly"); } public void newFileCreated(OpenDefinitionsDocument doc) { listenerFail("newFileCreated fired unexpectedly"); } public void filesNotFound(File... f) { listenerFail("fileNotFound fired unexpectedly"); } public File[] filesReadOnly(File... f) { listenerFail("filesReadOnly fired unexpectedly"); return f; } // Recent revision defers opening files until the document for a file is requested forcing the following comment out public void fileOpened(OpenDefinitionsDocument doc) { /* listenerFail("fileOpened fired unexpectedly"); */ } public void fileClosed(OpenDefinitionsDocument doc) { listenerFail("fileClosed fired unexpectedly"); } public void fileSaved(OpenDefinitionsDocument doc) { listenerFail("fileSaved fired unexpectedly"); } public void fileReverted(OpenDefinitionsDocument doc) { listenerFail("fileReverted fired unexpectedly"); } public void undoableEditHappened() { listenerFail("undoableEditHappened fired unexpectedly"); } public void saveBeforeCompile() { listenerFail("saveBeforeCompile fired unexpectedly"); } public void junitStarted() { listenerFail("junitStarted fired unexpectedly"); } public void junitClassesStarted() { listenerFail("junitAllStarted fired unexpectedly"); } public void junitSuiteStarted(int numTests) { listenerFail("junitSuiteStarted fired unexpectedly"); } public void junitTestStarted(String name) { listenerFail("junitTestStarted fired unexpectedly"); } public void junitTestEnded(String name, boolean wasSuccessful, boolean causedError) { listenerFail("junitTestEnded fired unexpectedly"); } public void junitEnded() { listenerFail("junitEnded fired unexpectedly"); } public void javadocStarted() { listenerFail("javadocStarted fired unexpectedly"); } public void javadocEnded(boolean success, File destDir, boolean allDocs) { listenerFail("javadocEnded fired unexpectedly"); } public void interactionStarted() { listenerFail("interactionStarted fired unexpectedly"); } public void interactionEnded() { listenerFail("interactionEnded fired unexpectedly"); } public void interactionErrorOccurred(int offset, int length) { listenerFail("interpreterErrorOccurred fired unexpectedly"); } public void interpreterChanged(boolean inProgress) { listenerFail("interpreterChanged fired unexpectedly"); } // /**Not used */ // public void interactionCaretPositionChanged(int pos) { // listenerFail("interactionCaretPosition fired unexpectedly"); // } public void compileStarted() { listenerFail("compileStarted fired unexpectedly"); } public void compileEnded(File workDir, List<? extends File> excludedFiles) { listenerFail("compileEnded fired unexpectedly"); } public void compileAborted(Exception e) { listenerFail("compileAborted fired unexpectedly"); } public void activeCompilerChanged() { listenerFail("activeCompilerChanged fired unexpectedly"); } public void prepareForRun(OpenDefinitionsDocument doc) { listenerFail("prepareForRun fired unexpectedly"); } public void interpreterResetting() { listenerFail("interpreterResetting fired unexpectedly"); } public void interpreterReady(File wd) { listenerFail("interpreterReady fired unexpectedly"); } public void interpreterExited(int status) { listenerFail("interpreterExited(" + status + ") fired unexpectedly"); } public void interpreterResetFailed(Throwable t) { listenerFail("interpreterResetFailed fired unexpectedly"); } public void slaveJVMUsed() { /* not directly tested; ignore it */ } public void consoleReset() { listenerFail("consoleReset fired unexpectedly"); } public void saveUntitled() { listenerFail("saveUntitled fired unexpectedly"); } public void compileBeforeJUnit(CompilerListener cl) { compileBeforeJUnitCount++; } public void saveBeforeJavadoc() { listenerFail("saveBeforeJavadoc fired unexpectedly"); } public void nonTestCase(boolean isTestAll) { listenerFail("nonTestCase fired unexpectedly"); } public boolean canAbandonFile(OpenDefinitionsDocument doc) { listenerFail("canAbandonFile fired unexpectedly"); throw new UnexpectedException(); } public boolean quitFile(OpenDefinitionsDocument doc) { listenerFail("quitFile fired unexpectedly"); throw new UnexpectedException(); } public void classFileError(ClassFileError e) { listenerFail("classFileError fired unexpectedly"); } public boolean shouldRevertFile(OpenDefinitionsDocument doc) { listenerFail("shouldRevertfile fired unexpectedly"); throw new UnexpectedException(); } public void interactionIncomplete() { listenerFail("interactionIncomplete fired unexpectedly"); } public void filePathContainsPound() { listenerFail("filePathContainsPound fired unexpectedly"); } public void documentNotFound(OpenDefinitionsDocument d, File f) { listenerFail("documentNotFound fired unexpectedly"); } public void activeDocumentChanged(OpenDefinitionsDocument active) { /* this event is not directly tested */ } public void activeDocumentRefreshed(OpenDefinitionsDocument active) { /* this event is not directly tested */ } public void focusOnDefinitionsPane() { /* this event is not dircectly tested */ } public void focusOnLastFocusOwner() { /* this event is not dircectly tested */ } public void browserChanged() { /* this event is not dircectly tested */ } } public static class InteractionListener extends TestListener { private volatile boolean _interactionDone = false; // records when the interaction is done private final Object _interactionLock = new Object(); // lock for _interactionDone private volatile boolean _resetDone = false; // records when the interaction is done private final Object _resetLock = new Object(); // lock for _interactionDone private volatile int _lastExitStatus = -1; /** Relying on the default constructor. */ public synchronized void interactionStarted() { interactionStartCount++; } public void interactionEnded() { // assertInteractionStartCount(1); synchronized(this) { interactionEndCount++; } synchronized(_interactionLock) { _interactionDone = true; _interactionLock.notify(); } } public void interpreterExited(int status) { // Utilities.showDebug("GlobalModelOtherTest: interpreterExited"); // assertInteractionStartCount(1); // assertInterpreterResettingCount(0); synchronized(this) { interpreterExitedCount++; _lastExitStatus = status; } synchronized(_interactionLock) { _interactionDone = true; _interactionLock.notify(); } } public void interpreterResetting() { assertInterpreterResettingCount(0); assertInterpreterReadyCount(0); synchronized(this) { interpreterResettingCount++; } } public void interpreterReady(File wd) { // Utilities.showDebug("GlobalModelOtherTest: interpreterReady"); synchronized(this) { interpreterReadyCount++; } synchronized(_resetLock) { // assertInteractionStartCount(1); // assertInterpreterExitedCount(1); // assertInterpreterResettingCount(1); // Utilities.showDebug("GlobalModelOtherTest: notifying resetDone"); _resetDone = true; _resetLock.notifyAll(); } } public void consoleReset() { assertConsoleResetCount(0); // assertCompileStartCount(1); // assertCompileEndCount(1); // don't care whether interactions or console are reset first synchronized(this) { consoleResetCount++; } } public void resetConsoleResetCount() { consoleResetCount = 0; } public void logInteractionStart() { _interactionDone = false; _resetDone = false; } public void waitInteractionDone() throws InterruptedException { synchronized(_interactionLock) { while (! _interactionDone) _interactionLock.wait(); } } public void waitResetDone() throws InterruptedException { synchronized(_resetLock) { while (! _resetDone) _resetLock.wait(); } } public int getLastExitStatus() { return _lastExitStatus; } }; /** A model listener for situations expecting a compilation to succeed. The _expectReset flag determines if interactions * are reset after a compilation. The interactionsReset() method notifies when reset has occurred. */ public static class CompileShouldSucceedListener extends InteractionListener { private volatile boolean _expectReset; private volatile boolean _compileDone = false; // records when compilaton is done private final Object _compileLock = new Object(); // lock for _compileDone public void logCompileStart() { logInteractionStart(); _compileDone = false; } public void compile(OpenDefinitionsDocument doc) throws IOException, InterruptedException { logCompileStart(); testStartCompile(doc); waitCompileDone(); } public void waitCompileDone() throws InterruptedException { synchronized(_compileLock) { while (! _compileDone) { // System.err.println("Waiting for JUnit to complete"); _compileLock.wait(); } } } private void _notifyCompileDone() { synchronized(_compileLock) { _compileDone = true; _compileLock.notifyAll(); } } /** Standard constructor. * @param expectReset Whether to listen for interactions being */ public CompileShouldSucceedListener(boolean expectReset) { _expectReset = expectReset; } public CompileShouldSucceedListener() { this(false); } // public boolean notDone() { return ! _interactionsReset; } @Override public void newFileCreated(OpenDefinitionsDocument doc) { /* ingore this operation */ } @Override public void compileStarted() { // Utilities.showDebug("compileStarted called in CSSListener"); assertCompileStartCount(0); assertCompileEndCount(0); assertActiveCompilerChangedCount(0); assertInterpreterResettingCount(0); assertInterpreterReadyCount(0); assertConsoleResetCount(0); synchronized(this) { compileStartCount++; } } @Override public void compileEnded(File workDir, List<? extends File> excludedFiles) { // Utilities.showDebug("compileEnded called in CSSListener"); assertCompileEndCount(0); assertActiveCompilerChangedCount(0); assertCompileStartCount(1); assertInterpreterResettingCount(0); assertInterpreterReadyCount(0); assertConsoleResetCount(0); synchronized(this) { compileEndCount++; } _notifyCompileDone(); } @Override public void compileAborted(Exception e) { _notifyCompileDone(); } @Override public void activeCompilerChanged() { // Utilities.showDebug("compileEnded called in CSSListener"); synchronized(this) { activeCompilerChangedCount++; } _notifyCompileDone(); } public void checkCompileOccurred() { assertCompileEndCount(1); assertActiveCompilerChangedCount(0); assertCompileStartCount(1); // if (_expectReset) { // assertInterpreterResettingCount(1); // assertInterpreterReadyCount(1); // } // else { // assertInterpreterResettingCount(0); // assertInterpreterReadyCount(0); // } // Note: console is no longer reset after a compile //assertConsoleResetCount(1); } } /** A model listener for situations expecting a compilation to fail. */ public static class CompileShouldFailListener extends TestListener { private volatile boolean _compileDone = false; // records when compilaton is done private final Object _compileLock = new Object(); // lock for _compileDone public void logCompileStart() { _compileDone = false; } public void waitCompileDone() throws InterruptedException { synchronized(_compileLock) { while (! _compileDone) { // System.err.println("Waiting for JUnit to complete"); _compileLock.wait(); } } } public void compile(OpenDefinitionsDocument doc) throws IOException, InterruptedException { logCompileStart(); testStartCompile(doc); waitCompileDone(); } private void _notifyCompileDone() { synchronized(_compileLock) { _compileDone = true; _compileLock.notify(); } } @Override public void compileStarted() { assertCompileStartCount(0); assertCompileEndCount(0); assertActiveCompilerChangedCount(0); synchronized(this) { compileStartCount++; } } @Override public void compileEnded(File workDir, List<? extends File> excludedFiles) { // Utilities.showDebug("compileEnded called in CSSListener"); assertCompileEndCount(0); assertActiveCompilerChangedCount(0); assertCompileStartCount(1); assertInterpreterResettingCount(0); assertInterpreterReadyCount(0); assertConsoleResetCount(0); synchronized(this) { compileEndCount++; } _notifyCompileDone(); } @Override public void compileAborted(Exception e) { _notifyCompileDone(); } public void checkCompileOccurred() { assertCompileEndCount(1); assertCompileStartCount(1); assertActiveCompilerChangedCount(0); } } public static class JUnitTestListener extends CompileShouldSucceedListener { protected volatile boolean _junitDone = false; protected final Object _junitLock = new Object(); // handle System.out's separately but default to outer class's printMessage value protected volatile boolean printMessages = GlobalModelJUnitTest.printMessages; /** Construct JUnitTestListener without resetting interactions */ public JUnitTestListener() { this(false, false); } public JUnitTestListener(boolean shouldResetAfterCompile) { this(shouldResetAfterCompile, false); } public JUnitTestListener(boolean shouldResetAfterCompile, boolean printListenerMessages) { super(shouldResetAfterCompile); this.printMessages = printListenerMessages; } public void logJUnitStart() { logCompileStart(); _junitDone = false; } /** Runs JUnit on doc to completion. */ public void runJUnit(OpenDefinitionsDocument doc) throws IOException, ClassNotFoundException, InterruptedException { logJUnitStart(); // System.err.println("Starting JUnit on " + doc); doc.startJUnit(); // System.err.println("JUnit Started on " + doc); waitJUnitDone(); } public void runJUnit(JUnitModel jm) throws IOException, ClassNotFoundException, InterruptedException { logJUnitStart(); // System.err.println("Starting JUnit"); jm.junitAll(); waitJUnitDone(); } public void waitJUnitDone() throws InterruptedException { synchronized(_junitLock) { while (! _junitDone) { _junitLock.wait(); } } } private void _notifyJUnitDone() { synchronized(_junitLock) { _junitDone = true; _junitLock.notify(); } } public void resetCompileCounts() { compileStartCount = 0; compileEndCount = 0; activeCompilerChangedCount = 0; } @Override public void junitStarted() { if (printMessages) System.out.println("listener.junitStarted"); synchronized(this) { junitStartCount++; } } @Override public void junitSuiteStarted(int numTests) { if (printMessages) System.out.println("listener.junitSuiteStarted, numTests = "+numTests); assertJUnitStartCount(1); synchronized(this) { junitSuiteStartedCount++; } } @Override public void junitTestStarted(String name) { if (printMessages) System.out.println(" listener.junitTestStarted, " + name); synchronized(this) { junitTestStartedCount++; } } @Override public void junitTestEnded(String name, boolean wasSuccessful, boolean causedError) { if (printMessages) System.out.println(" listener.junitTestEnded, name = " + name + " succ = " + wasSuccessful + " err = " + causedError); synchronized(this) { junitTestEndedCount++; } assertEquals("junitTestEndedCount should be same as junitTestStartedCount", junitTestEndedCount, junitTestStartedCount); } @Override public void nonTestCase(boolean isTestAll) { if (printMessages) System.out.println("listener.nonTestCase, isTestAll=" + isTestAll); synchronized(this) { nonTestCaseCount++; } _log.log("nonTestCase() called; notifying JUnitDone"); _notifyJUnitDone(); } @Override public void classFileError(ClassFileError e) { if (printMessages) System.out.println("listener.classFileError, e="+e); synchronized(this) { classFileErrorCount++; } _log.log("classFileError() called; notifying JUnitDone"); _notifyJUnitDone(); } @Override public void junitEnded() { //assertJUnitSuiteStartedCount(1); if (printMessages) System.out.println("junitEnded event!"); synchronized(this) { junitEndCount++; } _log.log("junitEnded() called; notifying JUnitDone"); _notifyJUnitDone(); } } /** Listener class for failing JUnit invocation. */ public static class JUnitNonTestListener extends JUnitTestListener { private volatile boolean _shouldBeTestAll; public JUnitNonTestListener() { this(false); } public JUnitNonTestListener(boolean shouldBeTestAll) { _shouldBeTestAll = shouldBeTestAll; } public void nonTestCase(boolean isTestAll) { synchronized(this) { nonTestCaseCount++; } assertEquals("Non test case heard the wrong value for test current/test all", _shouldBeTestAll, isTestAll); // Utilities.show("synchronizing on _junitLock"); synchronized(_junitLock) { // System.err.println("JUnit aborted as nonTestCase"); _junitDone = true; _junitLock.notify(); } } } /* A variant of DefaultGlobalModel used only for testing purposes. This variant * does not change the working directory when resetting interactions. This test class and its * descendants were written before the distinction between getWorkingDirectory and getMasterDirectory. * This method override restores the old semantics for getWorkingDirectory. The new definition breaks * some unit tests because the slave JVM keeps its working directory open until it shuts down. */ public class TestGlobalModel extends DefaultGlobalModel { public File getWorkingDirectory() { return getMasterWorkingDirectory(); } } }

The table below shows all metrics for GlobalModelTestCase.java.

MetricValueDescription
BLOCKS260.00Number of blocks
BLOCK_COMMENT41.00Number of block comment lines
COMMENTS213.00Comment lines
COMMENT_DENSITY 0.31Comment density
COMPARISONS14.00Number of comparison operators
CYCLOMATIC237.00Cyclomatic complexity
DECL_COMMENTS62.00Comments in declarations
DOC_COMMENT84.00Number of javadoc comment lines
ELOC695.00Effective lines of code
EXEC_COMMENTS56.00Comments in executable code
EXITS114.00Procedure exits
FUNCTIONS209.00Number of function declarations
HALSTEAD_DIFFICULTY69.28Halstead difficulty
HALSTEAD_EFFORT 0.00Halstead effort
INTERFACE_COMPLEXITY410.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 1.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 1.00JAVA0016 Abstract class contains public constructor
JAVA0017 0.00JAVA0017 Class name does not have required form
JAVA0018 5.00JAVA0018 Method name does not have required form
JAVA0019 0.00JAVA0019 Interface name does not have required form
JAVA002016.00JAVA0020 Field name does not have required form
JAVA0021 0.00JAVA0021 Interface method name does not have required form
JAVA0022 1.00JAVA0022 Static final field name does not have required form
JAVA0023 0.00JAVA0023 Empty finalize method
JAVA0024 3.00JAVA0024 Empty class
JAVA0025 1.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
JAVA003413.00JAVA0034 Missing braces in if statement
JAVA0035 0.00JAVA0035 Missing braces in for statement
JAVA0036 2.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 0.00JAVA0049 Nested block at depth N (maximum: M)
JAVA0050 0.00JAVA0050 Class derives from java.lang.Error
JAVA0051 3.00JAVA0051 Class derives from java.lang.RuntimeException
JAVA0052 0.00JAVA0052 Class derives from java.lang.Throwable
JAVA0053 0.00JAVA0053 Unused label
JAVA0054 2.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 5.00JAVA0074 Use of Object.notify()
JAVA0075 0.00JAVA0075 Method parameter hides field
JAVA0076 0.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 1.00JAVA0080 Import declaration not used
JAVA0081 0.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 2.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
JAVA010819.00JAVA0108 Incorrect javadoc: no @param tag for 'parameter'
JAVA0109 0.00JAVA0109 Incorrect javadoc: no parameter 'parameter'
JAVA0110 7.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
JAVA011522.00JAVA0115 Incorrect javadoc: no @throws or @exception tag for 'exception'
JAVA0116 1.00JAVA0116 Missing javadoc: field 'field'
JAVA011773.00JAVA0117 Missing javadoc: method 'method'
JAVA0118 8.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 9.00JAVA0126 Method declares unchecked exception in throws
JAVA0128 0.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 2.00JAVA0136 N methods defined in class (maximum: M)
JAVA0137 0.00JAVA0137 Non-abstract class missing constructor
JAVA0138 0.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 4.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 7.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 4.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 0.00JAVA0176 Local variable name does not have required form
JAVA0177 0.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 6.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 1.00JAVA0245 JUnit TestCase with non-trivial constructor
JAVA0246 1.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 1.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 7.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
LINES1269.00Number of lines in the source file
LINE_COMMENT88.00Number of line comments
LOC849.00Lines of code
LOGICAL_LINES497.00Number of statements
LOOPS 5.00Number of loops
NEST_DEPTH 3.00Maximum nesting depth
OPERANDS1867.00Number of operands
OPERATORS3979.00Number of operators
PARAMS160.00Number of formal parameter declarations
PROGRAM_LENGTH5846.00Halstead program length
PROGRAM_VOCAB825.00Halstead program vocabulary
PROGRAM_VOLUME 0.00Halstead program volume
RETURNS250.00Number of return points from functions
SIZE52303.00Size of the file in bytes
UNIQUE_OPERANDS768.00Number of unique operands
UNIQUE_OPERATORS57.00Number of unique operators
WHITESPACE207.00Number of whitespace lines