use of com.intellij.lang.annotation.Annotation in project intellij-community by JetBrains.
the class JavaFxAnnotator method attachColorIcon.
private static void attachColorIcon(final PsiElement element, AnnotationHolder holder, String attributeValueText) {
try {
Color color = null;
if (attributeValueText.startsWith("#")) {
color = ColorUtil.fromHex(attributeValueText.substring(1));
} else {
final String hexCode = ColorMap.getHexCodeForColorName(StringUtil.toLowerCase(attributeValueText));
if (hexCode != null) {
color = ColorUtil.fromHex(hexCode);
}
}
if (color != null) {
final ColorIcon icon = JBUI.scale(new ColorIcon(8, color));
final Annotation annotation = holder.createInfoAnnotation(element, null);
annotation.setGutterIconRenderer(new ColorIconRenderer(icon, element));
}
} catch (Exception ignored) {
}
}
use of com.intellij.lang.annotation.Annotation in project intellij-community by JetBrains.
the class PropertiesAnnotator method annotate.
public void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder holder) {
if (!(element instanceof IProperty))
return;
final Property property = (Property) element;
PropertiesFile propertiesFile = property.getPropertiesFile();
Collection<IProperty> others = propertiesFile.findPropertiesByKey(property.getUnescapedKey());
ASTNode keyNode = ((PropertyImpl) property).getKeyNode();
if (others.size() != 1) {
Annotation annotation = holder.createErrorAnnotation(keyNode, PropertiesBundle.message("duplicate.property.key.error.message"));
annotation.registerFix(PropertiesQuickFixFactory.getInstance().createRemovePropertyFix(property));
}
highlightTokens(property, keyNode, holder, new PropertiesHighlighter());
ASTNode valueNode = ((PropertyImpl) property).getValueNode();
if (valueNode != null) {
highlightTokens(property, valueNode, holder, new PropertiesValueHighlighter());
}
}
use of com.intellij.lang.annotation.Annotation in project intellij-community by JetBrains.
the class DomHighlightingLiteTest method testDefaultAnnotator.
public void testDefaultAnnotator() throws Throwable {
final DefaultDomAnnotator annotator = new DefaultDomAnnotator() {
@Override
protected DomElementAnnotationsManagerImpl getAnnotationsManager(final DomElement element) {
return myAnnotationsManager;
}
};
final StringBuilder s = new StringBuilder();
final ArrayList<Annotation> toFill = new ArrayList<>();
final MyDomElementsInspection inspection = new MyDomElementsInspection() {
@Override
public void checkFileElement(final DomFileElement fileElement, final DomElementAnnotationHolder holder) {
s.append("visited");
}
};
annotator.runInspection(inspection, myElement, toFill);
assertEquals("visited", s.toString());
final DomElementsProblemsHolderImpl holder = assertNotEmptyHolder(myAnnotationsManager.getProblemHolder(myElement));
assertEmpty(toFill);
annotator.runInspection(inspection, myElement, toFill);
assertEquals("visited", s.toString());
assertSame(holder, assertNotEmptyHolder(myAnnotationsManager.getProblemHolder(myElement)));
assertEmpty(toFill);
}
use of com.intellij.lang.annotation.Annotation in project kotlin by JetBrains.
the class AndroidLintExternalAnnotator method apply.
@Override
public void apply(@NotNull PsiFile file, State state, @NotNull AnnotationHolder holder) {
if (state.isDirty()) {
return;
}
final Project project = file.getProject();
for (ProblemData problemData : state.getProblems()) {
final Issue issue = problemData.getIssue();
final String message = problemData.getMessage();
final TextRange range = problemData.getTextRange();
if (range.getStartOffset() == range.getEndOffset()) {
continue;
}
final Pair<AndroidLintInspectionBase, HighlightDisplayLevel> pair = AndroidLintUtil.getHighlighLevelAndInspection(project, issue, file);
if (pair == null) {
continue;
}
final AndroidLintInspectionBase inspection = pair.getFirst();
HighlightDisplayLevel displayLevel = pair.getSecond();
if (inspection != null) {
final HighlightDisplayKey key = HighlightDisplayKey.find(inspection.getShortName());
if (key != null) {
final PsiElement startElement = file.findElementAt(range.getStartOffset());
final PsiElement endElement = file.findElementAt(range.getEndOffset() - 1);
if (startElement != null && endElement != null && !inspection.isSuppressedFor(startElement)) {
if (problemData.getConfiguredSeverity() != null) {
HighlightDisplayLevel configuredLevel = AndroidLintInspectionBase.toHighlightDisplayLevel(problemData.getConfiguredSeverity());
if (configuredLevel != null) {
displayLevel = configuredLevel;
}
}
final Annotation annotation = createAnnotation(holder, message, range, displayLevel, issue);
for (AndroidLintQuickFix fix : inspection.getQuickFixes(startElement, endElement, message)) {
if (fix.isApplicable(startElement, endElement, AndroidQuickfixContexts.EditorContext.TYPE)) {
annotation.registerFix(new MyFixingIntention(fix, startElement, endElement));
}
}
for (IntentionAction intention : inspection.getIntentions(startElement, endElement)) {
annotation.registerFix(intention);
}
String id = key.getID();
if (IntellijLintIssueRegistry.CUSTOM_ERROR == issue || IntellijLintIssueRegistry.CUSTOM_WARNING == issue) {
Issue original = IntellijLintClient.findCustomIssue(message);
if (original != null) {
id = original.getId();
}
}
annotation.registerFix(new SuppressLintIntentionAction(id, startElement));
annotation.registerFix(new MyDisableInspectionFix(key));
annotation.registerFix(new MyEditInspectionToolsSettingsAction(key, inspection));
if (INCLUDE_IDEA_SUPPRESS_ACTIONS) {
final SuppressQuickFix[] suppressActions = inspection.getBatchSuppressActions(startElement);
for (SuppressQuickFix action : suppressActions) {
if (action.isAvailable(project, startElement)) {
ProblemHighlightType type = annotation.getHighlightType();
annotation.registerFix(action, null, key, InspectionManager.getInstance(project).createProblemDescriptor(startElement, endElement, message, type, true, LocalQuickFix.EMPTY_ARRAY));
}
}
}
}
}
}
}
}
use of com.intellij.lang.annotation.Annotation in project intellij-community by JetBrains.
the class DomElementsHighlightingUtil method createAnnotation.
@Nullable
public static Annotation createAnnotation(final DomElementProblemDescriptor problemDescriptor) {
return createProblemDescriptors(problemDescriptor, s -> {
String text = problemDescriptor.getDescriptionTemplate();
if (StringUtil.isEmpty(text))
text = null;
final HighlightSeverity severity = problemDescriptor.getHighlightSeverity();
TextRange range = s.first;
if (text == null)
range = TextRange.from(range.getStartOffset(), 0);
range = range.shiftRight(s.second.getTextRange().getStartOffset());
final Annotation annotation = createAnnotation(severity, range, text);
if (problemDescriptor instanceof DomElementResolveProblemDescriptor) {
annotation.setTextAttributes(CodeInsightColors.WRONG_REFERENCES_ATTRIBUTES);
}
for (LocalQuickFix fix : problemDescriptor.getFixes()) {
if (fix instanceof IntentionAction)
annotation.registerFix((IntentionAction) fix);
}
return annotation;
});
}
Aggregations