下面列出了com.intellij.psi.PsiFile#getModificationStamp ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
static void divideInsideAndOutsideInOneRoot(@Nonnull PsiFile root,
@Nonnull TextRange restrictRange,
@Nonnull TextRange priorityRange,
@Nonnull Processor<DividedElements> processor) {
long modificationStamp = root.getModificationStamp();
DividedElements cached = SoftReference.dereference(root.getUserData(DIVIDED_ELEMENTS_KEY));
DividedElements elements;
if (cached == null || cached.modificationStamp != modificationStamp || !cached.restrictRange.equals(restrictRange) || !cached.priorityRange.contains(priorityRange)) {
elements = new DividedElements(modificationStamp, root, restrictRange, priorityRange);
divideInsideAndOutsideInOneRoot(root, restrictRange, priorityRange, elements.inside, elements.insideRanges, elements.outside,
elements.outsideRanges, elements.parents,
elements.parentRanges, true);
root.putUserData(DIVIDED_ELEMENTS_KEY, new java.lang.ref.SoftReference<>(elements));
}
else {
elements = cached;
}
processor.process(elements);
}
/**
* Gets modification count from tracker based on {@link #myModifyCause}
*
* @param tracker track to get modification count from
* @return modification count
* @throws AssertionError if {@link #myModifyCause} is junk
*/
private long getModificationCount(@Nonnull PsiElement element) {
PsiFile file = element.getContainingFile();
long fileStamp = file == null || file.isPhysical() ? 0 : file.getModificationStamp();
PsiModificationTracker tracker = file == null ? element.getManager().getModificationTracker() : file.getManager().getModificationTracker();
if (myModifyCause.equals(PsiModificationTracker.JAVA_STRUCTURE_MODIFICATION_COUNT)) {
return fileStamp + tracker.getJavaStructureModificationCount();
}
if (myModifyCause.equals(PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT)) {
return fileStamp + tracker.getOutOfCodeBlockModificationCount();
}
if (myModifyCause.equals(PsiModificationTracker.MODIFICATION_COUNT)) {
return fileStamp + tracker.getModificationCount();
}
throw new AssertionError("No modification tracker found for key " + myModifyCause);
}
@Override
protected long getTimeStamp(@Nonnull Object dependency) {
if (dependency instanceof PsiDirectory) {
return myManager.getModificationTracker().getOutOfCodeBlockModificationCount();
}
if (dependency instanceof PsiElement) {
PsiElement element = (PsiElement)dependency;
if (!element.isValid()) return -1;
PsiFile containingFile = element.getContainingFile();
if (containingFile != null) return containingFile.getModificationStamp();
}
if (dependency == PsiModificationTracker.MODIFICATION_COUNT || dependency == PSI_MOD_COUNT_OPTIMIZATION) {
return myManager.getModificationTracker().getModificationCount();
}
if (dependency == PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT) {
return myManager.getModificationTracker().getOutOfCodeBlockModificationCount();
}
if (dependency == PsiModificationTracker.JAVA_STRUCTURE_MODIFICATION_COUNT) {
return myManager.getModificationTracker().getJavaStructureModificationCount();
}
return super.getTimeStamp(dependency);
}
private static boolean canWriteToFile(Project project, PsiFile psiFile) {
VirtualFile vf = psiFile.getVirtualFile();
return psiFile.isValid()
&& psiFile.isWritable()
&& psiFile.getModificationStamp() != 0
&& vf != null
&& NonProjectFileWritingAccessProvider.isWriteAccessAllowed(vf, project);
}
private static long calcModCount(@Nonnull PsiFile hostPsiFile) {
return (hostPsiFile.getModificationStamp() << 32) + hostPsiFile.getManager().getModificationTracker().getModificationCount();
}