Example usage for com.google.common.base CaseFormat LOWER_CAMEL

List of usage examples for com.google.common.base CaseFormat LOWER_CAMEL

Introduction

In this page you can find the example usage for com.google.common.base CaseFormat LOWER_CAMEL.

Prototype

CaseFormat LOWER_CAMEL

To view the source code for com.google.common.base CaseFormat LOWER_CAMEL.

Click Source Link

Document

Java variable naming convention, e.g., "lowerCamel".

Usage

From source file:org.apache.brooklyn.util.javalang.Enums.java

/** attempts to match the givenValue against the given enum values, first looking for exact matches (against name and toString),
 * then matching ignoring case, /*  w w  w. ja  va  2  s . c  o  m*/
 * then matching with {@link CaseFormat#UPPER_UNDERSCORE} converted to {@link CaseFormat#LOWER_CAMEL},
 * then matching with {@link CaseFormat#LOWER_CAMEL} converted to {@link CaseFormat#UPPER_UNDERSCORE}
 * (including case insensitive matches for the final two)
 **/
public static <T extends Enum<?>> Maybe<T> valueOfIgnoreCase(String contextMessage, T[] enumValues,
        String givenValue) {
    if (givenValue == null)
        return Maybe.absent(new IllegalStateException("Value for " + contextMessage + " must not be null"));
    if (Strings.isBlank(givenValue))
        return Maybe.absent(new IllegalStateException("Value for " + contextMessage + " must not be blank"));

    for (T v : enumValues)
        if (v.name().equals(givenValue))
            return Maybe.of(v);
    for (T v : enumValues)
        if (v.toString().equals(givenValue))
            return Maybe.of(v);
    for (T v : enumValues)
        if (v.name().equalsIgnoreCase(givenValue))
            return Maybe.of(v);
    for (T v : enumValues)
        if (v.toString().equalsIgnoreCase(givenValue))
            return Maybe.of(v);
    for (T v : enumValues)
        if (CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, v.name()).equals(givenValue))
            return Maybe.of(v);
    for (T v : enumValues)
        if (CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, v.toString()).equals(givenValue))
            return Maybe.of(v);
    for (T v : enumValues)
        if (CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, v.name()).equalsIgnoreCase(givenValue))
            return Maybe.of(v);
    for (T v : enumValues)
        if (CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, v.toString()).equalsIgnoreCase(givenValue))
            return Maybe.of(v);
    for (T v : enumValues)
        if (CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, v.toString()).equalsIgnoreCase(givenValue))
            return Maybe.of(v);
    for (T v : enumValues)
        if (CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, v.name()).equals(givenValue))
            return Maybe.of(v);
    for (T v : enumValues)
        if (CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, v.toString()).equals(givenValue))
            return Maybe.of(v);
    for (T v : enumValues)
        if (CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, v.name()).equalsIgnoreCase(givenValue))
            return Maybe.of(v);

    return Maybe.absent(new IllegalStateException("Invalid value " + givenValue + " for " + contextMessage));
}

From source file:org.dbunitng.beans.BeanMetaData.java

/**
 * ?//ww w .  j av  a2s.  c o  m
 * 
 * @param name
 *            ??
 * @param getter
 *            Getter
 */
protected void addPropertyWithGetter(String name, Method getter) {
    String lowerName = name.toLowerCase();
    BeanProperty property = propertyMap.get(lowerName);
    Class<?> type = getter.getReturnType();
    if (property == null) {
        property = new BeanProperty(name, type, null, getter, null);
        propertyMap.put(CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, name), property);
    } else {
        property.setGetter(getter);
    }
}

From source file:com.google.template.soy.pysrc.internal.GeneratePySanitizeEscapingDirectiveCode.java

@Override
protected void useExistingLibraryFunction(StringBuilder outputCode, String identifier,
        String existingFunction) {
    String fnName = CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, identifier);
    outputCode.append("\ndef ").append(fnName).append("_helper(v):\n").append("  return ")
            .append(existingFunction).append("(str(v))\n").append("\n");
}

From source file:org.robotframework.ide.eclipse.main.plugin.assist.RedSettingProposals.java

