@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);
   }
 }
コード例 #2
0
 @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);
 }