Search in sources :

Example 66 with Language

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

the class CommonCodeStyleSettingsManager method readExternal.

public void readExternal(@NotNull Element element) throws InvalidDataException {
    synchronized (this) {
        initCommonSettingsMap();
        for (Element commonSettingsElement : element.getChildren(COMMON_SETTINGS_TAG)) {
            final String languageId = commonSettingsElement.getAttributeValue(LANGUAGE_ATTR);
            if (!StringUtil.isEmpty(languageId)) {
                Language target = Language.findLanguageByID(languageId);
                boolean isKnownLanguage = target != null;
                if (isKnownLanguage) {
                    final LanguageCodeStyleSettingsProvider provider = LanguageCodeStyleSettingsProvider.forLanguage(target);
                    if (provider != null) {
                        CommonCodeStyleSettings settings = provider.getDefaultCommonSettings();
                        if (settings != null) {
                            settings.readExternal(commonSettingsElement);
                            init(settings, target);
                        }
                    } else {
                        isKnownLanguage = false;
                    }
                }
                if (!isKnownLanguage) {
                    myUnknownSettingsMap.put(languageId, commonSettingsElement.clone());
                }
            }
        }
        initNonReadSettings();
    }
}
Also used : Language(com.intellij.lang.Language) Element(org.jdom.Element)

Example 67 with Language

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

the class PsiUtilBase method getPsiFileInEditor.

@Nullable
public static PsiFile getPsiFileInEditor(@NotNull Caret caret, @NotNull final Project project) {
    Editor editor = caret.getEditor();
    final PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
    if (file == null)
        return null;
    PsiUtilCore.ensureValid(file);
    final Language language = getLanguageInEditor(caret, project);
    if (language == null)
        return file;
    if (language == file.getLanguage())
        return file;
    int caretOffset = caret.getOffset();
    int mostProbablyCorrectLanguageOffset = caretOffset == caret.getSelectionEnd() ? caret.getSelectionStart() : caretOffset;
    return getPsiFileAtOffset(file, mostProbablyCorrectLanguageOffset);
}
Also used : Language(com.intellij.lang.Language) TextEditor(com.intellij.openapi.fileEditor.TextEditor) Editor(com.intellij.openapi.editor.Editor) FileEditor(com.intellij.openapi.fileEditor.FileEditor) Nullable(org.jetbrains.annotations.Nullable)

Example 68 with Language

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

the class ChameleonSyntaxHighlightingPass method collectHighlights.

private void collectHighlights(@NotNull PsiElement element, @NotNull List<HighlightInfo> inside, @NotNull List<HighlightInfo> outside, @NotNull ProperTextRange priorityRange) {
    EditorColorsScheme scheme = ObjectUtils.notNull(getColorsScheme(), EditorColorsManager.getInstance().getGlobalScheme());
    TextAttributes defaultAttrs = scheme.getAttributes(HighlighterColors.TEXT);
    Language language = ILazyParseableElementType.LANGUAGE_KEY.get(element.getNode());
    if (language == null)
        return;
    SyntaxHighlighter syntaxHighlighter = SyntaxHighlighterFactory.getSyntaxHighlighter(language, myProject, myFile.getVirtualFile());
    for (PsiElement token : psiTraverser(element).traverse(TreeTraversal.LEAVES_DFS)) {
        TextRange tr = token.getTextRange();
        if (tr.isEmpty())
            continue;
        IElementType type = PsiUtilCore.getElementType(token);
        TextAttributesKey[] keys = syntaxHighlighter.getTokenHighlights(type);
        // force attribute colors to override host' ones
        TextAttributes attributes = null;
        for (TextAttributesKey key : keys) {
            TextAttributes attrs2 = scheme.getAttributes(key);
            if (attrs2 != null) {
                attributes = attributes == null ? attrs2 : TextAttributes.merge(attributes, attrs2);
            }
        }
        TextAttributes forcedAttributes;
        if (attributes == null || attributes.isEmpty() || attributes.equals(defaultAttrs)) {
            forcedAttributes = TextAttributes.ERASE_MARKER;
        } else {
            HighlightInfo info = HighlightInfo.newHighlightInfo(HighlightInfoType.INJECTED_LANGUAGE_FRAGMENT).range(tr).textAttributes(TextAttributes.ERASE_MARKER).createUnconditionally();
            (priorityRange.contains(tr) ? inside : outside).add(info);
            forcedAttributes = new TextAttributes(attributes.getForegroundColor(), attributes.getBackgroundColor(), attributes.getEffectColor(), attributes.getEffectType(), attributes.getFontType());
        }
        HighlightInfo info = HighlightInfo.newHighlightInfo(HighlightInfoType.INJECTED_LANGUAGE_FRAGMENT).range(tr).textAttributes(forcedAttributes).createUnconditionally();
        (priorityRange.contains(tr) ? inside : outside).add(info);
    }
}
Also used : IElementType(com.intellij.psi.tree.IElementType) Language(com.intellij.lang.Language) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme) ProperTextRange(com.intellij.openapi.util.ProperTextRange) TextRange(com.intellij.openapi.util.TextRange) SyntaxHighlighter(com.intellij.openapi.fileTypes.SyntaxHighlighter) TextAttributesKey(com.intellij.openapi.editor.colors.TextAttributesKey) PsiElement(com.intellij.psi.PsiElement)

Example 69 with Language

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

the class HectorComponent method isModified.

private boolean isModified() {
    final FileViewProvider viewProvider = myFile.getViewProvider();
    for (Language language : mySliders.keySet()) {
        JSlider slider = mySliders.get(language);
        final PsiFile root = viewProvider.getPsi(language);
        HighlightingLevelManager highlightingLevelManager = HighlightingLevelManager.getInstance(myFile.getProject());
        if (root != null && getValue(highlightingLevelManager.shouldHighlight(root), highlightingLevelManager.shouldInspect(root)) != slider.getValue()) {
            return true;
        }
    }
    for (HectorComponentPanel panel : myAdditionalPanels) {
        if (panel.isModified()) {
            return true;
        }
    }
    return false;
}
Also used : HighlightingLevelManager(com.intellij.codeInsight.daemon.impl.analysis.HighlightingLevelManager) FileViewProvider(com.intellij.psi.FileViewProvider) Language(com.intellij.lang.Language) HectorComponentPanel(com.intellij.openapi.editor.HectorComponentPanel) PsiFile(com.intellij.psi.PsiFile)

Example 70 with Language

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

the class HectorComponent method layoutVertical.

private void layoutVertical(final JPanel panel) {
    for (Language language : mySliders.keySet()) {
        JSlider slider = mySliders.get(language);
        JPanel borderPanel = new JPanel(new BorderLayout());
        slider.setPreferredSize(JBUI.size(100));
        borderPanel.add(new JLabel(language.getID()), BorderLayout.NORTH);
        borderPanel.add(slider, BorderLayout.CENTER);
        panel.add(borderPanel, new GridBagConstraints(GridBagConstraints.RELATIVE, 1, 1, 1, 0, 1, GridBagConstraints.CENTER, GridBagConstraints.VERTICAL, new Insets(0, 5, 0, 5), 0, 0));
    }
}
Also used : 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