public ExtractClassProcessor(
     PsiClass sourceClass,
     List<PsiField> fields,
     List<PsiMethod> methods,
     List<PsiClass> classes,
     String packageName,
     MoveDestination moveDestination,
     String newClassName,
     String newVisibility,
     boolean generateAccessors,
     List<MemberInfo> enumConstants) {
   super(sourceClass.getProject());
   this.sourceClass = sourceClass;
   this.newPackageName = packageName;
   myMoveDestination = moveDestination;
   myNewVisibility = newVisibility;
   myGenerateAccessors = generateAccessors;
   this.enumConstants = new ArrayList<PsiField>();
   for (MemberInfo constant : enumConstants) {
     if (constant.isChecked()) {
       this.enumConstants.add((PsiField) constant.getMember());
     }
   }
   this.fields = new ArrayList<PsiField>(fields);
   this.methods = new ArrayList<PsiMethod>(methods);
   this.innerClasses = new ArrayList<PsiClass>(classes);
   this.newClassName = newClassName;
   delegateFieldName = calculateDelegateFieldName();
   requiresBackpointer =
       new BackpointerUsageVisitor(fields, innerClasses, methods, sourceClass)
           .backpointerRequired();
   if (requiresBackpointer) {
     ContainerUtil.addAll(typeParams, sourceClass.getTypeParameters());
   } else {
     final Set<PsiTypeParameter> typeParamSet = new HashSet<PsiTypeParameter>();
     final TypeParametersVisitor visitor = new TypeParametersVisitor(typeParamSet);
     for (PsiField field : fields) {
       field.accept(visitor);
     }
     for (PsiMethod method : methods) {
       method.accept(visitor);
       // do not include method's type parameters in class signature
       typeParamSet.removeAll(Arrays.asList(method.getTypeParameters()));
     }
     typeParams.addAll(typeParamSet);
   }
   myClass =
       new WriteCommandAction<PsiClass>(myProject, getCommandName()) {
         @Override
         protected void run(@NotNull Result<PsiClass> result) throws Throwable {
           result.setResult(buildClass());
         }
       }.execute().getResultObject();
   myExtractEnumProcessor = new ExtractEnumProcessor(myProject, this.enumConstants, myClass);
 }
 public void findUsages(@NotNull List<FixableUsageInfo> usages) {
   for (final MemberInfo memberInfo : myDelegateMethodInfos) {
     if (!memberInfo.isChecked()) continue;
     final PsiMethod method = (PsiMethod) memberInfo.getMember();
     final String getterName = GenerateMembersUtil.suggestGetterName(field);
     final int[] paramPermutation = DelegationUtils.getParameterPermutation(method);
     final PsiMethod delegatedMethod = DelegationUtils.getDelegatedMethod(method);
     LOG.assertTrue(!DelegationUtils.isAbstract(method));
     processUsagesForMethod(
         memberInfo.isToAbstract(), method, paramPermutation, getterName, delegatedMethod, usages);
   }
 }
예제 #3
0
 @Override
 public int checkForProblems(@NotNull MemberInfo member) {
   if (member.isChecked()) return OK;
   PsiClass currentSuperClass = getSuperClass();
   if (currentSuperClass != null && currentSuperClass.isInterface()) {
     PsiMember element = member.getMember();
     if (element.hasModifierProperty(PsiModifier.STATIC)) {
       return super.checkForProblems(member);
     }
     return OK;
   } else {
     return super.checkForProblems(member);
   }
 }
 @Override
 protected boolean preprocessUsages(@NotNull final Ref<UsageInfo[]> refUsages) {
   final MultiMap<PsiElement, String> conflicts = new MultiMap<PsiElement, String>();
   for (MemberInfo memberInfo : myDelegateMethodInfos) {
     if (memberInfo.isChecked() && memberInfo.isToAbstract()) {
       final PsiMember psiMember = memberInfo.getMember();
       if (psiMember instanceof PsiMethod
           && ((PsiMethod) psiMember).findDeepestSuperMethods().length > 0) {
         conflicts.putValue(
             psiMember,
             SymbolPresentationUtil.getSymbolPresentableText(psiMember)
                 + " will be deleted. Hierarchy will be broken");
       }
     }
   }
   return showConflicts(conflicts, refUsages.get());
 }
예제 #5
0
  public PushDownConflicts(PsiClass aClass, MemberInfo[] memberInfos) {
    myClass = aClass;

    myMovedMembers = new HashSet<PsiMember>();
    myAbstractMembers = new HashSet<PsiMethod>();
    for (MemberInfo memberInfo : memberInfos) {
      final PsiMember member = memberInfo.getMember();
      if (memberInfo.isChecked()
          && (!(memberInfo.getMember() instanceof PsiClass) || memberInfo.getOverrides() == null)) {
        myMovedMembers.add(member);
        if (memberInfo.isToAbstract()) {
          myAbstractMembers.add((PsiMethod) member);
        }
      }
    }

    myConflicts = new MultiMap<PsiElement, String>();
  }