types
Class LangDef

java.lang.Object
  extended by types.LangDef
Direct Known Subclasses:
Java

public abstract class LangDef
extends Object

LangDef is the abstract class that all Language Definitions inherit from. It contains several utility methods and one method stub, generateCode, which is called by the Controller and returns a double array of strings, with the first entry corresponding to the file name to be outputted to, and the second entry corresponding to the contents of that file.


Field Summary
protected  ErrorHandler errorHandler
          The ErrorHandler to use for reporting errors.
protected  Set<String> imports
          A running list of all the distinct import statements required by various Widgets within the code.
protected  Set<String> innerClasses
          A running list of all the distinct inner classes to be included in the final generated code.
protected  String libPath
          The pathname to the language's lib folder.
protected  Set<String> modifiers
          A running list of all the distinct modifiers to be included in the final generated code.
protected  Set<String> variables
          A running list of all the distinct fields to be included in the final generated code.
 
Constructor Summary
protected LangDef(String libPath)
           
protected LangDef(String libPath, Set<String> imports, Set<String> modifiers, Set<String> innerClasses, Set<String> variables)
           
 
Method Summary
protected  String createWidget(Widget widget)
          createWidget is a utility method included to cut down on potential code duplication.
protected  String createWidget(Widget widget, WidgetDef parentDef)
          Create a widget which may have child attributes granted by its parent widget.
static LangDef defineLanguage(String lang)
          Get a LangDef instance for the specified language.
abstract  String[][] generateCode(GUIFile guiFile, ErrorHandler errorHandler)
          generateCode accepts the generated Parser output and manipulates it according to the structure of the language to generate the appropriate output code.
 String getLibPath()
           
abstract  Class<? extends WidgetDef> getRootWidgetType()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

libPath

protected final String libPath
The pathname to the language's lib folder.


imports

protected final Set<String> imports
A running list of all the distinct import statements required by various Widgets within the code.


modifiers

protected final Set<String> modifiers
A running list of all the distinct modifiers to be included in the final generated code.


variables

protected final Set<String> variables
A running list of all the distinct fields to be included in the final generated code.


innerClasses

protected final Set<String> innerClasses
A running list of all the distinct inner classes to be included in the final generated code.


errorHandler

protected ErrorHandler errorHandler
The ErrorHandler to use for reporting errors.

Constructor Detail

LangDef

protected LangDef(String libPath,
                  Set<String> imports,
                  Set<String> modifiers,
                  Set<String> innerClasses,
                  Set<String> variables)
Parameters:
libPath - The package prefix for the widget library.
imports - The set to use for imports.
modifiers - The set to use for modifiers.
innerClasses - The set to use for innerClasses.
variables - The set to use for variables.

LangDef

protected LangDef(String libPath)
Parameters:
libPath - The package prefix for the widget library.
Method Detail

generateCode

public abstract String[][] generateCode(GUIFile guiFile,
                                        ErrorHandler errorHandler)
                                 throws GUIFileException
generateCode accepts the generated Parser output and manipulates it according to the structure of the language to generate the appropriate output code.

Parameters:
guiFile - A GUIFile object, as returned by the parser.
errorHandler - The ErrorHandler object to use for reporting errors.
Returns:
An array of two-element arrays. The first element should be a filename, and the second element should have the contents of the generated file with that name.
Throws:
GUIFileException - If any errors are found in the file.

getRootWidgetType

public abstract Class<? extends WidgetDef> getRootWidgetType()
Returns:
The widget type to use as the base of the widget hierarchy. This will typically be "Widget".

createWidget

protected String createWidget(Widget widget)
                       throws GUIFileException
createWidget is a utility method included to cut down on potential code duplication. It is not necessary to use or override it if the Language Definition does not desire to. createWidget consults with the library definitions of the widget type to assemble the code necessary for declaring a widget in the given language. If structural constraints of the language cause this method to be ineffective, it can be overridden in the subclass. It currently recursively generates child widgets as they are encountered.

Parameters:
widget - The widget from the GUIFile to create.
Returns:
The code to create the widget.
Throws:
BadAttributeException - If an invalid attribute is given.
BadWidgetTypeException - If the widget type does not exist.
BadChildWidgetException - For an incompatible child type.
GUIFileException

createWidget

protected String createWidget(Widget widget,
                              WidgetDef parentDef)
                       throws GUIFileException
Create a widget which may have child attributes granted by its parent widget.

Parameters:
widget - The widget to generate code for.
parentDef - The widget definition for the widget's parent, or null; if null then do not allow any child attributes.
Returns:
Generated code to create the widget and its children.
Throws:
GUIFileException
See Also:
WidgetDef.getChildDefaults()

getLibPath

public String getLibPath()
Returns:
The fully qualified name of the package containing the WidgetDefs for this language.

defineLanguage

public static LangDef defineLanguage(String lang)
Get a LangDef instance for the specified language.

Parameters:
lang - The name of the language, for instance "Java".
Returns:
The corresponding LangDef.