com.ibm.lab.soln.jdt
Class JavaMetrics

java.lang.Object
  |
  +--com.ibm.lab.soln.jdt.JavaMetrics
All Implemented Interfaces:
org.eclipse.jdt.core.IElementChangedListener

public class JavaMetrics
extends java.lang.Object
implements org.eclipse.jdt.core.IElementChangedListener

The purpose of JavaMetrics is to demonstrate how to integrate with the JDT model. It defines some basic Java code metrics:

This class will work with the JavaMetricsView to enable the user to see basic code metrics updated in real-time as the underlying Java model is changed.

See Also:
ASTNode, ASTVisitor, ICompilationUnit, IElementChangedListener, IJavaMetricsListener, JavaMetricsView

Constructor Summary
JavaMetrics()
          Returns an instance of JavaMetrics, initialized to zero.
 
Method Summary
 void addListener(IJavaMetricsListener listener)
          Add a change listener.
 void elementChanged(org.eclipse.jdt.core.ElementChangedEvent event)
          Notifies that one or more attributes of one or more Java elements have changed.
 int getFieldDeclarationCount()
          Return basic metrics.
 int getMethodDeclarationCount()
          Return basic metrics.
 int getStringLiteralCount()
          Return basic metrics.
 boolean hasValidMetrics()
          This method returns false in the case where this metrics instance does not yet have a compilation unit (i.e., everything is zero).
protected  boolean processFieldDeclaration(org.eclipse.jdt.core.dom.FieldDeclaration node)
          See JavaMetricsAccumulator inner class.
protected  boolean processMethodDeclaration(org.eclipse.jdt.core.dom.MethodDeclaration node)
          See JavaMetricsAccumulator inner class.
protected  boolean processStringLiteral(org.eclipse.jdt.core.dom.StringLiteral node)
          See JavaMetricsAccumulator inner class.
 void removeListener(IJavaMetricsListener listener)
          Remove a change listener.
 void reset(org.eclipse.jdt.core.ICompilationUnit newcu)
          Reset and recalculate code metrics for the given ICompilationUnit.
 java.lang.String summaryString()
          Return a string representation suitable for display.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JavaMetrics

public JavaMetrics()
Returns an instance of JavaMetrics, initialized to zero.

Method Detail

addListener

public void addListener(IJavaMetricsListener listener)
Add a change listener.

Parameters:
listener - new listener.
See Also:
IJavaMetricsListener

elementChanged

public void elementChanged(org.eclipse.jdt.core.ElementChangedEvent event)
Notifies that one or more attributes of one or more Java elements have changed. The specific details of the change are described by the given event. IJavaMetricsListener will be notified if this affected the calculated metrics.

Specified by:
elementChanged in interface org.eclipse.jdt.core.IElementChangedListener
Parameters:
event - the change event
See Also:
IJavaMetricsListener, JavaCore.addElementChangedListener(IElementChangedListener)

getFieldDeclarationCount

public int getFieldDeclarationCount()
Return basic metrics.

Returns:
The number of fields found in the compilation unit.

getMethodDeclarationCount

public int getMethodDeclarationCount()
Return basic metrics.

Returns:
The number of methods found in the compilation unit.

getStringLiteralCount

public int getStringLiteralCount()
Return basic metrics.

Returns:
The number of string literals ("string") found in the compilation unit.

hasValidMetrics

public boolean hasValidMetrics()
This method returns false in the case where this metrics instance does not yet have a compilation unit (i.e., everything is zero).

See Also:
summaryString()

processFieldDeclaration

protected boolean processFieldDeclaration(org.eclipse.jdt.core.dom.FieldDeclaration node)
See JavaMetricsAccumulator inner class.


processMethodDeclaration

protected boolean processMethodDeclaration(org.eclipse.jdt.core.dom.MethodDeclaration node)
See JavaMetricsAccumulator inner class.


processStringLiteral

protected boolean processStringLiteral(org.eclipse.jdt.core.dom.StringLiteral node)
See JavaMetricsAccumulator inner class.


removeListener

public void removeListener(IJavaMetricsListener listener)
Remove a change listener.

Parameters:
listener - old listener.
See Also:
IJavaMetricsListener

reset

public void reset(org.eclipse.jdt.core.ICompilationUnit newcu)
Reset and recalculate code metrics for the given ICompilationUnit. Listeners will be notified of this change.

Parameters:
newcu - new compilation unit whose metrics this class represents.
See Also:
IJavaMetricsListener

summaryString

public java.lang.String summaryString()
Return a string representation suitable for display.