org.teatrove.tea.parsetree
Class ParenExpression

java.lang.Object
  extended by org.teatrove.tea.parsetree.Node
      extended by org.teatrove.tea.parsetree.Expression
          extended by org.teatrove.tea.parsetree.ParenExpression
All Implemented Interfaces:
Serializable, Cloneable, NullSafe

public class ParenExpression
extends Expression
implements NullSafe

A ParenExpression is a thin wrapper around an Expression that was delimited by parenthesis in the source code. A parse tree does not necessarily need a ParenExpression, but it is useful when reconstructing something that resembles the source code.

Author:
Brian S O'Neill
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class org.teatrove.tea.parsetree.Expression
Expression.Conversion
 
Constructor Summary
ParenExpression(SourceInfo info, Expression expr)
           
 
Method Summary
 Object accept(NodeVisitor visitor)
          Every subclass of Node must override this method with the following: return visitor.visit(this).
 Object clone()
          Returns a clone of this Node and all its children.
 void convertTo(Type toType, boolean preferCast)
          Applies a type conversion to this expression which is chained to all previous conversions.
 LinkedList<Expression.Conversion> getConversionChain()
          Returns a list of Conversion objects representing the all the conversions that have been applied to this Expression.
 Expression getExpression()
           
 Type getInitialType()
          Returns the type of this expression before any conversions were applied, or null if the type isn't set.
 Type getType()
          The type of an expression is not necessarily set by a parser.
 Object getValue()
          Most expressions can't generate a value at compile-time, so this method simply returns null.
 boolean isExceptionPossible()
          Returns true if an exception can be thrown while executing this Expression.
 boolean isNullSafe()
           
 boolean isValueKnown()
          Returns true if the value generated by this expression is known at compile-time.
 void setExpression(Expression expr)
           
 void setInitialType(Type type)
          Sets the intial type in the conversion chain, but does not clear the conversions.
 void setNullSafe(boolean nullSafe)
           
 void setType(Type type)
          Sets the type of this expression, clearing the conversion chain.
 
Methods inherited from class org.teatrove.tea.parsetree.Expression
convertTo, forceConversion
 
Methods inherited from class org.teatrove.tea.parsetree.Node
getSourceInfo, toString
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ParenExpression

public ParenExpression(SourceInfo info,
                       Expression expr)
Method Detail

accept

public Object accept(NodeVisitor visitor)
Description copied from class: Node
Every subclass of Node must override this method with the following: return visitor.visit(this).

Overrides:
accept in class Expression
Parameters:
visitor - A visitor of this Node
Returns:
Node The Node returned by the visitor
See Also:
NodeVisitor

clone

public Object clone()
Description copied from class: Node
Returns a clone of this Node and all its children. Immutable child objects are not necessarily cloned

Overrides:
clone in class Expression

isExceptionPossible

public boolean isExceptionPossible()
Description copied from class: Expression
Returns true if an exception can be thrown while executing this Expression. By default, returns true only if a type conversion could cause an exception.

Overrides:
isExceptionPossible in class Expression

getType

public Type getType()
Description copied from class: Expression
The type of an expression is not necessarily set by a parser. It is typically set by a type checker. An expression's type may represent its natural type or its coerced type. A code generator is responsible for ensuring that the type it generates correctly matches the type of the expression.

Overrides:
getType in class Expression
Returns:
null if type is unknown

getInitialType

public Type getInitialType()
Description copied from class: Expression
Returns the type of this expression before any conversions were applied, or null if the type isn't set.

Overrides:
getInitialType in class Expression

convertTo

public void convertTo(Type toType,
                      boolean preferCast)
Description copied from class: Expression
Applies a type conversion to this expression which is chained to all previous conversions.

Overrides:
convertTo in class Expression
Parameters:
toType - the type to convert to.
preferCast - a hint that the conversion should be performed by a type cast operation, by default is true.

getConversionChain

public LinkedList<Expression.Conversion> getConversionChain()
Description copied from class: Expression
Returns a list of Conversion objects representing the all the conversions that have been applied to this Expression. Unless the type isn't set, the chain contains at least one element. The conversion chain may be reduced or expanded, so its length doesn't necessarily represent the exact sequence of calls to Expression.convertTo(org.teatrove.tea.compiler.Type).

Overrides:
getConversionChain in class Expression

setType

public void setType(Type type)
Description copied from class: Expression
Sets the type of this expression, clearing the conversion chain.

Overrides:
setType in class Expression

setInitialType

public void setInitialType(Type type)
Description copied from class: Expression
Sets the intial type in the conversion chain, but does not clear the conversions.

Overrides:
setInitialType in class Expression

isValueKnown

public boolean isValueKnown()
Description copied from class: Expression
Returns true if the value generated by this expression is known at compile-time. For most expressions, false is returned. Literals always return true.

Overrides:
isValueKnown in class Expression
See Also:
Literal

getValue

public Object getValue()
Description copied from class: Expression
Most expressions can't generate a value at compile-time, so this method simply returns null. Call isValueKnown to check if the expression's value is known at compile-time.

Overrides:
getValue in class Expression

getExpression

public Expression getExpression()

setExpression

public void setExpression(Expression expr)

isNullSafe

public boolean isNullSafe()
Specified by:
isNullSafe in interface NullSafe

setNullSafe

public void setNullSafe(boolean nullSafe)
Specified by:
setNullSafe in interface NullSafe


Copyright © 1997-2012 TeaTrove.org. All Rights Reserved.