Java Code Examples for com.sun.codemodel.JBlock#_return

The following examples show how to use com.sun.codemodel.JBlock#_return . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CreateTraversingVisitorClass.java    From jaxb-visitor with Apache License 2.0 6 votes vote down vote up
private void generateForDirectClass(JDefinedClass traversingVisitor, JTypeVar returnType, JTypeVar exceptionType, JClass implClass) {
    // add method impl to traversing visitor
    JMethod travViz;
    String visitMethodName = visitMethodNamer.apply(implClass.name());
    travViz = traversingVisitor.method(JMod.PUBLIC, returnType, visitMethodName);
    travViz._throws(exceptionType);
    JVar beanVar = travViz.param(implClass, "aBean");
    travViz.annotate(Override.class);
    JBlock travVizBloc = travViz.body();

    addTraverseBlock(travViz, beanVar, true);

    JVar retVal = travVizBloc.decl(returnType, "returnVal");

    travVizBloc.assign(retVal, JExpr.invoke(JExpr.invoke("getVisitor"), visitMethodName).arg(beanVar));

    travVizBloc._if(JExpr.ref("progressMonitor").ne(JExpr._null()))._then().invoke(JExpr.ref("progressMonitor"), "visited").arg(beanVar);

    addTraverseBlock(travViz, beanVar, false);

    travVizBloc._return(retVal);
}
 
Example 2
Source File: PojoBuilder.java    From springmvc-raml-plugin with Apache License 2.0 6 votes vote down vote up
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.getPojoConfig().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"));
}
 
Example 3
Source File: EqualsPlugin.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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");
	objectEquals.annotate(Override.class);
	{
		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;
}
 
Example 4
Source File: PluginImpl.java    From immutable-xjc with MIT License 6 votes vote down vote up
private void replaceCollectionGetter(JDefinedClass ownerClass, JFieldVar field, final JMethod getter) {
    // remove the old getter
    ownerClass.methods().remove(getter);
    // and create a new one
    JMethod newGetter = ownerClass.method(getter.mods().getValue(), getter.type(), getter.name());
    JBlock block = newGetter.body();

    JVar ret = block.decl(getJavaType(field), "ret");
    JCodeModel codeModel = field.type().owner();
    JVar param = generateMethodParameter(getter, field);
    JConditional conditional = block._if(param.eq(JExpr._null()));
    conditional._then().assign(ret, getEmptyCollectionExpression(codeModel, param));
    conditional._else().assign(ret, getUnmodifiableWrappedExpression(codeModel, param));
    block._return(ret);

    getter.javadoc().append("Returns unmodifiable collection.");
}
 
Example 5
Source File: FixJAXB1058Plugin.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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);
	}
}
 
Example 6
Source File: SimpleToStringPlugin.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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");
	object$toString.annotate(Override.class);
	{
		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;
}
 
Example 7
Source File: CopyablePlugin.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 6 votes vote down vote up
protected JMethod generateCopyTo$createNewInstance(
		final ClassOutline classOutline, final JDefinedClass theClass) {

	final JMethod existingMethod = theClass.getMethod("createNewInstance",
			new JType[0]);
	if (existingMethod == null) {

		final JMethod newMethod = theClass.method(JMod.PUBLIC, theClass
				.owner().ref(Object.class), "createNewInstance");
		newMethod.annotate(Override.class);
		{
			final JBlock body = newMethod.body();
			body._return(JExpr._new(theClass));
		}
		return newMethod;
	} else {
		return existingMethod;
	}
}
 
