本文整理汇总了Java中com.sun.codemodel.JBlock.block方法的典型用法代码示例。如果您正苦于以下问题:Java JBlock.block方法的具体用法?Java JBlock.block怎么用?Java JBlock.block使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.codemodel.JBlock
的用法示例。
在下文中一共展示了JBlock.block方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: append
import com.sun.codemodel.JBlock; //导入方法依赖的package包/类
private void append(JBlock block, String propertyName,
String propertyMethod, JType propertyType,
Collection<JType> possiblePropertyTypes, A arguments) {
block = block.block();
final JType declarablePropertyType = getTypeFactory().create(
propertyType).getDeclarableType();
// We assume that primitive properties are always set
boolean isAlwaysSet = propertyType.isPrimitive();
getCodeGenerator().generate(
block,
propertyType,
possiblePropertyTypes,
isAlwaysSet,
arguments.property(block, propertyName, propertyMethod,
declarablePropertyType, declarablePropertyType,
possiblePropertyTypes));
}
示例2: generate
import com.sun.codemodel.JBlock; //导入方法依赖的package包/类
@Override
protected void generate(ClassOutline classOutline, JDefinedClass theClass) {
final JCodeModel codeModel = theClass.owner();
final JMethod object$hashCode = theClass.method(JMod.PUBLIC,
codeModel.INT, "hashCode");
{
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);
}
}
示例3: if
import com.sun.codemodel.JBlock; //导入方法依赖的package包/类
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");
{
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;
}
示例4: if
import com.sun.codemodel.JBlock; //导入方法依赖的package包/类
protected JMethod generateHashCode$hashCode(ClassOutline classOutline,
final JDefinedClass theClass) {
JCodeModel codeModel = theClass.owner();
final JMethod hashCode$hashCode = theClass.method(JMod.PUBLIC,
codeModel.INT, "hashCode");
{
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;
}
示例5: if
import com.sun.codemodel.JBlock; //导入方法依赖的package包/类
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");
{
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;
}