mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
JavaJoinListAction: do not suggest intention when comments exists
GitOrigin-RevId: ad790d5b4abde39deea670873eb4b34f2a01828c
This commit is contained in:
committed by
intellij-monorepo-bot
parent
a29b9f588c
commit
1783bbf417
+15
@@ -1,10 +1,14 @@
|
||||
// Copyright 2000-2019 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.intention.impl.lists;
|
||||
|
||||
import com.intellij.psi.JavaTokenType;
|
||||
import com.intellij.psi.PsiComment;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class AbstractJavaJoinListAction<L extends PsiElement, E extends PsiElement> extends AbstractJoinListAction<L, E> {
|
||||
@Override
|
||||
@Nullable
|
||||
@@ -17,4 +21,15 @@ public abstract class AbstractJavaJoinListAction<L extends PsiElement, E extends
|
||||
PsiElement nextBreak(@NotNull PsiElement element) {
|
||||
return JavaListUtils.nextBreak(element);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean canJoin(@NotNull List<E> elements) {
|
||||
PsiElement parent = elements.get(0).getParent();
|
||||
for (PsiElement child : parent.getChildren()) {
|
||||
if (child instanceof PsiComment && ((PsiComment)child).getTokenType() == JavaTokenType.END_OF_LINE_COMMENT) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
+6
-1
@@ -41,7 +41,7 @@ public abstract class AbstractJoinListAction<L extends PsiElement, E extends Psi
|
||||
CodeStyleManager.getInstance(project).adjustLineIndent(context.myList.getContainingFile(), context.myList.getParent().getTextRange());
|
||||
}
|
||||
|
||||
private void deleteBreakIfPresent(Document document, PsiElement aBreak) {
|
||||
private static void deleteBreakIfPresent(Document document, PsiElement aBreak) {
|
||||
if (aBreak != null) {
|
||||
TextRange range = aBreak.getTextRange();
|
||||
document.deleteString(range.getStartOffset(), range.getEndOffset());
|
||||
@@ -65,6 +65,7 @@ public abstract class AbstractJoinListAction<L extends PsiElement, E extends Psi
|
||||
List<E> elements = getElements(list);
|
||||
if (elements == null) return null;
|
||||
if (elements.size() < minElementCount()) return null;
|
||||
if (!canJoin(elements)) return null;
|
||||
WhitespacesInfo whitespacesInfo = collectBreakWhitespaces(elements);
|
||||
if (whitespacesInfo == null) return null;
|
||||
return new Context<>(whitespacesInfo, list);
|
||||
@@ -82,6 +83,10 @@ public abstract class AbstractJoinListAction<L extends PsiElement, E extends Psi
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean canJoin(@NotNull List<E> elements) {
|
||||
return true;
|
||||
}
|
||||
|
||||
private WhitespacesInfo collectBreakWhitespaces(List<E> elements) {
|
||||
List<PsiElement> breaks = new ArrayList<>();
|
||||
PsiElement beforeFirst = null;
|
||||
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// "Put arguments on one line" "false"
|
||||
|
||||
class A {
|
||||
void foo(int a1, int a2, int a3) {
|
||||
foo(
|
||||
12, // 12
|
||||
23,<caret>
|
||||
4
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user