void (@NotNull StringBuilder buffer, @NotNull PsiElement element, @NotNull Predicate<PsiElement> filter) { PsiFile containingFile = element.getContainingFile(); SyntaxTraverser.psiTraverser(containingFile) .filter(e -> e.getFirstChild() == null) .filter(e -> e.getTextLength() > 0) .filter(filter::test) .forEach(e -> { String text = e.getText(); JavaDocHighlightingManager manager = getHighlightingManager(); if (e instanceof PsiIdentifier) { PsiElement parent = e.getParent(); if (parent instanceof PsiJavaCodeReferenceElement) { PsiElement resolve = ((PsiJavaCodeReferenceElement)parent).resolve(); if (resolve instanceof PsiMember) { String label; boolean externalTarget = resolve.getContainingFile() != containingFile; if (doSemanticHighlightingOfLinks() || doHighlightCodeBlocks() && !externalTarget) { TextAttributes attributes = null; if (resolve instanceof PsiClass) { attributes = manager.getClassNameAttributes(); } else if (resolve instanceof PsiMethod) { attributes = manager.getMethodCallAttributes(); } else if (resolve instanceof PsiField) { attributes = externalTarget ? manager.getFieldDeclarationAttributes((PsiField)resolve) : manager.getLocalVariableAttributes(); } label = attributes != null ? getStyledSpan(true, attributes, text) : text; } else { label = text; } buffer.append(externalTarget ? generateLink(resolve, label, false, isRendered()) : label); return; } } } TextAttributes attributes = null; if (doHighlightCodeBlocks()) { if (e instanceof PsiKeyword) { attributes = manager.getKeywordAttributes(); } else if (e instanceof PsiIdentifier) { PsiElement parent = e.getParent(); if (parent instanceof PsiField) { attributes = manager.getLocalVariableAttributes(); } else if (parent instanceof PsiParameter) { attributes = manager.getParameterAttributes(); } else if (parent instanceof PsiTypeParameter) { attributes = manager.getTypeParameterNameAttributes(); } } else if (e instanceof PsiJavaToken) { IElementType tokenType = ((PsiJavaToken)e).getTokenType(); if (tokenType == JavaTokenType.LBRACKET || tokenType == JavaTokenType.RBRACKET) { attributes = manager.getBracketsAttributes(); } else if (tokenType == JavaTokenType.LBRACE || tokenType == JavaTokenType.RBRACE) { attributes = manager.getParenthesesAttributes(); } else if (tokenType == JavaTokenType.COMMA) { attributes = manager.getCommaAttributes(); } else if (tokenType == JavaTokenType.DOT) { attributes = manager.getDotAttributes(); } else if (tokenType == JavaTokenType.NULL_KEYWORD || tokenType == JavaTokenType.TRUE_KEYWORD || tokenType == JavaTokenType.FALSE_KEYWORD) { attributes = manager.getKeywordAttributes(); } else if (ElementType.OPERATION_BIT_SET.contains(tokenType)) { attributes = manager.getOperationSignAttributes(); } } } buffer.append(attributes != null ? getStyledSpan(true, attributes, text) : text); }); }