[psi] ensure that cache in PsiExpressionsList#getExpressions is not corrupted during highlighting (IDEA-296766)

safer it would be to return array.clone() but there is a suspicion that it would to too expensive

GitOrigin-RevId: 9fd84fa2c3ff2d1d982d5747ec0f8f22fa220d5c
This commit is contained in:
Anna Kozlova
2022-06-28 15:34:01 +00:00
committed by intellij-monorepo-bot
parent fa3e33f2f1
commit 37e5457c2d
3 changed files with 22 additions and 18 deletions
@@ -1,4 +1,4 @@
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.codeInsight.daemon.impl.quickfix;
import com.intellij.codeInsight.daemon.QuickFixBundle;
@@ -94,8 +94,9 @@ public final class PermuteArgumentsFix implements IntentionAction, HighPriorityA
}
try {
registerSwapFixes(expressions, callExpression, permutations, methodCandidate, incompatibilitiesCount, minIncompatibleIndex, maxIncompatibleIndex);
registerShiftFixes(expressions, callExpression, permutations, methodCandidate, minIncompatibleIndex, maxIncompatibleIndex);
PsiExpression[] clonedExpressions = expressions.clone();
registerSwapFixes(clonedExpressions, callExpression, permutations, methodCandidate, incompatibilitiesCount, minIncompatibleIndex, maxIncompatibleIndex);
registerShiftFixes(clonedExpressions, callExpression, permutations, methodCandidate, minIncompatibleIndex, maxIncompatibleIndex);
}
catch (IncorrectOperationException e) {
LOG.error(e);
@@ -0,0 +1,7 @@
interface MyTest {
void foo(boolean withCompletion, boolean withAppointments, Boolean inDelay, String teamIds, String userIds, String ticketIds, String search, Long displayFilterId, Integer pageNumber, Integer pageSize, Object sort);
default void bar() {
foo(true, true, true, null, null, "", null, 1, <caret>null, null, null);
}
}
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.java.codeInsight.daemon.lambda;
import com.intellij.codeInsight.ExpectedTypeInfo;
@@ -60,6 +46,16 @@ public class Java8ExpressionsCheckTest extends LightDaemonAnalyzerTestCase {
assertFalse(type.getPresentableText(), type.equalsToText(CommonClassNames.JAVA_LANG_OBJECT));
}
public void testPermutedExpressionsInList() {
@NonNls String filePath = BASE_PATH + "/" + getTestName(false) + ".java";
configureByFile(filePath);
PsiExpressionList list =
PsiTreeUtil.getParentOfType(getFile().findElementAt(getEditor().getCaretModel().getOffset()), PsiExpressionList.class);
PsiExpression arg = list.getExpressions()[7];
assertEquals(1, highlightErrors().size());
assertEquals(arg, list.getExpressions()[7]);
}
public void testForbidCachingForAllQualifiersWhenDependOnThreadLocalTypes() {
configure();
PsiMethodCallExpression getKeyCall =