public static UnaryOperator fromSymbol(String symbol, boolean postfix) { for (UnaryOperator op : values()) { if (op.symbol.equals(symbol) && op.postfix == postfix) return op; } return null; } }
public Node createUnaryPrefixExpression(Node operand, org.parboiled.Node<Node> opNode, String symbol) { if (opNode == null) return operand; if (!opNode.getChildren().isEmpty() && "cast".equals(opNode.getChildren().get(0).getLabel())) { return posify(new Cast().rawOperand(operand).rawTypeReference(opNode.getValue())); } else { if (symbol != null) symbol = symbol.trim(); if (!symbol.isEmpty()) { UnaryOperator op = UnaryOperator.fromSymbol(symbol, false); UnaryExpression expr = new UnaryExpression().rawOperand(operand); if (op != null) expr.astOperator(op); return posify(expr); } } return operand; }
@Override public boolean visitUnaryExpression(UnaryExpression node) { Expression operand = node.astOperand(); UnaryOperator operator = node.astOperator(); if (operator == UnaryOperator.UNARY_MINUS && operand instanceof IntegralLiteral) { JCLiteral result = (JCLiteral) toTree(operand); result.value = negative(result.value); return set(node, setPos(operand, result)); } int start = node.getPosition().getStart(); int end = node.getPosition().getEnd(); /* * The pos of "++x" is the entire thing, but the pos of "x++" is only the symbol. * I guess the javac guys think consistency is overrated :( */ if (hasSourceStructures()) { switch (operator) { case POSTFIX_DECREMENT: case POSTFIX_INCREMENT: start = posOfStructure(node, node.astOperator().getSymbol(), true); end = posOfStructure(node, node.astOperator().getSymbol(), false); } } return set(node, setPos(start, end, treeMaker.Unary(UNARY_OPERATORS.get(operator), toExpression(operand)))); }
else otherIsPostfix = ((UnaryExpression)parent).astOperator().isPostfix(); } catch (Throwable ignore) {} try { if (self instanceof ConstructorInvocation) selfIsPostfix = true; else selfIsPostfix = ((UnaryExpression)self).astOperator().isPostfix(); } catch (Throwable ignore) {} return (!selfIsPostfix && otherIsPostfix);
public Node createUnaryPrefixExpression(Node operand, org.parboiled.Node<Node> opNode, String symbol) { if (opNode == null) return operand; if (!opNode.getChildren().isEmpty() && "cast".equals(opNode.getChildren().get(0).getLabel())) { return posify(new Cast().rawOperand(operand).rawTypeReference(opNode.getValue())); } else { if (symbol != null) symbol = symbol.trim(); if (!symbol.isEmpty()) { UnaryOperator op = UnaryOperator.fromSymbol(symbol, false); UnaryExpression expr = new UnaryExpression().rawOperand(operand); if (op != null) expr.astOperator(op); return posify(expr); } } return operand; }
@Override public boolean visitUnaryExpression(UnaryExpression node) { Expression operand = node.astOperand(); UnaryOperator operator = node.astOperator(); if (operator == UnaryOperator.UNARY_MINUS && operand instanceof IntegralLiteral) { JCLiteral result = (JCLiteral) toTree(operand); result.value = negative(result.value); return set(node, setPos(operand, result)); } int start = node.getPosition().getStart(); int end = node.getPosition().getEnd(); /* * The pos of "++x" is the entire thing, but the pos of "x++" is only the symbol. * I guess the javac guys think consistency is overrated :( */ if (hasSourceStructures()) { switch (operator) { case POSTFIX_DECREMENT: case POSTFIX_INCREMENT: start = posOfStructure(node, node.astOperator().getSymbol(), true); end = posOfStructure(node, node.astOperator().getSymbol(), false); } } return set(node, setPos(start, end, treeMaker.Unary(UNARY_OPERATORS.get(operator), toExpression(operand)))); }
else otherIsPostfix = ((UnaryExpression)parent).astOperator().isPostfix(); } catch (Throwable ignore) {} try { if (self instanceof ConstructorInvocation) selfIsPostfix = true; else selfIsPostfix = ((UnaryExpression)self).astOperator().isPostfix(); } catch (Throwable ignore) {} return (!selfIsPostfix && otherIsPostfix);
public Node createUnaryPrefixExpression(Node operand, org.parboiled.Node<Node> opNode, String symbol) { if (opNode == null) return operand; if (!opNode.getChildren().isEmpty() && "cast".equals(opNode.getChildren().get(0).getLabel())) { return posify(new Cast().rawOperand(operand).rawTypeReference(opNode.getValue())); } else { if (symbol != null) symbol = symbol.trim(); if (!symbol.isEmpty()) { UnaryOperator op = UnaryOperator.fromSymbol(symbol, false); UnaryExpression expr = new UnaryExpression().rawOperand(operand); if (op != null) expr.astOperator(op); return posify(expr); } } return operand; }
public static UnaryOperator fromSymbol(String symbol, boolean postfix) { for (UnaryOperator op : values()) { if (op.symbol.equals(symbol) && op.postfix == postfix) return op; } return null; } }
@Override public boolean visitUnaryExpression(UnaryExpression node) { Expression operand = node.astOperand(); UnaryOperator operator = node.astOperator(); if (operator == UnaryOperator.UNARY_MINUS && operand instanceof IntegralLiteral) { JCLiteral result = (JCLiteral) toTree(operand); result.value = negative(result.value); return set(node, setPos(operand, result)); } int start = node.getPosition().getStart(); int end = node.getPosition().getEnd(); /* * The pos of "++x" is the entire thing, but the pos of "x++" is only the symbol. * I guess the javac guys think consistency is overrated :( */ if (hasSourceStructures()) { switch (operator) { case POSTFIX_DECREMENT: case POSTFIX_INCREMENT: start = posOfStructure(node, node.astOperator().getSymbol(), true); end = posOfStructure(node, node.astOperator().getSymbol(), false); } } return set(node, setPos(start, end, treeMaker.Unary(UNARY_OPERATORS.get(operator), toExpression(operand)))); }
else otherIsPostfix = ((UnaryExpression)parent).astOperator().isPostfix(); } catch (Throwable ignore) {} try { if (self instanceof ConstructorInvocation) selfIsPostfix = true; else selfIsPostfix = ((UnaryExpression)self).astOperator().isPostfix(); } catch (Throwable ignore) {} return (!selfIsPostfix && otherIsPostfix);
if (symbol.isEmpty()) continue; UnaryOperator op = UnaryOperator.fromSymbol(symbol, false); UnaryExpression expr = new UnaryExpression().rawOperand(current); if (op != null) expr.astOperator(op);
public static UnaryOperator fromSymbol(String symbol, boolean postfix) { for (UnaryOperator op : values()) { if (op.symbol.equals(symbol) && op.postfix == postfix) return op; } return null; } }
@Override public boolean visitUnaryExpression(UnaryExpression node) { UnaryOperator op; parensOpen(node); try { op = node.astOperator(); if (op == null) throw new Exception(); } catch (Exception e) { formatter.buildInline(node); visit(node.astOperand()); formatter.closeInline(); parensClose(node); return true; } formatter.buildInline(node); formatter.property("operator", op.getSymbol()); formatter.property("postfix", op.isPostfix()); if (!op.isPostfix()) formatter.operator(op.getSymbol()); visit(node.astOperand()); if (op.isPostfix()) formatter.operator(op.getSymbol()); formatter.closeInline(); parensClose(node); return true; }
if (symbol.isEmpty()) continue; UnaryOperator op = UnaryOperator.fromSymbol(symbol, false); UnaryExpression expr = new UnaryExpression().rawOperand(current); if (op != null) expr.astOperator(op);
@Override public boolean visitUnaryExpression(UnaryExpression node) { UnaryOperator op; parensOpen(node); try { op = node.astOperator(); if (op == null) throw new Exception(); } catch (Exception e) { formatter.buildInline(node); visit(node.astOperand()); formatter.closeInline(); parensClose(node); return true; } formatter.buildInline(node); formatter.property("operator", op.getSymbol()); formatter.property("postfix", op.isPostfix()); if (!op.isPostfix()) formatter.operator(op.getSymbol()); visit(node.astOperand()); if (op.isPostfix()) formatter.operator(op.getSymbol()); formatter.closeInline(); parensClose(node); return true; }
if (symbol.isEmpty()) continue; UnaryOperator op = UnaryOperator.fromSymbol(symbol, false); UnaryExpression expr = new UnaryExpression().rawOperand(current); if (op != null) expr.astOperator(op);