private String toCanonicalName(final String settingName) {
    switch (target) {
    case GENERAL:
        final Iterable<String> upperCased = transform(Splitter.on(' ').split(settingName),
                new Function<String, String>() {

                    @Override//  www .jav  a  2  s . c o m
                    public String apply(final String elem) {
                        return CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_CAMEL, elem);
                    }
                });
        return Joiner.on(' ').join(upperCased);
    case TEST_CASE:
    case KEYWORD:
        final char firstLetter = settingName.charAt(1);
        return settingName.replaceAll("\\[" + firstLetter, "[" + Character.toUpperCase(firstLetter));
    default:
        throw new IllegalStateException("Unknown target value: " + target);
    }
}

From source file:com.ning.billing.util.dao.LowerToCamelBeanMapper.java

public T map(final int row, final ResultSet rs, final StatementContext ctx) throws SQLException {
    final T bean;
    try {/*from   www .j  a  v a 2 s .  c om*/
        bean = type.newInstance();
    } catch (Exception e) {
        throw new IllegalArgumentException(
                String.format("A bean, %s, was mapped " + "which was not instantiable", type.getName()), e);
    }

    final Class beanClass = bean.getClass();
    final ResultSetMetaData metadata = rs.getMetaData();

    for (int i = 1; i <= metadata.getColumnCount(); ++i) {
        final String name = metadata.getColumnLabel(i).toLowerCase();

        final PropertyDescriptor descriptor = properties.get(name);

        if (descriptor != null) {
            final Class<?> type = descriptor.getPropertyType();

            Object value;

            if (type.isAssignableFrom(Boolean.class) || type.isAssignableFrom(boolean.class)) {
                value = rs.getBoolean(i);
            } else if (type.isAssignableFrom(Byte.class) || type.isAssignableFrom(byte.class)) {
                value = rs.getByte(i);
            } else if (type.isAssignableFrom(Short.class) || type.isAssignableFrom(short.class)) {
                value = rs.getShort(i);
            } else if (type.isAssignableFrom(Integer.class) || type.isAssignableFrom(int.class)) {
                value = rs.getInt(i);
            } else if (type.isAssignableFrom(Long.class) || type.isAssignableFrom(long.class)) {
                value = rs.getLong(i);
            } else if (type.isAssignableFrom(Float.class) || type.isAssignableFrom(float.class)) {
                value = rs.getFloat(i);
            } else if (type.isAssignableFrom(Double.class) || type.isAssignableFrom(double.class)) {
                value = rs.getDouble(i);
            } else if (type.isAssignableFrom(BigDecimal.class)) {
                value = rs.getBigDecimal(i);
            } else if (type.isAssignableFrom(DateTime.class)) {
                final Timestamp timestamp = rs.getTimestamp(i);
                value = timestamp == null ? null : new DateTime(timestamp).toDateTime(DateTimeZone.UTC);
            } else if (type.isAssignableFrom(Time.class)) {
                value = rs.getTime(i);
            } else if (type.isAssignableFrom(LocalDate.class)) {
                final Date date = rs.getDate(i);
                value = date == null ? null : new LocalDate(date, DateTimeZone.UTC);
            } else if (type.isAssignableFrom(DateTimeZone.class)) {
                final String dateTimeZoneString = rs.getString(i);
                value = dateTimeZoneString == null ? null : DateTimeZone.forID(dateTimeZoneString);
            } else if (type.isAssignableFrom(String.class)) {
                value = rs.getString(i);
            } else if (type.isAssignableFrom(UUID.class)) {
                final String uuidString = rs.getString(i);
                value = uuidString == null ? null : UUID.fromString(uuidString);
            } else if (type.isEnum()) {
                final String enumString = rs.getString(i);
                //noinspection unchecked
                value = enumString == null ? null : Enum.valueOf((Class<Enum>) type, enumString);
            } else {
                value = rs.getObject(i);
            }

            if (rs.wasNull() && !type.isPrimitive()) {
                value = null;
            }

            try {
                final Method writeMethod = descriptor.getWriteMethod();
                if (writeMethod != null) {
                    writeMethod.invoke(bean, value);
                } else {
                    final String camelCasedName = CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, name);
                    final Field field = getField(beanClass, camelCasedName);
                    field.setAccessible(true); // Often private...
                    field.set(bean, value);
                }
            } catch (NoSuchFieldException e) {
                throw new IllegalArgumentException(
                        String.format("Unable to find field for " + "property, %s", name), e);
            } catch (IllegalAccessException e) {
                throw new IllegalArgumentException(
                        String.format("Unable to access setter for " + "property, %s", name), e);
            } catch (InvocationTargetException e) {
                throw new IllegalArgumentException(String.format(
                        "Invocation target exception trying to " + "invoker setter for the %s property", name),
                        e);
            } catch (NullPointerException e) {
                throw new IllegalArgumentException(
                        String.format("No appropriate method to " + "write value %s ", value.toString()), e);
            }
        }
    }

    return bean;
}

