示例#1
0
 @Nullable
 public HighlightSeverity getSeverity(@NotNull String name) {
   final HighlightInfoType type = STANDARD_SEVERITIES.get(name);
   if (type != null) return type.getSeverity(null);
   final SeverityBasedTextAttributes attributes = myMap.get(name);
   if (attributes != null) return attributes.getSeverity();
   return null;
 }
示例#2
0
  @Override
  public void readExternal(Element element) throws InvalidDataException {
    myMap.clear();
    myRendererColors.clear();
    final List children = element.getChildren(INFO_TAG);
    for (Object child : children) {
      final Element infoElement = (Element) child;

      final SeverityBasedTextAttributes highlightInfo =
          new SeverityBasedTextAttributes(infoElement);

      Color color = null;
      final String colorStr = infoElement.getAttributeValue(COLOR_ATTRIBUTE);
      if (colorStr != null) {
        color = new Color(Integer.parseInt(colorStr, 16));
      }
      registerSeverity(highlightInfo, color);
    }
    myReadOrder = new JDOMExternalizableStringList();
    myReadOrder.readExternal(element);
    List<HighlightSeverity> read = new ArrayList<HighlightSeverity>(myReadOrder.size());
    final List<HighlightSeverity> knownSeverities = getDefaultOrder();
    for (String name : myReadOrder) {
      HighlightSeverity severity = getSeverity(name);
      if (severity == null || !knownSeverities.contains(severity)) continue;
      read.add(severity);
    }
    OrderMap orderMap = fromList(read);
    if (orderMap.isEmpty()) {
      orderMap = fromList(knownSeverities);
    } else {
      // enforce include all known
      List<HighlightSeverity> list = getOrderAsList(orderMap);
      for (int i = 0; i < knownSeverities.size(); i++) {
        HighlightSeverity stdSeverity = knownSeverities.get(i);
        if (!list.contains(stdSeverity)) {
          for (int oIdx = 0; oIdx < list.size(); oIdx++) {
            HighlightSeverity orderSeverity = list.get(oIdx);
            HighlightInfoType type = STANDARD_SEVERITIES.get(orderSeverity.getName());
            if (type != null && knownSeverities.indexOf(type.getSeverity(null)) > i) {
              list.add(oIdx, stdSeverity);
              myReadOrder = null;
              break;
            }
          }
        }
      }
      orderMap = fromList(list);
    }
    myOrderMap = orderMap;
    severitiesChanged();
  }
示例#3
0
 @NotNull
 private List<HighlightSeverity> getDefaultOrder() {
   Collection<SeverityBasedTextAttributes> values = myMap.values();
   List<HighlightSeverity> order =
       new ArrayList<HighlightSeverity>(STANDARD_SEVERITIES.size() + values.size());
   for (HighlightInfoType type : STANDARD_SEVERITIES.values()) {
     order.add(type.getSeverity(null));
   }
   for (SeverityBasedTextAttributes attributes : values) {
     order.add(attributes.getSeverity());
   }
   ContainerUtil.sort(order);
   return order;
 }
 public static TextAttributes getAttributesByType(
     @Nullable final PsiElement element,
     @NotNull HighlightInfoType type,
     @NotNull TextAttributesScheme colorsScheme) {
   final SeverityRegistrar severityRegistrar =
       SeverityRegistrar.getSeverityRegistrar(element != null ? element.getProject() : null);
   final TextAttributes textAttributes =
       severityRegistrar.getTextAttributesBySeverity(type.getSeverity(element));
   if (textAttributes != null) {
     return textAttributes;
   }
   TextAttributesKey key = type.getAttributesKey();
   return colorsScheme.getAttributes(key);
 }
 /**
  * @deprecated To be removed in idea 13. Use {@link
  *     HighlightInfo#newHighlightInfo(HighlightInfoType)} instead.
  */
 @Deprecated
 @Nullable
 public static HighlightInfo createHighlightInfo(
     @NotNull HighlightInfoType type,
     @Nullable PsiElement element,
     int start,
     int end,
     @Nullable String description,
     @Nullable String toolTip,
     boolean isEndOfLine,
     @Nullable TextAttributes forcedAttributes) {
   LOG.assertTrue(
       element != null
           || ArrayUtilRt.find(HighlightSeverity.DEFAULT_SEVERITIES, type.getSeverity(element))
               != -1,
       "Custom type demands element to detect its text attributes");
   HighlightInfo highlightInfo =
       new HighlightInfo(
           forcedAttributes,
           null,
           type,
           start,
           end,
           description,
           toolTip,
           type.getSeverity(element),
           isEndOfLine,
           null,
           false,
           0);
   PsiFile file = element == null ? null : element.getContainingFile();
   for (HighlightInfoFilter filter : getFilters()) {
     if (!filter.accept(highlightInfo, file)) {
       return null;
     }
   }
   return highlightInfo;
 }
    @NotNull
    @Override
    public HighlightInfo createUnconditionally() {
      if (severity == null) {
        severity = type.getSeverity(psiElement);
      }

      return new HighlightInfo(
          forcedTextAttributes,
          forcedTextAttributesKey,
          type,
          startOffset,
          endOffset,
          escapedDescription,
          escapedToolTip,
          severity,
          isAfterEndOfLine,
          myNeedsUpdateOnTyping,
          isFileLevelAnnotation,
          navigationShift);
    }
 /**
  * @deprecated To be removed in idea 13. Use {@link
  *     HighlightInfo#newHighlightInfo(HighlightInfoType)} instead.
  */
 @Deprecated
 public static HighlightInfo createHighlightInfo(
     @NotNull final HighlightInfoType type,
     @NotNull final PsiElement element,
     @Nullable final String message,
     @Nullable final TextAttributesKey attributesKey) {
   TextRange textRange = element.getTextRange();
   // do not use HighlightInfoFilter
   return new HighlightInfo(
       null,
       attributesKey,
       type,
       textRange.getStartOffset(),
       textRange.getEndOffset(),
       message,
       htmlEscapeToolTip(message),
       type.getSeverity(element),
       false,
       Boolean.FALSE,
       false,
       0);
 }
 /**
  * @deprecated To be removed in idea 13. Use {@link
  *     HighlightInfo#newHighlightInfo(HighlightInfoType)} instead.
  */
 @Deprecated
 public static HighlightInfo createHighlightInfo(
     @NotNull HighlightInfoType type,
     @NotNull TextRange textRange,
     @Nullable String description,
     @Nullable String toolTip,
     @Nullable TextAttributes textAttributes) {
   // do not use HighlightInfoFilter
   return new HighlightInfo(
       textAttributes,
       null,
       type,
       textRange.getStartOffset(),
       textRange.getEndOffset(),
       description,
       htmlEscapeToolTip(toolTip),
       type.getSeverity(null),
       false,
       null,
       false,
       0);
 }