Пример #1
0
  private String format(PsiVariable variable, PsiModifierList modifierList) {
    String name = null;
    PsiElement parent =
        variable == null ? modifierList == null ? null : modifierList.getParent() : variable;
    if (parent instanceof PsiClass) {
      name = ((PsiClass) parent).getName();
    } else {
      int options =
          PsiFormatUtilBase.SHOW_NAME
              | (myShowContainingClass ? PsiFormatUtilBase.SHOW_CONTAINING_CLASS : 0);
      if (parent instanceof PsiMethod) {
        name = PsiFormatUtil.formatMethod((PsiMethod) parent, PsiSubstitutor.EMPTY, options, 0);
      } else if (parent instanceof PsiVariable) {
        name = PsiFormatUtil.formatVariable((PsiVariable) parent, options, PsiSubstitutor.EMPTY);
      } else if (parent instanceof PsiClassInitializer) {
        PsiClass containingClass = ((PsiClassInitializer) parent).getContainingClass();
        String className =
            containingClass instanceof PsiAnonymousClass
                ? QuickFixBundle.message(
                    "anonymous.class.presentation",
                    ((PsiAnonymousClass) containingClass).getBaseClassType().getPresentableText())
                : containingClass != null ? containingClass.getName() : "unknown";
        name = QuickFixBundle.message("class.initializer.presentation", className);
      }
    }

    String modifierText = VisibilityUtil.toPresentableText(myModifier);

    return QuickFixBundle.message(
        myShouldHave ? "add.modifier.fix" : "remove.modifier.fix", name, modifierText);
  }
Пример #2
0
 private static String getMethodPrototypeString(final PsiMethod prototype) {
   return PsiFormatUtil.formatMethod(
       prototype,
       PsiSubstitutor.EMPTY,
       PsiFormatUtil.SHOW_NAME | PsiFormatUtil.SHOW_PARAMETERS,
       PsiFormatUtil.SHOW_TYPE);
 }
