示例#1
0
  private void checkClass(
      BodiesResolveContext c,
      JetClass aClass,
      ClassDescriptorWithResolutionScopes classDescriptor) {
    checkOpenMembers(classDescriptor);
    checkTypeParameters(aClass);

    if (aClass.isInterface()) {
      ASTNode traitKeyword = aClass.getNode().findChildByType(JetTokens.TRAIT_KEYWORD);
      if (traitKeyword != null) {
        trace.report(Errors.DEPRECATED_TRAIT_KEYWORD.on(traitKeyword.getPsi()));
      }

      checkTraitModifiers(aClass);
      checkConstructorInTrait(aClass);
    } else if (aClass.isAnnotation()) {
      checkAnnotationClassWithBody(aClass);
      checkValOnAnnotationParameter(aClass);
    } else if (aClass.isEnum()) {
      checkEnumModifiers(aClass);
      if (aClass.isLocal()) {
        trace.report(LOCAL_ENUM_NOT_ALLOWED.on(aClass, classDescriptor));
      }
    } else if (aClass.hasModifier(JetTokens.SEALED_KEYWORD)) {
      checkSealedModifiers(aClass);
    } else if (aClass instanceof JetEnumEntry) {
      checkEnumEntry((JetEnumEntry) aClass, classDescriptor);
    }
  }
 @NotNull
 private static ClassKind getClassKind(@NotNull JetClass jetClass) {
   if (jetClass.isTrait()) return ClassKind.TRAIT;
   if (jetClass.isAnnotation()) return ClassKind.ANNOTATION_CLASS;
   if (jetClass.isEnum()) return ClassKind.ENUM_CLASS;
   return ClassKind.CLASS;
 }
示例#3
0
 private void checkNestedClassAllowed(
     @NotNull JetModifierListOwner modifierListOwner,
     @NotNull DeclarationDescriptor descriptor) {
   if (modifierListOwner.hasModifier(INNER_KEYWORD)) return;
   if (modifierListOwner instanceof JetClass && !(modifierListOwner instanceof JetEnumEntry)) {
     JetClass aClass = (JetClass) modifierListOwner;
     boolean localEnumError = aClass.isLocal() && aClass.isEnum();
     if (!localEnumError && isIllegalNestedClass(descriptor)) {
       trace.report(NESTED_CLASS_NOT_ALLOWED.on(aClass));
     }
   }
 }
示例#4
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;
  }