Java Code Examples for com.intellij.psi.PsiFile#getModificationStamp()

The following examples show how to use com.intellij.psi.PsiFile#getModificationStamp() . 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: Divider.java    From consulo with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example 2
Source File: PsiCacheKey.java    From consulo with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
}
 
Example 3
Source File: PsiCachedValue.java    From consulo with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example 4
Source File: BuildFileFormatOnSaveHandler.java    From intellij with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 5
Source File: InjectionResult.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static long calcModCount(@Nonnull PsiFile hostPsiFile) {
  return (hostPsiFile.getModificationStamp() << 32) + hostPsiFile.getManager().getModificationTracker().getModificationCount();
}