Java Code Examples for org.eclipse.core.resources.IResource#revertModificationStamp()
The following examples show how to use
org.eclipse.core.resources.IResource#revertModificationStamp() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractJavaElementRenameChange.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
@Override public final Change perform(IProgressMonitor pm) throws CoreException { try { pm.beginTask(RefactoringCoreMessages.AbstractRenameChange_Renaming, 1); IResource resource= getResource(); IPath newPath= createNewPath(); Change result= createUndoChange(resource.getModificationStamp()); doRename(new SubProgressMonitor(pm, 1)); if (fStampToRestore != IResource.NULL_STAMP) { IResource newResource= ResourcesPlugin.getWorkspace().getRoot().findMember(newPath); newResource.revertModificationStamp(fStampToRestore); } return result; } finally { pm.done(); } }
Example 2
Source File: RenamePackageChange.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
private void renamePackage(IPackageFragment pack, IProgressMonitor pm, IPath newPath, String newName) throws JavaModelException, CoreException { if (! pack.exists()) { return; // happens if empty parent with single subpackage is renamed, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=199045 } pack.rename(newName, false, pm); if (fCompilationUnitStamps != null) { IPackageFragment newPack= (IPackageFragment) JavaCore.create(ResourcesPlugin.getWorkspace().getRoot().getFolder(newPath)); if (newPack.exists()) { ICompilationUnit[] units= newPack.getCompilationUnits(); for (int i= 0; i < units.length; i++) { IResource resource= units[i].getResource(); if (resource != null) { Long stamp= fCompilationUnitStamps.get(resource); if (stamp != null) { resource.revertModificationStamp(stamp.longValue()); } } } } } }
Example 3
Source File: AbstractJavaElementRenameChange.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
@Override public final Change perform(IProgressMonitor pm) throws CoreException { try { pm.beginTask(RefactoringCoreMessages.AbstractRenameChange_Renaming, 1); IResource resource= getResource(); IPath newPath= createNewPath(); Change result= createUndoChange(resource.getModificationStamp()); doRename(new SubProgressMonitor(pm, 1)); if (fStampToRestore != IResource.NULL_STAMP) { IResource newResource= ResourcesPlugin.getWorkspace().getRoot().findMember(newPath); newResource.revertModificationStamp(fStampToRestore); } return result; } finally { pm.done(); } }
Example 4
Source File: RenamePackageChange.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private void renamePackage(IPackageFragment pack, IProgressMonitor pm, IPath newPath, String newName) throws JavaModelException, CoreException { if (! pack.exists()) return; // happens if empty parent with single subpackage is renamed, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=199045 pack.rename(newName, false, pm); if (fCompilationUnitStamps != null) { IPackageFragment newPack= (IPackageFragment) JavaCore.create(ResourcesPlugin.getWorkspace().getRoot().getFolder(newPath)); if (newPack.exists()) { ICompilationUnit[] units= newPack.getCompilationUnits(); for (int i= 0; i < units.length; i++) { IResource resource= units[i].getResource(); if (resource != null) { Long stamp= fCompilationUnitStamps.get(resource); if (stamp != null) { resource.revertModificationStamp(stamp.longValue()); } } } } } }
Example 5
Source File: MoveCompilationUnitChange.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 4 votes |
@Override Change doPerformReorg(IProgressMonitor pm) throws CoreException, OperationCanceledException { String name; String newName= getNewName(); if (newName == null) { name= getCu().getElementName(); } else { name= newName; } // get current modification stamp long currentStamp= IResource.NULL_STAMP; IResource resource= getCu().getResource(); if (resource != null) { currentStamp= resource.getModificationStamp(); } IPackageFragment destination= getDestinationPackage(); fUndoable= !destination.exists() || !destination.getCompilationUnit(name).exists(); IPackageFragment[] createdPackages= null; if (!destination.exists()) { IPackageFragmentRoot packageFragmentRoot= (IPackageFragmentRoot) destination.getParent(); createdPackages= createDestination(packageFragmentRoot, destination, pm); } // perform the move and restore modification stamp getCu().move(destination, null, newName, true, pm); if (fStampToRestore != IResource.NULL_STAMP) { ICompilationUnit moved= destination.getCompilationUnit(name); IResource movedResource= moved.getResource(); if (movedResource != null) { movedResource.revertModificationStamp(fStampToRestore); } } if (fDeletePackages != null) { for (int i= fDeletePackages.length - 1; i >= 0; i--) { fDeletePackages[i].delete(true, pm); } } if (fUndoable) { return new MoveCompilationUnitChange(destination, getCu().getElementName(), getOldPackage(), currentStamp, createdPackages); } else { return null; } }
Example 6
Source File: XdsRenameResourceChange.java From xds-ide with Eclipse Public License 1.0 | 4 votes |
public Change perform(IProgressMonitor pm) throws CoreException { try { pm.beginTask(RefactoringCoreMessages.RenameResourceChange_progress_description, 1); IResource resource= getResource(); File absoluteFile = ResourceUtils.getAbsoluteFile(resource); IPath destPath = renamedResourcePath(resource.getRawLocation(), fNewName); boolean isLinked = resource.isLinked(); long currentStamp= resource.getModificationStamp(); IPath newPath= renamedResourcePath(fResourcePath, fNewName); IFile destIFile = ResourceUtils.getWorkspaceRoot().getFile(newPath); Change undoDeleteChange = null; if (destIFile.exists()) { // handle rename conflict DeleteResourceChange deleteChange = new DeleteResourceChange(destIFile.getFullPath(), true); undoDeleteChange = deleteChange.perform(pm); } resource.move(newPath, IResource.SHALLOW, pm); if (isLinked) { File dest = destPath.toFile(); FileUtils.deleteQuietly(dest); absoluteFile.renameTo(dest); // get the resource again since after move resource can be inadequate IWorkspaceRoot workspaceRoot = ResourceUtils.getWorkspaceRoot(); resource = workspaceRoot.getFile(newPath); ((IFile)resource).createLink(destPath, IResource.REPLACE, new NullProgressMonitor()); } if (fStampToRestore != IResource.NULL_STAMP) { IResource newResource= ResourcesPlugin.getWorkspace().getRoot().findMember(newPath); newResource.revertModificationStamp(fStampToRestore); } String oldName= fResourcePath.lastSegment(); XdsRenameResourceChange undoRenameChange = new XdsRenameResourceChange(newPath, oldName, currentStamp); if (undoDeleteChange == null) { return undoRenameChange; } else { return new CompositeChange(getName(), new Change[]{undoRenameChange, undoDeleteChange}); // constructing undo changes } } finally { pm.done(); } }
Example 7
Source File: MoveCompilationUnitChange.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
@Override Change doPerformReorg(IProgressMonitor pm) throws CoreException, OperationCanceledException { String name; String newName= getNewName(); if (newName == null) name= getCu().getElementName(); else name= newName; // get current modification stamp long currentStamp= IResource.NULL_STAMP; IResource resource= getCu().getResource(); if (resource != null) { currentStamp= resource.getModificationStamp(); } IPackageFragment destination= getDestinationPackage(); fUndoable= !destination.exists() || !destination.getCompilationUnit(name).exists(); IPackageFragment[] createdPackages= null; if (!destination.exists()) { IPackageFragmentRoot packageFragmentRoot= (IPackageFragmentRoot) destination.getParent(); createdPackages= createDestination(packageFragmentRoot, destination, pm); } // perform the move and restore modification stamp getCu().move(destination, null, newName, true, pm); if (fStampToRestore != IResource.NULL_STAMP) { ICompilationUnit moved= destination.getCompilationUnit(name); IResource movedResource= moved.getResource(); if (movedResource != null) { movedResource.revertModificationStamp(fStampToRestore); } } if (fDeletePackages != null) { for (int i= fDeletePackages.length - 1; i >= 0; i--) { fDeletePackages[i].delete(true, pm); } } if (fUndoable) { return new MoveCompilationUnitChange(destination, getCu().getElementName(), getOldPackage(), currentStamp, createdPackages); } else { return null; } }
Example 8
Source File: PyRenameResourceChange.java From Pydev with Eclipse Public License 1.0 | 4 votes |
@Override public Change perform(IProgressMonitor pm) throws CoreException { try { pm.beginTask(getName(), 1); IResource resource = getResource(); long currentStamp = resource.getModificationStamp(); IContainer destination = target != null ? target : getDestination(resource, fInitialName, fNewName, pm); IResource[] createdFiles = createDestination(destination); IPath newPath; boolean copyChildrenInsteadOfMove = false; if (resource.getType() == IResource.FILE) { //Renaming file newPath = destination.getFullPath().append(FullRepIterable.getLastPart(fNewName) + ".py"); } else { //Renaming folder newPath = destination.getFullPath().append(FullRepIterable.getLastPart(fNewName)); IPath fullPath = resource.getFullPath(); if (fullPath.isPrefixOf(newPath)) { copyChildrenInsteadOfMove = true; } } if (copyChildrenInsteadOfMove) { IContainer container = (IContainer) resource; IResource[] members = container.members(true); //Note: get the members before creating the target. IFolder folder = container.getFolder(new Path(newPath.lastSegment())); IFile initFile = container.getFile(new Path("__init__.py")); folder.create(IResource.NONE, true, null); createdFiles = ArrayUtils.concatArrays(createdFiles, new IResource[] { folder }); for (IResource member : members) { member.move(newPath.append(member.getFullPath().lastSegment()), IResource.SHALLOW, pm); } initFile.create(new ByteArrayInputStream(new byte[0]), IResource.NONE, null); } else { //simple move resource.move(newPath, IResource.SHALLOW, pm); } if (fStampToRestore != IResource.NULL_STAMP) { IResource newResource = ResourcesPlugin.getWorkspace().getRoot().findMember(newPath); newResource.revertModificationStamp(fStampToRestore); } for (IResource r : this.fCreatedFiles) { r.delete(true, null); } //The undo command return new PyRenameResourceChange(newPath, fNewName, fInitialName, fComment, currentStamp, createdFiles); } finally { pm.done(); } }