Java Code Examples for com.intellij.psi.codeStyle.NameUtil#splitNameIntoWords()

The following examples show how to use com.intellij.psi.codeStyle.NameUtil#splitNameIntoWords() . 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: TestFinderHelper.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static List<Pair<String, Integer>> collectPossibleClassNamesWithWeights(String testName) {
  String[] words = NameUtil.splitNameIntoWords(testName);
  List<Pair<String, Integer>> result = new ArrayList<Pair<String, Integer>>();

  for (int from = 0; from < words.length; from++) {
    for (int to = from; to < words.length; to++) {
      result.add(new Pair<String, Integer>(StringUtil.join(words, from, to + 1, ""),
                                           words.length - from + to));
    }
  }

  return result;
}
 
Example 2
Source File: NameSuggester.java    From consulo with Apache License 2.0 5 votes vote down vote up
public NameSuggester(String oldClassName, String newClassName) {
  myOldClassNameAsGiven = oldClassName;
  myNewClassNameAsGiven = newClassName;
  myOldClassName = NameUtil.splitNameIntoWords(oldClassName);
  myNewClassName = NameUtil.splitNameIntoWords(newClassName);

  myChanges = new ArrayList<OriginalToNewChange>();
  int oldIndex = myOldClassName.length - 1;
  int oldLastMatch = myOldClassName.length;
  int newLastMatch = myNewClassName.length;

  while(oldIndex >= 0) {
    final String patternWord = myOldClassName[oldIndex];
    final int matchingWordIndex = findInNewBackwardsFromIndex(patternWord, newLastMatch - 1);
    if (matchingWordIndex < 0) { // no matching word
      oldIndex--;
    }
    else { // matching word found
      if (oldIndex + 1 <= oldLastMatch - 1 || matchingWordIndex + 1 <= newLastMatch - 1) {
        final OriginalToNewChange change = new OriginalToNewChange(
          oldIndex + 1, oldLastMatch - 1, matchingWordIndex + 1, newLastMatch - 1);
        myChanges.add(change);
      }
      oldLastMatch = oldIndex;
      newLastMatch = matchingWordIndex;
      oldIndex--;
    }
  }
  if (0 <= oldLastMatch - 1 || 0 <= newLastMatch - 1) {
    myChanges.add(new OriginalToNewChange(0, oldLastMatch - 1, 0, newLastMatch - 1));
  }
}
 
Example 3
Source File: NameSuggester.java    From consulo with Apache License 2.0 5 votes vote down vote up
public String suggestName(final String propertyName) {
  if (myOldClassNameAsGiven.equals(propertyName)) return myNewClassNameAsGiven;
  final String[] propertyWords = NameUtil.splitNameIntoWords(propertyName);
  TIntIntHashMap matches = calculateMatches(propertyWords);
  if (matches.isEmpty()) return propertyName;
  TreeMap<Pair<Integer,Integer>, String> replacements = calculateReplacements(propertyWords, matches);
  if (replacements.isEmpty()) return propertyName;
  return calculateNewName(replacements, propertyWords, propertyName);
}
 
Example 4
Source File: NameUtilTest.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static void assertSplitEquals(String[] expected, String name) {
  final String[] result = NameUtil.splitNameIntoWords(name);
  assertEquals(Arrays.asList(expected).toString(), Arrays.asList(result).toString());
}