本文整理汇总了Java中com.intellij.lang.LanguageUtil类的典型用法代码示例。如果您正苦于以下问题:Java LanguageUtil类的具体用法?Java LanguageUtil怎么用?Java LanguageUtil使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
LanguageUtil类属于com.intellij.lang包,在下文中一共展示了LanguageUtil类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getLanguagesToInject
import com.intellij.lang.LanguageUtil; //导入依赖的package包/类
@Override
public void getLanguagesToInject(@NotNull MultiHostRegistrar registrar, @NotNull PsiElement host) {
if (!host.isValid() || !(host instanceof XmlText) || !HtmlUtil.isHtmlTagContainingFile(host)) {
return;
}
XmlTag scriptTag = ((XmlText)host).getParentTag();
if (scriptTag == null) {
return;
}
final Language language = getScriptLanguageToInject(scriptTag);
if (language == null || HtmlScriptInjectionBlockerExtension.isInjectionBlocked(scriptTag, language)) {
return;
}
if (LanguageUtil.isInjectableLanguage(language)) {
registrar
.startInjecting(language)
.addPlace(null, null, (PsiLanguageInjectionHost)host, TextRange.create(0, host.getTextLength()))
.doneInjecting();
}
}
示例2: createAnchorInfo
import com.intellij.lang.LanguageUtil; //导入依赖的package包/类
@Nullable
private static SmartPointerElementInfo createAnchorInfo(@Nonnull PsiElement element, @Nonnull PsiFile containingFile) {
if (element instanceof StubBasedPsiElement && containingFile instanceof PsiFileImpl) {
IStubFileElementType stubType = ((PsiFileImpl)containingFile).getElementTypeForStubBuilder();
if (stubType != null && stubType.shouldBuildStubFor(containingFile.getViewProvider().getVirtualFile())) {
StubBasedPsiElement stubPsi = (StubBasedPsiElement)element;
int stubId = PsiAnchor.calcStubIndex(stubPsi);
if (stubId != -1) {
return new AnchorElementInfo(element, (PsiFileImpl)containingFile, stubId, stubPsi.getElementType());
}
}
}
Pair<Identikit.ByAnchor, PsiElement> pair = Identikit.withAnchor(element, LanguageUtil.getRootLanguage(containingFile));
if (pair != null) {
return new AnchorElementInfo(pair.second, containingFile, pair.first);
}
return null;
}
示例3: 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);
}
示例4: injectLanguages
import com.intellij.lang.LanguageUtil; //导入依赖的package包/类
@Override
public void injectLanguages(@NotNull MultiHostRegistrar registrar, @NotNull PsiElement host) {
if (!(host instanceof XmlText)) {
return;
}
XmlTag scriptTag = ((XmlText)host).getParentTag();
if (!"script".equalsIgnoreCase(scriptTag.getLocalName())) {
return;
}
String mimeType = scriptTag.getAttributeValue("type");
Collection<Language> languages = Language.findInstancesByMimeType(mimeType);
Language language = languages.isEmpty() ? null : languages.iterator().next();
if (language != null && LanguageUtil.isInjectableLanguage(language)) {
registrar
.startInjecting(language)
.addPlace(null, null, (PsiLanguageInjectionHost)host, TextRange.create(0, host.getTextLength()))
.doneInjecting();
}
}
示例5: fromXExpression
import com.intellij.lang.LanguageUtil; //导入依赖的package包/类
public static TextWithImports fromXExpression(@Nullable XExpression expression)
{
if(expression == null)
{
return null;
}
if(expression.getCustomInfo() == null && expression.getLanguage() == null)
{
return new TextWithImportsImpl(getKind(expression.getMode()), expression.getExpression());
}
else
{
return new TextWithImportsImpl(getKind(expression.getMode()), expression.getExpression(), StringUtil.notNullize(expression.getCustomInfo()), LanguageUtil.getLanguageFileType(expression.getLanguage()));
}
}
示例6: updateDialectsAndContexts
import com.intellij.lang.LanguageUtil; //导入依赖的package包/类
private void updateDialectsAndContexts() {
final FileType fileType = (FileType)fileTypes.getSelectedItem();
if (fileType instanceof LanguageFileType) {
Language language = ((LanguageFileType)fileType).getLanguage();
Language[] languageDialects = LanguageUtil.getLanguageDialects(language);
Arrays.sort(languageDialects, new Comparator<Language>() {
@Override
public int compare(Language o1, Language o2) {
return o1.getDisplayName().compareTo(o2.getDisplayName());
}
});
Language[] variants = new Language[languageDialects.length + 1];
variants[0] = null;
System.arraycopy(languageDialects, 0, variants, 1, languageDialects.length);
dialects.setModel(new DefaultComboBoxModel(variants));
dialects.setEnabled(variants.length > 1);
}
final StructuralSearchProfile profile = StructuralSearchUtil.getProfileByFileType(fileType);
if (profile instanceof StructuralSearchProfileBase) {
final String[] contextNames = ((StructuralSearchProfileBase)profile).getContextNames();
if (contextNames.length > 0) {
contexts.setModel(new DefaultComboBoxModel(contextNames));
contexts.setSelectedItem(contextNames[0]);
contexts.setEnabled(true);
return;
}
}
contexts.setSelectedItem(null);
contexts.setEnabled(false);
}
示例7: updateDialectsCombo
import com.intellij.lang.LanguageUtil; //导入依赖的package包/类
private void updateDialectsCombo(@Nullable final String lastUsed) {
final Object source = getSource();
ArrayList<Language> items = new ArrayList<Language>();
if (source instanceof LanguageFileType) {
final Language baseLang = ((LanguageFileType)source).getLanguage();
items.add(baseLang);
Language[] dialects = LanguageUtil.getLanguageDialects(baseLang);
Arrays.sort(dialects, LanguageUtil.LANGUAGE_COMPARATOR);
items.addAll(Arrays.asList(dialects));
}
myDialectComboBox.setModel(new CollectionComboBoxModel(items));
final int size = items.size();
final boolean visible = size > 1;
myDialectLabel.setVisible(visible);
myDialectComboBox.setVisible(visible);
if (visible && (myCurrentFile != null || lastUsed != null)) {
String curLanguage = myCurrentFile != null ? myCurrentFile.getLanguage().toString() : lastUsed;
for (int i = 0; i < size; ++i) {
if (curLanguage.equals(items.get(i).toString())) {
myDialectComboBox.setSelectedIndex(i);
return;
}
}
myDialectComboBox.setSelectedIndex(size > 0 ? 0 : -1);
}
}
示例8: forFileLanguages
import com.intellij.lang.LanguageUtil; //导入依赖的package包/类
@NotNull
public static ListPopup forFileLanguages(@NotNull Project project, @Nullable final Language selection, @NotNull final Consumer<Language> onChosen) {
return languagePopupBuilder(project, "Languages").
forValues(LanguageUtil.getFileLanguages()).
withSelection(selection).
onChosen(onChosen).
buildPopup();
}
示例9: getAllFilterValues
import com.intellij.lang.LanguageUtil; //导入依赖的package包/类
@NotNull
@Override
protected Collection<Language> getAllFilterValues() {
final Collection<Language> registeredLanguages = Language.getRegisteredLanguages();
List<Language> accepted = new ArrayList<Language>();
for (Language language : registeredLanguages) {
if (language != Language.ANY && !(language instanceof DependentLanguage)) {
accepted.add(language);
}
}
Collections.sort(accepted, LanguageUtil.LANGUAGE_COMPARATOR);
return accepted;
}
示例10: generateWhitespaceBetweenTokens
import com.intellij.lang.LanguageUtil; //导入依赖的package包/类
public ASTNode generateWhitespaceBetweenTokens(ASTNode left, ASTNode right) {
PsiManager manager = right.getTreeParent().getPsi().getManager();
if (left.getElementType() == PyTokenTypes.END_OF_LINE_COMMENT) {
return createLineBreak(manager);
}
if (left.getPsi().isValid() && right.getPsi().isValid()) {
final PsiElement commonParent = PsiTreeUtil.findCommonParent(left.getPsi(), right.getPsi());
if (commonParent == null) return null;
final PsiElement leftPrevAncestor = PsiTreeUtil.findPrevParent(commonParent, left.getPsi());
final PsiElement rightPrevAncestor = PsiTreeUtil.findPrevParent(commonParent, right.getPsi());
if (isStatementOrFunction(leftPrevAncestor) && isStatementOrFunction(rightPrevAncestor)) {
int leftIndent = PyPsiUtils.getElementIndentation(leftPrevAncestor);
int rightIndent = PyPsiUtils.getElementIndentation(rightPrevAncestor);
int maxIndent = Math.max(leftIndent, rightIndent);
return createWhitespace(manager, "\n" + StringUtil.repeatSymbol(' ', maxIndent));
}
}
if (right.getElementType() == PyTokenTypes.DEF_KEYWORD || right.getElementType() == PyTokenTypes.CLASS_KEYWORD) {
return createLineBreak(manager);
}
if (left.getElementType() == TokenType.WHITE_SPACE || right.getElementType() == TokenType.WHITE_SPACE) {
return null;
}
final PyStatement leftStatement = PsiTreeUtil.getParentOfType(left.getPsi(), PyStatement.class);
if (leftStatement != null && !PsiTreeUtil.isAncestor(leftStatement, right.getPsi(), false)) {
return createLineBreak(manager);
}
final Lexer lexer = new PythonIndentingLexer();
if (LanguageUtil.canStickTokensTogetherByLexer(left, right, lexer) == ParserDefinition.SpaceRequirements.MUST) {
return createSpace(manager);
}
return null;
}
示例11: getTokenType
import com.intellij.lang.LanguageUtil; //导入依赖的package包/类
public IElementType getTokenType() {
if (myTokenType!=null) return myTokenType;
IElementType tokenType = super.getTokenType();
myTokenStart = super.getTokenStart();
myTokenEnd = super.getTokenEnd();
if (hasSeenStyle()) {
if (hasSeenTag() && ourStyleElementType!=null && isStartOfEmbeddmentTagContent(tokenType)) {
myTokenEnd = skipToTheEndOfTheEmbeddment();
tokenType = ourStyleElementType;
} else if (ourInlineStyleElementType!=null && isStartOfEmbeddmentAttributeValue(tokenType) && hasSeenAttribute()) {
tokenType = ourInlineStyleElementType;
}
} else if (hasSeenScript()) {
Language scriptLanguage = getScriptLanguage();
boolean canInject = scriptLanguage == null || LanguageUtil.isInjectableLanguage(scriptLanguage);
if (hasSeenTag() && isStartOfEmbeddmentTagContent(tokenType) && canInject) {
myTokenEnd = skipToTheEndOfTheEmbeddment();
IElementType currentScriptElementType = getCurrentScriptElementType();
tokenType = currentScriptElementType == null ? XmlTokenType.XML_DATA_CHARACTERS : currentScriptElementType;
} else if (hasSeenAttribute() && isStartOfEmbeddmentAttributeValue(tokenType) && ourInlineScriptElementType!=null) {
myTokenEnd = skipToTheEndOfTheEmbeddment();
tokenType = ourInlineScriptElementType;
}
}
return myTokenType = tokenType;
}
示例12: initLanguageCache
import com.intellij.lang.LanguageUtil; //导入依赖的package包/类
private static void initLanguageCache() {
ourLanguageCache = new HashMap<String, Language>();
Collection<Language> registeredLanguages;
do {
registeredLanguages = new ArrayList<Language>(Language.getRegisteredLanguages());
for (Language language : registeredLanguages) {
if (LanguageUtil.isInjectableLanguage(language)) {
ourLanguageCache.put(language.getID(), language);
}
}
} while (Language.getRegisteredLanguages().size() != registeredLanguages.size());
ourLanguageCount = registeredLanguages.size();
}
示例13: spaceExistanceTypeBetweenTokens
import com.intellij.lang.LanguageUtil; //导入依赖的package包/类
@Override
public SpaceRequirements spaceExistanceTypeBetweenTokens(ASTNode left, ASTNode right) {
final IElementType lType = left.getElementType();
final IElementType rType = right.getElementType();
if (rType == GroovyTokenTypes.kIMPORT && lType != TokenType.WHITE_SPACE) {
return SpaceRequirements.MUST_LINE_BREAK;
}
else if (lType == MODIFIERS && rType == MODIFIERS) {
return SpaceRequirements.MUST;
}
if (lType == GroovyTokenTypes.mSEMI || lType == GroovyTokenTypes.mSL_COMMENT) {
return SpaceRequirements.MUST_LINE_BREAK;
}
if (lType == GroovyTokenTypes.mNLS || lType == GroovyDocTokenTypes.mGDOC_COMMENT_START) {
return SpaceRequirements.MAY;
}
if (lType == GroovyTokenTypes.mGT) return SpaceRequirements.MUST;
if (rType == GroovyTokenTypes.mLT) return SpaceRequirements.MUST;
final ASTNode parent = TreeUtil.findCommonParent(left, right);
if (parent == null || ArrayUtil.contains(parent.getElementType(), STRINGS)) {
return SpaceRequirements.MUST_NOT;
}
return LanguageUtil.canStickTokensTogetherByLexer(left, right, new GroovyLexer());
}
示例14: spaceExistanceTypeBetweenTokens
import com.intellij.lang.LanguageUtil; //导入依赖的package包/类
@NotNull
public SpaceRequirements spaceExistanceTypeBetweenTokens(@NotNull final ASTNode left, @NotNull final ASTNode right) {
if (left.getElementType() == OCamlElementTypes.LABEL_NAME && right.getElementType() == OCamlTokenTypes.COLON) {
return SpaceRequirements.MUST_NOT;
}
return LanguageUtil.canStickTokensTogetherByLexer(left, right, doCreateLexer());
}
示例15: getLanguagesToInject
import com.intellij.lang.LanguageUtil; //导入依赖的package包/类
@Override
public void getLanguagesToInject(@NotNull MultiHostRegistrar registrar, @NotNull PsiElement host) {
if (!host.isValid() || !(host instanceof XmlText) || !HtmlUtil.isHtmlTagContainingFile(host)) {
return;
}
XmlTag scriptTag = ((XmlText)host).getParentTag();
if (scriptTag == null || !"script".equalsIgnoreCase(scriptTag.getLocalName())) {
return;
}
String mimeType = scriptTag.getAttributeValue("type");
Collection<Language> languages = Language.findInstancesByMimeType(mimeType);
Language language;
if (!languages.isEmpty()) {
language = languages.iterator().next();
}
else if (mimeType != null && mimeType.contains("template")) {
language = StdLanguages.HTML;
}
else {
language = StdLanguages.TEXT;
}
if (LanguageUtil.isInjectableLanguage(language)) {
registrar
.startInjecting(language)
.addPlace(null, null, (PsiLanguageInjectionHost)host, TextRange.create(0, host.getTextLength()))
.doneInjecting();
}
}