Example 8
Source File: PluginImpl.java    From immutable-xjc with MIT License 6 votes vote down vote up
private JMethod addAddMethod(JDefinedClass builderClass, JFieldVar field, boolean inherit) {
    List<JClass> typeParams = ((JClass) getJavaType(field)).getTypeParameters();
    if (!typeParams.iterator().hasNext()) {
        return null;
    }
    JMethod method = builderClass.method(JMod.PUBLIC, builderClass, "add" + StringUtils.capitalize(field.name()));
    JBlock block = method.body();
    String fieldName = field.name();
    JVar param = method.param(JMod.FINAL, typeParams.iterator().next(), fieldName);
    if (inherit) {
        generateSuperCall(method);
    } else {
        JInvocation invocation = JExpr.refthis(fieldName).invoke("add").arg(param);
        block.add(invocation);
    }
    block._return(JExpr._this());
    return method;
}
 
Example 9
Source File: CopyablePlugin.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 6 votes vote down vote up
protected JMethod generateCopyTo$copyTo(final ClassOutline classOutline,
		final JDefinedClass theClass) {

	final JCodeModel codeModel = theClass.owner();
	final JMethod copyTo$copyTo = theClass.method(JMod.PUBLIC,
			codeModel.ref(Object.class), "copyTo");
	copyTo$copyTo.annotate(Override.class);
	{
		final JVar target = copyTo$copyTo.param(Object.class, "target");

		final JBlock body = copyTo$copyTo.body();
		final JVar copyStrategy = body.decl(JMod.FINAL,
				codeModel.ref(CopyStrategy2.class), "strategy",
				createCopyStrategy(codeModel));

		body._return(JExpr.invoke("copyTo").arg(JExpr._null()).arg(target)
				.arg(copyStrategy));
	}
	return copyTo$copyTo;
}
 
Example 10
Source File: UntypedListField.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void generateAccessors() {
    final MethodWriter writer = outline.createMethodWriter();
    final Accessor acc = create(JExpr._this());

    // [RESULT]
    // List getXXX() {
    //     return <ref>;
    // }
    $get = writer.declareMethod(listT,"get"+prop.getName(true));
    writer.javadoc().append(prop.javadoc);
    JBlock block = $get.body();
    fixNullRef(block);  // avoid using an internal getter
    block._return(acc.ref(true));

    String pname = NameConverter.standard.toVariableName(prop.getName(true));
    writer.javadoc().append(
        "Gets the value of the "+pname+" property.\n\n"+
        "<p>\n" +
        "This accessor method returns a reference to the live list,\n" +
        "not a snapshot. Therefore any modification you make to the\n" +
        "returned list will be present inside the JAXB object.\n" +
        "This is why there is not a <CODE>set</CODE> method for the " +pname+ " property.\n" +
        "\n"+
        "<p>\n" +
        "For example, to add a new item, do as follows:\n"+
        "<pre>\n"+
        "   get"+prop.getName(true)+"().add(newItem);\n"+
        "</pre>\n"+
        "\n\n"
    );

    writer.javadoc().append(
        "<p>\n" +
        "Objects of the following type(s) are allowed in the list\n")
        .append(listPossibleTypes(prop));
}
 
Example 11
Source File: OperationProcessor.java    From jpmml-evaluator with GNU Affero General Public License v3.0 5 votes vote down vote up
static
private void createAggregationMethod(JDefinedClass clazz, JClass valueClazz, String name, JExpression valueExpression, String operation, JPrimitiveType type){
	JMethod method = clazz.method(JMod.PUBLIC, valueClazz, name);
	method.annotate(Override.class);

	JBlock body = method.body();

	body._return(JExpr._new(valueClazz).arg(valueExpression).arg(JExpr.invoke("newReport")).arg(createReportInvocation(clazz, operation, Collections.emptyList(), type)));
}
 
