/** * Returns a new empty block. * * @return New empty block. */ protected JBlock newBlock() { return JBlock.dummyInstance.block(); }
public Object onEpsilon() { final JBlock block = JBlock.dummyInstance.block(); return block; }
public Object onIgnore(final IgnoreItem item) { final JBlock block = JBlock.dummyInstance.block(); return block; }
public Object onNullSet() { final JBlock block = JBlock.dummyInstance.block(); block.directStatement("// NullSetExpression - nothing to check"); return block; }
public Object onSequence(final SequenceExp exp) { final JBlock block = JBlock.dummyInstance.block(); final JBlock left = (JBlock) exp.exp1.visit(this); final JBlock right = (JBlock) exp.exp2.visit(this); block.add(left); block.add(right); return block; }
public Object onInterleave(final InterleaveExp exp) { final JBlock block = JBlock.dummyInstance.block(); final JBlock left = (JBlock) exp.exp1.visit(this); final JBlock right = (JBlock) exp.exp2.visit(this); block.add(left); block.add(right); return block; }
public Object onSuper(final SuperClassItem item) { final JBlock block = JBlock.dummyInstance.block(); block.invoke(JExpr.ref("super"), "check").arg(locator).arg(handler).arg(master); return block; }
public ElementWriterBuilderImpl(ElementWriterBuilderImpl parent, QName name, JType type) { this.parent = parent; this.name = name; this.buildContext = parent.buildContext; this.method = parent.buildContext.createMethod(parent.getWriterClass(), "write" + capitalize(type.name())); this.objectVar = addBasicArgs(method, type, decapitalize(type.name())); method._throws(XMLStreamException.class); this.writerClass = parent.writerClass; this.model = parent.model; exceptions.addAll(parent.exceptions); currentBlock = method.body(); currentBlock.add(conditions); attributeBlock = method.body().block(); }
private void createHashCode(final JDefinedClass bean, final Iterable<JFieldVar> fields) { final JMethod method = bean.method(JMod.PUBLIC, this.codeModel.INT, "hashCode"); method.annotate(java.lang.Override.class); final JBlock block = method.body().block(); final JClass objectUtilities = _classByNames(net.anwiba.commons.lang.object.ObjectUtilities.class.getName()); JInvocation hashCode = objectUtilities.staticInvoke("hashCode"); for (final JFieldVar field : fields) { hashCode = hashCode.arg(JExpr.refthis(field.name())); } block._return(hashCode); }
private void generateConstructors() { noArgConstructor = cls().constructor(JMod.PUBLIC); noArgConstructor.body().block().assign(_this().ref("value"), _null()); valueConstructor = cls().constructor(JMod.PUBLIC); valueConstructor.param(getJavaType(), "value"); valueConstructor.body().block().assign(_this().ref("value"), ref("value")); }
public Object onElement(final ElementExp exp) { final JBlock block = JBlock.dummyInstance.block(); final FieldUse nil = classContext.target.getField("Nil"); final JStatement statement = (JStatement) exp.contentModel.visit(this); if (nil == null) { block.add(statement); } else { final FieldItem nilFieldItem = FieldUtils.getFieldItem(nil); final JMethod isNil = AccessorUtils.get(classContext, nilFieldItem); block._if(JOp.not(master.invoke(isNil)))._then().add(statement); } return block; }
@Override public void execute(final JVar param) throws RuntimeException { ensureThatArgument(param, notNull()); method .body() ._if(param.eq(JExpr._null())) ._then() .block() .add(JExpr.refthis(param.name()).invoke("clear")) ._return(returnValue); } };
@Override public void execute(final JVar param) throws RuntimeException { ensureThatArgument(param, notNull()); method .body() ._if(param.eq(JExpr._null())) ._then() .block() .add(JExpr.refthis(param.name()).invoke("clear")) ._return(returnValue); } };
public Object onSingleField(FieldItem fieldItem) { final JMethod getter = AccessorUtils.get(classContext, fieldItem); final JMethod setter = AccessorUtils.set(classContext, fieldItem); final TypeItem typeItem = TypeUtils.getCommonBaseTypeItem(classContext, fieldItem); final JType type = typeItem != null ? typeItem.getType() : getter.type(); final JBlock block = JBlock.dummyInstance.block(); final JVar value = block.decl(JMod.FINAL, type, "value", source.invoke(getter)); final JVar valueCopy = block.decl(type, "valueCopy"); final JStatement statement = (JStatement) fieldItem.visit(new EntryCopyVisitor( classContext, value, valueCopy, type)); block.add(statement); block.invoke(cloned, setter).arg(valueCopy); return block; }
public Object onSingleField(FieldItem fieldItem) { final JMethod getter = AccessorUtils.get(classContext, fieldItem); final JMethod setter = AccessorUtils.set(classContext, fieldItem); final TypeItem typeItem = TypeUtils.getCommonBaseTypeItem(classContext, fieldItem); final JType type = typeItem != null ? typeItem.getType() : getter.type(); final JBlock block = JBlock.dummyInstance.block(); final JVar value = block.decl(JMod.FINAL, type, "value", source.invoke(getter)); final JVar valueCopy = block.decl(type, "valueCopy"); final JStatement statement = (JStatement) fieldItem.visit(new EntryCopyVisitor( classContext, value, valueCopy, clonedObjects, type)); block.add(statement); block.invoke(cloned, setter).arg(valueCopy); return block; }
@Override public void execute(final JVar param) throws RuntimeException { ensureThatArgument(param, notNull()); final ValueConverter valueConverter = new ValueConverter(codeModel); final JInvocation invocation = JExpr._new(param.type()); method .body() ._if(param.eq(JExpr._null())) ._then() .block() .assign(JExpr.refthis(param.name()), valueConverter.convert(invocation)) ._return(returnValue); } };
public Object onComplexSingleField(FieldItem fieldItem) { final ClassItem fieldClassItem = (ClassItem) TypeUtils.getCommonBaseTypeItem( classContext, fieldItem); final JBlock block = JBlock.dummyInstance.block(); final JArray nodes = JExpr.newArray(codeModel.ref(Node.class)); nodes.add(JExpr.invoke(AccessorUtils.get(classContext, fieldItem)).invoke("createNode").arg( JExpr.lit(fieldItem.name))); final JConditional ifSet = block ._if(JExpr.invoke(AccessorUtils.isSet(classContext, fieldItem))); ifSet._then()._return(nodes); ifSet._else()._return(JExpr.newArray(codeModel.ref(Node.class))); return block; }
private void generateToString() { toString = cls().method(JMod.PUBLIC, cm.ref("java.lang.String"), "toString"); toString.body()._return(ref("this").invoke("toString").arg(lit(""))); JMethod toString2 = cls().method(JMod.PUBLIC, cm.ref("java.lang.String"), "toString"); toString2.param(String.class, "indent"); toString2.body()._if(_this().ref("value").eq(_null()))._then().block()._return(lit("null")); if ( type.getName().equals("array") ) { toString2.body()._return(cm.ref("java.util.Arrays").staticInvoke("toString").arg(_this().ref("value"))); } else { toString2.body()._return(_this().ref("value").invoke("toString")); } }
protected void createInitialFields() { value = cls().field(JMod.PROTECTED, getJavaType(), "value"); generateConstructors(); getValue = cls().method(JMod.PUBLIC, getJavaType(), "getValue"); getValue.body()._return(_this().ref("value")); setValue = cls().method(JMod.PUBLIC, cm.VOID, "setValue"); setValue.param(getJavaType(), "value"); setValue.body().block().assign(_this().ref("value"), ref("value")); encodingPicker = generator.picker().cls().method(JMod.PUBLIC, cm.BYTE, "choose" + toJavaClassName(type.getName() + "Encoding")); encodingPicker.param(getJavaType(), "value"); generateSize(); generateEquals(); generateHashCode(); generateToString(); sizeOfConstructor().body()._return(lit(1)); sizeOfBody().body()._return(invoke("size").minus(invoke(sizeOfConstructor))); }