/** * Check that the attributes missing in a custom scheme with a version prior to 142 are explicitly added with fallback enabled, * not taken from parent scheme. * * @throws Exception */ public void testUpgradeFromVer141() throws Exception { TextAttributesKey constKey = DefaultLanguageHighlighterColors.CONSTANT; TextAttributesKey fallbackKey = constKey.getFallbackAttributeKey(); assertNotNull(fallbackKey); EditorColorsScheme scheme = loadScheme( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<scheme name=\"Test\" version=\"141\" parent_scheme=\"Default\">\n" + // Some 'attributes' section is required for the upgrade procedure to work. "<attributes>" + " <option name=\"TEXT\">\n" + " <value>\n" + " option name=\"FOREGROUND\" value=\"ffaaaa\" />\n" + " </value>\n" + " </option>" + "</attributes>" + "</scheme>\n" ); TextAttributes constAttrs = scheme.getAttributes(constKey); TextAttributes fallbackAttrs = scheme.getAttributes(fallbackKey); assertSame(fallbackAttrs, constAttrs); }
/** * * @param psiElement * @param annotationHolder */ void annotateVarExpansion(PsiElement psiElement, AnnotationHolder annotationHolder) { // Annotate variable expansion if(psiElement instanceof CMakeArgument) { String argtext = psiElement.getText(); int pos = psiElement.getTextRange().getStartOffset(); while(argtext.matches(".*\\$\\{.*\\}.*")) { int vstart = argtext.indexOf("${"); int vend = argtext.indexOf("}"); TextRange range = new TextRange(pos+vstart, pos+vend+1); Annotation annotation = annotationHolder.createInfoAnnotation(range, null); annotation.setTextAttributes(DefaultLanguageHighlighterColors.CONSTANT); argtext = argtext.substring(vend+1); pos+=vend+1; } } }
@Override public void visitPropertyType(ShaderPropertyTypeElement type) { super.visitPropertyType(type); PsiElement element = type.getTargetElement(); ShaderLabPropertyType shaderLabPropertyType = ShaderLabPropertyType.find(element.getText()); if(shaderLabPropertyType == null) { myHolder.add(HighlightInfo.newHighlightInfo(HighlightInfoType.WRONG_REF).range(element).descriptionAndTooltip("Wrong type").create()); } else { myHolder.add(HighlightInfo.newHighlightInfo(HighlightInfoType.INFORMATION).range(element).textAttributes(DefaultLanguageHighlighterColors.TYPE_ALIAS_NAME).create()); } }
@Override public void visitElement(PsiElement element) { super.visitElement(element); ASTNode node = element.getNode(); if(node != null) { if(node.getElementType() == ShaderLabKeyTokens.VALUE_KEYWORD) { myHolder.add(HighlightInfo.newHighlightInfo(HighlightInfoType.INFORMATION).range(node).textAttributes(DefaultLanguageHighlighterColors.MACRO_KEYWORD).create()); } else if(node.getElementType() == ShaderLabKeyTokens.START_KEYWORD) { myHolder.add(HighlightInfo.newHighlightInfo(HighlightInfoType.INFORMATION).range(node).textAttributes(DefaultLanguageHighlighterColors.KEYWORD).create()); } } }
@Override public void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder holder) { if (element instanceof RobotKeyword) { RobotKeyword robotKeyword = (RobotKeyword) element; RobotKeywordReference ref = new RobotKeywordReference(robotKeyword); ResolveResult[] resolveResults = ref.multiResolve(false); if (resolveResults.length <= 0) { String normalKeywordName = RobotPsiUtil.normalizeKeywordForIndex(robotKeyword.getText()); if (RobotBuiltInKeywords.isBuiltInKeyword(normalKeywordName)) { Annotation annotation = holder.createInfoAnnotation(robotKeyword, "Built-in Robot Keyword"); annotation.setTextAttributes(DefaultLanguageHighlighterColors.GLOBAL_VARIABLE); } else { if (RobotConfigurable.isHighlightInvalidKeywords(element.getProject())) { holder.createErrorAnnotation(robotKeyword, String.format("No Keyword found with name \"%s\"", robotKeyword.getText())); } } } } else if (element instanceof RobotGenericSettingName) { if (RobotConfigurable.isHighlightInvalidKeywords(element.getProject())) { holder.createErrorAnnotation(element, String.format("No Robot Setting exists with name \"%s\"", element.getText())); } } }
private static TextAttributesKey getAttributesKey(PsiElement element) { if(element instanceof ThriftService || element instanceof ThriftUnion || element instanceof ThriftStruct || element instanceof ThriftException || element instanceof ThriftEnum || element instanceof ThriftSenum) { return DefaultLanguageHighlighterColors.CLASS_NAME; } else if(element instanceof ThriftTypedef) { return DefaultLanguageHighlighterColors.TYPE_ALIAS_NAME; } else if(element instanceof ThriftConst || element instanceof ThriftEnumField) { return DefaultLanguageHighlighterColors.STATIC_FIELD; } else if(element instanceof ThriftField) { if(element.getParent() instanceof ThriftThrows) { return DefaultLanguageHighlighterColors.LOCAL_VARIABLE; } return DefaultLanguageHighlighterColors.INSTANCE_FIELD; } return null; }
@NotNull @Override public SyntaxHighlighter getHighlighter() { return new CfsSyntaxHighlighter(CfsLanguage.INSTANCE.findVersionByClass(IndexCfsLanguageVersion.class)) { @NotNull @Override public TextAttributesKey[] getTokenHighlights(IElementType elementType) { if(elementType == CfsTokens.TEXT) { return pack(DefaultLanguageHighlighterColors.STRING); } return super.getTokenHighlights(elementType); } }; }
@NotNull @Override public TextAttributesKey[] getTokenHighlights(IElementType elementType) { if(MsilTokenSets._KEYWORDS.contains(elementType)) { return pack(DefaultLanguageHighlighterColors.MACRO_KEYWORD); } else if(MsilTokenSets.COMMENTS.contains(elementType)) { return pack(DefaultLanguageHighlighterColors.LINE_COMMENT); } else if(MsilTokenSets.KEYWORDS.contains(elementType)) { return pack(DefaultLanguageHighlighterColors.KEYWORD); } else if(elementType == MsilTokens.STRING_LITERAL) { return pack(DefaultLanguageHighlighterColors.STRING); } else if(elementType == MsilTokens.NUMBER_LITERAL || elementType == MsilTokens.HEX_NUMBER_LITERAL || elementType == MsilTokens.DOUBLE_LITERAL) { return pack(DefaultLanguageHighlighterColors.NUMBER); } return new TextAttributesKey[0]; }
/** * Annotates the given comment so that tags like @command, @bis, and @fnc (Arma Intellij Plugin specific tags) are properly annotated * * @param annotator the annotator * @param comment the comment */ public static void annotateDocumentationWithArmaPluginTags(@NotNull AnnotationHolder annotator, @NotNull PsiComment comment) { List<String> allowedTags = new ArrayList<>(3); allowedTags.add("command"); allowedTags.add("bis"); allowedTags.add("fnc"); Pattern patternTag = Pattern.compile("@([a-zA-Z]+) ([a-zA-Z_0-9]+)"); Matcher matcher = patternTag.matcher(comment.getText()); String tag; Annotation annotation; int startTag, endTag, startArg, endArg; while (matcher.find()) { if (matcher.groupCount() < 2) { continue; } tag = matcher.group(1); if (!allowedTags.contains(tag)) { continue; } startTag = matcher.start(1); endTag = matcher.end(1); startArg = matcher.start(2); endArg = matcher.end(2); annotation = annotator.createAnnotation(HighlightSeverity.INFORMATION, TextRange.create(comment.getTextOffset() + startTag - 1, comment.getTextOffset() + endTag), null); annotation.setTextAttributes(DefaultLanguageHighlighterColors.DOC_COMMENT_TAG); annotation = annotator.createAnnotation(HighlightSeverity.INFORMATION, TextRange.create(comment.getTextOffset() + startArg, comment.getTextOffset() + endArg), null); annotation.setTextAttributes(DefaultLanguageHighlighterColors.DOC_COMMENT_TAG_VALUE); } }
public void testSaveNoInheritanceAndDefaults() throws Exception { TextAttributes identifierAttrs = EditorColorsManager.getInstance().getScheme(EditorColorsScheme.DEFAULT_SCHEME_NAME) .getAttributes(DefaultLanguageHighlighterColors.IDENTIFIER); TextAttributes declarationAttrs = identifierAttrs.clone(); Pair<EditorColorsScheme, TextAttributes> result = doTestWriteRead(DefaultLanguageHighlighterColors.FUNCTION_DECLARATION, declarationAttrs); TextAttributes fallbackAttrs = result.first.getAttributes( DefaultLanguageHighlighterColors.FUNCTION_DECLARATION.getFallbackAttributeKey() ); assertEquals(result.second, fallbackAttrs); assertNotSame(result.second, fallbackAttrs); }
@Override public void renderStringValue(@NotNull String value, @Nullable String additionalSpecialCharsToHighlight, int maxLength) { TextAttributes textAttributes = DebuggerUIUtil.getColorScheme().getAttributes(DefaultLanguageHighlighterColors.STRING); SimpleTextAttributes attributes = SimpleTextAttributes.fromTextAttributes(textAttributes); myText.append("\"", attributes); XValuePresentationUtil.renderValue(value, myText, attributes, maxLength, additionalSpecialCharsToHighlight); myText.append("\"", attributes); }
@NotNull @Override public TextAttributesKey[] getAttributesKey(Token t) { switch (t.getType()) { case STGLexer.DOC_COMMENT: return COMMENT_KEYS; case STGLexer.LINE_COMMENT: return COMMENT_KEYS; case STGLexer.BLOCK_COMMENT: return COMMENT_KEYS; case STGLexer.ID: return new TextAttributesKey[]{STGroup_TEMPLATE_NAME}; case STGLexer.DELIMITERS: case STGLexer.IMPORT: case STGLexer.DEFAULT: case STGLexer.KEY: case STGLexer.VALUE: case STGLexer.FIRST: case STGLexer.LAST: case STGLexer.REST: case STGLexer.TRUNC: case STGLexer.STRIP: case STGLexer.TRIM: case STGLexer.LENGTH: case STGLexer.STRLEN: case STGLexer.REVERSE: case STGLexer.GROUP: case STGLexer.WRAP: case STGLexer.ANCHOR: case STGLexer.SEPARATOR: return new TextAttributesKey[]{DefaultLanguageHighlighterColors.KEYWORD}; case Token.INVALID_TYPE: return new TextAttributesKey[]{HighlighterColors.BAD_CHARACTER}; default: return EMPTY; } }
@NotNull @Override public TextAttributesKey[] getAttributesKey(Token t) { int tokenType = t.getType(); TextAttributesKey key; switch ( tokenType ) { case STLexer.IF: case STLexer.ELSE: case STLexer.REGION_END: case STLexer.TRUE: case STLexer.FALSE: case STLexer.ELSEIF: case STLexer.ENDIF: case STLexer.SUPER: key = DefaultLanguageHighlighterColors.KEYWORD; break; case STLexer.ID: key = ST_ID; break; case STLexer.STRING: case STLexer.TEXT: key = STGroup_TEMPLATE_TEXT; break; case STLexer.COMMENT: key = DefaultLanguageHighlighterColors.LINE_COMMENT; break; case STLexer.ERROR_TYPE : key = HighlighterColors.BAD_CHARACTER; break; default: return EMPTY; } return new TextAttributesKey[]{key}; }
/** * Annotates logical and equality operators * @param psiElement * @param annotationHolder */ void annotateLogicalOperators(PsiElement psiElement, AnnotationHolder annotationHolder) { // Annotate logical operators if(psiElement instanceof CMakeArgument && (psiElement.getText().contains("NOT") || psiElement.getText().contains("AND") || psiElement.getText().contains("OR") || psiElement.getText().contains("STREQUAL")) ){ TextRange range = new TextRange(psiElement.getTextRange().getStartOffset(), psiElement.getTextRange().getStartOffset() + psiElement.getTextRange().getLength()); Annotation annotation = annotationHolder.createInfoAnnotation(range, null); annotation.setTextAttributes(DefaultLanguageHighlighterColors.OPERATION_SIGN); } }
/** * Annotates logical constants * @param psiElement * @param annotationHolder */ void annotateLogicalConstants(PsiElement psiElement, AnnotationHolder annotationHolder) { // Annotate logical constants if(psiElement instanceof CMakeArgument && (psiElement.getText().contains("ON") || psiElement.getText().contains("OFF") || psiElement.getText().contains("TRUE") ||psiElement.getText().contains("FALSE") ) ){ TextRange range = new TextRange(psiElement.getTextRange().getStartOffset(), psiElement.getTextRange().getStartOffset() + psiElement.getTextRange().getLength()); Annotation annotation = annotationHolder.createInfoAnnotation(range, null); annotation.setTextAttributes(DefaultLanguageHighlighterColors.CONSTANT); } }
@Override public void visitProperty(ShaderPropertyElement p) { super.visitProperty(p); PsiElement nameIdentifier = p.getNameIdentifier(); if(nameIdentifier != null) { myHolder.add(HighlightInfo.newHighlightInfo(HighlightInfoType.INFORMATION).range(nameIdentifier).textAttributes(DefaultLanguageHighlighterColors.INSTANCE_FIELD).create()); } }
@Override @RequiredReadAction public void visitReference(ShaderReference reference) { if(!reference.isSoft()) { PsiElement resolve = reference.resolve(); if(resolve == null) { myHolder.add(HighlightInfo.newHighlightInfo(HighlightInfoType.WRONG_REF).range(reference.getReferenceElement()).descriptionAndTooltip("'" + reference.getReferenceName() + "' is not " + "resolved").create()); } else { ShaderReference.ResolveKind kind = reference.kind(); TextAttributesKey key = null; switch(kind) { case ATTRIBUTE: key = DefaultLanguageHighlighterColors.METADATA; break; case PROPERTY: key = DefaultLanguageHighlighterColors.INSTANCE_FIELD; break; default: return; } myHolder.add(HighlightInfo.newHighlightInfo(HighlightInfoType.INFORMATION).range(reference.getReferenceElement()).textAttributes(key).create()); } } }
@Override public void append(String value, SimpleColoredText text, boolean changed) { SimpleTextAttributes attributes = SimpleTextAttributes.fromTextAttributes(EditorColorsManager.getInstance().getGlobalScheme().getAttributes(DefaultLanguageHighlighterColors.STRING)); text.append("\"", attributes); doAppend(value, text, attributes); text.append("\"", attributes); }
@Override @RequiredReadAction public void visit(@NotNull PsiElement element) { if(element instanceof CSharpPreprocessorReferenceExpressionImpl) { if(((CSharpPreprocessorReferenceExpressionImpl) element).resolve() != null) { myHighlightInfoHolder.add(HighlightInfo.newHighlightInfo(HighlightInfoType.INFORMATION).range(element).textAttributes(TemplateColors.TEMPLATE_VARIABLE_ATTRIBUTES).create()); } else { myHighlightInfoHolder.add(HighlightInfo.newHighlightInfo(HighlightInfoType.INFORMATION).range(element).textAttributes(DefaultLanguageHighlighterColors.LINE_COMMENT).create()); } } else if(element instanceof CSharpPreprocessorDefine) { if(((CSharpPreprocessorDefine) element).isUnDef()) { PsiElement varElement = ((CSharpPreprocessorDefine) element).getVarElement(); if(varElement != null) { myHighlightInfoHolder.add(HighlightInfo.newHighlightInfo(HighlightInfoType.INFORMATION).range(varElement).textAttributes(DefaultLanguageHighlighterColors.LINE_COMMENT).create()); } } else { CSharpPreprocessorVariable variable = ((CSharpPreprocessorDefine) element).getVariable(); if(variable != null) { myHighlightInfoHolder.add(HighlightInfo.newHighlightInfo(HighlightInfoType.INFORMATION).range(variable.getNameIdentifier()).textAttributes(TemplateColors .TEMPLATE_VARIABLE_ATTRIBUTES).create()); } } } else { element.accept(this); } }
public PlayBaseTemplateEditorHighlighter(@NotNull EditorColorsScheme scheme, @Nullable Project project, @Nullable VirtualFile virtualFile) { super(new PlayBaseTemplateSyntaxHighlighter(), scheme); SyntaxHighlighter htmlHighlighter = SyntaxHighlighterFactory.getSyntaxHighlighter(HTMLLanguage.INSTANCE, project, virtualFile); LayerDescriptor htmlLayer = new LayerDescriptor(new TemplateDataHighlighterWrapper(htmlHighlighter), "\n"); registerLayer(PlayBaseTemplateTokens.TEMPLATE_TEXT, htmlLayer); SyntaxHighlighter groovyHighlighter = new GroovySyntaxHighlighter(); LayerDescriptor groovyLayer = new LayerDescriptor(groovyHighlighter, "\n", DefaultLanguageHighlighterColors.TEMPLATE_LANGUAGE_COLOR); registerLayer(PlayBaseTemplateTokens.GROOVY_EXPRESSION_OLD, groovyLayer); }
public static boolean isHighlightedAsComment(TextAttributesKey... keys) { for (TextAttributesKey key : keys) { if (key == DefaultLanguageHighlighterColors.DOC_COMMENT || key == DefaultLanguageHighlighterColors.LINE_COMMENT || key == DefaultLanguageHighlighterColors.BLOCK_COMMENT) { return true; } if (key == null) continue; final TextAttributesKey fallbackAttributeKey = key.getFallbackAttributeKey(); if (fallbackAttributeKey != null && isHighlightedAsComment(fallbackAttributeKey)) { return true; } } return false; }
public static boolean isHighlightedAsString(TextAttributesKey... keys) { for (TextAttributesKey key : keys) { if (key == DefaultLanguageHighlighterColors.STRING) { return true; } if (key == null) continue; final TextAttributesKey fallbackAttributeKey = key.getFallbackAttributeKey(); if (fallbackAttributeKey != null && isHighlightedAsString(fallbackAttributeKey)) { return true; } } return false; }
@Nonnull protected HighlightInfo.Builder getInfoBuilder(int colorIndex, @Nullable TextAttributesKey colorKey) { if (colorKey == null) { colorKey = DefaultLanguageHighlighterColors.LOCAL_VARIABLE; } return HighlightInfo .newHighlightInfo(RAINBOW_ELEMENT) .textAttributes(TextAttributes .fromFlyweight(myColorsScheme .getAttributes(colorKey) .getFlyweight() .withForeground(calculateForeground(colorIndex)))); }
@Override public void renderStringValue(@Nonnull String value, @Nullable String additionalSpecialCharsToHighlight, char quoteChar, int maxLength) { TextAttributes textAttributes = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(DefaultLanguageHighlighterColors.STRING); SimpleTextAttributes attributes = SimpleTextAttributes.fromTextAttributes(textAttributes); myText.append(String.valueOf(quoteChar), attributes); XValuePresentationUtil.renderValue(value, myText, attributes, maxLength, additionalSpecialCharsToHighlight); myText.append(String.valueOf(quoteChar), attributes); }
public static void renderValue(@Nonnull String value, @Nonnull ColoredTextContainer text, @Nonnull SimpleTextAttributes attributes, int maxLength, @Nullable String additionalCharsToEscape) { SimpleTextAttributes escapeAttributes = null; int lastOffset = 0; int length = maxLength == -1 ? value.length() : Math.min(value.length(), maxLength); for (int i = 0; i < length; i++) { char ch = value.charAt(i); int additionalCharIndex = -1; if (ch == '\n' || ch == '\r' || ch == '\t' || ch == '\b' || ch == '\f' || (additionalCharsToEscape != null && (additionalCharIndex = additionalCharsToEscape.indexOf(ch)) != -1)) { if (i > lastOffset) { text.append(value.substring(lastOffset, i), attributes); } lastOffset = i + 1; if (escapeAttributes == null) { TextAttributes fromHighlighter = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(DefaultLanguageHighlighterColors.VALID_STRING_ESCAPE); if (fromHighlighter != null) { escapeAttributes = SimpleTextAttributes.fromTextAttributes(fromHighlighter); } else { escapeAttributes = new SimpleTextAttributes(SimpleTextAttributes.STYLE_BOLD, JBColor.GRAY); } } if (additionalCharIndex == -1) { text.append("\\", escapeAttributes); } text.append(String.valueOf(getEscapingSymbol(ch)), escapeAttributes); } } if (lastOffset < length) { text.append(value.substring(lastOffset, length), attributes); } }
@Override public void paint(@Nonnull Editor editor, @Nonnull Graphics g, @Nonnull Rectangle r) { if (myText != null && (step > steps || startWidth != 0)) { TextAttributes attributes = editor.getColorsScheme().getAttributes(DefaultLanguageHighlighterColors.INLINE_PARAMETER_HINT); if (attributes != null) { MyFontMetrics fontMetrics = getFontMetrics(editor); Color backgroundColor = attributes.getBackgroundColor(); if (backgroundColor != null) { GraphicsConfig config = GraphicsUtil.setupAAPainting(g); GraphicsUtil.paintWithAlpha(g, BACKGROUND_ALPHA); g.setColor(backgroundColor); int gap = r.height < (fontMetrics.lineHeight + 2) ? 1 : 2; g.fillRoundRect(r.x + 2, r.y + gap, r.width - 4, r.height - gap * 2, 8, 8); config.restore(); } Color foregroundColor = attributes.getForegroundColor(); if (foregroundColor != null) { g.setColor(foregroundColor); g.setFont(getFont(editor)); Shape savedClip = g.getClip(); g.clipRect(r.x + 3, r.y + 2, r.width - 6, r.height - 4); int editorAscent = editor instanceof EditorImpl ? ((EditorImpl)editor).getAscent() : 0; FontMetrics metrics = fontMetrics.metrics; g.drawString(myText, r.x + 7, r.y + Math.max(editorAscent, (r.height + metrics.getAscent() - metrics.getDescent()) / 2) - 1); g.setClip(savedClip); } } } }
@Override public void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder holder) { if (element instanceof PsiMethod) { Annotation annotation = holder.createErrorAnnotation(((PsiMethod)element).getNameIdentifier(), null); annotation.registerUniversalFix(new MyFix(), null, null); annotation.setTextAttributes(DefaultLanguageHighlighterColors.DOC_COMMENT_TAG_VALUE); } }
public AppleScriptSyntaxHighlighterColors() { UNRESOLVED_REFERENCE.setFallbackAttributeKey(DefaultLanguageHighlighterColors.CLASS_REFERENCE); }
public void testSaveInheritance() throws Exception { Pair<EditorColorsScheme,TextAttributes> result = doTestWriteRead(DefaultLanguageHighlighterColors.STATIC_METHOD, new TextAttributes()); TextAttributes fallbackAttrs = result.first.getAttributes(DefaultLanguageHighlighterColors.STATIC_METHOD.getFallbackAttributeKey()); assertSame(result.second, fallbackAttrs); }
@Override public void renderNumericValue(@NotNull String value) { renderRawValue(value, DefaultLanguageHighlighterColors.NUMBER); }
@Override public void renderKeywordValue(@NotNull String value) { renderRawValue(value, DefaultLanguageHighlighterColors.KEYWORD); }
public RTSyntaxHighlighter() { super(RTLanguage.INSTANCE.getOptionHolder()); myKeysMap.put(JSTokenTypes.AS_KEYWORD, DefaultLanguageHighlighterColors.KEYWORD); myKeysMap.put(JSTokenTypes.IN_KEYWORD, DefaultLanguageHighlighterColors.KEYWORD); // myKeysMap.put(RTTokenTypes.TRACK_BY_KEYWORD, DefaultLanguageHighlighterColors.KEYWORD); }
@Override public void annotate(@NotNull final PsiElement element, @NotNull AnnotationHolder holder) { if (element instanceof XmlAttributeValue) { String value = ((XmlAttributeValue) element).getValue(); NodeTypeModel nodeTypeModel = null; try { nodeTypeModel = new NodeTypeModel(value); } catch (IllegalArgumentException e) { //Nothing to do } if (nodeTypeModel != null) { String namespace = nodeTypeModel.getNamespace(); String nodeTypeName = nodeTypeModel.getNodeTypeName(); Project project = element.getProject(); int offset = element.getTextRange().getStartOffset() + 1; //because of starting " TextRange namespaceRange = new TextRange(offset, offset + namespace.length()); TextRange colonRange = new TextRange(offset + namespace.length(), offset + namespace.length() + 1); TextRange nodeTypeNameRange = new TextRange(offset + namespace.length() + 1, element.getTextRange().getEndOffset() - 1); //because of ending " //Color ":" Annotation colonAnnotation = holder.createInfoAnnotation(colonRange, null); colonAnnotation.setTextAttributes(DefaultLanguageHighlighterColors.LINE_COMMENT); if (CndUtil.findNamespace(project, namespace) != null) { Annotation namespaceAnnotation = holder.createInfoAnnotation(namespaceRange, null); namespaceAnnotation.setTextAttributes(CndSyntaxHighlighter.NAMESPACE); if (CndUtil.findNodeType(project, namespace, nodeTypeName) != null) { Annotation nodeTypeNameAnnotation = holder.createInfoAnnotation(nodeTypeNameRange, null); nodeTypeNameAnnotation.setTextAttributes(CndSyntaxHighlighter.NODE_TYPE); } else { holder.createWarningAnnotation(nodeTypeNameRange, "Unresolved CND node type").registerFix(new CreateNodeTypeQuickFix(namespace, nodeTypeName)); } // } else { // holder.createErrorAnnotation(namespaceRange, "Unresolved CND namespace"); } } } }
@Override public void annotate(@NotNull final PsiElement element, @NotNull AnnotationHolder holder) { if (element instanceof PsiLiteralExpression) { PsiLiteralExpression literalExpression = (PsiLiteralExpression) element; String value = literalExpression.getValue() instanceof String ? (String) literalExpression.getValue() : null; NodeTypeModel nodeTypeModel = null; try { nodeTypeModel = new NodeTypeModel(value); } catch (IllegalArgumentException e) { //Nothing to do } if (nodeTypeModel != null) { String namespace = nodeTypeModel.getNamespace(); String nodeTypeName = nodeTypeModel.getNodeTypeName(); Project project = element.getProject(); int offset = element.getTextRange().getStartOffset() + 1; //because of starting " TextRange namespaceRange = new TextRange(offset, offset + namespace.length()); TextRange colonRange = new TextRange(offset + namespace.length(), offset + namespace.length() + 1); TextRange nodeTypeNameRange = new TextRange(offset + namespace.length() + 1, element.getTextRange().getEndOffset() - 1); //because of closing " //Color ":" Annotation colonAnnotation = holder.createInfoAnnotation(colonRange, null); colonAnnotation.setTextAttributes(DefaultLanguageHighlighterColors.LINE_COMMENT); if (CndUtil.findNamespace(project, namespace) != null) { Annotation namespaceAnnotation = holder.createInfoAnnotation(namespaceRange, null); namespaceAnnotation.setTextAttributes(CndSyntaxHighlighter.NAMESPACE); if (CndUtil.findNodeType(project, namespace, nodeTypeName) != null) { Annotation nodeTypeNameAnnotation = holder.createInfoAnnotation(nodeTypeNameRange, null); nodeTypeNameAnnotation.setTextAttributes(CndSyntaxHighlighter.NODE_TYPE); } else { holder.createWarningAnnotation(nodeTypeNameRange, "Unresolved CND node type").registerFix(new CreateNodeTypeQuickFix(namespace, nodeTypeName)); } // } else { // holder.createErrorAnnotation(namespaceRange, "Unresolved CND namespace"); } } } }
protected void doAppend(String value, SimpleColoredText text, SimpleTextAttributes attributes) { SimpleTextAttributes escapeAttributes = null; int lastOffset = 0; int length = maxLength == -1 ? value.length() : Math.min(value.length(), maxLength); for (int i = 0; i < length; i++) { char ch = value.charAt(i); int additionalCharIndex = -1; if (ch == '\n' || ch == '\r' || ch == '\t' || ch == '\b' || ch == '\f' || (additionalChars != null && (additionalCharIndex = additionalChars.indexOf(ch)) != -1)) { if (i > lastOffset) { text.append(value.substring(lastOffset, i), attributes); } lastOffset = i + 1; if (escapeAttributes == null) { TextAttributes fromHighlighter = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(DefaultLanguageHighlighterColors.VALID_STRING_ESCAPE); if (fromHighlighter != null) { escapeAttributes = SimpleTextAttributes.fromTextAttributes(fromHighlighter); } else { escapeAttributes = new SimpleTextAttributes(SimpleTextAttributes.STYLE_BOLD, JBColor.GRAY); } } if (additionalCharIndex == -1) { text.append("\\", escapeAttributes); } String string; switch (ch) { case '"': string = "\""; break; case '\\': string = "\\"; break; case '\n': string = "n"; break; case '\r': string = "r"; break; case '\t': string = "t"; break; case '\b': string = "b"; break; case '\f': string = "f"; break; default: string = String.valueOf(ch); } text.append(string, escapeAttributes); } } if (lastOffset < length) { text.append(value.substring(lastOffset, length), attributes); } }
public AngularJSSyntaxHighlighter() { super(EmberJSLanguage.INSTANCE.getOptionHolder()); myKeysMap.put(JSTokenTypes.AS_KEYWORD, DefaultLanguageHighlighterColors.KEYWORD); myKeysMap.put(EmberJSTokenTypes.TRACK_BY_KEYWORD, DefaultLanguageHighlighterColors.KEYWORD); }
public PlayRouteHighlighter() { elementToKeys.put(COMMENT, DefaultLanguageHighlighterColors.LINE_COMMENT); elementToKeys.put(METHOD_TYPE, PlayJavaColors.ROUTE_METHOD); }
@NotNull @Override public TextAttributesKey[] getTokenHighlights(IElementType elementType) { return pack(DefaultLanguageHighlighterColors.TEMPLATE_LANGUAGE_COLOR, ourMap1.get(elementType)); }