コード例 #1
0
 protected boolean isPsiUpToDate(@NotNull VirtualFile vFile) {
   final FileViewProvider provider = myManager.findViewProvider(vFile);
   Language language = getLanguage();
   if (provider == null || provider.getPsi(language) == this) { // provider == null in tests
     return true;
   }
   Language baseLanguage = provider.getBaseLanguage();
   return baseLanguage != language && provider.getPsi(baseLanguage) == this;
 }
コード例 #2
0
  private void checkPsiIsCorrect(final FileViewProvider key) {
    PsiFile actualPsi = key.getPsi(key.getBaseLanguage());

    PsiTreeDebugBuilder treeDebugBuilder =
        new PsiTreeDebugBuilder().setShowErrorElements(false).setShowWhiteSpaces(false);

    String actualPsiTree = treeDebugBuilder.psiToString(actualPsi);

    String fileName = key.getVirtualFile().getName();
    PsiFile psi =
        PsiFileFactory.getInstance(myProject)
            .createFileFromText(
                fileName,
                FileTypeManager.getInstance().getFileTypeByFileName(fileName),
                actualPsi.getNode().getText(),
                LocalTimeCounter.currentTime(),
                false);

    if (actualPsi.getClass().equals(psi.getClass())) {
      String expectedPsi = treeDebugBuilder.psiToString(psi);

      if (!expectedPsi.equals(actualPsiTree)) {
        myReformatElements.clear();
        assert expectedPsi.equals(actualPsiTree)
            : "Refactored psi should be the same as result of parsing";
      }
    }
  }
コード例 #3
0
 public void execute(FileViewProvider viewProvider) {
   final Document document = viewProvider.getDocument();
   final PsiFile psiFile = viewProvider.getPsi(viewProvider.getBaseLanguage());
   for (Pair<Integer, RangeMarker> integerRangeMarkerPair : myRangesToReindent) {
     RangeMarker marker = integerRangeMarkerPair.second;
     final CharSequence charsSequence =
         document.getCharsSequence().subSequence(marker.getStartOffset(), marker.getEndOffset());
     final int oldIndent = integerRangeMarkerPair.first;
     final TextRange[] whitespaces =
         CharArrayUtil.getIndents(charsSequence, marker.getStartOffset());
     final int indentAdjustment = getNewIndent(psiFile, marker.getStartOffset()) - oldIndent;
     if (indentAdjustment != 0)
       adjustIndentationInRange(psiFile, document, whitespaces, indentAdjustment);
   }
 }
コード例 #4
0
 @Override
 public void visitFile(PsiFile file) {
   final VirtualFile virtualFile = file.getVirtualFile();
   if (virtualFile != null) {
     String relative =
         ProjectUtilCore.displayUrlRelativeToProject(
             virtualFile, virtualFile.getPresentableUrl(), myProject, true, false);
     myContext.incrementJobDoneAmount(myContext.getStdJobDescriptors().BUILD_GRAPH, relative);
   }
   final FileViewProvider viewProvider = file.getViewProvider();
   final Set<Language> relevantLanguages = viewProvider.getLanguages();
   for (Language language : relevantLanguages) {
     visitElement(viewProvider.getPsi(language));
   }
   myPsiManager.dropResolveCaches();
   InjectedLanguageManager.getInstance(myProject).dropFileCaches(file);
 }
コード例 #5
0
  @Override
  @NotNull
  public PsiFile[] getPsiRoots() {
    final FileViewProvider viewProvider = getViewProvider();
    final Set<Language> languages = viewProvider.getLanguages();

    final PsiFile[] roots = new PsiFile[languages.size()];
    int i = 0;
    for (Language language : languages) {
      PsiFile psi = viewProvider.getPsi(language);
      if (psi == null) {
        LOG.error("PSI is null for " + language + "; in file: " + this);
      }
      roots[i++] = psi;
    }
    if (roots.length > 1) {
      Arrays.sort(roots, FILE_BY_LANGUAGE_ID);
    }
    return roots;
  }
コード例 #6
0
 public void execute(FileViewProvider viewProvider) {
   final CodeFormatterFacade codeFormatter = getFormatterFacade(viewProvider);
   codeFormatter.processText(
       viewProvider.getPsi(viewProvider.getBaseLanguage()), myRanges.ensureNonEmpty(), false);
 }