Errai 3.0.1-SNAPSHOT

org.jboss.errai.codegen
Class Context

java.lang.Object
  extended by org.jboss.errai.codegen.Context

public class Context
extends Object

This class represents a context in which Statements are generated.

Its main purpose is to support the concept of scopes so that Statements can be validated prior to compilation.

Author:
Christian Sadilek , Mike Brock

Method Summary
 Context addImport(MetaClass clazz)
          Imports the given class.
 void addInterningCallback(InterningCallback interningCallback)
          Adds an InterningCallback to the context.
 Context addLabel(Label label)
          Add a Label to the current scope.
 void addLiteralizableClass(Class clazz)
          Mark a class "literalizable".
 void addLiteralizableClass(MetaClass clazz)
          Mark a class "literalizable".
 void addLiteralizableClasses(Collection<Class<?>> clazzes)
           
 void addLiteralizableMetaClasses(Collection<MetaClass> clazzes)
           
 Context addVariable(String name, Class<?> type)
          Add a variable to the current scope.
 Context addVariable(String name, Class<?> type, Object initialization)
          Add a variable to the current scope and initialize it.
 Context addVariable(Variable variable)
          Add a Variable to the current scope.
 void attachClass(MetaClass clazz)
          Attaches a class to the current scope.
 Context autoImport()
          Enables automatic import of classes used during code generation.
static Context create()
          Creates a new and empty context.
static Context create(Context parent)
          Create a new sub context for the given parent context.
 VariableReference getClassMember(String name)
          Returns a reference to the class member Variable with the given name.
 Collection<Variable> getDeclaredVariables()
          Returns all variables in this scope (does not include variables of parent scopes).
 LabelReference getLabel(String name)
          Returns the a reference to the Label with the given name.
 Class getLiteralizableTargetType(Class clazz)
          Returns the literalizable target type for any matching subtype.
 Class getLiteralizableTargetType(MetaClass clazz)
          Returns the literalizable target type for any matching subtype.
 Set<String> getMissingSymbols()
           
<K,V> Map<K,V>
getRenderingCache(RenderCacheStore<K,V> store)
           
 Set<String> getRequiredImports()
          Returns all imports except the optional ones (java.lang.*).
 VariableReference getVariable(String name)
          Returns a reference to the Variable with the given name.
 Map<String,Variable> getVariables()
          Returns all variables in this scope (does not include variables of parent scopes).
 boolean hasImport(MetaClass clazz)
          Checks whether the given class has been imported.
 Statement intern(LiteralValue<?> literalValue)
           
 boolean isAmbiguous(String varName)
          Checks if the the given variable name is ambiguous in this scope.
 boolean isAutoImportActive()
          Checks if automatic import is active.
 boolean isInScope(MetaField field)
          Checks is the given MetaField is in scope (part of the attached class contexts).
 boolean isInScope(MetaMethod method)
          Checks is the given MetaMethod is in scope (part of the attached class contexts).
 boolean isLiteralizableClass(Class clazz)
          Returns true if the specified class is literalizable.
 boolean isLiteralizableClass(MetaClass clazz)
          Returns true if the specified class is literalizable.
 boolean isPermissiveMode()
          Check is permissive mode is active for this context.
 boolean isScoped(Variable variable)
          Checks is the given Variable is in scope.
 void setPermissiveMode(boolean permissiveMode)
          Sets permissive mode active for this context.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

create

public static Context create()
Creates a new and empty context.

Returns:
empty context

create

public static Context create(Context parent)
Create a new sub context for the given parent context.

Parameters:
parent - the parent context to use.
Returns:
Created sub context

addVariable

public Context addVariable(String name,
                           Class<?> type)
Add a variable to the current scope.

Parameters:
name - the name of the variable, must not be null.
type - the type of the variable, must not be null.
Returns:
the current context with the variable added.

addVariable

public Context addVariable(String name,
                           Class<?> type,
                           Object initialization)
Add a variable to the current scope and initialize it.

Parameters:
name - the name of the variable, must not be null.
type - the type of the variable, must not be null.
initialization - the Statement or literal value to initialize the Variable, can be null.
Returns:
the current context with the variable added.

addVariable

public Context addVariable(Variable variable)
Add a Variable to the current scope.

Parameters:
variable - the variable instance to add, must not be null.
Returns:
the current context with the variable added.

addLabel

public Context addLabel(Label label)
Add a Label to the current scope.

Parameters:
label - the label instance to add, must not be null.
Returns:
the current context with the label added.

addImport

public Context addImport(MetaClass clazz)
Imports the given class.

Parameters:
clazz - the class to import, must not be null. If it is an array type (of any number of dimensions), its non-array component type will be imported.
Returns:
the current context with the import added.

hasImport

public boolean hasImport(MetaClass clazz)
Checks whether the given class has been imported.

Parameters:
clazz - the class to check, must not be null.
Returns:
true if import exists, otherwise false.

getRequiredImports

public Set<String> getRequiredImports()
Returns all imports except the optional ones (java.lang.*).

Returns:
required imports

autoImport

public Context autoImport()
Enables automatic import of classes used during code generation.

Returns:
the current context whit auto import enabled.

getVariable

public VariableReference getVariable(String name)
Returns a reference to the Variable with the given name.

Parameters:
name - the name of the variable.
Returns:
the VariableReference found, can not be null.
Throws:
OutOfScopeException - if variable with the given name can not be found.