Пример #3
0
 public static void checkFieldConflicts(
     @Nullable PsiClass aClass, String newName, final Map<PsiElement, String> conflicts) {
   PsiField existingField = aClass != null ? aClass.findFieldByName(newName, true) : null;
   if (existingField != null) {
     if (aClass.equals(existingField.getContainingClass())) {
       String className =
           aClass instanceof PsiAnonymousClass
               ? RefactoringBundle.message("current.class")
               : RefactoringUIUtil.getDescription(aClass, false);
       final String conflict =
           RefactoringBundle.message(
               "field.0.is.already.defined.in.the.1", existingField.getName(), className);
       conflicts.put(existingField, conflict);
     } else { // method somewhere in base class
       if (!existingField.hasModifierProperty(PsiModifier.PRIVATE)) {
         String fieldInfo =
             PsiFormatUtil.formatVariable(
                 existingField,
                 PsiFormatUtil.SHOW_NAME | PsiFormatUtil.SHOW_TYPE | PsiFormatUtil.TYPE_AFTER,
                 PsiSubstitutor.EMPTY);
         String className =
             RefactoringUIUtil.getDescription(existingField.getContainingClass(), false);
         final String descr =
             RefactoringBundle.message(
                 "field.0.will.hide.field.1.of.the.base.class", newName, fieldInfo, className);
         conflicts.put(existingField, descr);
       }
     }
   }
 }
 public PsiTypeLookupItem setShowPackage() {
   Object object = getObject();
   if (object instanceof PsiClass) {
     myLocationString = " (" + PsiFormatUtil.getPackageDisplayName((PsiClass) object) + ")";
   }
   return this;
 }
 @NotNull
 private static String buildSignature(@NotNull PsiMethod method) {
   return PsiFormatUtil.formatMethod(
       method,
       PsiSubstitutor.EMPTY,
       PsiFormatUtil.SHOW_NAME | PsiFormatUtil.SHOW_PARAMETERS,
       PsiFormatUtil.SHOW_TYPE | PsiFormatUtil.SHOW_FQ_CLASS_NAMES | PsiFormatUtil.SHOW_RAW_TYPE);
 }
  private static void generateModifiers(StringBuilder buffer, PsiElement element) {
    String modifiers =
        PsiFormatUtil.formatModifiers(element, PsiFormatUtilBase.JAVADOC_MODIFIERS_ONLY);

    if (!modifiers.isEmpty()) {
      buffer.append(modifiers);
      buffer.append(" ");
    }
  }
 @NotNull
 @Override
 protected String getMemberPresentableText(PsiField field) {
   return PsiFormatUtil.formatVariable(
       field,
       PsiFormatUtilBase.SHOW_NAME
           | PsiFormatUtilBase.SHOW_CONTAINING_CLASS
           | PsiFormatUtilBase.SHOW_FQ_NAME,
       PsiSubstitutor.EMPTY);
 }
  @NotNull
  public String getText() {
    PsiLocalVariable variable = myOutOfScopeVariable;

    String varText =
        variable == null
            ? ""
            : PsiFormatUtil.formatVariable(
                variable, PsiFormatUtil.SHOW_NAME | PsiFormatUtil.SHOW_TYPE, PsiSubstitutor.EMPTY);
    return QuickFixBundle.message("bring.variable.to.scope.text", varText);
  }
  public void updateReturnValueTemplate(PsiExpression expression) {
    if (myReturnValueTemplate == null) return;

    if (!getSuperMethods().isEmpty()) {
      for (final RefMethod refMethod : getSuperMethods()) {
        RefMethodImpl refSuper = (RefMethodImpl) refMethod;
        refSuper.updateReturnValueTemplate(expression);
      }
    } else {
      String newTemplate = null;
      final RefJavaUtil refUtil = RefJavaUtil.getInstance();
      if (expression instanceof PsiLiteralExpression) {
        PsiLiteralExpression psiLiteralExpression = (PsiLiteralExpression) expression;
        newTemplate = psiLiteralExpression.getText();
      } else if (expression instanceof PsiReferenceExpression) {
        PsiReferenceExpression referenceExpression = (PsiReferenceExpression) expression;
        PsiElement resolved = referenceExpression.resolve();
        if (resolved instanceof PsiField) {
          PsiField psiField = (PsiField) resolved;
          if (psiField.hasModifierProperty(PsiModifier.STATIC)
              && psiField.hasModifierProperty(PsiModifier.FINAL)
              && refUtil.compareAccess(refUtil.getAccessModifier(psiField), getAccessModifier())
                  >= 0) {
            newTemplate =
                PsiFormatUtil.formatVariable(
                    psiField,
                    PsiFormatUtilBase.SHOW_NAME
                        | PsiFormatUtilBase.SHOW_CONTAINING_CLASS
                        | PsiFormatUtilBase.SHOW_FQ_NAME,
                    PsiSubstitutor.EMPTY);
          }
        }
      } else if (refUtil.isCallToSuperMethod(expression, (PsiMethod) getElement())) return;

      //noinspection StringEquality
      if (myReturnValueTemplate == RETURN_VALUE_UNDEFINED) {
        myReturnValueTemplate = newTemplate;
      } else if (!Comparing.equal(myReturnValueTemplate, newTemplate)) {
        myReturnValueTemplate = null;
      }
    }
  }
 @Override
 @NotNull
 public String getText() {
   String text = QuickFixBundle.message("static.import.method.text");
   if (candidates != null && candidates.size() == 1) {
     text +=
         " '"
             + PsiFormatUtil.formatMethod(
                 candidates.get(0),
                 PsiSubstitutor.EMPTY,
                 PsiFormatUtilBase.SHOW_NAME
                     | PsiFormatUtilBase.SHOW_CONTAINING_CLASS
                     | PsiFormatUtilBase.SHOW_FQ_NAME,
                 0)
             + "'";
   } else {
     text += "...";
   }
   return text;
 }
 private static String getMethodCandidateInfo(GrReferenceExpression expr) {
   final GroovyResolveResult[] candidates = expr.multiResolve(false);
   final String text = expr.getText();
   if (candidates.length > 0) {
     @NonNls final StringBuilder sb = new StringBuilder();
     for (final GroovyResolveResult candidate : candidates) {
       final PsiElement element = candidate.getElement();
       if (!(element instanceof PsiMethod)) {
         continue;
       }
       final String str =
           PsiFormatUtil.formatMethod(
               (PsiMethod) element,
               candidate.getSubstitutor(),
               PsiFormatUtilBase.SHOW_NAME
                   | PsiFormatUtilBase.SHOW_TYPE
                   | PsiFormatUtilBase.SHOW_PARAMETERS,
               PsiFormatUtilBase.SHOW_TYPE);
       createElementLink(sb, element, str);
     }
     return CodeInsightBundle.message("javadoc.candidates", text, sb);
   }
   return CodeInsightBundle.message("javadoc.candidates.not.found", text);
 }
  private static LookupElementBuilder createGenerateMethodElement(
      PsiMethod prototype,
      PsiSubstitutor substitutor,
      Icon icon,
      String typeText,
      InsertHandler<LookupElement> insertHandler) {
    String methodName = prototype.getName();

    String visibility = VisibilityUtil.getVisibilityModifier(prototype.getModifierList());
    String modifiers = (visibility == PsiModifier.PACKAGE_LOCAL ? "" : visibility + " ");

    PsiType type = substitutor.substitute(prototype.getReturnType());
    String signature =
        modifiers + (type == null ? "" : type.getPresentableText() + " ") + methodName;

    String parameters =
        PsiFormatUtil.formatMethod(
            prototype, substitutor, PsiFormatUtilBase.SHOW_PARAMETERS, PsiFormatUtilBase.SHOW_NAME);

    String overrideSignature =
        " @Override "
            + signature; // leading space to make it a middle match, under all annotation
                         // suggestions
    LookupElementBuilder element =
        LookupElementBuilder.create(prototype, signature)
            .withLookupString(methodName)
            .withLookupString(signature)
            .withLookupString(overrideSignature)
            .withInsertHandler(insertHandler)
            .appendTailText(parameters, false)
            .appendTailText(" {...}", true)
            .withTypeText(typeText)
            .withIcon(icon);
    element.putUserData(GENERATE_ELEMENT, true);
    return element;
  }
  public static String checkMethodReferenceContext(
      PsiMethodReferenceExpression methodRef, PsiElement resolve, PsiType functionalInterfaceType) {
    final PsiClass containingClass =
        resolve instanceof PsiMethod
            ? ((PsiMethod) resolve).getContainingClass()
            : (PsiClass) resolve;
    final boolean isStaticSelector = isStaticallyReferenced(methodRef);
    final PsiElement qualifier = methodRef.getQualifier();

    boolean isMethodStatic = false;
    boolean receiverReferenced = false;
    boolean isConstructor = true;

    if (resolve instanceof PsiMethod) {
      final PsiMethod method = (PsiMethod) resolve;

      isMethodStatic = method.hasModifierProperty(PsiModifier.STATIC);
      isConstructor = method.isConstructor();
      receiverReferenced = hasReceiver(methodRef, method, functionalInterfaceType);

      if (method.hasModifierProperty(PsiModifier.ABSTRACT)
          && qualifier instanceof PsiSuperExpression) {
        return "Abstract method '" + method.getName() + "' cannot be accessed directly";
      }
    }

    if (!receiverReferenced && isStaticSelector && !isMethodStatic && !isConstructor) {
      return "Non-static method cannot be referenced from a static context";
    }

    if (!receiverReferenced && !isStaticSelector && isMethodStatic) {
      return "Static method referenced through non-static qualifier";
    }

    if (receiverReferenced && isStaticSelector && isMethodStatic && !isConstructor) {
      return "Static method referenced through receiver";
    }

    if (isMethodStatic && isStaticSelector && qualifier instanceof PsiTypeElement) {
      final PsiJavaCodeReferenceElement referenceElement =
          PsiTreeUtil.getChildOfType(qualifier, PsiJavaCodeReferenceElement.class);
      if (referenceElement != null) {
        final PsiReferenceParameterList parameterList = referenceElement.getParameterList();
        if (parameterList != null && parameterList.getTypeArguments().length > 0) {
          return "Parameterized qualifier on static method reference";
        }
      }
    }

    if (isConstructor) {
      if (containingClass != null
          && PsiUtil.isInnerClass(containingClass)
          && containingClass.isPhysical()) {
        PsiClass outerClass = containingClass.getContainingClass();
        if (outerClass != null
            && !InheritanceUtil.hasEnclosingInstanceInScope(outerClass, methodRef, true, false)) {
          return "An enclosing instance of type "
              + PsiFormatUtil.formatClass(outerClass, PsiFormatUtilBase.SHOW_NAME)
              + " is not in scope";
        }
      }
    }
    return null;
  }
