本文整理了Java中com.sun.codemodel.JBlock.staticInvoke()
方法的一些代码示例,展示了JBlock.staticInvoke()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JBlock.staticInvoke()
方法的具体详情如下:
包路径:com.sun.codemodel.JBlock
类名称:JBlock
方法名:staticInvoke
[英]Creates a static invocation statement.
[中]创建静态调用语句。
代码示例来源:origin: e-biz/androidkickstartr
public JCodeModel generate(JCodeModel jCodeModel, RefHelper ref) throws IOException {
logger = LoggerFactory.getLogger(getClass());
try {
jClass = jCodeModel._class(appDetails.getApplicationPackage());
jClass._extends(ref.application());
jClass.annotate(ref.reportsCrashes()).param("formKey", "YOUR_FORM_KEY");
JMethod onCreateMethod = jClass.method(JMod.PUBLIC, jCodeModel.VOID, "onCreate");
onCreateMethod.annotate(ref.override());
JBlock onCreateMethodBody = onCreateMethod.body();
onCreateMethodBody.staticInvoke(ref.acra(), "init").arg(JExpr._this());
onCreateMethodBody.invoke(JExpr._super(), "onCreate");
} catch (JClassAlreadyExistsException e1) {
logger.error("Classname already exists", e1);
}
return jCodeModel;
}
代码示例来源:origin: stackoverflow.com
JClass mapper = model.directClass("com.another.Mapper");
JDefinedClass dc = model._class("com.example.Something");
JMethod method = dc.method(JMod.PUBLIC | JMod.STATIC, Void.TYPE, "testMethod");
JBlock executerBlock = method.body();
executerBlock.staticInvoke(mapper, "get");
代码示例来源:origin: Evolveum/midpoint
private void createFieldSetterBody(JMethod method, JFieldVar field) {
JBlock body = method.body();
JInvocation invocation = body.staticInvoke(CLASS_MAP.get(PrismForJAXBUtil.class),
METHOD_PRISM_UTIL_SET_PROPERTY_VALUE);
//push arguments
invocation.arg(JExpr.invoke(METHOD_AS_PRISM_CONTAINER_VALUE));
invocation.arg(JExpr.ref(fieldFPrefixUnderscoredUpperCase(field.name())));
invocation.arg(method.listParams()[0]);
}
代码示例来源:origin: Evolveum/midpoint
private void createFieldReferenceSetterBody(JFieldVar field, JVar param, JBlock body) {
JVar cont = body.decl(CLASS_MAP.get(PrismReferenceValue.class), REFERENCE_VALUE_FIELD_NAME,
JOp.cond(param.ne(JExpr._null()), JExpr.invoke(param, METHOD_AS_REFERENCE_VALUE), JExpr._null()));
JInvocation invocation = body.staticInvoke(CLASS_MAP.get(PrismForJAXBUtil.class),
METHOD_PRISM_UTIL_SET_REFERENCE_VALUE_AS_REF);
invocation.arg(JExpr.invoke(METHOD_AS_PRISM_CONTAINER_VALUE));
invocation.arg(JExpr.ref(fieldFPrefixUnderscoredUpperCase(field.name())));
invocation.arg(cont);
}
代码示例来源:origin: Evolveum/midpoint
private void createFieldReferenceUseSetterBody(JFieldVar field, ClassOutline classOutline, JVar param,
JBlock body) {
JVar cont = body.decl(CLASS_MAP.get(PrismObject.class), OBJECT_LOCAL_FIELD_NAME, JOp.cond(param.ne(JExpr._null()),
JExpr.invoke(param, METHOD_AS_PRISM_CONTAINER), JExpr._null()));
JInvocation invocation = body.staticInvoke(CLASS_MAP.get(PrismForJAXBUtil.class),
METHOD_PRISM_UTIL_SET_REFERENCE_VALUE_AS_OBJECT);
invocation.arg(JExpr.invoke(METHOD_AS_PRISM_CONTAINER_VALUE));
JFieldVar referencedField = getReferencedField(field, classOutline);
invocation.arg(JExpr.ref(fieldFPrefixUnderscoredUpperCase(referencedField.name())));
invocation.arg(cont);
}
代码示例来源:origin: Evolveum/midpoint
private JMethod createFieldListCreator(JFieldVar field, ClassOutline classOutline, JMethod getterMethod, String itemCreationMethodName) {
JFieldRef qnameRef = JExpr.ref(fieldFPrefixUnderscoredUpperCase(field.name())); // F_ASSIGNMENT
// e.g. List<AssignmentType> createAssignmentList()
String methodName = getMethodName(classOutline, field, "create") + "List";
JMethod method = classOutline.implClass.method(JMod.PUBLIC, field.type(), methodName);
JBlock body = method.body();
// PrismForJAXBUtil.createContainer(asPrismContainerValue(), F_ASSIGNMENT)
body.staticInvoke(CLASS_MAP.get(PrismForJAXBUtil.class), itemCreationMethodName)
.arg(JExpr.invoke(METHOD_AS_PRISM_CONTAINER_VALUE))
.arg(qnameRef);
// return getAssignment();
body._return(JExpr.invoke(getterMethod));
return method;
}
代码示例来源:origin: Evolveum/midpoint
private void createContainerFieldSetterBody(JFieldVar field, ClassOutline classOutline, JMethod method) {
JVar param = method.listParams()[0];
JBlock body = method.body();
JVar cont;
if (isPrismContainer(param.type(), classOutline.parent())) {
cont = body.decl(CLASS_MAP.get(PrismContainerValue.class), FIELD_CONTAINER_VALUE_LOCAL_VAR_NAME,
JOp.cond(param.ne(JExpr._null()), JExpr.invoke(param, METHOD_AS_PRISM_CONTAINER_VALUE), JExpr._null()));
} else {
cont = body.decl(CLASS_MAP.get(PrismContainerValue.class), FIELD_CONTAINER_VALUE_LOCAL_VAR_NAME,
JOp.cond(param.ne(JExpr._null()), JExpr.invoke(param, METHOD_AS_PRISM_CONTAINER_VALUE), JExpr._null()));
}
JInvocation invocation = body.staticInvoke(CLASS_MAP.get(PrismForJAXBUtil.class),
METHOD_PRISM_UTIL_SET_FIELD_CONTAINER_VALUE);
invocation.arg(JExpr.invoke(METHOD_AS_PRISM_CONTAINER_VALUE));
invocation.arg(JExpr.ref(fieldFPrefixUnderscoredUpperCase(field.name())));
invocation.arg(cont);
}
代码示例来源:origin: fusesource/fuse-extra
private void addFieldWrite(Attribute attribute, JBlock body) {
if ( attribute.attribute.type().isArray() ) {
body.staticInvoke(cm.ref("AMQPArray"), "write").arg(_this().ref(attribute.attribute.name())).arg(ref("out"));
} else if ( generator.getMapping().get(attribute.type) != null ) {
body.staticInvoke(cm.ref(generator.getPrimitiveJavaClass().get(attribute.type)), "write").arg(_this().ref(attribute.attribute.name())).arg(ref("out"));
} else {
JConditional conditional = body
._if(ref(attribute.attribute.name()).ne(_null()));
conditional._then()
.invoke(ref(attribute.attribute.name()), "write").arg(ref("out"));
conditional._else().invoke(ref("out"), "writeByte").arg(generator.registry().cls().staticRef("NULL_FORMAT_CODE"));
}
}
代码示例来源:origin: com.googlecode.androidannotations/androidannotations
.staticInvoke(classes.LOG, "e") //
代码示例来源:origin: com.github.vsspt/jaxb-ri-xjc
private void createHashCodeMethod(final JDefinedClass implClass, final List<JFieldVar> fields, final boolean isSuperClass) {
final JMethod method = implClass.method(JMod.PUBLIC, implClass.owner().INT, OPERATION_HASH);
method.annotate(Override.class);
final JClass objectsClass = implClass.owner().ref(Objects.class);
final JBlock block = new JBlock();
final JInvocation invocation = block.staticInvoke(objectsClass, OPERATION_HASH_METHOD);
for (final JFieldVar jFieldVar : fields) {
invocation.arg(JExpr.ref(jFieldVar.name()));
}
if (isSuperClass) {
invocation.arg(JExpr._super().invoke(OPERATION_HASH));
}
method.body()._return(invocation);
}
代码示例来源:origin: com.github.vsspt/jaxb-ri-xjc
private void createEqualsMethod(final JDefinedClass implClass, final List<JFieldVar> fields, final boolean isSuperClass) {
final JMethod method = implClass.method(JMod.PUBLIC, implClass.owner().BOOLEAN, OPERATION_EQUALS);
method.annotate(Override.class);
final JVar vObj = method.param(Object.class, OBJ);
final JConditional condMe = method.body()._if(JExpr._this().eq(vObj));
condMe._then()._return(JExpr.TRUE);
final JConditional condNull = method.body()._if(vObj.eq(JExpr._null()));
condNull._then()._return(JExpr.FALSE);
if (isSuperClass) {
final JConditional condSuper = method.body()._if(JExpr._super().invoke(OPERATION_EQUALS).arg(vObj).eq(JExpr.FALSE));
condSuper._then()._return(JExpr.FALSE);
}
final JVar vOther = method.body().decl(JMod.FINAL, implClass, OTHER, JExpr.cast(implClass, vObj));
final JClass objectsClass = implClass.owner().ref(Objects.class);
final List<JFieldVar> clonedList = new ArrayList<JFieldVar>(fields.size());
clonedList.addAll(fields);
final JFieldVar first = clonedList.remove(IDX_TO_REMOVE);
final JBlock block = new JBlock();
JExpression invocation = block.staticInvoke(objectsClass, OPERATION_EQUALS).arg(JExpr.ref(first.name())).arg(vOther.ref(first.name()));
for (final JFieldVar jFieldVar : clonedList) {
invocation = JOp.cand(invocation, block.staticInvoke(objectsClass, OPERATION_EQUALS).arg(JExpr.ref(jFieldVar.name())).arg(vOther.ref(jFieldVar.name())));
}
method.body()._return(invocation);
}
代码示例来源:origin: com.googlecode.androidannotations/androidannotations
JInvocation errorInvoke = catchBody.staticInvoke(holder.classes().LOG, "e");
代码示例来源:origin: Evolveum/midpoint
private void updateObjectReferenceType(JDefinedClass definedClass, JMethod getReference) {
JFieldVar typeField = definedClass.fields().get("type");
JMethod getType = recreateMethod(findMethod(definedClass, "getType"), definedClass);
copyAnnotations(getType, typeField);
JBlock body = getType.body();
body._return(JExpr.invoke(JExpr.invoke(getReference), "getTargetType"));
definedClass.removeField(typeField);
JMethod setType = recreateMethod(findMethod(definedClass, "setType"), definedClass);
body = setType.body();
JInvocation invocation = body.invoke(JExpr.invoke(getReference), "setTargetType");
invocation.arg(setType.listParams()[0]);
invocation.arg(JExpr.lit(true));
JFieldVar targetNameField = definedClass.fields().get("targetName");
JMethod getTargetName = recreateMethod(findMethod(definedClass, "getTargetName"), definedClass);
copyAnnotations(getTargetName, targetNameField);
JBlock getTargetNamebody = getTargetName.body();
JInvocation getTargetNameInvocation = CLASS_MAP.get(PrismForJAXBUtil.class).staticInvoke(METHOD_PRISM_UTIL_GET_REFERENCE_TARGET_NAME);
getTargetNameInvocation.arg(JExpr.invoke(getReference));
getTargetNamebody._return(getTargetNameInvocation);
definedClass.removeField(targetNameField);
JMethod setTargetName = recreateMethod(findMethod(definedClass, "setTargetName"), definedClass);
JBlock setTargetNamebody = setTargetName.body();
JInvocation setTagetNameInvocation = setTargetNamebody.staticInvoke(CLASS_MAP.get(PrismForJAXBUtil.class), METHOD_PRISM_UTIL_SET_REFERENCE_TARGET_NAME);
setTagetNameInvocation.arg(JExpr.invoke(getReference));
setTagetNameInvocation.arg(setTargetName.listParams()[0]);
}
代码示例来源:origin: org.jvnet.hyperjaxb3/hyperjaxb3-tools
ifSetThen.staticInvoke(codeModel.ref(ToStringUtils.class), "toIndentedString").arg(value).arg(JOp.plus(indent, JExpr.lit('\t'))).arg(buffer);
ifSetThen.staticInvoke(codeModel.ref(ToStringUtils.class), "collectionToIndentedString").arg(value).arg(JOp.plus(indent, JExpr.lit('\t'))).arg(buffer);
代码示例来源:origin: fusesource/fuse-extra
private void initWriteMethods() {
write().body().staticInvoke(cls(), "write").arg(_this().ref("value")).arg(ref("out"));
writeConstructor().body()._return(cls().staticInvoke("writeConstructor").arg(_this().ref("value")).arg(ref("out")));
writeBody().body().staticInvoke(cls(), "writeBody").arg(ref("formatCode")).arg(_this().ref("value")).arg(ref("out"));
staticWrite().body().decl(cm.BYTE, "formatCode", cls().staticInvoke("writeConstructor").arg(ref("value")).arg(ref("out")));
staticWrite().body().staticInvoke(cls(), "writeBody").arg(ref("formatCode")).arg(ref("value")).arg(ref("out"));
staticWriteConstructor = cls().method(JMod.PUBLIC | JMod.STATIC, cm.BYTE, "writeConstructor");
staticWriteConstructor._throws(Exception.class);
staticWriteConstructor.param(getJavaType(), "value");
staticWriteConstructor.param(DataOutput.class, "out");
staticWriteConstructor.body().decl(cm.BYTE, "formatCode", generator.registry().cls()
.staticInvoke("instance")
.invoke("picker")
.invoke("choose" + toJavaClassName(type.getName() + "Encoding"))
.arg(ref("value")));
staticWriteConstructor.body().invoke(ref("out"), "writeByte").arg(ref("formatCode"));
staticWriteConstructor.body()._return(ref("formatCode"));
staticWriteBody = cls().method(JMod.PUBLIC | JMod.STATIC, cm.VOID, "writeBody");
staticWriteBody._throws(Exception.class);
staticWriteBody.param(cm.BYTE, "formatCode");
staticWriteBody.param(getJavaType(), "value");
staticWriteBody.param(DataOutput.class, "out");
}
代码示例来源:origin: uk.org.retep.tools/jaxb
bc.build.method.body().staticInvoke( bft, METHOD_BUILDALLIFNEEDED ).
arg( bf ).
arg( JExpr.invoke( bc.build.param, getGetterName( bc, f ) ) );
bc.clone.method.body().staticInvoke( bft, METHOD_ADDBUILDERS ).
arg( JExpr.invoke( bc.build.param, getGetterName( bc, f ) ) ).
arg( bf );
代码示例来源:origin: fusesource/fuse-extra
private void fillInWriteMethod() {
writeConstructor().body().block().invoke(ref("CONSTRUCTOR"), "write").arg(ref("out"));
writeConstructor().body()._return(cast(cm.BYTE, lit(0)));
write().body().invoke("writeConstructor").arg(ref("out"));
write().body().invoke("writeBody").arg(cast(cm.BYTE, lit((byte) 0))).arg(ref("out"));
if ( isComposite() ) {
writeBody().body().decl(cm.LONG, "fieldSize", _this().invoke("sizeOfFields"));
writeBody().body().decl(cm.INT, "count", _this().invoke("count"));
writeBody().body().staticInvoke(cm.ref(generator.getMarshaller() + ".DescribedTypeSupport"), "writeListHeader").arg(ref("fieldSize")).arg(ref("count")).arg(ref("out"));
}
for ( Attribute attribute : amqpFields ) {
if ( isComposite() ) {
writeBody().body().assign(ref("count"), ref("count").minus(lit(1)));
JBlock ifBody = writeBody().body()._if(ref("count").gte(lit(0)))._then();
addFieldWrite(attribute, ifBody);
} else {
addFieldWrite(attribute, writeBody().body());
}
}
}
内容来源于网络,如有侵权,请联系作者删除!