From 0cbc32d4a03402130fb07bb23bbc68373bd28d5f Mon Sep 17 00:00:00 2001 From: Grigorii Kirgizov Date: Mon, 20 May 2019 19:00:34 +0300 Subject: [PATCH] Get rid off nullability of Justs --- .../src/jetbrains/mps/logic/reactor/core/Occurrence.kt | 10 +++++----- .../mps/logic/reactor/core/internal/ControllerImpl.kt | 2 +- .../logic/reactor/core/internal/StoreAwareJournal.kt | 6 ++---- .../logic/reactor/evaluation/ConstraintOccurrence.java | 4 ++-- 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/reactor/Core/src/jetbrains/mps/logic/reactor/core/Occurrence.kt b/reactor/Core/src/jetbrains/mps/logic/reactor/core/Occurrence.kt index c8222332..1e060e46 100644 --- a/reactor/Core/src/jetbrains/mps/logic/reactor/core/Occurrence.kt +++ b/reactor/Core/src/jetbrains/mps/logic/reactor/core/Occurrence.kt @@ -39,7 +39,7 @@ data class Occurrence (val controller: Controller, val constraint: Constraint, val logicalContext: LogicalContext, val arguments: List<*>, - val justifications: Justs?): + val justifications: Justs): ConstraintOccurrence, LogicalObserver { @@ -58,7 +58,7 @@ data class Occurrence (val controller: Controller, override fun logicalContext(): LogicalContext = logicalContext - override fun justifications(): Justs? = justifications + override fun justifications(): Justs = justifications override fun valueUpdated(logical: Logical<*>) { if (alive) { @@ -96,18 +96,18 @@ data class Occurrence (val controller: Controller, fun Constraint.occurrence(controller: Controller, arguments: List<*>, - justifications: Justs?, + justifications: Justs, logicalContext: LogicalContext): Occurrence = Occurrence(controller, this, logicalContext, arguments, justifications) fun Constraint.occurrence(controller: Controller, arguments: List<*>, - justifications: Justs?): Occurrence = + justifications: Justs): Occurrence = Occurrence(controller, this, noLogicalContext, arguments, justifications) fun Constraint.occurrence(controller: Controller, arguments: List<*>): Occurrence = - Occurrence(controller, this, noLogicalContext, arguments, null) + Occurrence(controller, this, noLogicalContext, arguments, justsOf()) private val noLogicalContext: LogicalContext = object: LogicalContext { override fun variable(metaLogical: MetaLogical): Logical? = null diff --git a/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/ControllerImpl.kt b/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/ControllerImpl.kt index 6d1455f5..3bd3a000 100644 --- a/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/ControllerImpl.kt +++ b/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/ControllerImpl.kt @@ -191,7 +191,7 @@ internal class ControllerImpl ( val args = supervisor.instantiateArguments(constraint.arguments(), context.logicalContext, context) return context.eval { status -> - state.processActivated(constraint.occurrence(this, args, null, context.logicalContext), status) + state.processActivated(constraint.occurrence(this, args, justsOf(), context.logicalContext), status) } } diff --git a/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/StoreAwareJournal.kt b/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/StoreAwareJournal.kt index f1c03e37..5aa7c30c 100644 --- a/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/StoreAwareJournal.kt +++ b/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/StoreAwareJournal.kt @@ -120,7 +120,6 @@ internal open class MatchJournalImpl(view: MatchJournal.View?): MatchJournal { // Log discards match.forEachReplaced {occ -> - // this.dispatchFringe = dispatchFringe.contract(occ) current.occurrences.add(MatchJournal.Chunk.Entry(occ, true)) occ.terminate() } @@ -241,9 +240,8 @@ internal class StoreAwareJournalImpl(val state: ProcessingStateImpl, view: Match private fun RuleMatch.headJustifications(): Justs { val res: Justs = justsOf() - this.matchHeadKept().forEach { it.justifications()?.let { res.addAll(it) } } - this.matchHeadReplaced().forEach { it.justifications()?.let { res.addAll(it) } } + this.matchHeadKept().forEach { it.justifications().let { res.addAll(it) } } + this.matchHeadReplaced().forEach { it.justifications().let { res.addAll(it) } } return res -// return if (res.isEmpty) null else res } diff --git a/reactor/Core/src/jetbrains/mps/logic/reactor/evaluation/ConstraintOccurrence.java b/reactor/Core/src/jetbrains/mps/logic/reactor/evaluation/ConstraintOccurrence.java index cf614d34..e499f32c 100644 --- a/reactor/Core/src/jetbrains/mps/logic/reactor/evaluation/ConstraintOccurrence.java +++ b/reactor/Core/src/jetbrains/mps/logic/reactor/evaluation/ConstraintOccurrence.java @@ -20,7 +20,7 @@ package jetbrains.mps.logic.reactor.evaluation; import gnu.trove.set.TIntSet; import jetbrains.mps.logic.reactor.logical.LogicalContext; import jetbrains.mps.logic.reactor.program.Constraint; -import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.NotNull; import java.util.List; @@ -37,7 +37,7 @@ public interface ConstraintOccurrence { LogicalContext logicalContext(); - @Nullable + @NotNull TIntSet justifications(); }