xtc.type
Class JavaAST

java.lang.Object
  extended by xtc.type.AST
      extended by xtc.type.JavaAST

public class JavaAST
extends AST

Common type operations for Java ASTs.

Version:
$Revision: 1.9 $
Author:
Robert Grimm

Nested Class Summary
 
Nested classes/interfaces inherited from class xtc.type.AST
AST.MetaData
 
Field Summary
static java.util.Set<java.lang.String> KEYWORDS
          The set of Java keywords besides primitive types, modifiers, and void.
static java.util.Set<java.lang.String> MODIFIERS
          The set of Java modifiers.
static java.util.Set<java.lang.String> PRIMITIVES
          The set of Java primitive types.
protected  java.util.Map<java.lang.String,java.lang.Class<?>> resolvedTypes
          The map from Java class names to their classes.
 
Fields inherited from class xtc.type.AST
ACTION, ANY, CHAR, externToIntern, FORMATTING, GENERIC, importedModules, importedTypes, INTERNAL, internToExtern, LIST, NODE, NULL_NODE, originalNames, STRING, TOKEN, tuples, tupleVariants, variantNodes, variants, VOID, WILD_ACTION, WILD_LIST
 
Constructor Summary
JavaAST()
          Create a new Java AST instance.
 
Method Summary
protected  int endOfType(java.lang.String args, int start)
          Determine the last index (exclusive) of the generic type argument starting at the specified index.
protected  java.lang.String externAction(Type type)
          Convert the specified action type to a string.
protected  java.lang.String externList(Type type)
          Convert the specified list type to a string.
protected  java.lang.String externUser(Type type)
          Convert the specified user-defined type to a string.
protected  Constants.FuzzyBoolean hasLocationUser(Type type)
          Determine whether instances of the specified user-defined type have a source location.
 void initialize(boolean hasNode, boolean hasToken, boolean hasFormatting, boolean hasAction)
          Initialize the mapping between external and internal representations.
protected  Type internAction(java.lang.String s)
          Convert the specified string representation of an action type into the type.
protected  Type internList(java.lang.String s)
          Convert the specified string representation of a list type into the type.
protected  Type internUser(java.lang.String s)
          Convert the specified string representation of a user-defined type into its internal representation.
 boolean isGenericNode(java.lang.String s)
          Determine whether the specified string represents the generic node type.
 boolean isVoid(java.lang.String s)
          Determine whether the specified string represents the void type.
 java.lang.Class<?> resolve(java.lang.String name)
          Resolve the specified type name to its class.
protected  Type unifyUser(Type t1, Type t2, boolean strict)
          Unify the specified user-defined types.
 
Methods inherited from class xtc.type.AST
actionOf, add, combine, concretize, concretizeTuples, extern, flatten, getArgument, getMetaData, hasLocation, hasTuple, hasVariant, importModule, importType, intern, isAction, isAny, isChar, isDynamicNode, isFormatting, isGenericNode, isList, isMonomorphic, isNode, isNullNode, isOptional, isStaticNode, isString, isToken, isUser, isVariable, isVoid, listOf, markOptional, markVariable, overlap, print, toOriginal, toTuple, toTuple, toVariant, toVariantName, toVariants, unify, unify
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PRIMITIVES

public static final java.util.Set<java.lang.String> PRIMITIVES
The set of Java primitive types.


MODIFIERS

public static final java.util.Set<java.lang.String> MODIFIERS
The set of Java modifiers.


KEYWORDS

public static final java.util.Set<java.lang.String> KEYWORDS
The set of Java keywords besides primitive types, modifiers, and void.


resolvedTypes

protected java.util.Map<java.lang.String,java.lang.Class<?>> resolvedTypes
The map from Java class names to their classes.

Constructor Detail

JavaAST

public JavaAST()
Create a new Java AST instance.

Method Detail

initialize

public void initialize(boolean hasNode,
                       boolean hasToken,
                       boolean hasFormatting,
                       boolean hasAction)
Description copied from class: AST
Initialize the mapping between external and internal representations. This method fills the AST.externToIntern and AST.internToExtern data structures.

Specified by:
initialize in class AST
Parameters:
hasNode - Flag to indicate use of built-in nodes.
hasToken - Flag to indicate use of tokens.
hasFormatting - Flag to indicate use of formatting.
hasAction - Flag to indicate use of actions.

isVoid

public boolean isVoid(java.lang.String s)
Description copied from class: AST
Determine whether the specified string represents the void type.

Specified by:
isVoid in class AST
Parameters:
s - The type as a string.
Returns:
true if the string represents the void type.

isGenericNode

public boolean isGenericNode(java.lang.String s)
Description copied from class: AST
Determine whether the specified string represents the generic node type.

Specified by:
isGenericNode in class AST
Parameters:
s - The type as a string.
Returns:
true if the string represents the generic node type.

internList

protected Type internList(java.lang.String s)
Description copied from class: AST
Convert the specified string representation of a list type into the type.

Specified by:
internList in class AST
Parameters:
s - The list type as a string.
Returns:
The type or ErrorT.TYPE if the string does not represent a list.

internAction

protected Type internAction(java.lang.String s)
Description copied from class: AST
Convert the specified string representation of an action type into the type.

Specified by:
internAction in class AST
Parameters:
s - The action type as a string.
Returns:
The type or ErrorT.TYPE if the string does not represent an action.

internUser

protected Type internUser(java.lang.String s)
Description copied from class: AST
Convert the specified string representation of a user-defined type into its internal representation.

Specified by:
internUser in class AST
Parameters:
s - The user-defined type as a string.
Returns:
The type.

endOfType

protected int endOfType(java.lang.String args,
                        int start)
Determine the last index (exclusive) of the generic type argument starting at the specified index.

Parameters:
args - The generic type arguments.
start - The start index.
Returns:
The end index (exclusive).

externList

protected java.lang.String externList(Type type)
Description copied from class: AST
Convert the specified list type to a string.

Specified by:
externList in class AST
Parameters:
type - The list type.
Returns:
The type as a string.

externAction

protected java.lang.String externAction(Type type)
Description copied from class: AST
Convert the specified action type to a string.

Specified by:
externAction in class AST
Parameters:
type - The action type.
Returns:
The type as a string.

externUser

protected java.lang.String externUser(Type type)
Description copied from class: AST
Convert the specified user-defined type to a string.

Specified by:
externUser in class AST
Parameters:
type - The user-defined type.
Returns:
The type as a string.

hasLocationUser

protected Constants.FuzzyBoolean hasLocationUser(Type type)
Description copied from class: AST
Determine whether instances of the specified user-defined type have a source location.

Specified by:
hasLocationUser in class AST
Parameters:
type - The type.
Returns:
The inexact answer.

unifyUser

protected Type unifyUser(Type t1,
                         Type t2,
                         boolean strict)
Description copied from class: AST
Unify the specified user-defined types. Note that this method need not handle instantiated types but must preserve parameterize types.

Specified by:
unifyUser in class AST
Parameters:
t1 - The first user-defined type.
t2 - The second user-defined type.
strict - The flag for strict unification.
Returns:
The unified type or ErrorT.TYPE if the two types do not unify.

resolve

public java.lang.Class<?> resolve(java.lang.String name)
Resolve the specified type name to its class. This method relies on the AST.importedTypes and AST.importedModules data structures to map incomplete type names to fully qualified type names. It caches results in the resolvedTypes data structure to speed up future resolutions.

Parameters:
name - The type name.
Returns:
The corresponding class or null if the name cannot be resolved.


Copyright © 2012. All Rights Reserved.