edu.rice.cs.javalanglevels
Class LanguageLevelConverter

java.lang.Object
  extended by edu.rice.cs.javalanglevels.LanguageLevelConverter

public class LanguageLevelConverter
extends Object

An instance of this class converts a language level file to a .java file of the same name by first visiting the file to error-check it, and then by augmenting the file. This class is tested at the top level in the AdvancedLevelTest, ElementaryLevelTest, and IntermediateLevelTest.


Field Summary
static Log _log
           
static Hashtable<SymbolData,LanguageLevelVisitor> _newSDs
          Stores all the SymbolDatas (and corresponding visitors) created as in course of conversion.
static int INPUT_BUFFER_SIZE
           
static int LINE_NUM_MAPPINGS_PER_LINE
          Number of line number mappings (from dj* to java) per line.
static Options OPT
           
static Symboltable symbolTable
          Hashtable for a shared symbolTable.
 
Constructor Summary
LanguageLevelConverter()
           
 
Method Summary
static SymbolData _classFile2SymbolData(String qualifiedClassName)
          Defines library classes assuming they are available to the PathClassLoader.
static SymbolData _classFile2SymbolData(String qualifiedClassName, String programRoot)
          Uses the ASM class reader to read the class file corresponding to the class in the specified directory, and uses the information from ASM to build a SymbolData corresponding to the class.
static SymbolData _getPrimitiveSymbolData(String className)
          Checks to see if the provided class name is the name of a primative type, and if so, returns the corresponding SymbolData.
 Pair<LinkedList<JExprParseException>,LinkedList<Pair<String,JExpressionIF>>> convert(File[] files, Options options)
          Parse, Visit, Type Check, and Convert any language level files in the array of files.
 Pair<LinkedList<JExprParseException>,LinkedList<Pair<String,JExpressionIF>>> convert(File[] files, Options options, Map<File,Set<String>> sourceToTopLevelClassMap)
          Parse, visit, type check, and convert any language level files (and unconverted LL files they reference) in files/
static SymbolData getSymbolDataForClassFile(String className, String programRoot)
          Resolves a reference to a class embedded in a class file.
static boolean isAdvancedFile(File f)
          If a file name ends with .dj2, it is an Advanced File, which is a legacy notion.
static boolean isElementaryFile(File f)
          If a file name ends with .dj0, it is an Elementary File
static boolean isFullJavaFile(File f)
          If a file name ends with .dj, it is a Functional Java File
static boolean isFunctionalJavaFile(File f)
          If a file name ends with .dj, it is a Functional Java File
static boolean isIntermediateFile(File f)
          If a file name ends with .dj1, it is an Intermediate File
static void loadSymbolTable()
          Ensures that the symbol table contains essential symbols.
static void main(String[] args)
          Do a conversion from the command line, to allow quick testing
static boolean versionIs15(JavaVersion version)
           
static boolean versionSupportsAutoboxing(JavaVersion version)
          Only certain versions of the java compiler support autoboxing
static boolean versionSupportsForEach(JavaVersion version)
          Only 1.5 supports for each
static boolean versionSupportsGenerics(JavaVersion version)
          Only certain versions of the java compiler support generics
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_log

public static final Log _log

symbolTable

public static final Symboltable symbolTable
Hashtable for a shared symbolTable. Since this field is static, only one instance of LanguageLevelConverter should exist at a time. If we create a LanguageLevelConverter instance for each translation, we must drop the static attribute.


OPT

public static Options OPT

INPUT_BUFFER_SIZE

public static final int INPUT_BUFFER_SIZE
See Also:
Constant Field Values

LINE_NUM_MAPPINGS_PER_LINE

public static final int LINE_NUM_MAPPINGS_PER_LINE
Number of line number mappings (from dj* to java) per line.

See Also:
Constant Field Values

_newSDs

public static final Hashtable<SymbolData,LanguageLevelVisitor> _newSDs
Stores all the SymbolDatas (and corresponding visitors) created as in course of conversion. If we create a LanguageLevelConverter instance for each translation, we must drop the static attribute.

Constructor Detail

LanguageLevelConverter

public LanguageLevelConverter()
Method Detail

loadSymbolTable

public static void loadSymbolTable()
Ensures that the symbol table contains essential symbols. Should be done in the symbol table class.


_classFile2SymbolData

public static SymbolData _classFile2SymbolData(String qualifiedClassName)
Defines library classes assuming they are available to the PathClassLoader.


_classFile2SymbolData

public static SymbolData _classFile2SymbolData(String qualifiedClassName,
                                               String programRoot)
Uses the ASM class reader to read the class file corresponding to the class in the specified directory, and uses the information from ASM to build a SymbolData corresponding to the class. Ensures that the returned SymbolData (if any) is inserted in the symbolTable.

Parameters:
qualifiedClassName - The fully qualified class name of the class we are looking up
programRoot - The directory where the class is located.
Returns:
The SymbolData for the class file if the class file was found; null otherwise.

getSymbolDataForClassFile

public static SymbolData getSymbolDataForClassFile(String className,
                                                   String programRoot)
Resolves a reference to a class embedded in a class file. Assumes the class name is fully qualified. If the program is well-formed, the referenced class will either be: (i) primitive; (ii) already present in the symbol table; or (iii) a reference to another class defined by a class file. If the result is null, gives an error. Removes the symbol data from the continuations list, and return it.

Returns:
the result of trying to resolve className.

_getPrimitiveSymbolData

public static SymbolData _getPrimitiveSymbolData(String className)
Checks to see if the provided class name is the name of a primative type, and if so, returns the corresponding SymbolData. Otherwise, returns null.


convert

public Pair<LinkedList<JExprParseException>,LinkedList<Pair<String,JExpressionIF>>> convert(File[] files,
                                                                                            Options options)
Parse, Visit, Type Check, and Convert any language level files in the array of files.


convert

public Pair<LinkedList<JExprParseException>,LinkedList<Pair<String,JExpressionIF>>> convert(File[] files,
                                                                                            Options options,
                                                                                            Map<File,Set<String>> sourceToTopLevelClassMap)
Parse, visit, type check, and convert any language level files (and unconverted LL files they reference) in files/

Parameters:
files - The array of files to process.
sourceToTopLevelClassMap - A map from source files to names of top-level classes created from that source file; it is initially empty and subsequently filled out by this method

isElementaryFile

public static boolean isElementaryFile(File f)
If a file name ends with .dj0, it is an Elementary File


isIntermediateFile

public static boolean isIntermediateFile(File f)
If a file name ends with .dj1, it is an Intermediate File


isAdvancedFile

public static boolean isAdvancedFile(File f)
If a file name ends with .dj2, it is an Advanced File, which is a legacy notion.


isFunctionalJavaFile

public static boolean isFunctionalJavaFile(File f)
If a file name ends with .dj, it is a Functional Java File


isFullJavaFile

public static boolean isFullJavaFile(File f)
If a file name ends with .dj, it is a Functional Java File


versionSupportsAutoboxing

public static boolean versionSupportsAutoboxing(JavaVersion version)
Only certain versions of the java compiler support autoboxing


versionSupportsGenerics

public static boolean versionSupportsGenerics(JavaVersion version)
Only certain versions of the java compiler support generics


versionSupportsForEach

public static boolean versionSupportsForEach(JavaVersion version)
Only 1.5 supports for each


versionIs15

public static boolean versionIs15(JavaVersion version)

main

public static void main(String[] args)
Do a conversion from the command line, to allow quick testing