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

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

Introduction

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

Prototype

public static String uncapitalize(final String str) 

Source Link

Document

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

Usage

From source file:org.jsweet.input.typescriptdef.visitor.DuplicateMethodsCleaner.java

private void applyDisambiguation(Set<FullFunctionDeclaration> duplicates,
        Map<FullFunctionDeclaration, List<String>> nameMatrix) {
    TypeDeclaration highestTypeDeclaration = getHighestSuperType(duplicates);
    List<FullFunctionDeclaration> l = new ArrayList<FullFunctionDeclaration>(duplicates);
    for (int paramIndex = 0; paramIndex < l.get(0).function.getParameters().length; paramIndex++) {
        final int i = paramIndex;
        for (FullFunctionDeclaration f : l) {
            String newTypeName = nameMatrix.get(f).get(i);
            if (newTypeName == NO_OVERRIDE) {
                continue;
            }/*from   w w  w .j a v a2 s.com*/

            ParameterDeclaration parameter = f.function.getParameters()[i];
            TypeDeclaration newType = null;
            boolean alreadyCreated = false;

            if (newType == null && (newType = highestTypeDeclaration.findType(newTypeName)) != null) {
                alreadyCreated = true;
            }

            boolean functionalDisambiguation = isFunctionalTypeReference(
                    l.get(0).function.getParameters()[i].getType());
            if (functionalDisambiguation) {
                if (f.function.isConstructor()) {
                    if (!alreadyCreated) {
                        boolean hasResult = ((TypeDeclaration) parameter.getType().getDeclaration()).getName()
                                .contains("Function");
                        newType = DeclarationHelper.createFunctionalType(newTypeName,
                                parameter.getType().getTypeArguments().length - (hasResult ? 1 : 0), hasResult,
                                true);
                        newType.addStringAnnotation(JSweetDefTranslatorConfig.ANNOTATION_ERASED);
                        highestTypeDeclaration.addMember(newType);
                        context.registerType(
                                context.getTypeName(highestTypeDeclaration) + "." + newType.getName(), newType);
                    }
                    parameter.setType(new TypeReference(null, newType,
                            DeclarationHelper.copyReferences(parameter.getType().getTypeArguments())));
                } else {
                    if (!f.function.hasStringAnnotation(JSweetDefTranslatorConfig.ANNOTATION_NAME)) {
                        f.function.addStringAnnotation(JSweetDefTranslatorConfig.ANNOTATION_NAME + "(\""
                                + f.function.getName() + "\")");
                        f.function.setName(f.function.getName() + newTypeName);
                    } else {
                        if (!StringUtils.isBlank(newTypeName)) {
                            f.function.setName(StringUtils.uncapitalize(f.function.getName()) + newTypeName);
                        }
                    }
                }
            } else {
                TypeParameterDeclaration[] typeParameters = Util.findTypeParameters(this, parameter);
                if (typeParameters.length == 0) {
                    typeParameters = null;
                }
                if (!alreadyCreated) {
                    FunctionDeclaration newConstructor = new FunctionDeclaration(null, "constructor", null,
                            new ParameterDeclaration[] { parameter.copy() }, null);
                    newType = new TypeDeclaration(null, "class", newTypeName,
                            DeclarationHelper.copy(typeParameters), null, new Declaration[] { newConstructor });
                    newType.setDocumentation(
                            "/** This class was automatically generated for disambiguating erased method signatures. */");
                    if (newType.getTypeParameters() != null) {
                        for (TypeParameterDeclaration t : newType.getTypeParameters()) {
                            t.setUpperBound(null);
                        }
                    }
                    newType.addModifier("static");
                    newType.addStringAnnotation(JSweetDefTranslatorConfig.ANNOTATION_ERASED);
                    highestTypeDeclaration.addMember(newType);
                    context.registerType(context.getTypeName(highestTypeDeclaration) + "." + newType.getName(),
                            newType);
                }
                parameter.setType(
                        new TypeReference(null, newType, DeclarationHelper.toReferences(typeParameters)));
            }

        }
    }
}

From source file:org.kie.workbench.common.forms.integration.tests.modelslookup.GetDataObjectModelsTest.java

private String refactorFields(String oldFieldType, String newFieldType, String fileContent) {
    final String oldFieldName = StringUtils.uncapitalize(oldFieldType);
    final String newFieldName = StringUtils.uncapitalize(newFieldType);
    //replace field types, strings, getters and setters
    String updatedFileContent = replaceAllSurroundedBy(fileContent,
            Arrays.asList(DO_PACKAGE, "\"", "get", "set"), Arrays.asList("", "\"", "(", "("), oldFieldType,
            newFieldType);/*from   w  w w. j  a  v  a2 s.c  om*/
    //replace field declarations, method parameters and inner field references
    updatedFileContent = replaceAllSurroundedBy(updatedFileContent, Arrays.asList(" ", " ", " ", ".", ".", "."),
            Arrays.asList(";", ",", ")", " ", ";", ","), oldFieldName, newFieldName);
    return updatedFileContent;
}

From source file:org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.BaseOryxIdMappings.java

private String getDefaultOryxPropertyId(final Class<?> clazz) {
    return StringUtils.uncapitalize(clazz.getSimpleName());
}

From source file:org.kie.workbench.common.stunner.core.processors.MainProcessor.java

public static String toValidId(final String id) {
    return StringUtils.uncapitalize(id);
}

From source file:org.languagetool.rules.AbstractCompoundRule.java

