Search in sources :

Example 6 with SyntaxTable

use of com.intellij.ide.highlighter.custom.SyntaxTable in project intellij-community by JetBrains.

the class CommentByLineCommentHandler method getBlockSuitableCommenter.

private static Commenter getBlockSuitableCommenter(final PsiFile file, int offset, int endOffset) {
    final Language languageSuitableForCompleteFragment;
    if (offset >= endOffset) {
        // we are on empty line
        PsiElement element = file.findElementAt(offset);
        if (element != null)
            languageSuitableForCompleteFragment = element.getParent().getLanguage();
        else
            languageSuitableForCompleteFragment = null;
    } else {
        languageSuitableForCompleteFragment = PsiUtilBase.reallyEvaluateLanguageInRange(offset, endOffset, file);
    }
    Commenter blockSuitableCommenter = languageSuitableForCompleteFragment == null ? LanguageCommenters.INSTANCE.forLanguage(file.getLanguage()) : null;
    if (blockSuitableCommenter == null && file.getFileType() instanceof CustomSyntaxTableFileType) {
        blockSuitableCommenter = new Commenter() {

            final SyntaxTable mySyntaxTable = ((CustomSyntaxTableFileType) file.getFileType()).getSyntaxTable();

            @Override
            @Nullable
            public String getLineCommentPrefix() {
                return mySyntaxTable.getLineComment();
            }

            @Override
            @Nullable
            public String getBlockCommentPrefix() {
                return mySyntaxTable.getStartComment();
            }

            @Override
            @Nullable
            public String getBlockCommentSuffix() {
                return mySyntaxTable.getEndComment();
            }

            @Override
            public String getCommentedBlockCommentPrefix() {
                return null;
            }

            @Override
            public String getCommentedBlockCommentSuffix() {
                return null;
            }
        };
    }
    return blockSuitableCommenter;
}
Also used : SyntaxTable(com.intellij.ide.highlighter.custom.SyntaxTable) Language(com.intellij.lang.Language) Commenter(com.intellij.lang.Commenter) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable) CustomSyntaxTableFileType(com.intellij.openapi.fileTypes.impl.CustomSyntaxTableFileType)

Example 7 with SyntaxTable

use of com.intellij.ide.highlighter.custom.SyntaxTable in project intellij-community by JetBrains.

the class FileTypesTest method testRemappingToInstalledPluginExtension.

// for IDEA-114804 File types mapped to text are not remapped when corresponding plugin is installed
public void testRemappingToInstalledPluginExtension() throws WriteExternalException, InvalidDataException {
    ApplicationManager.getApplication().runWriteAction(() -> myFileTypeManager.associatePattern(PlainTextFileType.INSTANCE, "*.fromPlugin"));
    Element element = myFileTypeManager.getState();
    //String s = JDOMUtil.writeElement(element);
    final AbstractFileType typeFromPlugin = new AbstractFileType(new SyntaxTable());
    PlatformTestUtil.registerExtension(FileTypeFactory.FILE_TYPE_FACTORY_EP, new FileTypeFactory() {

        @Override
        public void createFileTypes(@NotNull FileTypeConsumer consumer) {
            consumer.consume(typeFromPlugin, "fromPlugin");
        }
    }, getTestRootDisposable());
    myFileTypeManager.initStandardFileTypes();
    myFileTypeManager.loadState(element);
    myFileTypeManager.initComponent();
    Map<FileNameMatcher, Pair<FileType, Boolean>> mappings = myFileTypeManager.getRemovedMappings();
    assertEquals(1, mappings.size());
    assertEquals(typeFromPlugin, mappings.values().iterator().next().first);
}
Also used : SyntaxTable(com.intellij.ide.highlighter.custom.SyntaxTable) Element(org.jdom.Element) Pair(com.intellij.openapi.util.Pair)

Example 8 with SyntaxTable

use of com.intellij.ide.highlighter.custom.SyntaxTable in project intellij-community by JetBrains.

