本文整理汇总了Java中com.sun.codemodel.JEnumConstant.arg方法的典型用法代码示例。如果您正苦于以下问题:Java JEnumConstant.arg方法的具体用法?Java JEnumConstant.arg怎么用?Java JEnumConstant.arg使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.codemodel.JEnumConstant
的用法示例。
在下文中一共展示了JEnumConstant.arg方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addEnumConstants
import com.sun.codemodel.JEnumConstant; //导入方法依赖的package包/类
private void addEnumConstants(JsonNode node, JDefinedClass _enum, JsonNode customNames, JType type) {
Collection<String> existingConstantNames = new ArrayList<String>();
for (int i = 0; i < node.size(); i++) {
JsonNode value = node.path(i);
if (!value.isNull()) {
String constantName = getConstantName(value.asText(), customNames.path(i).asText());
constantName = makeUnique(constantName, existingConstantNames);
existingConstantNames.add(constantName);
JEnumConstant constant = _enum.enumConstant(constantName);
constant.arg(DefaultRule.getDefaultValue(type, value));
ruleFactory.getAnnotator().enumConstant(constant, value.asText());
}
}
}
示例2: buildEnumClass
import com.sun.codemodel.JEnumConstant; //导入方法依赖的package包/类
private JDefinedClass buildEnumClass(String enumName, List<String> values) throws JClassAlreadyExistsException {
if (pkg.isDefined(enumName)) {
return pkg._getClass(enumName);
}
JDefinedClass valueEnum = pkg._enum(enumName);
JFieldVar valField = valueEnum.field(JMod.PRIVATE | JMod.FINAL, String.class, "value");
JMethod ctor = valueEnum.constructor(JMod.PRIVATE);
JVar param = ctor.param(String.class, "val");
ctor.body().assign(valField, param);
JMethod toString = valueEnum.method(JMod.PUBLIC, String.class, "toString");
toString.annotate(Override.class);
toString.body()._return(valField);
for (String value : values) {
JEnumConstant sortCnst = valueEnum.enumConstant(value.toUpperCase().replace(' ', '_'));
sortCnst.arg(JExpr.lit(value));
}
return valueEnum;
}
示例3: parseEnumMember
import com.sun.codemodel.JEnumConstant; //导入方法依赖的package包/类
@SuppressWarnings("unused")
private void parseEnumMember(Element root, ParsingContext context) {
JDefinedClass enumClass = (JDefinedClass) context.getCmNode();
JEnumConstant enumConstant = enumClass.enumConstant(
NameUtils.camelToUpper(enumClass.name()) + '_' + root.getAttributeValue("name").toUpperCase()
);
long value = Long.parseLong(root.getAttributeValue("value"));
enumConstant.arg(JExpr.lit(value));
System.out.println("--> " + enumConstant.getName() + " (" + value + ")");
}
示例4: withEnum
import com.sun.codemodel.JEnumConstant; //导入方法依赖的package包/类
public <T> EnumBuilder withEnum(T name, Class<T> type) {
pojoCreationCheck();
String cleaned = NamingHelper.cleanNameForJavaEnum(name.toString());
if (!doesEnumContainField(type, cleaned)) {
withValueField(type);
ENUM_CACHE.put(cleaned, true);
logger.debug("Adding field: " + name + " to " + this.pojo.name());
if (StringUtils.hasText(cleaned)) {
JEnumConstant enumConstant = this.pojo.enumConstant(cleaned);
if (type.equals(Integer.class)) {
enumConstant.arg(JExpr.lit((Integer)name));
} else if (type.equals(Boolean.class)) {
enumConstant.arg(JExpr.lit((Boolean)name));
} else if (type.equals(Double.class)) {
enumConstant.arg(JExpr.lit((Double)name));
} else if (type.equals(Float.class)) {
enumConstant.arg(JExpr.lit((Float)name));
} else if (type.equals(Long.class)) {
enumConstant.arg(JExpr.lit((Long)name));
} else {
enumConstant.arg(JExpr.lit(name.toString()));
enumConstant.annotate(JsonProperty.class).param("value", name.toString());
}
}
}
return this;
}
示例5: getSymbolObj
import com.sun.codemodel.JEnumConstant; //导入方法依赖的package包/类
public JExpression getSymbolObj(String symbol){
JEnumConstant obj = enums.get(symbol);
if(obj == null){
obj = clazz.enumConstant(symbol.toUpperCase());
String pseudo = g.getPseudonym(symbol);
if(pseudo != null){
obj.arg(JExpr.lit(pseudo));
}
enums.put(symbol, obj);
}
return obj;
}
示例6: getParamTypeEnum
import com.sun.codemodel.JEnumConstant; //导入方法依赖的package包/类
private JClass getParamTypeEnum(Filter filter) throws JClassAlreadyExistsException {
String enumName = camel(filter.getName(), true) + "Option";
if (pkg.isDefined(enumName)) {
return pkg._getClass(enumName);
}
List<Option> options = filter.getOption();
if (options.size() == 1) {/*turn into '*Only' method?*/}
if (options.size() == 2) {
if (ImmutableSet.of("true","false").equals(
ImmutableSet.of(options.get(0).getValue().toLowerCase(),
options.get(1).getValue().toLowerCase()
)
)) {
return model.ref(Boolean.class);
}
}
JDefinedClass valueEnum = pkg._enum(enumName);
JFieldVar valField = valueEnum.field(JMod.PRIVATE|JMod.FINAL, String.class, "value");
JMethod ctor = valueEnum.constructor(JMod.PRIVATE);
JVar param = ctor.param(String.class, "val");
ctor.body().assign(valField, param);
JMethod toString = valueEnum.method(JMod.PUBLIC, String.class, "toString");
toString.annotate(Override.class);
toString.body()._return(valField);
for (Option option : options) {
String optionName = option.getValue().toUpperCase().replace(' ', '_');
JEnumConstant optionCst = valueEnum.enumConstant(optionName);
optionCst.arg(JExpr.lit(option.getValue()));
}
return valueEnum;
}
示例7: addEnumConstants
import com.sun.codemodel.JEnumConstant; //导入方法依赖的package包/类
private void addEnumConstants(JsonNode node, JDefinedClass _enum) {
for (Iterator<JsonNode> values = node.elements(); values.hasNext();) {
JsonNode value = values.next();
if (!value.isNull()) {
JEnumConstant constant = _enum.enumConstant(getConstantName(value.asText()));
constant.arg(JExpr.lit(value.asText()));
}
}
}