mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Java: Add quick fix for "Vararg record component must be the last in the list" (IDEA-316182)
GitOrigin-RevId: f172229f06d5d21f0fcdcdc396931cd2867ac6c7
This commit is contained in:
committed by
intellij-monorepo-bot
parent
4e14b17373
commit
7980952817
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.codeInsight.intention;
|
||||
|
||||
import com.intellij.codeInspection.LocalQuickFix;
|
||||
@@ -370,7 +370,7 @@ public abstract class QuickFixFactory {
|
||||
@NotNull PsiTypeElement checkTypeElement);
|
||||
|
||||
@NotNull
|
||||
public abstract IntentionAction createMakeVarargParameterLastFix(@NotNull PsiParameter parameter);
|
||||
public abstract IntentionAction createMakeVarargParameterLastFix(@NotNull PsiVariable parameter);
|
||||
|
||||
@NotNull
|
||||
public abstract IntentionAction createMakeReceiverParameterFirstFix(@NotNull PsiReceiverParameter parameter);
|
||||
|
||||
+4
-1
@@ -1789,8 +1789,11 @@ public final class HighlightUtil {
|
||||
|
||||
static HighlightInfo.Builder checkRecordComponentVarArg(@NotNull PsiRecordComponent recordComponent) {
|
||||
if (recordComponent.isVarArgs() && PsiTreeUtil.getNextSiblingOfType(recordComponent, PsiRecordComponent.class) != null) {
|
||||
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(recordComponent)
|
||||
HighlightInfo.Builder info = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(recordComponent)
|
||||
.descriptionAndTooltip(JavaErrorBundle.message("record.component.vararg.not.last"));
|
||||
IntentionAction action = getFixFactory().createMakeVarargParameterLastFix(recordComponent);
|
||||
info.registerFix(action, null, null, null, null);
|
||||
return info;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
+4
-19
@@ -1,39 +1,24 @@
|
||||
/*
|
||||
* Copyright 2000-2016 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-2023 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;
|
||||
import com.intellij.codeInsight.daemon.impl.actions.IntentionActionWithFixAllOption;
|
||||
import com.intellij.codeInsight.intention.FileModifier;
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.codeInsight.intention.impl.BaseIntentionAction;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiParameter;
|
||||
import com.intellij.psi.PsiVariable;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class MakeVarargParameterLastFix implements IntentionActionWithFixAllOption {
|
||||
private final @NotNull PsiParameter myParameter;
|
||||
private final @NotNull PsiVariable myParameter;
|
||||
|
||||
public MakeVarargParameterLastFix(@NotNull PsiParameter parameter) {
|
||||
public MakeVarargParameterLastFix(@NotNull PsiVariable parameter) {
|
||||
myParameter = parameter;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -662,7 +662,7 @@ public final class QuickFixFactoryImpl extends QuickFixFactory {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public IntentionAction createMakeVarargParameterLastFix(@NotNull PsiParameter parameter) {
|
||||
public IntentionAction createMakeVarargParameterLastFix(@NotNull PsiVariable parameter) {
|
||||
return new MakeVarargParameterLastFix(parameter);
|
||||
}
|
||||
|
||||
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
// "Move 'a' to the end of the list" "true-preview"
|
||||
|
||||
record R(int[][] b, int... a) {}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
// "Move 'i' to the end of the list" "true-preview"
|
||||
|
||||
class Simple {
|
||||
|
||||
void x(int j, int... i) {
|
||||
}
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
// "Move 'a' to the end of the list" "true-preview"
|
||||
|
||||
record R(<caret>int... a, int[][] b) {}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
// "Move 'i' to the end of the list" "true-preview"
|
||||
|
||||
class Simple {
|
||||
|
||||
void x(int...<caret> i, int j) {
|
||||
}
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
// Copyright 2000-2023 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.quickFix.LightQuickFixParameterizedTestCase;
|
||||
import com.intellij.testFramework.LightProjectDescriptor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase.JAVA_LATEST;
|
||||
|
||||
/**
|
||||
* @author Bas Leijdekkers
|
||||
*/
|
||||
public final class MakeVarargParameterLastFixTest extends LightQuickFixParameterizedTestCase {
|
||||
@Override
|
||||
protected @NotNull LightProjectDescriptor getProjectDescriptor() {
|
||||
return JAVA_LATEST;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getBasePath() {
|
||||
return "/codeInsight/daemonCodeAnalyzer/quickFix/makeVarargParameterLast";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user