Example usage for org.apache.commons.lang StringUtils uncapitalize

List of usage examples for org.apache.commons.lang StringUtils uncapitalize

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils uncapitalize.

Prototype

public static String uncapitalize(String str) 

Source Link

Document

Uncapitalizes a String changing the first letter to title case as per Character#toLowerCase(char) .

Usage

From source file:org.gradle.language.base.internal.DefaultBinaryNamingScheme.java

public String getOutputDirectoryBase() {
    StringBuilder builder = new StringBuilder(baseName);
    for (String dimension : dimensions) {
        builder.append('/');
        builder.append(StringUtils.uncapitalize(dimension));
    }/*ww w .j  a  va2  s .com*/
    return builder.toString();
}

From source file:org.gradle.language.base.internal.plugins.CleanRule.java

public void apply(String taskName) {
    if (!taskName.startsWith(CLEAN) || taskName.equals(CLEAN)) {
        return;/*from   ww w.  j a va2  s  .  c o m*/
    }
    String targetTaskName = taskName.substring(CLEAN.length());
    if (Character.isLowerCase(targetTaskName.charAt(0))) {
        return;
    }

    Task task = tasks.findByName(StringUtils.uncapitalize(targetTaskName));
    if (task == null) {
        return;
    }

    Delete clean = tasks.create(taskName, Delete.class);
    clean.delete(task.getOutputs().getFiles());
}

From source file:org.gradle.model.internal.core.ModelReference.java

@Nullable
public static ModelPath findServicePath(ModelType<?> type) {
    Service service = type.getConcreteClass().getAnnotation(Service.class);
    if (service == null) {
        return null;
    }/*  w ww. ja v a 2  s .co  m*/
    String servicePath = service.value();
    if (servicePath == null || servicePath.equals(Service.UNSPECIFIED)) {
        servicePath = StringUtils.uncapitalize(type.getSimpleName());
    }
    return ModelPath.path(servicePath);
}

From source file:org.gradle.model.internal.manage.schema.extract.ImplTypeSchemaExtractionStrategySupport.java

private <R> List<ModelProperty<?>> extractPropertySchemas(ModelSchemaExtractionContext<R> extractionContext,
        Multimap<String, Method> methodsByName) {
    List<ModelProperty<?>> properties = Lists.newArrayList();
    Set<Method> handledMethods = Sets.newHashSet();

    for (String methodName : methodsByName.keySet()) {
        Collection<Method> methods = methodsByName.get(methodName);

        List<Method> overloadedMethods = getOverloadedMethods(methods);
        if (overloadedMethods != null) {
            handleOverloadedMethods(extractionContext, overloadedMethods);
            continue;
        }//from w w  w  . ja v a 2  s.c om

        if (methodName.startsWith("get") && !methodName.equals("get")) {
            PropertyAccessorExtractionContext getterContext = new PropertyAccessorExtractionContext(methods,
                    isGetterDefinedInManagedType(extractionContext, methodName, methods));

            Character getterPropertyNameFirstChar = methodName.charAt(3);
            if (!Character.isUpperCase(getterPropertyNameFirstChar)) {
                handleInvalidGetter(extractionContext, getterContext,
                        "the 4th character of the getter method name must be an uppercase character");
                continue;
            }

            String propertyNameCapitalized = methodName.substring(3);
            String propertyName = StringUtils.uncapitalize(propertyNameCapitalized);
            String setterName = "set" + propertyNameCapitalized;
            Collection<Method> setterMethods = methodsByName.get(setterName);
            PropertyAccessorExtractionContext setterContext = !setterMethods.isEmpty()
                    ? new PropertyAccessorExtractionContext(setterMethods)
                    : null;

            ModelProperty<?> property = extractPropertySchema(extractionContext, propertyName, getterContext,
                    setterContext, handledMethods);
            if (property != null) {
                properties.add(property);

                handledMethods.addAll(getterContext.getDeclaringMethods());
                if (setterContext != null) {
                    handledMethods.addAll(setterContext.getDeclaringMethods());
                }
            }
        }
    }

    validateAllNecessaryMethodsHandled(extractionContext, methodsByName.values(), handledMethods);
    return properties;
}

