Java 类com.intellij.psi.LanguageSubstitutors 实例源码

项目:rythm_plugin    文件:RythmFileViewProvider.java   
@NotNull
private static Language getTemplateDataLanguage(PsiManager manager, VirtualFile file) {
    Language dataLang = TemplateDataLanguageMappings.getInstance(manager.getProject()).getMapping(file);
    if (dataLang == null) {
        dataLang = RythmLanguage.getDefaultTemplateLang().getLanguage();
    }
    Language substituteLang = LanguageSubstitutors.INSTANCE.substituteLanguage(dataLang, file, manager.getProject());

    //Test for Java implementation
/* if (dataLang == null) {
        dataLang = RythmLanguage.getLanguage().getLanguage();
    }
    Language substituteLang = LanguageSubstitutors.INSTANCE.substituteLanguage(dataLang, file, manager.getProject());
*/

    if (TemplateDataLanguageMappings.getTemplateableLanguages().contains(substituteLang)) {
        dataLang = substituteLang;
    }
    return dataLang;
}
项目:intellij-ce-playground    文件:SubstitutedFileType.java   
@NotNull
public static FileType substituteFileType(@NotNull VirtualFile file, @NotNull FileType fileType, Project project) {
  if (project == null) {
    return fileType;
  }
  if (fileType instanceof LanguageFileType) {
    final Language language = ((LanguageFileType)fileType).getLanguage();
    final Language substitutedLanguage = LanguageSubstitutors.INSTANCE.substituteLanguage(language, file, project);
    LanguageFileType substFileType = substitutedLanguage.getAssociatedFileType();
    if (!substitutedLanguage.equals(language) && substFileType != null) {
      return new SubstitutedFileType(fileType, substFileType, substitutedLanguage);
    }
  }

  return fileType;
}
项目:tools-idea    文件:FileContentImpl.java   
/**
 * @return psiFile associated with the content. If the file was not set on FileContentCreation, it will be created on the spot
 */
