Esempio n. 1
0
  @NotNull
  public static Modality resolveModalityFromModifiers(
      @Nullable JetModifierList modifierList, @NotNull Modality defaultModality) {
    if (modifierList == null) return defaultModality;
    boolean hasAbstractModifier = modifierList.hasModifier(ABSTRACT_KEYWORD);
    boolean hasOverrideModifier = modifierList.hasModifier(OVERRIDE_KEYWORD);

    if (modifierList.hasModifier(SEALED_KEYWORD)) {
      return Modality.SEALED;
    }
    if (modifierList.hasModifier(OPEN_KEYWORD)) {
      if (hasAbstractModifier || defaultModality == Modality.ABSTRACT) {
        return Modality.ABSTRACT;
      }
      return Modality.OPEN;
    }
    if (hasAbstractModifier) {
      return Modality.ABSTRACT;
    }
    boolean hasFinalModifier = modifierList.hasModifier(FINAL_KEYWORD);
    if (hasOverrideModifier && !hasFinalModifier && !(defaultModality == Modality.ABSTRACT)) {
      return Modality.OPEN;
    }
    if (hasFinalModifier) {
      return Modality.FINAL;
    }
    return defaultModality;
  }
Esempio n. 2
0
 public static Visibility resolveVisibilityFromModifiers(
     @Nullable JetModifierList modifierList, @NotNull Visibility defaultVisibility) {
   if (modifierList == null) return defaultVisibility;
   if (modifierList.hasModifier(PRIVATE_KEYWORD)) return Visibilities.PRIVATE;
   if (modifierList.hasModifier(PUBLIC_KEYWORD)) return Visibilities.PUBLIC;
   if (modifierList.hasModifier(PROTECTED_KEYWORD)) return Visibilities.PROTECTED;
   if (modifierList.hasModifier(INTERNAL_KEYWORD)) return Visibilities.INTERNAL;
   return defaultVisibility;
 }
Esempio n. 3
0
 private void checkTraitModifiers(JetClass aClass) {
   reportErrorIfHasIllegalModifier(aClass);
   JetModifierList modifierList = aClass.getModifierList();
   if (modifierList == null) return;
   if (modifierList.hasModifier(JetTokens.FINAL_KEYWORD)) {
     trace.report(Errors.TRAIT_CAN_NOT_BE_FINAL.on(aClass));
   }
   if (modifierList.hasModifier(JetTokens.SEALED_KEYWORD)) {
     trace.report(Errors.TRAIT_CAN_NOT_BE_SEALED.on(aClass));
   }
   if (modifierList.hasModifier(JetTokens.ABSTRACT_KEYWORD)) {
     trace.report(Errors.ABSTRACT_MODIFIER_IN_TRAIT.on(aClass));
   }
   if (modifierList.hasModifier(JetTokens.OPEN_KEYWORD)) {
     trace.report(Errors.OPEN_MODIFIER_IN_TRAIT.on(aClass));
   }
 }
Esempio n. 4
0
 @NotNull
 public Map<JetModifierKeywordToken, PsiElement> getTokensCorrespondingToModifiers(
     @NotNull JetModifierList modifierList,
     @NotNull Collection<JetModifierKeywordToken> possibleModifiers) {
   Map<JetModifierKeywordToken, PsiElement> tokens = Maps.newHashMap();
   for (JetModifierKeywordToken modifier : possibleModifiers) {
     if (modifierList.hasModifier(modifier)) {
       tokens.put(modifier, modifierList.getModifier(modifier));
     }
   }
   return tokens;
 }
Esempio n. 5
0
 public static boolean isInnerClass(@Nullable JetModifierList modifierList) {
   return modifierList != null && modifierList.hasModifier(INNER_KEYWORD);
 }