private void makeFinal() { for (PsiVariable var : getVariablesToFix()) { if (var.isValid()) { PsiUtil.setModifierProperty(var, PsiModifier.FINAL, true); } } }
@Override public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) { return myClass != null && myClass.isValid() && myClass.getManager().isInProject(myClass) && myVariable != null && myVariable.isValid() && myFixType != -1 && !getVariablesToFix().isEmpty() && !inOwnInitializer(myVariable, myClass); }
@Override public boolean isAvailable( @NotNull Project project, @NotNull PsiFile file, @NotNull PsiElement startElement, @NotNull PsiElement endElement) { final PsiModifierList myModifierList = (PsiModifierList) startElement; PsiVariable variable = myVariable == null ? null : myVariable.getElement(); return myModifierList.isValid() && myModifierList.getManager().isInProject(myModifierList) && myModifierList.hasExplicitModifier(myModifier) != myShouldHave && (variable == null || variable.isValid()); }
@Override public void invoke( @NotNull Project project, @NotNull PsiFile file, @Nullable("is null when called from inspection") Editor editor, @NotNull PsiElement startElement, @NotNull PsiElement endElement) { final PsiModifierList myModifierList = (PsiModifierList) startElement; final PsiVariable variable = myVariable == null ? null : myVariable.getElement(); if (!CodeInsightUtilBase.preparePsiElementForWrite(myModifierList)) return; final List<PsiModifierList> modifierLists = new ArrayList<PsiModifierList>(); final PsiFile containingFile = myModifierList.getContainingFile(); final PsiModifierList modifierList; if (variable != null && variable.isValid()) { ApplicationManager.getApplication() .runWriteAction( new Runnable() { public void run() { try { variable.normalizeDeclaration(); } catch (IncorrectOperationException e) { LOG.error(e); } } }); modifierList = variable.getModifierList(); assert modifierList != null; } else { modifierList = myModifierList; } PsiElement owner = modifierList.getParent(); if (owner instanceof PsiMethod) { PsiModifierList copy = (PsiModifierList) myModifierList.copy(); changeModifierList(copy); final int accessLevel = PsiUtil.getAccessLevel(copy); OverridingMethodsSearch.search((PsiMethod) owner, owner.getResolveScope(), true) .forEach( new PsiElementProcessorAdapter<PsiMethod>( new PsiElementProcessor<PsiMethod>() { public boolean execute(@NotNull PsiMethod inheritor) { PsiModifierList list = inheritor.getModifierList(); if (inheritor.getManager().isInProject(inheritor) && PsiUtil.getAccessLevel(list) < accessLevel) { modifierLists.add(list); } return true; } })); } if (!CodeInsightUtilBase.prepareFileForWrite(containingFile)) return; if (!modifierLists.isEmpty()) { if (Messages.showYesNoDialog( project, QuickFixBundle.message("change.inheritors.visibility.warning.text"), QuickFixBundle.message("change.inheritors.visibility.warning.title"), Messages.getQuestionIcon()) == DialogWrapper.OK_EXIT_CODE) { ApplicationManager.getApplication() .runWriteAction( new Runnable() { public void run() { if (!CodeInsightUtilBase.preparePsiElementsForWrite(modifierLists)) { return; } for (final PsiModifierList modifierList : modifierLists) { changeModifierList(modifierList); } } }); } } ApplicationManager.getApplication() .runWriteAction( new Runnable() { public void run() { changeModifierList(modifierList); UndoUtil.markPsiFileForUndo(containingFile); } }); }
@Override public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) { return myVariable != null && myVariable.isValid() && myVariable.getManager().isInProject(myVariable); }