当前位置: 首页>>代码示例>>Java>>正文


Java JBlock._return方法代码示例

本文整理汇总了Java中com.sun.codemodel.JBlock._return方法的典型用法代码示例。如果您正苦于以下问题:Java JBlock._return方法的具体用法?Java JBlock._return怎么用?Java JBlock._return使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.sun.codemodel.JBlock的用法示例。


在下文中一共展示了JBlock._return方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: addPublicGetMethod

import com.sun.codemodel.JBlock; //导入方法依赖的package包/类
private JMethod addPublicGetMethod(JDefinedClass jclass, JMethod internalGetMethod, JFieldRef notFoundValue) {
    JMethod method = jclass.method(PUBLIC, jclass.owner()._ref(Object.class), GETTER_NAME);
    JTypeVar returnType = method.generify("T");
    method.type(returnType);
    Models.suppressWarnings(method, "unchecked");
    JVar nameParam = method.param(String.class, "name");
    JBlock body = method.body();
    JVar valueVar = body.decl(jclass.owner()._ref(Object.class), "value",
            invoke(internalGetMethod).arg(nameParam).arg(notFoundValue));
    JConditional found = method.body()._if(notFoundValue.ne(valueVar));
    found._then()._return(cast(returnType, valueVar));
    JBlock notFound = found._else();

    JMethod getAdditionalProperties = jclass.getMethod("getAdditionalProperties", new JType[] {});
    if (getAdditionalProperties != null) {
        notFound._return(cast(returnType, invoke(getAdditionalProperties).invoke("get").arg(nameParam)));
    } else {
        notFound._throw(illegalArgumentInvocation(jclass, nameParam));
    }

    return method;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:23,代码来源:DynamicPropertiesRule.java

示例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;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:23,代码来源:DynamicPropertiesRule.java

示例3: addToString

import com.sun.codemodel.JBlock; //导入方法依赖的package包/类
private void addToString(JDefinedClass jclass) {
    Map<String, JFieldVar> fields = jclass.fields();
    JMethod toString = jclass.method(JMod.PUBLIC, String.class, "toString");
    Set<String> excludes = new HashSet<String>(Arrays.asList(ruleFactory.getGenerationConfig().getToStringExcludes()));

    JBlock body = toString.body();
    Class<?> toStringBuilder = ruleFactory.getGenerationConfig().isUseCommonsLang3() ? org.apache.commons.lang3.builder.ToStringBuilder.class : org.apache.commons.lang.builder.ToStringBuilder.class;
    JClass toStringBuilderClass = jclass.owner().ref(toStringBuilder);
    JInvocation toStringBuilderInvocation = JExpr._new(toStringBuilderClass).arg(JExpr._this());

    if (!jclass._extends().fullName().equals(Object.class.getName())) {
        toStringBuilderInvocation = toStringBuilderInvocation.invoke("appendSuper").arg(JExpr._super().invoke("toString"));
    }

    for (JFieldVar fieldVar : fields.values()) {
        if (excludes.contains(fieldVar.name()) || (fieldVar.mods().getValue() & JMod.STATIC) == JMod.STATIC) {
            continue;
        }
        toStringBuilderInvocation = toStringBuilderInvocation.invoke("append").arg(fieldVar.name()).arg(fieldVar);
    }

    body._return(toStringBuilderInvocation.invoke("toString"));

    toString.annotate(Override.class);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:26,代码来源:ObjectRule.java

示例4: addHashCode

import com.sun.codemodel.JBlock; //导入方法依赖的package包/类
private void addHashCode(JDefinedClass jclass, JsonNode node) {
    Map<String, JFieldVar> fields = removeFieldsExcludedFromEqualsAndHashCode(jclass.fields(), node);

    JMethod hashCode = jclass.method(JMod.PUBLIC, int.class, "hashCode");

    Class<?> hashCodeBuilder = ruleFactory.getGenerationConfig().isUseCommonsLang3() ? org.apache.commons.lang3.builder.HashCodeBuilder.class : org.apache.commons.lang.builder.HashCodeBuilder.class;

    JBlock body = hashCode.body();
    JClass hashCodeBuilderClass = jclass.owner().ref(hashCodeBuilder);
    JInvocation hashCodeBuilderInvocation = JExpr._new(hashCodeBuilderClass);

    if (!jclass._extends().fullName().equals(Object.class.getName())) {
        hashCodeBuilderInvocation = hashCodeBuilderInvocation.invoke("appendSuper").arg(JExpr._super().invoke("hashCode"));
    }

    for (JFieldVar fieldVar : fields.values()) {
        if ((fieldVar.mods().getValue() & JMod.STATIC) == JMod.STATIC) {
            continue;
        }
        hashCodeBuilderInvocation = hashCodeBuilderInvocation.invoke("append").arg(fieldVar);
    }

    body._return(hashCodeBuilderInvocation.invoke("toHashCode"));

    hashCode.annotate(Override.class);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:27,代码来源:ObjectRule.java

示例5: createEquals

import com.sun.codemodel.JBlock; //导入方法依赖的package包/类
public void createEquals(final JDefinedClass bean, final Iterable<JFieldVar> fields) {
  final JMethod method = bean.method(JMod.PUBLIC, this.codeModel.BOOLEAN, "equals");
  method.annotate(java.lang.Override.class);
  final JVar object = method.param(_type(java.lang.Object.class.getName()), "object");
  final JBlock block = method.body();
  block._if(JExpr._this().eq(object))._then()._return(JExpr.TRUE);
  block._if(object._instanceof(bean).not())._then()._return(JExpr.FALSE);
  JExpression result = JExpr.TRUE;
  final JExpression other = block.decl(bean, "other", JExpr.cast(bean, object));
  final JClass objectUtilities = _classByNames(net.anwiba.commons.lang.object.ObjectUtilities.class.getName());
  for (final JFieldVar field : fields) {
    result =
        result.cand(objectUtilities.staticInvoke("equals").arg(JExpr.refthis(field.name())).arg(other.ref(field)));
  }
  block._return(result);
}
 
开发者ID:AndreasWBartels,项目名称:libraries,代码行数:17,代码来源:EqualsFactory.java

示例6: withEquals

import com.sun.codemodel.JBlock; //导入方法依赖的package包/类
private void withEquals() {
    JMethod equals = this.pojo.method(JMod.PUBLIC, boolean.class, "equals");
    JVar otherObject = equals.param(Object.class, "other");

    Class<?> equalsBuilderClass = org.apache.commons.lang3.builder.EqualsBuilder.class;
    if (!config.isUseCommonsLang3()) {
        equalsBuilderClass = org.apache.commons.lang.builder.EqualsBuilder.class;
    }

    JBlock body = equals.body();

    body._if(otherObject.eq(JExpr._null()))._then()._return(JExpr.FALSE);
    body._if(otherObject.eq(JExpr._this()))._then()._return(JExpr.TRUE);
    body._if(JExpr._this().invoke("getClass").ne(otherObject.invoke("getClass")))._then()._return(JExpr.FALSE);

    JVar otherObjectVar = body.decl(this.pojo, "otherObject").init(JExpr.cast(this.pojo, otherObject));

    JClass equalsBuilderRef = this.pojo.owner().ref(equalsBuilderClass);

    JInvocation equalsBuilderInvocation = appendFieldsToEquals(getNonTransientAndNonStaticFields(), otherObjectVar, equalsBuilderRef);

    body._return(equalsBuilderInvocation.invoke("isEquals"));
}
 
开发者ID:phoenixnap,项目名称:springmvc-raml-plugin,代码行数:24,代码来源:PojoBuilder.java

示例7: createMethodFieldIsSet

import com.sun.codemodel.JBlock; //导入方法依赖的package包/类
private void createMethodFieldIsSet(JDefinedClass _class, Map<String, JType> fields) {
	JMethod method = _class.method(JMod.PUBLIC, codeModel.BOOLEAN, "isSet");
	JClass refEnumFields = codeModel.ref(_class.fullName() + DOT_FIELD);
	JVar param = method.param(refEnumFields, "field");
	
	method.body()._if(param.eq(JExpr._null()))._then()._throw(JExpr._new(codeModel.ref(IllegalStateException.class)));

	JSwitch _switch = method.body()._switch(param);
	for (Map.Entry<String, JType> entry : fields.entrySet()) {
		JBlock bodyCase = _switch._case(JExpr.ref(entry.getKey().toUpperCase())).body();
		String capitalizeName = JavaGeneratorUtil.getCapitalizeString(entry.getKey());
		bodyCase._return(JExpr.invoke("isSet" + capitalizeName));
	}

	JInvocation _newException = JExpr._new(codeModel.ref(IllegalStateException.class));
	method.body()._throw(_newException);

}
 
开发者ID:l3ug1m,项目名称:thrift-java-compiler,代码行数:19,代码来源:StructCodeGeneratorHelper.java

示例8:

import com.sun.codemodel.JBlock; //导入方法依赖的package包/类
protected JMethod generateObject$equals(final ClassOutline classOutline,
		final JDefinedClass theClass) {
	final JCodeModel codeModel = theClass.owner();
	final JMethod objectEquals = theClass.method(JMod.PUBLIC,
			codeModel.BOOLEAN, "equals");
	{
		final JVar object = objectEquals.param(Object.class, "object");
		final JBlock body = objectEquals.body();
		final JVar equalsStrategy = body.decl(JMod.FINAL,
				codeModel.ref(EqualsStrategy2.class), "strategy",
				createEqualsStrategy(codeModel));
		body._return(JExpr.invoke("equals").arg(JExpr._null())
				.arg(JExpr._null()).arg(object).arg(equalsStrategy));
	}
	return objectEquals;
}
 
开发者ID:highsource,项目名称:jaxb2-basics,代码行数:17,代码来源:EqualsPlugin.java

示例9: fixDummyListField

import com.sun.codemodel.JBlock; //导入方法依赖的package包/类
private void fixDummyListField(DummyListField fieldOutline) {
	if (DummyListField_$get.get(fieldOutline) == null) {
		final JFieldVar field = AbstractListField_field.get(fieldOutline);
		final JType listT = AbstractListField_listT.get(fieldOutline);
		final JClass coreList = DummyListField_coreList
				.get(fieldOutline);
		final JMethod $get = fieldOutline.parent().implClass.method(
				JMod.PUBLIC, listT, "get" + 
				fieldOutline.getPropertyInfo().getName(true));
		JBlock block = $get.body();
		block._if(field.eq(JExpr._null()))._then()
				.assign(field, JExpr._new(coreList));
		block._return(JExpr._this().ref(field));
		DummyListField_$get.set(fieldOutline, $get);
	}
}
 
开发者ID:highsource,项目名称:jaxb2-basics,代码行数:17,代码来源:FixJAXB1058Plugin.java

示例10: createToStringStrategy

import com.sun.codemodel.JBlock; //导入方法依赖的package包/类
protected JMethod generateObject$toString(final ClassOutline classOutline,
		final JDefinedClass theClass) {
	final JCodeModel codeModel = theClass.owner();
	final JMethod object$toString = theClass.method(JMod.PUBLIC,
			codeModel.ref(String.class), "toString");
	{
		final JBlock body = object$toString.body();

		final JVar toStringStrategy =

		body.decl(JMod.FINAL, codeModel.ref(ToStringStrategy2.class),
				"strategy", createToStringStrategy(codeModel));

		final JVar buffer = body.decl(JMod.FINAL,
				codeModel.ref(StringBuilder.class), "buffer",
				JExpr._new(codeModel.ref(StringBuilder.class)));
		body.invoke("append").arg(JExpr._null()).arg(buffer)
				.arg(toStringStrategy);
		body._return(buffer.invoke("toString"));
	}
	return object$toString;
}
 
开发者ID:highsource,项目名称:jaxb2-basics,代码行数:23,代码来源:ToStringPlugin.java

示例11: headerFieldMethod

import com.sun.codemodel.JBlock; //导入方法依赖的package包/类
public JMethod headerFieldMethod(JDefinedClass klass,
				 String method_name,
				 String header_section,
				 String field_name)
{
	final JMethod method = klass.method(JMod.PUBLIC, String_t,
					    method_name);
	final JBlock body = method.body();
	comment_stamp(body);

	final JVar value = body.decl(Type_t, "value",
				     JExpr._this()
				     .invoke(makeGetter("header"))
				     .invoke(makeGetter(header_section))
				     .ref(field_name).invoke("get"));
	// XXX: this implementation is horrible. There's no reason
	// not to export individual header fields.

	final JVar cast = body.decl(TypeString_t, "cast",
				    JExpr.cast(TypeString_t, value));
	body._return(cast.invoke("getValue"));

	return method;
}
 
开发者ID:BrainTech,项目名称:jsignalml,代码行数:25,代码来源:JavaClassGen.java

示例12: getFormatIDMethod

import com.sun.codemodel.JBlock; //导入方法依赖的package包/类
public JMethod getFormatIDMethod(JDefinedClass klass)
{
	final JMethod method = klass.method(JMod.PUBLIC, String_t,
					    "getFormatID");
	final JBlock body = method.body();
	comment_stamp(body);

	final JVar value = body.decl(Type_t, "value",
				     JExpr._this()
				     .invoke(makeGetter("header"))
				     .invoke(makeGetter("format_id"))
				     .invoke("get"));
	final JVar cast = body.decl(TypeString_t, "cast",
				    JExpr.cast(TypeString_t, value));
	body._return(cast.invoke("getValue"));

	return method;
}
 
开发者ID:BrainTech,项目名称:jsignalml,代码行数:19,代码来源:JavaClassGen.java

示例13: addGenericJsonObjectGetterSetterDeclaration

import com.sun.codemodel.JBlock; //导入方法依赖的package包/类
public static void addGenericJsonObjectGetterSetterDeclaration(JDefinedClass in)
{
   
    //TODO create a map of generic fields -> mock support only one geenric field right now
    JFieldVar field = in.field(JMod.PRIVATE, String.class, "genericField");

    JMethod getter = in.method(JMod.PUBLIC, String.class, "getFieldAsJsonObject");
    getter.param(String.class, "fieldName");
    JBlock block = getter.body();
    block._return(field);
    
    
    JMethod setter = in.method(JMod.PUBLIC, in, "setFieldAsJsonObject");
    JVar setterParam = setter.param(String.class, "fieldName");
    JVar setterParam2 = setter.param(String.class, "fieldValueAsJsonObject");

    setter.body().assign(JExpr._this().ref(field), setterParam2)._return(JExpr._this());   
}
 
开发者ID:highcharts4gwt,项目名称:generator,代码行数:19,代码来源:MockFieldHelper.java

示例14: addInternalGetMethodJava6

import com.sun.codemodel.JBlock; //导入方法依赖的package包/类
private JMethod addInternalGetMethodJava6(JDefinedClass jclass, JsonNode propertiesNode) {
    JMethod method = jclass.method(PROTECTED, jclass.owner()._ref(Object.class), DEFINED_GETTER_NAME);
    JVar nameParam = method.param(String.class, "name");
    JVar notFoundParam = method.param(jclass.owner()._ref(Object.class), "notFoundValue");
    JBlock body = method.body();
    JConditional propertyConditional = null;

    if (propertiesNode != null) {
        for (Iterator<Map.Entry<String, JsonNode>> properties = propertiesNode.fields(); properties.hasNext();) {
            Map.Entry<String, JsonNode> property = properties.next();
            String propertyName = property.getKey();
            JsonNode node = property.getValue();
            String fieldName = ruleFactory.getNameHelper().getPropertyName(propertyName, node);
            JType propertyType = jclass.fields().get(fieldName).type();

            JExpression condition = lit(propertyName).invoke("equals").arg(nameParam);
            if (propertyConditional == null) {
                propertyConditional = body._if(condition);
            } else {
                propertyConditional = propertyConditional._elseif(condition);
            }
            JMethod propertyGetter = jclass.getMethod(getGetterName(propertyName, propertyType, node), new JType[] {});
            propertyConditional._then()._return(invoke(propertyGetter));
        }
    }

    JClass extendsType = jclass._extends();
    JBlock lastBlock = propertyConditional == null ? body : propertyConditional._else();
    if (extendsType != null && extendsType instanceof JDefinedClass) {
        JDefinedClass parentClass = (JDefinedClass) extendsType;
        JMethod parentMethod = parentClass.getMethod(DEFINED_GETTER_NAME,
                new JType[] { parentClass.owner()._ref(String.class), parentClass.owner()._ref(Object.class) });
        lastBlock._return(_super().invoke(parentMethod).arg(nameParam).arg(notFoundParam));
    } else {
        lastBlock._return(notFoundParam);
    }

    return method;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:40,代码来源:DynamicPropertiesRule.java

示例15: addInternalSetMethodJava7

import com.sun.codemodel.JBlock; //导入方法依赖的package包/类
private JMethod addInternalSetMethodJava7(JDefinedClass jclass, JsonNode propertiesNode) {
    JMethod method = jclass.method(PROTECTED, jclass.owner().BOOLEAN, DEFINED_SETTER_NAME);
    JVar nameParam = method.param(String.class, "name");
    JVar valueParam = method.param(Object.class, "value");
    JBlock body = method.body();
    JSwitch propertySwitch = body._switch(nameParam);
    if (propertiesNode != null) {
        for (Iterator<Map.Entry<String, JsonNode>> properties = propertiesNode.fields(); properties.hasNext();) {
            Map.Entry<String, JsonNode> property = properties.next();
            String propertyName = property.getKey();
            JsonNode node = property.getValue();
            String fieldName = ruleFactory.getNameHelper().getPropertyName(propertyName, node);
            JType propertyType = jclass.fields().get(fieldName).type();

            addSetPropertyCase(jclass, propertySwitch, propertyName, propertyType, valueParam, node);
        }
    }
    JBlock defaultBlock = propertySwitch._default().body();
    JClass extendsType = jclass._extends();
    if (extendsType != null && extendsType instanceof JDefinedClass) {
        JDefinedClass parentClass = (JDefinedClass) extendsType;
        JMethod parentMethod = parentClass.getMethod(DEFINED_SETTER_NAME,
                new JType[] { parentClass.owner()._ref(String.class), parentClass.owner()._ref(Object.class) });
        defaultBlock._return(_super().invoke(parentMethod).arg(nameParam).arg(valueParam));
    } else {
        defaultBlock._return(FALSE);
    }
    return method;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:30,代码来源:DynamicPropertiesRule.java


注:本文中的com.sun.codemodel.JBlock._return方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。