本文整理汇总了Java中com.sun.codemodel.JExpr._null方法的典型用法代码示例。如果您正苦于以下问题:Java JExpr._null方法的具体用法?Java JExpr._null怎么用?Java JExpr._null使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.codemodel.JExpr
的用法示例。
在下文中一共展示了JExpr._null方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getDefaultSet
import com.sun.codemodel.JExpr; //导入方法依赖的package包/类
/**
* Creates a default value for a set property by:
* <ol>
* <li>Creating a new {@link LinkedHashSet} with the correct generic type
* <li>Using {@link Arrays#asList(Object...)} to initialize the set with the
* correct default values
* </ol>
*
* @param fieldType
* the java type that applies for this field ({@link Set} with
* some generic type argument)
* @param node
* the node containing default values for this set
* @return an expression that creates a default value that can be assigned
* to this field
*/
private JExpression getDefaultSet(JType fieldType, JsonNode node) {
JClass setGenericType = ((JClass) fieldType).getTypeParameters().get(0);
JClass setImplClass = fieldType.owner().ref(LinkedHashSet.class);
setImplClass = setImplClass.narrow(setGenericType);
JInvocation newSetImpl = JExpr._new(setImplClass);
if (node instanceof ArrayNode && node.size() > 0) {
JInvocation invokeAsList = fieldType.owner().ref(Arrays.class).staticInvoke("asList");
for (JsonNode defaultValue : node) {
invokeAsList.arg(getDefaultValue(setGenericType, defaultValue));
}
newSetImpl.arg(invokeAsList);
} else if (!ruleFactory.getGenerationConfig().isInitializeCollections()) {
return JExpr._null();
}
return newSetImpl;
}
示例2: getDefaultList
import com.sun.codemodel.JExpr; //导入方法依赖的package包/类
/**
* Creates a default value for a list property by:
* <ol>
* <li>Creating a new {@link ArrayList} with the correct generic type
* <li>Using {@link Arrays#asList(Object...)} to initialize the list with
* the correct default values
* </ol>
*
* @param fieldType
* the java type that applies for this field ({@link List} with
* some generic type argument)
* @param node
* the node containing default values for this list
* @return an expression that creates a default value that can be assigned
* to this field
*/
private JExpression getDefaultList(JType fieldType, JsonNode node) {
JClass listGenericType = ((JClass) fieldType).getTypeParameters().get(0);
JClass listImplClass = fieldType.owner().ref(ArrayList.class);
listImplClass = listImplClass.narrow(listGenericType);
JInvocation newListImpl = JExpr._new(listImplClass);
if (node instanceof ArrayNode && node.size() > 0) {
JInvocation invokeAsList = fieldType.owner().ref(Arrays.class).staticInvoke("asList");
for (JsonNode defaultValue : node) {
invokeAsList.arg(getDefaultValue(listGenericType, defaultValue));
}
newListImpl.arg(invokeAsList);
} else if (!ruleFactory.getGenerationConfig().isInitializeCollections()) {
return JExpr._null();
}
return newListImpl;
}
示例3: literalExpr
import com.sun.codemodel.JExpr; //导入方法依赖的package包/类
/**
* Calls the correct {@link JExpr} <code>lit</code> method.
*
* @param value
* The literal value that must be output in an expresion.
* @return The matching expression for the real type of value.
*/
public static JExpression literalExpr(Object value) {
if (value == null) {
return JExpr._null();
} else if (value instanceof String) {
return JExpr.lit((String) value);
} else if (value instanceof Integer) {
return JExpr.lit((Integer) value);
}
throw new RuntimeException("Impossible to construct initial value for: " + value);
}
示例4: getDefaultValue
import com.sun.codemodel.JExpr; //导入方法依赖的package包/类
static JExpression getDefaultValue(JType fieldType, JsonNode node) {
fieldType = fieldType.unboxify();
if (fieldType.fullName().equals(String.class.getName())) {
return JExpr.lit(node.asText());
} else if (fieldType.fullName().equals(int.class.getName())) {
return JExpr.lit(Integer.parseInt(node.asText()));
} else if (fieldType.fullName().equals(BigInteger.class.getName())) {
return JExpr._new(fieldType).arg(JExpr.lit(node.asText()));
} else if (fieldType.fullName().equals(double.class.getName())) {
return JExpr.lit(Double.parseDouble(node.asText()));
} else if (fieldType.fullName().equals(BigDecimal.class.getName())) {
return JExpr._new(fieldType).arg(JExpr.lit(node.asText()));
} else if (fieldType.fullName().equals(boolean.class.getName())) {
return JExpr.lit(Boolean.parseBoolean(node.asText()));
} else if (fieldType.fullName().equals(DateTime.class.getName()) || fieldType.fullName().equals(Date.class.getName())) {
long millisecs = parseDateToMillisecs(node.asText());
JInvocation newDateTime = JExpr._new(fieldType);
newDateTime.arg(JExpr.lit(millisecs));
return newDateTime;
} else if (fieldType.fullName().equals(LocalDate.class.getName()) || fieldType.fullName().equals(LocalTime.class.getName())) {
JInvocation stringParseableTypeInstance = JExpr._new(fieldType);
stringParseableTypeInstance.arg(JExpr.lit(node.asText()));
return stringParseableTypeInstance;
} else if (fieldType.fullName().equals(long.class.getName())) {
return JExpr.lit(Long.parseLong(node.asText()));
} else if (fieldType.fullName().equals(float.class.getName())) {
return JExpr.lit(Float.parseFloat(node.asText()));
} else if (fieldType.fullName().equals(URI.class.getName())) {
JInvocation invokeCreate = fieldType.owner().ref(URI.class).staticInvoke("create");
return invokeCreate.arg(JExpr.lit(node.asText()));
} else if (fieldType instanceof JDefinedClass && ((JDefinedClass) fieldType).getClassType().equals(ClassType.ENUM)) {
return getDefaultEnum(fieldType, node);
} else {
return JExpr._null();
}
}