diff --git a/src/main/java/io/protostuff/jetbrains/plugin/ProtoBraceMatcher.java b/src/main/java/io/protostuff/jetbrains/plugin/ProtoBraceMatcher.java new file mode 100644 index 0000000..3393610 --- /dev/null +++ b/src/main/java/io/protostuff/jetbrains/plugin/ProtoBraceMatcher.java @@ -0,0 +1,39 @@ +package io.protostuff.jetbrains.plugin; + +import com.intellij.lang.BracePair; +import com.intellij.lang.PairedBraceMatcher; +import com.intellij.psi.PsiFile; +import com.intellij.psi.tree.IElementType; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import static io.protostuff.jetbrains.plugin.ProtoParserDefinition.*; + +/** + * @author Kostiantyn Shchepanovskyi + */ +public class ProtoBraceMatcher implements PairedBraceMatcher { + + private static final BracePair[] PAIRS = { + new BracePair(LCURLY, RCURLY, true), + new BracePair(LPAREN, RPAREN, false), + new BracePair(LSQUARE, RSQUARE, false), + new BracePair(LT, GT, false) + }; + + + @Override + public BracePair[] getPairs() { + return PAIRS; + } + + @Override + public boolean isPairedBracesAllowedBeforeType(@NotNull IElementType iElementType, @Nullable IElementType iElementType1) { + return true; + } + + @Override + public int getCodeConstructStart(PsiFile psiFile, int i) { + return i; + } +} diff --git a/src/main/java/io/protostuff/jetbrains/plugin/ProtoParserDefinition.java b/src/main/java/io/protostuff/jetbrains/plugin/ProtoParserDefinition.java index a31365d..6f77ca9 100644 --- a/src/main/java/io/protostuff/jetbrains/plugin/ProtoParserDefinition.java +++ b/src/main/java/io/protostuff/jetbrains/plugin/ProtoParserDefinition.java @@ -35,6 +35,18 @@ public class ProtoParserDefinition implements ParserDefinition { public static final TokenIElementType ID; public static final TokenSet KEYWORDS; + + // tokens + + public static final TokenIElementType LCURLY; + public static final TokenIElementType RCURLY; + public static final TokenIElementType LPAREN; + public static final TokenIElementType RPAREN; + public static final TokenIElementType LSQUARE; + public static final TokenIElementType RSQUARE; + public static final TokenIElementType LT; + public static final TokenIElementType GT; + // Rules public static final IElementType R_TYPE_REFERENCE; public static final IElementType R_NAME; @@ -44,12 +56,14 @@ public class ProtoParserDefinition implements ParserDefinition { private static final TokenSet WHITESPACE; private static final TokenSet STRING; + + static { PSIElementTypeFactory.defineLanguageIElementTypes(ProtoLanguage.INSTANCE, ProtoParser.tokenNames, ProtoParser.ruleNames); - List tokenIElementTypes = + List tokenTypes = PSIElementTypeFactory.getTokenIElementTypes(ProtoLanguage.INSTANCE); - ID = tokenIElementTypes.get(ProtoLexer.NAME); + ID = tokenTypes.get(ProtoLexer.NAME); FILE = new IFileElementType(ProtoLanguage.INSTANCE); COMMENTS = PSIElementTypeFactory.createTokenSet(ProtoLanguage.INSTANCE, COMMENT, LINE_COMMENT); WHITESPACE = PSIElementTypeFactory.createTokenSet(ProtoLanguage.INSTANCE, WS); @@ -102,6 +116,15 @@ public class ProtoParserDefinition implements ParserDefinition { R_TYPE_REFERENCE = ruleTypes.get(ProtoParser.RULE_typeReference); R_NAME = ruleTypes.get(ProtoParser.RULE_name); R_FIELD_MODIFIER = ruleTypes.get(ProtoParser.RULE_fieldModifier); + + LCURLY = tokenTypes.get(ProtoLexer.LCURLY); + RCURLY = tokenTypes.get(ProtoLexer.RCURLY); + LPAREN = tokenTypes.get(ProtoLexer.LPAREN); + RPAREN = tokenTypes.get(ProtoLexer.RPAREN); + LSQUARE = tokenTypes.get(ProtoLexer.LSQUARE); + RSQUARE = tokenTypes.get(ProtoLexer.RSQUARE); + LT = tokenTypes.get(ProtoLexer.LT); + GT = tokenTypes.get(ProtoLexer.GT); } @NotNull diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index 396b2c9..e15d968 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -78,6 +78,7 @@ +