From source file:org.dllearner.cli.DocumentationGenerator.java

private String getComponentConfigString(Class<?> component, Class<?> category) {
    // heading + anchor
    StringBuilder sb = new StringBuilder();
    String klass = component.getName();

    String header = "component: " + klass;
    String description = "";
    String catString = "component";
    String usage = null;//w  w w.  jav a2 s.  co m

    // some information about the component
    if (Component.class.isAssignableFrom(component)) {
        Class<? extends Component> ccomp = (Class<? extends Component>) component;
        header = "component: " + AnnComponentManager.getName(ccomp) + " (" + klass + ") v"
                + AnnComponentManager.getVersion(ccomp);
        description = AnnComponentManager.getDescription(ccomp);
        catString = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, category.getSimpleName());
        ComponentAnn catAnn = category.getAnnotation(ComponentAnn.class);
        if (catAnn != null) {
            catString = catAnn.shortName();
        }

        for (Entry<Class, String> entry : varNameMapping.entrySet()) {
            Class cls = entry.getKey();
            if (cls.isAssignableFrom(component)) {
                catString = entry.getValue();
            }
        }

        usage = "conf file usage: " + catString + ".type = \"" + AnnComponentManager.getShortName(ccomp)
                + "\"\n";

    } else {
        ComponentAnn ann = component.getAnnotation(ComponentAnn.class);
        if (ann != null) {
            header = "component: " + ann.name() + " (" + klass + ") v" + ann.version();
        }
        description = ann.description();
        if (component.equals(GlobalDoc.class)) {
            catString = "";
            usage = "";
        } else {
            catString = "cli";

            usage = "conf file usage: " + catString + ".type = \"" + klass + "\"\n";
        }
    }
    header += "\n" + Strings.repeat("=", header.length()) + "\n";
    sb.append(header);
    if (description.length() > 0) {
        sb.append(description + "\n");
    }
    sb.append("\n");
    sb.append(usage + "\n");
    optionsTable(sb, component, catString);
    return sb.toString();
}

From source file:com.facebook.buck.skylark.parser.RuleFunctionFactory.java

/**
 * Populates provided {@code builder} with values from {@code kwargs} assuming {@code ruleClass}
 * as the target {@link BaseDescription} class.
 *
 * @param kwargs The keyword arguments and their values passed to rule function in build file.
 * @param builder The map builder used for storing extracted attributes and their values.
 * @param allParamInfo The parameter information for every build rule attribute.
 *///w w w. ja v  a 2s. c  om
private void populateAttributes(Map<String, Object> kwargs, ImmutableMap.Builder<String, Object> builder,
        ImmutableMap<String, ParamInfo> allParamInfo) {
    for (Map.Entry<String, Object> kwargEntry : kwargs.entrySet()) {
        String paramName = CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, kwargEntry.getKey());
        if (!allParamInfo.containsKey(paramName) && !(IMPLICIT_ATTRIBUTES.contains(kwargEntry.getKey()))) {
            throw new IllegalArgumentException(kwargEntry.getKey() + " is not a recognized attribute");
        }
        if (Runtime.NONE.equals(kwargEntry.getValue())) {
            continue;
        }
        builder.put(paramName, kwargEntry.getValue());
    }
}

