Java Code Examples for com.sun.codemodel.JBlock._break

The following are Jave code examples for showing how to use _break of the com.sun.codemodel.JBlock class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: thrift-java-compiler   File: StructCodeGeneratorHelper.java   Source Code and License Vote up 6 votes
private void createMethodFieldSetFieldValue(JDefinedClass _class, Map<String, JType> fields) {
		JMethod method = _class.method(JMod.PUBLIC, Void.TYPE, "setFieldValue");
		JClass refEnumFields = codeModel.ref(_class.fullName() + DOT_FIELD);
		JVar param = method.param(refEnumFields, "field");
		JVar param2 = method.param(codeModel.ref(Object.class), "value");
		JBlock body = method.body();

		JSwitch _switch = body._switch(param);
		for (Map.Entry<String, JType> entry : fields.entrySet()) {
			JBlock bodyCase = _switch._case(JExpr.ref(entry.getKey().toUpperCase())).body();
			JConditional _if = bodyCase._if(param2.eq(JExpr._null()));
			String capitalizeName = JavaGeneratorUtil.getCapitalizeString(entry.getKey());
			_if._then().invoke("unset" + capitalizeName);
			_if._else().invoke("set" + capitalizeName).arg(JExpr.cast(getTypeGetMethodByName(_class, capitalizeName), param2));
			bodyCase._break();
		}

//		JInvocation _newException = JExpr._new(codeModel.ref(IllegalStateException.class));
//		_switch._default().body()._throw(_newException);

	}
 
Example 2
Project: QDrill   File: EvaluationVisitor.java   Source Code and License Vote up 4 votes
private HoldingContainer visitBooleanAnd(BooleanOperator op,
    ClassGenerator<?> generator) {

  HoldingContainer out = generator.declare(op.getMajorType());

  JLabel label = generator.getEvalBlockLabel("AndOP");
  JBlock eval = generator.getEvalBlock().block();  // enter into nested block
  generator.nestEvalBlock(eval);

  HoldingContainer arg = null;

  JExpression e = null;

  //  value of boolean "and" when one side is null
  //    p       q     p and q
  //    true    null     null
  //    false   null     false
  //    null    true     null
  //    null    false    false
  //    null    null     null
  for (int i = 0; i < op.args.size(); i++) {
    arg = op.args.get(i).accept(this, generator);

    JBlock earlyExit = null;
    if (arg.isOptional()) {
      earlyExit = eval._if(arg.getIsSet().eq(JExpr.lit(1)).cand(arg.getValue().ne(JExpr.lit(1))))._then();
      if (e == null) {
        e = arg.getIsSet();
      } else {
        e = e.mul(arg.getIsSet());
      }
    } else {
      earlyExit = eval._if(arg.getValue().ne(JExpr.lit(1)))._then();
    }

    if (out.isOptional()) {
      earlyExit.assign(out.getIsSet(), JExpr.lit(1));
    }

    earlyExit.assign(out.getValue(),  JExpr.lit(0));
    earlyExit._break(label);
  }

  if (out.isOptional()) {
    assert (e != null);

    JConditional notSetJC = eval._if(e.eq(JExpr.lit(0)));
    notSetJC._then().assign(out.getIsSet(), JExpr.lit(0));

    JBlock setBlock = notSetJC._else().block();
    setBlock.assign(out.getIsSet(), JExpr.lit(1));
    setBlock.assign(out.getValue(), JExpr.lit(1));
  } else {
    assert (e == null);
    eval.assign(out.getValue(), JExpr.lit(1)) ;
  }

  generator.unNestEvalBlock();     // exit from nested block

  return out;
}
 
