Search in sources :

Example 1 with SyntaxTable

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

the class StandardFileTypeRegistrator method init.

private static void init(final AbstractFileType abstractFileType) {
    SyntaxTable table = abstractFileType.getSyntaxTable();
    if (!isEmpty(table.getStartComment()) && !isEmpty(table.getEndComment()) || !isEmpty(table.getLineComment())) {
        abstractFileType.setCommenter(new MyCommenter(abstractFileType));
    }
    if (table.isHasBraces() || table.isHasBrackets() || table.isHasParens()) {
        BraceMatchingUtil.registerBraceMatcher(abstractFileType, CustomFileTypeBraceMatcher.createBraceMatcher());
    }
    TypedHandler.registerQuoteHandler(abstractFileType, new CustomFileTypeQuoteHandler());
}
Also used : SyntaxTable(com.intellij.ide.highlighter.custom.SyntaxTable)

Example 2 with SyntaxTable

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

the class FileTypeConfigurable method addFileType.

private void addFileType() {
    //TODO: support adding binary file types...
    AbstractFileType type = new AbstractFileType(new SyntaxTable());
    TypeEditor<AbstractFileType> editor = new TypeEditor<>(myRecognizedFileType.myFileTypesList, type, FileTypesBundle.message("filetype.edit.new.title"));
    if (editor.showAndGet()) {
        myTempFileTypes.add(type);
        updateFileTypeList();
        updateExtensionList();
        myRecognizedFileType.selectFileType(type);
    }
}
Also used : SyntaxTable(com.intellij.ide.highlighter.custom.SyntaxTable)

Example 3 with SyntaxTable

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

the class CustomFileTypeEditor method getSyntaxTable.

public SyntaxTable getSyntaxTable() {
    SyntaxTable syntaxTable = new SyntaxTable();
    syntaxTable.setLineComment(myLineComment.getText());
    syntaxTable.setStartComment(myBlockCommentStart.getText());
    syntaxTable.setEndComment(myBlockCommentEnd.getText());
    syntaxTable.setHexPrefix(myHexPrefix.getText());
    syntaxTable.setNumPostfixChars(myNumPostfixes.getText());
    syntaxTable.lineCommentOnlyAtStart = myCommentAtLineStart.isSelected();
    boolean ignoreCase = myIgnoreCase.isSelected();
    syntaxTable.setIgnoreCase(ignoreCase);
    syntaxTable.setHasBraces(mySupportBraces.isSelected());
    syntaxTable.setHasBrackets(mySupportBrackets.isSelected());
    syntaxTable.setHasParens(mySupportParens.isSelected());
    syntaxTable.setHasStringEscapes(mySupportEscapes.isSelected());
    for (int i = 0; i < myKeywordModels[0].size(); i++) {
        if (ignoreCase) {
            syntaxTable.addKeyword1(((String) myKeywordModels[0].getElementAt(i)).toLowerCase());
        } else {
            syntaxTable.addKeyword1((String) myKeywordModels[0].getElementAt(i));
        }
    }
    for (int i = 0; i < myKeywordModels[1].size(); i++) {
        if (ignoreCase) {
            syntaxTable.addKeyword2(((String) myKeywordModels[1].getElementAt(i)).toLowerCase());
        } else {
            syntaxTable.addKeyword2((String) myKeywordModels[1].getElementAt(i));
        }
    }
    for (int i = 0; i < myKeywordModels[2].size(); i++) {
        if (ignoreCase) {
            syntaxTable.addKeyword3(((String) myKeywordModels[2].getElementAt(i)).toLowerCase());
        } else {
            syntaxTable.addKeyword3((String) myKeywordModels[2].getElementAt(i));
        }
    }
    for (int i = 0; i < myKeywordModels[3].size(); i++) {
        if (ignoreCase) {
            syntaxTable.addKeyword4(((String) myKeywordModels[3].getElementAt(i)).toLowerCase());
        } else {
            syntaxTable.addKeyword4((String) myKeywordModels[3].getElementAt(i));
        }
    }
    return syntaxTable;
}
Also used : SyntaxTable(com.intellij.ide.highlighter.custom.SyntaxTable)

