boolean (final PsiLocalVariable local, final Editor editor) { boolean tempIsStatic = myIsConstant; PsiElement parent = local.getParent(); PsiType localType = local.getType(); boolean runtimeConstant = (localType instanceof PsiPrimitiveType || localType.equalsToText(CommonClassNames.JAVA_LANG_STRING)) && PsiUtil.isConstantExpression(local.getInitializer()); final List<PsiClass> classes = new ArrayList<>(); while (parent != null && parent.getContainingFile() != null) { if (parent instanceof PsiClass && (runtimeConstant || !myIsConstant || mayContainConstants((PsiClass) parent))) { classes.add((PsiClass)parent); } if (parent instanceof PsiFile && FileTypeUtils.isInServerPageFile(parent)) { String message = JavaRefactoringBundle.message("error.not.supported.for.jsp", getRefactoringName()); CommonRefactoringUtil.showErrorHint(myProject, editor, message, getRefactoringName(), HelpID.LOCAL_TO_FIELD); return false; } if (parent instanceof PsiModifierListOwner &&((PsiModifierListOwner)parent).hasModifierProperty(PsiModifier.STATIC)) { tempIsStatic = true; } parent = parent.getParent(); } if (classes.isEmpty()) return false; final AbstractInplaceIntroducer activeIntroducer = AbstractInplaceIntroducer.getActiveIntroducer(editor); final boolean shouldSuggestDialog = activeIntroducer instanceof InplaceIntroduceConstantPopup && activeIntroducer.startsOnTheSameElement(null, local); if (classes.size() == 1 || ApplicationManager.getApplication().isUnitTestMode() || shouldSuggestDialog) { if (convertLocalToField(local, classes.get(getChosenClassIndex(classes)), editor, tempIsStatic)) return false; } else { final boolean isStatic = tempIsStatic; final PsiClass firstClass = classes.get(0); final PsiClass preselection = AnonymousTargetClassPreselectionUtil.getPreselection(classes, firstClass); String title = myIsConstant ? JavaRefactoringBundle.message("local.to.field.popup.title.choose.class.to.introduce.constant") : JavaRefactoringBundle.message("local.to.field.popup.title.choose.class.to.introduce.field"); new PsiTargetNavigator<>(classes.toArray(PsiClass.EMPTY_ARRAY)).selection(preselection).createPopup(myProject, title, new PsiElementProcessor<>() { @Override public boolean execute(@NotNull PsiClass aClass) { AnonymousTargetClassPreselectionUtil.rememberSelection(aClass, aClass); convertLocalToField(local, aClass, editor, isStatic); return false; } }).showInBestPositionFor(editor); } return true; }