Class JustificationModel<E extends JustificationElement>

java.lang.Object
ca.mcscert.jpipe.model.JustificationModel<E>
Direct Known Subclasses:
Justification, Template

public abstract sealed class JustificationModel<E extends JustificationElement> extends Object permits Justification, Template
Abstract base for all named justification models. Sealed to exactly two subtypes: Justification (concrete) and Template (abstract/reusable).

The type parameter E constrains which elements can be added: Justification accepts only CommonElement, while Template accepts any JustificationElement including AbstractSupport.

Every model has exactly one Conclusion, set via setConclusion(Conclusion) and accessed via conclusion(). Passing a Conclusion to addElement(JustificationElement) is rejected.

Use validate() to check consistency and completeness. For location-aware diagnostics in a compiler pipeline use ConsistencyValidator and CompletenessValidator directly.

  • Constructor Details

    • JustificationModel

      protected JustificationModel(String name)
  • Method Details

    • getName

      public String getName()
    • setConclusion

      public void setConclusion(Conclusion conclusion)
      Sets the single required conclusion. Throws IllegalStateException if a conclusion has already been assigned.
    • conclusion

      public Optional<Conclusion> conclusion()
      Returns the conclusion, if one has been set.
    • getParent

      public Optional<Template> getParent()
    • setParent

      protected void setParent(Template parent)
    • addElement

      public void addElement(E element)
      Rejects Conclusion — use setConclusion(Conclusion) instead.
    • inline

      public void inline(Template template, String templateName)
      Inlines template into this model: each template element is copied with a qualified id (templateName:originalId) and support edges between copied elements are re-wired. The model becomes self-contained — operators can mutate it freely without affecting the original template.

      Whether a copy is added is controlled by includeInExpansion(JustificationElement): Justification excludes AbstractSupport copies (type constraint; abstract supports must be overridden by concrete elements); Template includes everything.

      The template's conclusion is always copied as a Conclusion, maintaining its top-level status. If this model already has a conclusion, the template's conclusion is mapped to it for edge re-wiring but not added as a second conclusion.

    • includeInExpansion

      protected abstract boolean includeInExpansion(JustificationElement copy)
      Returns true if the given element copy should be added to this model during template expansion. Justification returns false for AbstractSupport; Template returns true for all elements.
    • validate

      public List<Violation> validate()
      Validates this model for consistency and completeness without requiring a Unit. Useful for non-compiler consumers that build models programmatically.

      All violations carry SourceLocation.UNKNOWN because source location data is only available when building through the compiler pipeline (see ConsistencyValidator and CompletenessValidator).

      Returns:
      unmodifiable list of violations; empty means valid.
    • removeElement

      public void removeElement(String id)
      Removes the element with the given id from the elements list.
    • getElements

      public List<E> getElements()
    • hasOwnConclusion

      public boolean hasOwnConclusion()
      Returns true when the conclusion was defined directly in this model, i.e. it was not inherited from a parent template via inline(Template, String). Returns false when there is no conclusion yet or when the conclusion was set by inlining a parent template.
    • ownElements

      public List<E> ownElements()
      Elements defined directly in this model — their id has no counterpart in any ancestor template.
    • inheritedElements

      public List<E> inheritedElements()
      Elements copied from an ancestor template whose runtime type is unchanged (not overridden).
    • concreteOverrides

      public List<E> concreteOverrides()
      Elements that replaced an ancestor's AbstractSupport placeholder — same qualified id, but a concrete type (e.g. Evidence or SubConclusion).

      Together with ownElements() and inheritedElements(), these three lists partition getElements().

    • findById

      public Optional<JustificationElement> findById(String id)
      Searches both the conclusion field and the elements list, so callers do not need to know how the conclusion is stored.
    • elementsOfType

      public <T extends JustificationElement> List<T> elementsOfType(Class<T> type)
    • subConclusions

      public List<SubConclusion> subConclusions()
    • strategies

      public List<Strategy> strategies()
    • evidence

      public List<Evidence> evidence()
    • accept

      public final <R> R accept(JustificationVisitor<R> visitor)
    • visitSelf

      protected abstract <R> R visitSelf(JustificationVisitor<R> visitor)
    • plainId

      protected static String plainId(String id)
      Returns the last colon-separated segment of a qualified id.
    • qualifiedCopy

      protected static JustificationElement qualifiedCopy(JustificationElement elem, String prefix)
      Creates a copy of elem. If the element's id is already qualified (contains :), the id is preserved as-is — it was inherited from a grandparent template and must not be double-qualified. Plain ids are prefixed with prefix:.