Example 12
Source File: ValueVectorHashHelper.java    From Bats with Apache License 2.0 5 votes vote down vote up
private void setupBuild64Hash(ClassGenerator<Hash64> cg, MappingSet incomingMapping, VectorAccessible batch, LogicalExpression[] keyExprs, TypedFieldId[] toHashKeyFieldIds) throws SchemaChangeException {
  cg.setMappingSet(incomingMapping);
  if (keyExprs == null || keyExprs.length == 0) {
    cg.getEvalBlock()._return(JExpr.lit(0));
  }
  String seedValue = "seedValue";
  String fieldId = "fieldId";
  LogicalExpression seed = ValueExpressions.getParameterExpression(seedValue, Types.required(TypeProtos.MinorType.INT));

  LogicalExpression fieldIdParamExpr = ValueExpressions.getParameterExpression(fieldId, Types.required(TypeProtos.MinorType.INT));
  ClassGenerator.HoldingContainer fieldIdParamHolder = cg.addExpr(fieldIdParamExpr);
  int i = 0;
  for (LogicalExpression expr : keyExprs) {
    TypedFieldId targetTypeFieldId = toHashKeyFieldIds[i];
    ValueExpressions.IntExpression targetBuildFieldIdExp = new ValueExpressions.IntExpression(targetTypeFieldId.getFieldIds()[0], ExpressionPosition.UNKNOWN);

    JFieldRef targetBuildSideFieldId = cg.addExpr(targetBuildFieldIdExp, ClassGenerator.BlkCreateMode.TRUE_IF_BOUND).getValue();
    JBlock ifBlock = cg.getEvalBlock()._if(fieldIdParamHolder.getValue().eq(targetBuildSideFieldId))._then();
    cg.nestEvalBlock(ifBlock);
    LogicalExpression hashExpression = HashPrelUtil.getHash64Expression(expr, seed, true);
    LogicalExpression materializedExpr = ExpressionTreeMaterializer.materializeAndCheckErrors(hashExpression, batch, context.getFunctionRegistry());
    ClassGenerator.HoldingContainer hash = cg.addExpr(materializedExpr, ClassGenerator.BlkCreateMode.TRUE_IF_BOUND);
    ifBlock._return(hash.getValue());
    cg.unNestEvalBlock();
    i++;
  }
  cg.getEvalBlock()._return(JExpr.lit(0));
}
 
Example 13
Source File: HashCodePlugin.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private JMethod generateObject$hashCode(final JDefinedClass theClass) {
	final JMethod object$hashCode = theClass.method(JMod.PUBLIC,
			theClass.owner().INT, "hashCode");
	object$hashCode.annotate(Override.class);
	{
		final JBlock body = object$hashCode.body();
		final JVar hashCodeStrategy = body.decl(JMod.FINAL, theClass
				.owner().ref(HashCodeStrategy2.class), "strategy",
				createHashCodeStrategy(theClass.owner()));
		body._return(JExpr._this().invoke("hashCode").arg(JExpr._null())
				.arg(hashCodeStrategy));
	}
	return object$hashCode;
}
 
Example 14
Source File: ToStringPlugin.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 4 votes vote down vote up
protected JMethod generateToString$appendFields(ClassOutline classOutline,
		final JDefinedClass theClass) {
	final JCodeModel codeModel = theClass.owner();

	final JMethod toString$appendFields = theClass.method(JMod.PUBLIC,
			codeModel.ref(StringBuilder.class), "appendFields");
	toString$appendFields.annotate(Override.class);
	{
		final JVar locator = toString$appendFields.param(
				ObjectLocator.class, "locator");
		final JVar buffer = toString$appendFields.param(
				StringBuilder.class, "buffer");
		final JVar toStringStrategy = toString$appendFields.param(
				ToStringStrategy2.class, "strategy");
		final JBlock body = toString$appendFields.body();

		final Boolean superClassImplementsToString = StrategyClassUtils
				.superClassImplements(classOutline, ignoring,
						ToString2.class);

		if (superClassImplementsToString == null) {
			// No superclass
		} else if (superClassImplementsToString.booleanValue()) {
			body.invoke(JExpr._super(), "appendFields").arg(locator)
					.arg(buffer).arg(toStringStrategy);
		} else {
			// Superclass does not implement ToString
		}

		final FieldOutline[] declaredFields = FieldOutlineUtils.filter(
				classOutline.getDeclaredFields(), getIgnoring());

		if (declaredFields.length > 0) {

			for (final FieldOutline fieldOutline : declaredFields) {
				final JBlock block = body.block();
				final FieldAccessorEx fieldAccessor = getFieldAccessorFactory()
						.createFieldAccessor(fieldOutline, JExpr._this());
				final JVar theValue = block.decl(
						fieldAccessor.getType(),
						"the"
								+ fieldOutline.getPropertyInfo().getName(
										true));

				final JExpression valueIsSet = (fieldAccessor.isAlwaysSet() || fieldAccessor
						.hasSetValue() == null) ? JExpr.TRUE
						: fieldAccessor.hasSetValue();

				fieldAccessor.toRawValue(block, theValue);

				block.invoke(toStringStrategy, "appendField")
						.arg(locator)
						.arg(JExpr._this())
						.arg(JExpr.lit(fieldOutline.getPropertyInfo()
								.getName(false))).arg(buffer).arg(theValue)
						.arg(valueIsSet);
			}
		}
		body._return(buffer);
	}
	return toString$appendFields;
}
 