From source file:org.gradle.model.internal.manage.schema.extract.ManagedImplTypeSchemaExtractionStrategySupport.java

public <R> ModelSchemaExtractionResult<R> extract(final ModelSchemaExtractionContext<R> extractionContext,
        ModelSchemaStore store, final ModelSchemaCache cache) {
    ModelType<R> type = extractionContext.getType();
    Class<? super R> clazz = type.getRawClass();
    if (isTarget(type)) {
        validateType(type, extractionContext);

        Iterable<Method> methods = Arrays.asList(clazz.getMethods());
        if (!clazz.isInterface()) {
            methods = filterIgnoredMethods(methods);
        }//  ww w . j a  va 2s. c  o m
        ImmutableListMultimap<String, Method> methodsByName = Multimaps.index(methods,
                new Function<Method, String>() {
                    public String apply(Method method) {
                        return method.getName();
                    }
                });

        ensureNoOverloadedMethods(extractionContext, methodsByName);

        List<ModelProperty<?>> properties = Lists.newLinkedList();
        List<Method> handled = Lists.newArrayListWithCapacity(clazz.getMethods().length);
        ReturnTypeSpecializationOrdering returnTypeSpecializationOrdering = new ReturnTypeSpecializationOrdering();

        for (String methodName : methodsByName.keySet()) {
            if (methodName.startsWith("get") && !methodName.equals("get")) {
                ImmutableList<Method> getterMethods = methodsByName.get(methodName);

                // The overload check earlier verified that all methods for are equivalent for our purposes
                // So, taking the first one with the most specialized return type is fine.
                Method sampleMethod = returnTypeSpecializationOrdering.max(getterMethods);

                boolean abstractGetter = Modifier.isAbstract(sampleMethod.getModifiers());

                if (sampleMethod.getParameterTypes().length != 0) {
                    throw invalidMethod(extractionContext, "getter methods cannot take parameters",
                            sampleMethod);
                }

                Character getterPropertyNameFirstChar = methodName.charAt(3);
                if (!Character.isUpperCase(getterPropertyNameFirstChar)) {
                    throw invalidMethod(extractionContext,
                            "the 4th character of the getter method name must be an uppercase character",
                            sampleMethod);
                }

                ModelType<?> returnType = ModelType.returnType(sampleMethod);

                String propertyNameCapitalized = methodName.substring(3);
                String propertyName = StringUtils.uncapitalize(propertyNameCapitalized);
                String setterName = "set" + propertyNameCapitalized;
                ImmutableList<Method> setterMethods = methodsByName.get(setterName);

                boolean isWritable = !setterMethods.isEmpty();
                if (isWritable) {
                    Method setter = setterMethods.get(0);

                    if (!abstractGetter) {
                        throw invalidMethod(extractionContext,
                                "setters are not allowed for non-abstract getters", setter);
                    }
                    validateSetter(extractionContext, returnType, setter);
                    handled.addAll(setterMethods);
                }

                if (abstractGetter) {
                    ImmutableSet<ModelType<?>> declaringClasses = ImmutableSet
                            .copyOf(Iterables.transform(getterMethods, new Function<Method, ModelType<?>>() {
                                public ModelType<?> apply(Method input) {
                                    return ModelType.of(input.getDeclaringClass());
                                }
                            }));

                    boolean unmanaged = Iterables.any(getterMethods, new Predicate<Method>() {
                        public boolean apply(Method input) {
                            return input.getAnnotation(Unmanaged.class) != null;
                        }
                    });

                    properties.add(ModelProperty.of(returnType, propertyName, isWritable, declaringClasses,
                            unmanaged));
                }
                handled.addAll(getterMethods);
            }
        }

        Iterable<Method> notHandled = Iterables.filter(methodsByName.values(),
                Predicates.not(Predicates.in(handled)));

        // TODO - should call out valid getters without setters
        if (!Iterables.isEmpty(notHandled)) {
            throw invalidMethods(extractionContext, "only paired getter/setter methods are supported",
                    notHandled);
        }

        Class<R> concreteClass = type.getConcreteClass();
        final ModelSchema<R> schema = createSchema(extractionContext, store, type, properties, concreteClass);
        Iterable<ModelSchemaExtractionContext<?>> propertyDependencies = Iterables.transform(properties,
                new Function<ModelProperty<?>, ModelSchemaExtractionContext<?>>() {
                    public ModelSchemaExtractionContext<?> apply(final ModelProperty<?> property) {
                        return toPropertyExtractionContext(extractionContext, property, cache);
                    }
                });

        return new ModelSchemaExtractionResult<R>(schema, propertyDependencies);
    } else {
        return null;
    }
}

