Пример #1
0
  @Override
  public Icon getIcon(@NotNull PsiElement psiElement, int flags) {
    if (psiElement instanceof JetFile) {
      JetFile file = (JetFile) psiElement;
      JetClassOrObject mainClass = getMainClass(file);
      return mainClass != null ? getIcon(mainClass, flags) : JetIcons.FILE;
    }
    if (psiElement instanceof JetNamespaceHeader) {
      return (flags & Iconable.ICON_FLAG_OPEN) != 0
          ? PlatformIcons.PACKAGE_OPEN_ICON
          : PlatformIcons.PACKAGE_ICON;
    }
    if (psiElement instanceof JetNamedFunction) {
      return PsiTreeUtil.getParentOfType(psiElement, JetNamedDeclaration.class) instanceof JetClass
          ? PlatformIcons.METHOD_ICON
          : JetIcons.FUNCTION;
    }
    if (psiElement instanceof JetClass) {
      JetClass jetClass = (JetClass) psiElement;
      if (jetClass.isTrait()) {
        return JetIcons.TRAIT;
      }

      Icon icon =
          jetClass.hasModifier(JetTokens.ENUM_KEYWORD) ? PlatformIcons.ENUM_ICON : JetIcons.CLASS;
      if (jetClass instanceof JetEnumEntry) {
        JetEnumEntry enumEntry = (JetEnumEntry) jetClass;
        if (enumEntry.getPrimaryConstructorParameterList() == null) {
          icon = PlatformIcons.ENUM_ICON;
        }
      }
      return icon;
    }
    if (psiElement instanceof JetObjectDeclaration || psiElement instanceof JetClassObject) {
      return JetIcons.OBJECT;
    }
    if (psiElement instanceof JetParameter) {
      JetParameter parameter = (JetParameter) psiElement;
      if (parameter.getValOrVarNode() != null) {
        JetParameterList parameterList =
            PsiTreeUtil.getParentOfType(psiElement, JetParameterList.class);
        if (parameterList != null && parameterList.getParent() instanceof JetClass) {
          return parameter.isMutable() ? JetIcons.FIELD_VAR : JetIcons.FIELD_VAL;
        }
      }
      return JetIcons.PARAMETER;
    }
    if (psiElement instanceof JetProperty) {
      JetProperty property = (JetProperty) psiElement;
      return property.isVar() ? JetIcons.FIELD_VAR : JetIcons.FIELD_VAL;
    }
    return null;
  }
Пример #2
0
  public static Icon getBaseIcon(PsiElement psiElement) {
    if (psiElement instanceof JetNamespaceHeader) {
      return PlatformIcons.PACKAGE_ICON;
    }

    if (psiElement instanceof KotlinLightClassForPackage) {
      return JetIcons.FILE;
    }

    if (psiElement instanceof KotlinLightClassForExplicitDeclaration) {
      psiElement = psiElement.getNavigationElement();
    }

    if (psiElement instanceof JetNamedFunction) {
      if (((JetFunction) psiElement).getReceiverTypeRef() != null) {
        return JetIcons.EXTENSION_FUNCTION;
      }

      if (PsiTreeUtil.getParentOfType(psiElement, JetNamedDeclaration.class) instanceof JetClass) {
        if (JetPsiUtil.isAbstract((JetFunction) psiElement)) {
          return PlatformIcons.ABSTRACT_METHOD_ICON;
        } else {
          return PlatformIcons.METHOD_ICON;
        }
      } else {
        return JetIcons.FUNCTION;
      }
    }
    if (psiElement instanceof JetClass) {
      JetClass jetClass = (JetClass) psiElement;
      if (jetClass.isTrait()) {
        return JetIcons.TRAIT;
      }

      Icon icon = jetClass.isEnum() ? PlatformIcons.ENUM_ICON : JetIcons.CLASS;
      if (jetClass instanceof JetEnumEntry) {
        JetEnumEntry enumEntry = (JetEnumEntry) jetClass;
        if (enumEntry.getPrimaryConstructorParameterList() == null) {
          icon = PlatformIcons.ENUM_ICON;
        }
      }
      return icon;
    }
    if (psiElement instanceof JetObjectDeclaration || psiElement instanceof JetClassObject) {
      return JetIcons.OBJECT;
    }
    if (psiElement instanceof JetParameter) {
      JetParameter parameter = (JetParameter) psiElement;
      if (parameter.getValOrVarNode() != null) {
        JetParameterList parameterList =
            PsiTreeUtil.getParentOfType(psiElement, JetParameterList.class);
        if (parameterList != null && parameterList.getParent() instanceof JetClass) {
          return parameter.isMutable() ? JetIcons.FIELD_VAR : JetIcons.FIELD_VAL;
        }
      }
      return JetIcons.PARAMETER;
    }
    if (psiElement instanceof JetProperty) {
      JetProperty property = (JetProperty) psiElement;
      return property.isVar() ? JetIcons.FIELD_VAR : JetIcons.FIELD_VAL;
    }

    return null;
  }