mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-19 13:02:30 +07:00
[java-completion] Complete statement: fix missing comma (IDEA-268441)
GitOrigin-RevId: 43c014680dc72429f349d667cc66c0920def1358
This commit is contained in:
committed by
intellij-monorepo-bot
parent
a2628e3c90
commit
a2ebadc8dd
@@ -91,6 +91,7 @@ public class JavaSmartEnterProcessor extends SmartEnterProcessor {
|
||||
fixers.add(new MissingForBodyFixer());
|
||||
fixers.add(new MissingForeachBodyFixer());
|
||||
fixers.add(new ParameterListFixer());
|
||||
fixers.add(new MissingCommaFixer());
|
||||
fixers.add(new MissingMethodBodyFixer());
|
||||
fixers.add(new MissingClassBodyFixer());
|
||||
fixers.add(new MissingReturnExpressionFixer());
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
// 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.
|
||||
package com.intellij.codeInsight.editorActions.smartEnter;
|
||||
|
||||
import com.intellij.core.JavaPsiBundle;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiErrorElement;
|
||||
import com.intellij.psi.PsiExpression;
|
||||
import com.intellij.psi.PsiExpressionList;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
|
||||
public class MissingCommaFixer implements Fixer {
|
||||
@Override
|
||||
public void apply(Editor editor, JavaSmartEnterProcessor processor, PsiElement psiElement) throws IncorrectOperationException {
|
||||
if (psiElement instanceof PsiErrorElement) {
|
||||
if (((PsiErrorElement)psiElement).getErrorDescription().equals(JavaPsiBundle.message("expected.comma.or.rparen"))) {
|
||||
PsiElement parent = psiElement.getParent();
|
||||
if (parent instanceof PsiExpressionList) {
|
||||
PsiElement next = PsiTreeUtil.skipWhitespacesAndCommentsForward(psiElement);
|
||||
if (next instanceof PsiExpression) {
|
||||
editor.getDocument().insertString(psiElement.getTextOffset(), ",");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class SomeClass {
|
||||
|
||||
public static List<String> someMethod() {
|
||||
return Arrays.asList(
|
||||
"first",
|
||||
"second"<caret>
|
||||
"third"
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class SomeClass {
|
||||
|
||||
public static List<String> someMethod() {
|
||||
return Arrays.asList(
|
||||
"first",
|
||||
"second",
|
||||
"third"
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -190,6 +190,7 @@ public class CompleteStatementTest extends EditorActionTestCase {
|
||||
public void testOverloadedMethodOneOrThree() { doTest(); }
|
||||
public void testOverloadedMethodOneOrThree2() { doTest(); }
|
||||
public void testOverloadedMethodOneOrThree3() { doTest(); }
|
||||
public void testMissingComma() { doTest(); }
|
||||
|
||||
private void doTestBracesNextLineStyle() {
|
||||
myJavaSettings.BRACE_STYLE = CommonCodeStyleSettings.NEXT_LINE;
|
||||
|
||||
Reference in New Issue
Block a user