<commit_before>package com.sumologic.epigraph.ideaplugin.schema.presentation;

import com.intellij.icons.AllIcons;
import com.intellij.navigation.ItemPresentation;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiInvalidElementAccessException;
import com.intellij.psi.PsiNamedElement;
import com.intellij.psi.util.PsiTreeUtil;
import com.sumologic.epigraph.ideaplugin.schema.brains.NamespaceManager;
import com.sumologic.epigraph.ideaplugin.schema.brains.VirtualFileUtil;
import io.epigraph.lang.Fqn;
import io.epigraph.schema.parser.psi.*;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;
import java.util.List;

/**
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 */
public class SchemaPresentationUtil {
  // TODO own icons!
  public static final Icon SCHEMA_FILE_ICON = AllIcons.FileTypes.Custom;
  public static final Icon SCHEMA_OUTSIDE_SOURCE_FILE_ICON = AllIcons.FileTypes.Unknown;

  public static final Icon PARENT_TYPES_GUTTER_ICON = AllIcons.Gutter.OverridingMethod;
  public static final Icon CHILD_TYPES_GUTTER_ICON = AllIcons.Gutter.OverridenMethod;
  public static final Icon SUPPLEMENTS_GUTTER_ICON = AllIcons.Gutter.ExtAnnotation;

  public static final Icon OVERRIDEN_FIELD_GUTTER_ICON = AllIcons.Gutter.OverridenMethod;
  public static final Icon OVERRIDING_FIELD_GUTTER_ICON = AllIcons.Gutter.OverridingMethod;
  public static final Icon OVERRIDEN_TAG_GUTTER_ICON = AllIcons.Gutter.ImplementedMethod;
  public static final Icon OVERRIDING_TAG_GUTTER_ICON = AllIcons.Gutter.ImplementingMethod;

  @Nullable
  public static String getName(@NotNull PsiNamedElement element, boolean qualified) {
    if (element instanceof SchemaFqnSegment) {
      SchemaFqnSegment fqnSegment = (SchemaFqnSegment) element;
      return fqnSegment.getFqn().toString();
    }

    String shortName = element.getName();
    if (shortName == null) return null;

    if (qualified) {
      Fqn namespace;
      if (element instanceof SchemaTypeDef) {
        SchemaTypeDef typeDef = (SchemaTypeDef) element;
        namespace = typeDef.getNamespace();
      } else namespace = NamespaceManager.getNamespace(element);
      return namespace == null ? shortName : namespace.append(shortName).toString();
    } else return shortName;
  }

