KDoc wiki links pair matcher and @tags highlighter

This commit is contained in:
Sergey Rostov
2013-05-25 19:05:01 +04:00
committed by Mikhael Bogdanov
parent 12e20378a2
commit bcc2c46e99
13 changed files with 267 additions and 63 deletions
@@ -110,6 +110,8 @@ options.jet.attribute.descriptor.closure.braces=Function literal braces and arro
options.jet.attribute.descriptor.safe.access=Safe access dot
options.jet.attribute.descriptor.arrow=Arrow
options.jet.attribute.descriptor.kdoc.comment=KDoc comment
options.jet.attribute.descriptor.kdoc.tag=KDoc tag
options.jet.attribute.descriptor.kdoc.value=KDoc tag value
options.jet.attribute.descriptor.trait=Trait
options.jet.attribute.descriptor.annotation=Annotation
options.jet.attribute.descriptor.var=Var (mutable variable, parameter or property)
@@ -22,6 +22,7 @@ import com.intellij.psi.PsiFile;
import com.intellij.psi.tree.IElementType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.kdoc.lexer.KDocTokens;
import org.jetbrains.jet.lexer.JetTokens;
public class JetPairMatcher implements PairedBraceMatcher {
@@ -29,7 +30,8 @@ public class JetPairMatcher implements PairedBraceMatcher {
new BracePair(JetTokens.LPAR, JetTokens.RPAR, false),
new BracePair(JetTokens.LONG_TEMPLATE_ENTRY_START, JetTokens.LONG_TEMPLATE_ENTRY_END, false),
new BracePair(JetTokens.LBRACE, JetTokens.RBRACE, true),
new BracePair(JetTokens.LBRACKET, JetTokens.RBRACKET, false)
new BracePair(JetTokens.LBRACKET, JetTokens.RBRACKET, false),
new BracePair(KDocTokens.WIKI_LINK_OPEN, KDocTokens.WIKI_LINK_CLOSE, false)
};
@Override
@@ -44,6 +46,8 @@ public class JetPairMatcher implements PairedBraceMatcher {
return false;
}
if (lbraceType == KDocTokens.WIKI_LINK_OPEN) return false;
return JetTokens.WHITE_SPACE_OR_COMMENT_BIT_SET.contains(contextType)
|| contextType == JetTokens.SEMICOLON
|| contextType == JetTokens.COMMA
@@ -54,7 +54,7 @@ public class JetColorSettingsPage implements ColorSettingsPage {
"\n" +
"/**\n" +
" * Doc comment here for `SomeClass`\n" +
" * @see Iterator#next()\n" +
" * <KDOC_TAG>@see</KDOC_TAG> Iterator#next()\n" +
" */\n" +
"[<ANNOTATION>Deprecated</ANNOTATION>]\n" +
"<BUILTIN_ANNOTATION>public</BUILTIN_ANNOTATION> class <CLASS>MyClass</CLASS><<BUILTIN_ANNOTATION>out</BUILTIN_ANNOTATION> <TYPE_PARAMETER>T</TYPE_PARAMETER> : <TRAIT>Iterable</TRAIT><<TYPE_PARAMETER>T</TYPE_PARAMETER>>>(var <INSTANCE_PROPERTY><MUTABLE_VARIABLE>prop1</MUTABLE_VARIABLE></INSTANCE_PROPERTY> : Int) {\n" +
@@ -126,6 +126,8 @@ public class JetColorSettingsPage implements ColorSettingsPage {
new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.block.comment"), JetHighlightingColors.BLOCK_COMMENT),
new AttributesDescriptor(JetBundle.message("options.jet.attribute.descriptor.kdoc.comment"), JetHighlightingColors.DOC_COMMENT),
new AttributesDescriptor(JetBundle.message("options.jet.attribute.descriptor.kdoc.tag"), JetHighlightingColors.KDOC_TAG),
new AttributesDescriptor(JetBundle.message("options.jet.attribute.descriptor.kdoc.value"), JetHighlightingColors.KDOC_TAG_VALUE),
new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.class"), JetHighlightingColors.CLASS),
new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.type.parameter"), JetHighlightingColors.TYPE_PARAMETER),
@@ -23,7 +23,7 @@ import com.intellij.psi.TokenType;
import com.intellij.psi.tree.IElementType;
import com.intellij.psi.tree.TokenSet;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lexer.JetLexer;
import org.jetbrains.jet.kdoc.lexer.KDocTokens;
import org.jetbrains.jet.lexer.JetTokens;
import java.util.HashMap;
@@ -34,7 +34,7 @@ public class JetHighlighter extends SyntaxHighlighterBase {
@NotNull
public Lexer getHighlightingLexer() {
return new JetLexer();
return new JetHighlightingLexer();
}
@NotNull
@@ -83,6 +83,9 @@ public class JetHighlighter extends SyntaxHighlighterBase {
keys.put(JetTokens.BLOCK_COMMENT, JetHighlightingColors.BLOCK_COMMENT);
keys.put(JetTokens.DOC_COMMENT, JetHighlightingColors.DOC_COMMENT);
fillMap(keys, KDocTokens.CONTENT_TOKENS, JetHighlightingColors.DOC_COMMENT);
keys.put(KDocTokens.TAG_NAME, JetHighlightingColors.KDOC_TAG);
keys.put(TokenType.BAD_CHARACTER, JetHighlightingColors.BAD_CHARACTER);
}
}
@@ -44,6 +44,8 @@ public class JetHighlightingColors {
public static final TextAttributesKey LINE_COMMENT = createTextAttributesKey("KOTLIN_LINE_COMMENT", DefaultLanguageHighlighterColors.LINE_COMMENT);
public static final TextAttributesKey BLOCK_COMMENT = createTextAttributesKey("KOTLIN_BLOCK_COMMENT", DefaultLanguageHighlighterColors.BLOCK_COMMENT);
public static final TextAttributesKey DOC_COMMENT = createTextAttributesKey("KOTLIN_DOC_COMMENT", DefaultLanguageHighlighterColors.DOC_COMMENT);
public static final TextAttributesKey KDOC_TAG = createTextAttributesKey("KDOC_TAG_NAME", DefaultLanguageHighlighterColors.DOC_COMMENT_TAG);
public static final TextAttributesKey KDOC_TAG_VALUE = createTextAttributesKey("KDOC_TAG_VALUE", DefaultLanguageHighlighterColors.DOC_COMMENT_TAG_VALUE);
// class kinds
public static final TextAttributesKey CLASS = createTextAttributesKey("KOTLIN_CLASS", CodeInsightColors.CLASS_NAME_ATTRIBUTES);
@@ -0,0 +1,15 @@
package org.jetbrains.jet.plugin.highlighter;
import com.intellij.lexer.LayeredLexer;
import com.intellij.psi.tree.IElementType;
import org.jetbrains.jet.kdoc.lexer.KDocLexer;
import org.jetbrains.jet.lexer.JetLexer;
import org.jetbrains.jet.lexer.JetTokens;
public class JetHighlightingLexer extends LayeredLexer {
public JetHighlightingLexer() {
super(new JetLexer());
registerSelfStoppingLayer(new KDocLexer(), new IElementType[]{JetTokens.DOC_COMMENT}, IElementType.EMPTY_ARRAY);
}
}