FileDocCategorySizeDatePackage
ClassParser.javaAPI DocJ2ME CLDC 1.15718Wed Feb 05 15:56:04 GMT 2003kdp.classparser

ClassParser

public class ClassParser extends Object
Main program to run my Java class file parser.
author
Aaron Dietrich
version
$Id: ClassParser.java,v 1.2 2000/08/14 19:49:10 zmm3876 Exp $ Revision History $Log: ClassParser.java,v $ Revision 1.2 2000/08/14 19:49:10 zmm3876 *** empty log message *** Revision 1.1 2000/08/09 16:11:49 zmm3876 *** empty log message *** Revision 1.1.1.1 2000/07/07 13:34:23 jrv Initial import of kdp code Revision 1.1.1.1 2000/05/31 19:14:47 ritsun Initial import of kvmdt to CVS Revision 1.2 2000/05/15 16:52:51 jpc1870 added locationsOfLine() to refType() Revision 1.1 2000/04/25 00:36:43 ritsun Initial revision

Fields Summary
private String
className
Name of the Java class file to read
private String
baseName
private int
lineNumber
line number to look up in the class file, -1 if we don't want to look up a specific line just print all available class information
public ClassFile
classFile
stores the class file contents
private int
classID
private byte
typeTag
Constructors Summary
public ClassParser(String className, byte typeTag)
Constructor.

param
className classname

    
    
                         
          
    //make sure they passed at least 1 arg
    int index;

    
    //store the class file name
    this.className = className;
    if ((index = className.lastIndexOf('/")) != -1)
        this.baseName = className.substring(index+1);
    else
        this.baseName = className;
    this.typeTag = typeTag;
    
Methods Summary
public booleanequals(java.lang.String newclassName)

        return className.equals( newclassName );
    
public java.lang.StringgetBaseName()

    return baseName;
    
public ClassFilegetClassFile()
Returns the classFile object

    return classFile;
    
public java.lang.StringgetClassFileName()
Returns the class filename

    return (className + ".class");
    
public intgetClassID()

    return (classID);
    
public java.lang.StringgetClassName()

    return className;
    
public java.lang.StringgetFullClassFileName()

    return (className + ".class");
    
public bytegetJDWPTypeTag()

    return typeTag;
    
public static voidmain(java.lang.String[] args)
Main method. Where it all begins... and ends too.

param
args[] array of command line arguments

    int lineNumber = 0;
    ClassFile classfile;
        FileReference file = FileReference.create(args[0], args[1]);

      //declare a ClassParser object
      
      //create a new ClassFile object passing it the name of the
      //class file
      classfile = new ClassFile (file, args[1], (byte)'L");
      //read the class file
        try {
            classfile.readClassFile ();
        } catch (IOException e) {
            Log.LOGN(3, "Main: caught IOException " + e);
        }

      Log.LOGN(3, "\n");

      //if a line number was not specified then just output everything
      if (args.length < 3)
        classfile.print (System.out);
      else {
        //just output the information for the method the specified by line number
     lineNumber = Integer.parseInt (args[2]);
         MethodInfo    method = classfile.lookUpMethodByLineNumber (lineNumber);
         if (method != null)
           {
            Log.LOGN(3, "Associated the method \"" + method.getName () +
                                "\" with line number " + lineNumber + ".");
            Log.LOGN(3, "The following information if available for " +
                                 method.getName () + ".");
            Log.LOGN(3, method.toString());

            //output the code array index for this method at which a breakpoint
            //should be placed in order to stop at the specified line in the
            //source file.
            Log.LOGN(3, "");
            Log.LOGN(3, "To put a breakpoint at line " + lineNumber +
                                " break at code index " +
                                method.getCodeIndex (lineNumber) + ".");
            
            Log.LOGN(3, "");
            Log.LOGN(3, "Breakpoints can be set at the following lines in " +
                                 method.getName () + ":");
            Log.LOGN(3, "tSource Line Number\tBytecode Offset");
            Log.LOGN(3, "t------------------\t---------------");
            
            int     lineNumbers[][] = method.getBreakableLineNumbers ();
            if (lineNumbers == null)
              Log.LOGN(3, "Method contains no breakable lines.");
            else
              for (int lcv = 0; lcv < lineNumbers.length; ++lcv)
                Log.LOGN(3, "t\t" + lineNumbers[lcv][0] + "\t\t\t" + lineNumbers[lcv][1]);
           }
         else
           //the specified line was not an executable line of code within a method
           Log.LOGN(3, "Line number " + lineNumber + " does not contain" +
                               " code within a method.");
        }
        
       // classfile.getVariableTableForMethodName("main");
     
public voidsetClassID(int classID)

    this.classID = classID;