From source file:fr.zcraft.zlib.components.rawtext.RawTextPart.java

private String enumCamel(Enum enumValue) {
    return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, enumValue.toString());
}

From source file:com.phoenixnap.oss.ramlapisync.generation.rules.spring.SpringRestClientMethodBodyRule.java

@Override
public JMethod apply(ApiMappingMetadata endpointMetadata, CodeModelHelper.JExtMethod generatableType) {
    JBlock body = generatableType.get().body();
    JCodeModel owner = generatableType.owner();
    //build HttpHeaders   
    JClass httpHeadersClass = owner.ref(HttpHeaders.class);
    JExpression headersInit = JExpr._new(httpHeadersClass);
    JVar httpHeaders = body.decl(httpHeadersClass, "httpHeaders", headersInit);

    //Declare Arraylist to contain the acceptable Media Types
    body.directStatement("//  Add Accepts Headers and Body Content-Type");
    JClass mediaTypeClass = owner.ref(MediaType.class);
    JClass refArrayListClass = owner.ref(ArrayList.class).narrow(mediaTypeClass);
    JVar acceptsListVar = body.decl(refArrayListClass, "acceptsList", JExpr._new(refArrayListClass));

    //If we have a request body, lets set the content type of our request
    if (endpointMetadata.getRequestBody() != null) {
        body.invoke(httpHeaders, "setContentType")
                .arg(mediaTypeClass.staticInvoke("valueOf").arg(endpointMetadata.getRequestBodyMime()));
    }//from ww  w  . jav a2  s. c o  m

    //If we have response bodies defined, we need to add them to our accepts headers list
    //TODO possibly restrict
    String documentDefaultType = endpointMetadata.getParent().getDocument().getMediaType();
    //If a global mediatype is defined add it
    if (StringUtils.hasText(documentDefaultType)) {
        body.invoke(acceptsListVar, "add").arg(mediaTypeClass.staticInvoke("valueOf").arg(documentDefaultType));
    } else { //default to application/json just in case
        body.invoke(acceptsListVar, "add").arg(mediaTypeClass.staticInvoke("valueOf").arg("application/json"));
    }

    //Iterate over Response Bodies and add each distinct mime type to accepts headers
    if (endpointMetadata.getResponseBody() != null && !endpointMetadata.getResponseBody().isEmpty()) {
        for (String responseMime : endpointMetadata.getResponseBody().keySet()) {
            if (!responseMime.equals(documentDefaultType) && !responseMime.equals("application/json")) {
                body.invoke(acceptsListVar, "add")
                        .arg(mediaTypeClass.staticInvoke("valueOf").arg(responseMime));
            }
        }
    }

    //Set accepts list as our accepts headers for the call
    body.invoke(httpHeaders, "setAccept").arg(acceptsListVar);

    //Get the parameters from the model and put them in a map for easy lookup
    List<JVar> params = generatableType.get().params();
    Map<String, JVar> methodParamMap = new LinkedHashMap<>();
    for (JVar param : params) {
        methodParamMap.put(param.name(), param);
    }

    //Build the Http Entity object
    JClass httpEntityClass = owner.ref(HttpEntity.class);
    JInvocation init = JExpr._new(httpEntityClass);

    if (endpointMetadata.getRequestBody() != null) {
        init.arg(methodParamMap.get(CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL,
                endpointMetadata.getRequestBody().getName())));
    }
    init.arg(httpHeaders);

    //Build the URL variable                
    JExpression urlRef = JExpr.ref(baseUrlFieldName);
    JType urlClass = owner._ref(String.class);
    JExpression targetUrl = urlRef.invoke("concat").arg(endpointMetadata.getResource().getUri());
    JVar url = body.decl(urlClass, "url", targetUrl);
    JVar uriBuilderVar = null;
    JVar uriComponentVar = null;

    //Initialise the UriComponentsBuilder
    JClass builderClass = owner.ref(UriComponentsBuilder.class);
    JExpression builderInit = builderClass.staticInvoke("fromHttpUrl").arg(url);

    //If we have any Query Parameters, we will use the URIBuilder to encode them in the URL
    if (!CollectionUtils.isEmpty(endpointMetadata.getRequestParameters())) {
        //iterate over the parameters and add calls to .queryParam
        for (ApiParameterMetadata parameter : endpointMetadata.getRequestParameters()) {
            builderInit = builderInit.invoke("queryParam").arg(parameter.getName())
                    .arg(methodParamMap.get(parameter.getName()));
        }
    }
    //Add these to the code model
    uriBuilderVar = body.decl(builderClass, "builder", builderInit);

    JClass componentClass = owner.ref(UriComponents.class);
    JExpression component = uriBuilderVar.invoke("build");
    uriComponentVar = body.decl(componentClass, "uriComponents", component);

    //build request entity holder                
    JVar httpEntityVar = body.decl(httpEntityClass, "httpEntity", init);

    //construct the HTTP Method enum 
    JClass httpMethod = null;
    try {
        httpMethod = (JClass) owner._ref(HttpMethod.class);
    } catch (ClassCastException e) {

    }

    //get all uri params from metadata set and add them to the param map in code 
    if (!CollectionUtils.isEmpty(endpointMetadata.getPathVariables())) {
        //Create Map with Uri Path Variables
        JClass uriParamMap = owner.ref(Map.class).narrow(String.class, Object.class);
        JExpression uriParamMapInit = JExpr._new(owner.ref(HashMap.class));
        JVar uriParamMapVar = body.decl(uriParamMap, "uriParamMap", uriParamMapInit);

        endpointMetadata.getPathVariables().forEach(
                p -> body.invoke(uriParamMapVar, "put").arg(p.getName()).arg(methodParamMap.get(p.getName())));
        JInvocation expandInvocation = uriComponentVar.invoke("expand").arg(uriParamMapVar);

        body.assign(uriComponentVar, expandInvocation);
    }

    //Determining response entity type 
    JClass returnType = null;
    if (!endpointMetadata.getResponseBody().isEmpty()) {
        ApiBodyMetadata apiBodyMetadata = endpointMetadata.getResponseBody().values().iterator().next();
        JClass genericType = findFirstClassBySimpleName(apiBodyMetadata.getCodeModel(),
                apiBodyMetadata.getName());
        if (apiBodyMetadata.isArray()) {
            JClass arrayType = owner.ref(List.class);
            returnType = arrayType.narrow(genericType);
        } else {
            returnType = genericType;
        }
    } else {
        returnType = owner.ref(Object.class);
    }

    JExpression returnExpression = JExpr.dotclass(returnType);//assume not parameterized by default
    //check if return is parameterized
    if (!CollectionUtils.isEmpty(returnType.getTypeParameters())) {
        //if yes - build the parameterized type reference and change returnExpression
        //ParameterizedTypeReference<List<String>> typeRef = new ParameterizedTypeReference<List<String>>() {};
        //Create Map with Uri Path Variables
        JClass paramTypeRefClass = owner.ref(ParameterizedTypeReference.class);
        paramTypeRefClass = paramTypeRefClass.narrow(returnType);

        JExpression paramTypeRefInit = JExpr._new(owner.anonymousClass(paramTypeRefClass));
        returnExpression = body.decl(paramTypeRefClass, "typeReference", paramTypeRefInit);
    }

    //build rest template exchange invocation
    JInvocation jInvocation = JExpr._this().ref(restTemplateFieldName).invoke("exchange");

    jInvocation.arg(uriComponentVar.invoke("encode").invoke("toUri"));
    jInvocation.arg(httpMethod.staticRef(endpointMetadata.getActionType().name()));
    jInvocation.arg(httpEntityVar);
    jInvocation.arg(returnExpression);

    body._return(jInvocation);

    return generatableType.get();
}

