Buffer.java

Index Score
org.gjt.sp.jedit
jEdit

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
DECL_COMMENTSComments in declarations
LINE_COMMENTNumber of line comments
JAVA0034JAVA0034 Missing braces in if statement
CYCLOMATICCyclomatic complexity
LINESNumber of lines in the source file
LOCLines of code
COMMENTSComment lines
ELOCEffective lines of code
EXITSProcedure exits
COMPARISONSNumber of comparison operators
SIZESize of the file in bytes
JAVA0110JAVA0110 Incorrect javadoc: no @return tag
RETURNSNumber of return points from functions
OPERATORSNumber of operators
LOGICAL_LINESNumber of statements
INTERFACE_COMPLEXITYInterface complexity
PROGRAM_LENGTHHalstead program length
EXEC_COMMENTSComments in executable code
BLOCKSNumber of blocks
DOC_COMMENTNumber of javadoc comment lines
UNIQUE_OPERANDSNumber of unique operands
OPERANDSNumber of operands
FUNCTIONSNumber of function declarations
PROGRAM_VOCABHalstead program vocabulary
JAVA0145JAVA0145 Tab character used in source file
PARAMSNumber of formal parameter declarations
JAVA0108JAVA0108 Incorrect javadoc: no @param tag for 'parameter'
WHITESPACENumber of whitespace lines
JAVA0075JAVA0075 Method parameter hides field
LOOPSNumber of loops
JAVA0179JAVA0179 Local variable hides visible field
JAVA0049JAVA0049 Nested block at depth N (maximum: M)
JAVA0119JAVA0119 Control variable changed within body of for loop
UNIQUE_OPERATORSNumber of unique operators
JAVA0116JAVA0116 Missing javadoc: field 'field'
JAVA0173JAVA0173 Unused method parameter
NEST_DEPTHMaximum nesting depth
JAVA0177JAVA0177 Variable declaration missing initializer
PROGRAM_VOLUMEHalstead program volume
JAVA0136JAVA0136 N methods defined in class (maximum: M)
JAVA0035JAVA0035 Missing braces in for statement
JAVA0126JAVA0126 Method declares unchecked exception in throws
JAVA0117JAVA0117 Missing javadoc: method 'method'
JAVA0100JAVA0100 Class contains N non-final fields (maximum: M)
JAVA0270JAVA0270 Use Java 5.0 enhanced for loop construct to iterate over all elements in an array
/* * Buffer.java - jEdit buffer * :tabSize=8:indentSize=8:noTabs=false: * :folding=explicit:collapseFolds=1: * * Copyright (C) 1998, 2005 Slava Pestov * Portions copyright (C) 1999, 2000 mike dillon * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package org.gjt.sp.jedit; //{{{ Imports import org.gjt.sp.jedit.browser.VFSBrowser; import org.gjt.sp.jedit.buffer.*; import org.gjt.sp.jedit.bufferio.BufferAutosaveRequest; import org.gjt.sp.jedit.bufferio.BufferIORequest; import org.gjt.sp.jedit.bufferio.MarkersSaveRequest; import org.gjt.sp.jedit.gui.StyleEditor; import org.gjt.sp.jedit.io.FileVFS; import org.gjt.sp.jedit.io.VFS; import org.gjt.sp.jedit.io.VFSFile; import org.gjt.sp.jedit.io.VFSManager; import org.gjt.sp.jedit.msg.BufferUpdate; import org.gjt.sp.jedit.syntax.*; import org.gjt.sp.jedit.textarea.JEditTextArea; import org.gjt.sp.util.IntegerArray; import org.gjt.sp.util.Log; import org.gjt.sp.jedit.visitors.JEditVisitorAdapter; import org.gjt.sp.jedit.visitors.SaveCaretInfoVisitor; import org.gjt.sp.jedit.options.GeneralOptionPane; import javax.swing.*; import javax.swing.text.AttributeSet; import javax.swing.text.Segment; import java.io.File; import java.io.IOException; import java.net.Socket; import java.util.Enumeration; import java.util.Hashtable; import java.util.Vector; //}}} /** * A <code>Buffer</code> represents the contents of an open text * file as it is maintained in the computer's memory (as opposed to * how it may be stored on a disk).<p> * * In a BeanShell script, you can obtain the current buffer instance from the * <code>buffer</code> variable.<p> * * This class does not have a public constructor. * Buffers can be opened and closed using methods in the <code>jEdit</code> * class.<p> * * This class is partially thread-safe, however you must pay attention to two * very important guidelines: * <ul> * <li>Changes to a buffer can only be made from the AWT thread. * <li>When accessing the buffer from another thread, you must * grab a read lock if you plan on performing more than one call, to ensure that * the buffer contents are not changed by the AWT thread for the duration of the * lock. Only methods whose descriptions specify thread safety can be invoked * from other threads. * </ul> * * @author Slava Pestov * @version $Id: Buffer.java 12867 2008-06-21 12:18:16Z k_satoda $ */ public class Buffer extends JEditBuffer { //{{{ Some constants /** * Backed up property. * @since jEdit 3.2pre2 */ public static final String BACKED_UP = "Buffer__backedUp"; /** * Caret info properties. * @since jEdit 3.2pre1 */ public static final String CARET = "Buffer__caret"; public static final String CARET_POSITIONED = "Buffer__caretPositioned"; /** * Stores a List of {@link org.gjt.sp.jedit.textarea.Selection} instances. */ public static final String SELECTION = "Buffer__selection"; /** * This should be a physical line number, so that the scroll * position is preserved correctly across reloads (which will * affect virtual line numbers, due to fold being reset) */ public static final String SCROLL_VERT = "Buffer__scrollVert"; public static final String SCROLL_HORIZ = "Buffer__scrollHoriz"; /** * Should jEdit try to set the encoding based on a UTF8, UTF16 or * XML signature at the beginning of the file? */ public static final String ENCODING_AUTODETECT = "encodingAutodetect"; /** * This property is set to 'true' if the file has a trailing newline. * @since jEdit 4.0pre1 */ public static final String TRAILING_EOL = "trailingEOL"; /** * This property is set to 'true' if the file should be GZipped. * @since jEdit 4.0pre4 */ public static final String GZIPPED = "gzipped"; //}}} //{{{ Input/output methods //{{{ reload() method /** * Reloads the buffer from disk, asking for confirmation if the buffer * has unsaved changes. * @param view The view * @since jEdit 2.7pre2 */ public void reload(View view) { if (getFlag(UNTITLED)) return; if(isDirty()) { String[] args = { path }; int result = GUIUtilities.confirm(view,"changedreload", args,JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE); if(result != JOptionPane.YES_OPTION) return; } view.visit(new SaveCaretInfoVisitor()); load(view,true); } //}}} //{{{ load() method /** * Loads the buffer from disk. * @param view The view * @param reload If true, user will not be asked to recover autosave * file, if any * * @since 2.5pre1 */ public boolean load(final View view, final boolean reload) { if(isPerformingIO()) { GUIUtilities.error(view,"buffer-multiple-io",null); return false; } setBooleanProperty(BufferIORequest.ERROR_OCCURRED,false); setLoading(true); // view text areas temporarily blank out while a buffer is // being loaded, to indicate to the user that there is no // data available yet. if(!getFlag(TEMPORARY)) EditBus.send(new BufferUpdate(this,view,BufferUpdate.LOAD_STARTED)); final boolean loadAutosave; if(reload || !getFlag(NEW_FILE)) { if(file != null) modTime = file.lastModified(); // Only on initial load if(!reload && autosaveFile != null && autosaveFile.exists()) loadAutosave = recoverAutosave(view); else { if(autosaveFile != null) autosaveFile.delete(); loadAutosave = false; } if(!loadAutosave) { VFS vfs = VFSManager.getVFSForPath(path); if(!checkFileForLoad(view,vfs,path)) { setLoading(false); return false; } // have to check again since above might set // NEW_FILE flag if(reload || !getFlag(NEW_FILE)) { if(!vfs.load(view,this,path)) { setLoading(false); return false; } } } } else loadAutosave = false; //{{{ Do some stuff once loading is finished Runnable runnable = new Runnable() { public void run() { String newPath = getStringProperty( BufferIORequest.NEW_PATH); Segment seg = (Segment)getProperty( BufferIORequest.LOAD_DATA); IntegerArray endOffsets = (IntegerArray) getProperty(BufferIORequest.END_OFFSETS); loadText(seg,endOffsets); unsetProperty(BufferIORequest.LOAD_DATA); unsetProperty(BufferIORequest.END_OFFSETS); unsetProperty(BufferIORequest.NEW_PATH); undoMgr.clear(); undoMgr.setLimit(jEdit.getIntegerProperty( "buffer.undoCount",100)); if(!getFlag(TEMPORARY)) finishLoading(); setLoading(false); // if reloading a file, clear dirty flag if(reload) setDirty(false); if(!loadAutosave && newPath != null) setPath(newPath); // if loadAutosave is false, we loaded an // autosave file, so we set 'dirty' to true // note that we don't use setDirty(), // because a) that would send an unnecessary // message, b) it would also set the // AUTOSAVE_DIRTY flag, which will make // the autosave thread write out a // redundant autosave file if(loadAutosave) Buffer.super.setDirty(true); // send some EditBus messages if(!getFlag(TEMPORARY)) { fireBufferLoaded(); EditBus.send(new BufferUpdate(Buffer.this, view,BufferUpdate.LOADED)); //EditBus.send(new BufferUpdate(Buffer.this, // view,BufferUpdate.MARKERS_CHANGED)); } } }; //}}} if(getFlag(TEMPORARY)) runnable.run(); else VFSManager.runInAWTThread(runnable); return true; } //}}} //{{{ insertFile() method /** * Loads a file from disk, and inserts it into this buffer. * @param view The view * @param path the path of the file to insert * * @since 4.0pre1 */ public boolean insertFile(View view, String path) { if(isPerformingIO()) { GUIUtilities.error(view,"buffer-multiple-io",null); return false; } setBooleanProperty(BufferIORequest.ERROR_OCCURRED,false); path = MiscUtilities.constructPath(this.path,path); Buffer buffer = jEdit.getBuffer(path); if(buffer != null) { view.getTextArea().setSelectedText( buffer.getText(0,buffer.getLength())); return true; } VFS vfs = VFSManager.getVFSForPath(path); // this returns false if initial sanity // checks (if the file is a directory, etc) // fail return vfs.insert(view,this,path); } //}}} //{{{ autosave() method /** * Autosaves this buffer. */ public void autosave() { if(autosaveFile == null || !getFlag(AUTOSAVE_DIRTY) || !isDirty() || isPerformingIO() || !autosaveFile.getParentFile().exists()) return; setFlag(AUTOSAVE_DIRTY,false); VFSManager.runInWorkThread(new BufferAutosaveRequest( null,this,null,VFSManager.getFileVFS(), autosaveFile.getPath())); } //}}} //{{{ saveAs() method /** * Prompts the user for a file to save this buffer to. * @param view The view * @param rename True if the buffer's path should be changed, false * if only a copy should be saved to the specified filename * @since jEdit 2.6pre5 */ public boolean saveAs(View view, boolean rename) { String[] files = GUIUtilities.showVFSFileDialog(view,path, VFSBrowser.SAVE_DIALOG,false); // files[] should have length 1, since the dialog type is // SAVE_DIALOG if(files == null) return false; return save(view,files[0],rename); } //}}} //{{{ save() method /** * Saves this buffer to the specified path name, or the current path * name if it's null. * @param view The view * @param path The path name to save the buffer to, or null to use * the existing path */ public boolean save(View view, String path) { return save(view,path,true,false); } //}}} //{{{ save() method /** * Saves this buffer to the specified path name, or the current path * name if it's null. * @param view The view * @param path The path name to save the buffer to, or null to use * the existing path * @param rename True if the buffer's path should be changed, false * if only a copy should be saved to the specified filename * @since jEdit 2.6pre5 */ public boolean save(final View view, String path, final boolean rename) { return save(view,path,rename,false); } //}}} //{{{ save() method /** * Saves this buffer to the specified path name, or the current path * name if it's null. * @param view The view * @param path The path name to save the buffer to, or null to use * the existing path * @param rename True if the buffer's path should be changed, false * if only a copy should be saved to the specified filename * @param disableFileStatusCheck Disables file status checking * regardless of the state of the checkFileStatus property */ public boolean save(final View view, String path, final boolean rename, boolean disableFileStatusCheck) { if(isPerformingIO()) { GUIUtilities.error(view,"buffer-multiple-io",null); return false; } setBooleanProperty(BufferIORequest.ERROR_OCCURRED,false); if(path == null && getFlag(NEW_FILE)) return saveAs(view,rename); if(path == null && file != null) { long newModTime = file.lastModified(); if(newModTime != modTime && jEdit.getBooleanProperty("view.checkModStatus")) { Object[] args = { this.path }; int result = GUIUtilities.confirm(view, "filechanged-save",args, JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE); if(result != JOptionPane.YES_OPTION) return false; } } EditBus.send(new BufferUpdate(this,view,BufferUpdate.SAVING)); setPerformingIO(true); final String oldPath = this.path; final String oldSymlinkPath = symlinkPath; final String newPath = path == null ? this.path : path; VFS vfs = VFSManager.getVFSForPath(newPath); if(!checkFileForSave(view,vfs,newPath)) { setPerformingIO(false); return false; } Object session = vfs.createVFSSession(newPath,view); if (session == null) { setPerformingIO(false); return false; } unsetProperty("overwriteReadonly"); unsetProperty("forbidTwoStageSave"); try { VFSFile file = vfs._getFile(session,newPath,view); if (file != null) { boolean vfsRenameCap = (vfs.getCapabilities() & VFS.RENAME_CAP) != 0; if (!file.isWriteable()) { Log.log(Log.WARNING, this, "Buffer saving : File " + file + " is readOnly"); if (vfsRenameCap) { Log.log(Log.DEBUG, this, "Buffer saving : VFS can rename files"); String savePath = vfs._canonPath(session,newPath,view); if(!MiscUtilities.isURL(savePath)) savePath = MiscUtilities.resolveSymlinks(savePath); savePath = vfs.getTwoStageSaveName(savePath); if (savePath == null) { Log.log(Log.DEBUG, this, "Buffer saving : two stage save impossible because path is null"); VFSManager.error(view, newPath, "ioerror.save-readonly-twostagefail", null); setPerformingIO(false); return false; } else { int result = GUIUtilities.confirm( view, "vfs.overwrite-readonly", new Object[]{newPath}, JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE); if (result == JOptionPane.YES_OPTION) { Log.log(Log.WARNING, this, "Buffer saving : two stage save will be used to save buffer"); setBooleanProperty("overwriteReadonly",true); } else { Log.log(Log.DEBUG,this, "Buffer not saved"); setPerformingIO(false); return false; } } } else { Log.log(Log.WARNING, this, "Buffer saving : file is readonly and vfs cannot do two stage save"); VFSManager.error(view, newPath, "ioerror.write-error-readonly", null); setPerformingIO(false); return false; } } else { String savePath = vfs._canonPath(session,newPath,view); if(!MiscUtilities.isURL(savePath)) savePath = MiscUtilities.resolveSymlinks(savePath); savePath = vfs.getTwoStageSaveName(savePath); if (jEdit.getBooleanProperty("twoStageSave") && (!vfsRenameCap || savePath == null)) { // the file is writeable but the vfs cannot do two stage. We must overwrite // readonly flag int result = GUIUtilities.confirm( view, "vfs.twostageimpossible", new Object[]{newPath}, JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE); if (result == JOptionPane.YES_OPTION) { Log.log(Log.WARNING, this, "Buffer saving : two stage save cannot be used"); setBooleanProperty("forbidTwoStageSave",true); } else { Log.log(Log.DEBUG,this, "Buffer not saved"); setPerformingIO(false); return false; } } } } } catch(IOException io) { VFSManager.error(view,newPath,"ioerror", new String[] { io.toString() }); setPerformingIO(false); return false; } finally { try { vfs._endVFSSession(session,view); } catch(IOException io) { VFSManager.error(view,newPath,"ioerror", new String[] { io.toString() }); setPerformingIO(false); return false; } } if(!vfs.save(view,this,newPath)) { setPerformingIO(false); return false; } // Once save is complete, do a few other things VFSManager.runInAWTThread(new Runnable() { public void run() { setPerformingIO(false); setProperty("overwriteReadonly",null); finishSaving(view,oldPath,oldSymlinkPath, newPath,rename,getBooleanProperty( BufferIORequest.ERROR_OCCURRED)); updateMarkersFile(view); } }); int check = jEdit.getIntegerProperty("checkFileStatus"); if(!disableFileStatusCheck && (check == GeneralOptionPane.checkFileStatus_all || check == GeneralOptionPane.checkFileStatus_operations)) jEdit.checkBufferStatus(view,false); return true; } //}}} //{{{ checkFileStatus() method public static final int FILE_NOT_CHANGED = 0; public static final int FILE_CHANGED = 1; public static final int FILE_DELETED = 2; /** * Check if the buffer has changed on disk. * @return One of <code>NOT_CHANGED</code>, <code>CHANGED</code>, or * <code>DELETED</code>. * * @since jEdit 4.2pre1 */ public int checkFileStatus(View view) { // - don't do these checks while a save is in progress, // because for a moment newModTime will be greater than // oldModTime, due to the multithreading // - only supported on local file system if(!isPerformingIO() && file != null && !getFlag(NEW_FILE)) { boolean newReadOnly = (file.exists() && !file.canWrite()); if(newReadOnly != isFileReadOnly()) { setFileReadOnly(newReadOnly); EditBus.send(new BufferUpdate(this,null, BufferUpdate.DIRTY_CHANGED)); } long oldModTime = modTime; long newModTime = file.lastModified(); if(newModTime != oldModTime) { modTime = newModTime; if(!file.exists()) { setFlag(NEW_FILE,true); setDirty(true); return FILE_DELETED; } else { return FILE_CHANGED; } } } return FILE_NOT_CHANGED; } //}}} //}}} //{{{ Getters/setter methods for various buffer meta-data //{{{ getLastModified() method /** * Returns the last time jEdit modified the file on disk. * This method is thread-safe. */ public long getLastModified() { return modTime; } //}}} //{{{ setLastModified() method /** * Sets the last time jEdit modified the file on disk. * @param modTime The new modification time */ public void setLastModified(long modTime) { this.modTime = modTime; } //}}} //{{{ getAutoReload() method /** * Returns the status of the AUTORELOAD flag * If true, reload changed files automatically */ public boolean getAutoReload() { return getFlag(AUTORELOAD); } //}}} //{{{ setAutoReload() method /** * Sets the status of the AUTORELOAD flag * @param value # If true, reload changed files automatically */ public void setAutoReload(boolean value) { setFlag(AUTORELOAD, value); } //}}} //{{{ getAutoReloadDialog() method /** * Returns the status of the AUTORELOAD_DIALOG flag * If true, prompt for reloading or notify user * when the file has changed on disk */ public boolean getAutoReloadDialog() { return getFlag(AUTORELOAD_DIALOG); } //}}} //{{{ setAutoReloadDialog() method /** * Sets the status of the AUTORELOAD_DIALOG flag * @param value # If true, prompt for reloading or notify user * when the file has changed on disk */ public void setAutoReloadDialog(boolean value) { setFlag(AUTORELOAD_DIALOG, value); } //}}} //{{{ getVFS() method /** * Returns the virtual filesystem responsible for loading and * saving this buffer. This method is thread-safe. */ public VFS getVFS() { return VFSManager.getVFSForPath(path); } //}}} //{{{ getAutosaveFile() method /** * Returns the autosave file for this buffer. This may be null if * the file is non-local. */ public File getAutosaveFile() { return autosaveFile; } //}}} //{{{ removeAutosaveFile() method /** * Remove the autosave file. * @since jEdit 4.3pre12 */ public void removeAutosaveFile() { if (autosaveFile != null) { autosaveFile.delete(); setFlag(AUTOSAVE_DIRTY,true); } } //}}} //{{{ getName() method /** * Returns the name of this buffer. This method is thread-safe. */ public String getName() { return name; } //}}} //{{{ getPath() method /** * Returns the path name of this buffer. This method is thread-safe. */ public String getPath() { return path; } //}}} //{{{ getSymlinkPath() method /** * If this file is a symbolic link, returns the link destination. * Otherwise returns the file's path. This method is thread-safe. * @since jEdit 4.2pre1 */ public String getSymlinkPath() { return symlinkPath; } //}}} //{{{ getDirectory() method /** * Returns the directory containing this buffer. * @since jEdit 4.1pre11 */ public String getDirectory() { return directory; } //}}} //{{{ isClosed() method /** * Returns true if this buffer has been closed with * {@link org.gjt.sp.jedit.jEdit#closeBuffer(View,Buffer)}. * This method is thread-safe. */ public boolean isClosed() { return getFlag(CLOSED); } //}}} //{{{ isLoaded() method /** * Returns true if the buffer is loaded. This method is thread-safe. */ public boolean isLoaded() { return !isLoading(); } //}}} //{{{ isNewFile() method /** * Returns whether this buffer lacks a corresponding version on disk. * This method is thread-safe. */ public boolean isNewFile() { return getFlag(NEW_FILE); } //}}} //{{{ setNewFile() method /** * Sets the new file flag. * @param newFile The new file flag */ public void setNewFile(boolean newFile) { setFlag(NEW_FILE,newFile); if(!newFile) setFlag(UNTITLED,false); } //}}} //{{{ isUntitled() method /** * Returns true if this file is 'untitled'. This method is thread-safe. */ public boolean isUntitled() { return getFlag(UNTITLED); } //}}} //{{{ setDirty() method /** * Sets the 'dirty' (changed since last save) flag of this buffer. */ @Override public void setDirty(boolean d) { boolean old_d = isDirty(); super.setDirty(d); boolean editable = isEditable(); if(d) { if(editable) setFlag(AUTOSAVE_DIRTY,true); } else { setFlag(AUTOSAVE_DIRTY,false); if(autosaveFile != null) autosaveFile.delete(); } if(d != old_d && editable) { EditBus.send(new BufferUpdate(this,null, BufferUpdate.DIRTY_CHANGED)); } } //}}} //{{{ isTemporary() method /** * Returns if this is a temporary buffer. This method is thread-safe. * @see jEdit#openTemporary(View,String,String,boolean) * @see jEdit#commitTemporary(Buffer) * @since jEdit 2.2pre7 */ public boolean isTemporary() { return getFlag(TEMPORARY); } //}}} //{{{ getIcon() method /** * Returns this buffer's icon. * @since jEdit 2.6pre6 */ public Icon getIcon() { if(isDirty()) return GUIUtilities.loadIcon("dirty.gif"); else if(isReadOnly()) return GUIUtilities.loadIcon("readonly.gif"); else if(getFlag(NEW_FILE)) return GUIUtilities.loadIcon("new.gif"); else return GUIUtilities.loadIcon("normal.gif"); } //}}} //}}} //{{{ Buffer events //{{{ addBufferChangeListener() method /** * @deprecated Call {@link JEditBuffer#addBufferListener(BufferListener,int)}. */ @Deprecated public void addBufferChangeListener(BufferChangeListener listener, int priority) { addBufferListener(new BufferChangeListener.Adapter(listener),priority); } //}}} //{{{ addBufferChangeListener() method /** * @deprecated Call {@link JEditBuffer#addBufferListener(BufferListener)}. */ @Deprecated public void addBufferChangeListener(BufferChangeListener listener) { addBufferChangeListener(listener,NORMAL_PRIORITY); } //}}} //{{{ removeBufferChangeListener() method /** * @deprecated Call {@link JEditBuffer#removeBufferListener(BufferListener)}. */ @Deprecated public void removeBufferChangeListener(BufferChangeListener listener) { BufferListener[] listeners = getBufferListeners(); for(int i = 0; i < listeners.length; i++) { BufferListener l = listeners[i]; if(l instanceof BufferChangeListener.Adapter) { if(((BufferChangeListener.Adapter)l).getDelegate() == listener) { removeBufferListener(l); return; } } } } //}}} //}}} //{{{ Property methods //{{{ propertiesChanged() method /** * Reloads settings from the properties. This should be called * after the <code>syntax</code> or <code>folding</code> * buffer-local properties are changed. */ @Override public void propertiesChanged() { super.propertiesChanged(); EditBus.send(new BufferUpdate(this,null,BufferUpdate.PROPERTIES_CHANGED)); } //}}} //{{{ getDefaultProperty() method @Override public Object getDefaultProperty(String name) { Object retVal; if(mode != null) { retVal = mode.getProperty(name); if(retVal == null) return null; setDefaultProperty(name,retVal); return retVal; } // Now try buffer.<property> String value = jEdit.getProperty("buffer." + name); if(value == null) return null; // Try returning it as an integer first try { retVal = new Integer(value); } catch(NumberFormatException nf) { retVal = value; } return retVal; } //}}} //{{{ toggleWordWrap() method /** * Toggles word wrap between the three available modes. This is used * by the status bar. * @param view We show a message in the view's status bar * @since jEdit 4.1pre3 */ public void toggleWordWrap(View view) { String wrap = getStringProperty("wrap"); if(wrap.equals("none")) wrap = "soft"; else if(wrap.equals("soft")) wrap = "hard"; else if(wrap.equals("hard")) wrap = "none"; view.getStatus().setMessageAndClear(jEdit.getProperty( "view.status.wrap-changed",new String[] { wrap })); setProperty("wrap",wrap); propertiesChanged(); } //}}} //{{{ toggleLineSeparator() method /** * Toggles the line separator between the three available settings. * This is used by the status bar. * @param view We show a message in the view's status bar * @since jEdit 4.1pre3 */ public void toggleLineSeparator(View view) { String status = null; String lineSep = getStringProperty("lineSeparator"); if("\n".equals(lineSep)) { status = "windows"; lineSep = "\r\n"; } else if("\r\n".equals(lineSep)) { status = "mac"; lineSep = "\r"; } else if("\r".equals(lineSep)) { status = "unix"; lineSep = "\n"; } view.getStatus().setMessageAndClear(jEdit.getProperty( "view.status.linesep-changed",new String[] { jEdit.getProperty("lineSep." + status) })); setProperty("lineSeparator",lineSep); setDirty(true); propertiesChanged(); } //}}} //{{{ getContextSensitiveProperty() method /** * Some settings, like comment start and end strings, can * vary between different parts of a buffer (HTML text and inline * JavaScript, for example). * @param offset The offset * @param name The property name * @since jEdit 4.0pre3 */ @Override public String getContextSensitiveProperty(int offset, String name) { Object value = super.getContextSensitiveProperty(offset,name); if(value == null) { ParserRuleSet rules = getRuleSetAtOffset(offset); value = jEdit.getMode(rules.getModeName()) .getProperty(name); if(value == null) value = mode.getProperty(name); } if(value == null) return null; else return String.valueOf(value); } //}}} //}}} //{{{ Edit modes, syntax highlighting //{{{ setMode() method /** * Sets this buffer's edit mode by calling the accept() method * of each registered edit mode. */ public void setMode() { String userMode = getStringProperty("mode"); if(userMode != null) { unsetProperty("mode"); Mode m = ModeProvider.instance.getMode(userMode); if(m != null) { setMode(m); return; } } String firstLine = getLineText(0); Mode mode = ModeProvider.instance.getModeForFile(name, firstLine); if (mode != null) { setMode(mode); return; } Mode defaultMode = jEdit.getMode(jEdit.getProperty("buffer.defaultMode")); if(defaultMode == null) defaultMode = jEdit.getMode("text"); setMode(defaultMode); } //}}} //}}} //{{{ Deprecated methods //{{{ putProperty() method /** * @deprecated Call <code>setProperty()</code> instead. */ @Deprecated public void putProperty(Object name, Object value) { // for backwards compatibility if(!(name instanceof String)) return; setProperty((String)name,value); } //}}} //{{{ putBooleanProperty() method /** * @deprecated Call <code>setBooleanProperty()</code> instead */ @Deprecated public void putBooleanProperty(String name, boolean value) { setBooleanProperty(name,value); } //}}} //{{{ markTokens() method /** * @deprecated Use org.gjt.sp.jedit.syntax.DefaultTokenHandler instead */ @Deprecated public static class TokenList extends DefaultTokenHandler { public Token getFirstToken() { return getTokens(); } } /** * @deprecated Use the other form of <code>markTokens()</code> instead */ @Deprecated public TokenList markTokens(int lineIndex) { TokenList list = new TokenList(); markTokens(lineIndex,list); return list; } //}}} //{{{ insertString() method /** * @deprecated Call <code>insert()</code> instead. */ @Deprecated public void insertString(int offset, String str, AttributeSet attr) { insert(offset,str); } //}}} //{{{ getFile() method /** * @deprecated Do not call this method, use {@link #getPath()} * instead. */ @Deprecated public File getFile() { return file; } //}}} //}}} //{{{ Marker methods //{{{ getMarkers() method /** * Returns a vector of markers. * @since jEdit 3.2pre1 */ public Vector<Marker> getMarkers() { return markers; } //}}} //{{{ getMarkerStatusPrompt() method /** * Returns the status prompt for the given marker action. Only * intended to be called from <code>actions.xml</code>. * @since jEdit 4.2pre2 */ public String getMarkerStatusPrompt(String action) { return jEdit.getProperty("view.status." + action, new String[] { getMarkerNameString() }); } //}}} //{{{ getMarkerNameString() method /** * Returns a string of all set markers, used by the status bar * (eg, "a b $ % ^"). * @since jEdit 4.2pre2 */ public String getMarkerNameString() { StringBuilder buf = new StringBuilder(); for(int i = 0; i < markers.size(); i++) { Marker marker = markers.get(i); if(marker.getShortcut() != '\0') { if(buf.length() != 0) buf.append(' '); buf.append(marker.getShortcut()); } } if(buf.length() == 0) return jEdit.getProperty("view.status.no-markers"); else return buf.toString(); } //}}} //{{{ addOrRemoveMarker() method /** * If a marker is set on the line of the position, it is removed. Otherwise * a new marker with the specified shortcut is added. * @param pos The position of the marker * @param shortcut The shortcut ('\0' if none) * @since jEdit 3.2pre5 */ public void addOrRemoveMarker(char shortcut, int pos) { int line = getLineOfOffset(pos); if(getMarkerAtLine(line) != null) removeMarker(line); else addMarker(shortcut,pos); } //}}} //{{{ addMarker() method /** * Adds a marker to this buffer. * @param pos The position of the marker * @param shortcut The shortcut ('\0' if none) * @since jEdit 3.2pre1 */ public void addMarker(char shortcut, int pos) { Marker markerN = new Marker(this,shortcut,pos); boolean added = false; // don't sort markers while buffer is being loaded if(isLoaded()) { setFlag(MARKERS_CHANGED,true); markerN.createPosition(); for(int i = 0; i < markers.size(); i++) { Marker marker = markers.get(i); if(shortcut != '\0' && marker.getShortcut() == shortcut) marker.setShortcut('\0'); if(marker.getPosition() == pos) { markers.removeElementAt(i); i--; } } for(int i = 0; i < markers.size(); i++) { Marker marker = markers.get(i); if(marker.getPosition() > pos) { markers.insertElementAt(markerN,i); added = true; break; } } } if(!added) markers.addElement(markerN); if(isLoaded() && !getFlag(TEMPORARY)) { EditBus.send(new BufferUpdate(this,null, BufferUpdate.MARKERS_CHANGED)); } } //}}} //{{{ getMarkerInRange() method /** * Returns the first marker within the specified range. * @param start The start offset * @param end The end offset * @since jEdit 4.0pre4 */ public Marker getMarkerInRange(int start, int end) { for(int i = 0; i < markers.size(); i++) { Marker marker = markers.get(i); int pos = marker.getPosition(); if(pos >= start && pos < end) return marker; } return null; } //}}} //{{{ getMarkerAtLine() method /** * Returns the first marker at the specified line, or <code>null</code> * if there is none. * @param line The line number * @since jEdit 3.2pre2 */ public Marker getMarkerAtLine(int line) { for(int i = 0; i < markers.size(); i++) { Marker marker = markers.get(i); if(getLineOfOffset(marker.getPosition()) == line) return marker; } return null; } //}}} //{{{ removeMarker() method /** * Removes all markers at the specified line. * @param line The line number * @since jEdit 3.2pre2 */ public void removeMarker(int line) { for(int i = 0; i < markers.size(); i++) { Marker marker = markers.get(i); if(getLineOfOffset(marker.getPosition()) == line) { setFlag(MARKERS_CHANGED,true); marker.removePosition(); markers.removeElementAt(i); i--; } } EditBus.send(new BufferUpdate(this,null, BufferUpdate.MARKERS_CHANGED)); } //}}} //{{{ removeAllMarkers() method /** * Removes all defined markers. * @since jEdit 2.6pre1 */ public void removeAllMarkers() { setFlag(MARKERS_CHANGED,true); for(int i = 0; i < markers.size(); i++) markers.get(i).removePosition(); markers.removeAllElements(); if(isLoaded()) { EditBus.send(new BufferUpdate(this,null, BufferUpdate.MARKERS_CHANGED)); } } //}}} //{{{ getMarker() method /** * Returns the marker with the specified shortcut. * @param shortcut The shortcut * @since jEdit 3.2pre2 */ public Marker getMarker(char shortcut) { Enumeration<Marker> e = markers.elements(); while(e.hasMoreElements()) { Marker marker = e.nextElement(); if(marker.getShortcut() == shortcut) return marker; } return null; } //}}} //{{{ getMarkersPath() method /** * Returns the path for this buffer's markers file * @param vfs The appropriate VFS * @since jEdit 4.3pre7 * @deprecated it will fail if you save to another VFS. use {@link #getMarkersPath(VFS, String)} */ @Deprecated public String getMarkersPath(VFS vfs) { return getMarkersPath(vfs, path); } //}}} //{{{ getMarkersPath() method /** * Returns the path for this buffer's markers file * @param vfs The appropriate VFS * @param path the path of the buffer, it can be different from the field * when using save-as * @since jEdit 4.3pre10 */ public static String getMarkersPath(VFS vfs, String path) { return vfs.getParentOfPath(path) + '.' + vfs.getFileName(path) + ".marks"; } //}}} //{{{ updateMarkersFile() method /** * Save the markers file, or delete it when there are mo markers left * Handling markers is now independent from saving the buffer. * Changing markers will not set the buffer dirty any longer. * @param view The current view * @since jEdit 4.3pre7 */ public boolean updateMarkersFile(View view) { if(!markersChanged()) return true; // adapted from VFS.save VFS vfs = VFSManager.getVFSForPath(getPath()); if (((vfs.getCapabilities() & VFS.WRITE_CAP) == 0) || (!vfs.isMarkersFileSupported())) { VFSManager.error(view, path, "vfs.not-supported.save", new String[] { "markers file" }); return false; } Object session = vfs.createVFSSession(path, view); if(session == null) return false; VFSManager.runInWorkThread( new MarkersSaveRequest( view, this, session, vfs, path)); return true; } //}}} //{{{ markersChanged() method /** * Return true when markers have changed and the markers file needs * to be updated * @since jEdit 4.3pre7 */ public boolean markersChanged() { return getFlag(MARKERS_CHANGED); } //}}} //{{{ setMarkersChanged() method /** * Sets/unsets the MARKERS_CHANGED flag * @since jEdit 4.3pre7 */ public void setMarkersChanged(boolean changed) { setFlag(MARKERS_CHANGED, changed); } //}}} //}}} //{{{ Miscellaneous methods //{{{ setWaitSocket() method /** * This socket is closed when the buffer is closed. */ public void setWaitSocket(Socket waitSocket) { this.waitSocket = waitSocket; } //}}} //{{{ getNext() method /** * Returns the next buffer in the list. */ public Buffer getNext() { return next; } //}}} //{{{ getPrev() method /** * Returns the previous buffer in the list. */ public Buffer getPrev() { return prev; } //}}} //{{{ getIndex() method /** * Returns the position of this buffer in the buffer list. */ public int getIndex() { int count = 0; Buffer buffer = prev; while (true) { if(buffer == null) break; count++; buffer = buffer.prev; } return count; } //}}} //{{{ toString() method /** * Returns a string representation of this buffer. * This simply returns the path name. */ @Override public String toString() { return name + " (" + directory + ')'; } //}}} //}}} //{{{ Package-private members /** The previous buffer in the list. */ Buffer prev; /** The next buffer in the list. */ Buffer next; //{{{ Buffer constructor Buffer(String path, boolean newFile, boolean temp, Hashtable props) { super(props); markers = new Vector<Marker>(); setFlag(TEMPORARY,temp); // this must be called before any EditBus messages are sent setPath(path); /* Magic: UNTITLED is only set if newFile param to * constructor is set, NEW_FILE is also set if file * doesn't exist on disk. * * This is so that we can tell apart files created * with jEdit.newFile(), and those that just don't * exist on disk. * * Why do we need to tell the difference between the * two? jEdit.addBufferToList() checks if the only * opened buffer is an untitled buffer, and if so, * replaces it with the buffer to add. We don't want * this behavior to occur with files that don't * exist on disk; only untitled ones. */ setFlag(UNTITLED,newFile); setFlag(NEW_FILE,newFile); setFlag(AUTORELOAD,jEdit.getBooleanProperty("autoReload")); setFlag(AUTORELOAD_DIALOG,jEdit.getBooleanProperty("autoReloadDialog")); } //}}} //{{{ commitTemporary() method void commitTemporary() { setFlag(TEMPORARY,false); finishLoading(); } //}}} //{{{ close() method void close() { setFlag(CLOSED,true); if(autosaveFile != null) autosaveFile.delete(); // notify clients with -wait if(waitSocket != null) { try { waitSocket.getOutputStream().write('\0'); waitSocket.getOutputStream().flush(); waitSocket.getInputStream().close(); waitSocket.getOutputStream().close(); waitSocket.close(); } catch(IOException io) { //Log.log(Log.ERROR,this,io); } } } //}}} //}}} //{{{ Private members //{{{ Flags //{{{ setFlag() method private void setFlag(int flag, boolean value) { if(value) flags |= (1 << flag); else flags &= ~(1 << flag); } //}}} //{{{ getFlag() method private boolean getFlag(int flag) { int mask = (1 << flag); return (flags & mask) == mask; } //}}} //{{{ Flag values private static final int CLOSED = 0; private static final int NEW_FILE = 3; private static final int UNTITLED = 4; private static final int AUTOSAVE_DIRTY = 5; private static final int AUTORELOAD = 6; private static final int AUTORELOAD_DIALOG = 7; private static final int TEMPORARY = 10; private static final int MARKERS_CHANGED = 12; //}}} private int flags; //}}} //{{{ Instance variables private String path; private String symlinkPath; private String name; private String directory; private File file; private File autosaveFile; private long modTime; private final Vector<Marker> markers; private Socket waitSocket; //}}} //{{{ setPath() method private void setPath(final String path) { jEdit.visit(new JEditVisitorAdapter() { @Override public void visit(EditPane editPane) { editPane.bufferRenamed(Buffer.this.path, path); } }); this.path = path; VFS vfs = VFSManager.getVFSForPath(path); if((vfs.getCapabilities() & VFS.WRITE_CAP) == 0) setFileReadOnly(true); name = vfs.getFileName(path); directory = vfs.getParentOfPath(path); if(vfs instanceof FileVFS) { file = new File(path); symlinkPath = MiscUtilities.resolveSymlinks(path); // if we don't do this, the autosave file won't be // deleted after a save as if(autosaveFile != null) autosaveFile.delete(); autosaveFile = new File(file.getParent(),'#' + name + '#'); } else { // I wonder if the lack of this broke anything in the // past? file = null; autosaveFile = null; symlinkPath = path; } } //}}} //{{{ recoverAutosave() method private boolean recoverAutosave(final View view) { if(!autosaveFile.canRead()) return false; // this method might get called at startup GUIUtilities.hideSplashScreen(); final Object[] args = { autosaveFile.getPath() }; int result = GUIUtilities.confirm(view,"autosave-found",args, JOptionPane.YES_NO_OPTION,JOptionPane.WARNING_MESSAGE); if(result == JOptionPane.YES_OPTION) { VFSManager.getFileVFS().load(view,this,autosaveFile.getPath()); // show this message when all I/O requests are // complete VFSManager.runInAWTThread(new Runnable() { public void run() { GUIUtilities.message(view,"autosave-loaded",args); } }); return true; } else return false; } //}}} //{{{ checkFileForLoad() method private boolean checkFileForLoad(View view, VFS vfs, String path) { if((vfs.getCapabilities() & VFS.LOW_LATENCY_CAP) != 0) { Object session = vfs.createVFSSession(path, view); if(session == null) return false; try { VFSFile file = vfs._getFile(session,path,view); if(file == null) { setNewFile(true); return true; } if(!file.isReadable()) { VFSManager.error(view,path,"ioerror.no-read",null); setNewFile(false); return false; } setFileReadOnly(!file.isWriteable()); if(file.getType() != VFSFile.FILE) { VFSManager.error(view,path, "ioerror.open-directory",null); setNewFile(false); return false; } } catch(IOException io) { VFSManager.error(view,path,"ioerror", new String[] { io.toString() }); return false; } finally { try { vfs._endVFSSession(session,view); } catch(IOException io) { VFSManager.error(view,path,"ioerror", new String[] { io.toString() }); return false; } } } return true; } //}}} //{{{ checkFileForSave() method private static boolean checkFileForSave(View view, VFS vfs, String path) { if((vfs.getCapabilities() & VFS.LOW_LATENCY_CAP) != 0) { Object session = vfs.createVFSSession(path,view); if(session == null) return false; try { VFSFile file = vfs._getFile(session,path,view); if(file == null) return true; if(file.getType() != VFSFile.FILE) { VFSManager.error(view,path, "ioerror.save-directory",null); return false; } } catch(IOException io) { VFSManager.error(view,path,"ioerror", new String[] { io.toString() }); return false; } finally { try { vfs._endVFSSession(session,view); } catch(IOException io) { VFSManager.error(view,path,"ioerror", new String[] { io.toString() }); return false; } } } return true; } //}}} //{{{ finishLoading() method private void finishLoading() { parseBufferLocalProperties(); // AHA! // this is probably the only way to fix this FoldHandler oldFoldHandler = getFoldHandler(); setMode(); if(getFoldHandler() == oldFoldHandler) { // on a reload, the fold handler doesn't change, but // we still need to re-collapse folds. // don't do this on initial fold handler creation invalidateFoldLevels(); fireFoldHandlerChanged(); } // Create marker positions for(int i = 0; i < markers.size(); i++) { Marker marker = markers.get(i); marker.removePosition(); int pos = marker.getPosition(); if(pos > getLength()) marker.setPosition(getLength()); else if(pos < 0) marker.setPosition(0); marker.createPosition(); } } //}}} //{{{ finishSaving() method private void finishSaving(View view, String oldPath, String oldSymlinkPath, String path, boolean rename, boolean error) { //{{{ Set the buffer's path // Caveat: won't work if save() called with a relative path. // But I don't think anyone calls it like that anyway. if(!error && !path.equals(oldPath)) { Buffer buffer = jEdit.getBuffer(path); if(rename) { /* if we save a file with the same name as one * that's already open, we presume that we can * close the existing file, since the user * would have confirmed the overwrite in the * 'save as' dialog box anyway */ if(buffer != null && /* can't happen? */ !buffer.getPath().equals(oldPath)) { buffer.setDirty(false); jEdit.closeBuffer(view,buffer); } setPath(path); } else { /* if we saved over an already open file using * 'save a copy as', then reload the existing * buffer */ if(buffer != null && /* can't happen? */ !buffer.getPath().equals(oldPath)) { buffer.load(view,true); } } } //}}} //{{{ Update this buffer for the new path if(rename) { if(file != null) modTime = file.lastModified(); if(!error) { // we do a write lock so that the // autosave, which grabs a read lock, // is not executed between the // deletion of the autosave file // and clearing of the dirty flag try { writeLock(); if(autosaveFile != null) autosaveFile.delete(); setFlag(AUTOSAVE_DIRTY,false); setFileReadOnly(false); setFlag(NEW_FILE,false); setFlag(UNTITLED,false); super.setDirty(false); if(jEdit.getBooleanProperty("resetUndoOnSave")) { undoMgr.clear(); } } finally { writeUnlock(); } parseBufferLocalProperties(); if(!getPath().equals(oldPath)) { if (!isTemporary()) jEdit.updatePosition(oldSymlinkPath,this); setMode(); } else { // if user adds mode buffer-local property String newMode = getStringProperty("mode"); if(newMode != null && !newMode.equals(getMode() .getName())) setMode(); else propertiesChanged(); } if (!isTemporary()) { EditBus.send(new BufferUpdate(this, view,BufferUpdate.DIRTY_CHANGED)); // new message type introduced in 4.0pre4 EditBus.send(new BufferUpdate(this, view,BufferUpdate.SAVED)); } } } //}}} } //}}} //{{{ editSyntaxStyle() method /** * Edit the syntax style of the token under the caret. * * @param textArea the textarea where your caret is * @since jEdit 4.3pre11 */ void editSyntaxStyle(JEditTextArea textArea) { int lineNum = textArea.getCaretLine(); int start = getLineStartOffset(lineNum); int position = textArea.getCaretPosition(); DefaultTokenHandler tokenHandler = new DefaultTokenHandler(); markTokens(lineNum,tokenHandler); Token token = tokenHandler.getTokens(); while(token.id != Token.END) { int next = start + token.length; if (start <= position && next > position) break; start = next; token = token.next; } if (token.id == Token.END || token.id == Token.NULL) { JOptionPane.showMessageDialog(jEdit.getActiveView(), jEdit.getProperty("syntax-style-no-token.message"), jEdit.getProperty("syntax-style-no-token.title"), JOptionPane.PLAIN_MESSAGE); return; } String typeName = Token.tokenToString(token.id); String property = "view.style." + typeName.toLowerCase(); SyntaxStyle currentStyle = GUIUtilities.parseStyle( jEdit.getProperty(property), "Dialog",12); SyntaxStyle style = new StyleEditor(jEdit.getActiveView(), currentStyle, typeName).getStyle(); if(style != null) jEdit.setProperty(property, GUIUtilities.getStyleString(style)); jEdit.propertiesChanged(); } //}}} //}}} }

The table below shows all metrics for Buffer.java.

MetricValueDescription
BLOCKS192.00Number of blocks
BLOCK_COMMENT45.00Number of block comment lines
COMMENTS583.00Comment lines
COMMENT_DENSITY 0.63Comment density
COMPARISONS158.00Number of comparison operators
CYCLOMATIC260.00Cyclomatic complexity
DECL_COMMENTS182.00Comments in declarations
DOC_COMMENT369.00Number of javadoc comment lines
ELOC924.00Effective lines of code
EXEC_COMMENTS37.00Comments in executable code
EXITS169.00Procedure exits
FUNCTIONS81.00Number of function declarations
HALSTEAD_DIFFICULTY98.85Halstead difficulty
HALSTEAD_EFFORT 0.00Halstead effort
INTERFACE_COMPLEXITY216.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 0.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
JAVA003469.00JAVA0034 Missing braces in if statement
JAVA0035 1.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 4.00JAVA0049 Nested block at depth N (maximum: M)
JAVA0050 0.00JAVA0050 Class derives from java.lang.Error
JAVA0051 0.00JAVA0051 Class derives from java.lang.RuntimeException
JAVA0052 0.00JAVA0052 Class derives from java.lang.Throwable
JAVA0053 0.00JAVA0053 Unused label
JAVA0054 0.00JAVA0054 Inheritance depth N exceeds maximum M
JAVA0055 0.00JAVA0055 Class should be interface
JAVA0056 0.00JAVA0056 Unnecessary abstract modifier for interface or annotation
JAVA0057 0.00JAVA0057 Unnecessary default constructor
JAVA0058 0.00JAVA0058 Constructor calls super()
JAVA0059 0.00JAVA0059 Method override only calls super()
JAVA0061 0.00JAVA0061 Inaccessible member in anonymous class
JAVA0062 0.00JAVA0062 Public class missing public member or protected constructor
JAVA0063 0.00JAVA0063 Identifier name should not contain '$'
JAVA0064 0.00JAVA0064 N variations of identifier name (maximum: M)
JAVA0065 0.00JAVA0065 Unnecessary final modifier for method in final class
JAVA0066 0.00JAVA0066 Unnecessary modifier for interface nested type
JAVA0067 0.00JAVA0067 Array descriptor on identifier name
JAVA0068 0.00JAVA0068 Modifiers not declared in recommended order
JAVA0071 0.00JAVA0071 Strings compared with ==
JAVA0073 0.00JAVA0073 Integer division in floating-point context
JAVA0074 0.00JAVA0074 Use of Object.notify()
JAVA007510.00JAVA0075 Method parameter hides field
JAVA0076 1.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 0.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 1.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
JAVA010816.00JAVA0108 Incorrect javadoc: no @param tag for 'parameter'
JAVA0109 0.00JAVA0109 Incorrect javadoc: no parameter 'parameter'
JAVA011038.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 0.00JAVA0113 Incorrect javadoc: no @author tag
JAVA0114 0.00JAVA0114 Incorrect javadoc: no @version tag
JAVA0115 0.00JAVA0115 Incorrect javadoc: no @throws or @exception tag for 'exception'
JAVA0116 5.00JAVA0116 Missing javadoc: field 'field'
JAVA0117 1.00JAVA0117 Missing javadoc: method 'method'
JAVA0118 0.00JAVA0118 Missing javadoc: type 'type'
JAVA0119 2.00JAVA0119 Control variable changed within body of for loop
JAVA0123 0.00JAVA0123 Use all three components of for loop
JAVA0125 0.00JAVA0125 Continue statement with label
JAVA0126 0.00JAVA0126 Method declares unchecked exception in throws
JAVA0128 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 1.00JAVA0136 N methods defined in class (maximum: M)
JAVA0137 0.00JAVA0137 Non-abstract class missing constructor
JAVA0138 1.00JAVA0138 N parameters defined for method (maximum: M)
JAVA0139 0.00JAVA0139 Definition of main other than public static void main(java.lang.String[])
JAVA0141 0.00JAVA0141 Unnecessary modifier for method in interface
JAVA0143 0.00JAVA0143 Synchronized method
JAVA0144 0.00JAVA0144 Line exceeds maximum M characters
JAVA01454064.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 3.00JAVA0165 Conflicting return statement in finally block
JAVA0166 0.00JAVA0166 Generic exception caught
JAVA0167 0.00JAVA0167 ThreadDeath not rethrown
JAVA0169 0.00JAVA0169 Unnecessary catch block: exception 'exception'
JAVA0170 0.00JAVA0170 Caught exception not derived from java.lang.Exception
JAVA0171 0.00JAVA0171 Unused local variable
JAVA0173 2.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 2.00JAVA0177 Variable declaration missing initializer
JAVA0179 5.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 1.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 1.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
LINES2053.00Number of lines in the source file
LINE_COMMENT169.00Number of line comments
LOC1236.00Lines of code
LOGICAL_LINES506.00Number of statements
LOOPS12.00Number of loops
NEST_DEPTH 7.00Maximum nesting depth
OPERANDS2089.00Number of operands
OPERATORS4365.00Number of operators
PARAMS78.00Number of formal parameter declarations
PROGRAM_LENGTH6454.00Halstead program length
PROGRAM_VOCAB694.00Halstead program vocabulary
PROGRAM_VOLUME 0.00Halstead program volume
RETURNS138.00Number of return points from functions
SIZE48608.00Size of the file in bytes
UNIQUE_OPERANDS634.00Number of unique operands
UNIQUE_OPERATORS60.00Number of unique operators
WHITESPACE234.00Number of whitespace lines