use of com.intellij.lang.Language in project intellij-community by JetBrains.
the class ConcatenationInjector method getLanguagesToInject.
public void getLanguagesToInject(@NotNull final MultiHostRegistrar registrar, @NotNull PsiElement... operands) {
if (operands.length == 0)
return;
boolean hasLiteral = false;
InjectedLanguage tempInjectedLanguage = null;
PsiFile containingFile = null;
for (PsiElement operand : operands) {
if (PsiUtilEx.isStringOrCharacterLiteral(operand)) {
hasLiteral = true;
if (containingFile == null) {
containingFile = operands[0].getContainingFile();
}
tempInjectedLanguage = myTemporaryPlacesRegistry.getLanguageFor((PsiLanguageInjectionHost) operand, containingFile);
if (tempInjectedLanguage != null)
break;
}
}
if (!hasLiteral)
return;
final Language tempLanguage = tempInjectedLanguage == null ? null : tempInjectedLanguage.getLanguage();
final PsiFile finalContainingFile = containingFile;
InjectionProcessor injectionProcessor = new InjectionProcessor(myConfiguration, mySupport, operands) {
@Override
protected void processInjection(Language language, List<Trinity<PsiLanguageInjectionHost, InjectedLanguage, TextRange>> list, boolean settingsAvailable, boolean unparsable) {
InjectorUtils.registerInjection(language, list, finalContainingFile, registrar);
InjectorUtils.registerSupport(mySupport, settingsAvailable, registrar);
InjectorUtils.putInjectedFileUserData(registrar, InjectedLanguageUtil.FRANKENSTEIN_INJECTION, unparsable ? Boolean.TRUE : null);
}
@Override
protected boolean areThereInjectionsWithName(String methodName, boolean annoOnly) {
if (methodName == null)
return false;
if (getAnnotatedElementsValue().contains(methodName)) {
return true;
}
if (!annoOnly && getXmlAnnotatedElementsValue().contains(methodName)) {
return true;
}
return false;
}
};
if (tempLanguage != null) {
BaseInjection baseInjection = new BaseInjection(JavaLanguageInjectionSupport.JAVA_SUPPORT_ID);
baseInjection.setInjectedLanguageId(tempInjectedLanguage.getID());
injectionProcessor.processInjectionInner(baseInjection, false);
InjectorUtils.putInjectedFileUserData(registrar, LanguageInjectionSupport.TEMPORARY_INJECTED_LANGUAGE, tempInjectedLanguage);
} else {
injectionProcessor.processInjections();
}
}
use of com.intellij.lang.Language in project intellij-community by JetBrains.
the class XDebuggerEditorBase method createLanguagePopup.
private ListPopup createLanguagePopup() {
DefaultActionGroup actions = new DefaultActionGroup();
for (Language language : getSupportedLanguages()) {
//noinspection ConstantConditions
actions.add(new AnAction(language.getDisplayName(), null, language.getAssociatedFileType().getIcon()) {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
XExpression currentExpression = getExpression();
setExpression(new XExpressionImpl(currentExpression.getExpression(), language, currentExpression.getCustomInfo()));
requestFocusInEditor();
}
});
}
DataContext dataContext = DataManager.getInstance().getDataContext(getComponent());
return JBPopupFactory.getInstance().createActionGroupPopup("Choose Language", actions, dataContext, JBPopupFactory.ActionSelectionAid.SPEEDSEARCH, false);
}
use of com.intellij.lang.Language in project intellij-community by JetBrains.
the class InjectLanguageAction method getAllInjectables.
public static List<Injectable> getAllInjectables() {
Language[] languages = InjectedLanguage.getAvailableLanguages();
List<Injectable> list = new ArrayList<>();
for (Language language : languages) {
list.add(Injectable.fromLanguage(language));
}
list.addAll(Arrays.asList(ReferenceInjector.EXTENSION_POINT_NAME.getExtensions()));
Collections.sort(list);
return list;
}
use of com.intellij.lang.Language in project intellij-community by JetBrains.
the class InjectorUtils method getLanguageByString.
@Nullable
public static Language getLanguageByString(String languageId) {
Language language = InjectedLanguage.findLanguageById(languageId);
if (language != null)
return language;
ReferenceInjector injector = ReferenceInjector.findById(languageId);
if (injector != null)
return injector.toLanguage();
FileType fileType = FileTypeManager.getInstance().getFileTypeByExtension(languageId);
return fileType instanceof LanguageFileType ? ((LanguageFileType) fileType).getLanguage() : null;
}
use of com.intellij.lang.Language in project intellij-community by JetBrains.
the class UnInjectLanguageAction method defaultFunctionalityWorked.
private static boolean defaultFunctionalityWorked(final PsiLanguageInjectionHost host) {
final THashSet<String> languages = new THashSet<>();
final List<Pair<PsiElement, TextRange>> files = InjectedLanguageManager.getInstance(host.getProject()).getInjectedPsiFiles(host);
if (files == null)
return false;
for (Pair<PsiElement, TextRange> pair : files) {
for (Language lang = pair.first.getLanguage(); lang != null; lang = lang.getBaseLanguage()) {
languages.add(lang.getID());
}
}
// todo therefore this part doesn't work for java
return Configuration.getProjectInstance(host.getProject()).setHostInjectionEnabled(host, languages, false);
}
Aggregations