mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[Parameter Name Hints] show for single param null and this
This commit is contained in:
+14
-2
@@ -64,20 +64,32 @@ public class ParameterNameHintsManager {
|
||||
myDescriptors = descriptors;
|
||||
}
|
||||
|
||||
private static boolean isMethodToShowParams(PsiCallExpression callExpression, JavaResolveResult resolveResult) {
|
||||
private static boolean isMethodToShowParams(@NotNull PsiCallExpression callExpression, @NotNull JavaResolveResult resolveResult) {
|
||||
PsiElement element = resolveResult.getElement();
|
||||
if (element instanceof PsiMethod) {
|
||||
PsiMethod method = (PsiMethod)element;
|
||||
if (isSetter(method) || isBuilder(callExpression, method)) return false;
|
||||
if (hasSingleParameter(method)) {
|
||||
PsiParameter parameter = method.getParameterList().getParameters()[0];
|
||||
return PsiType.VOID.equals(method.getReturnType()) || isBoolean(parameter);
|
||||
return PsiType.VOID.equals(method.getReturnType()) || isBoolean(parameter) || isNullOrThis(callExpression);
|
||||
}
|
||||
return !isCommonMethod(method);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean isNullOrThis(@NotNull PsiCallExpression callExpression) {
|
||||
PsiExpressionList list = callExpression.getArgumentList();
|
||||
PsiExpression[] expressions = list != null ? list.getExpressions() : null;
|
||||
if (expressions != null && expressions.length > 0) {
|
||||
PsiExpression expression = expressions[0];
|
||||
if (expression.textMatches("null") || expression.textMatches("this")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean isBuilder(PsiCallExpression expression, PsiMethod method) {
|
||||
if (expression instanceof PsiNewExpression) {
|
||||
return false;
|
||||
|
||||
+21
@@ -526,6 +526,27 @@ public class VarArgTest {
|
||||
.assertInlays("test->this", "endIndex->1000")
|
||||
}
|
||||
|
||||
fun `test inline strange methods`() {
|
||||
setup("""
|
||||
public class Test {
|
||||
|
||||
void main() {
|
||||
createContent(null);
|
||||
createNewContent(this);
|
||||
}
|
||||
|
||||
Content createContent(DockManager manager) {}
|
||||
Content createNewContent(Test test) {}
|
||||
|
||||
}
|
||||
interface DockManager {}
|
||||
interface Content {}
|
||||
""")
|
||||
|
||||
onLineStartingWith("createContent").assertInlays("manager->null")
|
||||
onLineStartingWith("createNewContent").assertInlays("test->this")
|
||||
}
|
||||
|
||||
fun `test do not inline builder pattern`() {
|
||||
setup("""
|
||||
class Builder {
|
||||
|
||||
Reference in New Issue
Block a user