mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
shelf: refactoring - make ShelvedChange immutable, deprecate old method
GitOrigin-RevId: 68cf3dbf6cc8748d68c111a91d124e2293d37869
This commit is contained in:
committed by
intellij-monorepo-bot
parent
6fb3b95cea
commit
9fc0a99db6
+3
-3
@@ -392,7 +392,7 @@ public class DiffShelvedChangesActionProvider implements AnActionExtensionProvid
|
||||
}
|
||||
}
|
||||
else {
|
||||
return createDiffRequest(myProject, myChange.getChange(myProject), getName(), context, indicator);
|
||||
return createDiffRequest(myProject, myChange.getChange(), getName(), context, indicator);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -500,9 +500,9 @@ public class DiffShelvedChangesActionProvider implements AnActionExtensionProvid
|
||||
@NotNull TextFilePatch patch,
|
||||
@NotNull UserDataHolder context,
|
||||
@NotNull ProgressIndicator indicator) throws DiffRequestProducerException {
|
||||
DiffRequest diffRequest = myChange.isConflictingChange(myProject)
|
||||
DiffRequest diffRequest = myChange.isConflictingChange()
|
||||
? createConflictDiffRequest(myProject, myFile, patch, SHELVED_VERSION, texts, getName())
|
||||
: createDiffRequest(myProject, myChange.getChange(myProject), getName(), context, indicator);
|
||||
: createDiffRequest(myProject, myChange.getChange(), getName(), context, indicator);
|
||||
if (!myWithLocal) {
|
||||
DiffUtil.addNotification(createNotification(DIFF_WITH_BASE_ERROR + " Showing difference with local version"), diffRequest);
|
||||
}
|
||||
|
||||
@@ -49,18 +49,23 @@ public class ShelvedChange {
|
||||
private final String myBeforePath;
|
||||
private final String myAfterPath;
|
||||
private final FileStatus myFileStatus;
|
||||
private Change myChange;
|
||||
@NotNull private final Change myChange;
|
||||
|
||||
public ShelvedChange(final String patchPath, final String beforePath, final String afterPath, final FileStatus fileStatus) {
|
||||
public ShelvedChange(@NotNull Project project,
|
||||
final String patchPath,
|
||||
final String beforePath,
|
||||
final String afterPath,
|
||||
final FileStatus fileStatus) {
|
||||
myPatchPath = patchPath;
|
||||
myBeforePath = beforePath;
|
||||
// optimisation: memory
|
||||
myAfterPath = Comparing.equal(beforePath, afterPath) ? beforePath : afterPath;
|
||||
myFileStatus = fileStatus;
|
||||
myChange = createChange(project);
|
||||
}
|
||||
|
||||
public boolean isConflictingChange(final Project project) {
|
||||
ContentRevision afterRevision = getChange(project).getAfterRevision();
|
||||
public boolean isConflictingChange() {
|
||||
ContentRevision afterRevision = getChange().getAfterRevision();
|
||||
if (afterRevision == null) return false;
|
||||
try {
|
||||
afterRevision.getContent();
|
||||
@@ -86,33 +91,39 @@ public class ShelvedChange {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Change getChange(@NotNull Project project) {
|
||||
// todo unify with
|
||||
if (myChange == null) {
|
||||
File baseDir = new File(Objects.requireNonNull(project.getBasePath()));
|
||||
|
||||
File file = getAbsolutePath(baseDir, myBeforePath);
|
||||
FilePath beforePath = VcsUtil.getFilePath(file, false);
|
||||
ContentRevision beforeRevision = null;
|
||||
if (myFileStatus != FileStatus.ADDED) {
|
||||
beforeRevision = new CurrentContentRevision(beforePath) {
|
||||
@Override
|
||||
@NotNull
|
||||
public VcsRevisionNumber getRevisionNumber() {
|
||||
return new TextRevisionNumber(VcsBundle.message("local.version.title"));
|
||||
}
|
||||
};
|
||||
}
|
||||
ContentRevision afterRevision = null;
|
||||
if (myFileStatus != FileStatus.DELETED) {
|
||||
FilePath afterPath = VcsUtil.getFilePath(getAbsolutePath(baseDir, myAfterPath), false);
|
||||
afterRevision = new PatchedContentRevision(project, beforePath, afterPath);
|
||||
}
|
||||
myChange = new Change(beforeRevision, afterRevision, myFileStatus);
|
||||
}
|
||||
public Change getChange() {
|
||||
return myChange;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Deprecated
|
||||
public Change getChange(@NotNull Project project) {
|
||||
return myChange;
|
||||
}
|
||||
|
||||
private Change createChange(@NotNull Project project) {
|
||||
File baseDir = new File(Objects.requireNonNull(project.getBasePath()));
|
||||
|
||||
File file = getAbsolutePath(baseDir, myBeforePath);
|
||||
FilePath beforePath = VcsUtil.getFilePath(file, false);
|
||||
ContentRevision beforeRevision = null;
|
||||
if (myFileStatus != FileStatus.ADDED) {
|
||||
beforeRevision = new CurrentContentRevision(beforePath) {
|
||||
@Override
|
||||
@NotNull
|
||||
public VcsRevisionNumber getRevisionNumber() {
|
||||
return new TextRevisionNumber(VcsBundle.message("local.version.title"));
|
||||
}
|
||||
};
|
||||
}
|
||||
ContentRevision afterRevision = null;
|
||||
if (myFileStatus != FileStatus.DELETED) {
|
||||
FilePath afterPath = VcsUtil.getFilePath(getAbsolutePath(baseDir, myAfterPath), false);
|
||||
afterRevision = new PatchedContentRevision(project, beforePath, afterPath);
|
||||
}
|
||||
return new Change(beforeRevision, afterRevision, myFileStatus);
|
||||
}
|
||||
|
||||
private static File getAbsolutePath(final File baseDir, final String relativePath) {
|
||||
File file;
|
||||
try {
|
||||
|
||||
@@ -156,7 +156,7 @@ public class ShelvedChangeList implements JDOMExternalizable, ExternalizableSche
|
||||
else {
|
||||
status = FileStatus.MODIFIED;
|
||||
}
|
||||
myChanges.add(new ShelvedChange(PATH, patch.getBeforeName(), patch.getAfterName(), status));
|
||||
myChanges.add(new ShelvedChange(project, PATH, patch.getBeforeName(), patch.getAfterName(), status));
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
|
||||
@@ -70,7 +70,7 @@ class ShelvedWrapper {
|
||||
}
|
||||
|
||||
Change getChange(@NotNull Project project) {
|
||||
return myShelvedChange != null ? myShelvedChange.getChange(project) : assertNotNull(myBinaryFile).createChange(project);
|
||||
return myShelvedChange != null ? myShelvedChange.getChange() : assertNotNull(myBinaryFile).createChange(project);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
Reference in New Issue
Block a user