本文整理汇总了Java中com.sun.codemodel.JBlock.add方法的典型用法代码示例。如果您正苦于以下问题:Java JBlock.add方法的具体用法?Java JBlock.add怎么用?Java JBlock.add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.codemodel.JBlock
的用法示例。
在下文中一共展示了JBlock.add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addPublicSetMethod
import com.sun.codemodel.JBlock; //导入方法依赖的package包/类
private JMethod addPublicSetMethod(JDefinedClass jclass, JMethod internalSetMethod) {
JMethod method = jclass.method(PUBLIC, jclass.owner().VOID, SETTER_NAME);
JVar nameParam = method.param(String.class, "name");
JVar valueParam = method.param(Object.class, "value");
JBlock body = method.body();
JBlock notFound = body._if(JOp.not(invoke(internalSetMethod).arg(nameParam).arg(valueParam)))._then();
// if we have additional properties, then put value.
JMethod getAdditionalProperties = jclass.getMethod("getAdditionalProperties", new JType[] {});
if (getAdditionalProperties != null) {
JType additionalPropertiesType = ((JClass) (getAdditionalProperties.type())).getTypeParameters().get(1);
notFound.add(invoke(getAdditionalProperties).invoke("put").arg(nameParam)
.arg(cast(additionalPropertiesType, valueParam)));
}
// else throw exception.
else {
notFound._throw(illegalArgumentInvocation(jclass, nameParam));
}
return method;
}
示例2: addPublicWithMethod
import com.sun.codemodel.JBlock; //导入方法依赖的package包/类
private JMethod addPublicWithMethod(JDefinedClass jclass, JMethod internalSetMethod) {
JMethod method = jclass.method(PUBLIC, jclass, BUILDER_NAME);
JVar nameParam = method.param(String.class, "name");
JVar valueParam = method.param(Object.class, "value");
JBlock body = method.body();
JBlock notFound = body._if(JOp.not(invoke(internalSetMethod).arg(nameParam).arg(valueParam)))._then();
// if we have additional properties, then put value.
JMethod getAdditionalProperties = jclass.getMethod("getAdditionalProperties", new JType[] {});
if (getAdditionalProperties != null) {
JType additionalPropertiesType = ((JClass) (getAdditionalProperties.type())).getTypeParameters().get(1);
notFound.add(invoke(getAdditionalProperties).invoke("put").arg(nameParam)
.arg(cast(additionalPropertiesType, valueParam)));
}
// else throw exception.
else {
notFound._throw(illegalArgumentInvocation(jclass, nameParam));
}
body._return(_this());
return method;
}
示例3: generateWriter
import com.sun.codemodel.JBlock; //导入方法依赖的package包/类
protected JBlock generateWriter(AcScheme scheme, JavaWriter writer) {
JBlock bl=new JBlock();
for (AbstractType tp:scheme.getSchemes().keySet()){
String name = getName(tp, writer);
String ge="value.get"+Character.toUpperCase(name.charAt(0))+name.substring(1)+"()";
JBlock th=bl._if(JExpr.direct(ge+"!=null"))._then();
th.add(new JStatement() {
@Override
public void state(JFormatter f) {
f.p("gson.toJson("+ge+","+ge+".getClass(), out);");
f.nl();
}
});
}
return bl;
}
示例4: generateWriter
import com.sun.codemodel.JBlock; //导入方法依赖的package包/类
protected JBlock generateWriter(AcScheme scheme, JavaWriter writer) {
JBlock bl=new JBlock();
for (AbstractType tp:scheme.getSchemes().keySet()){
String name = getName(tp, writer);
String ge="value.get"+Character.toUpperCase(name.charAt(0))+name.substring(1)+"()";
JBlock th=bl._if(JExpr.direct(ge+"!=null"))._then();
th.add(new JStatement() {
@Override
public void state(JFormatter f) {
f.p("gen.writeObject("+ge+");");
f.nl();
}
});
}
return bl;
}
示例5: addCtor
import com.sun.codemodel.JBlock; //导入方法依赖的package包/类
/**
* The code generator creates a method called __DRILL_INIT__ which takes the
* place of the constructor when the code goes though the byte code merge.
* For Plain-old Java, we call the method from a constructor created for
* that purpose. (Generated code, fortunately, never includes a constructor,
* so we can create one.) Since the init block throws an exception (which
* should never occur), the generated constructor converts the checked
* exception into an unchecked one so as to not require changes to the
* various places that create instances of the generated classes.
*
* Example:<code><pre>
* public StreamingAggregatorGen1() {
* try {
* __DRILL_INIT__();
* } catch (SchemaChangeException e) {
* throw new UnsupportedOperationException(e);
* }
* }</pre></code>
*
* Note: in Java 8 we'd use the <tt>Parameter</tt> class defined in Java's
* introspection package. But, Drill prefers Java 7 which only provides
* parameter types.
*/
private void addCtor(Class<?>[] parameters) {
JMethod ctor = clazz.constructor(JMod.PUBLIC);
JBlock body = ctor.body();
// If there are parameters, need to pass them to the super class.
if (parameters.length > 0) {
JInvocation superCall = JExpr.invoke("super");
// This case only occurs for nested classes, and all nested classes
// in Drill are inner classes. Don't pass along the (hidden)
// this$0 field.
for (int i = 1; i < parameters.length; i++) {
Class<?> p = parameters[i];
superCall.arg(ctor.param(model._ref(p), "arg" + i));
}
body.add(superCall);
}
JTryBlock tryBlock = body._try();
tryBlock.body().invoke(SignatureHolder.DRILL_INIT_METHOD);
JCatchBlock catchBlock = tryBlock._catch(model.ref(SchemaChangeException.class));
catchBlock.body()._throw(JExpr._new(model.ref(UnsupportedOperationException.class)).arg(catchBlock.param("e")));
}
示例6: _cacheMethod
import com.sun.codemodel.JBlock; //导入方法依赖的package包/类
JMethod _cacheMethod(JDefinedClass parent, JClass klass, String id,
String methodname, JExpression init)
{
final JFieldVar stor = parent.field(JMod.NONE, klass, methodname,
JExpr._null());
final JMethod getter = parent.method(JMod.PUBLIC, klass, methodname);
comment_stamp(getter.body());
final JBlock then =
getter.body()._if(stor.eq(JExpr._null()))._then();
then.assign(stor, init);
if (id != null)
then.add(JExpr.invoke("register").arg(id).arg(stor));
if (ChannelSet_t.isAssignableFrom(klass))
then.add(JExpr.invoke("registerChannelSet").arg(stor));
if (Channel_t.isAssignableFrom(klass))
then.add(JExpr.invoke("registerChannel").arg(stor));
getter.body()._return(stor);
return getter;
}
示例7: loopClassConstructor
import com.sun.codemodel.JBlock; //导入方法依赖的package包/类
public JMethod loopClassConstructor(JDefinedClass klass,
String id, Type type,
JDefinedClass indexClass)
{
final JMethod cons = klass.constructor(JMod.NONE);
final JVar index = cons.param(convertTypeToJClass(type), id);
final JBlock body = cons.body();
comment_stamp(body);
klass.field(JMod.FINAL, indexClass, "index");
// work around bug in jcodemodel on using index instead of this.index
body.assign(JExpr.refthis("index"),
JExpr._new(indexClass).arg(index));
body.add(JExpr.invoke("register").arg(id)
.arg(JExpr.refthis("index")));
return cons;
}
示例8: generateCopyToMethod
import com.sun.codemodel.JBlock; //导入方法依赖的package包/类
final void generateCopyToMethod(final boolean partial) {
if (this.implement) {
final JDefinedClass typeDefinition = this.typeOutline.isInterface() && ((DefinedInterfaceOutline)this.typeOutline).getSupportInterface() != null ? ((DefinedInterfaceOutline)this.typeOutline).getSupportInterface() : this.definedClass;
final JMethod copyToMethod = typeDefinition.method(JMod.PUBLIC, this.pluginContext.voidType, this.settings.getCopyToMethodName());
final JTypeVar typeVar = copyToMethod.generify(BuilderGenerator.PARENT_BUILDER_TYPE_PARAMETER_NAME);
final JVar otherParam = copyToMethod.param(JMod.FINAL, this.builderClass.raw.narrow(typeVar), BuilderGenerator.OTHER_PARAM_NAME);
final CopyGenerator cloneGenerator = this.pluginContext.createCopyGenerator(copyToMethod, partial);
final JBlock body = copyToMethod.body();
final JVar otherRef;
if (this.typeOutline.getSuperClass() != null) {
body.add(cloneGenerator.generatePartialArgs(this.pluginContext.invoke(JExpr._super(), copyToMethod.name()).arg(otherParam)));
}
otherRef = otherParam;
generateFieldCopyExpressions(cloneGenerator, body, otherRef, JExpr._this());
copyToMethod.javadoc().append(getMessage("javadoc.method.copyTo"));
copyToMethod.javadoc().addParam(otherParam).append(getMessage("javadoc.method.copyTo.param.other"));
}
}
示例9: generatePopulationCode
import com.sun.codemodel.JBlock; //导入方法依赖的package包/类
/**
* Generates a Holder class that will hold an {@link ArrayList} with all the
* first level beans in the graph (contents of {@link #beans}) on it.
*/
private void generatePopulationCode() {
try {
// Generate the holder class
JDefinedClass holderClass = cm._class(Config.CFG.getBasePackageName() + ".Holder");
JClass alObject = (JClass) cm._ref(ArrayList.class);
alObject = alObject.narrow(Object.class);
JFieldVar beansField = holderClass.field(JMod.PUBLIC, alObject, "beans", JExpr._new(alObject));
JMethod defConstructor = holderClass.constructor(JMod.PUBLIC);
JBlock body = defConstructor.body();
// Init the beans and add them to the array
for (MetaJavaBean mjb : beans) {
mjb.generateStaticInitCode();
JVar beanDecl = generateBeanNonStaticInitCode(mjb, body, 0);
body.add(beansField.invoke("add").arg(beanDecl));
}
// Init the base beans but don't add them to the array
for (MetaJavaBean bmjb : baseBeans) {
bmjb.generateStaticInitCode();
}
} catch (JClassAlreadyExistsException e) {
throw new RuntimeException("Error generating the holder class.", e);
}
}
示例10: visitValueVectorWriteExpression
import com.sun.codemodel.JBlock; //导入方法依赖的package包/类
private HoldingContainer visitValueVectorWriteExpression(ValueVectorWriteExpression e, ClassGenerator<?> generator) {
final LogicalExpression child = e.getChild();
final HoldingContainer inputContainer = child.accept(this, generator);
JBlock block = generator.getEvalBlock();
JExpression outIndex = generator.getMappingSet().getValueWriteIndex();
JVar vv = generator.declareVectorValueSetupAndMember(generator.getMappingSet().getOutgoing(), e.getFieldId());
// Only when the input is a reader, use writer interface to copy value.
// Otherwise, input is a holder and we use vv mutator to set value.
if (inputContainer.isReader()) {
JType writerImpl = generator.getModel()._ref(
TypeHelper.getWriterImpl(inputContainer.getMinorType(), inputContainer.getMajorType().getMode()));
JType writerIFace = generator.getModel()._ref(
TypeHelper.getWriterInterface(inputContainer.getMinorType(), inputContainer.getMajorType().getMode()));
JVar writer = generator.declareClassField("writer", writerIFace);
generator.getSetupBlock().assign(writer, JExpr._new(writerImpl).arg(vv).arg(JExpr._null()));
generator.getEvalBlock().add(writer.invoke("setPosition").arg(outIndex));
String copyMethod = inputContainer.isSingularRepeated() ? "copyAsValueSingle" : "copyAsValue";
generator.getEvalBlock().add(inputContainer.getHolder().invoke(copyMethod).arg(writer));
if (e.isSafe()) {
HoldingContainer outputContainer = generator.declare(Types.REQUIRED_BIT);
generator.getEvalBlock().assign(outputContainer.getValue(), JExpr.lit(1));
return outputContainer;
}
} else {
final JInvocation setMeth = GetSetVectorHelper.write(e.getChild().getMajorType(), vv, inputContainer, outIndex, e.isSafe() ? "setSafe" : "set");
if (inputContainer.isOptional()) {
JConditional jc = block._if(inputContainer.getIsSet().eq(JExpr.lit(0)).not());
block = jc._then();
}
block.add(setMeth);
}
return null;
}
示例11: generateInitWorkspaceBlockHA
import com.sun.codemodel.JBlock; //导入方法依赖的package包/类
private JBlock generateInitWorkspaceBlockHA(ClassGenerator<?> g, BlockType bt, String body, JVar[] workspaceJVars, JExpression wsIndexVariable){
JBlock initBlock = new JBlock(true, true);
if(!Strings.isNullOrEmpty(body) && !body.trim().isEmpty()){
JBlock sub = new JBlock(true, true);
addProtectedBlockHA(g, sub, body, null, workspaceJVars, wsIndexVariable);
initBlock.directStatement(String.format("/** start %s for function %s **/ ", bt.name(), registeredNames[0]));
initBlock.add(sub);
initBlock.directStatement(String.format("/** end %s for function %s **/ ", bt.name(), registeredNames[0]));
}
return initBlock;
}
示例12: visitIfExpression
import com.sun.codemodel.JBlock; //导入方法依赖的package包/类
@Override
public HoldingContainer visitIfExpression(IfExpression ifExpr, ClassGenerator<?> generator) throws RuntimeException {
JBlock local = generator.getEvalBlock();
HoldingContainer output = generator.declare(ifExpr.getCompleteType());
JBlock conditionalBlock = new JBlock(false, false);
IfCondition c = ifExpr.ifCondition;
HoldingContainer holdingContainer = c.condition.accept(this, generator);
final JConditional jc = conditionalBlock._if(holdingContainer.getIsSet().eq(JExpr.lit(1)).cand(holdingContainer.getValue().eq(JExpr.lit(1))));
generator.nestEvalBlock(jc._then());
HoldingContainer thenExpr = c.expression.accept(this, generator);
generator.unNestEvalBlock();
JConditional newCond = jc._then()._if(thenExpr.getIsSet().ne(JExpr.lit(0)));
JBlock b = newCond._then();
b.assign(output.getHolder(), thenExpr.getHolder());
// b.assign(output.getIsSet(), thenExpr.getIsSet());
// b.assign(output.getValue(), thenExpr.getValue());
generator.nestEvalBlock(jc._else());
HoldingContainer elseExpr = ifExpr.elseExpression.accept(this, generator);
generator.unNestEvalBlock();
JConditional newCond2 = jc._else()._if(elseExpr.getIsSet().ne(JExpr.lit(0)));
JBlock b2 = newCond2._then();
b2.assign(output.getHolder(), elseExpr.getHolder());
//b.assign(output.getIsSet(), elseExpr.getIsSet());
local.add(conditionalBlock);
return output;
}
示例13: visitValueVectorWriteExpression
import com.sun.codemodel.JBlock; //导入方法依赖的package包/类
private HoldingContainer visitValueVectorWriteExpression(ValueVectorWriteExpression e, ClassGenerator<?> generator) {
final LogicalExpression child = e.getChild();
final HoldingContainer inputContainer = child.accept(this, generator);
JBlock block = generator.getEvalBlock();
JExpression outIndex = generator.getMappingSet().getValueWriteIndex();
JVar vv = generator.declareVectorValueSetupAndMember(generator.getMappingSet().getOutgoing(), e.getFieldId());
// Only when the input is a reader, use writer interface to copy value.
// Otherwise, input is a holder and we use vv mutator to set value.
if (inputContainer.isReader()) {
JType writerImpl = generator.getModel()._ref(
TypeHelper.getWriterImpl(getArrowMinorType(inputContainer.getCompleteType().toMinorType())));
JType writerIFace = generator.getModel()._ref(
TypeHelper.getWriterInterface(getArrowMinorType(inputContainer.getCompleteType().toMinorType())));
JVar writer = generator.declareClassField("writer", writerIFace);
generator.getSetupBlock().assign(writer, JExpr._new(writerImpl).arg(vv));
generator.getEvalBlock().add(writer.invoke("setPosition").arg(outIndex));
String copyMethod = inputContainer.isSingularRepeated() ? "copyAsValueSingle" : "copyAsValue";
generator.getEvalBlock().add(inputContainer.getHolder().invoke(copyMethod).arg(writer));
if (e.isSafe()) {
HoldingContainer outputContainer = generator.declare(CompleteType.BIT);
generator.getEvalBlock().assign(outputContainer.getValue(), JExpr.lit(1));
return outputContainer;
}
} else {
final JInvocation setMeth = GetSetVectorHelper.write(e.getChild().getCompleteType().toMinorType(), vv, inputContainer, outIndex, e.isSafe() ? "setSafe" : "set");
JConditional jc = block._if(inputContainer.getIsSet().eq(JExpr.lit(0)).not());
block = jc._then();
block.add(setMeth);
}
return null;
}
示例14: createInnerBlock
import com.sun.codemodel.JBlock; //导入方法依赖的package包/类
/**
* Creates an inner braced and indented block
* @param type type of the created block
* @return a newly created inner block
*/
private JBlock createInnerBlock(BlockType type) {
final JBlock currBlock = getBlock(type);
final JBlock innerBlock = new JBlock();
currBlock.add(innerBlock);
return innerBlock;
}
示例15: generateInitWorkspaceBlockHA
import com.sun.codemodel.JBlock; //导入方法依赖的package包/类
private JBlock generateInitWorkspaceBlockHA(ClassGenerator<?> g, BlockType bt, String body, JVar[] workspaceJVars, JExpression wsIndexVariable){
JBlock initBlock = new JBlock(true, true);
if(!Strings.isNullOrEmpty(body) && !body.trim().isEmpty()){
JBlock sub = new JBlock(true, true);
addProtectedBlockHA(g, sub, body, null, workspaceJVars, wsIndexVariable);
initBlock.directStatement(String.format("/** start %s for function %s **/ ", bt.name(), getRegisteredNames()[0]));
initBlock.add(sub);
initBlock.directStatement(String.format("/** end %s for function %s **/ ", bt.name(), getRegisteredNames()[0]));
}
return initBlock;
}