the class AbstractFileType method readSyntaxTable.

@NotNull
public static SyntaxTable readSyntaxTable(@NotNull Element root) {
    SyntaxTable table = new SyntaxTable();
    for (Element element : root.getChildren()) {
        if (ELEMENT_OPTIONS.equals(element.getName())) {
            for (final Object o1 : element.getChildren(ELEMENT_OPTION)) {
                Element e = (Element) o1;
                String name = e.getAttributeValue(ATTRIBUTE_NAME);
                String value = e.getAttributeValue(ATTRIBUTE_VALUE);
                if (VALUE_LINE_COMMENT.equals(name)) {
                    table.setLineComment(value);
                } else if (VALUE_COMMENT_START.equals(name)) {
                    table.setStartComment(value);
                } else if (VALUE_COMMENT_END.equals(name)) {
                    table.setEndComment(value);
                } else if (VALUE_HEX_PREFIX.equals(name)) {
                    table.setHexPrefix(value);
                } else if (VALUE_NUM_POSTFIXES.equals(name)) {
                    table.setNumPostfixChars(value);
                } else if (VALUE_LINE_COMMENT_AT_START.equals(name)) {
                    table.lineCommentOnlyAtStart = Boolean.valueOf(value).booleanValue();
                } else if (VALUE_HAS_BRACES.equals(name)) {
                    table.setHasBraces(Boolean.valueOf(value).booleanValue());
                } else if (VALUE_HAS_BRACKETS.equals(name)) {
                    table.setHasBrackets(Boolean.valueOf(value).booleanValue());
                } else if (VALUE_HAS_PARENS.equals(name)) {
                    table.setHasParens(Boolean.valueOf(value).booleanValue());
                } else if (VALUE_HAS_STRING_ESCAPES.equals(name)) {
                    table.setHasStringEscapes(Boolean.valueOf(value).booleanValue());
                }
            }
        } else if (ELEMENT_KEYWORDS.equals(element.getName())) {
            boolean ignoreCase = Boolean.valueOf(element.getAttributeValue(ATTRIBUTE_IGNORE_CASE)).booleanValue();
            table.setIgnoreCase(ignoreCase);
            loadKeywords(element, table.getKeywords1());
        } else if (ELEMENT_KEYWORDS2.equals(element.getName())) {
            loadKeywords(element, table.getKeywords2());
        } else if (ELEMENT_KEYWORDS3.equals(element.getName())) {
            loadKeywords(element, table.getKeywords3());
        } else if (ELEMENT_KEYWORDS4.equals(element.getName())) {
            loadKeywords(element, table.getKeywords4());
        }
    }
    boolean DUMP_TABLE = false;
    if (DUMP_TABLE) {
        Element element = new Element("temp");
        writeTable(element, table);
        XMLOutputter outputter = JDOMUtil.createOutputter("\n");
        try {
            outputter.output((Element) element.getContent().get(0), System.out);
        } catch (IOException ignored) {
        }
    }
    return table;
}
Also used : SyntaxTable(com.intellij.ide.highlighter.custom.SyntaxTable) XMLOutputter(org.jdom.output.XMLOutputter) Element(org.jdom.Element) IOException(java.io.IOException) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

SyntaxTable (com.intellij.ide.highlighter.custom.SyntaxTable)8 Element (org.jdom.Element)3 NotNull (org.jetbrains.annotations.NotNull)2 Commenter (com.intellij.lang.Commenter)1 Language (com.intellij.lang.Language)1 CustomSyntaxTableFileType (com.intellij.openapi.fileTypes.impl.CustomSyntaxTableFileType)1 Pair (com.intellij.openapi.util.Pair)1 PsiElement (com.intellij.psi.PsiElement)1 IOException (java.io.IOException)1 XMLOutputter (org.jdom.output.XMLOutputter)1 Nullable (org.jetbrains.annotations.Nullable)1