Java Code Examples for org.eclipse.core.resources.IResource#NULL_STAMP

The following examples show how to use org.eclipse.core.resources.IResource#NULL_STAMP . 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 vote down vote up
@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: AnalysisBuilderRunnableFactory.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
private static boolean checkTimesOk(IAnalysisBuilderRunnable oldAnalysisBuilderThread, long oldDocTime,
        long documentTime, long oldResourceStamp, long resourceStamp) {
    if (oldAnalysisBuilderThread != null && oldDocTime > documentTime - DELTA_TO_CONSIDER_SAME) {
        //If the document version of the new one is lower than the one already active, don't do the analysis
        if (oldResourceStamp != resourceStamp) {
            if (oldResourceStamp == IResource.NULL_STAMP || resourceStamp == IResource.NULL_STAMP) {
                return true; //one of them is null, so, it's ok to keep going.
            }
            if (resourceStamp > oldResourceStamp) {
                return true; //it actually changed in the meantime, so, just keep going
            }
        }
        if (DebugSettings.DEBUG_ANALYSIS_REQUESTS) {
            org.python.pydev.shared_core.log.ToLogFile.toLogFile(oldAnalysisBuilderThread,
                    createExistinTimeHigherMessage(oldDocTime, documentTime, oldResourceStamp, resourceStamp));
        }

        return false;
    }
    return true;
}
 
Example 3
Source File: AbstractJavaElementRenameChange.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@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: ResourceHelper.java    From tlaplus with MIT License 6 votes vote down vote up
/**
 * If file has been parsed since it was last written, then return
 * its parseResult.  Else, return null.
 * @param file
 * @return
 */
public static ParseResult getValidParseResult(IFile file)
{

    ParseResult parseResult = ParseResultBroadcaster.getParseResultBroadcaster().getParseResult(file.getLocation());
    if ((parseResult == null))
    {
        return null;
    }

    long timeWhenParsed = parseResult.getParserCalled();
    long timeWhenWritten = file.getLocalTimeStamp();
    if ((timeWhenWritten == IResource.NULL_STAMP) || (timeWhenWritten > timeWhenParsed))
    {
        return null;
    }
    return parseResult;
}
 
Example 5
Source File: PyChange.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
public void checkModificationStamp(RefactoringStatus status, long stampToMatch) {
    if (fKind == DOCUMENT) {
        if (stampToMatch != IDocumentExtension4.UNKNOWN_MODIFICATION_STAMP
                && fModificationStamp != stampToMatch) {
            status.addFatalError(StringUtils.format("Resource %s has modifications", fResource.getFullPath()));
        }
    } else {
        if (stampToMatch != IResource.NULL_STAMP && fModificationStamp != stampToMatch) {
            status.addFatalError(StringUtils.format("Resource %s has modifications", fResource.getFullPath()));

        }
    }
}
 
Example 6
Source File: RenameSourceFolderChange.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public RenameSourceFolderChange(IPackageFragmentRoot sourceFolder, String newName) {
	this(sourceFolder.getPath(), sourceFolder.getElementName(), newName, IResource.NULL_STAMP);
	Assert.isTrue(!sourceFolder.isReadOnly(), "should not be read only"); //$NON-NLS-1$
	Assert.isTrue(!sourceFolder.isArchive(), "should not be an archive"); //$NON-NLS-1$
	Assert.isTrue(!sourceFolder.isExternal(), "should not be an external folder"); //$NON-NLS-1$
	setValidationMethod(VALIDATE_NOT_DIRTY);
}
 
Example 7
Source File: MoveCompilationUnitChange.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public MoveCompilationUnitChange(ICompilationUnit cu, IPackageFragment newPackage){
	super(cu, newPackage);
	fStampToRestore= IResource.NULL_STAMP;
	fDeletePackages= null;

	setValidationMethod(SAVE_IF_DIRTY | VALIDATE_NOT_READ_ONLY);
}
 
Example 8
Source File: Spec.java    From tlaplus with MIT License 5 votes vote down vote up
/**
 * @return the lastModified
 */
public Date getLastModified() {
    if (IResource.NULL_STAMP == project.getModificationStamp()) {
        return null;
    }
    return new Date(project.getModificationStamp());
}
 
Example 9
Source File: RenamePackageChange.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
private void addStamps(Map<IResource, Long> stamps, ICompilationUnit[] units) {
	for (int i= 0; i < units.length; i++) {
		IResource resource= units[i].getResource();
		long stamp= IResource.NULL_STAMP;
		if (resource != null && (stamp= resource.getModificationStamp()) != IResource.NULL_STAMP) {
			stamps.put(resource, Long.valueOf(stamp));
		}
	}
}
 
