Class MethodAccessModifierRules
This encodes exactly the genus-based visibility rules the compiler enforces in
VisibilityOfOperationsOrError (phase 2). It is deliberately a pure function over the
method's shape (genus, the candidate access modifier, override / open / constructor / operator
flags) so it can be reused by tooling WITHOUT dragging in error emission — most importantly by
the change_visibility viability predicate, which must decide whether a PROPOSED modifier
is legal, not just validate the one already written in source.
Rules covered (matching VisibilityOfOperationsOrError):
- COMPONENT method marked
protected→METHOD_MODIFIER_PROTECTED_IN_COMPONENT - SERVICE method marked
protected→METHOD_MODIFIER_PROTECTED_IN_SERVICE - CLASS_TRAIT method with any non-public modifier →
METHOD_MODIFIER_NOT_REQUIRED_IN_TRAIT - CLASS method marked
protectedwhen not an override AND the class is not open →METHOD_MODIFIER_PROTECTED_IN_CLOSED_CLASS - RECORD method that is neither a constructor nor an operator
→
RECORDS_ONLY_SUPPORT_CONSTRUCTOR_AND_OPERATOR_METHODS
Rules NOT covered here (enforced in other phases, layered on by the viability predicate):
the redundant explicit public (METHOD_ACCESS_MODIFIER_DEFAULT, phase 1),
override + private (METHOD_ACCESS_MODIFIER_PRIVATE_OVERRIDE, phase 1),
and an override having to match its parent's modifier
(METHOD_ACCESS_MODIFIERS_DIFFER, phase 3).
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvisibilityViolation(SymbolGenus genus, String accessModifier, boolean isOverride, boolean aggregateIsOpen, boolean isConstructor, boolean isOperator) Determine whether a method/operator/constructor of the given shape may carry the supplied access modifier within an aggregate of the given genus.
-
Constructor Details
-
MethodAccessModifierRules
public MethodAccessModifierRules()
-
-
Method Details
-
visibilityViolation
public Optional<ErrorListener.SemanticClassification> visibilityViolation(SymbolGenus genus, String accessModifier, boolean isOverride, boolean aggregateIsOpen, boolean isConstructor, boolean isOperator) Determine whether a method/operator/constructor of the given shape may carry the supplied access modifier within an aggregate of the given genus.- Parameters:
genus- the enclosing aggregate's genusaccessModifier- the candidate access modifier ("public" / "protected" / "private")isOverride- whether the method overrides an inherited methodaggregateIsOpen- whether the enclosing aggregate is open for extensionisConstructor- whether the method is a constructorisOperator- whether the method is an operator- Returns:
- the semantic violation if the modifier is illegal there, otherwise empty
-