From source file:org.ballerinalang.composer.tools.ModelGenerator.java

public static JsonObject getContext() {

    // Set alias for the classes
    alias.put("ImportNode", "ImportPackageNode");
    alias.put("ArrayLiteralExprNode", "ArrayLiteralNode");
    alias.put("BinaryExprNode", "BinaryExpressionNode");
    alias.put("BracedTupleExprNode", "BracedOrTupleExpression");
    alias.put("TypeInitExprNode", "TypeInitNode");
    alias.put("FieldBasedAccessExprNode", "FieldBasedAccessNode");
    alias.put("IndexBasedAccessExprNode", "IndexBasedAccessNode");
    alias.put("IntRangeExprNode", "IntRangeExpression");
    alias.put("LambdaNode", "LambdaFunctionNode");
    alias.put("SimpleVariableRefNode", "SimpleVariableReferenceNode");
    alias.put("TernaryExprNode", "TernaryExpressionNode");
    alias.put("AwaitExprNode", "AwaitExpressionNode");
    alias.put("TypeCastExprNode", "TypeCastNode");
    alias.put("TypeConversionExprNode", "TypeConversionNode");
    alias.put("UnaryExprNode", "UnaryExpressionNode");
    alias.put("RestArgsExprNode", "RestArgsNode");
    alias.put("NamedArgsExprNode", "NamedArgNode");
    alias.put("MatchExpressionPatternClauseNode", "MatchExpressionNode");
    alias.put("MatchPatternClauseNode", "MatchStatementPatternNode");
    alias.put("TryNode", "TryCatchFinallyNode");
    alias.put("VariableDefNode", "VariableDefinitionNode");
    alias.put("UnionTypeNodeNode", "UnionTypeNode");
    alias.put("TupleTypeNodeNode", "TupleTypeNode");
    alias.put("EndpointTypeNode", "UserDefinedTypeNode");
    alias.put("StreamingQueryNode", "StreamingQueryStatementNode");
    alias.put("WithinNode", "WithinClause");
    alias.put("PatternClauseNode", "PatternClause");
    alias.put("ElvisExprNode", "ElvisExpressionNode");
    alias.put("CheckExprNode", "CheckedExpressionNode");
    alias.put("RecordLiteralExprNode", "RecordLiteralNode");
    alias.put("TypeDefinitionNode", "TypeDefinition");

    alias.put("EnumeratorNode", "");
    alias.put("RecordLiteralKeyValueNode", "");
    alias.put("TableNode", "");
    alias.put("XmlnsNode", "");
    alias.put("IsAssignableExprNode", "");
    alias.put("XmlQnameNode", "");
    alias.put("XmlAttributeNode", "");
    alias.put("XmlAttributeAccessExprNode", "");
    alias.put("XmlQuotedStringNode", "");
    alias.put("XmlElementLiteralNode", "");
    alias.put("XmlTextLiteralNode", "");
    alias.put("XmlCommentLiteralNode", "");
    alias.put("XmlPiLiteralNode", "");
    alias.put("XmlSequenceLiteralNode", "");
    alias.put("TableQueryExpressionNode", "");
    alias.put("NextNode", "");
    alias.put("TransformNode", "");
    alias.put("StreamNode", "");
    alias.put("FiniteTypeNodeNode", "");
    alias.put("BuiltInRefTypeNode", "");
    alias.put("StreamingInputNode", "");
    alias.put("JoinStreamingInputNode", "");
    alias.put("TableQueryNode", "");
    alias.put("SetAssignmentClauseNode", "");
    alias.put("SetNode", "");
    alias.put("QueryNode", "");
    alias.put("StreamingQueryDeclarationNode", "");

    List<Class<?>> list = ModelGenerator.find("org.ballerinalang.model.tree");

    NodeKind[] nodeKinds = NodeKind.class.getEnumConstants();
    JsonObject nodes = new JsonObject();
    for (NodeKind node : nodeKinds) {
        String nodeKind = CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, node.toString());
        String nodeClassName = nodeKind + "Node";
        try {/*  ww w  .j  av a2 s .  c o  m*/
            String actualClassName = (alias.get(nodeClassName) != null) ? alias.get(nodeClassName)
                    : nodeClassName;
            Class<?> clazz = list.stream()
                    .filter(nodeClass -> nodeClass.getSimpleName().equals(actualClassName)).findFirst().get();

            JsonObject nodeObj = new JsonObject();
            nodeObj.addProperty("kind", nodeKind);
            nodeObj.addProperty("name", nodeClassName);
            nodeObj.addProperty("fileName", CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_HYPHEN, nodeClassName));
            JsonArray attr = new JsonArray();
            JsonArray bools = new JsonArray();
            JsonArray imports = new JsonArray();
            List<String> parents = Arrays.asList(clazz.getInterfaces()).stream()
                    .map(parent -> parent.getSimpleName()).collect(Collectors.toList());

            // tag object with supper type
            if (parents.contains("StatementNode")) {
                nodeObj.addProperty("isStatement", true);
                JsonObject imp = new JsonObject();
                imp.addProperty("returnType", "StatementNode");
                imp.addProperty("returnTypeFile", "statement-node");
                imports.add(imp);
            } else {
                nodeObj.addProperty("isStatement", false);
            }

            if (parents.contains("ExpressionNode")) {
                nodeObj.addProperty("isExpression", true);
                JsonObject imp = new JsonObject();
                imp.addProperty("returnType", "ExpressionNode");
                imp.addProperty("returnTypeFile", "expression-node");
                imports.add(imp);
            } else {
                nodeObj.addProperty("isExpression", false);
            }

            if (!parents.contains("StatementNode") && !parents.contains("ExpressionNode")) {
                JsonObject imp = new JsonObject();
                imp.addProperty("returnType", "Node");
                imp.addProperty("returnTypeFile", "node");
                imports.add(imp);
            }

            Method[] methods = clazz.getMethods();
            for (Method m : methods) {
                String methodName = m.getName();
                if ("getKind".equals(methodName) || "getWS".equals(methodName)
                        || "getPosition".equals(methodName)) {
                    continue;
                }
                if (methodName.startsWith("get")) {
                    JsonObject attribute = new JsonObject();
                    JsonObject imp = new JsonObject();
                    attribute.addProperty("property", toJsonName(m.getName(), 3));
                    attribute.addProperty("methodSuffix", m.getName().substring(3));
                    attribute.addProperty("list", List.class.isAssignableFrom(m.getReturnType()));
                    attribute.addProperty("isNode", Node.class.isAssignableFrom(m.getReturnType()));
                    if (Node.class.isAssignableFrom(m.getReturnType())) {
                        String returnClass = m.getReturnType().getSimpleName();
                        if (alias.containsValue(m.getReturnType().getSimpleName())) {
                            returnClass = getKindForAliasClass(m.getReturnType().getSimpleName());
                        }
                        imp.addProperty("returnType", returnClass);
                        attribute.addProperty("returnType", returnClass);
                        imp.addProperty("returnTypeFile",
                                CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_HYPHEN, returnClass));
                        if (!imports.contains(imp)) {
                            imports.add(imp);
                        }
                    }
                    attr.add(attribute);
                }
                if (methodName.startsWith("is")) {
                    JsonObject attribute = new JsonObject();
                    JsonObject imp = new JsonObject();
                    attribute.addProperty("property", toJsonName(m.getName(), 2));
                    attribute.addProperty("methodSuffix", m.getName().substring(2));
                    attribute.addProperty("list", List.class.isAssignableFrom(m.getReturnType()));
                    attribute.addProperty("isNode", Node.class.isAssignableFrom(m.getReturnType()));
                    if (Node.class.isAssignableFrom(m.getReturnType())) {
                        String returnClass = m.getReturnType().getSimpleName();
                        if (alias.containsValue(m.getReturnType().getSimpleName())) {
                            returnClass = getKindForAliasClass(m.getReturnType().getSimpleName());
                        }
                        imp.addProperty("returnType", returnClass);
                        attribute.addProperty("returnType", returnClass);
                        imp.addProperty("returnTypeFile",
                                CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_HYPHEN, returnClass));
                        if (!imports.contains(imp)) {
                            imports.add(imp);
                        }
                    }
                    bools.add(attribute);
                }
            }
            nodeObj.add("attributes", attr);
            nodeObj.add("bools", bools);
            nodeObj.add("imports", imports);
            nodes.add(nodeClassName, nodeObj);
        } catch (NoSuchElementException e) {
            out.println("alias.put(\"" + nodeClassName + "\", \"\");");
        }
    }
    out.println(nodes);
    return nodes;
}