Example 3
Project: QDrill   File: EvaluationVisitor.java   Source Code and License Vote up 4 votes
private HoldingContainer visitBooleanOr(BooleanOperator op,
    ClassGenerator<?> generator) {

  HoldingContainer out = generator.declare(op.getMajorType());

  JLabel label = generator.getEvalBlockLabel("OrOP");
  JBlock eval = generator.getEvalBlock().block();
  generator.nestEvalBlock(eval);   // enter into nested block.

  HoldingContainer arg = null;

  JExpression e = null;

  //  value of boolean "or" when one side is null
  //    p       q       p and q
  //    true    null     true
  //    false   null     null
  //    null    true     true
  //    null    false    null
  //    null    null     null

  for (int i = 0; i < op.args.size(); i++) {
    arg = op.args.get(i).accept(this, generator);

    JBlock earlyExit = null;
    if (arg.isOptional()) {
      earlyExit = eval._if(arg.getIsSet().eq(JExpr.lit(1)).cand(arg.getValue().eq(JExpr.lit(1))))._then();
      if (e == null) {
        e = arg.getIsSet();
      } else {
        e = e.mul(arg.getIsSet());
      }
    } else {
      earlyExit = eval._if(arg.getValue().eq(JExpr.lit(1)))._then();
    }

    if (out.isOptional()) {
      earlyExit.assign(out.getIsSet(), JExpr.lit(1));
    }

    earlyExit.assign(out.getValue(),  JExpr.lit(1));
    earlyExit._break(label);
  }

  if (out.isOptional()) {
    assert (e != null);

    JConditional notSetJC = eval._if(e.eq(JExpr.lit(0)));
    notSetJC._then().assign(out.getIsSet(), JExpr.lit(0));

    JBlock setBlock = notSetJC._else().block();
    setBlock.assign(out.getIsSet(), JExpr.lit(1));
    setBlock.assign(out.getValue(), JExpr.lit(0));
  } else {
    assert (e == null);
    eval.assign(out.getValue(), JExpr.lit(0)) ;
  }

  generator.unNestEvalBlock();   // exit from nested block.

  return out;
}
 
Example 4
Project: dremio-oss   File: EvaluationVisitor.java   Source Code and License Vote up 4 votes
private HoldingContainer visitBooleanAnd(BooleanOperator op,
    ClassGenerator<?> generator) {

  HoldingContainer out = generator.declare(op.getCompleteType());

  JLabel label = generator.getEvalBlockLabel("AndOP");
  JBlock eval = generator.createInnerEvalBlock();
  generator.nestEvalBlock(eval);  // enter into nested block

  HoldingContainer arg = null;

  JExpression e = null;

  //  value of boolean "and" when one side is null
  //    p       q     p and q
  //    true    null     null
  //    false   null     false
  //    null    true     null
  //    null    false    false
  //    null    null     null
  for (int i = 0; i < op.args.size(); i++) {
    arg = op.args.get(i).accept(this, generator);

    JBlock earlyExit = null;
      earlyExit = eval._if(arg.getIsSet().eq(JExpr.lit(1)).cand(arg.getValue().ne(JExpr.lit(1))))._then();
      if (e == null) {
        e = arg.getIsSet();
      } else {
        e = e.mul(arg.getIsSet());
      }
    earlyExit.assign(out.getIsSet(), JExpr.lit(1));

    earlyExit.assign(out.getValue(),  JExpr.lit(0));
    earlyExit._break(label);
  }

  assert (e != null);

  JConditional notSetJC = eval._if(e.eq(JExpr.lit(0)));
  notSetJC._then().assign(out.getIsSet(), JExpr.lit(0));

  JBlock setBlock = notSetJC._else().block();
  setBlock.assign(out.getIsSet(), JExpr.lit(1));
  setBlock.assign(out.getValue(), JExpr.lit(1));

  generator.unNestEvalBlock();     // exit from nested block

  return out;
}
 
