mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Use Stream API to join strings
This commit is contained in:
+4
-6
@@ -19,6 +19,9 @@ import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author max
|
||||
*/
|
||||
@@ -83,12 +86,7 @@ public class CommentFormatter {
|
||||
|
||||
private static String stripSpaces(String text) {
|
||||
String[] lines = LineTokenizer.tokenize(text.toCharArray(), false);
|
||||
StringBuilder buf = new StringBuilder(text.length());
|
||||
for (int i = 0; i < lines.length; i++) {
|
||||
if (i > 0) buf.append('\n');
|
||||
buf.append(rTrim(lines[i]));
|
||||
}
|
||||
return buf.toString();
|
||||
return Arrays.stream(lines).map(CommentFormatter::rTrim).collect(Collectors.joining("\n"));
|
||||
}
|
||||
|
||||
private static String rTrim(String text) {
|
||||
|
||||
@@ -30,6 +30,7 @@ import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class JavaNameSuggestionProvider implements NameSuggestionProvider {
|
||||
@Override
|
||||
@@ -102,13 +103,8 @@ public class JavaNameSuggestionProvider implements NameSuggestionProvider {
|
||||
prefix = codeStyleManager.getPrefixByVariableKind(kind);
|
||||
if (kind == VariableKind.STATIC_FINAL_FIELD) {
|
||||
final String[] words = NameUtil.splitNameIntoWords(name);
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
for (int i = 0; i < words.length; i++) {
|
||||
String word = words[i];
|
||||
if (i > 0) buffer.append('_');
|
||||
buffer.append(StringUtil.toUpperCase(word));
|
||||
}
|
||||
return new String[] {buffer.toString()};
|
||||
String buffer = Arrays.stream(words).map(StringUtil::toUpperCase).collect(Collectors.joining("_"));
|
||||
return new String[] {buffer};
|
||||
}
|
||||
}
|
||||
final List<String> result = new ArrayList<>();
|
||||
@@ -117,7 +113,7 @@ public class JavaNameSuggestionProvider implements NameSuggestionProvider {
|
||||
name = name.substring(prefix.length());
|
||||
result.add(suggestProperlyCasedName(prefix, NameUtil.splitNameIntoWords(name)));
|
||||
}
|
||||
result.add(suggestProperlyCasedName(prefix, NameUtil.splitNameIntoWords(name.toLowerCase())));
|
||||
result.add(suggestProperlyCasedName(prefix, NameUtil.splitNameIntoWords(name.toLowerCase(Locale.ENGLISH))));
|
||||
return ArrayUtil.toStringArray(result);
|
||||
}
|
||||
|
||||
|
||||
@@ -140,11 +140,6 @@ public class FormatterStarter implements ApplicationStarter {
|
||||
}
|
||||
|
||||
private static void logArgs(@NotNull String[] args) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (String arg : args) {
|
||||
if (sb.length() > 0) sb.append(",");
|
||||
sb.append(arg);
|
||||
}
|
||||
LOG.info("Arguments: " + sb);
|
||||
LOG.info("Arguments: " + String.join(",", args));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,8 +36,9 @@ import org.jetbrains.annotations.Nullable;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class KeymapUtil {
|
||||
|
||||
@@ -263,15 +264,7 @@ public class KeymapUtil {
|
||||
if (shortcuts.length == 0) {
|
||||
return "";
|
||||
}
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
for (int i = 0; i < shortcuts.length; i++) {
|
||||
Shortcut shortcut = shortcuts[i];
|
||||
if (i > 0) {
|
||||
buffer.append(' ');
|
||||
}
|
||||
buffer.append(getShortcutText(shortcut));
|
||||
}
|
||||
return buffer.toString();
|
||||
return Arrays.stream(shortcuts).map(KeymapUtil::getShortcutText).collect(Collectors.joining(" "));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -509,17 +509,8 @@ public class PlatformTestUtil {
|
||||
return print(Arrays.asList(objects));
|
||||
}
|
||||
|
||||
public static String print(Collection c) {
|
||||
StringBuilder result = new StringBuilder();
|
||||
for (Iterator iterator = c.iterator(); iterator.hasNext();) {
|
||||
Object each = iterator.next();
|
||||
result.append(toString(each, null));
|
||||
if (iterator.hasNext()) {
|
||||
result.append("\n");
|
||||
}
|
||||
}
|
||||
|
||||
return result.toString();
|
||||
public static String print(Collection<?> c) {
|
||||
return c.stream().map(each -> toString(each, null)).collect(Collectors.joining("\n"));
|
||||
}
|
||||
|
||||
public static String print(ListModel model) {
|
||||
|
||||
+2
-10
@@ -30,9 +30,9 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class I18nizeConcatenationQuickFix extends I18nizeQuickFix{
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.i18n.I18nizeConcatenationQuickFix");
|
||||
@@ -71,15 +71,7 @@ public class I18nizeConcatenationQuickFix extends I18nizeQuickFix{
|
||||
}
|
||||
|
||||
private static String composeParametersText(final List<PsiExpression> args) {
|
||||
final StringBuilder result = new StringBuilder();
|
||||
for (Iterator<PsiExpression> iterator = args.iterator(); iterator.hasNext();) {
|
||||
PsiExpression psiExpression = iterator.next();
|
||||
result.append(psiExpression.getText());
|
||||
if (iterator.hasNext()) {
|
||||
result.append(",");
|
||||
}
|
||||
}
|
||||
return result.toString();
|
||||
return args.stream().map(PsiExpression::getText).collect(Collectors.joining(","));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user