com.sun.codemodel.JEnumConstant Java Examples
The following examples show how to use
com.sun.codemodel.JEnumConstant.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JaxRsEnumRule.java From apicurio-studio with Apache License 2.0 | 5 votes |
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); String typeName = type.unboxify().fullName(); if(typeName.equals("int")){ // integer constant.arg(JExpr.lit(value.intValue())); } else if(typeName.equals("long")){ // integer-as-long constant.arg(JExpr.lit(value.longValue())); } else if(typeName.equals("double")){ // number constant.arg(JExpr.lit(value.doubleValue())); } else if(typeName.equals("boolean")){ // boolean constant.arg(JExpr.lit(value.booleanValue())); } else { // string, null, array, object? // only string should really be valid here... TODO throw error? constant.arg(JExpr.lit(value.asText())); } ruleFactory.getAnnotator().enumConstant(_enum, constant, value.asText()); } } }
Example #2
Source File: EnumBuilder.java From springmvc-raml-plugin with Apache License 2.0 | 5 votes |
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: {} to {}", name, 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; }
Example #3
Source File: CMEnumConstantOutline.java From jaxb2-basics with BSD 2-Clause "Simplified" License | 5 votes |
public CMEnumConstantOutline(MEnumOutline enumOutline, MEnumConstantInfo<NType, NClass> target, JEnumConstant code) { Validate.notNull(enumOutline); Validate.notNull(target); Validate.notNull(code); this.enumOutline = enumOutline; this.target = target; this.code = code; }
Example #4
Source File: CMEnumConstantOutline.java From jaxb2-basics with BSD 2-Clause "Simplified" License | 4 votes |
public JEnumConstant getCode() { return code; }
Example #5
Source File: MEnumConstantOutline.java From jaxb2-basics with BSD 2-Clause "Simplified" License | votes |
public JEnumConstant getCode();