GlobalModelOtherTest.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
EXEC_COMMENTSComments in executable code
LINE_COMMENTNumber of line comments
JAVA0115JAVA0115 Incorrect javadoc: no @throws or @exception tag for 'exception'
RETURNSNumber of return points from functions
LOGICAL_LINESNumber of statements
JAVA0126JAVA0126 Method declares unchecked exception in throws
SIZESize of the file in bytes
OPERANDSNumber of operands
PROGRAM_LENGTHHalstead program length
JAVA0076JAVA0076 Use of magic number
OPERATORSNumber of operators
EXITSProcedure exits
UNIQUE_OPERANDSNumber of unique operands
INTERFACE_COMPLEXITYInterface complexity
PROGRAM_VOCABHalstead program vocabulary
JAVA0034JAVA0034 Missing braces in if statement
ELOCEffective lines of code
JAVA0177JAVA0177 Variable declaration missing initializer
FUNCTIONSNumber of function declarations
JAVA0117JAVA0117 Missing javadoc: method 'method'
LINESNumber of lines in the source file
LOCLines of code
JAVA0166JAVA0166 Generic exception caught
JAVA0094JAVA0094 Field hides a superclass field
PROGRAM_VOLUMEHalstead program volume
COMPARISONSNumber of comparison operators
JAVA0171JAVA0171 Unused local variable
JAVA0020JAVA0020 Field name does not have required form
WHITESPACENumber of whitespace lines
DOC_COMMENTNumber of javadoc comment lines
PARAMSNumber of formal parameter declarations
JAVA0130JAVA0130 Non-static method does not use instance fields
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.model; import java.io.*; import javax.swing.text.BadLocationException; import javax.swing.event.*; import java.util.ArrayList; import java.util.Iterator; import java.util.Vector; import edu.rice.cs.drjava.DrJava; import edu.rice.cs.drjava.config.*; import edu.rice.cs.drjava.model.repl.*; import edu.rice.cs.util.Log; import edu.rice.cs.util.UnexpectedException; import edu.rice.cs.util.text.EditDocumentException; import edu.rice.cs.util.swing.Utilities; import edu.rice.cs.plt.iter.IterUtil; import static edu.rice.cs.plt.debug.DebugUtil.debug; /** A test on the GlobalModel that does deals with everything outside of simple file operations, e.g., compile, quit. * @version $Id: GlobalModelOtherTest.java 4639 2008-08-19 02:47:41Z rcartwright $ */ public final class GlobalModelOtherTest extends GlobalModelTestCase implements OptionConstants { // _log can be inherited from GlobalModelTestCase Log _log = new Log("GlobalModelOtherTest.txt", false); private static final String FOO_CLASS = "package bar;\n" + "public class Foo {\n" + " public static void main(String[] args) {\n" + " System.out.println(\"Foo\");\n" + " }\n" + "}\n"; /** Get the canonical name of a file. If the operation fails, the test will fail. */ private File makeCanonical(File f) { try { return f.getCanonicalFile(); } catch (IOException e) { fail("Can't get a canonical path for file " + f); return null; } } /** Tests that the undoableEditHappened event is fired if the undo manager is in use. */ public void testUndoEventsOccur() /* throws BadLocationException */ { final TestListener listener = new TestListener() { public void undoableEditHappened() { undoableEditCount++; // System.err.println("undoableEditHappened call propagated to listener"); } }; final OpenDefinitionsDocument doc = _model.newFile(); Utilities.clearEventQueue(); _model.addListener(listener); // Have to add an undoable edit listener for Undo to work doc.addUndoableEditListener(new UndoableEditListener() { public void undoableEditHappened(UndoableEditEvent e) { // System.err.println("undoableEditHappened(" + e + ") called"); doc.getUndoManager().addEdit(e.getEdit()); } }); changeDocumentText("test", doc); Utilities.clearEventQueue(); // undoableEditHappened propagated using invokeLater Utilities.invokeAndWait(new Runnable() { public void run() { listener.assertUndoableEditCount(1); _model.removeListener(listener); } }); Utilities.clearEventQueue(); _log.log("testUndoEventsOccur() completed"); } /** Checks that System.exit is handled appropriately from interactions pane. */ public void testExitInteractions() throws EditDocumentException, InterruptedException { InteractionListener listener = new InteractionListener() { // public void consoleReset() { consoleResetCount++; } }; _model.addListener(listener); listener.logInteractionStart(); interpretIgnoreResult("System.exit(23);"); listener.waitInteractionDone(); listener.waitResetDone(); Utilities.clearEventQueue(); _model.removeListener(listener); // listener.assertConsoleResetCount(0); listener.assertInteractionStartCount(1); listener.assertInterpreterResettingCount(1); listener.assertInterpreterReadyCount(1); listener.assertInterpreterExitedCount(1); assertEquals("exit status", 23, listener.getLastExitStatus()); _log.log("testExitInteractions() completed"); } /** Creates a new class, compiles it and then checks that the REPL can see it. Then checks that a compiled class * file in another directory can be both accessed and extended if it is on the "extra.classpath" config option. */ public void testInteractionsCanSeeCompiledClasses() throws BadLocationException, EditDocumentException, IOException, InterruptedException { // Compile Foo OpenDefinitionsDocument doc1 = setupDocument(FOO_TEXT); File dir1 = makeCanonical(new File(_tempDir, "dir1")); dir1.mkdir(); File file1 = makeCanonical(new File(dir1, "TestFile1.java")); doCompile(doc1, file1); assertEquals("interactions result", "\"DrJavaTestFoo\"", interpret("new DrJavaTestFoo().getClass().getName()")); // Add directory 1 to extra classpath and close doc1 Vector<File> cp = new Vector<File>(); cp.add(dir1); DrJava.getConfig().setSetting(EXTRA_CLASSPATH, cp); Utilities.clearEventQueue(); _model.closeFile(doc1); // Compile Baz which extends Foo in another directory. OpenDefinitionsDocument doc2 = setupDocument(BAZ_TEXT); File dir2 = makeCanonical(new File(_tempDir, "dir2")); dir2.mkdir(); File file2 = makeCanonical(new File(dir2, "TestFile1.java")); doCompile(doc2, file2); // Ensure that Baz can use the Foo class from extra classpath assertEquals("interactions result", "\"DrJavaTestBaz\"", interpret("new DrJavaTestBaz().getClass().getName()")); // Ensure that static fields can be seen assertEquals("result of static field", "3", interpret("DrJavaTestBaz.x")); // Also ensure that Foo can be used directly assertEquals("interactions result", "\"DrJavaTestFoo\"", interpret("new DrJavaTestFoo().getClass().getName()")); _log.log("testInteractionsCanSeeCompletedClasses() completed"); } /** Compiles a new class in the default package with a mixed case name, and ensures that it can be instantiated on a * variable with an identical name (but a lowercase first letter). Catches SF bug #689026 ("DynamicJava can't handle * certain variable names") */ public void testInteractionsVariableWithLowercaseClassName() throws BadLocationException, EditDocumentException, IOException, InterruptedException { // Compile a test file OpenDefinitionsDocument doc1 = setupDocument("public class DrJavaTestClass {}"); File file1 = makeCanonical(new File(_tempDir, "DrJavaTestClass.java")); doCompile(doc1, file1); // This shouldn't cause an error (no output should be displayed) assertEquals("interactions result", "", interpret("Object drJavaTestClass = new DrJavaTestClass();")); _log.log("testInteractionsVariableWithLowercaseClassName() completed"); } /** Checks that updating a class and recompiling it is visible from the REPL. */ public void testInteractionsCanSeeChangedClass() throws BadLocationException, EditDocumentException, IOException, InterruptedException { final String text_before = "class DrJavaTestFoo { public int m() { return "; final String text_after = "; } }"; final int num_iterations = 3; File file; OpenDefinitionsDocument doc; for (int i = 0; i < num_iterations; i++) { doc = setupDocument(text_before + i + text_after); file = tempFile(i); doCompile(doc, file); assertEquals("interactions result, i=" + i, String.valueOf(i), interpret("new DrJavaTestFoo().m()")); } _log.log("testInteractionsCanSeeChangedClass() completed"); } /** Checks that an anonymous inner class can be defined in the repl! */ public void testInteractionsDefineAnonymousInnerClass() throws BadLocationException, EditDocumentException, IOException, InterruptedException { final String interface_text = "public interface I { int getValue(); }"; final File file = createFile("I.java"); OpenDefinitionsDocument doc; doc = setupDocument(interface_text); doCompile(doc, file); for (int i = 0; i < 3; i++) { String s = "new I() { public int getValue() { return " + i + "; } }.getValue()"; assertEquals("interactions result, i=" + i, String.valueOf(i), interpret(s)); } _log.log("testInteractionsDefineAnonymousInnerClass() completed"); } public void testGetSourceRootDefaultPackage() throws BadLocationException, IOException { // Get source root (current directory only) Iterable<File> roots = _model.getSourceRootSet(); assertEquals("number of source roots", 0, IterUtil.sizeOf(roots)); // Create temp directory File baseTempDir = tempDirectory(); // Now make subdirectory a/b/c File subdir = makeCanonical(new File(baseTempDir, "a")); subdir = makeCanonical(new File(subdir, "b")); subdir = makeCanonical(new File(subdir, "c")); subdir.mkdirs(); // Save the footext to DrJavaTestFoo.java in the subdirectory File fooFile = makeCanonical(new File(subdir, "DrJavaTestFoo.java")); OpenDefinitionsDocument doc = setupDocument(FOO_TEXT); saveFileAs(doc, new FileSelector(fooFile)); // No events should fire _model.addListener(new TestListener()); // Get source roots roots = _model.getSourceRootSet(); assertEquals("number of source roots", 1, IterUtil.sizeOf(roots)); // Get the source root for the new file in directory subdir assertEquals("source root", subdir, IterUtil.first(roots)); _log.log("testGetSourceRootDefaultPackage() completed"); } public void testGetSourceRootPackageThreeDeepValid() throws BadLocationException, IOException { // Create temp directory File baseTempDir = tempDirectory(); // Now make subdirectory a/b/c File subdir = makeCanonical(new File(baseTempDir, "a")); subdir = makeCanonical(new File(subdir, "b").getCanonicalFile()); subdir = makeCanonical(new File(subdir, "c").getCanonicalFile()); subdir.mkdirs(); // Save the footext to DrJavaTestFoo.java in the subdirectory File fooFile = makeCanonical(new File(subdir, "DrJavaTestFoo.java")); OpenDefinitionsDocument doc = setupDocument("package a.b.c;\n" + FOO_TEXT); saveFileAs(doc, new FileSelector(fooFile)); // System.err.println("Package name is: " + _model.getPackageName()); // No events should fire _model.addListener(new TestListener()); // Since we had the package statement the source root should be base dir Iterable<File> roots = _model.getSourceRootSet(); assertEquals("number of source roots", 1, IterUtil.sizeOf(roots)); assertEquals("source root", baseTempDir.getCanonicalFile(), IterUtil.first(roots).getCanonicalFile()); _log.log("testGetSourceRootPackageThreeDeepValid() completed"); } /** Tests that getSourceRoot works with a relative path when a package name is present. */ public void testGetSourceRootPackageThreeDeepValidRelative() throws BadLocationException, IOException { // Create temp directory File baseTempDir = tempDirectory(); File subdir = makeCanonical(new File(baseTempDir, "a")); subdir = makeCanonical(new File(subdir, "b")); subdir = makeCanonical(new File(subdir, "c")); subdir.mkdirs(); // Save the footext to DrJavaTestFoo.java in a relative directory // temp/./a/b/../b/c == temp/a/b/c File relDir = makeCanonical(new File(baseTempDir, "./a/b/../b/c")); File fooFile = makeCanonical(new File(relDir, "DrJavaTestFoo.java")); OpenDefinitionsDocument doc = setupDocument("package a.b.c;\n" + FOO_TEXT); saveFileAs(doc, new FileSelector(fooFile)); // No events should fire _model.addListener(new TestListener()); // Since we had the package statement the source root should be base dir Iterable<File> roots = _model.getSourceRootSet(); assertEquals("number of source roots", 1, IterUtil.sizeOf(roots)); assertEquals("source root", baseTempDir.getCanonicalFile(), IterUtil.first(roots).getCanonicalFile()); _log.log("testGetSourceRootPackageThreeDeepValidRelative() completed"); } public void testGetSourceRootPackageThreeDeepInvalid() throws BadLocationException, IOException { // Create temp directory File baseTempDir = tempDirectory(); // Now make subdirectory a/b/d File subdir = makeCanonical(new File(baseTempDir, "a")); subdir = makeCanonical(new File(subdir, "b")); subdir = makeCanonical(new File(subdir, "d")); subdir.mkdirs(); // Save the footext to DrJavaTestFoo.java in the subdirectory File fooFile = makeCanonical(new File(subdir, "DrJavaTestFoo.java")); OpenDefinitionsDocument doc = setupDocument("package a.b.c;\n" + FOO_TEXT); saveFileAs(doc, new FileSelector(fooFile)); // No events should fire _model.addListener(new TestListener()); // The package name is wrong so this should return only currDir Iterable<File> roots = _model.getSourceRootSet(); assertEquals("number of source roots", 0, IterUtil.sizeOf(roots)); _log.log("testGetSourceRootPackageThreeDeepInvalid() completed"); } public void testGetSourceRootPackageOneDeepValid() throws BadLocationException, IOException { // Create temp directory File baseTempDir = tempDirectory(); // Now make subdirectory a File subdir = makeCanonical(new File(baseTempDir, "a")); subdir.mkdir(); // Save the footext to DrJavaTestFoo.java in the subdirectory File fooFile = makeCanonical(new File(subdir, "DrJavaTestFoo.java")); OpenDefinitionsDocument doc = setupDocument("package a;\n" + FOO_TEXT); saveFileAs(doc, new FileSelector(fooFile)); // No events should fire _model.addListener(new TestListener()); // Since we had the package statement the source root should be base dir Iterable<File> roots = _model.getSourceRootSet(); assertEquals("number of source roots", 1, IterUtil.sizeOf(roots)); assertEquals("source root", baseTempDir.getCanonicalFile(), IterUtil.first(roots).getCanonicalFile()); _log.log("testGetSourceRootPackageOneDeepValid() completed"); } public void testGetMultipleSourceRootsDefaultPackage() throws BadLocationException, IOException { // Create temp directory File baseTempDir = tempDirectory(); // Now make subdirectories a, b File subdir1 = makeCanonical(new File(baseTempDir, "a")); subdir1.mkdir(); File subdir2 = makeCanonical(new File(baseTempDir, "b")); subdir2.mkdir(); // Save the footext to DrJavaTestFoo.java in subdirectory 1 File file1 = makeCanonical(new File(subdir1, "DrJavaTestFoo.java")); OpenDefinitionsDocument doc1 = setupDocument(FOO_TEXT); saveFileAs(doc1, new FileSelector(file1)); // Save the bartext to Bar.java in subdirectory 1 File file2 = makeCanonical(new File(subdir1, "Bar.java")); OpenDefinitionsDocument doc2 = setupDocument(BAR_TEXT); saveFileAs(doc2, new FileSelector(file2)); // Save the bartext to Bar.java in subdirectory 2 File file3 = makeCanonical(new File(subdir2, "Bar.java")); OpenDefinitionsDocument doc3 = setupDocument(BAR_TEXT); saveFileAs(doc3, new FileSelector(file3)); Utilities.clearEventQueue(); // No events should fire _model.addListener(new TestListener()); // Get source roots (should be 2: no duplicates) Iterable<File> roots = _model.getSourceRootSet(); assertEquals("number of source roots", 2, IterUtil.sizeOf(roots)); Iterator<File> i = roots.iterator(); File root1 = i.next(); File root2 = i.next(); // Make sure both source roots are in set // But we don't care about the order if (!( (root1.equals(subdir1) && root2.equals(subdir2)) || (root1.equals(subdir2) && root2.equals(subdir1)) )) { fail("source roots did not match"); } _log.log("testGetMultipleSourceRootsDefaultPackage() completed"); } /** Creates a new class, compiles it and then checks that the REPL can see it. */ public void testInteractionsLiveUpdateClassPath() throws BadLocationException, EditDocumentException, IOException, InterruptedException { OpenDefinitionsDocument doc = setupDocument(FOO_TEXT); Utilities.clearEventQueue(); File f = tempFile(); doCompile(doc, f); // Rename the directory so it's not on the classpath anymore String tempPath = f.getParent(); File tempDir = makeCanonical(new File(tempPath)); tempDir.renameTo(makeCanonical(new File(tempPath + "a"))); String result = interpret("new DrJavaTestFoo().getClass().getName()"); // Should cause a NoClassDefFound, but we shouldn't check exact syntax. // Instead, make sure it isn't "DrJavaTestFoo", as if the class was found. assertFalse("interactions should have an error, not the correct answer", "\"DrJavaTestFoo\"".equals(result)); // System.err.println("Result1 is: " + result); // Add new directory to classpath through Config Vector<File> cp = new Vector<File>(); cp.add(makeCanonical(new File(tempPath + "a"))); DrJava.getConfig().setSetting(EXTRA_CLASSPATH, cp); Utilities.clearEventQueue(); _model.resetInteractionsClassPath(); result = interpret("new DrJavaTestFoo().getClass().getName()"); // Now it should be on the classpath assertEquals("interactions result", "\"DrJavaTestFoo\"", result); // Rename directory back to clean up tempDir = makeCanonical(new File(tempPath + "a")); boolean renamed = tempDir.renameTo(makeCanonical(new File(tempPath))); _log.log("testInteractionsLiveUpdateClasspath() completed"); } /** Tests that the appropriate event is fired when the model's interpreter changes.*/ public void testSwitchInterpreters() { TestListener listener = new TestListener() { public void interpreterChanged(boolean inProgress) { assertTrue("should not be in progress", !inProgress); interpreterChangedCount++; } }; _model.addListener(listener); final DefaultInteractionsModel dim = _model.getInteractionsModel(); // Create a new Java interpreter, and set it to be active Utilities.invokeAndWait(new Runnable() { public void run() { dim.addInterpreter("testInterpreter"); dim.setActiveInterpreter("testInterpreter", "myPrompt>"); } }); // Utilities.clearEventQueue(); listener.assertInterpreterChangedCount(1); _model.removeListener(listener); _log.log("testSwitchInterpreters() completed"); } public void testRunMainMethod() throws Exception { File dir = makeCanonical(new File(_tempDir, "bar")); dir.mkdir(); File file = makeCanonical(new File(dir, "Foo.java")); final OpenDefinitionsDocument doc = doCompile(FOO_CLASS, file); Utilities.invokeAndWait(new Runnable() { public void run() { try { doc.runMain(); } catch(Exception e) { throw new UnexpectedException(e); } } }); // Utilities.clearEventQueue(); assertInteractionsContains(InteractionsModel.BANNER_PREFIX); doc.insertString(doc.getLength(), " ", null); Utilities.invokeAndWait(new Runnable() { public void run() { try { doc.runMain(); } catch(Exception e) { throw new UnexpectedException(e); } } }); // Utilities.clearEventQueue(); assertInteractionsContains(DefaultGlobalModel.DOCUMENT_OUT_OF_SYNC_MSG); Utilities.clearEventQueue(); // Killing time here; Slave JVM may not have released Foo.class so that the file can be deleted on Windows. _log.log("testRunMainMethod() completed"); } public void testBookmark() throws Exception { File dir = makeCanonical(new File(_tempDir, "bar")); dir.mkdir(); final File file = makeCanonical(new File(dir, "Foo.java")); java.io.FileWriter fw = new java.io.FileWriter(file); fw.write(FOO_CLASS); fw.close(); _model.openFile(new edu.rice.cs.util.FileOpenSelector() { public File[] getFiles() throws edu.rice.cs.util.OperationCanceledException { return new File[] { file }; } }); assertEquals("Should be 0 bookmarks", 0, _model.getBookmarkManager().getRegions().size()); Utilities.invokeAndWait(new Runnable() { public void run() { _model.toggleBookmark(3,3); } }); ArrayList<OrderedDocumentRegion> bms = _model.getBookmarkManager().getRegions(); assertEquals("Should be 1 bookmarks", 1, bms.size()); assertEquals("Start offset should be 0", 0, bms.get(0).getStartOffset()); assertEquals("End offset should be "+FOO_CLASS.indexOf('\n'), FOO_CLASS.indexOf('\n'), bms.get(0).getEndOffset()); Utilities.invokeAndWait(new Runnable() { public void run() { _model.toggleBookmark(3,3); } }); bms = _model.getBookmarkManager().getRegions(); assertEquals("Should be 0 bookmarks", 0, bms.size()); Utilities.invokeAndWait(new Runnable() { public void run() { _model.toggleBookmark(3,6); } }); bms = _model.getBookmarkManager().getRegions(); assertEquals("Should be 1 bookmarks", 1, bms.size()); assertEquals("Start offset should be 3", 3, bms.get(0).getStartOffset()); assertEquals("End offset should be 6", 6, bms.get(0).getEndOffset()); Utilities.invokeAndWait(new Runnable() { public void run() { _model.toggleBookmark(12,8); } }); bms = _model.getBookmarkManager().getRegions(); // Note: bms is sorted by increasing (startOffset, endOffset) assertEquals("Should be 2 bookmarks", 2, bms.size()); // the bookmarks are disjoint assertEquals("Start offset should be 3", 3, bms.get(0).getStartOffset()); assertEquals("End offset should be 6", 6, bms.get(0).getEndOffset()); assertEquals("Start offset should be 8", 8, bms.get(1).getStartOffset()); assertEquals("End offset should be 12", 12, bms.get(1).getEndOffset()); Utilities.invokeAndWait(new Runnable() { public void run() { _model.toggleBookmark(5,10); } }); bms = _model.getBookmarkManager().getRegions(); assertEquals("Should be 0 bookmarks", 0, bms.size()); // the preceding two bookmarks overlapped and were deleted // assertEquals("Start offset should be 5", 5, bms.get(0).getStartOffset()); // assertEquals("End offset should be 10", 10, bms.get(0).getEndOffset()); // assertEquals("Start offset should be 5", 5, bms.get(1).getStartOffset()); // assertEquals("End offset should be 10", 10, bms.get(1).getEndOffset()); // assertEquals("Start offset should be 8", 8, bms.get(2).getStartOffset()); // assertEquals("End offset should be 12", 12, bms.get(2).getEndOffset()); Utilities.invokeAndWait(new Runnable() { public void run() { _model.toggleBookmark(8,12); } }); bms = _model.getBookmarkManager().getRegions(); assertEquals("Should be 1 bookmarks", 1, bms.size()); // no preceding bookmark assertEquals("Start offset should be 8", 8, bms.get(0).getStartOffset()); assertEquals("End offset should be 12", 12, bms.get(0).getEndOffset()); // assertEquals("Start offset should be 5", 5, bms.get(1).getStartOffset()); // assertEquals("End offset should be 10", 10, bms.get(1).getEndOffset()); Utilities.invokeAndWait(new Runnable() { public void run() { _model.toggleBookmark(3,6); } }); bms = _model.getBookmarkManager().getRegions(); assertEquals("Should be 2 bookmarks", 2, bms.size()); // no overlap assertEquals("Start offset should be 3", 3, bms.get(0).getStartOffset()); assertEquals("End offset should be 6", 6, bms.get(0).getEndOffset()); assertEquals("Start offset should be 8", 8, bms.get(1).getStartOffset()); assertEquals("End offset should be 12", 12, bms.get(1).getEndOffset()); Utilities.invokeAndWait(new Runnable() { public void run() { _model.toggleBookmark(10,5); } }); bms = _model.getBookmarkManager().getRegions(); assertEquals("Should be 0 bookmarks", 0, bms.size()); } }

The table below shows all metrics for GlobalModelOtherTest.java.

MetricValueDescription
BLOCKS42.00Number of blocks
BLOCK_COMMENT35.00Number of block comment lines
COMMENTS125.00Comment lines
COMMENT_DENSITY 0.39Comment density
COMPARISONS 7.00Number of comparison operators
CYCLOMATIC42.00Cyclomatic complexity
DECL_COMMENTS14.00Comments in declarations
DOC_COMMENT18.00Number of javadoc comment lines
ELOC321.00Effective lines of code
EXEC_COMMENTS67.00Comments in executable code
EXITS74.00Procedure exits
FUNCTIONS33.00Number of function declarations
HALSTEAD_DIFFICULTY74.10Halstead difficulty
HALSTEAD_EFFORT 0.00Halstead effort
INTERFACE_COMPLEXITY102.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
JAVA0018 0.00JAVA0018 Method name does not have required form
JAVA0019 0.00JAVA0019 Interface name does not have required form
JAVA0020 1.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
JAVA0034 0.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 0.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 1.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
JAVA007617.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 1.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 0.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
JAVA0108 1.00JAVA0108 Incorrect javadoc: no @param tag for 'parameter'
JAVA0109 0.00JAVA0109 Incorrect javadoc: no parameter 'parameter'
JAVA0110 1.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
JAVA011524.00JAVA0115 Incorrect javadoc: no @throws or @exception tag for 'exception'
JAVA0116 0.00JAVA0116 Missing javadoc: field 'field'
JAVA0117 7.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 6.00JAVA0126 Method declares unchecked exception in throws
JAVA0128 0.00JAVA0128 Public constructor in non-public class
JAVA0130 1.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 0.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 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 2.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 1.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 3.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 0.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
LINES585.00Number of lines in the source file
LINE_COMMENT72.00Number of line comments
LOC350.00Lines of code
LOGICAL_LINES284.00Number of statements
LOOPS 2.00Number of loops
NEST_DEPTH 3.00Maximum nesting depth
OPERANDS1282.00Number of operands
OPERATORS2125.00Number of operators
PARAMS 3.00Number of formal parameter declarations
PROGRAM_LENGTH3407.00Halstead program length
PROGRAM_VOCAB386.00Halstead program vocabulary
PROGRAM_VOLUME 0.00Halstead program volume
RETURNS99.00Number of return points from functions
SIZE25724.00Size of the file in bytes
UNIQUE_OPERANDS346.00Number of unique operands
UNIQUE_OPERATORS40.00Number of unique operators
WHITESPACE110.00Number of whitespace lines