mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[Inline Param Name Hints] do not show single hint if it is string literal
This commit is contained in:
+9
-3
@@ -27,6 +27,7 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static com.intellij.openapi.util.text.StringUtil.containsIgnoreCase;
|
||||
import static com.intellij.psi.CommonClassNames.JAVA_LANG_STRING;
|
||||
|
||||
public class ParameterNameHintsManager {
|
||||
private static final List<Couple<String>> COMMONLY_USED_PARAMETER_PAIR = ContainerUtil.newArrayList(
|
||||
@@ -134,18 +135,23 @@ public class ParameterNameHintsManager {
|
||||
}
|
||||
}
|
||||
|
||||
if (parameters.length == 2 && descriptors.size() == 2
|
||||
&& isCommonlyNamedParameterPair(descriptors.get(0), descriptors.get(1))) {
|
||||
if (descriptors.size() == 1 && isStringLiteral(descriptors.get(0))
|
||||
|| parameters.length == 2 && descriptors.size() == 2 && isCommonlyNamedParameterPair(descriptors.get(0), descriptors.get(1))) {
|
||||
return ContainerUtil.emptyList();
|
||||
}
|
||||
|
||||
return descriptors;
|
||||
}
|
||||
|
||||
private static boolean isStringLiteral(InlayInfo info) {
|
||||
PsiType type = info.getArgument().getType();
|
||||
return type != null && type.equalsToText(JAVA_LANG_STRING);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static InlayInfo createInlayInfo(@NotNull PsiExpression callArgument, @NotNull PsiParameter methodParam) {
|
||||
String paramName = ((methodParam.getType() instanceof PsiEllipsisType) ? "..." : "") + methodParam.getName();
|
||||
return new InlayInfo(paramName, callArgument.getTextRange().getStartOffset());
|
||||
return new InlayInfo(paramName, callArgument.getTextRange().getStartOffset(), callArgument);
|
||||
}
|
||||
|
||||
private static boolean isCommonlyNamedParameterPair(InlayInfo first, InlayInfo second) {
|
||||
|
||||
@@ -15,4 +15,6 @@
|
||||
*/
|
||||
package com.intellij.codeInsight.daemon.impl
|
||||
|
||||
class InlayInfo(val text: String, val offset: Int)
|
||||
import com.intellij.psi.PsiExpression
|
||||
|
||||
class InlayInfo(val text: String, val offset: Int, val argument: PsiExpression)
|
||||
+39
@@ -478,6 +478,45 @@ public class VarArgTest {
|
||||
.assertInlays("test->this", "endIndex->1000")
|
||||
}
|
||||
|
||||
fun `test do not show single parameter hint if it is string literal`() {
|
||||
setup("""
|
||||
public class Test {
|
||||
|
||||
public void test() {
|
||||
debug("Error message");
|
||||
info("Error message", new Object());
|
||||
}
|
||||
|
||||
void debug(String message) {}
|
||||
void info(String message, Object error) {}
|
||||
|
||||
}
|
||||
""")
|
||||
|
||||
onLineStartingWith("debug(").assertNoInlays()
|
||||
onLineStartingWith("info(").assertNoInlays()
|
||||
}
|
||||
|
||||
fun `test show hints for literals if there are many of them`() {
|
||||
setup("""
|
||||
public class Test {
|
||||
|
||||
public void test() {
|
||||
int a = 2;
|
||||
debug("Debug", "DTitle", a);
|
||||
info("Error message", "Title");
|
||||
}
|
||||
|
||||
void debug(String message, String title, int value) {}
|
||||
void info(String message, String title) {}
|
||||
|
||||
}
|
||||
""")
|
||||
|
||||
onLineStartingWith("debug(").assertInlays("message->\"Debug\"", "title->\"DTitle\"")
|
||||
onLineStartingWith("info(").assertInlays("message->\"Error message\"", "title->\"Title\"")
|
||||
}
|
||||
|
||||
private fun getInlays(): List<Inlay> {
|
||||
val editor = myFixture.editor
|
||||
return editor.inlayModel.getInlineElementsInRange(0, editor.document.textLength)
|
||||
|
||||
Reference in New Issue
Block a user