Example 15
Source File: OperationProcessor.java    From jpmml-evaluator with GNU Affero General Public License v3.0 4 votes vote down vote up
static
private void createFormatMethod(JDefinedClass clazz, JPrimitiveType type){
	JCodeModel codeModel = clazz.owner();

	JClass numberClazz = codeModel.ref(Number.class);
	JClass stringBuilderClazz = codeModel.ref(StringBuilder.class);

	JMethod method = clazz.method(JMod.STATIC | JMod.PRIVATE, String.class, "format");

	JVar valuesParameter = method.varParam(numberClazz, "values");

	JBlock body = method.body();

	JVar sbVariable = body.decl(stringBuilderClazz, "sb", JExpr._new(stringBuilderClazz).arg(valuesParameter.ref("length").mul(JExpr.lit(32))));

	JForEach forStatement = body.forEach(numberClazz, "value", valuesParameter);

	JBlock forBody = forStatement.body();

	forBody.add(createReportInvocation(clazz, sbVariable, "${0}", Collections.singletonList(forStatement.var()), type));

	body._return(sbVariable.invoke("toString"));
}
 
Example 16
Source File: HashCodePlugin.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 4 votes vote down vote up
protected JMethod generateHashCode$hashCode(ClassOutline classOutline,
		final JDefinedClass theClass) {

	JCodeModel codeModel = theClass.owner();
	final JMethod hashCode$hashCode = theClass.method(JMod.PUBLIC,
			codeModel.INT, "hashCode");
	hashCode$hashCode.annotate(Override.class);
	{
		final JVar locator = hashCode$hashCode.param(ObjectLocator.class,
				"locator");
		final JVar hashCodeStrategy = hashCode$hashCode.param(
				HashCodeStrategy2.class, "strategy");
		final JBlock body = hashCode$hashCode.body();

		final JExpression currentHashCodeExpression;

		final Boolean superClassImplementsHashCode = StrategyClassUtils
				.superClassImplements(classOutline, ignoring,
						HashCode2.class);

		if (superClassImplementsHashCode == null) {
			currentHashCodeExpression = JExpr.lit(1);
		} else if (superClassImplementsHashCode.booleanValue()) {
			currentHashCodeExpression = JExpr._super().invoke("hashCode")
					.arg(locator).arg(hashCodeStrategy);
		} else {
			currentHashCodeExpression = JExpr._super().invoke("hashCode");
		}

		final JVar currentHashCode = body.decl(codeModel.INT,
				"currentHashCode", currentHashCodeExpression);

		final FieldOutline[] declaredFields = FieldOutlineUtils.filter(
				classOutline.getDeclaredFields(), getIgnoring());

		if (declaredFields.length > 0) {

			for (final FieldOutline fieldOutline : declaredFields) {
				final FieldAccessorEx fieldAccessor = getFieldAccessorFactory()
						.createFieldAccessor(fieldOutline, JExpr._this());
				if (fieldAccessor.isConstant()) {
					continue;
				}
				final JBlock block = body.block();

				final JVar theValue = block.decl(
						fieldAccessor.getType(),
						"the"
								+ fieldOutline.getPropertyInfo().getName(
										true));

				final JExpression valueIsSet = (fieldAccessor.isAlwaysSet() || fieldAccessor
						.hasSetValue() == null) ? JExpr.TRUE
						: fieldAccessor.hasSetValue();

				fieldAccessor.toRawValue(block, theValue);

				block.assign(
						currentHashCode,
						hashCodeStrategy
								.invoke("hashCode")
								.arg(codeModel
										.ref(LocatorUtils.class)
										.staticInvoke("property")
										.arg(locator)
										.arg(fieldOutline.getPropertyInfo()
												.getName(false))
										.arg(theValue))
								.arg(currentHashCode).arg(theValue)
								.arg(valueIsSet));
			}
		}
		body._return(currentHashCode);
	}
	return hashCode$hashCode;
}
 