Example 5
Project: dremio-oss   File: EvaluationVisitor.java   Source Code and License Vote up 4 votes
private HoldingContainer visitBooleanOr(BooleanOperator op,
    ClassGenerator<?> generator) {

  HoldingContainer out = generator.declare(op.getCompleteType());

  JLabel label = generator.getEvalBlockLabel("OrOP");
  JBlock eval = generator.createInnerEvalBlock();
  generator.nestEvalBlock(eval);   // enter into nested block.

  HoldingContainer arg = null;

  JExpression e = null;

  //  value of boolean "or" when one side is null
  //    p       q       p and q
  //    true    null     true
  //    false   null     null
  //    null    true     true
  //    null    false    null
  //    null    null     null

  for (int i = 0; i < op.args.size(); i++) {
    arg = op.args.get(i).accept(this, generator);

    JBlock earlyExit = eval._if(arg.getIsSet().eq(JExpr.lit(1)).cand(arg.getValue().eq(JExpr.lit(1))))._then();
    if (e == null) {
      e = arg.getIsSet();
    } else {
      e = e.mul(arg.getIsSet());
    }
    earlyExit.assign(out.getIsSet(), JExpr.lit(1));
    earlyExit.assign(out.getValue(),  JExpr.lit(1));
    earlyExit._break(label);
  }

  assert (e != null);

  JConditional notSetJC = eval._if(e.eq(JExpr.lit(0)));
  notSetJC._then().assign(out.getIsSet(), JExpr.lit(0));

  JBlock setBlock = notSetJC._else().block();
  setBlock.assign(out.getIsSet(), JExpr.lit(1));
  setBlock.assign(out.getValue(), JExpr.lit(0));

  generator.unNestEvalBlock();   // exit from nested block.

  return out;
}
 
Example 6
Project: drill   File: EvaluationVisitor.java   Source Code and License Vote up 4 votes
private HoldingContainer visitBooleanAnd(BooleanOperator op,
    ClassGenerator<?> generator) {

  HoldingContainer out = generator.declare(op.getMajorType());

  JLabel label = generator.getEvalBlockLabel("AndOP");
  JBlock eval = generator.createInnerEvalBlock();
  generator.nestEvalBlock(eval);  // enter into nested block

  HoldingContainer arg = null;

  JExpression e = null;

  //  value of boolean "and" when one side is null
  //    p       q     p and q
  //    true    null     null
  //    false   null     false
  //    null    true     null
  //    null    false    false
  //    null    null     null
  for (int i = 0; i < op.args.size(); i++) {
    arg = op.args.get(i).accept(this, generator);

    JBlock earlyExit = null;
    if (arg.isOptional()) {
      earlyExit = eval._if(arg.getIsSet().eq(JExpr.lit(1)).cand(arg.getValue().ne(JExpr.lit(1))))._then();
      if (e == null) {
        e = arg.getIsSet();
      } else {
        e = e.mul(arg.getIsSet());
      }
    } else {
      earlyExit = eval._if(arg.getValue().ne(JExpr.lit(1)))._then();
    }

    if (out.isOptional()) {
      earlyExit.assign(out.getIsSet(), JExpr.lit(1));
    }

    earlyExit.assign(out.getValue(),  JExpr.lit(0));
    earlyExit._break(label);
  }

  if (out.isOptional()) {
    assert (e != null);

    JConditional notSetJC = eval._if(e.eq(JExpr.lit(0)));
    notSetJC._then().assign(out.getIsSet(), JExpr.lit(0));

    JBlock setBlock = notSetJC._else().block();
    setBlock.assign(out.getIsSet(), JExpr.lit(1));
    setBlock.assign(out.getValue(), JExpr.lit(1));
  } else {
    assert (e == null);
    eval.assign(out.getValue(), JExpr.lit(1)) ;
  }

  generator.unNestEvalBlock();     // exit from nested block

  return out;
}
 
