本文整理汇总了Java中com.sun.codemodel.JEnumConstant.annotate方法的典型用法代码示例。如果您正苦于以下问题:Java JEnumConstant.annotate方法的具体用法?Java JEnumConstant.annotate怎么用?Java JEnumConstant.annotate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.codemodel.JEnumConstant
的用法示例。
在下文中一共展示了JEnumConstant.annotate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: enumConstant
import com.sun.codemodel.JEnumConstant; //导入方法依赖的package包/类
@Override
public void enumConstant(JEnumConstant constant, String value) {
constant.annotate(Deprecated.class);
}
示例2: generateEnum
import com.sun.codemodel.JEnumConstant; //导入方法依赖的package包/类
/**
* Generates an enum for a given field
*
* @param f
* @param name
* of enum in UpperCamelCase
* @return
* @throws JClassAlreadyExistsException
*/
public JDefinedClass generateEnum(ApplicationField f, String name) throws JClassAlreadyExistsException {
JDefinedClass result = jp != null ? jp._enum(name) : jc._package("")._enum(name);
result._implements(PodioCategory.class);
// fields:
JFieldVar podioId = result.field(JMod.PRIVATE, jc.INT, "podioId");
JFieldVar value = result.field(JMod.PRIVATE, jc.ref(String.class), "value");
// constructor:
JMethod constructor = result.constructor(JMod.PRIVATE);
JVar constructorPodioIdParam = constructor.param(jc.INT, "podioId");
JVar constructorToStringParam = constructor.param(jc.ref(String.class), "value");
constructor.body().assign(JExpr._this().ref(podioId), constructorPodioIdParam);
constructor.body().assign(JExpr._this().ref(value), constructorToStringParam);
// toString:
result.method(JMod.PUBLIC, String.class, "toString").body()._return(value);
// getId:
result.method(JMod.PUBLIC, jc.INT, "getPodioId").body()._return(podioId);
// static byId:
JMethod byId = result.method(JMod.PUBLIC | JMod.STATIC, result, "byId");
byId.javadoc().addReturn().add("{@code null}, if no element with given {@code id} exists.");
JVar byIdParam = byId.param(jc.INT, "podioId");
JForEach forEach = byId.body().forEach(result, "e", result.staticInvoke("values"));
forEach.body()._if(byIdParam.eq(forEach.var().invoke("getPodioId")))._then()._return(forEach.var());
byId.body()._return(JExpr._null());
// literals:
result.enumConstant("NONE").arg(JExpr.lit(0)).arg(JExpr.lit("--"));
for (CategoryOption option : f.getConfiguration().getSettings().getOptions()) {
String constantName = JavaNames.createValidJavaTypeName(option.getText(), name);
String finalConstantName = CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE,
constantName);
JEnumConstant constant = result.enumConstant(finalConstantName);
constant.arg(JExpr.lit(option.getId())).arg(JExpr.lit(option.getText()));
if (option.getStatus().equals(CategoryOptionStatus.DELETED)) {
constant.annotate(Deprecated.class);
}
}
return result;
}