Interface LoadingStrategy

All Known Implementing Classes:
EagerLoadingStrategy, OnDemandLoadingStrategy

public interface LoadingStrategy
Determines how a JavaView resolves its classes: on demand (lazily, on first lookup) or eagerly (all at once, at construction time). Injected into JavaView's constructor, mirroring how a ClassCacheProvider supplies the view's ClassCache.

Implementations live in sootup.java.core.views, the same package as JavaView, because resolveOnCacheMiss(sootup.java.core.views.JavaView, sootup.core.types.ClassType) and the default initialize(sootup.java.core.views.JavaView) need to call JavaView's protected getClassSource/buildClassFrom/ inputLocations through a JavaView-typed parameter - which only compiles for same-package callers, not arbitrary subclasses (JLS 6.6.2).

  • Method Details

    • onDemand

      static @NonNull LoadingStrategy onDemand()
    • eager

      static @NonNull LoadingStrategy eager()
    • initialize

      default void initialize(@NonNull JavaView view)
      Called exactly once, as the last statement of JavaView's constructor, after all of JavaView's own fields (inputLocations, cache, loadingStrategy, identifierFactory) have been assigned. The default does nothing; only the eager strategy overrides this to resolve every class up front.

      Because this runs before any subclass's own constructor body, any virtual call this makes on view must not depend on subclass fields that a subclass constructor would otherwise have initialized first. Do not wire the eager strategy into a JavaView subclass that overrides getClasses() or buildClassFrom(...) without re-checking this.

    • resolveOnCacheMiss

      @NonNull Optional<JavaSootClass> resolveOnCacheMiss(@NonNull JavaView view, @NonNull ClassType type)
      Called from JavaView.getClass(ClassType) after a cache miss, while holding the owning view's monitor. Returns the resolved class, or Optional.empty() if type cannot be resolved.
    • makeAvailable

      default void makeAvailable(@NonNull ClassType type)
      Called from JavaView.forgetAbsence(ClassType), itself called e.g. when MutableJavaView.addClass(sootup.java.core.JavaSootClass) makes a previously-absent type available. The default does nothing, which is correct for the eager strategy: it tracks no absence state to forget, since a class absent after an eager load can never become present.