大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。
Jetbrains全系列IDE稳定放心使用
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
/**
* Applies this schema rule to take the required code generation steps.
*
* A Java {@link Enum} is created, with constants for each of the enum
* values present in the schema. The enum name is derived from the nodeName,
* and the enum type itself is created as an inner class of the owning type.
* In the rare case that no owning type exists (the enum is the root of the
* schema), then the enum becomes a public class in its own right.
*
* The actual JSON value for each enum constant is held in a property called
* “value” in the generated type. A static factory method
* fromValue(String)
is added to the generated enum, and the
* methods are annotated to allow Jackson to marshal/unmarshal values
* correctly.
*
* @param nodeName
* the name of the property which is an “enum”
* @param node
* the enum node
* @param container
* the class container (class or package) to which this enum
* should be added
* @return the newly generated Java type that was created to represent the
* given enum
*/
@Override
public JType apply(String nodeName, JsonNode node, JClassContainer container, Schema schema) {
JDefinedClass _enum;
try {
_enum = createEnum(node, nodeName, container);
} catch (ClassAlreadyExistsException e) {
return e.getExistingClass();
}
schema.setJavaTypeIfEmpty(_enum);
if (node.has(“javaInterfaces”)) {
addInterfaces(_enum, node.get(“javaInterfaces”));
}
// copy our node; remove the javaType as it will throw off the TypeRule for our case
ObjectNode typeNode = (ObjectNode)node.deepCopy();
typeNode.remove(“javaType”);
// If type is specified on the enum, get a type rule for it. Otherwise, we’re a string.
// (This is different from the default of Object, which is why we don’t do this for every case.)
JType backingType = node.has(“type”) ?
ruleFactory.getTypeRule().apply(nodeName, typeNode, container, schema) :
container.owner().ref(String.class);
JFieldVar valueField = addValueField(_enum, backingType);
// override toString only if we have a sensible string to return
if(isString(backingType)){
addToString(_enum, valueField);
}
addValueMethod(_enum, valueField);
addEnumConstants(node.path(“enum”), _enum, node.path(“javaEnumNames”), backingType);
addFactoryMethod(_enum, backingType);
return _enum;
}
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/186803.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...