@Override
 public void visitNewExpression(@NotNull PsiNewExpression expression) {
   if (!PsiUtil.isLanguageLevel5OrHigher(expression)) {
     return;
   }
   super.visitNewExpression(expression);
   final PsiType type = expression.getType();
   if (type == null) {
     return;
   }
   final String canonicalText = type.getCanonicalText();
   if (!cachedNumberTypes.contains(canonicalText)) {
     return;
   }
   final PsiClass aClass = ClassUtils.getContainingClass(expression);
   if (aClass != null && cachedNumberTypes.contains(aClass.getQualifiedName())) {
     return;
   }
   final PsiExpressionList argumentList = expression.getArgumentList();
   if (argumentList == null) {
     return;
   }
   final PsiExpression[] arguments = argumentList.getExpressions();
   if (arguments.length != 1) {
     return;
   }
   final PsiExpression argument = arguments[0];
   final PsiType argumentType = argument.getType();
   if (argumentType == null || argumentType.equalsToText("java.lang.String")) {
     return;
   }
   registerError(expression, expression);
 }
Example #2
0
 public boolean isAvailable(
     @NotNull Project project, Editor editor, @Nullable PsiElement element) {
   if (element == null) return false;
   if (!PsiUtil.isLanguageLevel5OrHigher(element)) return false;
   if (!element.isWritable()) return false;
   return findVariable(element) != null;
 }
  public static PsiType getType(@NotNull PsiClassObjectAccessExpression classAccessExpression) {
    GlobalSearchScope resolveScope = classAccessExpression.getResolveScope();
    PsiManager manager = classAccessExpression.getManager();
    final PsiClass classClass =
        JavaPsiFacade.getInstance(manager.getProject()).findClass("java.lang.Class", resolveScope);
    if (classClass == null) {
      return new PsiClassReferenceType(
          new LightClassReference(manager, "Class", "java.lang.Class", resolveScope), null);
    }
    if (!PsiUtil.isLanguageLevel5OrHigher(classAccessExpression)) {
      // Raw java.lang.Class
      return JavaPsiFacade.getInstance(manager.getProject())
          .getElementFactory()
          .createType(classClass);
    }

    PsiSubstitutor substitutor = PsiSubstitutor.EMPTY;
    PsiType operandType = classAccessExpression.getOperand().getType();
    if (operandType instanceof PsiPrimitiveType && !PsiType.NULL.equals(operandType)) {
      if (PsiType.VOID.equals(operandType)) {
        operandType =
            JavaPsiFacade.getInstance(manager.getProject())
                .getElementFactory()
                .createTypeByFQClassName("java.lang.Void", classAccessExpression.getResolveScope());
      } else {
        operandType = ((PsiPrimitiveType) operandType).getBoxedType(classAccessExpression);
      }
    }
    final PsiTypeParameter[] typeParameters = classClass.getTypeParameters();
    if (typeParameters.length == 1) {
      substitutor = substitutor.put(typeParameters[0], operandType);
    }

    return new PsiImmediateClassType(classClass, substitutor);
  }
  @NotNull
  @Override
  public PsiElementVisitor buildVisitor(@NotNull ProblemsHolder holder, boolean isOnTheFly) {
    PsiFile file = holder.getFile();
    if (!PsiUtil.isLanguageLevel5OrHigher(file)) return new PsiElementVisitor() {};

    return super.buildVisitor(holder, isOnTheFly);
  }
 @Override
 public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
   return PsiUtil.isLanguageLevel5OrHigher(file)
       && myMethodCall.getElement() != null
       && myMethodCall.getElement().isValid()
       && myMethodCall.getElement().getMethodExpression().getQualifierExpression() == null
       && file.getManager().isInProject(file)
       && !(candidates == null ? candidates = getMethodsToImport() : candidates).isEmpty();
 }
 @NotNull
 @Override
 public PsiElementVisitor buildVisitor(@NotNull ProblemsHolder holder, boolean isOnTheFly) {
   PsiFile psiFile = holder.getFile();
   if (psiFile.getLanguage() != JavaLanguage.INSTANCE
       || !PsiUtil.isLanguageLevel5OrHigher(psiFile)) {
     return new PsiElementVisitor() {};
   }
   return super.buildVisitor(holder, isOnTheFly);
 }
 @Override
 public void visitElement(PsiElement element) {
   if (element.getLanguage() != JavaLanguage.INSTANCE) {
     return;
   }
   if (!PsiUtil.isLanguageLevel5OrHigher(element)) {
     return;
   }
   super.visitElement(element);
 }