From source file:org.gradle.model.internal.manage.schema.extract.MethodType.java

public String propertyNameFor(Method method) {
    String methodName = method.getName();
    int prefixLength = this == MethodType.IS_GETTER ? 2 : 3;
    String methodNamePrefixRemoved = methodName.substring(prefixLength);
    return StringUtils.uncapitalize(methodNamePrefixRemoved);
}

From source file:org.gradle.model.internal.manage.schema.extract.PropertyAccessorType.java

public String propertyNameFor(String methodName) {
    String methodNamePrefixRemoved = methodName.substring(prefixLength);
    return StringUtils.uncapitalize(methodNamePrefixRemoved);
}

From source file:org.gradle.model.internal.manage.schema.extract.StructSchemaExtractionStrategySupport.java

private <R> List<ModelPropertyExtractionResult<?>> extractPropertySchemas(
        ModelSchemaExtractionContext<R> extractionContext, Multimap<String, Method> methodsByName) {
    List<ModelPropertyExtractionResult<?>> results = Lists.newArrayList();
    Set<Method> handledMethods = Sets.newHashSet();

    List<String> methodNames = Lists.newArrayList(methodsByName.keySet());
    Collections.sort(methodNames);
    Set<String> skippedMethodNames = Sets.newHashSet();
    for (String methodName : methodNames) {
        if (skippedMethodNames.contains(methodName)) {
            continue;
        }/*from w  w w  . j  ava 2  s. c  o  m*/

        Collection<Method> methods = methodsByName.get(methodName);

        List<Method> overloadedMethods = getOverloadedMethods(methods);
        if (overloadedMethods != null) {
            handleOverloadedMethods(extractionContext, overloadedMethods);
            methods = filterGetterMethods(methods);
            if (methods.isEmpty()) {
                continue;
            }
        }

        int getterPrefixLen = getterPrefixLength(methodName);
        if (getterPrefixLen >= 0) {
            Method mostSpecificGetter = ModelSchemaUtils.findMostSpecificMethod(methods);

            char getterPropertyNameFirstChar = methodName.charAt(getterPrefixLen);
            if (!Character.isUpperCase(getterPropertyNameFirstChar)) {
                handleInvalidGetter(extractionContext, mostSpecificGetter,
                        String.format(
                                "the %s character of the getter method name must be an uppercase character",
                                getterPrefixLen == 2 ? "3rd" : "4th"));
                continue;
            }

            String propertyNameCapitalized = methodName.substring(getterPrefixLen);
            String propertyName = StringUtils.uncapitalize(propertyNameCapitalized);
            String setterName = "set" + propertyNameCapitalized;
            Collection<Method> setterMethods = methodsByName.get(setterName);
            PropertyAccessorExtractionContext setterContext = !setterMethods.isEmpty()
                    ? new PropertyAccessorExtractionContext(setterMethods)
                    : null;

            String prefix = methodName.substring(0, getterPrefixLen);
            Iterable<Method> getterMethods = methods;
            if (prefix.equals("get")) {
                String isGetterName = "is" + propertyNameCapitalized;
                Collection<Method> isGetterMethods = methodsByName.get(isGetterName);
                if (!isGetterMethods.isEmpty()) {
                    List<Method> overloadedIsGetterMethods = getOverloadedMethods(isGetterMethods);
                    if (overloadedIsGetterMethods != null) {
                        handleOverloadedMethods(extractionContext, overloadedIsGetterMethods);
                        isGetterMethods = filterGetterMethods(isGetterMethods);
                    }

                    if (!isGetterMethods.isEmpty()) {
                        Method mostSpecificIsGetter = ModelSchemaUtils.findMostSpecificMethod(isGetterMethods);
                        if (mostSpecificGetter.getReturnType() != boolean.class
                                || mostSpecificIsGetter.getReturnType() != boolean.class) {
                            handleInvalidGetter(extractionContext, mostSpecificIsGetter, String.format(
                                    "property '%s' has both '%s()' and '%s()' getters, but they don't both return a boolean",
                                    propertyName, isGetterName, methodName));
                            continue;
                        }
                        getterMethods = Iterables.concat(getterMethods, isGetterMethods);
                        skippedMethodNames.add(isGetterName);
                    }
                }
            }

            PropertyAccessorExtractionContext getterContext = new PropertyAccessorExtractionContext(
                    getterMethods);
            ModelPropertyExtractionResult<?> result = extractPropertySchema(extractionContext, propertyName,
                    getterContext, setterContext, getterPrefixLen);
            if (result != null) {
                results.add(result);
                handledMethods.addAll(getterContext.getDeclaringMethods());
                if (setterContext != null) {
                    handledMethods.addAll(setterContext.getDeclaringMethods());
                }

            }
        }
    }

    validateAllNecessaryMethodsHandled(extractionContext, methodsByName.values(), handledMethods);
    return results;
}

