mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-05 01:50:56 +07:00
move: leave classes in one file if they were together
This commit is contained in:
@@ -37,29 +37,30 @@ public class MoveJavaClassHandler implements MoveClassHandler {
|
||||
final PsiPackage newPackage = JavaDirectoryService.getInstance().getPackage(moveDestination);
|
||||
|
||||
PsiClass newClass = null;
|
||||
if (file instanceof PsiJavaFile && ((PsiJavaFile)file).getClasses().length > 1) {
|
||||
correctSelfReferences(aClass, newPackage);
|
||||
final PsiClass created = JavaDirectoryService.getInstance().createClass(moveDestination, aClass.getName());
|
||||
if (aClass.getDocComment() == null) {
|
||||
final PsiDocComment createdDocComment = created.getDocComment();
|
||||
if (createdDocComment != null) {
|
||||
aClass.addAfter(createdDocComment, null);
|
||||
}
|
||||
if (file instanceof PsiJavaFile) {
|
||||
if (!moveDestination.equals(file.getContainingDirectory()) &&
|
||||
moveDestination.findFile(file.getName()) != null) {
|
||||
// moving second of two classes which were in the same file to a different directory (IDEADEV-3089)
|
||||
correctSelfReferences(aClass, newPackage);
|
||||
final PsiFile newFile = moveDestination.findFile(file.getName());
|
||||
LOG.assertTrue(newFile != null);
|
||||
newClass = (PsiClass)newFile.add(aClass);
|
||||
correctOldClassReferences(newClass, aClass);
|
||||
aClass.delete();
|
||||
}
|
||||
else if (((PsiJavaFile)file).getClasses().length > 1) {
|
||||
correctSelfReferences(aClass, newPackage);
|
||||
final PsiClass created = JavaDirectoryService.getInstance().createClass(moveDestination, aClass.getName());
|
||||
if (aClass.getDocComment() == null) {
|
||||
final PsiDocComment createdDocComment = created.getDocComment();
|
||||
if (createdDocComment != null) {
|
||||
aClass.addAfter(createdDocComment, null);
|
||||
}
|
||||
}
|
||||
newClass = (PsiClass)created.replace(aClass);
|
||||
correctOldClassReferences(newClass, aClass);
|
||||
aClass.delete();
|
||||
}
|
||||
newClass = (PsiClass)created.replace(aClass);
|
||||
correctOldClassReferences(newClass, aClass);
|
||||
aClass.delete();
|
||||
}
|
||||
else if (file instanceof PsiJavaFile &&
|
||||
!moveDestination.equals(file.getContainingDirectory()) &&
|
||||
moveDestination.findFile(file.getName()) != null) {
|
||||
// moving second of two classes which were in the same file to a different directory (IDEADEV-3089)
|
||||
correctSelfReferences(aClass, newPackage);
|
||||
final PsiFile newFile = moveDestination.findFile(file.getName());
|
||||
LOG.assertTrue(newFile != null);
|
||||
newClass = (PsiClass)newFile.add(aClass);
|
||||
correctOldClassReferences(newClass, aClass);
|
||||
aClass.delete();
|
||||
}
|
||||
return newClass;
|
||||
}
|
||||
|
||||
@@ -4,4 +4,8 @@ public class S1{
|
||||
S11 s11;
|
||||
}
|
||||
|
||||
class S11{}
|
||||
class S11{}
|
||||
|
||||
class S12{}
|
||||
|
||||
class S13{}
|
||||
@@ -5,3 +5,7 @@ public class S1{
|
||||
}
|
||||
|
||||
class S11{}
|
||||
|
||||
class S12{}
|
||||
|
||||
class S13{}
|
||||
|
||||
Reference in New Issue
Block a user