Example #8
0
 @Override
 public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
   return PsiUtil.isLanguageLevel5OrHigher(file)
       && file instanceof PsiJavaFile
       && getElement() != null
       && getElement().isValid()
       && getQualifierExpression() == null
       && resolveRef() == null
       && file.getManager().isInProject(file)
       && !(candidates == null ? candidates = getMembersToImport(false) : candidates).isEmpty();
 }
 private static ThreeState isReferenceToAnnotation(final PsiElement psiElement) {
   if (!PsiUtil.isLanguageLevel5OrHigher(psiElement)) {
     return ThreeState.NO;
   }
   if (PsiTreeUtil.getParentOfType(psiElement, PsiAnnotation.class) != null) {
     return ThreeState.YES;
   }
   if (PsiTreeUtil.getParentOfType(psiElement, PsiImportStatement.class) != null) {
     return ThreeState.UNSURE;
   }
   return ThreeState.NO;
 }
  @Override
  public boolean isAvailable(
      @NotNull Project project,
      @NotNull PsiFile file,
      @NotNull PsiElement startElement,
      @NotNull PsiElement endElement) {
    if (!startElement.isValid()) return false;
    if (!PsiUtil.isLanguageLevel5OrHigher(startElement)) return false;
    final PsiModifierListOwner myModifierListOwner = (PsiModifierListOwner) startElement;

    return !AnnotationUtil.isAnnotated(myModifierListOwner, myAnnotation, false);
  }
  /**
   * Allows to check if static import may be performed for the given element.
   *
   * @param element element to check
   * @return target class that may be statically imported if any; <code>null</code> otherwise
   */
  @Nullable
  public static PsiClass getClassToPerformStaticImport(@NotNull PsiElement element) {
    if (!PsiUtil.isLanguageLevel5OrHigher(element)) return null;
    if (!(element instanceof PsiIdentifier)
        || !(element.getParent() instanceof PsiJavaCodeReferenceElement)) {
      return null;
    }
    PsiJavaCodeReferenceElement refExpr = (PsiJavaCodeReferenceElement) element.getParent();
    if (refExpr instanceof PsiMethodReferenceExpression) return null;
    final PsiElement gParent = refExpr.getParent();
    if (gParent instanceof PsiMethodReferenceExpression) return null;
    if (!(gParent instanceof PsiJavaCodeReferenceElement)
        || isParameterizedReference((PsiJavaCodeReferenceElement) gParent)) return null;

    PsiElement resolved = refExpr.resolve();
    if (!(resolved instanceof PsiClass)) {
      return null;
    }
    PsiClass psiClass = (PsiClass) resolved;
    if (PsiUtil.isFromDefaultPackage(psiClass)
        || psiClass.hasModifierProperty(PsiModifier.PRIVATE)
        || psiClass.getQualifiedName() == null) return null;

    final PsiElement ggParent = gParent.getParent();
    if (ggParent instanceof PsiMethodCallExpression) {
      final PsiMethodCallExpression call = (PsiMethodCallExpression) ggParent.copy();
      final PsiElement qualifier = call.getMethodExpression().getQualifier();
      if (qualifier == null) return null;
      qualifier.delete();
      final PsiMethod method = call.resolveMethod();
      if (method != null && method.getContainingClass() != psiClass) return null;
    } else {
      final PsiJavaCodeReferenceElement copy = (PsiJavaCodeReferenceElement) gParent.copy();
      final PsiElement qualifier = copy.getQualifier();
      if (qualifier == null) return null;
      qualifier.delete();
      final PsiElement target = copy.resolve();
      if (target != null && PsiTreeUtil.getParentOfType(target, PsiClass.class) != psiClass)
        return null;
    }

    PsiFile file = refExpr.getContainingFile();
    if (!(file instanceof PsiJavaFile)) return null;
    PsiImportList importList = ((PsiJavaFile) file).getImportList();
    if (importList == null) return null;

    return psiClass;
  }
 @Nullable
 @Override
 public CommonProblemDescriptor[] checkElement(
     @NotNull RefEntity refEntity,
     @NotNull AnalysisScope scope,
     @NotNull InspectionManager manager,
     @NotNull GlobalInspectionContext globalContext) {
   if (!(refEntity instanceof RefPackage)) {
     return null;
   }
   final RefPackage refPackage = (RefPackage) refEntity;
   final String packageName = refPackage.getQualifiedName();
   final Project project = globalContext.getProject();
   final PsiPackage aPackage = JavaPsiFacade.getInstance(project).findPackage(packageName);
   if (aPackage == null) {
     return null;
   }
   final List<RefEntity> children = refPackage.getChildren();
   boolean hasClasses = false;
   for (RefEntity child : children) {
     if (child instanceof RefClass) {
       hasClasses = true;
       break;
     }
   }
   if (!hasClasses) {
     return null;
   }
   final PsiDirectory[] directories = aPackage.getDirectories();
   for (PsiDirectory directory : directories) {
     final boolean packageInfoFound = directory.findFile(PsiPackage.PACKAGE_INFO_FILE) != null;
     final boolean packageDotHtmlFound = directory.findFile("package.html") != null;
     if (packageInfoFound || packageDotHtmlFound) {
       return null;
     }
   }
   if (PsiUtil.isLanguageLevel5OrHigher(aPackage)) {
     return new CommonProblemDescriptor[] {
       manager.createProblemDescriptor(
           InspectionGadgetsBundle.message("missing.package.info.problem.descriptor", packageName))
     };
   } else {
     return new CommonProblemDescriptor[] {
       manager.createProblemDescriptor(
           InspectionGadgetsBundle.message("missing.package.html.problem.descriptor", packageName))
     };
   }
 }
 @Override
 public void visitForStatement(
   @NotNull PsiForStatement forStatement) {
   super.visitForStatement(forStatement);
   if (!PsiUtil.isLanguageLevel5OrHigher(forStatement)) {
     return;
   }
   if (isArrayLoopStatement(forStatement)
       || isCollectionLoopStatement(forStatement,
                                    ignoreUntypedCollections)
       || (REPORT_INDEXED_LOOP &&
           isIndexedListLoopStatement(forStatement,
                                      ignoreUntypedCollections))) {
     registerStatementError(forStatement);
   }
 }
 @Nullable
 private static String getCollectionsAddAllText(PsiForeachStatement foreachStatement)
     throws IncorrectOperationException {
   final PsiStatement body = getBody(foreachStatement);
   if (!(body instanceof PsiExpressionStatement)) {
     return null;
   }
   final PsiExpressionStatement expressionStatement = (PsiExpressionStatement) body;
   final PsiMethodCallExpression methodCallExpression =
       (PsiMethodCallExpression) expressionStatement.getExpression();
   final PsiReferenceExpression methodExpression = methodCallExpression.getMethodExpression();
   final PsiElement collection = methodExpression.getQualifier();
   if (collection == null) {
     // fixme for when the array is added to 'this'
     return null;
   }
   final String collectionText = collection.getText();
   final PsiExpression iteratedValue = foreachStatement.getIteratedValue();
   if (iteratedValue == null) {
     return null;
   }
   final String arrayText = iteratedValue.getText();
   @NonNls final StringBuilder buffer = new StringBuilder();
   if (PsiUtil.isLanguageLevel5OrHigher(foreachStatement)) {
     buffer.append("java.util.Collections.addAll(");
     buffer.append(collectionText);
     buffer.append(',');
     buffer.append(arrayText);
     buffer.append(");");
   } else {
     buffer.append(collectionText);
     buffer.append(".addAll(java.util.Arrays.asList(");
     buffer.append(arrayText);
     buffer.append("));");
   }
   return buffer.toString();
 }
  static void setupPatternMethods(
      PsiManager manager,
      GlobalSearchScope searchScope,
      List<PsiMethod> patternMethods,
      IntArrayList indices) {
    final JavaPsiFacade javaPsiFacade = JavaPsiFacade.getInstance(manager.getProject());
    final PsiClass collectionClass =
        javaPsiFacade.findClass(CommonClassNames.JAVA_UTIL_COLLECTION, searchScope);
    PsiType[] javaLangObject = {PsiType.getJavaLangObject(manager, searchScope)};
    MethodSignature removeSignature =
        MethodSignatureUtil.createMethodSignature(
            "remove", javaLangObject, PsiTypeParameter.EMPTY_ARRAY, PsiSubstitutor.EMPTY);
    if (collectionClass != null) {
      PsiMethod remove =
          MethodSignatureUtil.findMethodBySignature(collectionClass, removeSignature, false);
      addMethod(remove, 0, patternMethods, indices);

      MethodSignature containsSignature =
          MethodSignatureUtil.createMethodSignature(
              "contains", javaLangObject, PsiTypeParameter.EMPTY_ARRAY, PsiSubstitutor.EMPTY);
      PsiMethod contains =
          MethodSignatureUtil.findMethodBySignature(collectionClass, containsSignature, false);
      addMethod(contains, 0, patternMethods, indices);

      if (PsiUtil.isLanguageLevel5OrHigher(collectionClass)) {
        PsiClassType wildcardCollection =
            javaPsiFacade
                .getElementFactory()
                .createType(collectionClass, PsiWildcardType.createUnbounded(manager));
        MethodSignature removeAllSignature =
            MethodSignatureUtil.createMethodSignature(
                "removeAll",
                new PsiType[] {wildcardCollection},
                PsiTypeParameter.EMPTY_ARRAY,
                PsiSubstitutor.EMPTY);
        PsiMethod removeAll =
            MethodSignatureUtil.findMethodBySignature(collectionClass, removeAllSignature, false);
        addMethod(removeAll, 0, patternMethods, indices);
      }
    }

    final PsiClass listClass =
        javaPsiFacade.findClass(CommonClassNames.JAVA_UTIL_LIST, searchScope);
    if (listClass != null) {
      MethodSignature indexofSignature =
          MethodSignatureUtil.createMethodSignature(
              "indexOf", javaLangObject, PsiTypeParameter.EMPTY_ARRAY, PsiSubstitutor.EMPTY);
      PsiMethod indexof =
          MethodSignatureUtil.findMethodBySignature(listClass, indexofSignature, false);
      addMethod(indexof, 0, patternMethods, indices);
      MethodSignature lastindexofSignature =
          MethodSignatureUtil.createMethodSignature(
              "lastIndexOf", javaLangObject, PsiTypeParameter.EMPTY_ARRAY, PsiSubstitutor.EMPTY);
      PsiMethod lastindexof =
          MethodSignatureUtil.findMethodBySignature(listClass, lastindexofSignature, false);
      addMethod(lastindexof, 0, patternMethods, indices);
    }

    final PsiClass mapClass = javaPsiFacade.findClass(CommonClassNames.JAVA_UTIL_MAP, searchScope);
    if (mapClass != null) {
      PsiMethod remove =
          MethodSignatureUtil.findMethodBySignature(mapClass, removeSignature, false);
      addMethod(remove, 0, patternMethods, indices);
      MethodSignature getSignature =
          MethodSignatureUtil.createMethodSignature(
              "get", javaLangObject, PsiTypeParameter.EMPTY_ARRAY, PsiSubstitutor.EMPTY);
      PsiMethod get = MethodSignatureUtil.findMethodBySignature(mapClass, getSignature, false);
      addMethod(get, 0, patternMethods, indices);
      MethodSignature containsKeySignature =
          MethodSignatureUtil.createMethodSignature(
              "containsKey", javaLangObject, PsiTypeParameter.EMPTY_ARRAY, PsiSubstitutor.EMPTY);
      PsiMethod containsKey =
          MethodSignatureUtil.findMethodBySignature(mapClass, containsKeySignature, false);
      addMethod(containsKey, 0, patternMethods, indices);
      MethodSignature containsValueSignature =
          MethodSignatureUtil.createMethodSignature(
              "containsValue", javaLangObject, PsiTypeParameter.EMPTY_ARRAY, PsiSubstitutor.EMPTY);
      PsiMethod containsValue =
          MethodSignatureUtil.findMethodBySignature(mapClass, containsValueSignature, false);
      addMethod(containsValue, 1, patternMethods, indices);
    }

    final PsiClass concurrentMapClass =
        javaPsiFacade.findClass(CommonClassNames.JAVA_UTIL_CONCURRENT_HASH_MAP, searchScope);
    if (concurrentMapClass != null) {
      MethodSignature containsSignature =
          MethodSignatureUtil.createMethodSignature(
              "contains", javaLangObject, PsiTypeParameter.EMPTY_ARRAY, PsiSubstitutor.EMPTY);
      PsiMethod contains =
          MethodSignatureUtil.findMethodBySignature(concurrentMapClass, containsSignature, false);
      addMethod(contains, 1, patternMethods, indices);
    }
  }
  private void doMoveMethod(PsiSubstitutor substitutor, MemberInfo info) {
    PsiElementFactory elementFactory = JavaPsiFacade.getElementFactory(myProject);
    PsiMethod method = (PsiMethod) info.getMember();
    PsiMethod sibling = method;
    PsiMethod anchor = null;
    while (sibling != null) {
      sibling = PsiTreeUtil.getNextSiblingOfType(sibling, PsiMethod.class);
      if (sibling != null) {
        anchor =
            MethodSignatureUtil.findMethodInSuperClassBySignatureInDerived(
                method.getContainingClass(),
                myTargetSuperClass,
                sibling.getSignature(PsiSubstitutor.EMPTY),
                false);
        if (anchor != null) {
          break;
        }
      }
    }
    PsiMethod methodCopy = (PsiMethod) method.copy();
    Language language = myTargetSuperClass.getLanguage();
    final PsiMethod superClassMethod = myTargetSuperClass.findMethodBySignature(methodCopy, false);
    if (superClassMethod != null && superClassMethod.findDeepestSuperMethods().length == 0
        || method.findSuperMethods(myTargetSuperClass).length == 0) {
      deleteOverrideAnnotationIfFound(methodCopy);
    }
    boolean isOriginalMethodAbstract =
        method.hasModifierProperty(PsiModifier.ABSTRACT)
            || method.hasModifierProperty(PsiModifier.DEFAULT);
    boolean isOriginalMethodPrototype =
        method instanceof HaxeFunctionPrototypeDeclarationWithAttributes;
    if (myIsTargetInterface || info.isToAbstract()) {
      ChangeContextUtil.clearContextInfo(method);

      if (!info.isToAbstract()
          && !method.hasModifierProperty(PsiModifier.ABSTRACT)
          && PsiUtil.isLanguageLevel8OrHigher(myTargetSuperClass)) {
        // pull as default
        RefactoringUtil.makeMethodDefault(methodCopy);
        isOriginalMethodAbstract = true;
      } else {
        RefactoringUtil.makeMethodAbstract(myTargetSuperClass, methodCopy);
      }

      RefactoringUtil.replaceMovedMemberTypeParameters(
          methodCopy, PsiUtil.typeParametersIterable(mySourceClass), substitutor, elementFactory);

      myJavaDocPolicy.processCopiedJavaDoc(
          methodCopy.getDocComment(), method.getDocComment(), isOriginalMethodAbstract);

      final PsiMember movedElement;
      if (superClassMethod != null && superClassMethod.hasModifierProperty(PsiModifier.ABSTRACT)) {
        movedElement =
            (PsiMember) superClassMethod.replace(convertMethodToLanguage(methodCopy, language));
      } else {
        methodCopy =
            HaxeElementGenerator.createFunctionPrototypeDeclarationWithAttributes(
                myProject, methodCopy.getText().trim() + ";");

        movedElement =
            anchor != null
                ? (PsiMember) myTargetSuperClass.addBefore(methodCopy, anchor)
                : (PsiMember)
                    myTargetSuperClass.addBefore(methodCopy, myTargetSuperClass.getRBrace());

        reformat(movedElement);
      }
      CodeStyleSettings styleSettings = CodeStyleSettingsManager.getSettings(method.getProject());
      if (styleSettings.INSERT_OVERRIDE_ANNOTATION) {
        if (PsiUtil.isLanguageLevel5OrHigher(mySourceClass) && !myIsTargetInterface
            || PsiUtil.isLanguageLevel6OrHigher(mySourceClass)) {
          new AddAnnotationFix(Override.class.getName(), method)
              .invoke(method.getProject(), null, mySourceClass.getContainingFile());
        }
      }
      if (!PsiUtil.isLanguageLevel6OrHigher(mySourceClass) && myIsTargetInterface) {
        if (isOriginalMethodAbstract) {
          for (PsiMethod oMethod : OverridingMethodsSearch.search(method)) {
            deleteOverrideAnnotationIfFound(oMethod);
          }
        }
        deleteOverrideAnnotationIfFound(method);
      }
      myMembersAfterMove.add(movedElement);
      // if (isOriginalMethodAbstract) {
      method.delete();
      // }
    } else {
      if (isOriginalMethodAbstract) {
        PsiUtil.setModifierProperty(myTargetSuperClass, PsiModifier.ABSTRACT, true);
      }
      RefactoringUtil.replaceMovedMemberTypeParameters(
          methodCopy, PsiUtil.typeParametersIterable(mySourceClass), substitutor, elementFactory);
      fixReferencesToStatic(methodCopy);

      if (superClassMethod != null && superClassMethod.hasModifierProperty(PsiModifier.ABSTRACT)) {
        superClassMethod.replace(convertMethodToLanguage(methodCopy, language));
      } else {
        final PsiMember movedElement =
            anchor != null
                ? (PsiMember)
                    myTargetSuperClass.addBefore(
                        convertMethodToLanguage(methodCopy, language), anchor)
                : (PsiMember)
                    myTargetSuperClass.addBefore(
                        convertMethodToLanguage(methodCopy, language),
                        myTargetSuperClass.getRBrace());
        reformat(movedElement);
        myMembersAfterMove.add(movedElement);
      }
      method.delete();
    }
  }
  private void doMoveMethod(PsiSubstitutor substitutor, GrMemberInfo info) {
    GroovyPsiElementFactory elementFactory = GroovyPsiElementFactory.getInstance(myProject);
    GrMethod method = (GrMethod) info.getMember();
    PsiMethod sibling = method;
    PsiMethod anchor = null;
    while (sibling != null) {
      sibling = PsiTreeUtil.getNextSiblingOfType(sibling, PsiMethod.class);
      if (sibling != null) {
        anchor =
            MethodSignatureUtil.findMethodInSuperClassBySignatureInDerived(
                method.getContainingClass(),
                myTargetSuperClass,
                sibling.getSignature(PsiSubstitutor.EMPTY),
                false);
        if (anchor != null) {
          break;
        }
      }
    }

    GrMethod methodCopy = (GrMethod) method.copy();
    if (method.findSuperMethods(myTargetSuperClass).length == 0) {
      deleteOverrideAnnotationIfFound(methodCopy);
    }

    final boolean isOriginalMethodAbstract =
        method.hasModifierProperty(PsiModifier.ABSTRACT)
            || method.hasModifierProperty(PsiModifier.DEFAULT);
    if (myTargetSuperClass.isInterface() || info.isToAbstract()) {
      GroovyChangeContextUtil.clearContextInfo(method);
      RefactoringUtil.makeMethodAbstract(myTargetSuperClass, methodCopy);
      if (myTargetSuperClass.isInterface()) {
        PsiUtil.setModifierProperty(methodCopy, PsiModifier.ABSTRACT, false);
      }
      replaceMovedMemberTypeParameters(
          methodCopy, PsiUtil.typeParametersIterable(mySourceClass), substitutor, elementFactory);

      final GrMethod movedElement =
          anchor != null
              ? (GrMethod) myTargetSuperClass.addBefore(methodCopy, anchor)
              : (GrMethod) myTargetSuperClass.add(methodCopy);
      CodeStyleSettings styleSettings = CodeStyleSettingsManager.getSettings(method.getProject());
      if (styleSettings.INSERT_OVERRIDE_ANNOTATION) {
        if (PsiUtil.isLanguageLevel5OrHigher(mySourceClass) && !myTargetSuperClass.isInterface()
            || PsiUtil.isLanguageLevel6OrHigher(mySourceClass)) {
          new AddAnnotationFix(CommonClassNames.JAVA_LANG_OVERRIDE, method)
              .invoke(method.getProject(), null, mySourceClass.getContainingFile());
        }
      }

      GrDocComment oldDoc = method.getDocComment();
      if (oldDoc != null) {
        GrDocCommentUtil.setDocComment(movedElement, oldDoc);
      }

      myDocCommentPolicy.processCopiedJavaDoc(
          methodCopy.getDocComment(), oldDoc, isOriginalMethodAbstract);

      myMembersAfterMove.add(movedElement);
      if (isOriginalMethodAbstract) {
        deleteMemberWithDocComment(method);
      }
    } else {
      if (isOriginalMethodAbstract) {
        PsiUtil.setModifierProperty(myTargetSuperClass, PsiModifier.ABSTRACT, true);
      }

      // fixReferencesToStatic(methodCopy, movedMembers);
      replaceMovedMemberTypeParameters(
          methodCopy, PsiUtil.typeParametersIterable(mySourceClass), substitutor, elementFactory);
      final PsiMethod superClassMethod =
          myTargetSuperClass.findMethodBySignature(methodCopy, false);
      final GrMethod movedElement;
      if (superClassMethod != null && superClassMethod.hasModifierProperty(PsiModifier.ABSTRACT)) {
        movedElement = (GrMethod) superClassMethod.replace(methodCopy);
      } else {
        movedElement =
            anchor != null
                ? (GrMethod) myTargetSuperClass.addBefore(methodCopy, anchor)
                : (GrMethod) myTargetSuperClass.add(methodCopy);
        myMembersAfterMove.add(movedElement);
      }

      GrDocCommentUtil.setDocComment(movedElement, method.getDocComment());

      deleteMemberWithDocComment(method);
    }
  }
 @Nullable
 private static String getCollectionsAddAllText(PsiForStatement forStatement)
     throws IncorrectOperationException {
   final PsiExpression expression = forStatement.getCondition();
   final PsiBinaryExpression condition =
       (PsiBinaryExpression) ParenthesesUtils.stripParentheses(expression);
   if (condition == null) {
     return null;
   }
   final PsiStatement initialization = forStatement.getInitialization();
   if (initialization == null) {
     return null;
   }
   if (!(initialization instanceof PsiDeclarationStatement)) {
     return null;
   }
   final PsiDeclarationStatement declaration = (PsiDeclarationStatement) initialization;
   final PsiElement[] declaredElements = declaration.getDeclaredElements();
   if (declaredElements.length != 1) {
     return null;
   }
   final PsiElement declaredElement = declaredElements[0];
   if (!(declaredElement instanceof PsiLocalVariable)) {
     return null;
   }
   final PsiLocalVariable variable = (PsiLocalVariable) declaredElement;
   final String collectionText = buildCollectionText(forStatement);
   final PsiArrayAccessExpression arrayAccessExpression = getArrayAccessExpression(forStatement);
   if (arrayAccessExpression == null) {
     return null;
   }
   final PsiExpression arrayExpression = arrayAccessExpression.getArrayExpression();
   final String arrayText = arrayExpression.getText();
   final PsiExpression indexExpression = arrayAccessExpression.getIndexExpression();
   final String fromOffsetText = buildFromOffsetText(indexExpression, variable);
   if (fromOffsetText == null) {
     return null;
   }
   final PsiExpression limit;
   final IElementType tokenType = condition.getOperationTokenType();
   if (tokenType == JavaTokenType.LT || tokenType == JavaTokenType.LE) {
     limit = condition.getROperand();
   } else {
     limit = condition.getLOperand();
   }
   @NonNls
   final String toOffsetText =
       buildToOffsetText(limit, tokenType == JavaTokenType.LE || tokenType == JavaTokenType.GE);
   if (toOffsetText == null) {
     return null;
   }
   if (fromOffsetText.equals("0")
       && toOffsetText.equals(arrayText + ".length")
       && PsiUtil.isLanguageLevel5OrHigher(forStatement)) {
     return "java.util.Collections.addAll(" + collectionText + ',' + arrayText + ");";
   } else {
     @NonNls final StringBuilder buffer = new StringBuilder();
     buffer.append(collectionText);
     buffer.append('.');
     buffer.append("addAll(java.util.Arrays.asList(");
     buffer.append(arrayText);
     buffer.append(')');
     if (!fromOffsetText.equals("0") || !toOffsetText.equals(arrayText + ".length")) {
       buffer.append(".subList(");
       buffer.append(fromOffsetText);
       buffer.append(", ");
       buffer.append(toOffsetText);
       buffer.append(')');
     }
     buffer.append(");");
     return buffer.toString();
   }
 }