disable create method from usage/change signature based on void argument (IDEA-205710)

This commit is contained in:
Anna.Kozlova
2019-01-31 16:59:11 +01:00
parent c70be8885a
commit f2b9476d0f
4 changed files with 24 additions and 3 deletions

View File

@@ -336,7 +336,7 @@ public class ChangeMethodSignatureFromUsageFix implements IntentionAction/*, Hig
else {
if (PsiPolyExpressionUtil.isPolyExpression(expression)) return null;
PsiType exprType = RefactoringUtil.getTypeByExpression(expression);
if (exprType == null) return null;
if (exprType == null || PsiType.VOID.equals(exprType)) return null;
if (exprType instanceof PsiDisjunctionType) {
exprType = ((PsiDisjunctionType)exprType).getLeastUpperBound();
}
@@ -412,7 +412,7 @@ public class ChangeMethodSignatureFromUsageFix implements IntentionAction/*, Hig
if (varargParam != null && pi >= parameters.length) return false;
if (PsiPolyExpressionUtil.isPolyExpression(expression)) return false;
PsiType exprType = RefactoringUtil.getTypeByExpression(expression);
if (exprType == null) return false;
if (exprType == null || PsiType.VOID.equals(exprType)) return false;
if (exprType instanceof PsiDisjunctionType) {
exprType = ((PsiDisjunctionType)exprType).getLeastUpperBound();
}

View File

@@ -87,10 +87,14 @@ public class CreateMethodFromUsageFix extends CreateFromUsageBaseFix {
public static boolean hasErrorsInArgumentList(final PsiMethodCallExpression call) {
Project project = call.getProject();
PsiExpressionList argumentList = call.getArgumentList();
for (PsiExpression expression : argumentList.getExpressions()) {
PsiType type = expression.getType();
if (type == null || PsiType.VOID.equals(type)) return true;
}
Document document = PsiDocumentManager.getInstance(project).getDocument(call.getContainingFile());
if (document == null) return true;
PsiExpressionList argumentList = call.getArgumentList();
final TextRange argRange = argumentList.getTextRange();
return !DaemonCodeAnalyzerEx.processHighlights(document, project, HighlightSeverity.ERROR,
//strictly inside arg list

View File

@@ -0,0 +1,9 @@
// "Change 1st parameter of method 'foo' from 'String' to 'void'" "false"
public class S {
void bar() {}
void foo(String s) {}
{
foo(b<caret>ar());
}
}

View File

@@ -0,0 +1,8 @@
// "Create method 'bar'" "false"
class Test {
{
ba<caret>r(foo());
}
void foo() {}
}