Пример #14
0
  @Override
  @NotNull
  public String getDescriptiveName(@NotNull final PsiElement element) {
    if (ThrowSearchUtil.isSearchable(element)) {
      return ThrowSearchUtil.getSearchableTypeName(element);
    }
    if (element instanceof PsiDirectory) {
      return getPackageName((PsiDirectory) element, false);
    }
    if (element instanceof PsiPackage) {
      return getPackageName((PsiPackage) element);
    }
    if (element instanceof PsiFile) {
      return ((PsiFile) element).getVirtualFile().getPresentableUrl();
    }
    if (element instanceof PsiLabeledStatement) {
      return ((PsiLabeledStatement) element).getLabelIdentifier().getText();
    }
    if (element instanceof PsiClass) {
      if (element instanceof PsiAnonymousClass) {
        String name = ((PsiAnonymousClass) element).getBaseClassReference().getReferenceName();
        return "anonymous " + StringUtil.notNullize(name, "class");
      } else {
        PsiClass aClass = (PsiClass) element;
        String qName = aClass.getQualifiedName();
        return qName != null ? qName : aClass.getName() != null ? aClass.getName() : "<unknown>";
      }
    }
    if (element instanceof PsiMethod) {
      PsiMethod psiMethod = (PsiMethod) element;
      String formatted =
          PsiFormatUtil.formatMethod(
              psiMethod,
              PsiSubstitutor.EMPTY,
              PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_PARAMETERS,
              PsiFormatUtilBase.SHOW_TYPE | PsiFormatUtilBase.SHOW_RAW_NON_TOP_TYPE);
      PsiClass psiClass = psiMethod.getContainingClass();
      if (psiClass != null) {
        return getContainingClassDescription(psiClass, formatted);
      }

      return formatted;
    }
    if (element instanceof PsiField) {
      PsiField psiField = (PsiField) element;
      String formatted =
          PsiFormatUtil.formatVariable(psiField, PsiFormatUtilBase.SHOW_NAME, PsiSubstitutor.EMPTY);
      PsiClass psiClass = psiField.getContainingClass();
      if (psiClass != null) {
        return getContainingClassDescription(psiClass, formatted);
      }

      return formatted;
    }
    if (element instanceof PsiVariable) {
      return PsiFormatUtil.formatVariable(
          (PsiVariable) element, PsiFormatUtilBase.SHOW_NAME, PsiSubstitutor.EMPTY);
    }
    if (element instanceof PsiLiteralExpression) {
      return element.getText();
    }
    if (element instanceof PsiJavaModule) {
      return ((PsiJavaModule) element).getModuleName();
    }

    return "";
  }
  @Nullable
  public static String getSuspiciousMethodCallMessage(
      @NotNull PsiMethodCallExpression methodCall,
      PsiType argType,
      boolean reportConvertibleMethodCalls,
      @NotNull List<PsiMethod> patternMethods,
      @NotNull IntArrayList indices) {
    final PsiReferenceExpression methodExpression = methodCall.getMethodExpression();
    final PsiExpression qualifier = methodExpression.getQualifierExpression();
    if (qualifier == null
        || qualifier instanceof PsiThisExpression
        || qualifier instanceof PsiSuperExpression) return null;
    if (argType instanceof PsiPrimitiveType) {
      argType = ((PsiPrimitiveType) argType).getBoxedType(methodCall);
    }

    if (!(argType instanceof PsiClassType)) return null;

    final JavaResolveResult resolveResult = methodExpression.advancedResolve(false);
    PsiMethod calleeMethod = (PsiMethod) resolveResult.getElement();
    if (calleeMethod == null) return null;
    PsiMethod contextMethod = PsiTreeUtil.getParentOfType(methodCall, PsiMethod.class);

    //noinspection SynchronizationOnLocalVariableOrMethodParameter
    synchronized (patternMethods) {
      if (patternMethods.isEmpty()) {
        setupPatternMethods(
            methodCall.getManager(), methodCall.getResolveScope(), patternMethods, indices);
      }
    }

    for (int i = 0; i < patternMethods.size(); i++) {
      PsiMethod patternMethod = patternMethods.get(i);
      if (!patternMethod.getName().equals(methodExpression.getReferenceName())) continue;
      int index = indices.get(i);

      // we are in collections method implementation
      if (contextMethod != null && isInheritorOrSelf(contextMethod, patternMethod)) return null;

      final PsiClass calleeClass = calleeMethod.getContainingClass();
      PsiSubstitutor substitutor = resolveResult.getSubstitutor();
      final PsiClass patternClass = patternMethod.getContainingClass();
      assert patternClass != null;
      assert calleeClass != null;
      substitutor = TypeConversionUtil.getClassSubstitutor(patternClass, calleeClass, substitutor);
      if (substitutor == null) continue;

      if (!patternMethod
          .getSignature(substitutor)
          .equals(calleeMethod.getSignature(PsiSubstitutor.EMPTY))) continue;

      PsiTypeParameter[] typeParameters = patternClass.getTypeParameters();
      if (typeParameters.length <= index) return null;
      final PsiTypeParameter typeParameter = typeParameters[index];
      PsiType typeParamMapping = substitutor.substitute(typeParameter);
      if (typeParamMapping == null) return null;

      PsiParameter[] parameters = patternMethod.getParameterList().getParameters();
      if (parameters.length == 1 && "removeAll".equals(patternMethod.getName())) {
        PsiType paramType = parameters[0].getType();
        if (InheritanceUtil.isInheritor(paramType, CommonClassNames.JAVA_UTIL_COLLECTION)) {
          PsiType qualifierType = qualifier.getType();
          if (qualifierType != null) {
            final PsiType itemType =
                JavaGenericsUtil.getCollectionItemType(argType, calleeMethod.getResolveScope());
            final PsiType qualifierItemType =
                JavaGenericsUtil.getCollectionItemType(
                    qualifierType, calleeMethod.getResolveScope());
            if (qualifierItemType != null
                && itemType != null
                && !qualifierItemType.isAssignableFrom(itemType)) {
              return InspectionsBundle.message(
                  "inspection.suspicious.collections.method.calls.problem.descriptor",
                  PsiFormatUtil.formatType(qualifierType, 0, PsiSubstitutor.EMPTY),
                  PsiFormatUtil.formatType(itemType, 0, PsiSubstitutor.EMPTY));
            }
          }
          return null;
        }
      }

      String message = null;
      if (typeParamMapping instanceof PsiCapturedWildcardType) {
        typeParamMapping = ((PsiCapturedWildcardType) typeParamMapping).getWildcard();
      }
      if (!typeParamMapping.isAssignableFrom(argType)) {
        if (typeParamMapping.isConvertibleFrom(argType)) {
          if (reportConvertibleMethodCalls) {
            message =
                InspectionsBundle.message(
                    "inspection.suspicious.collections.method.calls.problem.descriptor1",
                    PsiFormatUtil.formatMethod(
                        calleeMethod,
                        substitutor,
                        PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_CONTAINING_CLASS,
                        PsiFormatUtilBase.SHOW_TYPE));
          }
        } else {
          PsiType qualifierType = qualifier.getType();
          if (qualifierType != null) {
            message =
                InspectionsBundle.message(
                    "inspection.suspicious.collections.method.calls.problem.descriptor",
                    PsiFormatUtil.formatType(qualifierType, 0, PsiSubstitutor.EMPTY),
                    PsiFormatUtil.formatType(argType, 0, PsiSubstitutor.EMPTY));
          }
        }
      }
      return message;
    }
    return null;
  }
