Пример #1
0
  @Override
  public Block astToBlock() {
    Block jaxbDestination = new Block();
    JaxbTransformerHelper.setBasicProperties(this, jaxbDestination);

    Mutation mutation = new Mutation();
    mutation.setAt(false);
    mutation.setStatement(getElementOperation().isStatment());
    JaxbTransformerHelper.addField(
        jaxbDestination, BlocklyConstants.MODE_, getElementOperation().name());
    JaxbTransformerHelper.addField(jaxbDestination, BlocklyConstants.WHERE, getLocation().name());
    JaxbTransformerHelper.addValue(jaxbDestination, BlocklyConstants.VALUE, getParam().get(0));
    if (getParam().size() > 1) {
      JaxbTransformerHelper.addValue(jaxbDestination, BlocklyConstants.AT, getParam().get(1));
      mutation.setAt(true);
    }
    jaxbDestination.setMutation(mutation);
    return jaxbDestination;
  }
Пример #2
0
 /**
  * Transformation from JAXB object to corresponding AST object.
  *
  * @param block for transformation
  * @param helper class for making the transformation
  * @return corresponding AST object
  */
 public static <V> Phrase<V> jaxbToAst(Block block, Jaxb2AstTransformer<V> helper) {
   List<Field> fields = helper.extractFields(block, (short) 2);
   List<ExprParam> exprParams = new ArrayList<ExprParam>();
   String op = helper.extractField(fields, BlocklyConstants.MODE_);
   exprParams.add(new ExprParam(BlocklyConstants.VALUE, String.class));
   if (block.getMutation().isAt()) {
     exprParams.add(new ExprParam(BlocklyConstants.AT, Integer.class));
   }
   List<Expr<V>> params = helper.extractExprParameters(block, exprParams);
   return ListGetIndex.make(
       ListElementOperations.get(op),
       IndexLocation.get(helper.extractField(fields, BlocklyConstants.WHERE)),
       params,
       helper.extractBlockProperties(block),
       helper.extractComment(block));
 }