private static void addAnnotation()

in src/main/java/org/jetbrains/plugins/spotbugs/gui/editor/BugAnnotator.java [91:236]


	private static void addAnnotation(final ExtendedProblemDescriptor problemDescriptor, final List<ExtendedProblemDescriptor> matchingDescriptors, final PsiElement psiElement, @NotNull final AnnotationHolder annotationHolder) {
		final BugInstance bugInstance = problemDescriptor.getBug().getInstance();
		final int priority = bugInstance.getPriority();
		final AnnotationBuilder annotation;
		final PsiElement problemElement = problemDescriptor.getPsiElement();
		final TextRange textRange = problemElement.getTextRange();


		switch (priority) {
			case Detector.HIGH_PRIORITY:

				if (psiElement instanceof PsiClass) {
					PsiElement elementToAnnotation;
					if (psiElement instanceof PsiAnonymousClass) {
						elementToAnnotation = psiElement.getFirstChild();
					} else {
						elementToAnnotation = ((PsiClass) psiElement).getNameIdentifier();
					}

					annotation = annotationHolder.newAnnotation(HighlightSeverity.WARNING, getAnnotationText(matchingDescriptors))
									.range(elementToAnnotation == null ? psiElement : elementToAnnotation)
									// FIXME: use color from annotation configuration
									.enforcedTextAttributes(new TextAttributes(null, null, JBColor.RED.brighter(), EffectType.BOXED, Font.PLAIN));
				} else {
					annotation = annotationHolder.newAnnotation(HighlightSeverity.WARNING, getAnnotationText(matchingDescriptors))
									.range(textRange)
									// FIXME: use color from annotation configuration
									.enforcedTextAttributes(new TextAttributes(null, null, JBColor.RED, EffectType.WAVE_UNDERSCORE, Font.PLAIN));
				}

				annotation.newFix(new SuppressReportBugIntentionAction(problemDescriptor)).range(textRange).registerFix()
								.newFix(new SuppressReportBugForClassIntentionAction(problemDescriptor)).range(textRange).registerFix()
								.newFix(new ClearBugIntentionAction(problemDescriptor)).range(textRange).registerFix()
								.newFix(new ClearAndSuppressBugIntentionAction(problemDescriptor)).range(textRange).registerFix()
								.create();

				break;

			case Detector.NORMAL_PRIORITY:

				if (psiElement instanceof PsiClass) {
					PsiElement elementToAnnotation;
					if (psiElement instanceof PsiAnonymousClass) {
						elementToAnnotation = psiElement.getFirstChild();
					} else {
						elementToAnnotation = ((PsiClass) psiElement).getNameIdentifier();
					}
					annotation = annotationHolder.newAnnotation(HighlightSeverity.WARNING, getAnnotationText(matchingDescriptors))
									.range(elementToAnnotation == null ? psiElement : elementToAnnotation);
				} else {
					annotation = annotationHolder.newAnnotation(HighlightSeverity.WARNING, getAnnotationText(matchingDescriptors))
									.range(textRange);
				}

				// FIXME: use color from annotation configuration
				annotation
								.enforcedTextAttributes(
												new TextAttributes(null, null, JBColor.YELLOW.darker(), EffectType.WAVE_UNDERSCORE, Font.PLAIN))

								.newFix(new SuppressReportBugIntentionAction(problemDescriptor)).range(textRange).registerFix()
								.newFix(new SuppressReportBugForClassIntentionAction(problemDescriptor)).range(textRange).registerFix()
								.newFix(new ClearBugIntentionAction(problemDescriptor)).range(textRange).registerFix()
								.newFix(new ClearAndSuppressBugIntentionAction(problemDescriptor)).range(textRange).registerFix()
								.create();

				break;

			case Detector.EXP_PRIORITY:

				if (problemElement instanceof PsiClass) {
					PsiElement elementToAnnotation;
					if (problemElement instanceof PsiAnonymousClass) {
						elementToAnnotation = problemElement.getFirstChild();
					} else {
						elementToAnnotation = ((PsiClass) problemElement).getNameIdentifier();
					}
					annotation = annotationHolder.newAnnotation(HighlightSeverity.WARNING, getAnnotationText(matchingDescriptors))
									.range(elementToAnnotation == null ? psiElement : elementToAnnotation);
				} else {
					annotation = annotationHolder.newAnnotation(HighlightSeverity.WARNING, getAnnotationText(matchingDescriptors))
									.range(textRange);
				}

				// FIXME: use color from annotation configuration
				annotation.enforcedTextAttributes(new TextAttributes(null, null, JBColor.GRAY, EffectType.WAVE_UNDERSCORE, Font.PLAIN))
								.newFix(new SuppressReportBugIntentionAction(problemDescriptor)).range(textRange).registerFix()
								.newFix(new SuppressReportBugForClassIntentionAction(problemDescriptor)).range(textRange).registerFix()
								.newFix(new ClearBugIntentionAction(problemDescriptor)).range(textRange).registerFix()
								.newFix(new ClearAndSuppressBugIntentionAction(problemDescriptor)).range(textRange).registerFix()
								.create();

				break;
			case Detector.LOW_PRIORITY:

				if (psiElement instanceof PsiClass) {
					PsiElement elementToAnnotation;
					if (psiElement instanceof PsiAnonymousClass) {
						elementToAnnotation = psiElement.getFirstChild();
					} else {
						elementToAnnotation = ((PsiClass) psiElement).getNameIdentifier();
					}
					annotation = annotationHolder.newAnnotation(HighlightSeverity.INFORMATION, getAnnotationText(matchingDescriptors))
									.range(elementToAnnotation == null ? psiElement : elementToAnnotation);
				} else {
					annotation = annotationHolder.newAnnotation(HighlightSeverity.INFORMATION, getAnnotationText(matchingDescriptors))
									.range(textRange);
				}

				// FIXME: use color from annotation configuration
				annotation.enforcedTextAttributes(new TextAttributes(null, null, JBColor.GREEN, EffectType.WAVE_UNDERSCORE, Font.PLAIN))
								.newFix(new SuppressReportBugIntentionAction(problemDescriptor)).range(textRange).registerFix()
								.newFix(new SuppressReportBugForClassIntentionAction(problemDescriptor)).range(textRange).registerFix()
								.newFix(new ClearBugIntentionAction(problemDescriptor)).range(textRange).registerFix()
								.newFix(new ClearAndSuppressBugIntentionAction(problemDescriptor)).range(textRange).registerFix()
								.create();

				break;
			case Detector.IGNORE_PRIORITY:
				if (problemElement instanceof PsiClass) {
					PsiElement elementToAnnotation;
					if (problemElement instanceof PsiAnonymousClass) {
						elementToAnnotation = problemElement.getFirstChild();
					} else {
						elementToAnnotation = ((PsiClass) problemElement).getNameIdentifier();
					}
					annotation = annotationHolder.newAnnotation(HighlightSeverity.WARNING, getAnnotationText(matchingDescriptors))
									.range(elementToAnnotation == null ? psiElement : elementToAnnotation)
									.enforcedTextAttributes(new TextAttributes(null, null, JBColor.MAGENTA.brighter(), EffectType.WAVE_UNDERSCORE, Font.PLAIN));
				} else {
					annotation = annotationHolder.newAnnotation(HighlightSeverity.WARNING, getAnnotationText(matchingDescriptors))
									.range(textRange);
				}

				// FIXME: use color from annotation configuration
				annotation.enforcedTextAttributes(new TextAttributes(null, null, JBColor.MAGENTA, EffectType.WAVE_UNDERSCORE, Font.PLAIN))
								.newFix(new SuppressReportBugIntentionAction(problemDescriptor)).range(textRange).registerFix()
								.newFix(new SuppressReportBugForClassIntentionAction(problemDescriptor)).range(textRange).registerFix()
								.newFix(new ClearBugIntentionAction(problemDescriptor)).range(textRange).registerFix()
								.newFix(new ClearAndSuppressBugIntentionAction(problemDescriptor)).range(textRange).registerFix()
								.create();

				break;
			default:
				throw new IllegalArgumentException("Unknown bugInstance.getPriority() == " + priority);
		}
	}