com.sun.codemodel.JStatement Java Examples

The following examples show how to use com.sun.codemodel.JStatement. 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: CodeModelUtils.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public static JStatement split(JDefinedClass theClass,
		JStatement[] statements, String prefix, int start, int length,
		int threshold) {
	final JMethod method = theClass.method(JMod.PRIVATE + JMod.STATIC,
			theClass.owner().VOID, prefix);
	if (length < threshold) {
		for (int index = start; (index - start) < length; index++) {
			final JStatement statement = statements[index];
			method.body().add(statement);
		}
	} else {
		method.body().add(
				split(theClass, statements, prefix + "_0", start,
						length / 2, threshold));
		method.body().add(
				split(theClass, statements, prefix + "_1", start + length
						/ 2, length - (length / 2), threshold));
	}
	return JExpr.invoke(method);
}