boolean (@NotNull Ref<UsageInfo[]> refUsages) { UsageInfo[] usagesIn = refUsages.get(); MultiMap<PsiElement, @DialogMessage String> conflicts = new MultiMap<>(); ReferencedElementsCollector collector = new ReferencedElementsCollector(); PsiExpression initializer = InlineConstantFieldHandler.getInitializer(myField); LOG.assertTrue(initializer != null); initializer.accept(collector); HashSet<PsiMember> referencedWithVisibility = collector.myReferencedMembers; if (!myField.hasInitializer()) { boolean dependsOnContext; PsiMethod[] constructors = Objects.requireNonNull(myField.getContainingClass()).getConstructors(); if (constructors.length == 1) { Ref<PsiElement> reference = new Ref<>(); dependsOnContext = !PsiTreeUtil.processElements(initializer, element -> { if (element instanceof PsiJavaCodeReferenceElement) { PsiElement resolve = ((PsiJavaCodeReferenceElement)element).resolve(); if (resolve != null && PsiTreeUtil.isAncestor(constructors[0], resolve, true) && !PsiTreeUtil.isAncestor(initializer, resolve, true)) { reference.set(resolve); return false; } } return true; }); if (dependsOnContext) { for (UsageInfo usageInfo : usagesIn) { PsiElement element = usageInfo.getElement(); if (element != null && !PsiTreeUtil.isAncestor(constructors[0], element, true)) { conflicts.putValue(element, JavaRefactoringBundle.message("inline.field.initializer.is.not.accessible", RefactoringUIUtil.getDescription(reference.get(), false), RefactoringUIUtil.getDescription(ConflictsUtil.getContainer(element), true))); } } } } } PsiResolveHelper resolveHelper = JavaPsiFacade.getInstance(myField.getProject()).getResolveHelper(); for (UsageInfo info : usagesIn) { PsiElement element = info.getElement(); if (element instanceof PsiExpression && (!myField.hasModifierProperty(PsiModifier.FINAL) || myInlineThisOnly) && isAccessedForWriting((PsiExpression)element)) { String message = JavaRefactoringBundle.message("0.is.used.for.writing.in.1", RefactoringUIUtil.getDescription(myField, true), RefactoringUIUtil.getDescription(ConflictsUtil.getContainer(element), true)); conflicts.putValue(element, message); } for (PsiMember member : referencedWithVisibility) { if (!resolveHelper.isAccessible(member, element, null)) { String message = JavaRefactoringBundle.message("0.will.not.be.accessible.from.1.after.inlining", RefactoringUIUtil.getDescription(member, true), RefactoringUIUtil.getDescription(ConflictsUtil.getContainer(element), true)); conflicts.putValue(member, message); } } } myInliners = GenericInlineHandler.initInliners(myField, usagesIn, new InlineHandler.Settings() { @Override public boolean isOnlyOneReferenceToInline() { return myInlineThisOnly; } }, conflicts, JavaLanguage.INSTANCE); if (!myInlineThisOnly) { for (UsageInfo info : usagesIn) { final PsiElement element = info.getElement(); if (element instanceof PsiDocMethodOrFieldRef) { if (!PsiTreeUtil.isAncestor(myField, element, false)) { conflicts.putValue(element, JavaRefactoringBundle.message("inline.field.used.in.javadoc")); } } if (element instanceof PsiLiteralExpression && ContainerUtil.or(element.getReferences(), JavaLangClassMemberReference.class::isInstance)) { conflicts.putValue(element, JavaRefactoringBundle.message("inline.field.used.in.reflection")); } } } return showConflicts(conflicts, usagesIn); }