Example 17
Source File: BuilderGenerator.java    From jaxb2-rich-contract-plugin with MIT License 4 votes vote down vote up
public void buildProperties() throws SAXException {
	final TypeOutline superClass = this.typeOutline.getSuperClass();
	final JMethod initMethod;
	final JVar productParam;
	final JBlock initBody;
	if (this.implement) {
		initMethod = this.builderClass.raw.method(JMod.PROTECTED, this.definedClass, PluginContext.INIT_METHOD_NAME);
		final JTypeVar typeVar = initMethod.generify(BuilderGenerator.PRODUCT_TYPE_PARAMETER_NAME, this.definedClass);
		initMethod.type(typeVar);
		productParam = initMethod.param(JMod.FINAL, typeVar, BuilderGenerator.PRODUCT_VAR_NAME);
		initBody = initMethod.body();
	} else {
		initMethod = null;
		initBody = null;
		productParam = null;
	}
	generateDefinedClassJavadoc();

	if (this.typeOutline.getDeclaredFields() != null) {
		for (final PropertyOutline fieldOutline : this.typeOutline.getDeclaredFields()) {
			if (fieldOutline.hasGetter()) {
				generateBuilderMember(fieldOutline, initBody, productParam);
			}
		}
	}
	if (superClass != null) {
		generateExtendsClause(getBuilderDeclaration(superClass.getImplClass()));
		if (this.implement) initBody._return(JExpr._super().invoke(initMethod).arg(productParam));
		generateBuilderMemberOverrides(superClass);
	} else if (this.implement) {
		initBody._return(productParam);
	}
	generateImplementsClause();
	generateBuildMethod(initMethod);
	generateCopyToMethod(false);
	generateNewCopyBuilderMethod(false);
	if (this.implement && !this.definedClass.isAbstract()) {
		generateNewBuilderMethod();
		generateCopyOfMethod(this.typeOutline, false);
	}
	if (this.settings.isGeneratingPartialCopy()) {
		generateCopyToMethod(true);
		generateNewCopyBuilderMethod(true);
		if (this.implement && !this.definedClass.isAbstract()) {
			final JMethod partialCopyOfMethod = generateCopyOfMethod(this.typeOutline, true);
			generateConveniencePartialCopyMethod(this.typeOutline, partialCopyOfMethod, this.pluginContext.copyExceptMethodName, this.pluginContext.excludeConst);
			generateConveniencePartialCopyMethod(this.typeOutline, partialCopyOfMethod, this.pluginContext.copyOnlyMethodName, this.pluginContext.includeConst);
		}
	}
	generateCopyOfBuilderMethods();
}
 
