Search in sources :

Example 61 with Language

use of com.intellij.lang.Language in project intellij-plugins by JetBrains.

the class CfmlCommenter method getCfmlElementAtOffset.

private static PsiElement getCfmlElementAtOffset(int offset, PsiFile file) {
    final FileViewProvider fileViewProvider = file.getViewProvider();
    file = fileViewProvider.getPsi(fileViewProvider.getBaseLanguage());
    final Language cfmlLanguage = file.getLanguage();
    return fileViewProvider.findElementAt(offset, cfmlLanguage);
}
Also used : FileViewProvider(com.intellij.psi.FileViewProvider) Language(com.intellij.lang.Language)

Example 62 with Language

use of com.intellij.lang.Language in project intellij-plugins by JetBrains.

the class AngularJSErrorFilter method shouldHighlightErrorElement.

@Override
public boolean shouldHighlightErrorElement(@NotNull PsiErrorElement error) {
    final Project project = error.getProject();
    final Language language = error.getLanguage();
    if ("CSS".equals(language.getID()) && PsiTreeUtil.getParentOfType(error, XmlAttribute.class) != null && AngularIndexUtil.hasAngularJS(project)) {
        final PsiFile file = error.getContainingFile();
        PsiErrorElement nextError = error;
        while (nextError != null) {
            if (hasAngularInjectionAt(project, file, nextError.getTextOffset()))
                return false;
            nextError = PsiTreeUtil.getNextSiblingOfType(nextError, PsiErrorElement.class);
        }
    }
    if (HTMLLanguage.INSTANCE.is(language) && error.getErrorDescription().endsWith("not closed")) {
        final PsiElement parent = error.getParent();
        final XmlElementDescriptor descriptor = parent instanceof XmlTag ? ((XmlTag) parent).getDescriptor() : null;
        return !(descriptor instanceof AngularJSTagDescriptor);
    }
    if (XMLLanguage.INSTANCE.is(language) && error.getErrorDescription().equals(XmlErrorMessages.message("xml.parsing.unexpected.tokens"))) {
        return !error.getParent().getLanguage().is(Angular2HTMLLanguage.INSTANCE);
    }
    return true;
}
Also used : Project(com.intellij.openapi.project.Project) PsiErrorElement(com.intellij.psi.PsiErrorElement) XmlAttribute(com.intellij.psi.xml.XmlAttribute) Language(com.intellij.lang.Language) Angular2HTMLLanguage(org.angularjs.html.Angular2HTMLLanguage) XMLLanguage(com.intellij.lang.xml.XMLLanguage) HTMLLanguage(com.intellij.lang.html.HTMLLanguage) PsiFile(com.intellij.psi.PsiFile) AngularJSTagDescriptor(org.angularjs.codeInsight.tags.AngularJSTagDescriptor) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor) PsiElement(com.intellij.psi.PsiElement) XmlTag(com.intellij.psi.xml.XmlTag)

Example 63 with Language

use of com.intellij.lang.Language in project intellij-plugins by JetBrains.

the class AngularJSBracesUtil method hasConflicts.

public static boolean hasConflicts(String start, String end, PsiElement element) {
    final Language elementLanguage = element.getLanguage();
    // JSP contains two roots that contain XmlText, don't inject anything in JSP root to prevent double injections
    if ("JSP".equals(elementLanguage.getDisplayName())) {
        return true;
    }
    PsiFile file = element.getContainingFile();
    if (DEFAULT_START.equals(start) || DEFAULT_END.equals(end)) {
        // JSX attributes don't contain AngularJS injections, {{}} is JSX injection with object inside
        if (elementLanguage.isKindOf(JavascriptLanguage.INSTANCE))
            return true;
        for (Language language : file.getViewProvider().getLanguages()) {
            if (DEFAULT_CONFLICTS.contains(language.getDisplayName())) {
                return true;
            }
        }
    }
    return false;
}
Also used : Language(com.intellij.lang.Language) JavascriptLanguage(com.intellij.lang.javascript.JavascriptLanguage) PsiFile(com.intellij.psi.PsiFile)

Example 64 with Language

use of com.intellij.lang.Language in project intellij-community by JetBrains.

the class TailType method getLocalCodeStyleSettings.

protected static CommonCodeStyleSettings getLocalCodeStyleSettings(Editor editor, int tailOffset) {
    final PsiFile psiFile = getFile(editor);
    Language language = PsiUtilCore.getLanguageAtOffset(psiFile, tailOffset);
    final Project project = editor.getProject();
    assert project != null;
    return CodeStyleSettingsManager.getSettings(project).getCommonSettings(language);
}
Also used : Project(com.intellij.openapi.project.Project) Language(com.intellij.lang.Language) PsiFile(com.intellij.psi.PsiFile)

Example 65 with Language

use of com.intellij.lang.Language in project intellij-community by JetBrains.

the class TabbedLanguageCodeStylePanel method applyLanguageSettings.

private void applyLanguageSettings(Language lang) {
    final Project currProject = ProjectUtil.guessCurrentProject(getPanel());
    CodeStyleSettings rootSettings = CodeStyleSettingsManager.getSettings(currProject);
    CommonCodeStyleSettings sourceSettings = rootSettings.getCommonSettings(lang);
    CommonCodeStyleSettings targetSettings = getSettings().getCommonSettings(getDefaultLanguage());
    if (sourceSettings == null || targetSettings == null)
        return;
    if (!(targetSettings instanceof CodeStyleSettings)) {
        CommonCodeStyleSettingsManager.copy(sourceSettings, targetSettings);
    } else {
        Language targetLang = getDefaultLanguage();
        LOG.error((targetLang != null ? targetLang.getDisplayName() : "Unknown") + " language plug-in either uses an outdated API or does not initialize" + " its own code style settings in LanguageCodeStyleSettingsProvider.getDefaultSettings()." + " The operation can not be applied in this case.");
    }
    reset(getSettings());
    onSomethingChanged();
}
Also used : Project(com.intellij.openapi.project.Project) Language(com.intellij.lang.Language)

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