javar.util
Class ClassHelper

java.lang.Object
  |
  +--javar.util.ClassHelper

public class ClassHelper
extends Object

This will help do some conversions that may be needed.

Author:
Ben Litchfield (ben@csh.rit.edu)

Field Summary
static String BOOLEAN
           
static String BYTE
           
static String CHAR
           
static String DOUBLE
           
static String FLOAT
           
static String INT
           
static String KEYWORD_EXTENDS
           
static String KEYWORD_IMPLEMENTS
           
static String KEYWORD_IMPORT
           
static String KEYWORD_PACKAGE
           
static String KEYWORD_THIS
           
static String LONG
           
static String MODIFIER_ABSTRACT
           
static String MODIFIER_CLASS
           
static String MODIFIER_FINAL
           
static String MODIFIER_INTERFACE
           
static String MODIFIER_NATIVE
           
static String MODIFIER_PRIVATE
           
static String MODIFIER_PROTECTED
           
static String MODIFIER_PUBLIC
           
static String MODIFIER_STATIC
           
static String MODIFIER_STRICTFP
           
static String MODIFIER_SYNCHRONIZED
           
static String MODIFIER_TRANSIENT
           
static String MODIFIER_VOLATILE
           
static String SHORT
           
static String VOID
           
 
Constructor Summary
ClassHelper()
           
 
Method Summary
static File createDestination(String className, File dir, String extension)
          This will simply create the destination file for where this class should be saved.
static Vector getArguments(String type)
          This will get all the arguments a method takes.
static String getPackage(String className)
          This will return the name of the package for a class.
static String getReturnType(String type)
          This will get all the arguments that a method takes.
static String getShortClassName(String className)
          This will return the name of this class without the package.
static String getShortestClassName(JavaByteCodeFile aClass, String className)
          This will get the short name of a class if applicable.
static String makeValidJavaIdentifier(String identifier)
          This will take in a string and return a valid java identifier by stripping off all invalid characters.
static String typeToJava(String type)
          This will take a class type and convert it into a normal java type.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

KEYWORD_PACKAGE

public static final String KEYWORD_PACKAGE
See Also:
Constant Field Values

KEYWORD_IMPORT

public static final String KEYWORD_IMPORT
See Also:
Constant Field Values

KEYWORD_EXTENDS

public static final String KEYWORD_EXTENDS
See Also:
Constant Field Values

KEYWORD_IMPLEMENTS

public static final String KEYWORD_IMPLEMENTS
See Also:
Constant Field Values

KEYWORD_THIS

public static final String KEYWORD_THIS
See Also:
Constant Field Values

MODIFIER_PUBLIC

public static final String MODIFIER_PUBLIC
See Also:
Constant Field Values

MODIFIER_PRIVATE

public static final String MODIFIER_PRIVATE
See Also:
Constant Field Values

MODIFIER_PROTECTED

public static final String MODIFIER_PROTECTED
See Also:
Constant Field Values

MODIFIER_ABSTRACT

public static final String MODIFIER_ABSTRACT
See Also:
Constant Field Values

MODIFIER_STATIC

public static final String MODIFIER_STATIC
See Also:
Constant Field Values

MODIFIER_FINAL

public static final String MODIFIER_FINAL
See Also:
Constant Field Values

MODIFIER_NATIVE

public static final String MODIFIER_NATIVE
See Also:
Constant Field Values

MODIFIER_SYNCHRONIZED

public static final String MODIFIER_SYNCHRONIZED
See Also:
Constant Field Values

MODIFIER_STRICTFP

public static final String MODIFIER_STRICTFP
See Also:
Constant Field Values

MODIFIER_INTERFACE

public static final String MODIFIER_INTERFACE
See Also:
Constant Field Values

MODIFIER_TRANSIENT

public static final String MODIFIER_TRANSIENT
See Also:
Constant Field Values

MODIFIER_VOLATILE

public static final String MODIFIER_VOLATILE
See Also:
Constant Field Values

MODIFIER_CLASS

public static final String MODIFIER_CLASS
See Also:
Constant Field Values

VOID

public static final String VOID
See Also:
Constant Field Values

BOOLEAN

public static final String BOOLEAN
See Also:
Constant Field Values

SHORT

public static final String SHORT
See Also:
Constant Field Values

LONG

public static final String LONG
See Also:
Constant Field Values

INT

public static final String INT
See Also:
Constant Field Values

FLOAT

public static final String FLOAT
See Also:
Constant Field Values

DOUBLE

public static final String DOUBLE
See Also:
Constant Field Values

CHAR

public static final String CHAR
See Also:
Constant Field Values

BYTE

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

ClassHelper

public ClassHelper()
Method Detail

typeToJava

public static String typeToJava(String type)
                         throws JavarBadArgumentException
This will take a class type and convert it into a normal java type. For example Ljava/lang/String; -> java.lang.String I -> int [I -> int[]

JavarBadArgumentException

getShortClassName

public static String getShortClassName(String className)
This will return the name of this class without the package.

Returns:
The name of this class;

getPackage

public static String getPackage(String className)
This will return the name of the package for a class.

Returns:
The name of the package;

getShortestClassName

public static String getShortestClassName(JavaByteCodeFile aClass,
                                          String className)
This will get the short name of a class if applicable. ie "java.lang.String" will return "String" but not if this class references "com.company.String" because that would create a class name conflict.

Parameters:
className - A fully qualified className.
Returns:
The shortest name that can be used for that class.

createDestination

public static File createDestination(String className,
                                     File dir,
                                     String extension)
                              throws JavarIOException
This will simply create the destination file for where this class should be saved. This is a helper method that will create a directory structure and file based on the package structure of a class.

Parameters:
className - The name of the class.
dir - The root directory to create
extension - The extension to the file
JavarIOException

getReturnType

public static String getReturnType(String type)
                            throws JavarBadArgumentException
This will get all the arguments that a method takes.

Parameters:
type - A type descriptor for a method.
Returns:
A string representing the type of return value.
Throws:
JavarBadArgumentException - If there is an error during the parse of arguments.

getArguments

public static Vector getArguments(String type)
                           throws JavarParseException
This will get all the arguments a method takes.

Parameters:
type - A type descriptor for a method.
Returns:
A List of string elements that represent the types of arguments
Throws:
JavarParseException - If there is an error during the parse of arguments.

makeValidJavaIdentifier

public static String makeValidJavaIdentifier(String identifier)
This will take in a string and return a valid java identifier by stripping off all invalid characters. This will return null if there are no characters left.

Parameters:
identifier - A potential java identifier.
Returns:
a Valid java identifier.