From 67fee39e6dd22fce8dfaa800f0a5ddbe0ede0be3 Mon Sep 17 00:00:00 2001 From: bculkin2442 Date: Wed, 27 Jul 2016 17:42:35 -0400 Subject: General cleanup --- .../main/java/bjc/dicelang/ast/DiceASTUtils.java | 28 ++++++++++++---------- 1 file changed, 15 insertions(+), 13 deletions(-) (limited to 'dice-lang/src/main/java/bjc/dicelang/ast/DiceASTUtils.java') diff --git a/dice-lang/src/main/java/bjc/dicelang/ast/DiceASTUtils.java b/dice-lang/src/main/java/bjc/dicelang/ast/DiceASTUtils.java index 8d70af8..d98c8fe 100644 --- a/dice-lang/src/main/java/bjc/dicelang/ast/DiceASTUtils.java +++ b/dice-lang/src/main/java/bjc/dicelang/ast/DiceASTUtils.java @@ -21,13 +21,14 @@ public class DiceASTUtils { * Check if a dice AST contains a simple variable reference * * @param nameTree + * The tree to check for a reference in * @return Whether or not a dice AST contains a simple variable * reference */ public static boolean containsSimpleVariable( ITree nameTree) { - return nameTree.transformHead((nameNod) -> { - if (nameNod.getType() != DiceASTType.VARIABLE) { + return nameTree.transformHead((nameNode) -> { + if (nameNode.getType() != DiceASTType.VARIABLE) { return false; } @@ -36,10 +37,10 @@ public class DiceASTUtils { } /** - * Convert an AST tree to a dice expression, if possible. + * Convert an literal AST node to a dice expression, if possible. * * @param tree - * The tree to convert + * The node to convert in tree form * @return The tree as a dice expression * * @throws ClassCastException @@ -48,15 +49,16 @@ public class DiceASTUtils { * @throws UnsupportedOperationException * if the head of the tree is not optimizable */ - public static IDiceExpression toExpression(ITree tree) { - ILiteralDiceNode litNode = (ILiteralDiceNode) tree.getHead(); + public static IDiceExpression literalToExpression( + ITree tree) { + ILiteralDiceNode literalNode = (ILiteralDiceNode) tree.getHead(); - switch (litNode.getLiteralType()) { + switch (literalNode.getLiteralType()) { case DICE: - return ((DiceLiteralNode) litNode).getValue(); + return ((DiceLiteralNode) literalNode).getValue(); case INTEGER: return new ScalarDie( - ((IntegerLiteralNode) litNode).getValue()); + ((IntegerLiteralNode) literalNode).getValue()); default: throw new UnsupportedOperationException( "This type of literal isn't convertable to an expression"); @@ -64,11 +66,11 @@ public class DiceASTUtils { } /** - * Convert an AST tree to an integer, if possible. + * Convert an literal AST node to an integer, if possible. * * @param tree - * The tree to convert - * @return The tree as an integer + * The literal node to convert, as a tree + * @return The node as an integer * * @throws ClassCastException * if the head of the tree is not a literal (implements @@ -76,7 +78,7 @@ public class DiceASTUtils { * @throws UnsupportedOperationException * if the head of the tree is not optimizable */ - public static int toInt(ITree tree) { + public static int literalToInteger(ITree tree) { return tree.transformHead((node) -> { return ((ILiteralDiceNode) node).optimize(); }); -- cgit v1.2.3