@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 static boolean isInExtendsList( final RefJavaElement to, final PsiReferenceList extendsList) { if (extendsList != null) { final PsiJavaCodeReferenceElement[] referenceElements = extendsList.getReferenceElements(); for (PsiJavaCodeReferenceElement referenceElement : referenceElements) { final PsiReferenceParameterList parameterList = referenceElement.getParameterList(); if (parameterList != null) { for (PsiType type : parameterList.getTypeArguments()) { if (extendsList .getManager() .areElementsEquivalent(PsiUtil.resolveClassInType(type), to.getElement())) { return true; } } } } } return false; }