Java 类org.jsonschema2pojo.util.NameHelper 实例源码

项目:springmvc-raml-plugin    文件:NamingHelper.java   
/**
 * Cleans a string with characters that are not valid as a java identifier
 * 
 * @param resourceName The string to clean
 * @return cleaned string
 */
public static String cleanNameForJava(String resourceName) {
    String outString = resourceName;
    if (StringUtils.hasText(resourceName)) {
        outString = getNameHelper().normalizeName(resourceName);
        if (StringUtils.hasText(outString)) {
            outString = outString.replaceAll(NameHelper.ILLEGAL_CHARACTER_REGEX, "");
        }
    }
    return outString;
}
项目:GitHub    文件:ObjectRule.java   
/**
 * Retrieve the list of properties to go in the constructor from node. This
 * is all properties listed in node["properties"] if ! onlyRequired, and
 * only required properties if onlyRequired.
 *
 * @param node
 * @return
 */
private LinkedHashSet<String> getConstructorProperties(JsonNode node, boolean onlyRequired) {

    if (!node.has("properties")) {
        return new LinkedHashSet<String>();
    }

    LinkedHashSet<String> rtn = new LinkedHashSet<String>();
    Set<String> draft4RequiredProperties = new HashSet<String>();

    // setup the set of required properties for draft4 style "required"
    if (onlyRequired && node.has("required")) {
        JsonNode requiredArray =  node.get("required");
        if (requiredArray.isArray()) {
            for (JsonNode requiredEntry: requiredArray) {
                if (requiredEntry.isTextual()) {
                    draft4RequiredProperties.add(requiredEntry.asText());
                }
            }
        }
    }

    NameHelper nameHelper = ruleFactory.getNameHelper();
    for (Iterator<Map.Entry<String, JsonNode>> properties = node.get("properties").fields(); properties.hasNext();) {
        Map.Entry<String, JsonNode> property = properties.next();

        JsonNode propertyObj = property.getValue();
        if (onlyRequired) {
            // draft3 style
            if (propertyObj.has("required") && propertyObj.get("required").asBoolean()) {
                rtn.add(nameHelper.getPropertyName(property.getKey(), property.getValue()));
            }

            // draft4 style
            if (draft4RequiredProperties.contains(property.getKey())) {
                rtn.add(nameHelper.getPropertyName(property.getKey(), property.getValue()));
            }
        } else {
            rtn.add(nameHelper.getPropertyName(property.getKey(), property.getValue()));
        }
    }
    return rtn;
}
项目:GitHub    文件:Jsonschema2Pojo.java   
private static String childQualifiedName(String parentQualifiedName, String childSimpleName) {
    String safeChildName = childSimpleName.replaceAll(NameHelper.ILLEGAL_CHARACTER_REGEX, "_");
    return isEmpty(parentQualifiedName) ? safeChildName : parentQualifiedName + "." + safeChildName;
}
项目:GitHub    文件:RuleFactory.java   
/**
 * Create a new rule factory with the given generation config options.
 *
 * @param generationConfig
 *            The generation config options for type generation. These
 *            config options will influence the java code generated by rules
 *            created by this factory.
 * @param annotator
 *            the annotator used to mark up Java types with any annotations
 *            that are required to build JSON compatible types
 * @param schemaStore
 *            the object used by this factory to get and store schemas
 */
public RuleFactory(GenerationConfig generationConfig, Annotator annotator, SchemaStore schemaStore) {
    this.generationConfig = generationConfig;
    this.annotator = annotator;
    this.schemaStore = schemaStore;
    this.nameHelper = new NameHelper(generationConfig);
}
项目:GitHub    文件:RuleFactory.java   
/**
 * The generation config options for type generation. These config options
 * will influence the java code generated by rules created by this factory.
 *
 * @param generationConfig
 *            Generation config
 */
public void setGenerationConfig(final GenerationConfig generationConfig) {
    this.generationConfig = generationConfig;
    this.nameHelper = new NameHelper(generationConfig);
}
项目:GitHub    文件:RuleFactory.java   
/**
 * Gets the name helper that is used to generate normalized Class and field
 * names.
 *
 * @return a name helper instance that can be used to normalize Class and
 *         field names.
 */
public NameHelper getNameHelper() {
    return nameHelper;
}