下面列出了怎么用com.intellij.openapi.editor.colors.CodeInsightColors的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* Returns the text attribute key used for highlighting the annotation. If not specified
* explicitly, the key is determined automatically based on the problem highlight type and
* the annotation severity.
*
* @return the text attribute key used for highlighting
*/
@Nonnull
public TextAttributesKey getTextAttributes() {
if (myEnforcedAttributesKey != null) return myEnforcedAttributesKey;
if (myHighlightType == ProblemHighlightType.GENERIC_ERROR_OR_WARNING) {
if (mySeverity == HighlightSeverity.ERROR) return CodeInsightColors.ERRORS_ATTRIBUTES;
if (mySeverity == HighlightSeverity.WARNING) return CodeInsightColors.WARNINGS_ATTRIBUTES;
if (mySeverity == HighlightSeverity.WEAK_WARNING) return CodeInsightColors.WEAK_WARNING_ATTRIBUTES;
}
if (myHighlightType == ProblemHighlightType.GENERIC_ERROR) {
return CodeInsightColors.ERRORS_ATTRIBUTES;
}
if (myHighlightType == ProblemHighlightType.LIKE_DEPRECATED) {
return CodeInsightColors.DEPRECATED_ATTRIBUTES;
}
if (myHighlightType == ProblemHighlightType.LIKE_UNUSED_SYMBOL) {
return CodeInsightColors.NOT_USED_ELEMENT_ATTRIBUTES;
}
if (myHighlightType == ProblemHighlightType.LIKE_UNKNOWN_SYMBOL || myHighlightType == ProblemHighlightType.ERROR) {
return CodeInsightColors.WRONG_REFERENCES_ATTRIBUTES;
}
return HighlighterColors.NO_HIGHLIGHTING;
}
private static void flashUsageScriptaculously(@Nonnull final Usage usage) {
if (!(usage instanceof UsageInfo2UsageAdapter)) {
return;
}
UsageInfo2UsageAdapter usageInfo = (UsageInfo2UsageAdapter)usage;
Editor editor = usageInfo.openTextEditor(true);
if (editor == null) return;
TextAttributes attributes = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(CodeInsightColors.BLINKING_HIGHLIGHTS_ATTRIBUTES);
RangeBlinker rangeBlinker = new RangeBlinker(editor, attributes, 6);
List<Segment> segments = new ArrayList<>();
Processor<Segment> processor = Processors.cancelableCollectProcessor(segments);
usageInfo.processRangeMarkers(processor);
rangeBlinker.resetMarkers(segments);
rangeBlinker.startBlinking();
}
private static void addInspectionSeverityAttributes(List<AttributesDescriptor> descriptors) {
descriptors.add(new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.unknown.symbol"), CodeInsightColors.WRONG_REFERENCES_ATTRIBUTES));
descriptors.add(new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.deprecated.symbol"), CodeInsightColors.DEPRECATED_ATTRIBUTES));
descriptors.add(new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.unused.symbol"), CodeInsightColors.NOT_USED_ELEMENT_ATTRIBUTES));
descriptors.add(new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.error"), CodeInsightColors.ERRORS_ATTRIBUTES));
descriptors.add(new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.warning"), CodeInsightColors.WARNINGS_ATTRIBUTES));
descriptors.add(new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.weak.warning"), CodeInsightColors.WEAK_WARNING_ATTRIBUTES));
descriptors.add(new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.server.problems"), CodeInsightColors.GENERIC_SERVER_ERROR_OR_WARNING));
descriptors.add(new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.server.duplicate"), CodeInsightColors.DUPLICATE_FROM_SERVER));
for (SeveritiesProvider provider : Extensions.getExtensions(SeveritiesProvider.EP_NAME)) {
for (HighlightInfoType highlightInfoType : provider.getSeveritiesHighlightInfoTypes()) {
final TextAttributesKey attributesKey = highlightInfoType.getAttributesKey();
descriptors.add(new AttributesDescriptor(toDisplayName(attributesKey), attributesKey));
}
}
}
@Override
protected void updateImpl(PresentationData data) {
PsiFile value = getValue();
data.setPresentableText(value.getName());
data.setIcon(IconDescriptorUpdaters.getIcon(value, Iconable.ICON_FLAG_READ_STATUS));
VirtualFile file = getVirtualFile();
if (file != null && file.is(VFileProperty.SYMLINK)) {
String target = file.getCanonicalPath();
if (target == null) {
data.setAttributesKey(CodeInsightColors.WRONG_REFERENCES_ATTRIBUTES);
data.setTooltip(CommonBundle.message("vfs.broken.link"));
}
else {
data.setTooltip(FileUtil.toSystemDependentName(target));
}
}
}
@Override
public void doApplyInformationToEditor() {
HighlightInfo info = null;
final InplaceChangeSignature currentRefactoring = InplaceChangeSignature.getCurrentRefactoring(myEditor);
if (currentRefactoring != null) {
final ChangeInfo changeInfo = currentRefactoring.getStableChange();
final PsiElement element = changeInfo.getMethod();
int offset = myEditor.getCaretModel().getOffset();
if (element == null || !element.isValid()) return;
final TextRange elementTextRange = element.getTextRange();
if (elementTextRange == null || !elementTextRange.contains(offset)) return;
final LanguageChangeSignatureDetector<ChangeInfo> detector = LanguageChangeSignatureDetectors.INSTANCE.forLanguage(changeInfo.getLanguage());
TextRange range = detector.getHighlightingRange(changeInfo);
TextAttributes attributes = new TextAttributes(null, null,
myEditor.getColorsScheme().getAttributes(CodeInsightColors.WEAK_WARNING_ATTRIBUTES)
.getEffectColor(),
null, Font.PLAIN);
HighlightInfo.Builder builder = HighlightInfo.newHighlightInfo(HighlightInfoType.INFORMATION).range(range);
builder.textAttributes(attributes);
builder.descriptionAndTooltip(SIGNATURE_SHOULD_BE_POSSIBLY_CHANGED);
info = builder.createUnconditionally();
QuickFixAction.registerQuickFixAction(info, new ApplyChangeSignatureAction(currentRefactoring.getInitialName()));
}
Collection<HighlightInfo> infos = info != null ? Collections.singletonList(info) : Collections.emptyList();
UpdateHighlightersUtil.setHighlightersToEditor(myProject, myDocument, 0, myFile.getTextLength(), infos, getColorsScheme(), getId());
}
@Nullable
@RequiredReadAction
public static HighlightInfo highlightNamed(@Nonnull HighlightInfoHolder holder, @Nullable PsiElement element, @Nullable PsiElement target, @Nullable PsiElement owner)
{
if(target == null || element == null)
{
return null;
}
IElementType elementType = target.getNode().getElementType();
if(CSharpTokenSets.KEYWORDS.contains(elementType)) // don't highlight keywords
{
return null;
}
if(isMethodRef(owner, element))
{
HighlightInfo highlightInfo = HighlightInfo.newHighlightInfo(HighlightInfoType.INFORMATION).range(target).textAttributes(CSharpHighlightKey.METHOD_REF).create();
holder.add(highlightInfo);
}
TextAttributesKey defaultTextAttributeKey = getDefaultTextAttributeKey(element, target);
if(defaultTextAttributeKey == null)
{
return null;
}
HighlightInfo info = HighlightInfo.newHighlightInfo(HighlightInfoType.INFORMATION).range(target).textAttributes(defaultTextAttributeKey).create();
holder.add(info);
if(!(target instanceof CSharpIdentifier) && DotNetAttributeUtil.hasAttribute(element, DotNetTypes.System.ObsoleteAttribute))
{
holder.add(HighlightInfo.newHighlightInfo(HighlightInfoType.INFORMATION).range(target).textAttributes(CodeInsightColors.DEPRECATED_ATTRIBUTES).create());
}
return info;
}
private static TextAttributesKey getAttributesKey(LineData lineData) {
if (lineData != null) {
switch (lineData.getStatus()) {
case LineCoverage.FULL:
return CodeInsightColors.LINE_FULL_COVERAGE;
case LineCoverage.PARTIAL:
return CodeInsightColors.LINE_PARTIAL_COVERAGE;
}
}
return CodeInsightColors.LINE_NONE_COVERAGE;
}
@Nonnull
public static HighlightInfoType highlightTypeFromDescriptor(@Nonnull ProblemDescriptor problemDescriptor,
@Nonnull HighlightSeverity severity,
@Nonnull SeverityRegistrar severityRegistrar) {
final ProblemHighlightType highlightType = problemDescriptor.getHighlightType();
switch (highlightType) {
case GENERIC_ERROR_OR_WARNING:
return severityRegistrar.getHighlightInfoTypeBySeverity(severity);
case LIKE_DEPRECATED:
return new HighlightInfoType.HighlightInfoTypeImpl(severity, HighlightInfoType.DEPRECATED.getAttributesKey());
case LIKE_UNKNOWN_SYMBOL:
if (severity == HighlightSeverity.ERROR) {
return new HighlightInfoType.HighlightInfoTypeImpl(severity, HighlightInfoType.WRONG_REF.getAttributesKey());
}
if (severity == HighlightSeverity.WARNING) {
return new HighlightInfoType.HighlightInfoTypeImpl(severity, CodeInsightColors.WEAK_WARNING_ATTRIBUTES);
}
return severityRegistrar.getHighlightInfoTypeBySeverity(severity);
case LIKE_UNUSED_SYMBOL:
return new HighlightInfoType.HighlightInfoTypeImpl(severity, HighlightInfoType.UNUSED_SYMBOL.getAttributesKey());
case INFO:
return HighlightInfoType.INFO;
case WEAK_WARNING:
return HighlightInfoType.WEAK_WARNING;
case ERROR:
return HighlightInfoType.WRONG_REF;
case GENERIC_ERROR:
return HighlightInfoType.ERROR;
case INFORMATION:
final TextAttributesKey attributes = ((ProblemDescriptorBase)problemDescriptor).getEnforcedTextAttributes();
if (attributes != null) {
return new HighlightInfoType.HighlightInfoTypeImpl(HighlightSeverity.INFORMATION, attributes);
}
return HighlightInfoType.INFORMATION;
}
throw new RuntimeException("Cannot map " + highlightType);
}
@Nonnull
private static TextAttributes getFollowedHyperlinkAttributes(@Nonnull RangeHighlighter range) {
HyperlinkInfoTextAttributes attrs = HYPERLINK.get(range);
TextAttributes result = attrs != null ? attrs.getFollowedHyperlinkAttributes() : null;
if (result == null) {
result = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(CodeInsightColors.FOLLOWED_HYPERLINK_ATTRIBUTES);
}
return result;
}
@Nonnull
private static JPanel createSeparatorLine(@Nonnull EditorColorsScheme colorsScheme) {
Color color = colorsScheme.getColor(CodeInsightColors.METHOD_SEPARATORS_COLOR);
if (color == null) {
color = JBColor.namedColor("Group.separatorColor", new JBColor(Gray.xCD, Gray.x51));
}
return JBUI.Panels.simplePanel().withBorder(JBUI.Borders.customLine(color, 1, 0, 0, 0));
}
@Nonnull
private static SimpleTextAttributes createBreadcrumbsTextAttributes(@Nonnull EditorColorsScheme colorsScheme, boolean selected) {
Color backgroundColor = getBackgroundColor(colorsScheme, selected);
TextAttributes attributes = colorsScheme.getAttributes(CodeInsightColors.NOT_USED_ELEMENT_ATTRIBUTES);
if (attributes != null) {
Color unusedForeground = attributes.getForegroundColor();
if (unusedForeground != null) {
return SimpleTextAttributes.fromTextAttributes(new TextAttributes(unusedForeground, backgroundColor, null, null, Font.PLAIN));
}
}
return SimpleTextAttributes.fromTextAttributes(createDefaultTextAttributesWithBackground(colorsScheme, backgroundColor));
}
private void highlightBrace(@Nonnull TextRange braceRange, boolean matched) {
EditorColorsScheme scheme = myEditor.getColorsScheme();
final TextAttributes attributes =
matched ? scheme.getAttributes(CodeInsightColors.MATCHED_BRACE_ATTRIBUTES)
: scheme.getAttributes(CodeInsightColors.UNMATCHED_BRACE_ATTRIBUTES);
RangeHighlighter rbraceHighlighter =
myEditor.getMarkupModel().addRangeHighlighter(
braceRange.getStartOffset(), braceRange.getEndOffset(), HighlighterLayer.LAST + 1, attributes, HighlighterTargetArea.EXACT_RANGE);
rbraceHighlighter.setGreedyToLeft(false);
rbraceHighlighter.setGreedyToRight(false);
registerHighlighter(rbraceHighlighter);
}
@Nonnull
public static LineMarkerInfo<PsiElement> createMethodSeparatorLineMarker(@Nonnull PsiElement startFrom, @Nonnull EditorColorsManager colorsManager) {
LineMarkerInfo<PsiElement> info = new LineMarkerInfo<>(startFrom, startFrom.getTextRange(), null, Pass.LINE_MARKERS, FunctionUtil.<Object, String>nullConstant(), null, GutterIconRenderer.Alignment.RIGHT);
EditorColorsScheme scheme = colorsManager.getGlobalScheme();
info.separatorColor = scheme.getColor(CodeInsightColors.METHOD_SEPARATORS_COLOR);
info.separatorPlacement = SeparatorPlacement.TOP;
return info;
}
public IntentionUsagePanel() {
myEditor = (EditorEx)createEditor("", 10, 3, -1);
setLayout(new BorderLayout());
add(myEditor.getComponent(), BorderLayout.CENTER);
TextAttributes blinkAttributes = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(CodeInsightColors.BLINKING_HIGHLIGHTS_ATTRIBUTES);
myRangeBlinker = new RangeBlinker(myEditor, blinkAttributes, Integer.MAX_VALUE);
}
public ActionUsagePanel() {
myEditor = (EditorEx)createEditor("", 10, 3, -1);
setLayout(new BorderLayout());
add(myEditor.getComponent(), BorderLayout.CENTER);
TextAttributes blinkAttributes =
EditorColorsManager.getInstance().getGlobalScheme().getAttributes(CodeInsightColors.BLINKING_HIGHLIGHTS_ATTRIBUTES);
myRangeBlinker = new RangeBlinker(myEditor, blinkAttributes, Integer.MAX_VALUE);
}
@RequiredUIAccess
@Override
public void customizeCellRenderer(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
Font font = UIUtil.getTreeFont();
setFont(font.deriveFont(font.getSize() + JBUI.scale(1f)));
if (value instanceof PackageDependenciesNode) {
PackageDependenciesNode node = (PackageDependenciesNode)value;
try {
setIcon(node.getIcon());
}
catch (IndexNotReadyException ignore) {
}
final SimpleTextAttributes regularAttributes = SimpleTextAttributes.REGULAR_ATTRIBUTES;
TextAttributes textAttributes = regularAttributes.toTextAttributes();
if (node instanceof BasePsiNode && ((BasePsiNode)node).isDeprecated()) {
textAttributes = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(CodeInsightColors.DEPRECATED_ATTRIBUTES).clone();
}
final PsiElement psiElement = node.getPsiElement();
textAttributes.setForegroundColor(CopyPasteManager.getInstance().isCutElement(psiElement) ? CopyPasteManager.CUT_COLOR : node.getColor());
append(node.toString(), SimpleTextAttributes.fromTextAttributes(textAttributes));
String oldToString = toString();
if (!myProject.isDisposed()) {
for (ProjectViewNodeDecorator decorator : Extensions.getExtensions(ProjectViewNodeDecorator.EP_NAME, myProject)) {
decorator.decorate(node, this);
}
}
if (toString().equals(oldToString)) { // nothing was decorated
final String locationString = node.getComment();
if (locationString != null && locationString.length() > 0) {
append(" (" + locationString + ")", SimpleTextAttributes.GRAY_ATTRIBUTES);
}
}
}
}
private static Map<String, TextAttributesKey> createAdditionalHlAttrs() {
final Map<String, TextAttributesKey> descriptors = new THashMap<>();
descriptors.put("field", ObjectUtils.notNull(TextAttributesKey.find("INSTANCE_FIELD_ATTRIBUTES"),
DefaultLanguageHighlighterColors.INSTANCE_FIELD));
descriptors.put("unusedField", CodeInsightColors.NOT_USED_ELEMENT_ATTRIBUTES);
descriptors.put("error", CodeInsightColors.ERRORS_ATTRIBUTES);
descriptors.put("warning", CodeInsightColors.WARNINGS_ATTRIBUTES);
descriptors.put("weak_warning", CodeInsightColors.WEAK_WARNING_ATTRIBUTES);
descriptors.put("server_problems", CodeInsightColors.GENERIC_SERVER_ERROR_OR_WARNING);
descriptors.put("server_duplicate", CodeInsightColors.DUPLICATE_FROM_SERVER);
descriptors.put("unknownType", CodeInsightColors.WRONG_REFERENCES_ATTRIBUTES);
descriptors.put("localVar", ObjectUtils.notNull(TextAttributesKey.find("LOCAL_VARIABLE_ATTRIBUTES"),
DefaultLanguageHighlighterColors.LOCAL_VARIABLE));
descriptors.put("reassignedLocalVar", ObjectUtils.notNull(TextAttributesKey.find("REASSIGNED_LOCAL_VARIABLE_ATTRIBUTES"),
DefaultLanguageHighlighterColors.REASSIGNED_LOCAL_VARIABLE));
descriptors.put("reassignedParameter", ObjectUtils.notNull(TextAttributesKey.find("REASSIGNED_PARAMETER_ATTRIBUTES);"),
DefaultLanguageHighlighterColors.REASSIGNED_PARAMETER));
descriptors.put("implicitAnonymousParameter",
ObjectUtils.notNull(TextAttributesKey.find("IMPLICIT_ANONYMOUS_CLASS_PARAMETER_ATTRIBUTES);"),
DefaultLanguageHighlighterColors.CLASS_NAME));
descriptors.put("static", ObjectUtils.notNull(TextAttributesKey.find("STATIC_FIELD_ATTRIBUTES);"),
DefaultLanguageHighlighterColors.STATIC_FIELD));
descriptors.put("static_final", ObjectUtils.notNull(TextAttributesKey.find("STATIC_FINAL_FIELD_ATTRIBUTES);"),
DefaultLanguageHighlighterColors.STATIC_FIELD));
descriptors.put("deprecated", CodeInsightColors.DEPRECATED_ATTRIBUTES);
descriptors.put("for_removal", CodeInsightColors.MARKED_FOR_REMOVAL_ATTRIBUTES);
descriptors.put("constructorCall", ObjectUtils.notNull(TextAttributesKey.find("CONSTRUCTOR_CALL_ATTRIBUTES);"),
DefaultLanguageHighlighterColors.FUNCTION_CALL));
descriptors.put("constructorDeclaration", ObjectUtils.notNull(TextAttributesKey.find("CONSTRUCTOR_DECLARATION_ATTRIBUTES);"),
DefaultLanguageHighlighterColors.FUNCTION_DECLARATION));
descriptors.put("methodCall", ObjectUtils.notNull(TextAttributesKey.find("METHOD_CALL_ATTRIBUTES);"),
DefaultLanguageHighlighterColors.FUNCTION_CALL));
descriptors.put("methodDeclaration", ObjectUtils.notNull(TextAttributesKey.find("METHOD_DECLARATION_ATTRIBUTES);"),
DefaultLanguageHighlighterColors.FUNCTION_DECLARATION));
descriptors.put("static_method", ObjectUtils.notNull(TextAttributesKey.find("STATIC_METHOD_ATTRIBUTES);"),
DefaultLanguageHighlighterColors.STATIC_METHOD));
descriptors.put("abstract_method", ObjectUtils.notNull(TextAttributesKey.find("ABSTRACT_METHOD_ATTRIBUTES);"),
DefaultLanguageHighlighterColors.FUNCTION_CALL));
descriptors.put("inherited_method", ObjectUtils.notNull(TextAttributesKey.find("INHERITED_METHOD_ATTRIBUTES);"),
DefaultLanguageHighlighterColors.FUNCTION_CALL));
descriptors.put("param", ObjectUtils.notNull(TextAttributesKey.find("PARAMETER_ATTRIBUTES);"),
DefaultLanguageHighlighterColors.PARAMETER));
descriptors.put("lambda_param", ObjectUtils.notNull(TextAttributesKey.find("LAMBDA_PARAMETER_ATTRIBUTES);"),
DefaultLanguageHighlighterColors.PARAMETER));
descriptors.put("class", ObjectUtils.notNull(TextAttributesKey.find("CLASS_NAME_ATTRIBUTES);"),
DefaultLanguageHighlighterColors.CLASS_NAME));
descriptors.put("anonymousClass", ObjectUtils.notNull(TextAttributesKey.find("ANONYMOUS_CLASS_NAME_ATTRIBUTES);"),
DefaultLanguageHighlighterColors.CLASS_NAME));
descriptors.put("typeParameter", ObjectUtils.notNull(TextAttributesKey.find("TYPE_PARAMETER_NAME_ATTRIBUTES);"),
DefaultLanguageHighlighterColors.PARAMETER));
descriptors.put("abstractClass", ObjectUtils.notNull(TextAttributesKey.find("ABSTRACT_CLASS_NAME_ATTRIBUTES);"),
DefaultLanguageHighlighterColors.CLASS_NAME));
descriptors.put("interface", ObjectUtils.notNull(TextAttributesKey.find("INTERFACE_NAME_ATTRIBUTES);"),
DefaultLanguageHighlighterColors.INTERFACE_NAME));
descriptors.put("enum", ObjectUtils.notNull(TextAttributesKey.find("ENUM_NAME_ATTRIBUTES);"),
DefaultLanguageHighlighterColors.CLASS_NAME));
descriptors.put("annotationName", ObjectUtils.notNull(TextAttributesKey.find("ANNOTATION_NAME_ATTRIBUTES);"),
DefaultLanguageHighlighterColors.METADATA));
descriptors.put("annotationAttributeName", ObjectUtils.notNull(TextAttributesKey.find("ANNOTATION_ATTRIBUTE_NAME_ATTRIBUTES);"),
DefaultLanguageHighlighterColors.METADATA));
descriptors.put("javadocTagValue", ObjectUtils.notNull(TextAttributesKey.find("DOC_COMMENT_TAG_VALUE);"),
DefaultLanguageHighlighterColors.DOC_COMMENT_TAG_VALUE));
descriptors.put("instanceFinalField", ObjectUtils.notNull(TextAttributesKey.find("INSTANCE_FINAL_FIELD_ATTRIBUTES);"),
DefaultLanguageHighlighterColors.INSTANCE_FIELD));
descriptors.put("staticallyConstImported", ObjectUtils.notNull(TextAttributesKey.find("STATIC_FINAL_FIELD_IMPORTED_ATTRIBUTES);"),
DefaultLanguageHighlighterColors.STATIC_FIELD));
descriptors.put("staticallyImported", ObjectUtils.notNull(TextAttributesKey.find("STATIC_FIELD_IMPORTED_ATTRIBUTES);"),
DefaultLanguageHighlighterColors.STATIC_FIELD));
descriptors.put("static_imported_method", ObjectUtils.notNull(TextAttributesKey.find("STATIC_METHOD_CALL_IMPORTED_ATTRIBUTES);"),
DefaultLanguageHighlighterColors.STATIC_METHOD));
descriptors.put("keyword", JavaColorSettings.JAVA_KEYWORD);
descriptors.put("this", JavaColorSettings.THIS_SUPER);
descriptors.put("sf", JavaColorSettings.STATIC_FINAL);
descriptors.put("modifier", JavaColorSettings.MODIFIER);
return descriptors;
}
@SuppressWarnings("unchecked")
@Override
public void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder holder) {
final IElementType elementType = element.getNode().getElementType();
// highlight TO-DO items
if(elementType == JSGraphQLEndpointDocTokenTypes.DOCTEXT) {
final String elementText = element.getText().toLowerCase();
if(isTodoToken(elementText)) {
setTextAttributes(element, holder, CodeInsightColors.TODO_DEFAULT_ATTRIBUTES);
holder.getCurrentAnnotationSession().putUserData(TODO_ELEMENT, element);
return;
} else {
PsiElement prevSibling = element.getPrevSibling();
while (prevSibling != null) {
if(prevSibling == holder.getCurrentAnnotationSession().getUserData(TODO_ELEMENT)) {
setTextAttributes(element, holder, CodeInsightColors.TODO_DEFAULT_ATTRIBUTES);
return;
}
prevSibling = prevSibling.getPrevSibling();
}
}
}
final PsiComment comment = PsiTreeUtil.getContextOfType(element, PsiComment.class);
if (comment != null && JSGraphQLEndpointDocPsiUtil.isDocumentationComment(comment)) {
final TextAttributesKey textAttributesKey = ATTRIBUTES.get(elementType);
if (textAttributesKey != null) {
setTextAttributes(element, holder, textAttributesKey);
}
// highlight invalid argument names after @param
if(elementType == JSGraphQLEndpointDocTokenTypes.DOCVALUE) {
final JSGraphQLEndpointFieldDefinition field = PsiTreeUtil.getNextSiblingOfType(comment, JSGraphQLEndpointFieldDefinition.class);
if(field != null) {
final JSGraphQLEndpointDocTag tag = PsiTreeUtil.getParentOfType(element, JSGraphQLEndpointDocTag.class);
if(tag != null && tag.getDocName().getText().equals("@param")) {
final String paramName = element.getText();
final JSGraphQLEndpointInputValueDefinitions arguments = PsiTreeUtil.findChildOfType(field, JSGraphQLEndpointInputValueDefinitions.class);
if(arguments == null) {
// no arguments so invalid use of @param
holder.createErrorAnnotation(element, "Invalid use of @param. The property has no arguments");
} else {
final JSGraphQLEndpointInputValueDefinition[] inputValues = PsiTreeUtil.getChildrenOfType(arguments, JSGraphQLEndpointInputValueDefinition.class);
boolean found = false;
if(inputValues != null) {
for (JSGraphQLEndpointInputValueDefinition inputValue: inputValues) {
if(inputValue.getInputValueDefinitionIdentifier().getText().equals(paramName)) {
found = true;
break;
}
}
}
if(!found) {
holder.createErrorAnnotation(element, "@param name '" + element.getText() + "' doesn't match any of the field arguments");
}
}
}
}
}
}
}
public UnreachableAnnotation() {
unreachableAttributes = TextAttributesKey.createTextAttributesKey("GLSL.UNREACHABLE", CodeInsightColors.NOT_USED_ELEMENT_ATTRIBUTES);
}
@RequiredReadAction
@Nullable
@Override
public LineMarkerInfo getLineMarkerInfo(@Nonnull PsiElement element)
{
if(myDaemonCodeAnalyzerSettings.SHOW_METHOD_SEPARATORS && (element instanceof DotNetQualifiedElement))
{
if(element.getNode().getTreeParent() == null)
{
return null;
}
final PsiElement parent = element.getParent();
if(!(parent instanceof DotNetMemberOwner))
{
return null;
}
if(ArrayUtil.getFirstElement(((DotNetMemberOwner) parent).getMembers()) == element)
{
return null;
}
LineMarkerInfo info = new LineMarkerInfo<PsiElement>(element, element.getTextRange(), null, Pass.UPDATE_ALL, FunctionUtil.<Object, String>nullConstant(), null,
GutterIconRenderer.Alignment.RIGHT);
EditorColorsScheme scheme = myEditorColorsManager.getGlobalScheme();
info.separatorColor = scheme.getColor(CodeInsightColors.METHOD_SEPARATORS_COLOR);
info.separatorPlacement = SeparatorPlacement.TOP;
return info;
}
final Ref<LineMarkerInfo> ref = Ref.create();
Consumer<LineMarkerInfo> consumer = new Consumer<LineMarkerInfo>()
{
@Override
public void consume(LineMarkerInfo markerInfo)
{
ref.set(markerInfo);
}
};
//noinspection ForLoopReplaceableByForEach
for(int j = 0; j < ourSingleCollector.length; j++)
{
LineMarkerCollector ourCollector = ourSingleCollector[j];
ourCollector.collect(element, consumer);
}
return ref.get();
}
@Nonnull
public static TextAttributes getDefaultColorSchemeTextAttributes() {
return EditorColorsManager.getInstance().getGlobalScheme().getAttributes(CodeInsightColors.TODO_DEFAULT_ATTRIBUTES).clone();
}
private static TextAttributes getHyperlinkAttributes() {
return EditorColorsManager.getInstance().getGlobalScheme().getAttributes(CodeInsightColors.HYPERLINK_ATTRIBUTES);
}
@Nonnull
private static TextAttributes createEmptyTextForegroundTextAttributes(@Nonnull EditorColorsScheme colorsScheme) {
TextAttributes unusedAttributes = colorsScheme.getAttributes(CodeInsightColors.NOT_USED_ELEMENT_ATTRIBUTES);
return unusedAttributes != null ? unusedAttributes : SimpleTextAttributes.GRAYED_ATTRIBUTES.toTextAttributes();
}
private void highlightBraces(@Nullable TextRange lBrace, @Nullable TextRange rBrace, boolean matched, boolean scopeHighlighting, @Nonnull FileType fileType) {
if (!matched && fileType == PlainTextFileType.INSTANCE) {
return;
}
EditorColorsScheme scheme = myEditor.getColorsScheme();
final TextAttributes attributes =
matched ? scheme.getAttributes(CodeInsightColors.MATCHED_BRACE_ATTRIBUTES)
: scheme.getAttributes(CodeInsightColors.UNMATCHED_BRACE_ATTRIBUTES);
if (rBrace != null && !scopeHighlighting) {
highlightBrace(rBrace, matched);
}
if (lBrace != null && !scopeHighlighting) {
highlightBrace(lBrace, matched);
}
FileEditorManager fileEditorManager = FileEditorManager.getInstance(myProject); // null in default project
if (fileEditorManager == null || !myEditor.equals(fileEditorManager.getSelectedTextEditor())) {
return;
}
if (lBrace != null && rBrace !=null) {
final int startLine = myEditor.offsetToLogicalPosition(lBrace.getStartOffset()).line;
final int endLine = myEditor.offsetToLogicalPosition(rBrace.getEndOffset()).line;
if (endLine - startLine > 0) {
final Runnable runnable = () -> {
if (myProject.isDisposed() || myEditor.isDisposed()) return;
Color color = attributes.getBackgroundColor();
if (color == null) return;
color = ColorUtil.isDark(EditorColorsManager.getInstance().getGlobalScheme().getDefaultBackground()) ? ColorUtil.shift(color, 1.5d) : color.darker();
lineMarkFragment(startLine, endLine, color);
};
if (!scopeHighlighting) {
myAlarm.addRequest(runnable, 300);
}
else {
runnable.run();
}
}
else {
removeLineMarkers();
}
if (!scopeHighlighting) {
showScopeHint(lBrace.getStartOffset(), lBrace.getEndOffset());
}
}
else {
if (!myCodeInsightSettings.HIGHLIGHT_SCOPE) {
removeLineMarkers();
}
}
}