private static void checkCall( @NotNull PsiCallExpression methodCall, @NotNull ProblemsHolder holder) { PsiMethod method = methodCall.resolveMethod(); if (method == null) return; PsiParameter[] parameters = method.getParameterList().getParameters(); PsiExpression[] arguments = methodCall.getArgumentList().getExpressions(); for (int i = 0; i < parameters.length; i++) { PsiParameter parameter = parameters[i]; AllowedValues values = getAllowedValues(parameter, parameter.getType(), null); if (values == null) continue; if (i >= arguments.length) break; PsiExpression argument = arguments[i]; argument = PsiUtil.deparenthesizeExpression(argument); if (argument == null) continue; checkMagicParameterArgument(parameter, argument, values, holder); } }
private static boolean isTrivial(PsiStatement body, PsiParameter parameter) { final PsiIfStatement ifStatement = extractIfStatement(body); // filter if (ifStatement != null) { return false; } // method reference final PsiCallExpression callExpression = LambdaCanBeMethodReferenceInspection.canBeMethodReferenceProblem( body instanceof PsiBlockStatement ? ((PsiBlockStatement) body).getCodeBlock() : body, new PsiParameter[] {parameter}, createDefaultConsumerType(parameter.getProject(), parameter)); if (callExpression == null) { return true; } final PsiMethod method = callExpression.resolveMethod(); return method != null && isThrowsCompatible(method); }
private static void addDelegateArguments( JavaChangeInfo changeInfo, PsiElementFactory factory, final PsiCallExpression callExpression) throws IncorrectOperationException { final JavaParameterInfo[] newParms = changeInfo.getNewParameters(); final String[] oldParameterNames = changeInfo.getOldParameterNames(); for (int i = 0; i < newParms.length; i++) { JavaParameterInfo newParm = newParms[i]; final PsiExpression actualArg; if (newParm.getOldIndex() >= 0) { actualArg = factory.createExpressionFromText( oldParameterNames[newParm.getOldIndex()], callExpression); } else { actualArg = changeInfo.getValue(i, callExpression); } JavaCodeStyleManager.getInstance(callExpression.getProject()) .shortenClassReferences(callExpression.getArgumentList().add(actualArg)); } }