Class VisibilityChangePredicate

java.lang.Object
org.ek9lang.compiler.common.VisibilityChangePredicate

public final class VisibilityChangePredicate extends Object
Decides whether a member's visibility may legally be changed to a proposed access modifier - the "declaration viability" of a change_visibility refactoring.

Reuses MethodAccessModifierRules (the same rule core the compiler enforces in VisibilityOfOperationsOrError) so the predicate can never drift from what the compiler accepts, and layers on the rules that live in other phases: a no-op change, the fields/operators-have-no-modifier facts (grammar), and the override lock (E07010 forbids private; E05130 forces an override to match its parent's modifier - so an override's visibility cannot change at all).

Intended to be shared by the compiler-services MCP ek9_change_visibility tool and the IDE Refactor menu (which should not offer the option when it is not viable).

NOTE - this is purely structural. It does NOT check whether narrowing visibility would leave existing call sites unable to reach the member (E06180 NOT_ACCESSIBLE); that reference-graph "narrowing safety" check belongs to the tool's apply / dry-run path.

  • Constructor Details

    • VisibilityChangePredicate

      public VisibilityChangePredicate()
  • Method Details

    • canChangeTo

      public VisibilityChangeViability canChangeTo(ISymbol member, String targetAccessModifier)
      Parameters:
      member - the member whose visibility a change is proposed for
      targetAccessModifier - the proposed access modifier ("public" / "protected" / "private")
      Returns:
      whether the change is structurally possible, with a reason when not