FeaturesPluginsDocs & SupportCommunityPartners

org.netbeans.modules.jackpot/2 2 1

org.netbeans.api.jackpot
Class ConversionOperations

java.lang.Object
  extended by org.netbeans.api.jackpot.QueryOperations
      extended by org.netbeans.api.jackpot.ConversionOperations

public class ConversionOperations
extends QueryOperations

Utility methods for creating and simplifying trees using techniques such as constant-folding and dead-code analysis. All of these methods preserve the semantic meaning of the tree, so updating an original tree will not change its behavior.


Constructor Summary
ConversionOperations(org.netbeans.api.java.source.WorkingCopy workingCopy)
          Create a ConversionOperations instance.
 
Method Summary
 ExpressionTree and(ExpressionTree left, ExpressionTree right)
          Returns an AND binary expression tree from left and right operands.
 BlockTree block(List<StatementTree> stats, boolean isStatic)
          Create a block from a list of statements.
 BlockTree block(StatementTree a)
          Creates a BlockTree which contains a specified StatementTree.
 StatementTree block(StatementTree a, StatementTree b)
          Creates a single statement from two statements.
static
<T extends Tree>
List<T>
chopUnreachable(List<T> stats)
          Removes any trailing statements in a list if they are unreachable during execution.
 void copyComments(Tree oldTree, Tree newTree)
          Copy all comments associated with one tree to another.
 Object eval(ExpressionTree t)
          Perform constant-folding on an expression tree, either returning a simpler version of the tree or the tree itself.
 StatementTree If(ExpressionTree cond, StatementTree thenpart, StatementTree elsepart)
          Create an if statement, or a simplified equivalent, from a condition expression, then and else statements.
 ExpressionTree not(ExpressionTree t)
          Returns a NOT expression tree from an expression.
 ExpressionTree or(ExpressionTree left, ExpressionTree right)
          Returns an OR binary expression tree from left and right operands.
 StatementTree statement(Tree t)
          Returns a statement from an expression.
static
<T extends Tree>
List<T>
sublist(List<T> t, int index, int len)
          Create a sublist of a list of statements.
 StatementTree sublist(StatementTree t, int index)
          Create a statement which contains a subset of the statements in a specified tree.
 StatementTree sublist(StatementTree t, int index, int len)
          Create a statement which contains a subset of the statements in a specified tree.
 
Methods inherited from class org.netbeans.api.jackpot.QueryOperations
blockLength, deblock, getStatement, isConstant, isEmpty, isFalse, isTrue, sideEffectFree, sideEffectFree
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConversionOperations

public ConversionOperations(org.netbeans.api.java.source.WorkingCopy workingCopy)
Create a ConversionOperations instance.

Parameters:
workingCopy - the workingCopy used by the calling Transformer.
Method Detail

block

public BlockTree block(StatementTree a)
Creates a BlockTree which contains a specified StatementTree. If the StatementTree is an instanceof BlockTree or null, then the tree itself is returned.

Parameters:
a - the statement to be blocked
Returns:
the returned BlockTree

block

public StatementTree block(StatementTree a,
                           StatementTree b)
Creates a single statement from two statements. Either parameter can be a block or any other statement type. Blocks are flattened, with any unreachable statements removed. If either statement is empty, the other is returned.

Parameters:
a - the first statement
b - the second statement
Returns:
a statement which combines the two parameters

chopUnreachable

public static <T extends Tree> List<T> chopUnreachable(List<T> stats)
Removes any trailing statements in a list if they are unreachable during execution. One common example is a break statement following a return statement in a switch.

Parameters:
stats - the list of statements to inspect
Returns:
a shortened list with the unreachable statements removed, or the original list

sublist

public StatementTree sublist(StatementTree t,
                             int index)
Create a statement which contains a subset of the statements in a specified tree. This method is similar to String.substring(n), with statements instead of characters.
Although the parameter and return value are normally BlockTree instances, other statements may be used.