Example 4 with SyntaxTable

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

the class CustomFileTypeEditor method resetEditorFrom.

@Override
public void resetEditorFrom(@NotNull AbstractFileType fileType) {
    myFileTypeName.setText(fileType.getName());
    myFileTypeDescr.setText(fileType.getDescription());
    SyntaxTable table = fileType.getSyntaxTable();
    if (table != null) {
        myLineComment.setText(table.getLineComment());
        myBlockCommentEnd.setText(table.getEndComment());
        myBlockCommentStart.setText(table.getStartComment());
        myHexPrefix.setText(table.getHexPrefix());
        myNumPostfixes.setText(table.getNumPostfixChars());
        myIgnoreCase.setSelected(table.isIgnoreCase());
        myCommentAtLineStart.setSelected(table.lineCommentOnlyAtStart);
        mySupportBraces.setSelected(table.isHasBraces());
        mySupportBrackets.setSelected(table.isHasBrackets());
        mySupportParens.setSelected(table.isHasParens());
        mySupportEscapes.setSelected(table.isHasStringEscapes());
        table.getKeywords1().stream().sorted().forEach(s -> myKeywordModels[0].addElement(s));
        table.getKeywords2().stream().sorted().forEach(s -> myKeywordModels[1].addElement(s));
        table.getKeywords3().stream().sorted().forEach(s -> myKeywordModels[2].addElement(s));
        table.getKeywords4().stream().sorted().forEach(s -> myKeywordModels[3].addElement(s));
    }
}
Also used : SyntaxTable(com.intellij.ide.highlighter.custom.SyntaxTable)

Example 5 with SyntaxTable

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

the class FileTypeManagerImpl method loadFileType.

@NotNull
private FileType loadFileType(@NotNull Element typeElement, boolean isDefault) {
    String fileTypeName = typeElement.getAttributeValue(ATTRIBUTE_NAME);
    String fileTypeDescr = typeElement.getAttributeValue(ATTRIBUTE_DESCRIPTION);
    String iconPath = typeElement.getAttributeValue("icon");
    String extensionsStr = StringUtil.nullize(typeElement.getAttributeValue("extensions"));
    if (isDefault && extensionsStr != null) {
        // todo support wildcards
        extensionsStr = filterAlreadyRegisteredExtensions(extensionsStr);
    }
    FileType type = isDefault ? getFileTypeByName(fileTypeName) : null;
    if (type != null) {
        return type;
    }
    Element element = typeElement.getChild(AbstractFileType.ELEMENT_HIGHLIGHTING);
    if (element == null) {
        for (CustomFileTypeFactory factory : CustomFileTypeFactory.EP_NAME.getExtensions()) {
            type = factory.createFileType(typeElement);
            if (type != null) {
                break;
            }
        }
        if (type == null) {
            type = new UserBinaryFileType();
        }
    } else {
        SyntaxTable table = AbstractFileType.readSyntaxTable(element);
        type = new AbstractFileType(table);
        ((AbstractFileType) type).initSupport();
    }
    setFileTypeAttributes((UserFileType) type, fileTypeName, fileTypeDescr, iconPath);
    registerFileTypeWithoutNotification(type, parse(extensionsStr), isDefault);
    if (isDefault) {
        myDefaultTypes.add(type);
        if (type instanceof ExternalizableFileType) {
            ((ExternalizableFileType) type).markDefaultSettings();
        }
    } else {
        Element extensions = typeElement.getChild(AbstractFileType.ELEMENT_EXTENSION_MAP);
        if (extensions != null) {
            for (Pair<FileNameMatcher, String> association : AbstractFileType.readAssociations(extensions)) {
                associate(type, association.getFirst(), false);
            }
            for (Trinity<FileNameMatcher, String, Boolean> removedAssociation : AbstractFileType.readRemovedAssociations(extensions)) {
                removeAssociation(type, removedAssociation.getFirst(), false);
            }
        }
    }
    return type;
}
Also used : SyntaxTable(com.intellij.ide.highlighter.custom.SyntaxTable) Element(org.jdom.Element) 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