mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
insert paired brace before the closing brace or punctuation in the custom file type
This commit is contained in:
@@ -45,6 +45,7 @@ public interface CustomHighlighterTokenType {
|
||||
IElementType MULTI_LINE_COMMENT = new CustomElementType("MULTI_LINE_COMMENT");
|
||||
IElementType WHITESPACE = new CustomElementType("WHITESPACE");
|
||||
IElementType CHARACTER = new CustomElementType("CHARACTER");
|
||||
IElementType PUNCTUATION = new CustomElementType("PUNCTUATION");
|
||||
|
||||
IElementType L_BRACE = new CustomElementType("L_BRACE");
|
||||
IElementType R_BRACE = new CustomElementType("R_BRACE");
|
||||
|
||||
@@ -65,6 +65,7 @@ public final class CustomFileTypeLexer extends AbstractCustomLexer {
|
||||
tokenParsers.add(multilineCommentParser);
|
||||
}
|
||||
tokenParsers.add(numberParser);
|
||||
tokenParsers.add(new PunctuationParser());
|
||||
if (hexNumberParser != null) {
|
||||
tokenParsers.add(hexNumberParser);
|
||||
}
|
||||
|
||||
+6
-2
@@ -42,8 +42,10 @@ class CustomFileTypeBraceMatcher implements BraceMatcher {
|
||||
}
|
||||
|
||||
public boolean isRBraceToken(HighlighterIterator iterator, CharSequence fileText, FileType fileType) {
|
||||
final IElementType tokenType = iterator.getTokenType();
|
||||
return isRBraceToken(iterator.getTokenType());
|
||||
}
|
||||
|
||||
private static boolean isRBraceToken(IElementType tokenType) {
|
||||
return tokenType == CustomHighlighterTokenType.R_BRACKET ||
|
||||
tokenType == CustomHighlighterTokenType.R_PARENTH ||
|
||||
tokenType == CustomHighlighterTokenType.R_BRACE;
|
||||
@@ -80,7 +82,9 @@ class CustomFileTypeBraceMatcher implements BraceMatcher {
|
||||
}
|
||||
|
||||
public boolean isPairedBracesAllowedBeforeType(@NotNull final IElementType lbraceType, @Nullable final IElementType contextType) {
|
||||
return contextType == CustomHighlighterTokenType.WHITESPACE;
|
||||
return contextType == CustomHighlighterTokenType.PUNCTUATION ||
|
||||
contextType == CustomHighlighterTokenType.WHITESPACE ||
|
||||
isRBraceToken(contextType);
|
||||
}
|
||||
|
||||
public int getCodeConstructStart(final PsiFile file, final int openingBraceOffset) {
|
||||
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.intellij.ide.highlighter.custom.tokens;
|
||||
|
||||
import com.intellij.psi.CustomHighlighterTokenType;
|
||||
|
||||
/**
|
||||
* @author peter
|
||||
*/
|
||||
public class PunctuationParser extends BaseTokenParser {
|
||||
@Override
|
||||
public boolean hasToken(int position) {
|
||||
final char c = myBuffer.charAt(position);
|
||||
if (".,:;".indexOf(c) >= 0) {
|
||||
myTokenInfo.updateData(position, position+1, CustomHighlighterTokenType.PUNCTUATION);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSmartUpdateShift() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user