@Override public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) { final PsiReferenceParameterList typeArgumentList = (PsiReferenceParameterList) descriptor.getPsiElement(); if (!FileModificationService.getInstance().preparePsiElementForWrite(typeArgumentList)) return; try { final PsiMethodCallExpression expr = (PsiMethodCallExpression) JavaPsiFacade.getInstance(project) .getElementFactory() .createExpressionFromText("foo()", null); typeArgumentList.replace(expr.getTypeArgumentList()); } catch (IncorrectOperationException e) { LOG.error(e); } }
private void reportCallMayProduceNpe( ProblemsHolder holder, PsiMethodCallExpression callExpression, boolean onTheFly) { LocalQuickFix[] fix = createNPEFixes( callExpression.getMethodExpression().getQualifierExpression(), callExpression, onTheFly); holder.registerProblem( callExpression, InspectionsBundle.message("dataflow.message.npe.method.invocation"), fix); }
private static boolean canCallMethodsInConstructors(PsiClass aClass, boolean virtual) { for (PsiMethod constructor : aClass.getConstructors()) { if (!constructor.getLanguage().isKindOf(JavaLanguage.INSTANCE)) return true; PsiCodeBlock body = constructor.getBody(); if (body == null) continue; for (PsiMethodCallExpression call : SyntaxTraverser.psiTraverser().withRoot(body).filter(PsiMethodCallExpression.class)) { PsiReferenceExpression methodExpression = call.getMethodExpression(); if (methodExpression instanceof PsiThisExpression || methodExpression instanceof PsiSuperExpression) continue; if (!virtual) return true; PsiMethod target = call.resolveMethod(); if (target != null && PsiUtil.canBeOverriden(target)) return true; } } return false; }