org.sadun.util.codegen
Class VariableNameGenerator

java.lang.Object
  extended byorg.sadun.util.codegen.VariableNameGenerator

public class VariableNameGenerator
extends java.lang.Object

A class to generate variable names depending on types.

Given a method name and a Java type, the generateNext() method produces valid (i.e. compilable) sequences of variable names, depending on the passed type, until either a different method name is passed or the reset() method is invoked.

For example, the invocations:

  generateNext("myMethod", t1);
  generateNext("myMethod", t2);
  generateNext("myMethod", t3);
 
where t1=String, t2=int, t3=String will produce string1, i1, string2.

This generator supports both JDK1.3 and JDK1.4 keywords.

Version:
1.0
Author:
Cristiano Sadun

Field Summary
static int JDK1_3
          Constant to use at construction to indicate JDK1_3 keyword compliance.
static int JDK1_4
          Constant to use at construction to indicate JDK1_4 keyword compliance.
 
Constructor Summary
VariableNameGenerator()
          Create a variable name generator for the JDK1_4 target compiler (see class constants).
VariableNameGenerator(int jdkRelease)
          Create a variable name generator for the given target compiler (see class constants).
 
Method Summary
 java.lang.String generateNext(java.lang.String methodName, java.lang.Class type)
           
 void reset()
          Reset the name generator
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

JDK1_3

public static final int JDK1_3
Constant to use at construction to indicate JDK1_3 keyword compliance.

See Also:
Constant Field Values

JDK1_4

public static final int JDK1_4
Constant to use at construction to indicate JDK1_4 keyword compliance.

See Also:
Constant Field Values
Constructor Detail

VariableNameGenerator

public VariableNameGenerator(int jdkRelease)
Create a variable name generator for the given target compiler (see class constants).

Parameters:
jdkRelease - one of the JDK_x constants.

VariableNameGenerator

public VariableNameGenerator()
Create a variable name generator for the JDK1_4 target compiler (see class constants).

Method Detail

reset

public void reset()
Reset the name generator


generateNext

public java.lang.String generateNext(java.lang.String methodName,
                                     java.lang.Class type)