  @Nullable
  public static Icon getIcon(@NotNull PsiElement element) {
    if (element instanceof SchemaFile) return SCHEMA_FILE_ICON;

    if (element instanceof SchemaRecordTypeDef) return AllIcons.Nodes.Class;
    if (element instanceof SchemaEnumTypeDef) return AllIcons.Nodes.Enum;
    if (element instanceof SchemaVarTypeDef) return AllIcons.Nodes.Interface;

    if (element instanceof SchemaTypeDef) return AllIcons.Nodes.Class;

    if (element instanceof SchemaSupplementDef) return AllIcons.Nodes.Aspect;

    if (element instanceof SchemaCustomParam) return AllIcons.Nodes.Annotationtype;
    if (element instanceof SchemaFieldDecl) return AllIcons.Nodes.Field;
    if (element instanceof SchemaEnumMemberDecl) return AllIcons.Nodes.Property;
    if (element instanceof SchemaVarTagDecl)
      return AllIcons.Nodes.Function; // IconUtil.addText(icon, "D") for default member?
<commit_msg>plugin: added overlay to epigraph files/types icons<commit_after>package com.sumologic.epigraph.ideaplugin.schema.presentation;

import com.intellij.icons.AllIcons;
import com.intellij.navigation.ItemPresentation;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiInvalidElementAccessException;
import com.intellij.psi.PsiNamedElement;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.util.IconUtil;
import com.sumologic.epigraph.ideaplugin.schema.brains.NamespaceManager;
import com.sumologic.epigraph.ideaplugin.schema.brains.VirtualFileUtil;
import io.epigraph.lang.Fqn;
import io.epigraph.schema.parser.psi.*;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;
import java.util.List;

/**
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 */
public class SchemaPresentationUtil {
  private static final String OVERLAY = "§";
  // TODO own icons!
  public static final Icon SCHEMA_FILE_ICON = addOverlay(AllIcons.FileTypes.Custom);
  public static final Icon SCHEMA_OUTSIDE_SOURCE_FILE_ICON = addOverlay(AllIcons.FileTypes.Unknown);

  public static final Icon PARENT_TYPES_GUTTER_ICON = addOverlay(AllIcons.Gutter.OverridingMethod);
  public static final Icon CHILD_TYPES_GUTTER_ICON = addOverlay(AllIcons.Gutter.OverridenMethod);
  public static final Icon SUPPLEMENTS_GUTTER_ICON = addOverlay(AllIcons.Gutter.ExtAnnotation);

  public static final Icon OVERRIDEN_FIELD_GUTTER_ICON = addOverlay(AllIcons.Gutter.OverridenMethod);
  public static final Icon OVERRIDING_FIELD_GUTTER_ICON = addOverlay(AllIcons.Gutter.OverridingMethod);
  public static final Icon OVERRIDEN_TAG_GUTTER_ICON = addOverlay(AllIcons.Gutter.ImplementedMethod);
  public static final Icon OVERRIDING_TAG_GUTTER_ICON = addOverlay(AllIcons.Gutter.ImplementingMethod);

  private static Icon addOverlay(@NotNull Icon i) { return IconUtil.addText(i, OVERLAY); }

  @Nullable
  public static String getName(@NotNull PsiNamedElement element, boolean qualified) {
    if (element instanceof SchemaFqnSegment) {
      SchemaFqnSegment fqnSegment = (SchemaFqnSegment) element;
      return fqnSegment.getFqn().toString();
    }

    String shortName = element.getName();
    if (shortName == null) return null;

    if (qualified) {
      Fqn namespace;
      if (element instanceof SchemaTypeDef) {
        SchemaTypeDef typeDef = (SchemaTypeDef) element;
        namespace = typeDef.getNamespace();
      } else namespace = NamespaceManager.getNamespace(element);
      return namespace == null ? shortName : namespace.append(shortName).toString();
    } else return shortName;
  }

  @Nullable
  public static Icon getIcon(@NotNull PsiElement element) {
    if (element instanceof SchemaFile) return SCHEMA_FILE_ICON;

    if (element instanceof SchemaRecordTypeDef) return addOverlay(AllIcons.Nodes.Class);
    if (element instanceof SchemaEnumTypeDef) return addOverlay(AllIcons.Nodes.Enum);
    if (element instanceof SchemaVarTypeDef) return addOverlay(AllIcons.Nodes.Interface);

    if (element instanceof SchemaTypeDef) return addOverlay(AllIcons.Nodes.Class);

    if (element instanceof SchemaSupplementDef) return addOverlay(AllIcons.Nodes.Aspect);

    if (element instanceof SchemaCustomParam) return AllIcons.Nodes.Annotationtype;
    if (element instanceof SchemaFieldDecl) return AllIcons.Nodes.Field;
    if (element instanceof SchemaEnumMemberDecl) return AllIcons.Nodes.Property;
    if (element instanceof SchemaVarTagDecl)
      return AllIcons.Nodes.Function; 

{'fraction_non_alphanumeric': 0.08431257344300823, 'fraction_numerical': 0.0, 'mean_word_length': 5.287165281625115, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '685805', 'n_tokens_mistral': 2103, 'n_tokens_neox': 2012, 'n_words': 456}