From 924849bd8b5c8d6d55f502cc3f47648f9b6ce930 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Wed, 6 Sep 2017 22:03:54 -0700 Subject: [PATCH] Make reloads go through the Abacus core. --- .../main/java/org/nwapw/abacus/plugin/Plugin.java | 8 -------- .../java/org/nwapw/abacus/plugin/PluginManager.java | 9 +-------- core/src/main/kotlin/org/nwapw/abacus/Abacus.kt | 13 ++++++++----- .../org/nwapw/abacus/tests/CalculationTests.java | 2 +- .../java/org/nwapw/abacus/tests/TokenizerTests.java | 2 +- .../java/org/nwapw/abacus/fx/AbacusController.java | 4 ++-- 6 files changed, 13 insertions(+), 25 deletions(-) diff --git a/core/src/main/java/org/nwapw/abacus/plugin/Plugin.java b/core/src/main/java/org/nwapw/abacus/plugin/Plugin.java index ecec78a..2481ac4 100644 --- a/core/src/main/java/org/nwapw/abacus/plugin/Plugin.java +++ b/core/src/main/java/org/nwapw/abacus/plugin/Plugin.java @@ -220,12 +220,4 @@ public abstract class Plugin { */ public abstract void onDisable(); - /** - * Get the variable database. - * @return the variable database. - */ - public final VariableDatabase getVariableDatabase(){ - return manager.getVariableDatabase(); - } - } diff --git a/core/src/main/java/org/nwapw/abacus/plugin/PluginManager.java b/core/src/main/java/org/nwapw/abacus/plugin/PluginManager.java index 9f7e0ab..64b87c1 100644 --- a/core/src/main/java/org/nwapw/abacus/plugin/PluginManager.java +++ b/core/src/main/java/org/nwapw/abacus/plugin/PluginManager.java @@ -422,12 +422,5 @@ public class PluginManager { public Set> getLoadedPluginClasses() { return loadedPluginClasses; } - - /** - * Gets the variable database. - * @return the database. - */ - public VariableDatabase getVariableDatabase(){ - return abacus.getVariableDatabase(); - } + } diff --git a/core/src/main/kotlin/org/nwapw/abacus/Abacus.kt b/core/src/main/kotlin/org/nwapw/abacus/Abacus.kt index d123ee4..b2fbfa5 100644 --- a/core/src/main/kotlin/org/nwapw/abacus/Abacus.kt +++ b/core/src/main/kotlin/org/nwapw/abacus/Abacus.kt @@ -46,10 +46,6 @@ class Abacus(val configuration: Configuration) { * The promotion manager used to convert between number implementations. */ val promotionManager = PromotionManager(this) - /** - * The database of variable definitions. - */ - val variableDatabase = VariableDatabase(this) /** * The hidden, mutable implementation of the context. @@ -65,9 +61,16 @@ class Abacus(val configuration: Configuration) { pluginManager.addListener(tokenizer) pluginManager.addListener(parser) pluginManager.addListener(promotionManager) - pluginManager.addListener(variableDatabase) } + fun reload(){ + pluginManager.reload() + with(mutableContext) { + numberImplementation = pluginManager.numberImplementationFor(configuration.numberImplementation) + clearVariables() + clearDefinitions() + } + } /** * Parses a string into a tree structure using the main * tree builder. diff --git a/core/src/test/java/org/nwapw/abacus/tests/CalculationTests.java b/core/src/test/java/org/nwapw/abacus/tests/CalculationTests.java index 39cf091..1818090 100755 --- a/core/src/test/java/org/nwapw/abacus/tests/CalculationTests.java +++ b/core/src/test/java/org/nwapw/abacus/tests/CalculationTests.java @@ -17,7 +17,7 @@ public class CalculationTests { @BeforeClass public static void prepareTests() { abacus.getPluginManager().addInstantiated(new StandardPlugin(abacus.getPluginManager())); - abacus.getPluginManager().load(); + abacus.reload(); } private void testOutput(String input, String parseOutput, String output) { diff --git a/core/src/test/java/org/nwapw/abacus/tests/TokenizerTests.java b/core/src/test/java/org/nwapw/abacus/tests/TokenizerTests.java index 5ef7f2f..90272c4 100644 --- a/core/src/test/java/org/nwapw/abacus/tests/TokenizerTests.java +++ b/core/src/test/java/org/nwapw/abacus/tests/TokenizerTests.java @@ -82,7 +82,7 @@ public class TokenizerTests { public static void prepareTests() { abacus.getPluginManager().addListener(lexerTokenizer); abacus.getPluginManager().addInstantiated(testPlugin); - abacus.getPluginManager().load(); + abacus.reload(); } @Test diff --git a/fx/src/main/java/org/nwapw/abacus/fx/AbacusController.java b/fx/src/main/java/org/nwapw/abacus/fx/AbacusController.java index 8b05f3f..74527a1 100644 --- a/fx/src/main/java/org/nwapw/abacus/fx/AbacusController.java +++ b/fx/src/main/java/org/nwapw/abacus/fx/AbacusController.java @@ -320,13 +320,13 @@ public class AbacusController implements PluginListener { } catch (IOException | ClassNotFoundException e) { e.printStackTrace(); } - abacusPluginManager.reload(); + abacus.reload(); } @FXML public void performReload() { alertIfApplyNeeded(true); - abacus.getPluginManager().reload(); + abacus.reload(); } @FXML