wt.tools.xref
Class xref

java.lang.Object
  extended bywt.tools.xref.xref
All Implemented Interfaces:
ProcessFileInterface

public class xref
extends Object
implements ProcessFileInterface

This class scans a compiled Java codebase and produces a set of HTML files containing 'where used' information about the codebase. TO DO: 1) unused/uncalled methods foreach package 2) unused/uncalled fields foreach package 3) unused/uncalled constants foreach package CLEANUP TODO: 1) Eliminate redundant code, adding new PackageSpec, ClassInterfaceSpec, MethodSpec & FieldSpec's to the master SpecContainer. 2) Redundant code in processCode() in this file.

 Known Problems:

  1.  References to some static final variables are not found at this time. The javac compiler 
      compiles this information in such as way that it is not clear from the bytecode, what is 
      being referenced in a comparison statement. Consider the following:

      public static final int SUCCESS = 0;

      void someMethod(int value)
      {
          if ( value == SUCCESS )
              return
      }

      In non-static final variables, the compiler emit's getfield and/or putfield instructions for
      references to fields and in the disassembled output you see the name of the field. With
      public static final fields, it does not emit getfield/putfield instructions.


Field Summary
(package private)  String d_currentClassInterfaceName
          This variable stores the name of the current Class/Interface being processed.
(package private)  ClassInterfaceSpec d_currentClassInterfaceSpec
          This variable stores a reference to the current ClassInterface object that is being processed.
(package private)  Spec d_currentPackageSpec
          This variable stores the name of the current package being processed.
(package private)  boolean d_firstTimeCalled
          This variable is used to make sure that d_topLevelPackageName gets initialized only one time.
(package private)  String d_outputDirectory
          This variable stores the name of the output directory that the user passed in on the command line.
(package private)  String d_rootPackageName
          This variable stores the name of the root package name that the user passed in on the command line.
(package private)  String d_startingDirectory
          This variable stores the name of the starting directory that the user passed in on the command line.
(package private)  String d_topLevelPackageName
          This variable stores the top level prefix of the codebase being scanned by this tool.
static String DEFAULT_ROOT_PACKAGE_NAME
           
 
Constructor Summary
xref()
          Constructor
 
Method Summary
(package private)  void addClass(String classSpec)
          This convenience method extracts the packageName and className from the specified classSpec and then add's them both to the codebaseXref container.
(package private)  void directoryCheck(String dirName)
           
 boolean directoryNameOk(String directoryName)
          This method implements the ProcessFileInterface
(package private)  void exceptionCheck(ClassInterfaceSpec cis)
           
 boolean fileTypeOk(String fileName)
          This method provides filename filtering capability to this application and in the case of this application, all we want to do is process .class files, so this method only returns true if the fileName is a .class file.
(package private)  void getParentInterfaces(Vector container, ClassInterfaceSpec cis)
           
 void main(int someNumber)
          This meaningless method exists only to test the ability of this program to track multiple methods with the same name and different signatures.
static void main(String[] args)
           
(package private)  void processCode(ClassFile cf, CodeAttrInfo cai, MethodSpec currentMethodSpec)
          This method walks through the ByteCode watching for more subtle dependencies that only show up in the Byte Code.
(package private)  void processCommandLineArgs(String[] args)
          -s startingDirectory -mn methodNames -fn fieldNames -mc methodCalls -mcb methodCalledBy -fr fieldReference -ci classInstantiation
 void processDirectory(String directoryName)
          This method implements the ProcessFileInterface
 void processFile(String className)
          This method implements the method processFile() dictated by the interface ProcessFileInterface.
 void run(String[] args)
          this method is used to run this class in stand-alone-mode in order to process a single class file
(package private)  void textualOutput()
           
(package private) static void usage()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

d_topLevelPackageName

String d_topLevelPackageName
This variable stores the top level prefix of the codebase being scanned by this tool. This tool will normally encounter classes outside of this package like the standard Javaa stuff java.*. The contents of this variable is then used to only produce where used information for the specified codebase and NOT code outside of this codebase.


d_firstTimeCalled

boolean d_firstTimeCalled
This variable is used to make sure that d_topLevelPackageName gets initialized only one time.


d_currentPackageSpec

Spec d_currentPackageSpec
This variable stores the name of the current package being processed.


d_currentClassInterfaceName

String d_currentClassInterfaceName
This variable stores the name of the current Class/Interface being processed.


d_currentClassInterfaceSpec

ClassInterfaceSpec d_currentClassInterfaceSpec
This variable stores a reference to the current ClassInterface object that is being processed.


d_rootPackageName

String d_rootPackageName
This variable stores the name of the root package name that the user passed in on the command line.


d_startingDirectory

String d_startingDirectory
This variable stores the name of the starting directory that the user passed in on the command line. This directory and optionally any of it's subdirectories should contain one or more .class files that this program will process.


d_outputDirectory

String d_outputDirectory
This variable stores the name of the output directory that the user passed in on the command line. This is the directory where all output from this program will be written.


DEFAULT_ROOT_PACKAGE_NAME

public static final String DEFAULT_ROOT_PACKAGE_NAME
See Also:
Constant Field Values
Constructor Detail

xref

public xref()
Constructor

Method Detail

addClass

void addClass(String classSpec)
        throws Exception
This convenience method extracts the packageName and className from the specified classSpec and then add's them both to the codebaseXref container.

Throws:
Exception

processDirectory

public void processDirectory(String directoryName)
This method implements the ProcessFileInterface

Specified by:
processDirectory in interface ProcessFileInterface
See Also:
ProcessFileInterface

directoryNameOk

public boolean directoryNameOk(String directoryName)
This method implements the ProcessFileInterface

Specified by:
directoryNameOk in interface ProcessFileInterface
See Also:
ProcessFileInterface

fileTypeOk

public boolean fileTypeOk(String fileName)
This method provides filename filtering capability to this application and in the case of this application, all we want to do is process .class files, so this method only returns true if the fileName is a .class file. This method implements the method fileTypeOk() dictated by the interface ProcessFileInterface.

Specified by:
fileTypeOk in interface ProcessFileInterface
See Also:
ProcessFileInterface

exceptionCheck

void exceptionCheck(ClassInterfaceSpec cis)

processFile

public void processFile(String className)
This method implements the method processFile() dictated by the interface ProcessFileInterface.

Specified by:
processFile in interface ProcessFileInterface
See Also:
ProcessFileInterface

getParentInterfaces

void getParentInterfaces(Vector container,
                         ClassInterfaceSpec cis)

directoryCheck

void directoryCheck(String dirName)

processCommandLineArgs

void processCommandLineArgs(String[] args)
-s startingDirectory -mn methodNames -fn fieldNames -mc methodCalls -mcb methodCalledBy -fr fieldReference -ci classInstantiation


processCode

void processCode(ClassFile cf,
                 CodeAttrInfo cai,
                 MethodSpec currentMethodSpec)
           throws Exception
This method walks through the ByteCode watching for more subtle dependencies that only show up in the Byte Code. Things like:
  1. use of the INSTANCEOF instruction
  2. reference to a field in a class
  3. instantiation of a class
  4. call to a method in a class

Throws:
Exception

usage

static void usage()

textualOutput

void textualOutput()

run

public void run(String[] args)
this method is used to run this class in stand-alone-mode in order to process a single class file


main

public void main(int someNumber)
This meaningless method exists only to test the ability of this program to track multiple methods with the same name and different signatures.


main

public static void main(String[] args)