|
| 1 | +/* |
| 2 | + * This file is a part of IntelliJ Language 1C (BSL) Plugin. |
| 3 | + * |
| 4 | + * Copyright © 2018 |
| 5 | + * Alexey Sosnoviy <labotamy@yandex.ru>, Nikita Gryzlov <nixel2007@gmail.com> |
| 6 | + * |
| 7 | + * SPDX-License-Identifier: LGPL-3.0-or-later |
| 8 | + * |
| 9 | + * IntelliJ Language 1C (BSL) Plugin is free software; you can redistribute it and/or |
| 10 | + * modify it under the terms of the GNU Lesser General Public |
| 11 | + * License as published by the Free Software Foundation; either |
| 12 | + * version 3.0 of the License, or (at your option) any later version. |
| 13 | + * |
| 14 | + * IntelliJ Language 1C (BSL) Plugin is distributed in the hope that it will be useful, |
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 17 | + * Lesser General Public License for more details. |
| 18 | + * |
| 19 | + * You should have received a copy of the GNU Lesser General Public |
| 20 | + * License along with IntelliJ Language 1C (BSL) Plugin. |
| 21 | + */ |
| 22 | +package org.github._1c_syntax.intellij.bsl; |
| 23 | + |
| 24 | +import com.intellij.lang.BracePair; |
| 25 | +import com.intellij.lang.PairedBraceMatcher; |
| 26 | +import com.intellij.psi.PsiFile; |
| 27 | +import com.intellij.psi.tree.IElementType; |
| 28 | +import org.antlr.jetbrains.adapter.lexer.PsiElementTypeFactory; |
| 29 | +import org.antlr.jetbrains.adapter.lexer.TokenIElementType; |
| 30 | +import org.github._1c_syntax.parser.BSLLexer; |
| 31 | +import org.jetbrains.annotations.NotNull; |
| 32 | +import org.jetbrains.annotations.Nullable; |
| 33 | + |
| 34 | +import java.util.List; |
| 35 | + |
| 36 | +public class BSLPairedBraceMatcher implements PairedBraceMatcher { |
| 37 | + |
| 38 | + @NotNull |
| 39 | + @Override |
| 40 | + public BracePair[] getPairs() { |
| 41 | + PsiElementTypeFactory psiElementTypeFactory = BSLSyntaxHighlighter.getPsiElementTypeFactory(); |
| 42 | + List<TokenIElementType> tokenIElementTypes = psiElementTypeFactory.getTokenIElementTypes(); |
| 43 | + |
| 44 | + TokenIElementType lParen = tokenIElementTypes.get(BSLLexer.LPAREN); |
| 45 | + TokenIElementType rParen = tokenIElementTypes.get(BSLLexer.RPAREN); |
| 46 | + |
| 47 | + TokenIElementType lBracket = tokenIElementTypes.get(BSLLexer.LBRACK); |
| 48 | + TokenIElementType rBracket = tokenIElementTypes.get(BSLLexer.RBRACK); |
| 49 | + |
| 50 | + return new BracePair[]{ |
| 51 | + new BracePair(lParen, rParen, true), |
| 52 | + new BracePair(lBracket, rBracket, false), |
| 53 | + }; |
| 54 | + } |
| 55 | + |
| 56 | + @Override |
| 57 | + public boolean isPairedBracesAllowedBeforeType(@NotNull IElementType lbraceType, @Nullable IElementType contextType) { |
| 58 | + return false; |
| 59 | + } |
| 60 | + |
| 61 | + @Override |
| 62 | + public int getCodeConstructStart(PsiFile file, int openingBraceOffset) { |
| 63 | + return 0; |
| 64 | + } |
| 65 | +} |
0 commit comments