mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Use StringJoiner instead of hand-written joining pattern
+some converted to Stream GitOrigin-RevId: 92068910b1fb560b6d016a247ee6f4fec022fce0
This commit is contained in:
committed by
intellij-monorepo-bot
parent
f8f402347c
commit
2bc502e1f9
@@ -78,17 +78,11 @@ public abstract class DebuggerUtils {
|
||||
}
|
||||
if (value instanceof ObjectReference) {
|
||||
if (value instanceof ArrayReference) {
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
builder.append("[");
|
||||
for (Iterator<Value> iterator = ((ArrayReference)value).getValues().iterator(); iterator.hasNext();) {
|
||||
final Value element = iterator.next();
|
||||
builder.append(getValueAsString(evaluationContext, element));
|
||||
if (iterator.hasNext()) {
|
||||
builder.append(",");
|
||||
}
|
||||
final StringJoiner joiner = new StringJoiner(",", "[", "]");
|
||||
for (final Value element : ((ArrayReference)value).getValues()) {
|
||||
joiner.add(getValueAsString(evaluationContext, element));
|
||||
}
|
||||
builder.append("]");
|
||||
return builder.toString();
|
||||
return joiner.toString();
|
||||
}
|
||||
|
||||
final ObjectReference objRef = (ObjectReference)value;
|
||||
|
||||
@@ -240,15 +240,11 @@ abstract class ProjectLayoutPanel<T> extends JPanel {
|
||||
|
||||
final Collection<? extends DetectedProjectRoot> sourceRoots = moduleDescriptor.getSourceRoots();
|
||||
if (sourceRoots.size() > 0) {
|
||||
builder.append(" [");
|
||||
for (Iterator<? extends DetectedProjectRoot> it = sourceRoots.iterator(); it.hasNext();) {
|
||||
DetectedProjectRoot root = it.next();
|
||||
builder.append(root.getDirectory().getName());
|
||||
if (it.hasNext()) {
|
||||
builder.append(",");
|
||||
}
|
||||
StringJoiner joiner = new StringJoiner(",", " [", "]");
|
||||
for (DetectedProjectRoot root : sourceRoots) {
|
||||
joiner.add(root.getDirectory().getName());
|
||||
}
|
||||
builder.append("]");
|
||||
builder.append(joiner);
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
+2
-4
@@ -2100,12 +2100,10 @@ public abstract class LongRangeSet {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder("{");
|
||||
StringJoiner sb = new StringJoiner(", ", "{", "}");
|
||||
for (int i = 0; i < myRanges.length; i += 2) {
|
||||
if (i > 0) sb.append(", ");
|
||||
sb.append(LongRangeSet.toString(myRanges[i], myRanges[i + 1]));
|
||||
sb.add(LongRangeSet.toString(myRanges[i], myRanges[i + 1]));
|
||||
}
|
||||
sb.append("}");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import com.intellij.psi.util.TypeConversionUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Intersection types arise in a process of computing least upper bound.
|
||||
@@ -169,12 +170,7 @@ public class PsiIntersectionType extends PsiType.Stub {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder("PsiIntersectionType: ");
|
||||
for (int i = 0; i < myConjuncts.length; i++) {
|
||||
if (i > 0) sb.append(", ");
|
||||
sb.append(myConjuncts[i].getPresentableText());
|
||||
}
|
||||
return sb.toString();
|
||||
return Arrays.stream(myConjuncts).map(PsiType::getPresentableText).collect(Collectors.joining(", ", "PsiIntersectionType: ", ""));
|
||||
}
|
||||
|
||||
public String getConflictingConjunctsMessage() {
|
||||
|
||||
@@ -10,6 +10,8 @@ import org.intellij.lang.annotations.MagicConstant;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.StringJoiner;
|
||||
|
||||
public class PsiFormatUtil extends PsiFormatUtilBase {
|
||||
@MagicConstant(flags = {
|
||||
SHOW_MODIFIERS, SHOW_TYPE, TYPE_AFTER, SHOW_CONTAINING_CLASS, SHOW_FQ_NAME, SHOW_NAME, SHOW_MODIFIERS,
|
||||
@@ -335,19 +337,17 @@ public class PsiFormatUtil extends PsiFormatUtilBase {
|
||||
}
|
||||
|
||||
private static String formatReferenceList(PsiReferenceList list, int options) {
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
StringJoiner buffer = new StringJoiner(", ");
|
||||
if (BitUtil.isSet(options, SHOW_RAW_TYPE)) {
|
||||
PsiClassType[] types = list.getReferencedTypes();
|
||||
for (int i = 0; i < types.length; i++) {
|
||||
if (i > 0) buffer.append(", ");
|
||||
buffer.append(formatType(types[i], options, PsiSubstitutor.EMPTY));
|
||||
for (PsiClassType type : types) {
|
||||
buffer.add(formatType(type, options, PsiSubstitutor.EMPTY));
|
||||
}
|
||||
}
|
||||
else {
|
||||
PsiJavaCodeReferenceElement[] refs = list.getReferenceElements();
|
||||
for (int i = 0; i < refs.length; i++) {
|
||||
if (i > 0) buffer.append(", ");
|
||||
buffer.append(formatReference(refs[i], options));
|
||||
for (PsiJavaCodeReferenceElement ref : refs) {
|
||||
buffer.add(formatReference(ref, options));
|
||||
}
|
||||
}
|
||||
return buffer.toString();
|
||||
|
||||
@@ -20,6 +20,8 @@ import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.PsiImplUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.StringJoiner;
|
||||
|
||||
/**
|
||||
* @author dsl
|
||||
*/
|
||||
@@ -35,16 +37,10 @@ public class LightReferenceParameterList extends LightElement implements PsiRefe
|
||||
|
||||
private String calculateText() {
|
||||
if (myTypeElements.length == 0) return "";
|
||||
final StringBuilder buffer = new StringBuilder();
|
||||
buffer.append("<");
|
||||
for (int i = 0; i < myTypeElements.length; i++) {
|
||||
PsiTypeElement type = myTypeElements[i];
|
||||
if (i > 0) {
|
||||
buffer.append(",");
|
||||
}
|
||||
buffer.append(type.getText());
|
||||
final StringJoiner buffer = new StringJoiner(",", "<", ">");
|
||||
for (PsiTypeElement type : myTypeElements) {
|
||||
buffer.add(type.getText());
|
||||
}
|
||||
buffer.append(">");
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class LocalSearchScope extends SearchScope {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.psi.search.LocalSearchScope");
|
||||
@@ -198,16 +199,8 @@ public class LocalSearchScope extends SearchScope {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder result = new StringBuilder();
|
||||
for (int i = 0; i < myScope.length; i++) {
|
||||
final PsiElement element = myScope[i];
|
||||
if (i > 0) {
|
||||
result.append(",");
|
||||
}
|
||||
result.append(element);
|
||||
}
|
||||
//noinspection HardCodedStringLiteral
|
||||
return "LocalSearchScope:" + result;
|
||||
return Arrays.stream(myScope).map(String::valueOf).collect(Collectors.joining(",", "LocalSearchScope:", ""));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -23,6 +23,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
class SoftMargins implements Cloneable {
|
||||
|
||||
@@ -39,7 +40,6 @@ class SoftMargins implements Cloneable {
|
||||
if (valueList != null) {
|
||||
String[] values = valueList.split(",\\s*");
|
||||
myValues = new ArrayList<>(values.length);
|
||||
int i = 0;
|
||||
for (String value : values) {
|
||||
try {
|
||||
myValues.add(Integer.parseInt(value));
|
||||
@@ -87,14 +87,10 @@ class SoftMargins implements Cloneable {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (myValues != null) {
|
||||
for (int margin: myValues) {
|
||||
if (sb.length() > 0) sb.append(",");
|
||||
sb.append(margin);
|
||||
}
|
||||
if (myValues == null) {
|
||||
return "";
|
||||
}
|
||||
return sb.toString();
|
||||
return myValues.stream().map(String::valueOf).collect(Collectors.joining(","));
|
||||
}
|
||||
|
||||
public void serializeInto(@NotNull Element element) {
|
||||
|
||||
Reference in New Issue
Block a user