Example 10
Source File: OpenTypeHistory.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private synchronized void internalCheckConsistency(IProgressMonitor monitor) throws OperationCanceledException {
	// Setting fNeedsConsistencyCheck is necessary here since
	// markAsInconsistent isn't synchronized.
	fNeedsConsistencyCheck= true;
	List<Object> typesToCheck= new ArrayList<Object>(getKeys());
	monitor.beginTask(CorextMessages.TypeInfoHistory_consistency_check, typesToCheck.size());
	monitor.setTaskName(CorextMessages.TypeInfoHistory_consistency_check);
	for (Iterator<Object> iter= typesToCheck.iterator(); iter.hasNext();) {
		TypeNameMatch type= (TypeNameMatch)iter.next();
		long currentTimestamp= getContainerTimestamp(type);
		Long lastTested= fTimestampMapping.get(type);
		if (lastTested != null && currentTimestamp != IResource.NULL_STAMP && currentTimestamp == lastTested.longValue() && !isContainerDirty(type))
			continue;
		try {
			IType jType= type.getType();
			if (jType == null || !jType.exists()) {
				remove(type);
			} else {
				// copy over the modifiers since they may have changed
				int modifiers= jType.getFlags();
				if (modifiers != type.getModifiers()) {
					replace(type, SearchEngine.createTypeNameMatch(jType, modifiers));
				} else {
					fTimestampMapping.put(type, new Long(currentTimestamp));
				}
			}
		} catch (JavaModelException e) {
			remove(type);
		}
		if (monitor.isCanceled())
			throw new OperationCanceledException();
		monitor.worked(1);
	}
	monitor.done();
	fNeedsConsistencyCheck= false;
}
 
Example 11
Source File: Storage2UriMapperJavaImpl.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @since 2.9
 */
protected Object getLastModified(IResource resource) throws CoreException {
	IPath location = resource.getLocation();
	if (location != null) {
		return location.toFile().lastModified();
	}
	long timestamp = resource.getLocalTimeStamp();
	if (timestamp == IResource.NULL_STAMP) {
		return null;
	}
	return timestamp;
}
 
Example 12
Source File: RenameCompilationUnitChange.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
public RenameCompilationUnitChange(ICompilationUnit unit, String newName) {
	this(unit.getResource().getFullPath(), unit.getElementName(), newName, IResource.NULL_STAMP);
	Assert.isTrue(!unit.isReadOnly(), "compilation unit must not be read-only"); //$NON-NLS-1$
}
 
Example 13
Source File: XdsRenameResourceChange.java    From xds-ide with Eclipse Public License 1.0 4 votes vote down vote up
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 14
Source File: AbstractJavaElementRenameChange.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
protected AbstractJavaElementRenameChange(IPath resourcePath, String oldName, String newName) {
	this(resourcePath, oldName, newName, IResource.NULL_STAMP);
}
 
Example 15
Source File: PyChange.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
protected PyChange() {
    fModificationStamp = IResource.NULL_STAMP;
    fReadOnly = false;
}
 
Example 16
Source File: CreateFileChange.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public CreateFileChange(IPath path, String source, String encoding) {
	this(path, source, encoding, IResource.NULL_STAMP);
}
 
Example 17
Source File: RenamePackageChange.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public RenamePackageChange(IPackageFragment pack, String newName, boolean renameSubpackages) {
	this(pack.getPath(), pack.getElementName(), newName, IResource.NULL_STAMP, null, renameSubpackages);
	Assert.isTrue(!pack.isReadOnly(), "package must not be read only"); //$NON-NLS-1$
}
 
Example 18
Source File: CreateFileChange.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
public CreateFileChange(IPath path, String source, String encoding) {
	this(path, source, encoding, IResource.NULL_STAMP);
}
 
Example 19
Source File: MoveCompilationUnitChange.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@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 20
Source File: XdsRenameResourceChange.java    From xds-ide with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Creates the change.
 *
 * @param resourcePath the path of the resource to rename
 * @param newName the new name. Must not be empty.
 */
public XdsRenameResourceChange(IPath resourcePath, IPath conflictingResourcePath, String newName) {
	this(resourcePath, newName, IResource.NULL_STAMP);
	fConflictingResourcePath = conflictingResourcePath;
}