From source file:org.gradle.model.internal.manage.schema.extract.StructStrategy.java

public <R> ModelSchemaExtractionResult<R> extract(final ModelSchemaExtractionContext<R> extractionContext,
        final ModelSchemaCache cache) {
    ModelType<R> type = extractionContext.getType();
    Class<? super R> clazz = type.getRawClass();
    if (clazz.isAnnotationPresent(Managed.class)) {
        validateType(type, extractionContext);

        Iterable<Method> methods = Arrays.asList(clazz.getMethods());
        if (!clazz.isInterface()) {
            methods = filterIgnoredMethods(methods);
        }//from ww  w  .  j a  va2  s.c o  m
        ImmutableListMultimap<String, Method> methodsByName = Multimaps.index(methods,
                new Function<Method, String>() {
                    public String apply(Method method) {
                        return method.getName();
                    }
                });

        ensureNoOverloadedMethods(extractionContext, methodsByName);

        List<ModelProperty<?>> properties = Lists.newLinkedList();
        List<Method> handled = Lists.newArrayListWithCapacity(clazz.getMethods().length);
        ReturnTypeSpecializationOrdering returnTypeSpecializationOrdering = new ReturnTypeSpecializationOrdering();

        for (String methodName : methodsByName.keySet()) {
            if (methodName.startsWith("get") && !methodName.equals("get")) {
                ImmutableList<Method> getterMethods = methodsByName.get(methodName);

                // The overload check earlier verified that all methods for are equivalent for our purposes
                // So, taking the first one with the most specialized return type is fine.
                Method sampleMethod = returnTypeSpecializationOrdering.max(getterMethods);

                boolean abstractGetter = Modifier.isAbstract(sampleMethod.getModifiers());

                if (sampleMethod.getParameterTypes().length != 0) {
                    throw invalidMethod(extractionContext, "getter methods cannot take parameters",
                            sampleMethod);
                }

                Character getterPropertyNameFirstChar = methodName.charAt(3);
                if (!Character.isUpperCase(getterPropertyNameFirstChar)) {
                    throw invalidMethod(extractionContext,
                            "the 4th character of the getter method name must be an uppercase character",
                            sampleMethod);
                }

                ModelType<?> returnType = ModelType.returnType(sampleMethod);

                String propertyNameCapitalized = methodName.substring(3);
                String propertyName = StringUtils.uncapitalize(propertyNameCapitalized);
                String setterName = "set" + propertyNameCapitalized;
                ImmutableList<Method> setterMethods = methodsByName.get(setterName);

                boolean isWritable = !setterMethods.isEmpty();
                if (isWritable) {
                    Method setter = setterMethods.get(0);

                    if (!abstractGetter) {
                        throw invalidMethod(extractionContext,
                                "setters are not allowed for non-abstract getters", setter);
                    }
                    validateSetter(extractionContext, returnType, setter);
                    handled.addAll(setterMethods);
                }

                if (abstractGetter) {
                    ImmutableSet<ModelType<?>> declaringClasses = ImmutableSet
                            .copyOf(Iterables.transform(getterMethods, new Function<Method, ModelType<?>>() {
                                public ModelType<?> apply(Method input) {
                                    return ModelType.of(input.getDeclaringClass());
                                }
                            }));

                    boolean unmanaged = Iterables.any(getterMethods, new Predicate<Method>() {
                        public boolean apply(Method input) {
                            return input.getAnnotation(Unmanaged.class) != null;
                        }
                    });

                    properties.add(ModelProperty.of(returnType, propertyName, isWritable, declaringClasses,
                            unmanaged));
                }
                handled.addAll(getterMethods);
            }
        }

        Iterable<Method> notHandled = Iterables.filter(methodsByName.values(),
                Predicates.not(Predicates.in(handled)));

        // TODO - should call out valid getters without setters
        if (!Iterables.isEmpty(notHandled)) {
            throw invalidMethods(extractionContext, "only paired getter/setter methods are supported",
                    notHandled);
        }

        Class<R> concreteClass = type.getConcreteClass();
        Class<? extends R> implClass = classGenerator.generate(concreteClass);
        final ModelStructSchema<R> schema = ModelSchema.struct(type, properties, implClass);
        extractionContext.addValidator(new Action<ModelSchemaExtractionContext<R>>() {
            @Override
            public void execute(ModelSchemaExtractionContext<R> validatorModelSchemaExtractionContext) {
                ensureCanBeInstantiated(extractionContext, schema);
            }
        });
        Iterable<ModelSchemaExtractionContext<?>> propertyDependencies = Iterables.transform(properties,
                new Function<ModelProperty<?>, ModelSchemaExtractionContext<?>>() {
                    public ModelSchemaExtractionContext<?> apply(final ModelProperty<?> property) {
                        return toPropertyExtractionContext(extractionContext, property, cache);
                    }
                });

        return new ModelSchemaExtractionResult<R>(schema, propertyDependencies);
    } else {
        return null;
    }
}

From source file:org.gradle.model.internal.manage.schema.extraction.ModelSchemaExtractor.java

private <T> ModelProperty<T> extractNonManagedProperty(Class<?> type, Map<String, Method> methods,
        String getterName, ModelType<T> propertyType, List<String> handled) {
    String propertyNameCapitalized = getterName.substring(3);
    String propertyName = StringUtils.uncapitalize(propertyNameCapitalized);
    String setterName = "set" + propertyNameCapitalized;

    if (!methods.containsKey(setterName)) {
        throw invalidMethod(type, getterName, "no corresponding setter for getter");
    }/* w  w w  .  j a va  2 s .  com*/

    validateSetter(type, propertyType, methods.get(setterName));
    handled.add(setterName);
    return new ModelProperty<T>(propertyName, propertyType);
}