Class CloseableResourceToBeChecked

java.lang.Object
org.ek9lang.compiler.common.CloseableResourceToBeChecked
All Implemented Interfaces:
Predicate<ISymbol>

public final class CloseableResourceToBeChecked extends Object implements Predicate<ISymbol>
Checks if a symbol should be tracked as a closeable resource. A closeable resource is a local variable whose type has a close() operator.
This predicate is used to identify variables that need to be tracked for resource leak detection. The rules are:
  • Must be a VariableSymbol (not a type or function)
  • Must not be a property field (fields are managed by the containing aggregate)
  • Must not be an incoming parameter (caller's responsibility)
  • Must not be a returning parameter (callee transfers ownership)
  • Type must have a close() operator with no parameters and no return
  • Type must NOT be Stdin, Stdout, or Stderr (these are global, never really closed)
  • Constructor Details

    • CloseableResourceToBeChecked

      public CloseableResourceToBeChecked(HasCloseOperator hasCloseOperator)
  • Method Details

    • isLocalVariable

      public static boolean isLocalVariable(ISymbol symbol)
      THE 'is this a local variable' for resource management: a variable that is not a property, not an incoming parameter and not the returning parameter. Asked by the phase-5 check that a closeable local is a try resource (E81056).
    • test

      public boolean test(ISymbol symbol)
      Specified by:
      test in interface Predicate<ISymbol>
    • isManagedCloseableType

      public boolean isManagedCloseableType(ISymbol type)
      THE 'is this a type whose values the compiler must see closed' predicate: an aggregate with a close operator that is not one of the global standard streams and not a bare type parameter. The phase-5 named-local rule (E81056) asks it of a variable's type; the phase-5 store rule (E81059) asks it of both a stored value's type and the declared type of the slot it is stored into; phase 7 asks it of an unnamed temporary's type to decide whether the statement that created it must close it. All ask HERE so the ownership rules cannot disagree about what is closeable.