@Override public void doFix(Project project, ProblemDescriptor descriptor) throws IncorrectOperationException { final PsiElement methodNameElement = descriptor.getPsiElement(); final PsiReferenceExpression methodExpression = (PsiReferenceExpression) methodNameElement.getParent(); assert methodExpression != null; final PsiExpression qualifier = methodExpression.getQualifierExpression(); if (qualifier == null) { PsiReplacementUtil.replaceExpression(methodExpression, HardcodedMethodConstants.NOTIFY_ALL); } else { final String qualifierText = qualifier.getText(); PsiReplacementUtil.replaceExpression( methodExpression, qualifierText + '.' + HardcodedMethodConstants.NOTIFY_ALL); } }
@Override public void doFix(Project project, ProblemDescriptor descriptor) throws IncorrectOperationException { final PsiIdentifier name = (PsiIdentifier) descriptor.getPsiElement(); final PsiReferenceExpression expression = (PsiReferenceExpression) name.getParent(); if (expression == null) { return; } final PsiMethodCallExpression call = (PsiMethodCallExpression) expression.getParent(); final String methodName = expression.getReferenceName(); if (call == null) { return; } final PsiMethod method = call.resolveMethod(); if (method == null) { return; } final PsiClass containingClass = method.getContainingClass(); final PsiExpressionList argumentList = call.getArgumentList(); if (containingClass == null) { return; } final String containingClassName = containingClass.getQualifiedName(); final String argText = argumentList.getText(); PsiReplacementUtil.replaceExpressionAndShorten( call, containingClassName + '.' + methodName + argText); }
@Override protected void doFix(Project project, ProblemDescriptor descriptor) throws IncorrectOperationException { final PsiMethodCallExpression methodCallExpression = (PsiMethodCallExpression) descriptor.getPsiElement().getParent().getParent(); final PsiReferenceExpression methodExpression = methodCallExpression.getMethodExpression(); final PsiExpression qualifier = methodExpression.getQualifierExpression(); if (qualifier == null) { PsiReplacementUtil.replaceExpression(methodCallExpression, "this"); } else { methodCallExpression.replace(qualifier); } }
@Override public void doFix(Project project, ProblemDescriptor descriptor) throws IncorrectOperationException { final PsiElement forElement = descriptor.getPsiElement(); final PsiElement parent = forElement.getParent(); final String newExpression; if (parent instanceof PsiForStatement) { final PsiForStatement forStatement = (PsiForStatement) parent; newExpression = getCollectionsAddAllText(forStatement); if (newExpression == null) { return; } PsiReplacementUtil.replaceStatementAndShortenClassNames(forStatement, newExpression); } else { final PsiForeachStatement foreachStatement = (PsiForeachStatement) parent; newExpression = getCollectionsAddAllText(foreachStatement); if (newExpression == null) { return; } PsiReplacementUtil.replaceStatementAndShortenClassNames(foreachStatement, newExpression); } }
@Override public void doFix(Project project, ProblemDescriptor descriptor) throws IncorrectOperationException { final PsiElement forElement = descriptor.getPsiElement(); final PsiElement parent = forElement.getParent(); if (!(parent instanceof PsiForStatement)) { return; } final PsiForStatement forStatement = (PsiForStatement) parent; final String newExpression; if (isArrayLoopStatement(forStatement)) { newExpression = createArrayIterationText(forStatement); } else if (isCollectionLoopStatement(forStatement, ignoreUntypedCollections)) { newExpression = createCollectionIterationText(forStatement); } else if (isIndexedListLoopStatement(forStatement, ignoreUntypedCollections)) { newExpression = createListIterationText(forStatement); } else { return; } if (newExpression == null) { return; } PsiReplacementUtil.replaceStatementAndShortenClassNames(forStatement, newExpression); }