[Parameter Name Hints] show for single param null and this

This commit is contained in:
Yaroslav Lepenkin
2016-10-04 12:15:33 +03:00
parent e3f966a2ed
commit 71046b4a52
2 changed files with 35 additions and 2 deletions
@@ -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;
@@ -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 {