Parameters:
t - the statement tree used to create the sublist
index - the index of the first statement to be returned
Returns:
the sublist

sublist

public static <T extends Tree> List<T> sublist(List<T> t,
                                               int index,
                                               int len)
Create a sublist of a list of statements.

Parameters:
t - the list used to create the sublist
index - the index of the first statement to be returned
len - the number of statements to include
Returns:
the sublist

sublist

public StatementTree sublist(StatementTree t,
                             int index,
                             int len)
Create a statement which contains a subset of the statements in a specified tree. This method is similar to String.substring(start, n), with statements instead of characters.
Although the parameter and return value are normally BlockTree instances, other statements may be used.

Parameters:
t - the statement tree used to create the sublist
index - the index of the first statement to be returned
len - the number of statements to include
Returns:
the new sublist

copyComments

public void copyComments(Tree oldTree,
                         Tree newTree)
Copy all comments associated with one tree to another. The original tree does not need to have any comments associated with it, however, nor do the trees need to be the same kind of tree.

Parameters:
oldTree - the tree with comments to copy
newTree - the tree to copy the comments to

block

public BlockTree block(List<StatementTree> stats,
                       boolean isStatic)
Create a block from a list of statements.

Parameters:
stats - the list of statements
isStatic - true if the block has a static modifier
Returns:
a block tree

statement

public StatementTree statement(Tree t)
Returns a statement from an expression. If the tree is a conditional expression, it is converted to an IfTree. If it is an expression, it is converted into an ExpressTree. Otherwise the tree itself is returned.

Parameters:
t - the tree to convert into a statement
Returns:
the new statement, or t if it is a statement
Throws:
IllegalArgumentException - if the tree is not an expression or statment

and

public ExpressionTree and(ExpressionTree left,
                          ExpressionTree right)
Returns an AND binary expression tree from left and right operands. If either of the operands evaluates to Boolean.TRUE or Boolean.FALSE, then the appropriate side is returned instead. This is similar to what the compiler might do during constant folding.

Parameters:
left - the left-hand operand
right - the right-hand operand
Returns:
the AND expression, or equivalent

or

public ExpressionTree or(ExpressionTree left,
                         ExpressionTree right)
Returns an OR binary expression tree from left and right operands. If either of the operands evaluates to Boolean.TRUE or Boolean.FALSE, then the appropriate side is returned instead. This is similar to what the compiler might do during constant folding.

Parameters:
left - the left-hand operand
right - the right-hand operand
Returns:
the OR expression, or equivalent

not

public ExpressionTree not(ExpressionTree t)
Returns a NOT expression tree from an expression. If the expression can be simplified, an equivalent expression is returned instead.

Parameters:
t - the expression to be negated
Returns:
the NOT expression, or equivalent

eval

public Object eval(ExpressionTree t)
Perform constant-folding on an expression tree, either returning a simpler version of the tree or the tree itself.

Parameters:
t - the tree to evaluate
Returns:
an equivalent tree which has been simplified, or the tree itself if no folding can be performed.

If

public StatementTree If(ExpressionTree cond,
                        StatementTree thenpart,
                        StatementTree elsepart)
Create an if statement, or a simplified equivalent, from a condition expression, then and else statements.

Parameters:
cond - the conditional expression
thenpart - the statement if the condition is true
elsepart - the statement if the condition is false, or null if there is no else statement.
Returns:
an if statement, or a simplified equivalent

org.netbeans.modules.jackpot/2 2 1

Built on April 6 2007.  |  Portions Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
Companion
Projects:
MySQL Database Server   Open JDK: an Open SourceJDK   GlassFish Community: an Open Source Application Server    Mobile & Embedded Community    Open Solaris   java.net - The Source for Java Technology Collaboration   Virtual Box - full virtualizer  Open ESB - The Open Enterprise Service Bus Powered by