@NotNull
@Override
public PsiFile getPsiFile() {
  PsiFile psi = getUserData(IndexingDataKeys.PSI_FILE);

  if (psi == null) {
    psi = getUserData(CACHED_PSI);
  }

  if (psi == null) {
    Project project = getProject();
    if (project == null) {
      project = DefaultProjectFactory.getInstance().getDefaultProject();
    }
    final Language language = ((LanguageFileType)getFileTypeWithoutSubstitution()).getLanguage();
    final Language substitutedLanguage = LanguageSubstitutors.INSTANCE.substituteLanguage(language, getFile(), project);
    psi = PsiFileFactory.getInstance(project).createFileFromText(getFileName(), substitutedLanguage, getContentAsText(), false, false, true);

    psi.putUserData(IndexingDataKeys.VIRTUAL_FILE, getFile());
    putUserData(CACHED_PSI, psi);
  }
  return psi;
}
项目:tools-idea    文件:SubstitutedFileType.java   
@NotNull
public static FileType substituteFileType(VirtualFile file, @NotNull FileType fileType, Project project) {
  if (project == null) {
    return fileType;
  }
  if (fileType instanceof LanguageFileType) {
    final Language language = ((LanguageFileType)fileType).getLanguage();
    final Language substitutedLanguage = LanguageSubstitutors.INSTANCE.substituteLanguage(language, file, project);
    LanguageFileType substFileType = substitutedLanguage.getAssociatedFileType();
    if (!substitutedLanguage.equals(language) && substFileType != null && !substFileType.equals(fileType)) {
      return new SubstitutedFileType(fileType, substFileType);
    }
  }

  return fileType;
}
项目:consulo    文件:SubstitutedFileType.java   
@Nonnull
public static FileType substituteFileType(VirtualFile file, @Nonnull FileType fileType, Project project) {
  if (project == null) {
    return fileType;
  }
  if (fileType instanceof LanguageFileType) {
    final Language language = ((LanguageFileType)fileType).getLanguage();
    final Language substitutedLanguage = LanguageSubstitutors.INSTANCE.substituteLanguage(language, file, project);
    LanguageFileType substFileType = substitutedLanguage.getAssociatedFileType();
    if (!substitutedLanguage.equals(language) && substFileType != null) {
      return new SubstitutedFileType(fileType, substFileType, substitutedLanguage);
    }
  }

  return fileType;
}
项目:GoJetPlugin    文件:JetFileViewProvider.java   
public JetFileViewProvider(PsiManager manager, VirtualFile file, boolean physical) {
    super(manager, file, physical);

    Language dataLang = TemplateDataLanguageMappings.getInstance(manager.getProject()).getMapping(file);
    if (dataLang == null) dataLang = StdFileTypes.HTML.getLanguage();

    if (dataLang instanceof TemplateLanguage) {
        myTemplateDataLanguage = PlainTextLanguage.INSTANCE;
    } else {
        myTemplateDataLanguage = LanguageSubstitutors.INSTANCE.substituteLanguage(dataLang, file, manager.getProject());
    }
}
项目:intellij-ce-playground    文件:EditorHighlighterFactoryImpl.java   
@Nullable
private static LanguageFileType substituteFileType(Language language, VirtualFile vFile, Project project) {
  LanguageFileType fileType = null;
  if (vFile != null && project != null) {
    Language substLanguage = LanguageSubstitutors.INSTANCE.substituteLanguage(language, vFile, project);
    if (substLanguage != language) {
      fileType = substLanguage.getAssociatedFileType();
    }
  }
  return fileType;
}
项目:intellij-ce-playground    文件:FileContentImpl.java   
public PsiFile createFileFromText(@NotNull CharSequence text) {
  Project project = getProject();
  if (project == null) {
    project = DefaultProjectFactory.getInstance().getDefaultProject();
  }
  final Language language = ((LanguageFileType)getFileTypeWithoutSubstitution()).getLanguage();
  final VirtualFile file = getFile();
  final Language substitutedLanguage = LanguageSubstitutors.INSTANCE.substituteLanguage(language, file, project);
  return PsiFileFactory.getInstance(project).createFileFromText(getFileName(), substitutedLanguage, text, false, false, true, file);
}
项目:intellij-ce-playground    文件:ScratchFileActions.java   
@NotNull
protected Function<VirtualFile, Language> fileLanguage(final Project project) {
  return new Function<VirtualFile, Language>() {
    ScratchFileService fileService = ScratchFileService.getInstance();

    @Override
    public Language fun(VirtualFile file) {
      Language lang = fileService.getScratchesMapping().getMapping(file);
      if (lang == null) {
        lang = LanguageSubstitutors.INSTANCE.substituteLanguage(((LanguageFileType)file.getFileType()).getLanguage(), file, project);
      }
      return lang;
    }
  };
}
项目:tools-idea    文件:EditorHighlighterFactoryImpl.java   
@Nullable
private static LanguageFileType substituteFileType(Language language, VirtualFile vFile, Project project) {
  LanguageFileType fileType = null;
  if (vFile != null && project != null) {
    Language substLanguage = LanguageSubstitutors.INSTANCE.substituteLanguage(language, vFile, project);
    if (substLanguage != language) {
      fileType = substLanguage.getAssociatedFileType();
    }
  }
  return fileType;
}
项目:idea-doT    文件:DotFileViewProvider.java   
private Language getTemplateDataLanguage(PsiManager manager, VirtualFile file) {
    Language dataLang = TemplateDataLanguageMappings.getInstance(manager.getProject()).getMapping(file);
    if(dataLang == null) {
        dataLang = DotLanguage.getDefaultTemplateLang().getLanguage();
    }

    Language substituteLang = LanguageSubstitutors.INSTANCE.substituteLanguage(dataLang, file, manager.getProject());

    // only use a substituted language if it's templateable
    if (TemplateDataLanguageMappings.getTemplateableLanguages().contains(substituteLang)) {
        dataLang = substituteLang;
    }

    return dataLang;
}
项目:consulo    文件:EditorHighlighterFactoryImpl.java   
@javax.annotation.Nullable
private static LanguageFileType substituteFileType(Language language, VirtualFile vFile, Project project) {
  LanguageFileType fileType = null;
  if (vFile != null && project != null) {
    Language substLanguage = LanguageSubstitutors.INSTANCE.substituteLanguage(language, vFile, project);
    if (substLanguage != language) {
      fileType = substLanguage.getAssociatedFileType();
    }
  }
  return fileType;
}
项目:consulo    文件:FileContentImpl.java   
@Nonnull
@RequiredReadAction
public static PsiFile createFileFromText(@Nonnull Project project, @Nonnull CharSequence text, @Nonnull LanguageFileType fileType,
                                         @Nonnull VirtualFile file, @Nonnull String fileName) {
  final Language language = fileType.getLanguage();
  final Language substitutedLanguage = LanguageSubstitutors.INSTANCE.substituteLanguage(language, file, project);
  LanguageVersion languageVersion =
          LanguageVersionResolvers.INSTANCE.forLanguage(substitutedLanguage).getLanguageVersion(substitutedLanguage, project, file);
  return PsiFileFactory.getInstance(project).createFileFromText(fileName, languageVersion, text, false, false, true, file);
}
项目:consulo    文件:ScratchFileServiceImpl.java   
@Nullable
public static Language substituteLanguage(@Nonnull Project project, @Nonnull VirtualFile file) {
  RootType rootType = ScratchFileService.getInstance().getRootType(file);
  if (rootType == null) return null;
  Language language = rootType.substituteLanguage(project, file);
  Language adjusted = language != null ? language : getLanguageByFileName(file);
  return adjusted != null && adjusted != ScratchFileType.INSTANCE.getLanguage()
         ? LanguageSubstitutors.INSTANCE.substituteLanguage(adjusted, file, project)
         : adjusted;
}
项目:intellij-ce-playground    文件:StubIndexImpl.java   
@Override
protected <Psi extends PsiElement> void reportStubPsiMismatch(Psi psi, VirtualFile file, Class<Psi> requiredClass) {
  if (file == null) {
    super.reportStubPsiMismatch(psi, file, requiredClass);
    return;
  }

  StringWriter writer = new StringWriter();
  //noinspection IOResourceOpenedButNotSafelyClosed
  PrintWriter out = new PrintWriter(writer);

  out.print("Invalid stub element type in index:");
  out.printf("\nfile: %s\npsiElement: %s\nrequiredClass: %s\nactualClass: %s",
             file, psi, requiredClass, psi.getClass());

  FileType fileType = file.getFileType();
  Language language = fileType instanceof LanguageFileType ?
                      LanguageSubstitutors.INSTANCE.substituteLanguage(((LanguageFileType)fileType).getLanguage(), file, psi.getProject()) :
                      Language.ANY;
  out.printf("\nvirtualFile: size:%s; stamp:%s; modCount:%s; fileType:%s; language:%s",
             file.getLength(), file.getModificationStamp(), file.getModificationCount(),
             fileType.getName(), language.getID());

  Document document = FileDocumentManager.getInstance().getCachedDocument(file);
  if (document != null) {
    boolean committed = PsiDocumentManager.getInstance(psi.getProject()).isCommitted(document);
    boolean saved = !FileDocumentManager.getInstance().isDocumentUnsaved(document);
    out.printf("\ndocument: size:%s; stamp:%s; committed:%s; saved:%s",
               document.getTextLength(), document.getModificationStamp(), committed, saved);
  }

  PsiFile psiFile = psi.getManager().findFile(file);
  if (psiFile != null) {
    out.printf("\npsiFile: size:%s; stamp:%s; class:%s; language:%s",
               psiFile.getTextLength(), psiFile.getViewProvider().getModificationStamp(), psiFile.getClass().getName(),
               psiFile.getLanguage().getID());
  }

  StubTree stub = psiFile instanceof PsiFileWithStubSupport ? ((PsiFileWithStubSupport)psiFile).getStubTree() : null;
  FileElement treeElement = stub == null && psiFile instanceof PsiFileImpl? ((PsiFileImpl)psiFile).getTreeElement() : null;
  if (stub != null) {
    out.printf("\nstubInfo: " + stub.getDebugInfo());
  }
  else if (treeElement != null) {
    out.printf("\nfileAST: size:%s; parsed:%s", treeElement.getTextLength(), treeElement.isParsed());
  }

  out.printf("\nindexing info: " + StubUpdatingIndex.getIndexingStampInfo(file));
  LOG.error(writer.toString());
}
项目:intellij-ce-playground    文件:RootType.java   
@Nullable
protected static Language substituteLanguageImpl(Language language, VirtualFile file, Project project) {
  return language != null && language != ScratchFileType.INSTANCE.getLanguage() ?
         LanguageSubstitutors.INSTANCE.substituteLanguage(language, file, project) : language;
}
项目:consulo    文件:LanguageUtil.java   
@Nullable
public static Language getLanguageForPsi(@Nonnull Project project, @Nullable VirtualFile file) {
  Language language = getFileLanguage(file);
  if (language == null) return null;
  return LanguageSubstitutors.INSTANCE.substituteLanguage(language, file, project);
}
项目:consulo    文件:StubIndexImpl.java   
@Override
protected <Psi extends PsiElement> void reportStubPsiMismatch(Psi psi, VirtualFile file, Class<Psi> requiredClass) {
  if (file == null) {
    super.reportStubPsiMismatch(psi, file, requiredClass);
    return;
  }

  StringWriter writer = new StringWriter();
  //noinspection IOResourceOpenedButNotSafelyClosed
  PrintWriter out = new PrintWriter(writer);

  out.print("Invalid stub element type in index:");
  out.printf("\nfile: %s\npsiElement: %s\nrequiredClass: %s\nactualClass: %s",
             file, psi, requiredClass, psi.getClass());

  FileType fileType = file.getFileType();
  Language language = fileType instanceof LanguageFileType ?
                      LanguageSubstitutors.INSTANCE.substituteLanguage(((LanguageFileType)fileType).getLanguage(), file, psi.getProject()) :
                      Language.ANY;
  out.printf("\nvirtualFile: size:%s; stamp:%s; modCount:%s; fileType:%s; language:%s",
             file.getLength(), file.getModificationStamp(), file.getModificationCount(),
             fileType.getName(), language.getID());

  Document document = FileDocumentManager.getInstance().getCachedDocument(file);
  if (document != null) {
    boolean committed = PsiDocumentManager.getInstance(psi.getProject()).isCommitted(document);
    boolean saved = !FileDocumentManager.getInstance().isDocumentUnsaved(document);
    out.printf("\ndocument: size:%s; stamp:%s; committed:%s; saved:%s",
               document.getTextLength(), document.getModificationStamp(), committed, saved);
  }

  PsiFile psiFile = psi.getManager().findFile(file);
  if (psiFile != null) {
    out.printf("\npsiFile: size:%s; stamp:%s; class:%s; language:%s",
               psiFile.getTextLength(), psiFile.getViewProvider().getModificationStamp(), psiFile.getClass().getName(),
               psiFile.getLanguage().getID());
  }

  StubTree stub = psiFile instanceof PsiFileWithStubSupport ? ((PsiFileWithStubSupport)psiFile).getStubTree() : null;
  FileElement treeElement = stub == null && psiFile instanceof PsiFileImpl? ((PsiFileImpl)psiFile).getTreeElement() : null;
  if (stub != null) {
    out.printf("\nstubInfo: " + stub.getDebugInfo());
  }
  else if (treeElement != null) {
    out.printf("\nfileAST: size:%s; parsed:%s", treeElement.getTextLength(), treeElement.isParsed());
  }

  out.printf("\nindexing info: " + StubUpdatingIndex.getIndexingStampInfo(file));
  LOG.error(writer.toString());
}
项目:consulo-apache-velocity    文件:VtlFileViewProvider.java   
public VtlFileViewProvider(final PsiManager manager, final VirtualFile virtualFile, final boolean physical) {
    super(manager, virtualFile, physical);
    final Language language = getTemplateDataLanguage(virtualFile, manager.getProject());
    myTemplateDataLanguage = language instanceof TemplateLanguage ? PlainTextLanguage.INSTANCE : LanguageSubstitutors.INSTANCE.substituteLanguage(language, virtualFile, manager.getProject());
}