use of com.intellij.lang.Language in project intellij-community by JetBrains.
the class XmlAutoPopupHandler method isLanguageRelevant.
private static boolean isLanguageRelevant(final PsiElement element, final PsiFile file, final Ref<Boolean> isRelevantLanguage, final Ref<Boolean> isAnt) {
Boolean isAntFile = isAnt.get();
if (isAntFile == null) {
isAntFile = XmlUtil.isAntFile(file);
isAnt.set(isAntFile);
}
Boolean result = isRelevantLanguage.get();
if (result == null) {
Language language = element.getLanguage();
PsiElement parent = element.getParent();
if (element instanceof PsiWhiteSpace && parent != null) {
language = parent.getLanguage();
}
result = language instanceof XMLLanguage || HtmlUtil.supportsXmlTypedHandlers(file) || isAntFile.booleanValue();
isRelevantLanguage.set(result);
}
return result.booleanValue();
}
use of com.intellij.lang.Language in project intellij-community by JetBrains.
the class XmlAutoPopupHandler method autoPopupXmlLookup.
public static void autoPopupXmlLookup(final Project project, final Editor editor) {
AutoPopupController.getInstance(project).autoPopupMemberLookup(editor, file -> {
int offset = editor.getCaretModel().getOffset();
PsiElement lastElement = InjectedLanguageUtil.findElementAtNoCommit(file, offset - 1);
if (lastElement instanceof PsiFile) {
lastElement = file.findElementAt(offset - 1);
}
if (lastElement == null || !lastElement.isValid())
return false;
if (doCompleteIfNeeded(offset, file, lastElement)) {
return true;
}
FileViewProvider fileViewProvider = file.getViewProvider();
Language templateDataLanguage;
final PsiElement parent = lastElement.getParent();
if (fileViewProvider instanceof TemplateLanguageFileViewProvider && (templateDataLanguage = ((TemplateLanguageFileViewProvider) fileViewProvider).getTemplateDataLanguage()) != parent.getLanguage()) {
lastElement = fileViewProvider.findElementAt(offset - 1, templateDataLanguage);
if (lastElement == null || !lastElement.isValid())
return false;
return doCompleteIfNeeded(offset, file, lastElement);
}
return false;
});
}
use of com.intellij.lang.Language in project intellij-community by JetBrains.
the class XmlTagNameSynchronizer method installSynchronizer.
private void installSynchronizer(final Editor editor) {
final Project project = editor.getProject();
if (project == null)
return;
final Document document = editor.getDocument();
final VirtualFile file = myFileDocumentManager.getFile(document);
final Language language = findXmlLikeLanguage(project, file);
if (language != null)
new TagNameSynchronizer(editor, project, language);
}
use of com.intellij.lang.Language in project intellij-community by JetBrains.
the class HtmlSelectioner method select.
@Override
public List<TextRange> select(PsiElement e, @NotNull CharSequence editorText, int cursorOffset, @NotNull Editor editor) {
List<TextRange> result;
if (!(e instanceof XmlToken) || XmlTokenSelectioner.shouldSelectToken((XmlToken) e) || ((XmlToken) e).getTokenType() == XmlTokenType.XML_DATA_CHARACTERS) {
result = super.select(e, editorText, cursorOffset, editor);
} else {
result = ContainerUtil.newArrayList();
}
final PsiElement parent = e.getParent();
if (parent instanceof XmlComment) {
result.addAll(expandToWholeLine(editorText, parent.getTextRange(), true));
}
PsiFile psiFile = e.getContainingFile();
addAttributeSelection(result, editor, cursorOffset, editorText, e);
final FileViewProvider fileViewProvider = psiFile.getViewProvider();
for (Language lang : fileViewProvider.getLanguages()) {
final PsiFile langFile = fileViewProvider.getPsi(lang);
if (langFile != psiFile)
addAttributeSelection(result, editor, cursorOffset, editorText, fileViewProvider.findElementAt(cursorOffset, lang));
}
EditorHighlighter highlighter = HighlighterFactory.createHighlighter(e.getProject(), psiFile.getVirtualFile());
highlighter.setText(editorText);
addTagSelection2(e, result);
return result;
}
use of com.intellij.lang.Language in project intellij-community by JetBrains.
the class EduCustomCourseModuleBuilder method createModule.
@NotNull
@Override
public Module createModule(@NotNull ModifiableModuleModel moduleModel) throws InvalidDataException, IOException, ModuleWithNameAlreadyExists, JDOMException, ConfigurationException {
Module baseModule = super.createModule(moduleModel);
if (mySelectedCourse != null) {
String type = mySelectedCourse.getType();
String languageName = type.substring("pycharm ".length());
Language language = Language.findLanguageByID(languageName);
if (language != null) {
EduCourseConfigurator configurator = EduCourseConfigurator.INSTANCE.forLanguage(language);
if (configurator != null) {
configurator.createCourseFromCourseInfo(moduleModel, baseModule.getProject(), myGenerator, mySelectedCourse, getModuleFileDirectory());
}
}
}
return baseModule;
}
Aggregations