mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
make some clients independent of order of results in Query.findAll()
GitOrigin-RevId: df14c535f9ff642399ed42e123563dac3db8bb20
This commit is contained in:
committed by
intellij-monorepo-bot
parent
15e30d4520
commit
2b081e39ab
@@ -1064,7 +1064,7 @@ public class JavaDocInfoGenerator {
|
||||
PsiParameter parm = parameters[i];
|
||||
generateAnnotations(buffer, parm, place, false);
|
||||
generateType(buffer, parm.getType(), method, generateLink, isTooltip);
|
||||
if (parm.getName() != null && !isTooltip) {
|
||||
if (!isTooltip) {
|
||||
buffer.append(NBSP);
|
||||
buffer.append(parm.getName());
|
||||
}
|
||||
@@ -1648,6 +1648,10 @@ public class JavaDocInfoGenerator {
|
||||
if (parentClass == null) return;
|
||||
if (parentClass.isInterface() && !overrides) return;
|
||||
PsiMethod[] supers = method.findSuperMethods();
|
||||
Arrays.sort(supers, Comparator.comparing(m-> {
|
||||
PsiClass aClass = m.getContainingClass();
|
||||
return aClass == null ? null : aClass.getName();
|
||||
}));
|
||||
if (supers.length == 0) return;
|
||||
boolean headerGenerated = false;
|
||||
for (PsiMethod superMethod : supers) {
|
||||
|
||||
+3
-1
@@ -1149,7 +1149,9 @@ public class SimplifyStreamApiCallChainsInspection extends AbstractBaseJavaLocal
|
||||
generator.byCollectionName(((PsiReferenceExpression)containerQualifier).getReferenceName());
|
||||
}
|
||||
String name = generator.byType(elementType).byName("item", "element").generate(true);
|
||||
Collection<PsiReference> refs = ReferencesSearch.search(indexParameter, new LocalSearchScope(body)).findAll();
|
||||
List<PsiReference> refs = new ArrayList<>(ReferencesSearch.search(indexParameter, new LocalSearchScope(body)).findAll());
|
||||
refs.sort(Comparator.comparingInt(ref -> ref.getElement().getTextOffset()));
|
||||
|
||||
for (PsiReference ref : refs) {
|
||||
PsiExpression getExpression = container.extractGetExpressionFromIndex(tryCast(ref, PsiExpression.class));
|
||||
if (getExpression != null) {
|
||||
|
||||
@@ -37,6 +37,7 @@ import org.jetbrains.annotations.TestOnly;
|
||||
import javax.swing.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
public class NullityInferrer {
|
||||
@@ -573,7 +574,10 @@ public class NullityInferrer {
|
||||
final PsiMethod method = (PsiMethod)grandParent;
|
||||
if (method.getBody() != null) {
|
||||
|
||||
for (PsiReference reference : ReferencesSearch.search(parameter, new LocalSearchScope(method))) {
|
||||
List<PsiReference> all = new ArrayList<>(ReferencesSearch.search(parameter, new LocalSearchScope(method)).findAll());
|
||||
all.sort(Comparator.comparingInt(ref->ref.getElement().getTextOffset()));
|
||||
|
||||
for (PsiReference reference : all) {
|
||||
final PsiElement place = reference.getElement();
|
||||
if (place instanceof PsiReferenceExpression) {
|
||||
final PsiReferenceExpression expr = (PsiReferenceExpression)place;
|
||||
|
||||
+2
-1
@@ -209,7 +209,8 @@ public class ReturnSeparatedFromComputationInspection extends AbstractBaseJavaLo
|
||||
}
|
||||
|
||||
Query<PsiReference> query = ReferencesSearch.search(context.returnedVariable, new LocalSearchScope(context.variableScope));
|
||||
Collection<PsiReference> usages = query.findAll();
|
||||
List<PsiReference> usages = new ArrayList<>(query.findAll());
|
||||
usages.sort(Comparator.comparingInt(ref -> ref.getElement().getTextOffset()));
|
||||
for (PsiReference usage : usages) {
|
||||
PsiElement parent = PsiTreeUtil.skipParentsOfType(usage.getElement(),
|
||||
PsiParenthesizedExpression.class, PsiTypeCastExpression.class);
|
||||
|
||||
+5
-2
@@ -25,7 +25,9 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.Collection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class Java8MapForEachInspection extends AbstractBaseJavaLocalInspectionTool {
|
||||
@@ -150,7 +152,8 @@ public class Java8MapForEachInspection extends AbstractBaseJavaLocalInspectionTo
|
||||
PsiType entryType = entryParameter.getType();
|
||||
ParameterCandidate key = new ParameterCandidate(entryType, true);
|
||||
ParameterCandidate value = new ParameterCandidate(entryType, false);
|
||||
Collection<PsiReference> references = ReferencesSearch.search(entryParameter).findAll();
|
||||
List<PsiReference> references = new ArrayList<>(ReferencesSearch.search(entryParameter).findAll());
|
||||
references.sort(Comparator.comparingInt(ref->ref.getElement().getTextOffset()));
|
||||
for (PsiReference ref : references) {
|
||||
PsiMethodCallExpression entryCall = ExpressionUtils.getCallForQualifier(ObjectUtils.tryCast(ref.getElement(), PsiExpression.class));
|
||||
if (ENTRY_GETTER.test(entryCall)) {
|
||||
|
||||
+2
-4
@@ -25,10 +25,7 @@ import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.*;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
import static com.intellij.codeInspection.streamMigration.StreamApiMigrationInspection.isCallOf;
|
||||
@@ -807,6 +804,7 @@ class CollectMigration extends BaseStreamApiMigration {
|
||||
|
||||
List<? extends PsiExpression> usages = terminal.targetReferences().toList();
|
||||
if (usages.isEmpty()) return null;
|
||||
usages.sort(Comparator.comparingInt(ref->ref.getTextOffset()));
|
||||
PsiMethodCallExpression toArrayCandidate = StreamEx.of(usages)
|
||||
.map(usage -> ExpressionUtils.getCallForQualifier(tryCast(usage, PsiExpression.class)))
|
||||
.nonNull().findFirst().orElse(null);
|
||||
|
||||
+6
-2
@@ -124,12 +124,14 @@ public abstract class BaseConvertToLocalQuickFix<V extends PsiVariable> implemen
|
||||
final Collection<PsiReference> references = ReferencesSearch.search(variable).findAll();
|
||||
if (references.isEmpty()) return Collections.emptyList();
|
||||
|
||||
return Collections.singletonList(moveDeclaration(project, variable, references, true));
|
||||
return Collections.singletonList(ObjectUtils.notNull(moveDeclaration(project, variable, references, true)));
|
||||
}
|
||||
|
||||
protected PsiElement moveDeclaration(Project project, V variable, final Collection<? extends PsiReference> references, boolean delete) {
|
||||
final PsiCodeBlock anchorBlock = findAnchorBlock(references);
|
||||
if (anchorBlock == null) return null; //was assert, but need to fix the case when obsolete inspection highlighting is left
|
||||
if (anchorBlock == null) {
|
||||
return null; //was assert, but need to fix the case when obsolete inspection highlighting is left
|
||||
}
|
||||
|
||||
final PsiElement firstElement = getLowestOffsetElement(references);
|
||||
final String localName = suggestLocalName(project, variable, anchorBlock);
|
||||
@@ -281,6 +283,7 @@ public abstract class BaseConvertToLocalQuickFix<V extends PsiVariable> implemen
|
||||
PsiCodeBlock result = null;
|
||||
for (PsiReference psiReference : refs) {
|
||||
final PsiElement element = psiReference.getElement();
|
||||
if (PsiUtil.isInsideJavadocComment(element)) continue;
|
||||
PsiCodeBlock block = PsiTreeUtil.getParentOfType(element, PsiCodeBlock.class);
|
||||
if (result == null || block == null) {
|
||||
result = block;
|
||||
@@ -288,6 +291,7 @@ public abstract class BaseConvertToLocalQuickFix<V extends PsiVariable> implemen
|
||||
else {
|
||||
final PsiElement commonParent = PsiTreeUtil.findCommonParent(result, block);
|
||||
result = PsiTreeUtil.getParentOfType(commonParent, PsiCodeBlock.class, false);
|
||||
if (result == null) return null;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
||||
@@ -29,9 +29,7 @@ import com.intellij.refactoring.util.classMembers.ClassMemberReferencesVisitor;
|
||||
import com.intellij.refactoring.util.classMembers.MemberInfo;
|
||||
import com.intellij.util.containers.MultiMap;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
|
||||
public class PushDownConflicts {
|
||||
private final PsiClass myClass;
|
||||
@@ -118,8 +116,10 @@ public class PushDownConflicts {
|
||||
if (superMethod.hasModifierProperty(PsiModifier.DEFAULT)) {
|
||||
unrelatedDefaults.add(superMethod.getContainingClass());
|
||||
if (unrelatedDefaults.size() > 1) {
|
||||
List<PsiClass> supers = new ArrayList<>(unrelatedDefaults);
|
||||
supers.sort(Comparator.comparing(PsiClass::getName));
|
||||
myConflicts.putValue(member, CommonRefactoringUtil.capitalize(RefactoringUIUtil.getDescription(myClass, false) + " will inherit unrelated defaults from " +
|
||||
StringUtil.join(unrelatedDefaults, aClass -> RefactoringUIUtil.getDescription(aClass, false)," and ")));
|
||||
StringUtil.join(supers, aClass -> RefactoringUIUtil.getDescription(aClass, false)," and ")));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,9 @@ import com.intellij.openapi.application.WriteAction;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.Segment;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.source.resolve.reference.impl.providers.JavaClassReference;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
@@ -28,6 +30,8 @@ import com.intellij.usageView.UsageInfo;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
public class MigrationUtil {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.refactoring.migration.MigrationUtil");
|
||||
@@ -61,11 +65,18 @@ public class MigrationUtil {
|
||||
}
|
||||
|
||||
private static UsageInfo[] findRefs(final PsiElement aClass, GlobalSearchScope searchScope) {
|
||||
final ArrayList<UsageInfo> results = new ArrayList<>();
|
||||
List<UsageInfo> results = new ArrayList<>();
|
||||
for (PsiReference usage : ReferencesSearch.search(aClass, searchScope, false)) {
|
||||
results.add(new UsageInfo(usage));
|
||||
}
|
||||
|
||||
results.sort(Comparator.<UsageInfo, String>comparing(u -> {
|
||||
VirtualFile file = u.getVirtualFile();
|
||||
return file == null ? null : file.getName();
|
||||
}).thenComparingInt(u->{
|
||||
Segment range = u.getNavigationRange();
|
||||
return range == null ? 0 : range.getStartOffset();
|
||||
}));
|
||||
return results.toArray(UsageInfo.EMPTY_ARRAY);
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@ import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class Test {
|
||||
class Test {
|
||||
public String[] testToArray(String[] args) {
|
||||
return Arrays.stream(args).distinct().sorted().toArray(String[]::new);
|
||||
}
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@ import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class Test {
|
||||
class Test {
|
||||
public String[] testToArray(String[] args) {
|
||||
Set<String> set = Arrays.stream(args).co<caret>llect(Collectors.toCollection(TreeSet::new));
|
||||
return set.toArray(new String[set.size()]);
|
||||
|
||||
@@ -24,12 +24,13 @@ import com.intellij.refactoring.util.DocCommentPolicy;
|
||||
import com.intellij.refactoring.util.classMembers.MemberInfo;
|
||||
import com.intellij.refactoring.util.classMembers.MemberInfoStorage;
|
||||
import com.intellij.usageView.UsageInfo;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.containers.MultiMap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@@ -124,7 +125,7 @@ public class PushDownTest extends LightRefactoringTestCase {
|
||||
}
|
||||
|
||||
public void testClassInheritsUnrelatedDefaultsConflict() {
|
||||
doTest(conflicts -> assertSameElements(conflicts.values(), Collections.singletonList("Class <b><code>B</code></b> will inherit unrelated defaults from interface <b><code>I</code></b> and interface <b><code>A</code></b>")));
|
||||
doTest(conflicts -> assertSameElements(conflicts.values(), Collections.singletonList("Class <b><code>B</code></b> will inherit unrelated defaults from interface <b><code>A</code></b> and interface <b><code>I</code></b>")));
|
||||
}
|
||||
|
||||
public void testStaticToLocal() {
|
||||
@@ -132,11 +133,11 @@ public class PushDownTest extends LightRefactoringTestCase {
|
||||
}
|
||||
|
||||
public void testStaticToLocalWithReferenceUpdate() {
|
||||
doTest(conflicts -> assertSameElements(conflicts.values(),
|
||||
Arrays.asList("Method <b><code>m()</code></b> uses method <b><code>foo()</code></b>, which is pushed down",
|
||||
"Method <b><code>m()</code></b> uses method <b><code>foo()</code></b>, which is pushed down",
|
||||
"Static method <b><code>foo()</code></b> can't be pushed to non-static class <b><code>FooExt1</code></b>",
|
||||
"Static method <b><code>foo()</code></b> can't be pushed to non-static class <b><code>FooExt</code></b>")));
|
||||
doTest(conflicts -> assertSameElements(new HashSet<>(conflicts.values()),
|
||||
ContainerUtil.newHashSet("Method <b><code>m()</code></b> uses method <b><code>foo()</code></b>, which is pushed down",
|
||||
"Method <b><code>m()</code></b> uses method <b><code>foo()</code></b>, which is pushed down",
|
||||
"Static method <b><code>foo()</code></b> can't be pushed to non-static class <b><code>FooExt1</code></b>",
|
||||
"Static method <b><code>foo()</code></b> can't be pushed to non-static class <b><code>FooExt</code></b>")));
|
||||
}
|
||||
|
||||
private void doTest() {
|
||||
@@ -151,7 +152,7 @@ public class PushDownTest extends LightRefactoringTestCase {
|
||||
});
|
||||
}
|
||||
|
||||
private void doTest(final Consumer<MultiMap<PsiElement, String>> checkConflicts) {
|
||||
private void doTest(final Consumer<? super MultiMap<PsiElement, String>> checkConflicts) {
|
||||
configureByFile(BASE_PATH + getTestName(false) + ".java");
|
||||
|
||||
final PsiElement targetElement = TargetElementUtil.findTargetElement(getEditor(), TargetElementUtil.ELEMENT_NAME_ACCEPTED);
|
||||
|
||||
+2
-1
@@ -393,7 +393,8 @@ public class StringConcatenationInLoopsInspection extends BaseInspection {
|
||||
Predicate<? super PsiReferenceExpression> skip) {
|
||||
Query<PsiReference> query =
|
||||
scope == null ? ReferencesSearch.search(variable) : ReferencesSearch.search(variable, new LocalSearchScope(scope));
|
||||
Collection<PsiReference> refs = query.findAll();
|
||||
List<PsiReference> refs = new ArrayList<>(query.findAll());
|
||||
refs.sort(Comparator.comparingInt(ref -> ref.getElement().getTextOffset()));
|
||||
if (myNullSafe) {
|
||||
fillNullables(variable, refs);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user