Search in sources :

Example 21 with Language

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();
}
Also used : Language(com.intellij.lang.Language) XMLLanguage(com.intellij.lang.xml.XMLLanguage) XMLLanguage(com.intellij.lang.xml.XMLLanguage) PsiElement(com.intellij.psi.PsiElement) PsiWhiteSpace(com.intellij.psi.PsiWhiteSpace)

Example 22 with Language

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;
    });
}
Also used : TemplateLanguageFileViewProvider(com.intellij.psi.templateLanguages.TemplateLanguageFileViewProvider) FileViewProvider(com.intellij.psi.FileViewProvider) Language(com.intellij.lang.Language) XMLLanguage(com.intellij.lang.xml.XMLLanguage) PsiFile(com.intellij.psi.PsiFile) TemplateLanguageFileViewProvider(com.intellij.psi.templateLanguages.TemplateLanguageFileViewProvider) PsiElement(com.intellij.psi.PsiElement)

Example 23 with Language

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);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) Language(com.intellij.lang.Language) XMLLanguage(com.intellij.lang.xml.XMLLanguage) XHTMLLanguage(com.intellij.lang.xhtml.XHTMLLanguage) HTMLLanguage(com.intellij.lang.html.HTMLLanguage) TemplateLanguage(com.intellij.psi.templateLanguages.TemplateLanguage)

Example 24 with 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;
}
Also used : FileViewProvider(com.intellij.psi.FileViewProvider) Language(com.intellij.lang.Language) TextRange(com.intellij.openapi.util.TextRange) UnfairTextRange(com.intellij.openapi.util.UnfairTextRange) PsiFile(com.intellij.psi.PsiFile) PsiElement(com.intellij.psi.PsiElement) EditorHighlighter(com.intellij.openapi.editor.highlighter.EditorHighlighter)

Example 25 with Language

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;
}
Also used : Language(com.intellij.lang.Language) EduCourseConfigurator(com.jetbrains.edu.learning.intellij.EduCourseConfigurator) Module(com.intellij.openapi.module.Module) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

Language (com.intellij.lang.Language)292 NotNull (org.jetbrains.annotations.NotNull)58 Nullable (org.jetbrains.annotations.Nullable)49 PsiElement (com.intellij.psi.PsiElement)46 PsiFile (com.intellij.psi.PsiFile)45 FileType (com.intellij.openapi.fileTypes.FileType)31 Project (com.intellij.openapi.project.Project)31 TextRange (com.intellij.openapi.util.TextRange)25 LanguageFileType (com.intellij.openapi.fileTypes.LanguageFileType)23 VirtualFile (com.intellij.openapi.vfs.VirtualFile)21 FileViewProvider (com.intellij.psi.FileViewProvider)21 HbLanguage (com.dmarcotte.handlebars.HbLanguage)20 JavaLanguage (com.intellij.lang.java.JavaLanguage)16 Editor (com.intellij.openapi.editor.Editor)14 XMLLanguage (com.intellij.lang.xml.XMLLanguage)12 TemplateLanguageFileViewProvider (com.intellij.psi.templateLanguages.TemplateLanguageFileViewProvider)11 List (java.util.List)11 HTMLLanguage (com.intellij.lang.html.HTMLLanguage)9 JavascriptLanguage (com.intellij.lang.javascript.JavascriptLanguage)9 Document (com.intellij.openapi.editor.Document)9