net.sourceforge.retroweaver.translator
Class NameTranslator

java.lang.Object
  extended by net.sourceforge.retroweaver.translator.NameTranslator

public class NameTranslator
extends java.lang.Object

Substitutes JDK 1.5 classes for their mirrors. Out of the box, Retroweaver supports: all new language features and their associated runtime (autoboxing, generics, annotations, extended for loop, static import, varargs) java.util.concurrent TODO: full list of what is supported Additional runtime support can be added to Retroweaver by writing a mirror class and adding it to the class path. A mirror class can be one of two types: class or methods mirror. 1) Class mirror: Retroweaver replaces every single reference to the JDK 1.5 class directly with the mirror class. 2) Methods mirror: Retroweaver replaces calls to the JDK 1.5 class with static calls to the mirror class. Mirrors for instance calls are different from mirrors from static calls in that Retroweaver adds the JDK 1.5 object as the first parameter to the mirror. For example, a static call to java.lang.Integer.valueOf( int ) is replaced directly by net.sourceforge.retroweaver.runtime.java.lang.Integer_.valueOf( int ). However, an instance call to Class.getAnnotations() is replaced with a static call to net.sourceforge.retroweaver.runtime.java.lang.Class_.getAnnotations( Class ). Notice how the receiver (Class) is added as the first parameter to the mirror call. In order for Retroweaver to find your mirror classes, you must place them in Retroweaver's class path and register their mirror namespace. A mirror namespace defines the prefix of the package being replaced and the prefix of the package doing the replacing. For example, the namespace for the java.util.concurrent backport mirrors is "java.util.concurrent/edu.emory.mathcs.backport.java.util.concurrent". Retroweaver has a default mirror namespace "/net.sourceforge.retroweaver.runtime". As an example, java.lang.annotation.Annotation is replaced with net.sourceforge.retroweaver.runtime.java.lang.annotation.Annotation. In order to differentiate class mirrors from methods mirrors, a methods mirror must have exactly one trailing underscore in its class name: for example, net.sourceforge.retroweaver.runtime.java.lang.Class_


Method Summary
 void addNameSpace(NameSpace nameSpace)
          Adds a new runtime subsystem for the name translation.
 java.lang.String getClassMirrorTranslation(java.lang.String name)
          Translates the name only if it represents a fully mirrored class.
 java.lang.String getClassMirrorTranslationDescriptor(java.lang.String name)
          Translates the name only if it represents a fully mirrored class.
static NameTranslator getGeneralTranslator()
           
protected  net.sourceforge.retroweaver.translator.Mirror getMirror(java.lang.String class_)
          Returns either a class or methods mirror Returns noMirror if there is no match
static NameTranslator getStringBuilderTranslator()
           
protected  java.lang.String translate(java.lang.String name)
          Translate an id or a method signature into its retroweaver runtime or concurrent backport equivalent.
protected  java.lang.String translateDescriptor(java.lang.String descriptor)
          Translates a simple type descriptor, specifically.
protected  java.lang.String translateMethodDescriptor(java.lang.String descriptor)
          Translates a descriptor, specifically.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getGeneralTranslator

public static final NameTranslator getGeneralTranslator()

getStringBuilderTranslator

public static final NameTranslator getStringBuilderTranslator()

addNameSpace

public void addNameSpace(NameSpace nameSpace)
Adds a new runtime subsystem for the name translation. For instance the concurrency backport translation is done with the NameSpace "java.util.concurrent", "edu.emory.mathcs.backport.java.util.concurrent"


getMirror

protected net.sourceforge.retroweaver.translator.Mirror getMirror(java.lang.String class_)
Returns either a class or methods mirror Returns noMirror if there is no match


translate

protected java.lang.String translate(java.lang.String name)
Translate an id or a method signature into its retroweaver runtime or concurrent backport equivalent.

Parameters:
name - The String to translate.
Returns:
the translated name

getClassMirrorTranslation

public java.lang.String getClassMirrorTranslation(java.lang.String name)
Translates the name only if it represents a fully mirrored class.


getClassMirrorTranslationDescriptor

public java.lang.String getClassMirrorTranslationDescriptor(java.lang.String name)
Translates the name only if it represents a fully mirrored class.


translateMethodDescriptor

protected java.lang.String translateMethodDescriptor(java.lang.String descriptor)
Translates a descriptor, specifically. Only translates names in the descriptor, if they are represented by class mirrors.


translateDescriptor

protected java.lang.String translateDescriptor(java.lang.String descriptor)
Translates a simple type descriptor, specifically. Only translates names in the descriptor, if they are represented by class mirrors.