Example 7
Project: drill   File: EvaluationVisitor.java   Source Code and License Vote up 4 votes
private HoldingContainer visitBooleanOr(BooleanOperator op,
    ClassGenerator<?> generator) {

  HoldingContainer out = generator.declare(op.getMajorType());

  JLabel label = generator.getEvalBlockLabel("OrOP");
  JBlock eval = generator.createInnerEvalBlock();
  generator.nestEvalBlock(eval);   // enter into nested block.

  HoldingContainer arg = null;

  JExpression e = null;

  //  value of boolean "or" when one side is null
  //    p       q       p and q
  //    true    null     true
  //    false   null     null
  //    null    true     true
  //    null    false    null
  //    null    null     null

  for (int i = 0; i < op.args.size(); i++) {
    arg = op.args.get(i).accept(this, generator);

    JBlock earlyExit = null;
    if (arg.isOptional()) {
      earlyExit = eval._if(arg.getIsSet().eq(JExpr.lit(1)).cand(arg.getValue().eq(JExpr.lit(1))))._then();
      if (e == null) {
        e = arg.getIsSet();
      } else {
        e = e.mul(arg.getIsSet());
      }
    } else {
      earlyExit = eval._if(arg.getValue().eq(JExpr.lit(1)))._then();
    }

    if (out.isOptional()) {
      earlyExit.assign(out.getIsSet(), JExpr.lit(1));
    }

    earlyExit.assign(out.getValue(),  JExpr.lit(1));
    earlyExit._break(label);
  }

  if (out.isOptional()) {
    assert (e != null);

    JConditional notSetJC = eval._if(e.eq(JExpr.lit(0)));
    notSetJC._then().assign(out.getIsSet(), JExpr.lit(0));

    JBlock setBlock = notSetJC._else().block();
    setBlock.assign(out.getIsSet(), JExpr.lit(1));
    setBlock.assign(out.getValue(), JExpr.lit(0));
  } else {
    assert (e == null);
    eval.assign(out.getValue(), JExpr.lit(0)) ;
  }

  generator.unNestEvalBlock();   // exit from nested block.

  return out;
}
 
Example 8
Project: visualakka   File: DefaultGenerator.java   Source Code and License Vote up 4 votes
private void introduceUserCodeBlock(JDefinedClass jc, JCodeModel jm,
        ConcreticisedMethod block,
        JSwitch methodSwitch,
        JVar _ca2, JVar _ca1,
        Map<String, JMethod> virtualMethods) {

    JMethod vmethhandler = jc.method(JMod.PUBLIC,
            jm.VOID,
            block.getRefMeth().getArguments().get(0).getIdentificator());

    vmethhandler._throws(AVEInternaException.class);
    vmethhandler.javadoc().add("Virtual method handler for " + block.getMethodName() + " method.");
    vmethhandler.javadoc().addThrows(AVEInternaException.class).
            add("Throws when message has an invalid instance.");

    allMethods.put(UCB_DECLPREFIX + block.getMethodName(), methodsEnum.enumConstant(UCB_DECLPREFIX + block.getMethodName()));

    JBlock userBlockSwitch = methodSwitch._case(JExpr.ref(UCB_DECLPREFIX + block.getMethodName())).body();
    JArray mthNames = JExpr.newArray(jm.ref(String.class));

    int argId = 0;
    for (Argument arg : block.getRefMeth().getArguments()) {
        String defaultV = arg.getDefaultValue();
        userBlockSwitch.add(_ca2.invoke("add").arg(
                JExpr._new(jm.ref(Node.class))
                .arg(arg.getIdentificator())
                .arg(arg.getType())
                .arg(defaultV == null ? "" : defaultV)
                .arg(JExpr.lit(arg.isFixed()))));

        mthNames.add(JExpr.lit(arg.getIdentificator()));
        vmethargs.put(block.getMethodName() + argId, vmethhandler.param(Message.class, arg.getIdentificator()));

        argId++;
    }
    userBlockSwitch.add(_ca1.invoke("add").arg(jm.ref(Arrays.class)
            .staticInvoke("asList").arg(mthNames)));

    userBlockSwitch._break();

    virtualMethods.put(block.getMethodName(), vmethhandler);
}