use of com.intellij.lang.Language in project idea-handlebars by dmarcotte.
the class HbFileType method getAssociatedFileType.
private static LanguageFileType getAssociatedFileType(VirtualFile file, Project project) {
if (project == null) {
return null;
}
Language language = TemplateDataLanguageMappings.getInstance(project).getMapping(file);
LanguageFileType associatedFileType = null;
if (language != null) {
associatedFileType = language.getAssociatedFileType();
}
if (language == null || associatedFileType == null) {
associatedFileType = HbLanguage.getDefaultTemplateLang();
}
return associatedFileType;
}
use of com.intellij.lang.Language in project idea-handlebars by dmarcotte.
the class HbConfigurationPage method resetCommentLanguageCombo.
private void resetCommentLanguageCombo(Language commentLanguage) {
final DefaultComboBoxModel model = (DefaultComboBoxModel) myCommenterLanguage.getModel();
final List<Language> languages = TemplateDataLanguageMappings.getTemplateableLanguages();
// add using the native Handlebars commenter as an option
languages.add(HbLanguage.INSTANCE);
Collections.sort(languages, new Comparator<Language>() {
@Override
public int compare(final Language o1, final Language o2) {
return o1.getID().compareTo(o2.getID());
}
});
for (Language language : languages) {
model.addElement(language);
}
myCommenterLanguage.setRenderer(new ListCellRendererWrapper() {
@Override
public void customize(JList list, Object value, int index, boolean selected, boolean hasFocus) {
setText(value == null ? "" : ((Language) value).getDisplayName());
if (value != null) {
final FileType type = ((Language) value).getAssociatedFileType();
if (type != null) {
setIcon(type.getIcon());
}
}
}
});
myCommenterLanguage.setSelectedItem(commentLanguage);
}
use of com.intellij.lang.Language in project Main by SpartanRefactoring.
the class LeonidasTipper method getPsiTreeFromString.
/**
* @param name the name of the tipper
* @param content the definition file of the tipper
* @return PsiFile representing the file of the tipper
*/
private PsiJavaFile getPsiTreeFromString(String name, String content) {
Language language = JavaLanguage.INSTANCE;
LightVirtualFile virtualFile = new LightVirtualFile(name, language, content);
SingleRootFileViewProvider.doNotCheckFileSizeLimit(virtualFile);
final FileViewProviderFactory factory = LanguageFileViewProviders.INSTANCE.forLanguage(language);
FileViewProvider viewProvider = factory != null ? factory.createFileViewProvider(virtualFile, language, Utils.getPsiManager(Utils.getProject()), true) : null;
if (viewProvider == null)
viewProvider = new SingleRootFileViewProvider(Utils.getPsiManager(ProjectManager.getInstance().getDefaultProject()), virtualFile, true);
language = viewProvider.getBaseLanguage();
final ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(language);
if (parserDefinition != null) {
return (PsiJavaFile) viewProvider.getPsi(language);
}
return null;
}
use of com.intellij.lang.Language in project intellij-community by JetBrains.
the class MavenPluginConfigurationLanguageInjector method getLanguagesToInject.
@Override
public void getLanguagesToInject(@NotNull final PsiLanguageInjectionHost host, @NotNull final InjectedLanguagePlaces injectionPlacesRegistrar) {
if (host.isValid() && host.getContainingFile().getLanguage().is(HTMLLanguage.INSTANCE))
return;
if (!(host instanceof XmlText))
return;
final XmlText xmlText = (XmlText) host;
if (!MavenPluginParamInfo.isSimpleText(xmlText))
return;
MavenPluginParamInfo.ParamInfoList infoList = MavenPluginParamInfo.getParamInfoList(xmlText);
for (MavenPluginParamInfo.ParamInfo info : infoList) {
Language language = info.getLanguage();
if (language == null) {
MavenParamLanguageProvider provider = info.getLanguageProvider();
if (provider != null) {
language = provider.getLanguage(xmlText, infoList.getDomCfg());
}
}
if (language != null) {
injectionPlacesRegistrar.addPlace(language, TextRange.from(0, host.getTextLength()), info.getLanguageInjectionPrefix(), info.getLanguageInjectionSuffix());
return;
}
}
}
use of com.intellij.lang.Language in project intellij-community by JetBrains.
the class PyTypingAnnotationInjector method registerCommentInjection.
@NotNull
private static PyInjectionUtil.InjectionResult registerCommentInjection(@NotNull MultiHostRegistrar registrar, @NotNull PsiLanguageInjectionHost host) {
final String text = host.getText();
final Matcher m = PyTypingTypeProvider.TYPE_COMMENT_PATTERN.matcher(text);
if (m.matches()) {
final String annotationText = m.group(1);
if (annotationText != null) {
final int start = m.start(1);
final int end = m.end(1);
if (start < end && allowInjectionInComment(host)) {
Language language = null;
if ("ignore".equals(annotationText)) {
language = null;
} else if (isFunctionTypeComment(host)) {
language = PyFunctionTypeAnnotationDialect.INSTANCE;
} else if (isTypingAnnotation(annotationText)) {
language = PyDocstringLanguageDialect.getInstance();
}
if (language != null) {
registrar.startInjecting(language);
registrar.addPlace("", "", host, TextRange.create(start, end));
registrar.doneInjecting();
return new PyInjectionUtil.InjectionResult(true, true);
}
}
}
}
return PyInjectionUtil.InjectionResult.EMPTY;
}
Aggregations