use of com.jetbrains.python.refactoring.classes.membersManager.vp.BadDataException in project intellij-community by JetBrains.
the class PyExtractSuperclassPresenterImpl method validateView.
@Override
protected void validateView() throws BadDataException {
super.validateView();
final Project project = myClassUnderRefactoring.getProject();
if (!myNamesValidator.isIdentifier(myView.getSuperClassName(), project)) {
throw new BadDataException(PyBundle.message("refactoring.extract.super.name.0.must.be.ident", myView.getSuperClassName()));
}
boolean rootFound = false;
final File moduleFile = new File(myView.getModuleFile());
try {
final String targetDir = FileUtil.toSystemIndependentName(moduleFile.getCanonicalPath());
for (final VirtualFile file : ProjectRootManager.getInstance(project).getContentRoots()) {
if (StringUtil.startsWithIgnoreCase(targetDir, file.getPath())) {
rootFound = true;
break;
}
}
} catch (final IOException ignore) {
}
if (!rootFound) {
throw new BadDataException(PyBundle.message("refactoring.extract.super.target.path.outside.roots"));
}
// TODO: Cover with test. It can't be done for now, because testFixture reports root path incorrectly
// PY-12173
myView.getModuleFile();
final VirtualFile moduleVirtualFile = LocalFileSystem.getInstance().findFileByIoFile(moduleFile);
if (moduleVirtualFile != null) {
final PsiFile psiFile = PsiManager.getInstance(project).findFile(moduleVirtualFile);
if (psiFile instanceof PyFile) {
if (((PyFile) psiFile).findTopLevelClass(myView.getSuperClassName()) != null) {
throw new BadDataException(PyBundle.message("refactoring.extract.super.target.class.already.exists", myView.getSuperClassName()));
}
}
}
}
Aggregations