Example 18
Source File: SimpleHashCodePlugin.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
	protected void generate(ClassOutline classOutline, JDefinedClass theClass) {

		final JCodeModel codeModel = theClass.owner();
		final JMethod object$hashCode = theClass.method(JMod.PUBLIC,
				codeModel.INT, "hashCode");
		object$hashCode.annotate(Override.class);
		{
			final JBlock body = object$hashCode.body();

			final JExpression currentHashCodeExpression = JExpr.lit(1);

			final JVar currentHashCode = body.decl(codeModel.INT,
					"currentHashCode", currentHashCodeExpression);

			final Boolean superClassImplementsHashCode = StrategyClassUtils
					.superClassNotIgnored(classOutline, getIgnoring());

			if (superClassImplementsHashCode != null) {
				body.assign(
						currentHashCode,
						currentHashCode.mul(JExpr.lit(getMultiplier())).plus(
								JExpr._super().invoke("hashCode")));
			}

			final FieldOutline[] declaredFields = FieldOutlineUtils.filter(
					classOutline.getDeclaredFields(), getIgnoring());

			if (declaredFields.length > 0) {

				for (final FieldOutline fieldOutline : declaredFields) {
					final FieldAccessorEx fieldAccessor = getFieldAccessorFactory()
							.createFieldAccessor(fieldOutline, JExpr._this());
					if (fieldAccessor.isConstant()) {
						continue;
					}
					final JBlock block = body.block();
					block.assign(currentHashCode,
							currentHashCode.mul(JExpr.lit(getMultiplier())));

					String propertyName = fieldOutline.getPropertyInfo()
							.getName(true);
					final JVar value = block.decl(fieldAccessor.getType(),
							"the" + propertyName);

					fieldAccessor.toRawValue(block, value);
					final JType exposedType = fieldAccessor.getType();

					final Collection<JType> possibleTypes = FieldUtils
							.getPossibleTypes(fieldOutline, Aspect.EXPOSED);
					final boolean isAlwaysSet = fieldAccessor.isAlwaysSet();
//					final JExpression hasSetValue = exposedType.isPrimitive() ? JExpr.TRUE
//							: value.ne(JExpr._null());
					
					final JExpression hasSetValue = (fieldAccessor.isAlwaysSet() || fieldAccessor
							.hasSetValue() == null) ? JExpr.TRUE
							: fieldAccessor.hasSetValue();					
					getCodeGenerator().generate(
							block,
							exposedType,
							possibleTypes,
							isAlwaysSet,
							new HashCodeArguments(codeModel, currentHashCode,
									getMultiplier(), value, hasSetValue));
				}
			}
			body._return(currentHashCode);
		}
	}
 
Example 19
Source File: OperationProcessor.java    From jpmml-evaluator with GNU Affero General Public License v3.0 3 votes vote down vote up
static
private void createCopyMethod(JDefinedClass clazz){
	JCodeModel codeModel = clazz.owner();

	JClass reportClazz = codeModel.ref(Report.class);

	JMethod method = clazz.method(JMod.PUBLIC, clazz, "copy");
	method.annotate(Override.class);

	JBlock body = method.body();

	JVar reportVariable = body.decl(reportClazz, "report", JExpr.invoke("getReport"));

	body._return(JExpr._new(clazz).arg(JExpr._super().ref("value")).arg(reportVariable.invoke("copy")).arg(JExpr._null()));
}
 
Example 20
Source File: OperationProcessor.java    From jpmml-evaluator with GNU Affero General Public License v3.0 3 votes vote down vote up
static
private void createGetMethod(JDefinedClass clazz, JClass valueClazz, JExpression valueExpression){
	JCodeModel codeModel = clazz.owner();

	JMethod method = clazz.method(JMod.PUBLIC, valueClazz, "get");
	method.annotate(Override.class);

	method.param(codeModel.INT, "index");

	JBlock body = method.body();

	body._return(JExpr._new(valueClazz).arg(valueExpression).arg(JExpr.invoke("newReport")));
}