private Map<String, AnalyzedTokenReadings> getStringToTokenMap(Queue<AnalyzedTokenReadings> prevTokens,
        List<String> stringsToCheck, List<String> origStringsToCheck) {
    StringBuilder sb = new StringBuilder();
    Map<String, AnalyzedTokenReadings> stringToToken = new HashMap<>();
    int j = 0;/*from w  ww. ja  va 2 s.co  m*/
    boolean isFirstSentStart = false;
    for (AnalyzedTokenReadings atr : prevTokens) {
        sb.append(' ');
        sb.append(atr.getToken());
        if (j == 0) {
            isFirstSentStart = atr.hasPosTag(JLanguageTool.SENTENCE_START_TAGNAME);
        }
        if (j >= 1) {
            String stringToCheck = normalize(sb.toString());
            if (sentenceStartsWithUpperCase && isFirstSentStart) {
                stringToCheck = StringUtils.uncapitalize(stringToCheck);
            }
            stringsToCheck.add(stringToCheck);
            origStringsToCheck.add(sb.toString().trim());
            if (!stringToToken.containsKey(stringToCheck)) {
                stringToToken.put(stringToCheck, atr);
            }
        }
        j++;
    }
    return stringToToken;
}

From source file:org.languagetool.rules.AbstractCompoundRule.java

private String mergeCompound(String str, boolean uncapitalizeMidWords) {
    String[] stringParts = str.split(" ");
    StringBuilder sb = new StringBuilder();
    for (int k = 0; k < stringParts.length; k++) {
        if (isHyphenIgnored() || !"-".equals(stringParts[k])) {
            if (k == 0) {
                sb.append(stringParts[0]);
            } else {
                sb.append(uncapitalizeMidWords ? StringUtils.uncapitalize(stringParts[k]) : stringParts[k]);
            }//from   www. j a v  a2 s  . c  o  m
        }
    }
    return sb.toString();
}

From source file:org.languagetool.rules.de.GermanSpellerRule.java

@Override
protected boolean ignoreWord(List<String> words, int idx) throws IOException {
    boolean ignore = super.ignoreWord(words, idx);
    boolean ignoreUncapitalizedWord = !ignore && idx == 0
            && super.ignoreWord(StringUtils.uncapitalize(words.get(0)));
    boolean ignoreByHyphen = false;
    boolean ignoreHyphenatedCompound = false;
    if (!ignore && !ignoreUncapitalizedWord) {
        if (words.get(idx).contains("-")) {
            ignoreByHyphen = words.get(idx).endsWith("-") && ignoreByHangingHyphen(words, idx);
        }/*from   ww  w.  j  av a  2  s  . c  om*/
        ignoreHyphenatedCompound = !ignoreByHyphen && ignoreCompoundWithIgnoredWord(words.get(idx));
    }
    return ignore || ignoreUncapitalizedWord || ignoreByHyphen || ignoreHyphenatedCompound
            || ignoreElative(words.get(0));
}

From source file:org.languagetool.rules.uk.MissingHyphenRule.java

@Override
public RuleMatch[] match(AnalyzedSentence sentence) throws IOException {
    List<RuleMatch> ruleMatches = new ArrayList<>();
    AnalyzedTokenReadings[] tokens = sentence.getTokensWithoutWhitespace();

    for (int i = 1; i < tokens.length - 1; i++) {
        AnalyzedTokenReadings tokenReadings = tokens[i];
        AnalyzedTokenReadings nextTokenReadings = tokens[i + 1];

        boolean isCapitalized = Character.isUpperCase(tokenReadings.getToken().charAt(0));

        if ((isInPrefixes(tokenReadings, isCapitalized)
                || (tokenReadings.getToken().toLowerCase().equals("")
                        && LemmaHelper.hasLemma(tokens[i + 1], "")))
                && PosTagHelper.hasPosTagPart(nextTokenReadings, "noun")
                //          && ! PosTagHelper.hasPosTag(nextTokenReadings, Pattern.compile("^(?!noun).*"))
                && ALL_LOWER.matcher(nextTokenReadings.getToken()).matches()) {

            String hyphenedWord = tokenReadings.getToken() + "-" + nextTokenReadings.getToken();
            String tokenToCheck = isCapitalized ? StringUtils.uncapitalize(hyphenedWord) : hyphenedWord;

            if (wordTagger.tag(tokenToCheck).size() > 0) {
                RuleMatch potentialRuleMatch = new RuleMatch(this, sentence, tokenReadings.getStartPos(),
                        nextTokenReadings.getEndPos(), ",  ??",
                        getDescription());
                potentialRuleMatch.setSuggestedReplacement(hyphenedWord);

                ruleMatches.add(potentialRuleMatch);
            }//from   w  w w  . j  av  a 2s .  com
        }

    }

    return ruleMatches.toArray(new RuleMatch[0]);
}

From source file:org.languagetool.rules.uk.MissingHyphenRule.java

private boolean isInPrefixes(AnalyzedTokenReadings tokenReadings, boolean isCapitalized) {
    String token = tokenReadings.getToken();
    if (isCapitalized) {
        token = StringUtils.uncapitalize(token);
    }//from ww w  .  jav  a  2 s . c  om
    return dashPrefixes.contains(token);
}

From source file:org.libreplan.web.common.components.Autocomplete.java

public void setFinder(String classname) {
    finder = (IFinder) getBean(StringUtils.uncapitalize(classname));
    setModel(finder.getModel());/*from ww w .j  a va 2  s  .  com*/
    setItemRenderer(finder.getItemRenderer());
    bindOnChangeAutocomplete(this);
}