getClassMember

public VariableReference getClassMember(String name)
Returns a reference to the class member Variable with the given name.

Parameters:
name - the name of the class member variable.
Returns:
the VariableReference found, can not be null.
Throws:
OutOfScopeException - if member variable with the given name can not be found.

getLabel

public LabelReference getLabel(String name)
Returns the a reference to the Label with the given name.

Parameters:
name - the name of the label.
Returns:
the LabelReference found, can not be null.
Throws:
OutOfScopeException - if label with the given name can not be found.

isScoped

public boolean isScoped(Variable variable)
Checks is the given Variable is in scope.

Parameters:
variable - the variable to check.
Returns:
true if in scope, otherwise false.

isInScope

public boolean isInScope(MetaMethod method)
Checks is the given MetaMethod is in scope (part of the attached class contexts).

Parameters:
method - the method to check.
Returns:
true if in scope, otherwise false.

isInScope

public boolean isInScope(MetaField field)
Checks is the given MetaField is in scope (part of the attached class contexts).

Parameters:
field - the field to check.
Returns:
true if in scope, otherwise false.

isAmbiguous

public boolean isAmbiguous(String varName)
Checks if the the given variable name is ambiguous in this scope.

Parameters:
varName - the variable name to check.
Returns:
true if ambiguous, otherwise false.

getDeclaredVariables

public Collection<Variable> getDeclaredVariables()
Returns all variables in this scope (does not include variables of parent scopes).

Returns:
collection of Variable, empty if no variables are in scope.

addLiteralizableClasses

public void addLiteralizableClasses(Collection<Class<?>> clazzes)

addLiteralizableMetaClasses

public void addLiteralizableMetaClasses(Collection<MetaClass> clazzes)

addLiteralizableClass

public void addLiteralizableClass(Class clazz)
Mark a class "literalizable". Meaning that all classes that are assignable to this type, are candidates for reification to code snapshots for this context and all subcontexts. See SnapshotMaker for further details.

Parameters:
clazz - the class, interface or superclass to be considered literalizable.

addLiteralizableClass

public void addLiteralizableClass(MetaClass clazz)
Mark a class "literalizable". Meaning that all classes that are assignable to this type, are candidates for reification to code snapshots for this context and all subcontexts. See SnapshotMaker for further details.

Parameters:
clazz - the class, interface or superclass to be considered literalizable.

isLiteralizableClass

public boolean isLiteralizableClass(Class clazz)
Returns true if the specified class is literalizable.

Parameters:
clazz - the class, interface or superclass to be tested if literalizable
Returns:
true if the specified class is literalizable
See Also:
addLiteralizableClass(Class)

isLiteralizableClass

public boolean isLiteralizableClass(MetaClass clazz)
Returns true if the specified class is literalizable.

Parameters:
clazz - the class, interface or superclass to be tested if literalizable
Returns:
true if the specified class is literalizable
See Also:
addLiteralizableClass(MetaClass)

getLiteralizableTargetType

public Class getLiteralizableTargetType(Class clazz)
Returns the literalizable target type for any matching subtype. Meaning, that if say, the type is a subtype of the interface com.bar.Foo, which is itself marked literalizable, this method will return a reference to the java.lang.Class instance for com.bar.Foo

Parameters:
clazz - the class, interface or superclass to obtain a literalizable target type for.
clazz - . If there are no matches, returns null.
Returns:
the literalizable target type that matches

getLiteralizableTargetType

public Class getLiteralizableTargetType(MetaClass clazz)
Returns the literalizable target type for any matching subtype. Meaning, that if say, the type com.bar.FooImpl is a subtype of the interface com.bar.Foo, which is itself marked literalizable, this method will return a reference to the java.lang.Class instance for com.bar.Foo

Parameters:
clazz - the class, interface or superclass to obtain a literalizable target type for.
clazz - . If there are no matches, returns null.
Returns:
the literalizable target type that matches

getVariables

public Map<String,Variable> getVariables()
Returns all variables in this scope (does not include variables of parent scopes).

Returns:
map of variable name to Variable, empty if no variables are in scope.

attachClass

public void attachClass(MetaClass clazz)
Attaches a class to the current scope.

Parameters:
clazz - class to attach.

isAutoImportActive

public boolean isAutoImportActive()
Checks if automatic import is active.

Returns:
true if auto import active, otherwise false.

isPermissiveMode

public boolean isPermissiveMode()
Check is permissive mode is active for this context.

Returns:

setPermissiveMode

public void setPermissiveMode(boolean permissiveMode)
Sets permissive mode active for this context.

Parameters:
permissiveMode -

getRenderingCache

public <K,V> Map<K,V> getRenderingCache(RenderCacheStore<K,V> store)

addInterningCallback

public void addInterningCallback(InterningCallback interningCallback)
Adds an InterningCallback to the context. Multiple callbacks can be registered. But, in the event that multiple callbacks fire and intern the same values, the last callback fired will be the effective interning behavior.

Parameters:
interningCallback -

intern

public Statement intern(LiteralValue<?> literalValue)

toString

public String toString()
Overrides:
toString in class Object

getMissingSymbols

public Set<String> getMissingSymbols()

Errai 3.0.1-SNAPSHOT

Copyright © 2013-2014 JBoss, a division of Red Hat. All Rights Reserved.