Пример #16
0
  @Override
  @NotNull
  public String getNodeText(@NotNull PsiElement element, boolean useFullName) {
    if (element instanceof PsiDirectory) {
      return getPackageName((PsiDirectory) element, false);
    }

    if (element instanceof PsiPackage) {
      return getPackageName((PsiPackage) element);
    }

    if (element instanceof PsiFile) {
      return useFullName
          ? ((PsiFile) element).getVirtualFile().getPresentableUrl()
          : ((PsiFile) element).getName();
    }

    if (element instanceof PsiLabeledStatement) {
      return ((PsiLabeledStatement) element).getLabelIdentifier().getText();
    }

    if (ThrowSearchUtil.isSearchable(element)) {
      return ThrowSearchUtil.getSearchableTypeName(element);
    }

    if (element instanceof PsiClass) {
      String name = ((PsiClass) element).getQualifiedName();
      if (name == null || !useFullName) {
        name = ((PsiClass) element).getName();
      }
      if (name != null) return name;
    }

    if (element instanceof PsiMethod) {
      PsiMethod psiMethod = (PsiMethod) element;
      if (useFullName) {
        int options =
            PsiFormatUtilBase.TYPE_AFTER
                | PsiFormatUtilBase.SHOW_TYPE
                | PsiFormatUtilBase.SHOW_NAME
                | PsiFormatUtilBase.SHOW_PARAMETERS;
        String s =
            PsiFormatUtil.formatMethod(
                (PsiMethod) element,
                PsiSubstitutor.EMPTY,
                options,
                PsiFormatUtilBase.SHOW_TYPE | PsiFormatUtilBase.SHOW_NAME);
        return appendClassName(s, psiMethod.getContainingClass());
      } else {
        int options = PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_PARAMETERS;
        return PsiFormatUtil.formatMethod(
            psiMethod, PsiSubstitutor.EMPTY, options, PsiFormatUtilBase.SHOW_TYPE);
      }
    }

    if (element instanceof PsiParameter
        && ((PsiParameter) element).getDeclarationScope() instanceof PsiMethod) {
      PsiMethod method = (PsiMethod) ((PsiParameter) element).getDeclarationScope();
      int varOptions =
          PsiFormatUtilBase.TYPE_AFTER | PsiFormatUtilBase.SHOW_TYPE | PsiFormatUtilBase.SHOW_NAME;
      int methodOptions = PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_PARAMETERS;
      String s =
          LangBundle.message(
              "java.terms.variable.of.method",
              PsiFormatUtil.formatVariable((PsiVariable) element, varOptions, PsiSubstitutor.EMPTY),
              PsiFormatUtil.formatMethod(
                  method, PsiSubstitutor.EMPTY, methodOptions, PsiFormatUtilBase.SHOW_TYPE));
      return appendClassName(s, method.getContainingClass());
    }

    if (element instanceof PsiField) {
      PsiField psiField = (PsiField) element;
      int options =
          PsiFormatUtilBase.TYPE_AFTER | PsiFormatUtilBase.SHOW_TYPE | PsiFormatUtilBase.SHOW_NAME;
      String s = PsiFormatUtil.formatVariable(psiField, options, PsiSubstitutor.EMPTY);
      return appendClassName(s, psiField.getContainingClass());
    }

    if (element instanceof PsiVariable) {
      int options =
          PsiFormatUtilBase.TYPE_AFTER | PsiFormatUtilBase.SHOW_TYPE | PsiFormatUtilBase.SHOW_NAME;
      return PsiFormatUtil.formatVariable((PsiVariable) element, options, PsiSubstitutor.EMPTY);
    }

    return "";
  }
 @Nullable
 protected static String getExternalName(
     @NotNull PsiModifierListOwner listOwner, boolean showParamName) {
   return PsiFormatUtil.getExternalName(listOwner, showParamName, Integer.MAX_VALUE);
 }
  private void checkExistingMethods(MultiMap<PsiElement, String> conflicts, boolean isGetter) {
    if (isGetter) {
      if (!myDescriptor.isToEncapsulateGet()) return;
    } else {
      if (!myDescriptor.isToEncapsulateSet()) return;
    }

    for (FieldDescriptor descriptor : myFieldDescriptors) {
      PsiMethod prototype =
          isGetter ? descriptor.getGetterPrototype() : descriptor.getSetterPrototype();

      final PsiType prototypeReturnType = prototype.getReturnType();
      PsiMethod existing = myClass.findMethodBySignature(prototype, true);
      if (existing != null) {
        final PsiType returnType = existing.getReturnType();
        if (!RefactoringUtil.equivalentTypes(
            prototypeReturnType, returnType, myClass.getManager())) {
          final String descr =
              PsiFormatUtil.formatMethod(
                  existing,
                  PsiSubstitutor.EMPTY,
                  PsiFormatUtilBase.SHOW_NAME
                      | PsiFormatUtilBase.SHOW_PARAMETERS
                      | PsiFormatUtilBase.SHOW_TYPE,
                  PsiFormatUtilBase.SHOW_TYPE);
          String message =
              isGetter
                  ? RefactoringBundle.message(
                      "encapsulate.fields.getter.exists",
                      CommonRefactoringUtil.htmlEmphasize(descr),
                      CommonRefactoringUtil.htmlEmphasize(prototype.getName()))
                  : RefactoringBundle.message(
                      "encapsulate.fields.setter.exists",
                      CommonRefactoringUtil.htmlEmphasize(descr),
                      CommonRefactoringUtil.htmlEmphasize(prototype.getName()));
          conflicts.putValue(existing, message);
        }
      } else {
        PsiClass containingClass = myClass.getContainingClass();
        while (containingClass != null && existing == null) {
          existing = containingClass.findMethodBySignature(prototype, true);
          if (existing != null) {
            for (PsiReference reference : ReferencesSearch.search(existing)) {
              final PsiElement place = reference.getElement();
              LOG.assertTrue(place instanceof PsiReferenceExpression);
              final PsiExpression qualifierExpression =
                  ((PsiReferenceExpression) place).getQualifierExpression();
              final PsiClass inheritor;
              if (qualifierExpression == null) {
                inheritor = PsiTreeUtil.getParentOfType(place, PsiClass.class, false);
              } else {
                inheritor = PsiUtil.resolveClassInType(qualifierExpression.getType());
              }

              if (InheritanceUtil.isInheritorOrSelf(inheritor, myClass, true)) {
                conflicts.putValue(
                    existing,
                    "There is already a "
                        + RefactoringUIUtil.getDescription(existing, true)
                        + " which would be hidden by generated "
                        + (isGetter ? "getter" : "setter"));
                break;
              }
            }
          }
          containingClass = containingClass.getContainingClass();
        }
      }
    }
  }
  @Override
  public void customizeCellRendererFor(@NotNull SliceUsage sliceUsage) {
    boolean isForcedLeaf = sliceUsage instanceof JavaSliceDereferenceUsage;
    // might come SliceTooComplexDFAUsage
    JavaSliceUsage javaSliceUsage =
        sliceUsage instanceof JavaSliceUsage ? (JavaSliceUsage) sliceUsage : null;

    TextChunk[] text = sliceUsage.getText();
    final List<TextRange> usageRanges = new SmartList<TextRange>();
    sliceUsage.processRangeMarkers(
        new Processor<Segment>() {
          @Override
          public boolean process(Segment segment) {
            usageRanges.add(TextRange.create(segment));
            return true;
          }
        });
    boolean isInsideContainer = javaSliceUsage != null && javaSliceUsage.indexNesting != 0;
    for (int i = 0, length = text.length; i < length; i++) {
      TextChunk textChunk = text[i];
      SimpleTextAttributes attributes = textChunk.getSimpleAttributesIgnoreBackground();
      if (isForcedLeaf) {
        attributes =
            attributes.derive(
                attributes.getStyle(),
                JBColor.LIGHT_GRAY,
                attributes.getBgColor(),
                attributes.getWaveColor());
      }
      boolean inUsage = (attributes.getFontStyle() & Font.BOLD) != 0;
      if (isInsideContainer && inUsage) {
        // Color darker = Color.BLACK;//attributes.getBgColor() == null ? Color.BLACK :
        // attributes.getBgColor().darker();
        // attributes = attributes.derive(SimpleTextAttributes.STYLE_OPAQUE,
        // attributes.getFgColor(), UIUtil.getTreeBackground().brighter(),
        // attributes.getWaveColor());
        // setMyBorder(IdeBorderFactory.createRoundedBorder(10, 3));
        // setPaintFocusBorder(true);
      }
      append(textChunk.getText(), attributes);
      if (i == 0) {
        append(FontUtil.spaceAndThinSpace());
      }
    }

    if (javaSliceUsage != null) {
      for (int i = 0; i < javaSliceUsage.indexNesting; i++) {
        append(
            " (Tracking container contents"
                + (javaSliceUsage.syntheticField.isEmpty()
                    ? ""
                    : " '" + javaSliceUsage.syntheticField + "'")
                + ")",
            SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES);
      }
    }

    PsiElement element = sliceUsage.getElement();
    PsiMethod method;
    PsiClass aClass;
    while (true) {
      method = PsiTreeUtil.getParentOfType(element, PsiMethod.class);
      aClass =
          method == null
              ? PsiTreeUtil.getParentOfType(element, PsiClass.class)
              : method.getContainingClass();
      if (aClass instanceof PsiAnonymousClass) {
        element = aClass;
      } else {
        break;
      }
    }
    int methodOptions =
        PsiFormatUtilBase.SHOW_NAME
            | PsiFormatUtilBase.SHOW_PARAMETERS
            | PsiFormatUtilBase.SHOW_CONTAINING_CLASS;
    String location =
        method != null
            ? PsiFormatUtil.formatMethod(
                method, PsiSubstitutor.EMPTY, methodOptions, PsiFormatUtilBase.SHOW_TYPE, 2)
            : aClass != null
                ? PsiFormatUtil.formatClass(aClass, PsiFormatUtilBase.SHOW_NAME)
                : null;
    if (location != null) {
      SimpleTextAttributes attributes = SimpleTextAttributes.GRAY_ATTRIBUTES;
      append(" in " + location, attributes);
    }
  }
 public static LookupItem setShowFQN(final LookupItem ret) {
   ret.setAttribute(
       JavaPsiClassReferenceElement.PACKAGE_NAME,
       PsiFormatUtil.getPackageDisplayName((PsiClass) ret.getObject()));
   return ret;
 }