@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; }
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; }
@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; }
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)); } }
@Override public void invoke(@NotNull Project project, Editor editor, @NotNull JetFile file) throws IncorrectOperationException { JetPsiFactory factory = new JetPsiFactory(annotationClass.getProject()); JetModifierList list = annotationClass.getModifierList(); String annotation = KotlinBuiltIns.FQ_NAMES.annotation.shortName().asString(); PsiElement added; if (list == null) { JetModifierList newModifierList = factory.createModifierList(annotation); added = annotationClass.addBefore(newModifierList, annotationClass.getClassOrInterfaceKeyword()); } else { JetAnnotationEntry entry = factory.createAnnotationEntry(annotation); added = list.addBefore(entry, list.getFirstChild()); } annotationClass.addAfter(factory.createWhiteSpace(), added); }
private void checkModifiersAndAnnotationsInPackageDirective(JetFile file) { JetPackageDirective packageDirective = file.getPackageDirective(); if (packageDirective == null) return; JetModifierList modifierList = packageDirective.getModifierList(); if (modifierList == null) return; for (JetAnnotationEntry annotationEntry : modifierList.getAnnotationEntries()) { JetConstructorCalleeExpression calleeExpression = annotationEntry.getCalleeExpression(); if (calleeExpression != null) { JetReferenceExpression reference = calleeExpression.getConstructorReferenceExpression(); if (reference != null) { trace.report(UNRESOLVED_REFERENCE.on(reference, reference)); } } } AnnotationTargetChecker.INSTANCE$.check(packageDirective, trace); ModifiersChecker.reportIllegalModifiers( modifierList, Arrays.asList(JetTokens.MODIFIER_KEYWORDS_ARRAY), trace); }
private void checkPropertyAbstractness( @NotNull JetProperty property, @NotNull PropertyDescriptor propertyDescriptor, @NotNull ClassDescriptor classDescriptor) { JetPropertyAccessor getter = property.getGetter(); JetPropertyAccessor setter = property.getSetter(); JetModifierList modifierList = property.getModifierList(); ASTNode abstractNode = modifierList != null ? modifierList.getModifierNode(JetTokens.ABSTRACT_KEYWORD) : null; if (abstractNode != null) { // has abstract modifier if (!classCanHaveAbstractMembers(classDescriptor)) { String name = property.getName(); trace.report( ABSTRACT_PROPERTY_IN_NON_ABSTRACT_CLASS.on( property, name != null ? name : "", classDescriptor)); return; } if (classDescriptor.getKind() == ClassKind.INTERFACE) { trace.report(ABSTRACT_MODIFIER_IN_TRAIT.on(property)); } } if (propertyDescriptor.getModality() == Modality.ABSTRACT) { JetExpression initializer = property.getInitializer(); if (initializer != null) { trace.report(ABSTRACT_PROPERTY_WITH_INITIALIZER.on(initializer)); } JetPropertyDelegate delegate = property.getDelegate(); if (delegate != null) { trace.report(ABSTRACT_DELEGATED_PROPERTY.on(delegate)); } if (getter != null && getter.hasBody()) { trace.report(ABSTRACT_PROPERTY_WITH_GETTER.on(getter)); } if (setter != null && setter.hasBody()) { trace.report(ABSTRACT_PROPERTY_WITH_SETTER.on(setter)); } } }
public static boolean isInnerClass(@Nullable JetModifierList modifierList) { return modifierList != null && modifierList.hasModifier(INNER_KEYWORD); }