SmartSemicolonAutoEditStrategy.java

Index Score
net.sourceforge.phpdt.internal.ui.text
PHPeclipse

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
JAVA0034JAVA0034 Missing braces in if statement
DOC_COMMENTNumber of javadoc comment lines
COMPARISONSNumber of comparison operators
COMMENTSComment lines
LINE_COMMENTNumber of line comments
SIZESize of the file in bytes
PARAMSNumber of formal parameter declarations
INTERFACE_COMPLEXITYInterface complexity
CYCLOMATICCyclomatic complexity
LINESNumber of lines in the source file
RETURNSNumber of return points from functions
EXEC_COMMENTSComments in executable code
ELOCEffective lines of code
OPERANDSNumber of operands
PROGRAM_LENGTHHalstead program length
OPERATORSNumber of operators
DECL_COMMENTSComments in declarations
LOCLines of code
LOGICAL_LINESNumber of statements
LOOPSNumber of loops
JAVA0145JAVA0145 Tab character used in source file
UNIQUE_OPERANDSNumber of unique operands
PROGRAM_VOCABHalstead program vocabulary
BLOCKSNumber of blocks
EXITSProcedure exits
JAVA0108JAVA0108 Incorrect javadoc: no @param tag for 'parameter'
JAVA0109JAVA0109 Incorrect javadoc: no parameter 'parameter'
JAVA0008JAVA0008 Empty catch block
WHITESPACENumber of whitespace lines
JAVA0036JAVA0036 Missing braces in while statement
JAVA0130JAVA0130 Non-static method does not use instance fields
JAVA0117JAVA0117 Missing javadoc: method 'method'
JAVA0177JAVA0177 Variable declaration missing initializer
UNIQUE_OPERATORSNumber of unique operators
FUNCTIONSNumber of function declarations
PROGRAM_VOLUMEHalstead program volume
JAVA0136JAVA0136 N methods defined in class (maximum: M)
JAVA0126JAVA0126 Method declares unchecked exception in throws
JAVA0110JAVA0110 Incorrect javadoc: no @return tag
JAVA0123JAVA0123 Use all three components of for loop
JAVA0173JAVA0173 Unused method parameter
/******************************************************************************* * Copyright (c) 2000, 2004 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/cpl-v10.html * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ package net.sourceforge.phpdt.internal.ui.text; import java.util.Arrays; import net.sourceforge.phpdt.internal.compiler.parser.Scanner; import net.sourceforge.phpdt.internal.core.Assert; import net.sourceforge.phpdt.internal.ui.text.SmartBackspaceManager.UndoSpec; import net.sourceforge.phpdt.ui.PreferenceConstants; import net.sourceforge.phpeclipse.PHPeclipsePlugin; import net.sourceforge.phpeclipse.phpeditor.PHPUnitEditor; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.DocumentCommand; import org.eclipse.jface.text.IAutoEditStrategy; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.IRegion; import org.eclipse.jface.text.ITextSelection; import org.eclipse.jface.text.ITypedRegion; import org.eclipse.jface.text.Region; import org.eclipse.jface.text.TextSelection; import org.eclipse.jface.text.TextUtilities; import org.eclipse.text.edits.DeleteEdit; import org.eclipse.text.edits.MalformedTreeException; import org.eclipse.text.edits.ReplaceEdit; import org.eclipse.text.edits.TextEdit; import org.eclipse.ui.IEditorPart; import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.texteditor.ITextEditorExtension2; import org.eclipse.ui.texteditor.ITextEditorExtension3; /** * Modifies <code>DocumentCommand</code>s inserting semicolons and opening * braces to place them smartly, i.e. moving them to the end of a line if that * is what the user expects. * * <p> * In practice, semicolons and braces (and the caret) are moved to the end of * the line if they are typed anywhere except for semicolons in a * <code>for</code> statements definition. If the line contains a semicolon or * brace after the current caret position, the cursor is moved after it. * </p> * * @see org.eclipse.jface.text.DocumentCommand * @since 3.0 */ public class SmartSemicolonAutoEditStrategy implements IAutoEditStrategy { /** String representation of a semicolon. */ private static final String SEMICOLON = ";"; //$NON-NLS-1$ /** Char representation of a semicolon. */ private static final char SEMICHAR = ';'; /** String represenattion of a opening brace. */ private static final String BRACE = "{"; //$NON-NLS-1$ /** Char representation of a opening brace */ private static final char BRACECHAR = '{'; private char fCharacter; private String fPartitioning; /** * Creates a new SmartSemicolonAutoEditStrategy. * * @param partitioning * the document partitioning */ public SmartSemicolonAutoEditStrategy(String partitioning) { fPartitioning = partitioning; } /* * @see org.eclipse.jface.text.IAutoEditStrategy#customizeDocumentCommand(org.eclipse.jface.text.IDocument, * org.eclipse.jface.text.DocumentCommand) */ public void customizeDocumentCommand(IDocument document, DocumentCommand command) { // 0: early pruning // also customize if <code>doit</code> is false (so it works in code // completion situations) // if (!command.doit) // return; if (command.text == null) return; if (command.text.equals(SEMICOLON)) fCharacter = SEMICHAR; else if (command.text.equals(BRACE)) fCharacter = BRACECHAR; else return; IPreferenceStore store = PHPeclipsePlugin.getDefault() .getPreferenceStore(); if (fCharacter == SEMICHAR && !store .getBoolean(PreferenceConstants.EDITOR_SMART_SEMICOLON)) return; if (fCharacter == BRACECHAR && !store .getBoolean(PreferenceConstants.EDITOR_SMART_OPENING_BRACE)) return; IWorkbenchPage page = PHPeclipsePlugin.getActivePage(); if (page == null) return; IEditorPart part = page.getActiveEditor(); if (!(part instanceof PHPUnitEditor)) return; PHPUnitEditor editor = (PHPUnitEditor) part; if (editor.getInsertMode() != ITextEditorExtension3.SMART_INSERT || !editor.isEditable()) return; ITextEditorExtension2 extension = (ITextEditorExtension2) editor .getAdapter(ITextEditorExtension2.class); if (extension != null && !extension.validateEditorInputState()) return; if (isMultilineSelection(document, command)) return; // 1: find concerned line / position in java code, location in statement int pos = command.offset; ITextSelection line; try { IRegion l = document.getLineInformationOfOffset(pos); line = new TextSelection(document, l.getOffset(), l.getLength()); } catch (BadLocationException e) { return; } // 2: choose action based on findings (is for-Statement?) // for now: compute the best position to insert the new character int positionInLine = computeCharacterPosition(document, line, pos - line.getOffset(), fCharacter, fPartitioning); int position = positionInLine + line.getOffset(); // never position before the current position! if (position < pos) return; // never double already existing content if (alreadyPresent(document, fCharacter, position)) return; // don't do special processing if what we do is actually the normal // behaviour String insertion = adjustSpacing(document, position, fCharacter); if (command.offset == position && insertion.equals(command.text)) return; try { final SmartBackspaceManager manager = (SmartBackspaceManager) editor .getAdapter(SmartBackspaceManager.class); if (manager != null && PHPeclipsePlugin.getDefault().getPreferenceStore() .getBoolean( PreferenceConstants.EDITOR_SMART_BACKSPACE)) { TextEdit e1 = new ReplaceEdit(command.offset, command.text .length(), document.get(command.offset, command.length)); UndoSpec s1 = new UndoSpec(command.offset + command.text.length(), new Region(command.offset, 0), new TextEdit[] { e1 }, 0, null); DeleteEdit smart = new DeleteEdit(position, insertion.length()); ReplaceEdit raw = new ReplaceEdit(command.offset, command.length, command.text); UndoSpec s2 = new UndoSpec(position + insertion.length(), new Region(command.offset + command.text.length(), 0), new TextEdit[] { smart, raw }, 2, s1); manager.register(s2); } // 3: modify command command.offset = position; command.length = 0; command.caretOffset = position; command.text = insertion; command.doit = true; command.owner = null; } catch (MalformedTreeException e) { PHPeclipsePlugin.log(e); } catch (BadLocationException e) { PHPeclipsePlugin.log(e); } } /** * Returns <code>true</code> if the document command is applied on a multi * line selection, <code>false</code> otherwise. * * @param document * the document * @param command * the command * @return <code>true</code> if <code>command</code> is a multiline * command */ private boolean isMultilineSelection(IDocument document, DocumentCommand command) { try { return document.getNumberOfLines(command.offset, command.length) > 1; } catch (BadLocationException e) { // ignore return false; } } /** * Adds a space before a brace if it is inserted after a parenthesis, equal * sign, or one of the keywords <code>try, else, do</code>. * * @param document * the document we are working on * @param position * the insert position of <code>character</code> * @param character * the character to be inserted * @return a <code>String</code> consisting of <code>character</code> * plus any additional spacing */ private String adjustSpacing(IDocument doc, int position, char character) { if (character == BRACECHAR) { if (position > 0 && position <= doc.getLength()) { int pos = position - 1; if (looksLike(doc, pos, ")") //$NON-NLS-1$ || looksLike(doc, pos, "=") //$NON-NLS-1$ || looksLike(doc, pos, "]") //$NON-NLS-1$ || looksLike(doc, pos, "try") //$NON-NLS-1$ || looksLike(doc, pos, "else") //$NON-NLS-1$ || looksLike(doc, pos, "synchronized") //$NON-NLS-1$ || looksLike(doc, pos, "static") //$NON-NLS-1$ || looksLike(doc, pos, "finally") //$NON-NLS-1$ || looksLike(doc, pos, "do")) //$NON-NLS-1$ return new String(new char[] { ' ', character }); } } return new String(new char[] { character }); } /** * Checks whether a character to be inserted is already present at the * insert location (perhaps separated by some whitespace from * <code>position</code>. * * @param document * the document we are working on * @param position * the insert position of <code>ch</code> * @param character * the character to be inserted * @return <code>true</code> if <code>ch</code> is already present at * <code>location</code>, <code>false</code> otherwise */ private boolean alreadyPresent(IDocument document, char ch, int position) { int pos = firstNonWhitespaceForward(document, position, fPartitioning, document.getLength()); try { if (pos != -1 && document.getChar(pos) == ch) return true; } catch (BadLocationException e) { } return false; } /** * Computes the next insert position of the given character in the current * line. * * @param document * the document we are working on * @param line * the line where the change is being made * @param offset * the position of the caret in the line when * <code>character</code> was typed * @param character * the character to look for * @param partitioning * the document partitioning * @return the position where <code>character</code> should be inserted / * replaced */ protected static int computeCharacterPosition(IDocument document, ITextSelection line, int offset, char character, String partitioning) { String text = line.getText(); if (text == null) return 0; int insertPos; if (character == BRACECHAR) { insertPos = computeArrayInitializationPos(document, line, offset, partitioning); if (insertPos == -1) { insertPos = computeAfterTryDoElse(document, line, offset); } if (insertPos == -1) { insertPos = computeAfterParenthesis(document, line, offset, partitioning); } } else if (character == SEMICHAR) { if (isForStatement(text, offset)) { insertPos = -1; // don't do anything in for statements, as semis // are vital part of these } else { int nextPartitionPos = nextPartitionOrLineEnd(document, line, offset, partitioning); insertPos = startOfWhitespaceBeforeOffset(text, nextPartitionPos); // if there is a semi present, return its location as // alreadyPresent() will take it out this way. if (insertPos > 0 && text.charAt(insertPos - 1) == character) insertPos = insertPos - 1; } } else { Assert.isTrue(false); return -1; } return insertPos; } /** * Computes an insert position for an opening brace if <code>offset</code> * maps to a position in <code>document</code> that looks like being the * RHS of an assignment or like an array definition. * * @param document * the document being modified * @param line * the current line under investigation * @param offset * the offset of the caret position, relative to the line start. * @param partitioning * the document partitioning * @return an insert position relative to the line start if * <code>line</code> looks like being an array initialization at * <code>offset</code>, -1 otherwise */ private static int computeArrayInitializationPos(IDocument document, ITextSelection line, int offset, String partitioning) { // search backward while WS, find = (not != <= >= ==) in default // partition int pos = offset + line.getOffset(); if (pos == 0) return -1; int p = firstNonWhitespaceBackward(document, pos - 1, partitioning, -1); if (p == -1) return -1; try { char ch = document.getChar(p); if (ch != '=' && ch != ']') return -1; if (p == 0) return offset; p = firstNonWhitespaceBackward(document, p - 1, partitioning, -1); if (p == -1) return -1; ch = document.getChar(p); if (Scanner.isPHPIdentifierPart(ch) || ch == ']' || ch == '[') return offset; } catch (BadLocationException e) { } return -1; } /** * Computes an insert position for an opening brace if <code>offset</code> * maps to a position in <code>document</code> involving a keyword taking * a block after it. These are: <code>try</code>, <code>do</code>, * <code>synchronized</code>, <code>static</code>, * <code>finally</code>, or <code>else</code>. * * @param document * the document being modified * @param line * the current line under investigation * @param offset * the offset of the caret position, relative to the line start. * @return an insert position relative to the line start if * <code>line</code> contains one of the above keywords at or * before <code>offset</code>, -1 otherwise */ private static int computeAfterTryDoElse(IDocument doc, ITextSelection line, int offset) { // search backward while WS, find 'try', 'do', 'else' in default // partition int p = offset + line.getOffset(); p = firstWhitespaceToRight(doc, p); if (p == -1) return -1; p--; if (looksLike(doc, p, "try") //$NON-NLS-1$ || looksLike(doc, p, "do") //$NON-NLS-1$ || looksLike(doc, p, "synchronized") //$NON-NLS-1$ || looksLike(doc, p, "static") //$NON-NLS-1$ || looksLike(doc, p, "finally") //$NON-NLS-1$ || looksLike(doc, p, "else")) //$NON-NLS-1$ return p + 1 - line.getOffset(); return -1; } /** * Computes an insert position for an opening brace if <code>offset</code> * maps to a position in <code>document</code> with a expression in * parenthesis that will take a block after the closing parenthesis. * * @param document * the document being modified * @param line * the current line under investigation * @param offset * the offset of the caret position, relative to the line start. * @param partitioning * the document partitioning * @return an insert position relative to the line start if * <code>line</code> contains a parenthesized expression that can * be followed by a block, -1 otherwise */ private static int computeAfterParenthesis(IDocument document, ITextSelection line, int offset, String partitioning) { // find the opening parenthesis for every closing parenthesis on the // current line after offset // return the position behind the closing parenthesis if it looks like a // method declaration // or an expression for an if, while, for, catch statement int pos = offset + line.getOffset(); int length = line.getOffset() + line.getLength(); int scanTo = scanForward(document, pos, partitioning, length, '}'); if (scanTo == -1) scanTo = length; int closingParen = findClosingParenToLeft(document, pos, partitioning) - 1; while (true) { int startScan = closingParen + 1; closingParen = scanForward(document, startScan, partitioning, scanTo, ')'); if (closingParen == -1) break; int openingParen = findOpeningParenMatch(document, closingParen, partitioning); // no way an expression at the beginning of the document can mean // anything if (openingParen < 1) break; // only select insert positions for parenthesis currently embracing // the caret if (openingParen > pos) continue; if (looksLikeAnonymousClassDef(document, openingParen - 1, partitioning)) return closingParen + 1 - line.getOffset(); if (looksLikeIfWhileForCatch(document, openingParen - 1, partitioning)) return closingParen + 1 - line.getOffset(); if (looksLikeMethodDecl(document, openingParen - 1, partitioning)) return closingParen + 1 - line.getOffset(); } return -1; } /** * Finds a closing parenthesis to the left of <code>position</code> in * document, where that parenthesis is only separated by whitespace from * <code>position</code>. If no such parenthesis can be found, * <code>position</code> is returned. * * @param document * the document being modified * @param position * the first character position in <code>document</code> to be * considered * @param partitioning * the document partitioning * @return the position of a closing parenthesis left to * <code>position</code> separated only by whitespace, or * <code>position</code> if no parenthesis can be found */ private static int findClosingParenToLeft(IDocument document, int position, String partitioning) { final char CLOSING_PAREN = ')'; try { if (position < 1) return position; int nonWS = firstNonWhitespaceBackward(document, position - 1, partitioning, -1); if (nonWS != -1 && document.getChar(nonWS) == CLOSING_PAREN) return nonWS; } catch (BadLocationException e1) { } return position; } /** * Finds the first whitespace character position to the right of (and * including) <code>position</code>. * * @param document * the document being modified * @param position * the first character position in <code>document</code> to be * considered * @return the position of a whitespace character greater or equal than * <code>position</code> separated only by whitespace, or -1 if * none found */ private static int firstWhitespaceToRight(IDocument document, int position) { int length = document.getLength(); Assert.isTrue(position >= 0); Assert.isTrue(position <= length); try { while (position < length) { char ch = document.getChar(position); if (Character.isWhitespace(ch)) return position; position++; } return position; } catch (BadLocationException e) { } return -1; } /** * Finds the highest position in <code>document</code> such that the * position is &lt;= <code>position</code> and &gt; <code>bound</code> * and <code>Character.isWhitespace(document.getChar(pos))</code> * evaluates to <code>false</code> and the position is in the default * partition. * * @param document * the document being modified * @param position * the first character position in <code>document</code> to be * considered * @param partitioning * the document partitioning * @param bound * the first position in <code>document</code> to not consider * any more, with <code>bound</code> &gt; <code>position</code> * @return the highest position of one element in <code>chars</code> in [<code>position</code>, * <code>scanTo</code>) that resides in a Java partition, or * <code>-1</code> if none can be found */ private static int firstNonWhitespaceBackward(IDocument document, int position, String partitioning, int bound) { Assert.isTrue(position < document.getLength()); Assert.isTrue(bound >= -1); try { while (position > bound) { char ch = document.getChar(position); if (!Character.isWhitespace(ch) && isDefaultPartition(document, position, partitioning)) return position; position--; } } catch (BadLocationException e) { } return -1; } /** * Finds the smallest position in <code>document</code> such that the * position is &gt;= <code>position</code> and &lt; <code>bound</code> * and <code>Character.isWhitespace(document.getChar(pos))</code> * evaluates to <code>false</code> and the position is in the default * partition. * * @param document * the document being modified * @param position * the first character position in <code>document</code> to be * considered * @param partitioning * the document partitioning * @param bound * the first position in <code>document</code> to not consider * any more, with <code>bound</code> &gt; <code>position</code> * @return the smallest position of one element in <code>chars</code> in [<code>position</code>, * <code>scanTo</code>) that resides in a Java partition, or * <code>-1</code> if none can be found */ private static int firstNonWhitespaceForward(IDocument document, int position, String partitioning, int bound) { Assert.isTrue(position >= 0); Assert.isTrue(bound <= document.getLength()); try { while (position < bound) { char ch = document.getChar(position); if (!Character.isWhitespace(ch) && isDefaultPartition(document, position, partitioning)) return position; position++; } } catch (BadLocationException e) { } return -1; } /** * Finds the highest position in <code>document</code> such that the * position is &lt;= <code>position</code> and &gt; <code>bound</code> * and <code>document.getChar(position) == ch</code> evaluates to * <code>true</code> for at least one ch in <code>chars</code> and the * position is in the default partition. * * @param document * the document being modified * @param position * the first character position in <code>document</code> to be * considered * @param partitioning * the document partitioning * @param bound * the first position in <code>document</code> to not consider * any more, with <code>scanTo</code> &gt; * <code>position</code> * @param chars * an array of <code>char</code> to search for * @return the highest position of one element in <code>chars</code> in (<code>bound</code>, * <code>position</code>] that resides in a Java partition, or * <code>-1</code> if none can be found */ private static int scanBackward(IDocument document, int position, String partitioning, int bound, char[] chars) { Assert.isTrue(bound >= -1); Assert.isTrue(position < document.getLength()); Arrays.sort(chars); try { while (position > bound) { if (Arrays.binarySearch(chars, document.getChar(position)) >= 0 && isDefaultPartition(document, position, partitioning)) return position; position--; } } catch (BadLocationException e) { } return -1; } // /** // * Finds the highest position in <code>document</code> such that the // position is &lt;= <code>position</code> // * and &gt; <code>bound</code> and <code>document.getChar(position) == // ch</code> evaluates to <code>true</code> // * and the position is in the default partition. // * // * @param document the document being modified // * @param position the first character position in <code>document</code> // to be considered // * @param bound the first position in <code>document</code> to not // consider any more, with <code>scanTo</code> &gt; <code>position</code> // * @param chars an array of <code>char</code> to search for // * @return the highest position of one element in <code>chars</code> in // [<code>position</code>, <code>scanTo</code>) that resides in a Java // partition, or <code>-1</code> if none can be found // */ // private static int scanBackward(IDocument document, int position, int // bound, char ch) { // return scanBackward(document, position, bound, new char[] {ch}); // } // /** * Finds the lowest position in <code>document</code> such that the * position is &gt;= <code>position</code> and &lt; <code>bound</code> * and <code>document.getChar(position) == ch</code> evaluates to * <code>true</code> for at least one ch in <code>chars</code> and the * position is in the default partition. * * @param document * the document being modified * @param position * the first character position in <code>document</code> to be * considered * @param partitioning * the document partitioning * @param bound * the first position in <code>document</code> to not consider * any more, with <code>scanTo</code> &gt; * <code>position</code> * @param chars * an array of <code>char</code> to search for * @return the lowest position of one element in <code>chars</code> in [<code>position</code>, * <code>bound</code>) that resides in a Java partition, or * <code>-1</code> if none can be found */ private static int scanForward(IDocument document, int position, String partitioning, int bound, char[] chars) { Assert.isTrue(position >= 0); Assert.isTrue(bound <= document.getLength()); Arrays.sort(chars); try { while (position < bound) { if (Arrays.binarySearch(chars, document.getChar(position)) >= 0 && isDefaultPartition(document, position, partitioning)) return position; position++; } } catch (BadLocationException e) { } return -1; } /** * Finds the lowest position in <code>document</code> such that the * position is &gt;= <code>position</code> and &lt; <code>bound</code> * and <code>document.getChar(position) == ch</code> evaluates to * <code>true</code> and the position is in the default partition. * * @param document * the document being modified * @param position * the first character position in <code>document</code> to be * considered * @param partitioning * the document partitioning * @param bound * the first position in <code>document</code> to not consider * any more, with <code>scanTo</code> &gt; * <code>position</code> * @param chars * an array of <code>char</code> to search for * @return the lowest position of one element in <code>chars</code> in [<code>position</code>, * <code>bound</code>) that resides in a Java partition, or * <code>-1</code> if none can be found */ private static int scanForward(IDocument document, int position, String partitioning, int bound, char ch) { return scanForward(document, position, partitioning, bound, new char[] { ch }); } /** * Checks whether the content of <code>document</code> in the range (<code>offset</code>, * <code>length</code>) contains the <code>new</code> keyword. * * @param document * the document being modified * @param offset * the first character position in <code>document</code> to be * considered * @param length * the length of the character range to be considered * @param partitioning * the document partitioning * @return <code>true</code> if the specified character range contains a * <code>new</code> keyword, <code>false</code> otherwise. */ private static boolean isNewMatch(IDocument document, int offset, int length, String partitioning) { Assert.isTrue(length >= 0); Assert.isTrue(offset >= 0); Assert.isTrue(offset + length < document.getLength() + 1); try { String text = document.get(offset, length); int pos = text.indexOf("new"); //$NON-NLS-1$ while (pos != -1 && !isDefaultPartition(document, pos + offset, partitioning)) pos = text.indexOf("new", pos + 2); //$NON-NLS-1$ if (pos < 0) return false; if (pos != 0 && Scanner.isPHPIdentifierPart(text.charAt(pos - 1))) return false; if (pos + 3 < length && Scanner.isPHPIdentifierPart(text.charAt(pos + 3))) return false; return true; } catch (BadLocationException e) { } return false; } /** * Checks whether the content of <code>document</code> at * <code>position</code> looks like an anonymous class definition. * <code>position</code> must be to the left of the opening parenthesis of * the definition's parameter list. * * @param document * the document being modified * @param position * the first character position in <code>document</code> to be * considered * @param partitioning * the document partitioning * @return <code>true</code> if the content of <code>document</code> * looks like an anonymous class definition, <code>false</code> * otherwise */ private static boolean looksLikeAnonymousClassDef(IDocument document, int position, String partitioning) { int previousCommaOrParen = scanBackward(document, position - 1, partitioning, -1, new char[] { ',', '(' }); if (previousCommaOrParen == -1 || position < previousCommaOrParen + 5) // 2 // for // borders, // 3 // for // "new" return false; if (isNewMatch(document, previousCommaOrParen + 1, position - previousCommaOrParen - 2, partitioning)) return true; return false; } /** * Checks whether <code>position</code> resides in a default (Java) * partition of <code>document</code>. * * @param document * the document being modified * @param position * the position to be checked * @param partitioning * the document partitioning * @return <code>true</code> if <code>position</code> is in the default * partition of <code>document</code>, <code>false</code> * otherwise */ private static boolean isDefaultPartition(IDocument document, int position, String partitioning) { Assert.isTrue(position >= 0); Assert.isTrue(position <= document.getLength()); try { // don't use getPartition2 since we're interested in the scanned // character's partition ITypedRegion region = TextUtilities.getPartition(document, partitioning, position, false); return region.getType().equals(IDocument.DEFAULT_CONTENT_TYPE); } catch (BadLocationException e) { } return false; } /** * Finds the position of the parenthesis matching the closing parenthesis at * <code>position</code>. * * @param document * the document being modified * @param position * the position in <code>document</code> of a closing * parenthesis * @param partitioning * the document partitioning * @return the position in <code>document</code> of the matching * parenthesis, or -1 if none can be found */ private static int findOpeningParenMatch(IDocument document, int position, String partitioning) { final char CLOSING_PAREN = ')'; final char OPENING_PAREN = '('; Assert.isTrue(position < document.getLength()); Assert.isTrue(position >= 0); Assert.isTrue(isDefaultPartition(document, position, partitioning)); try { Assert.isTrue(document.getChar(position) == CLOSING_PAREN); int depth = 1; while (true) { position = scanBackward(document, position - 1, partitioning, -1, new char[] { CLOSING_PAREN, OPENING_PAREN }); if (position == -1) return -1; if (document.getChar(position) == CLOSING_PAREN) depth++; else depth--; if (depth == 0) return position; } } catch (BadLocationException e) { return -1; } } /** * Checks whether, to the left of <code>position</code> and separated only * by whitespace, <code>document</code> contains a keyword taking a * parameter list and a block after it. These are: <code>if</code>, * <code>while</code>, <code>catch</code>, <code>for</code>, * <code>synchronized</code>, <code>switch</code>. * * @param document * the document being modified * @param position * the first character position in <code>document</code> to be * considered * @param partitioning * the document partitioning * @return <code>true</code> if <code>document</code> contains any of * the above keywords to the left of <code>position</code>, * <code>false</code> otherwise */ private static boolean looksLikeIfWhileForCatch(IDocument document, int position, String partitioning) { position = firstNonWhitespaceBackward(document, position, partitioning, -1); if (position == -1) return false; return looksLike(document, position, "if") //$NON-NLS-1$ || looksLike(document, position, "while") //$NON-NLS-1$ || looksLike(document, position, "catch") //$NON-NLS-1$ || looksLike(document, position, "synchronized") //$NON-NLS-1$ || looksLike(document, position, "switch") //$NON-NLS-1$ || looksLike(document, position, "for"); //$NON-NLS-1$ } /** * Checks whether code>document</code> contains the <code>String</code> <code>like</code> * such that its last character is at <code>position</code>. If <code>like</code> * starts with a identifier part (as determined by * {@link Scanner#isPHPIdentifierPart(char)}), it is also made sure that * <code>like</code> is preceded by some non-identifier character or * stands at the document start. * * @param document * the document being modified * @param position * the first character position in <code>document</code> to be * considered * @param like * the <code>String</code> to look for. * @return <code>true</code> if <code>document</code> contains <code>like</code> * such that it ends at <code>position</code>, <code>false</code> * otherwise */ private static boolean looksLike(IDocument document, int position, String like) { int length = like.length(); if (position < length - 1) return false; try { if (!like.equals(document.get(position - length + 1, length))) return false; if (position >= length && Scanner.isPHPIdentifierPart(like.charAt(0)) && Scanner.isPHPIdentifierPart(document.getChar(position - length))) return false; } catch (BadLocationException e) { return false; } return true; } /** * Checks whether the content of <code>document</code> at * <code>position</code> looks like a method declaration header (i.e. only * the return type and method name). <code>position</code> must be just * left of the opening parenthesis of the parameter list. * * @param document * the document being modified * @param position * the first character position in <code>document</code> to be * considered * @param partitioning * the document partitioning * @return <code>true</code> if the content of <code>document</code> * looks like a method definition, <code>false</code> otherwise */ private static boolean looksLikeMethodDecl(IDocument document, int position, String partitioning) { // method name position = eatIdentToLeft(document, position, partitioning); if (position < 1) return false; position = eatBrackets(document, position - 1, partitioning); if (position < 1) return false; position = eatIdentToLeft(document, position - 1, partitioning); return position != -1; } /** * From <code>position</code> to the left, eats any whitespace and then a * pair of brackets as used to declare an array return type like * * <pre> * String [ ] * </pre>. The return value is either the position of the opening bracket * or <code>position</code> if no pair of brackets can be parsed. * * @param document * the document being modified * @param position * the first character position in <code>document</code> to be * considered * @param partitioning * the document partitioning * @return the smallest character position of bracket pair or * <code>position</code> */ private static int eatBrackets(IDocument document, int position, String partitioning) { // accept array return type int pos = firstNonWhitespaceBackward(document, position, partitioning, -1); try { if (pos > 1 && document.getChar(pos) == ']') { pos = firstNonWhitespaceBackward(document, pos - 1, partitioning, -1); if (pos > 0 && document.getChar(pos) == '[') return pos; } } catch (BadLocationException e) { // won't happen } return position; } /** * From <code>position</code> to the left, eats any whitespace and the * first identifier, returning the position of the first identifier * character (in normal read order). * <p> * When called on a document with content <code>" some string "</code> and * positionition 13, the return value will be 6 (the first letter in * <code>string</code>). * </p> * * @param document * the document being modified * @param position * the first character position in <code>document</code> to be * considered * @param partitioning * the document partitioning * @return the smallest character position of an identifier or -1 if none * can be found; always &lt;= <code>position</code> */ private static int eatIdentToLeft(IDocument document, int position, String partitioning) { if (position < 0) return -1; Assert.isTrue(position < document.getLength()); int p = firstNonWhitespaceBackward(document, position, partitioning, -1); if (p == -1) return -1; try { while (p >= 0) { char ch = document.getChar(p); if (Scanner.isPHPIdentifierPart(ch)) { p--; continue; } // length must be > 0 if (Character.isWhitespace(ch) && p != position) return p + 1; else return -1; } // start of document reached return 0; } catch (BadLocationException e) { } return -1; } /** * Returns a position in the first java partition after the last non-empty * and non-comment partition. There is no non-whitespace from the returned * position to the end of the partition it is contained in. * * @param document * the document being modified * @param line * the line under investigation * @param offset * the caret offset into <code>line</code> * @param partitioning * the document partitioning * @return the position of the next Java partition, or the end of * <code>line</code> */ private static int nextPartitionOrLineEnd(IDocument document, ITextSelection line, int offset, String partitioning) { // run relative to document final int docOffset = offset + line.getOffset(); final int eol = line.getOffset() + line.getLength(); int nextPartitionPos = eol; // init with line end int validPosition = docOffset; try { ITypedRegion partition = TextUtilities.getPartition(document, partitioning, nextPartitionPos, true); validPosition = getValidPositionForPartition(document, partition, eol); while (validPosition == -1) { nextPartitionPos = partition.getOffset() - 1; if (nextPartitionPos < docOffset) { validPosition = docOffset; break; } partition = TextUtilities.getPartition(document, partitioning, nextPartitionPos, false); validPosition = getValidPositionForPartition(document, partition, eol); } } catch (BadLocationException e) { } validPosition = Math.max(validPosition, docOffset); // make relative to line validPosition -= line.getOffset(); return validPosition; } /** * Returns a valid insert location (except for whitespace) in * <code>partition</code> or -1 if there is no valid insert location. An * valid insert location is right after any java string or character * partition, or at the end of a java default partition, but never behind * <code>maxOffset</code>. Comment partitions or empty java partitions do * never yield valid insert positions. * * @param doc * the document being modified * @param partition * the current partition * @param maxOffset * the maximum offset to consider * @return a valid insert location in <code>partition</code>, or -1 if * there is no valid insert location */ private static int getValidPositionForPartition(IDocument doc, ITypedRegion partition, int maxOffset) { final int INVALID = -1; if (IPHPPartitions.PHP_PHPDOC_COMMENT.equals(partition.getType())) return INVALID; if (IPHPPartitions.PHP_MULTILINE_COMMENT.equals(partition.getType())) return INVALID; if (IPHPPartitions.PHP_SINGLELINE_COMMENT.equals(partition.getType())) return INVALID; int endOffset = Math.min(maxOffset, partition.getOffset() + partition.getLength()); // if (IPHPPartitions.JAVA_CHARACTER.equals(partition.getType())) // return endOffset; if (IPHPPartitions.PHP_STRING_DQ.equals(partition.getType())) return endOffset; if (IPHPPartitions.PHP_STRING_SQ.equals(partition.getType())) return endOffset; if (IPHPPartitions.PHP_STRING_HEREDOC.equals(partition.getType())) return endOffset; if (IDocument.DEFAULT_CONTENT_TYPE.equals(partition.getType())) { try { if (doc.get(partition.getOffset(), endOffset - partition.getOffset()).trim().length() == 0) return INVALID; else return endOffset; } catch (BadLocationException e) { return INVALID; } } // default: we don't know anything about the partition - assume valid return endOffset; } /** * Determines whether the current line contains a for statement. Algorithm: * any "for" word in the line is a positive, "for" contained in a string * literal will produce a false positive. * * @param line * the line where the change is being made * @param offset * the position of the caret * @return <code>true</code> if <code>line</code> contains * <code>for</code>, <code>false</code> otherwise */ private static boolean isForStatement(String line, int offset) { /* searching for (^|\s)for(\s|$) */ int forPos = line.indexOf("for"); //$NON-NLS-1$ if (forPos != -1) { if ((forPos == 0 || !Scanner.isPHPIdentifierPart(line .charAt(forPos - 1))) && (line.length() == forPos + 3 || !Scanner .isPHPIdentifierPart(line.charAt(forPos + 3)))) return true; } return false; } /** * Returns the position in <code>text</code> after which there comes only * whitespace, up to <code>offset</code>. * * @param text * the text being searched * @param offset * the maximum offset to search for * @return the smallest value <code>v</code> such that * <code>text.substring(v, offset).trim() == 0</code> */ private static int startOfWhitespaceBeforeOffset(String text, int offset) { int i = Math.min(offset, text.length()); for (; i >= 1; i--) { if (!Character.isWhitespace(text.charAt(i - 1))) break; } return i; } }

The table below shows all metrics for SmartSemicolonAutoEditStrategy.java.

MetricValueDescription
BLOCKS93.00Number of blocks
BLOCK_COMMENT 5.00Number of block comment lines
COMMENTS568.00Comment lines
COMMENT_DENSITY 1.09Comment density
COMPARISONS179.00Number of comparison operators
CYCLOMATIC171.00Cyclomatic complexity
DECL_COMMENTS36.00Comments in declarations
DOC_COMMENT494.00Number of javadoc comment lines
ELOC523.00Effective lines of code
EXEC_COMMENTS27.00Comments in executable code
EXITS63.00Procedure exits
FUNCTIONS29.00Number of function declarations
HALSTEAD_DIFFICULTY113.35Halstead difficulty
HALSTEAD_EFFORT 0.00Halstead effort
INTERFACE_COMPLEXITY192.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 0.00JAVA0005 Imports not in specified order
JAVA0006 0.00JAVA0006 Empty finally block
JAVA0007 0.00JAVA0007 Should not declare public field
JAVA0008 3.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
JAVA003470.00JAVA0034 Missing braces in if statement
JAVA0035 0.00JAVA0035 Missing braces in for statement
JAVA0036 1.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 0.00JAVA0054 Inheritance depth N exceeds maximum M
JAVA0055 0.00JAVA0055 Class should be interface
JAVA0056 0.00JAVA0056 Unnecessary abstract modifier for interface or annotation
JAVA0057 0.00JAVA0057 Unnecessary default constructor
JAVA0058 0.00JAVA0058 Constructor calls super()
JAVA0059 0.00JAVA0059 Method override only calls super()
JAVA0061 0.00JAVA0061 Inaccessible member in anonymous class
JAVA0062 0.00JAVA0062 Public class missing public member or protected constructor
JAVA0063 0.00JAVA0063 Identifier name should not contain '$'
JAVA0064 0.00JAVA0064 N variations of identifier name (maximum: M)
JAVA0065 0.00JAVA0065 Unnecessary final modifier for method in final class
JAVA0066 0.00JAVA0066 Unnecessary modifier for interface nested type
JAVA0067 0.00JAVA0067 Array descriptor on identifier name
JAVA0068 0.00JAVA0068 Modifiers not declared in recommended order
JAVA0071 0.00JAVA0071 Strings compared with ==
JAVA0073 0.00JAVA0073 Integer division in floating-point context
JAVA0074 0.00JAVA0074 Use of Object.notify()
JAVA0075 0.00JAVA0075 Method parameter hides field
JAVA0076 0.00JAVA0076 Use of magic number
JAVA0077 0.00JAVA0077 Private field not used in declaring class
JAVA0078 0.00JAVA0078 Floating point values compared with ==
JAVA0079 0.00JAVA0079 Use of instance to reference static member
JAVA0080 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 1.00JAVA0084 Should use compound assignment operator
JAVA0085 0.00JAVA0085 Use of sun.* class
JAVA0087 0.00JAVA0087 Use of Thread.sleep()
JAVA0089 0.00JAVA0089 Use of restricted package
JAVA0092 0.00JAVA0092 Use of restricted type
JAVA0093 0.00JAVA0093 Redundant assignment
JAVA0094 0.00JAVA0094 Field hides a superclass field
JAVA0095 0.00JAVA0095 Uninitialized private field
JAVA0096 0.00JAVA0096 Field in nested class hides outer field
JAVA0098 0.00JAVA0098 Minimize use of implicit field initializers
JAVA0100 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 4.00JAVA0108 Incorrect javadoc: no @param tag for 'parameter'
JAVA0109 4.00JAVA0109 Incorrect javadoc: no parameter 'parameter'
JAVA0110 0.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 1.00JAVA0114 Incorrect javadoc: no @version tag
JAVA0115 0.00JAVA0115 Incorrect javadoc: no @throws or @exception tag for 'exception'
JAVA0116 0.00JAVA0116 Missing javadoc: field 'field'
JAVA0117 0.00JAVA0117 Missing javadoc: method 'method'
JAVA0118 0.00JAVA0118 Missing javadoc: type 'type'
JAVA0119 0.00JAVA0119 Control variable changed within body of for loop
JAVA0123 1.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 2.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 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
JAVA01452343.00JAVA0145 Tab character used in source file
JAVA0150 0.00JAVA0150 java.lang.Error (or subclass) thrown
JAVA0153 0.00JAVA0153 Inefficient conversion of integer to string
JAVA0159 0.00JAVA0159 Inefficient conversion of string to integer
JAVA0160 0.00JAVA0160 Method does not throw specified exception
JAVA0161 0.00JAVA0161 Conditional wait() not in loop
JAVA0163 0.00JAVA0163 Empty statement
JAVA0165 0.00JAVA0165 Conflicting return statement in finally block
JAVA0166 0.00JAVA0166 Generic exception caught
JAVA0167 0.00JAVA0167 ThreadDeath not rethrown
JAVA0169 0.00JAVA0169 Unnecessary catch block: exception 'exception'
JAVA0170 0.00JAVA0170 Caught exception not derived from java.lang.Exception
JAVA0171 0.00JAVA0171 Unused local variable
JAVA0173 1.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 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
LINES1298.00Number of lines in the source file
LINE_COMMENT69.00Number of line comments
LOC594.00Lines of code
LOGICAL_LINES265.00Number of statements
LOOPS11.00Number of loops
NEST_DEPTH 4.00Maximum nesting depth
OPERANDS1498.00Number of operands
OPERATORS2665.00Number of operators
PARAMS94.00Number of formal parameter declarations
PROGRAM_LENGTH4163.00Halstead program length
PROGRAM_VOCAB388.00Halstead program vocabulary
PROGRAM_VOLUME 0.00Halstead program volume
RETURNS98.00Number of return points from functions
SIZE43295.00Size of the file in bytes
UNIQUE_OPERANDS337.00Number of unique operands
UNIQUE_OPERATORS51.00Number of unique operators
WHITESPACE136.00Number of whitespace lines