encapsulate fields: do not invoke refactoring on empty set of fields

This commit is contained in:
anna
2009-11-12 19:06:32 +03:00
parent 11373491d2
commit 1d1e4ba7fa
2 changed files with 10 additions and 0 deletions
@@ -457,6 +457,11 @@ public String getAccessorsVisibility() {
return;
}
if (getCheckedRows().length == 0) {
CommonRefactoringUtil.showErrorMessage(REFACTORING_NAME, "Nothing found to encapsulate", HelpID.ENCAPSULATE_FIELDS, myProject);
return;
}
invokeRefactoring(new EncapsulateFieldsProcessor(myProject, this));
JavaRefactoringSettings settings = JavaRefactoringSettings.getInstance();
settings.ENCAPSULATE_FIELDS_USE_ACCESSORS_WHEN_ACCESSIBLE = myCbUseAccessorsWhenAccessible.isSelected();
@@ -106,6 +106,11 @@ public class EncapsulateFieldsHandler implements RefactoringActionHandler {
}
LOG.assertTrue(aClass != null);
final PsiField[] fields = aClass.getFields();
if (fields.length == 0) {
CommonRefactoringUtil.showErrorHint(project, PlatformDataKeys.EDITOR.getData(dataContext), "Class has no fields to encapsulate", REFACTORING_NAME, HelpID.ENCAPSULATE_FIELDS);
return;
}
if (aClass.isInterface()) {
String message = RefactoringBundle.getCannotRefactorMessage(RefactoringBundle.message("encapsulate.fields.refactoring.cannot.be.applied.to.interface"));