本文整理汇总了Java中com.intellij.lang.LanguageUtil.getLanguageForPsi方法的典型用法代码示例。如果您正苦于以下问题:Java LanguageUtil.getLanguageForPsi方法的具体用法?Java LanguageUtil.getLanguageForPsi怎么用?Java LanguageUtil.getLanguageForPsi使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.lang.LanguageUtil
的用法示例。
在下文中一共展示了LanguageUtil.getLanguageForPsi方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: updateFileExtension
import com.intellij.lang.LanguageUtil; //导入方法依赖的package包/类
public static void updateFileExtension(@Nonnull Project project, @Nullable VirtualFile file) throws IOException {
ApplicationManager.getApplication().assertWriteAccessAllowed();
if (CommandProcessor.getInstance().getCurrentCommand() == null) {
throw new AssertionError("command required");
}
if (file == null) return;
Language language = LanguageUtil.getLanguageForPsi(project, file);
FileType expected = getFileTypeFromName(file);
FileType actual = language == null ? null : language.getAssociatedFileType();
if (expected == actual || actual == null) return;
String ext = actual.getDefaultExtension();
if (StringUtil.isEmpty(ext)) return;
String newName = PathUtil.makeFileName(file.getNameWithoutExtension(), ext);
VirtualFile parent = file.getParent();
newName = parent != null && parent.findChild(newName) != null ? PathUtil.makeFileName(file.getName(), ext) : newName;
file.rename(ScratchUtil.class, newName);
}
示例2: calcBaseLanguage
import com.intellij.lang.LanguageUtil; //导入方法依赖的package包/类
private static Language calcBaseLanguage(@Nonnull VirtualFile file, @Nonnull Project project, @Nonnull final FileType fileType) {
if (fileType.isBinary()) return Language.ANY;
if (isTooLargeForIntelligence(file)) return PlainTextLanguage.INSTANCE;
Language language = LanguageUtil.getLanguageForPsi(project, file);
return language != null ? language : PlainTextLanguage.INSTANCE;
}
示例3: createFileViewProvider
import com.intellij.lang.LanguageUtil; //导入方法依赖的package包/类
@Override
@Nonnull
public FileViewProvider createFileViewProvider(@Nonnull final VirtualFile file, boolean eventSystemEnabled) {
FileType fileType = file.getFileType();
Language language = LanguageUtil.getLanguageForPsi(myManager.getProject(), file);
FileViewProviderFactory factory = language == null
? FileTypeFileViewProviders.INSTANCE.forFileType(fileType)
: LanguageFileViewProviders.INSTANCE.forLanguage(language);
FileViewProvider viewProvider = factory == null ? null : factory.createFileViewProvider(file, language, myManager, eventSystemEnabled);
return viewProvider == null ? new SingleRootFileViewProvider(myManager, file, eventSystemEnabled, fileType) : viewProvider;
}
示例4: create
import com.intellij.lang.LanguageUtil; //导入方法依赖的package包/类
@Override
@Nullable
public SyntaxHighlighter create(@Nonnull FileType fileType, @Nullable Project project, @Nullable VirtualFile file) {
if (project == null || file == null || !(fileType instanceof ScratchFileType)) return null;
Language language = LanguageUtil.getLanguageForPsi(project, file);
return language == null ? null : SyntaxHighlighterFactory.getSyntaxHighlighter(language, project, file);
}
示例5: hasMatchingExtension
import com.intellij.lang.LanguageUtil; //导入方法依赖的package包/类
public static boolean hasMatchingExtension(@Nonnull Project project, @Nonnull VirtualFile file) {
FileType expected = getFileTypeFromName(file);
Language language = LanguageUtil.getLanguageForPsi(project, file);
FileType actual = language == null ? null : language.getAssociatedFileType();
return expected == actual && actual != null;
}