From 14550b58fbde019192c75f8426286deda73e3282 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Fuch=C3=9F?= Date: Wed, 23 Aug 2023 12:17:09 +0200 Subject: [PATCH] Configurable redesign (#261) * Configurable redesign * Remove code duplicates by introducing ChildClassConfigurable * Apply review comments --- .../configuration/AbstractConfigurable.java | 52 ++++++++++++------- .../configuration/ChildClassConfigurable.java | 18 +++++++ .../core/configuration/NoConfiguration.java | 18 +++++++ .../core/pipeline/AbstractExecutionStage.java | 39 ++++++++++---- .../core/pipeline/agent/PipelineAgent.java | 34 ++++++++---- .../core/execution/ConfigurationHelper.java | 2 +- .../execution/ConfigurationHelperTest.java | 49 +++++++++++++++++ .../SadCodeTraceabilityLinkRecovery.java | 29 +---------- .../SadSamCodeTraceabilityLinkRecovery.java | 28 +--------- .../SamCodeTraceabilityLinkRecovery.java | 29 +---------- ...tectureLinkToCodeLinkTransformerAgent.java | 26 +--------- .../agents/InitialCodeTraceabilityAgent.java | 25 +-------- .../agents/TransitiveTraceabilityAgent.java | 26 +--------- .../ConnectionGenerator.java | 32 +----------- .../agents/InitialConnectionAgent.java | 23 +------- .../agents/InstanceConnectionAgent.java | 22 +------- .../agents/ProjectNameFilterAgent.java | 22 +------- .../agents/ReferenceAgent.java | 23 +------- .../mcse/ardoco/lissa/DiagramRecognition.kt | 27 +--------- .../agents/DiagramRecognitionAgent.kt | 27 +++------- .../inconsistency/InconsistencyChecker.java | 31 +---------- .../agents/InitialInconsistencyAgent.java | 26 +--------- ...MissingModelElementInconsistencyAgent.java | 25 +-------- ...umentedModelElementInconsistencyAgent.java | 24 +-------- .../core/models/ArCoTLModelProviderAgent.java | 18 ++----- .../core/models/ModelProviderAgent.java | 30 +++-------- .../RecommendationGenerator.java | 33 ++---------- .../agents/InitialRecommendationAgent.java | 23 +------- .../agents/PhraseRecommendationAgent.java | 23 +------- .../core/textextraction/TextExtraction.java | 31 +---------- .../agents/InitialTextAgent.java | 24 +-------- .../agents/MappingCombiner.java | 24 +-------- .../textextraction/agents/PhraseAgent.java | 23 +------- .../providers/TextPreprocessingAgent.java | 22 +------- .../tests/eval/ConfigurationTestBase.java | 2 +- .../eval/baseline/InconsistencyBaseline.java | 8 +-- .../baseline/InconsistencyBaselineAgent.java | 9 +--- 37 files changed, 231 insertions(+), 696 deletions(-) create mode 100644 framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/configuration/ChildClassConfigurable.java create mode 100644 framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/configuration/NoConfiguration.java diff --git a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/configuration/AbstractConfigurable.java b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/configuration/AbstractConfigurable.java index 1e4abc67a..84086688f 100644 --- a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/configuration/AbstractConfigurable.java +++ b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/configuration/AbstractConfigurable.java @@ -25,21 +25,9 @@ public abstract class AbstractConfigurable implements IConfigurable { private SortedMap lastAppliedConfiguration = new TreeMap<>(); - protected final List findByClassName(List selected, List instances) { - List target = new ArrayList<>(0); - for (var clazz : selected) { - var elem = instances.stream() - .filter(e -> e.getClass().getSimpleName().equals(clazz)) - .findFirst() - .orElseThrow(() -> new IllegalArgumentException("Could not find " + clazz)); - target.add(elem); - } - return target; - } - @Override public final void applyConfiguration(SortedMap additionalConfiguration) { - applyConfiguration(additionalConfiguration, this.getClass()); + applyConfiguration(additionalConfiguration, this, this.getClass()); delegateApplyConfigurationToInternalObjects(additionalConfiguration); this.lastAppliedConfiguration = new TreeMap<>(additionalConfiguration); } @@ -51,23 +39,49 @@ public SortedMap getLastAppliedConfiguration() { protected abstract void delegateApplyConfigurationToInternalObjects(SortedMap additionalConfiguration); - private void applyConfiguration(SortedMap additionalConfiguration, Class currentClass) { - if (currentClass == Object.class || currentClass == AbstractConfigurable.class) + private void applyConfiguration(SortedMap additionalConfiguration, AbstractConfigurable configurable, Class currentClassInHierarchy) { + if (currentClassInHierarchy == Object.class || currentClassInHierarchy == AbstractConfigurable.class) return; - var fields = currentClass.getDeclaredFields(); + if (currentClassInHierarchy.getAnnotation(NoConfiguration.class) != null) { + logger.debug("Skipping configuration for class {}", currentClassInHierarchy.getSimpleName()); + return; + } + + var fields = currentClassInHierarchy.getDeclaredFields(); for (Field field : fields) { if (!field.isAnnotationPresent(Configurable.class)) { continue; } - Configurable c = field.getAnnotation(Configurable.class); - String key = c.key().isBlank() ? (currentClass.getSimpleName() + CLASS_ATTRIBUTE_CONNECTOR + field.getName()) : c.key(); + String key = getKeyOfField(configurable, currentClassInHierarchy, field); if (additionalConfiguration.containsKey(key)) { setValue(field, additionalConfiguration.get(key)); } } - applyConfiguration(additionalConfiguration, currentClass.getSuperclass()); + applyConfiguration(additionalConfiguration, configurable, currentClassInHierarchy.getSuperclass()); + } + + /** + * Returns the key (for the configuration file) of a field. If the field is marked as ChildClassConfigurable, the key is based on the class of the + * configurable object. Otherwise, the key is based on the class where the field is defined. + * + * @param configurable the configurable object + * @param currentClassInHierarchy the class where the field is defined + * @param field the field + * @return the key of the field + */ + public static String getKeyOfField(AbstractConfigurable configurable, Class currentClassInHierarchy, Field field) { + Configurable configurableAnnotation = field.getAnnotation(Configurable.class); + ChildClassConfigurable childClassConfigurableAnnotation = field.getAnnotation(ChildClassConfigurable.class); + + if (childClassConfigurableAnnotation != null && !configurableAnnotation.key().isBlank()) { + throw new IllegalStateException("You cannot define a key for a field that is marked as ChildClassConfigurable."); + } + + String classOfDefinition = childClassConfigurableAnnotation == null ? currentClassInHierarchy.getSimpleName() : configurable.getClass().getSimpleName(); + + return configurableAnnotation.key().isBlank() ? (classOfDefinition + CLASS_ATTRIBUTE_CONNECTOR + field.getName()) : configurableAnnotation.key(); } private void setValue(Field field, String value) { diff --git a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/configuration/ChildClassConfigurable.java b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/configuration/ChildClassConfigurable.java new file mode 100644 index 000000000..be62da2e0 --- /dev/null +++ b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/configuration/ChildClassConfigurable.java @@ -0,0 +1,18 @@ +/* Licensed under MIT 2023. */ +package edu.kit.kastel.mcse.ardoco.core.configuration; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * This annotation marks a field that is configurable as configured by child class. That means that the key that is used to configure the field is based on the + * actual class (not on the class where the configurable field is defined). + */ +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Target(ElementType.FIELD) +public @interface ChildClassConfigurable { +} diff --git a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/configuration/NoConfiguration.java b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/configuration/NoConfiguration.java new file mode 100644 index 000000000..cc6309883 --- /dev/null +++ b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/configuration/NoConfiguration.java @@ -0,0 +1,18 @@ +/* Licensed under MIT 2023. */ +package edu.kit.kastel.mcse.ardoco.core.configuration; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * This annotation is used to mark classes that should not be configured. This means that the fields of the class will not be modified. The cascade + * configuration will be applied to the fields of the class. + */ +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Target(ElementType.TYPE) +public @interface NoConfiguration { +} diff --git a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/pipeline/AbstractExecutionStage.java b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/pipeline/AbstractExecutionStage.java index c5a0d1d76..6bad5b494 100644 --- a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/pipeline/AbstractExecutionStage.java +++ b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/pipeline/AbstractExecutionStage.java @@ -2,7 +2,13 @@ package edu.kit.kastel.mcse.ardoco.core.pipeline; import java.util.List; +import java.util.SortedMap; +import org.eclipse.collections.api.factory.Lists; +import org.eclipse.collections.api.list.MutableList; + +import edu.kit.kastel.mcse.ardoco.core.configuration.ChildClassConfigurable; +import edu.kit.kastel.mcse.ardoco.core.configuration.Configurable; import edu.kit.kastel.mcse.ardoco.core.data.DataRepository; import edu.kit.kastel.mcse.ardoco.core.pipeline.agent.PipelineAgent; @@ -11,18 +17,26 @@ * Inconsistency-Checker. *

* Implementing classes need to implement {@link #initializeState()} that cares for setting up the state for processing. - * Additionally, implementing classes need to implement {@link #getEnabledAgents()} that returns the listof enabled {@link PipelineAgent pipeline agents} */ public abstract class AbstractExecutionStage extends Pipeline { + private final MutableList agents; + + @Configurable + @ChildClassConfigurable + private List enabledAgents; + /** * Constructor for ExecutionStages - * + * + * @param agents the agents that could be executed by this pipeline * @param id the id of the stage * @param dataRepository the {@link DataRepository} that should be used */ - protected AbstractExecutionStage(String id, DataRepository dataRepository) { + protected AbstractExecutionStage(List agents, String id, DataRepository dataRepository) { super(id, dataRepository); + this.agents = Lists.mutable.withAll(agents); + this.enabledAgents = this.agents.collect(PipelineAgent::getId); } @Override @@ -37,8 +51,10 @@ protected final void preparePipelineSteps() { protected final void initialize() { initializeState(); - for (var agent : getEnabledAgents()) { - this.addPipelineStep(agent); + for (var agent : agents) { + if (enabledAgents.contains(agent.getId())) { + this.addPipelineStep(agent); + } } } @@ -47,10 +63,11 @@ protected final void initialize() { */ protected abstract void initializeState(); - /** - * Return the enabled {@link PipelineAgent agents} - * - * @return the list of agents - */ - protected abstract List getEnabledAgents(); + @Override + protected void delegateApplyConfigurationToInternalObjects(SortedMap additionalConfiguration) { + super.delegateApplyConfigurationToInternalObjects(additionalConfiguration); + for (var agent : agents) { + agent.applyConfiguration(additionalConfiguration); + } + } } diff --git a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/pipeline/agent/PipelineAgent.java b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/pipeline/agent/PipelineAgent.java index 1112efa52..ac07b081d 100644 --- a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/pipeline/agent/PipelineAgent.java +++ b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/pipeline/agent/PipelineAgent.java @@ -1,8 +1,12 @@ /* Licensed under MIT 2022-2023. */ package edu.kit.kastel.mcse.ardoco.core.pipeline.agent; +import java.util.ArrayList; import java.util.List; +import java.util.SortedMap; +import edu.kit.kastel.mcse.ardoco.core.configuration.ChildClassConfigurable; +import edu.kit.kastel.mcse.ardoco.core.configuration.Configurable; import edu.kit.kastel.mcse.ardoco.core.data.DataRepository; import edu.kit.kastel.mcse.ardoco.core.pipeline.AbstractExecutionStage; import edu.kit.kastel.mcse.ardoco.core.pipeline.Pipeline; @@ -11,13 +15,21 @@ * This class represents a pipeline agent that calculates some results for an {@link AbstractExecutionStage} execution * stage}. * - * Implementing classes need to override {@link #getEnabledPipelineSteps()}. + * Implementing classes need to override. * Additionally, sub-classes are free to override {@link #initializeState()} to execute code at the beginning of the initialization before the main processing. */ public abstract class PipelineAgent extends Pipeline implements Agent { - protected PipelineAgent(String id, DataRepository dataRepository) { + private final List informants; + + @Configurable + @ChildClassConfigurable + private List enabledInformants; + + protected PipelineAgent(List informants, String id, DataRepository dataRepository) { super(id, dataRepository); + this.informants = new ArrayList<>(informants); + this.enabledInformants = informants.stream().map(Informant::getId).toList(); } @Override @@ -31,8 +43,10 @@ protected final void preparePipelineSteps() { */ protected final void initialize() { initializeState(); - for (var informant : getEnabledPipelineSteps()) { - this.addPipelineStep(informant); + for (var informant : informants) { + if (enabledInformants.contains(informant.getId())) { + this.addPipelineStep(informant); + } } } @@ -43,10 +57,10 @@ protected void initializeState() { // do nothing here } - /** - * Return the enabled pipeline steps (informants) - * - * @return the list of Informants - */ - protected abstract List getEnabledPipelineSteps(); + @Override + protected void delegateApplyConfigurationToInternalObjects(SortedMap additionalConfiguration) { + super.delegateApplyConfigurationToInternalObjects(additionalConfiguration); + informants.forEach(filter -> filter.applyConfiguration(additionalConfiguration)); + } + } diff --git a/pipeline/pipeline-core/src/main/java/edu/kit/kastel/mcse/ardoco/core/execution/ConfigurationHelper.java b/pipeline/pipeline-core/src/main/java/edu/kit/kastel/mcse/ardoco/core/execution/ConfigurationHelper.java index 44fae55d4..c439f925a 100644 --- a/pipeline/pipeline-core/src/main/java/edu/kit/kastel/mcse/ardoco/core/execution/ConfigurationHelper.java +++ b/pipeline/pipeline-core/src/main/java/edu/kit/kastel/mcse/ardoco/core/execution/ConfigurationHelper.java @@ -100,7 +100,7 @@ protected static void processConfigurationOfClass(Map configs, C private static void fillConfigs(AbstractConfigurable object, List fields, Map configs) throws IllegalAccessException { for (Field f : fields) { f.setAccessible(true); - var key = f.getDeclaringClass().getSimpleName() + AbstractConfigurable.CLASS_ATTRIBUTE_CONNECTOR + f.getName(); + var key = AbstractConfigurable.getKeyOfField(object, f.getDeclaringClass(), f); var rawValue = f.get(object); var value = getValue(rawValue); if (configs.containsKey(key)) { diff --git a/pipeline/pipeline-core/src/test/java/edu/kit/kastel/mcse/ardoco/core/execution/ConfigurationHelperTest.java b/pipeline/pipeline-core/src/test/java/edu/kit/kastel/mcse/ardoco/core/execution/ConfigurationHelperTest.java index 146220703..297713a1e 100644 --- a/pipeline/pipeline-core/src/test/java/edu/kit/kastel/mcse/ardoco/core/execution/ConfigurationHelperTest.java +++ b/pipeline/pipeline-core/src/test/java/edu/kit/kastel/mcse/ardoco/core/execution/ConfigurationHelperTest.java @@ -11,6 +11,7 @@ import edu.kit.kastel.mcse.ardoco.core.architecture.Deterministic; import edu.kit.kastel.mcse.ardoco.core.configuration.AbstractConfigurable; +import edu.kit.kastel.mcse.ardoco.core.configuration.ChildClassConfigurable; import edu.kit.kastel.mcse.ardoco.core.configuration.Configurable; @Deterministic @@ -77,6 +78,54 @@ void testBasicConfigurable() throws Exception { } + @Test + void testBaseAndChildConfigurable() throws Exception { + SortedMap configs = new TreeMap<>(); + ConfigurationHelper.processConfigurationOfClass(configs, TestBaseConfigurable.class); + Assertions.assertEquals(1, configs.size()); + Assertions.assertEquals("1", configs.get(TestBaseConfigurable.class.getSimpleName() + AbstractConfigurable.CLASS_ATTRIBUTE_CONNECTOR + "value")); + + configs = new TreeMap<>(); + ConfigurationHelper.processConfigurationOfClass(configs, TestChildConfigurable.class); + Assertions.assertEquals(1, configs.size()); + Assertions.assertEquals("2", configs.get(TestChildConfigurable.class.getSimpleName() + AbstractConfigurable.CLASS_ATTRIBUTE_CONNECTOR + "value")); + + configs = new TreeMap<>(Map.of(// + TestBaseConfigurable.class.getSimpleName() + AbstractConfigurable.CLASS_ATTRIBUTE_CONNECTOR + "value", "42", // + TestChildConfigurable.class.getSimpleName() + AbstractConfigurable.CLASS_ATTRIBUTE_CONNECTOR + "value", "43" // + )); + + var t1 = new TestBaseConfigurable(); + t1.applyConfiguration(configs); + Assertions.assertEquals(42, t1.value); + + var t2 = new TestChildConfigurable(); + t2.applyConfiguration(configs); + Assertions.assertEquals(43, t2.value); + } + + private static class TestBaseConfigurable extends AbstractConfigurable { + @Configurable + @ChildClassConfigurable + public int value; + + public TestBaseConfigurable() { + value = 1; + } + + @Override + protected void delegateApplyConfigurationToInternalObjects(SortedMap additionalConfiguration) { + // NOP + } + } + + private static final class TestChildConfigurable extends TestBaseConfigurable { + public TestChildConfigurable() { + super(); + value = 2; + } + } + private static final class TestConfigurable extends AbstractConfigurable { @Configurable diff --git a/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/SadCodeTraceabilityLinkRecovery.java b/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/SadCodeTraceabilityLinkRecovery.java index a78010cb0..5ea44f06f 100644 --- a/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/SadCodeTraceabilityLinkRecovery.java +++ b/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/SadCodeTraceabilityLinkRecovery.java @@ -4,30 +4,16 @@ import java.util.List; import java.util.SortedMap; -import org.eclipse.collections.api.factory.Lists; -import org.eclipse.collections.api.list.MutableList; - import edu.kit.kastel.mcse.ardoco.core.api.codetraceability.CodeTraceabilityState; import edu.kit.kastel.mcse.ardoco.core.codetraceability.agents.ArchitectureLinkToCodeLinkTransformerAgent; import edu.kit.kastel.mcse.ardoco.core.common.util.DataRepositoryHelper; -import edu.kit.kastel.mcse.ardoco.core.configuration.Configurable; import edu.kit.kastel.mcse.ardoco.core.data.DataRepository; import edu.kit.kastel.mcse.ardoco.core.pipeline.AbstractExecutionStage; -import edu.kit.kastel.mcse.ardoco.core.pipeline.agent.Agent; -import edu.kit.kastel.mcse.ardoco.core.pipeline.agent.PipelineAgent; public class SadCodeTraceabilityLinkRecovery extends AbstractExecutionStage { - private final MutableList agents; - - @Configurable - private List enabledAgents; - public SadCodeTraceabilityLinkRecovery(DataRepository dataRepository) { - super(SadCodeTraceabilityLinkRecovery.class.getSimpleName(), dataRepository); - - agents = Lists.mutable.of(new ArchitectureLinkToCodeLinkTransformerAgent(dataRepository)); - enabledAgents = agents.collect(Agent::getId); + super(List.of(new ArchitectureLinkToCodeLinkTransformerAgent(dataRepository)), SadCodeTraceabilityLinkRecovery.class.getSimpleName(), dataRepository); } public static SadCodeTraceabilityLinkRecovery get(SortedMap additionalConfigs, DataRepository dataRepository) { @@ -44,17 +30,4 @@ protected void initializeState() { dataRepository.addData(CodeTraceabilityState.ID, codeTraceabilityState); } } - - @Override - protected List getEnabledAgents() { - return findByClassName(enabledAgents, agents); - } - - @Override - protected void delegateApplyConfigurationToInternalObjects(SortedMap additionalConfiguration) { - super.delegateApplyConfigurationToInternalObjects(additionalConfiguration); - for (var agent : agents) { - agent.applyConfiguration(additionalConfiguration); - } - } } diff --git a/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/SadSamCodeTraceabilityLinkRecovery.java b/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/SadSamCodeTraceabilityLinkRecovery.java index 3e724f2d0..c486c42ad 100644 --- a/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/SadSamCodeTraceabilityLinkRecovery.java +++ b/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/SadSamCodeTraceabilityLinkRecovery.java @@ -4,30 +4,17 @@ import java.util.List; import java.util.SortedMap; -import org.eclipse.collections.api.factory.Lists; -import org.eclipse.collections.api.list.MutableList; - import edu.kit.kastel.mcse.ardoco.core.api.codetraceability.CodeTraceabilityState; import edu.kit.kastel.mcse.ardoco.core.codetraceability.agents.TransitiveTraceabilityAgent; import edu.kit.kastel.mcse.ardoco.core.common.util.DataRepositoryHelper; -import edu.kit.kastel.mcse.ardoco.core.configuration.Configurable; import edu.kit.kastel.mcse.ardoco.core.data.DataRepository; import edu.kit.kastel.mcse.ardoco.core.pipeline.AbstractExecutionStage; -import edu.kit.kastel.mcse.ardoco.core.pipeline.agent.Agent; -import edu.kit.kastel.mcse.ardoco.core.pipeline.agent.PipelineAgent; public class SadSamCodeTraceabilityLinkRecovery extends AbstractExecutionStage { - private final MutableList agents; - - @Configurable - private List enabledAgents; - public SadSamCodeTraceabilityLinkRecovery(DataRepository dataRepository) { - super(SadSamCodeTraceabilityLinkRecovery.class.getSimpleName(), dataRepository); + super(List.of(new TransitiveTraceabilityAgent(dataRepository)), SadSamCodeTraceabilityLinkRecovery.class.getSimpleName(), dataRepository); - agents = Lists.mutable.of(new TransitiveTraceabilityAgent(dataRepository)); - enabledAgents = agents.collect(Agent::getId); } public static SadSamCodeTraceabilityLinkRecovery get(SortedMap additionalConfigs, DataRepository dataRepository) { @@ -44,17 +31,4 @@ protected void initializeState() { dataRepository.addData(CodeTraceabilityState.ID, codeTraceabilityState); } } - - @Override - protected List getEnabledAgents() { - return findByClassName(enabledAgents, agents); - } - - @Override - protected void delegateApplyConfigurationToInternalObjects(SortedMap additionalConfiguration) { - super.delegateApplyConfigurationToInternalObjects(additionalConfiguration); - for (var agent : agents) { - agent.applyConfiguration(additionalConfiguration); - } - } } diff --git a/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/SamCodeTraceabilityLinkRecovery.java b/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/SamCodeTraceabilityLinkRecovery.java index 0ab48bab6..4042e0f6a 100644 --- a/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/SamCodeTraceabilityLinkRecovery.java +++ b/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/SamCodeTraceabilityLinkRecovery.java @@ -4,30 +4,16 @@ import java.util.List; import java.util.SortedMap; -import org.eclipse.collections.api.factory.Lists; -import org.eclipse.collections.api.list.MutableList; - import edu.kit.kastel.mcse.ardoco.core.api.codetraceability.CodeTraceabilityState; import edu.kit.kastel.mcse.ardoco.core.codetraceability.agents.InitialCodeTraceabilityAgent; import edu.kit.kastel.mcse.ardoco.core.common.util.DataRepositoryHelper; -import edu.kit.kastel.mcse.ardoco.core.configuration.Configurable; import edu.kit.kastel.mcse.ardoco.core.data.DataRepository; import edu.kit.kastel.mcse.ardoco.core.pipeline.AbstractExecutionStage; -import edu.kit.kastel.mcse.ardoco.core.pipeline.agent.Agent; -import edu.kit.kastel.mcse.ardoco.core.pipeline.agent.PipelineAgent; public class SamCodeTraceabilityLinkRecovery extends AbstractExecutionStage { - private final MutableList agents; - - @Configurable - private List enabledAgents; - public SamCodeTraceabilityLinkRecovery(DataRepository dataRepository) { - super(SamCodeTraceabilityLinkRecovery.class.getSimpleName(), dataRepository); - - agents = Lists.mutable.of(new InitialCodeTraceabilityAgent(dataRepository)); - enabledAgents = agents.collect(Agent::getId); + super(List.of(new InitialCodeTraceabilityAgent(dataRepository)), SamCodeTraceabilityLinkRecovery.class.getSimpleName(), dataRepository); } public static SamCodeTraceabilityLinkRecovery get(SortedMap additionalConfigs, DataRepository dataRepository) { @@ -44,17 +30,4 @@ protected void initializeState() { dataRepository.addData(CodeTraceabilityState.ID, codeTraceabilityState); } } - - @Override - protected List getEnabledAgents() { - return findByClassName(enabledAgents, agents); - } - - @Override - protected void delegateApplyConfigurationToInternalObjects(SortedMap additionalConfiguration) { - super.delegateApplyConfigurationToInternalObjects(additionalConfiguration); - for (var agent : agents) { - agent.applyConfiguration(additionalConfiguration); - } - } } diff --git a/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/agents/ArchitectureLinkToCodeLinkTransformerAgent.java b/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/agents/ArchitectureLinkToCodeLinkTransformerAgent.java index 0f43401f1..3d49c42a8 100644 --- a/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/agents/ArchitectureLinkToCodeLinkTransformerAgent.java +++ b/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/agents/ArchitectureLinkToCodeLinkTransformerAgent.java @@ -2,45 +2,23 @@ package edu.kit.kastel.mcse.ardoco.core.codetraceability.agents; import java.util.List; -import java.util.SortedMap; - -import org.eclipse.collections.api.factory.Lists; -import org.eclipse.collections.api.list.MutableList; import edu.kit.kastel.mcse.ardoco.core.codetraceability.informants.ArchitectureLinkToCodeLinkTransformerInformant; -import edu.kit.kastel.mcse.ardoco.core.configuration.Configurable; import edu.kit.kastel.mcse.ardoco.core.data.DataRepository; -import edu.kit.kastel.mcse.ardoco.core.pipeline.agent.Informant; import edu.kit.kastel.mcse.ardoco.core.pipeline.agent.PipelineAgent; /** * This class transforms architecture trace links to code trace links by remapping the architecture ids (which are code ids) to the compilation units. */ public class ArchitectureLinkToCodeLinkTransformerAgent extends PipelineAgent { - private final MutableList informants; - - @Configurable - private List enabledInformants; public ArchitectureLinkToCodeLinkTransformerAgent(DataRepository dataRepository) { - super(ArchitectureLinkToCodeLinkTransformerAgent.class.getSimpleName(), dataRepository); - - informants = Lists.mutable.of(new ArchitectureLinkToCodeLinkTransformerInformant(dataRepository)); - enabledInformants = informants.collect(Informant::getId); + super(List.of(new ArchitectureLinkToCodeLinkTransformerInformant(dataRepository)), ArchitectureLinkToCodeLinkTransformerAgent.class.getSimpleName(), + dataRepository); } @Override protected void initializeState() { // empty } - - @Override - protected List getEnabledPipelineSteps() { - return findByClassName(enabledInformants, informants); - } - - @Override - protected void delegateApplyConfigurationToInternalObjects(SortedMap additionalConfiguration) { - informants.forEach(filter -> filter.applyConfiguration(additionalConfiguration)); - } } diff --git a/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/agents/InitialCodeTraceabilityAgent.java b/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/agents/InitialCodeTraceabilityAgent.java index 1f1a51529..39e714890 100644 --- a/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/agents/InitialCodeTraceabilityAgent.java +++ b/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/agents/InitialCodeTraceabilityAgent.java @@ -2,42 +2,19 @@ package edu.kit.kastel.mcse.ardoco.core.codetraceability.agents; import java.util.List; -import java.util.SortedMap; - -import org.eclipse.collections.api.factory.Lists; -import org.eclipse.collections.api.list.MutableList; import edu.kit.kastel.mcse.ardoco.core.codetraceability.informants.ArCoTLInformant; -import edu.kit.kastel.mcse.ardoco.core.configuration.Configurable; import edu.kit.kastel.mcse.ardoco.core.data.DataRepository; -import edu.kit.kastel.mcse.ardoco.core.pipeline.agent.Informant; import edu.kit.kastel.mcse.ardoco.core.pipeline.agent.PipelineAgent; public class InitialCodeTraceabilityAgent extends PipelineAgent { - private final MutableList informants; - - @Configurable - private List enabledInformants; public InitialCodeTraceabilityAgent(DataRepository dataRepository) { - super(InitialCodeTraceabilityAgent.class.getSimpleName(), dataRepository); - - informants = Lists.mutable.of(new ArCoTLInformant(dataRepository)); - enabledInformants = informants.collect(Informant::getId); + super(List.of(new ArCoTLInformant(dataRepository)), InitialCodeTraceabilityAgent.class.getSimpleName(), dataRepository); } @Override protected void initializeState() { // empty } - - @Override - protected List getEnabledPipelineSteps() { - return findByClassName(enabledInformants, informants); - } - - @Override - protected void delegateApplyConfigurationToInternalObjects(SortedMap additionalConfiguration) { - informants.forEach(filter -> filter.applyConfiguration(additionalConfiguration)); - } } diff --git a/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/agents/TransitiveTraceabilityAgent.java b/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/agents/TransitiveTraceabilityAgent.java index 11f5b6471..f34bd4682 100644 --- a/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/agents/TransitiveTraceabilityAgent.java +++ b/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/agents/TransitiveTraceabilityAgent.java @@ -2,43 +2,19 @@ package edu.kit.kastel.mcse.ardoco.core.codetraceability.agents; import java.util.List; -import java.util.SortedMap; - -import org.eclipse.collections.api.factory.Lists; -import org.eclipse.collections.api.list.MutableList; import edu.kit.kastel.mcse.ardoco.core.codetraceability.informants.TraceLinkCombiner; -import edu.kit.kastel.mcse.ardoco.core.configuration.Configurable; import edu.kit.kastel.mcse.ardoco.core.data.DataRepository; -import edu.kit.kastel.mcse.ardoco.core.pipeline.agent.Informant; import edu.kit.kastel.mcse.ardoco.core.pipeline.agent.PipelineAgent; public class TransitiveTraceabilityAgent extends PipelineAgent { - private final MutableList informants; - - @Configurable - private List enabledInformants; - public TransitiveTraceabilityAgent(DataRepository dataRepository) { - super(TransitiveTraceabilityAgent.class.getSimpleName(), dataRepository); - - informants = Lists.mutable.of(new TraceLinkCombiner(dataRepository)); - enabledInformants = informants.collect(Informant::getId); + super(List.of(new TraceLinkCombiner(dataRepository)), TransitiveTraceabilityAgent.class.getSimpleName(), dataRepository); } @Override protected void initializeState() { // empty } - - @Override - protected List getEnabledPipelineSteps() { - return findByClassName(enabledInformants, informants); - } - - @Override - protected void delegateApplyConfigurationToInternalObjects(SortedMap additionalConfiguration) { - informants.forEach(filter -> filter.applyConfiguration(additionalConfiguration)); - } } diff --git a/stages/connection-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/connectiongenerator/ConnectionGenerator.java b/stages/connection-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/connectiongenerator/ConnectionGenerator.java index b1177dc2c..51f60fbd6 100644 --- a/stages/connection-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/connectiongenerator/ConnectionGenerator.java +++ b/stages/connection-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/connectiongenerator/ConnectionGenerator.java @@ -4,19 +4,13 @@ import java.util.List; import java.util.SortedMap; -import org.eclipse.collections.api.factory.Lists; -import org.eclipse.collections.api.list.MutableList; - import edu.kit.kastel.mcse.ardoco.core.api.connectiongenerator.ConnectionStates; -import edu.kit.kastel.mcse.ardoco.core.configuration.Configurable; import edu.kit.kastel.mcse.ardoco.core.connectiongenerator.agents.InitialConnectionAgent; import edu.kit.kastel.mcse.ardoco.core.connectiongenerator.agents.InstanceConnectionAgent; import edu.kit.kastel.mcse.ardoco.core.connectiongenerator.agents.ProjectNameFilterAgent; import edu.kit.kastel.mcse.ardoco.core.connectiongenerator.agents.ReferenceAgent; import edu.kit.kastel.mcse.ardoco.core.data.DataRepository; import edu.kit.kastel.mcse.ardoco.core.pipeline.AbstractExecutionStage; -import edu.kit.kastel.mcse.ardoco.core.pipeline.agent.Agent; -import edu.kit.kastel.mcse.ardoco.core.pipeline.agent.PipelineAgent; /** * The ModelConnectionAgent runs different analyzers and solvers. This agent creates recommendations as well as @@ -25,22 +19,14 @@ */ public class ConnectionGenerator extends AbstractExecutionStage { - private final MutableList agents; - - @Configurable - private List enabledAgents; - /** * Create the module. * * @param dataRepository the {@link DataRepository} */ public ConnectionGenerator(DataRepository dataRepository) { - super("ConnectionGenerator", dataRepository); - - agents = Lists.mutable.of(new InitialConnectionAgent(dataRepository), new ReferenceAgent(dataRepository), new ProjectNameFilterAgent(dataRepository), - new InstanceConnectionAgent(dataRepository)); - enabledAgents = agents.collect(Agent::getId); + super(List.of(new InitialConnectionAgent(dataRepository), new ReferenceAgent(dataRepository), new ProjectNameFilterAgent(dataRepository), + new InstanceConnectionAgent(dataRepository)), "ConnectionGenerator", dataRepository); } /** @@ -61,18 +47,4 @@ protected void initializeState() { var connectionStates = ConnectionStatesImpl.build(); getDataRepository().addData(ConnectionStates.ID, connectionStates); } - - @Override - protected List getEnabledAgents() { - return findByClassName(enabledAgents, agents); - } - - @Override - protected void delegateApplyConfigurationToInternalObjects(SortedMap additionalConfiguration) { - super.delegateApplyConfigurationToInternalObjects(additionalConfiguration); - for (var agent : agents) { - agent.applyConfiguration(additionalConfiguration); - } - } - } diff --git a/stages/connection-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/connectiongenerator/agents/InitialConnectionAgent.java b/stages/connection-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/connectiongenerator/agents/InitialConnectionAgent.java index 67276d823..971f82d95 100644 --- a/stages/connection-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/connectiongenerator/agents/InitialConnectionAgent.java +++ b/stages/connection-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/connectiongenerator/agents/InitialConnectionAgent.java @@ -2,23 +2,16 @@ package edu.kit.kastel.mcse.ardoco.core.connectiongenerator.agents; import java.util.List; -import java.util.SortedMap; -import edu.kit.kastel.mcse.ardoco.core.configuration.Configurable; import edu.kit.kastel.mcse.ardoco.core.connectiongenerator.informants.ExtractionDependentOccurrenceInformant; import edu.kit.kastel.mcse.ardoco.core.connectiongenerator.informants.NameTypeConnectionInformant; import edu.kit.kastel.mcse.ardoco.core.data.DataRepository; -import edu.kit.kastel.mcse.ardoco.core.pipeline.agent.Informant; import edu.kit.kastel.mcse.ardoco.core.pipeline.agent.PipelineAgent; /** * The agent that executes the extractors of this stage. */ public class InitialConnectionAgent extends PipelineAgent { - private final List informants; - - @Configurable - private List enabledInformants; /** * Create the agent. @@ -26,19 +19,7 @@ public class InitialConnectionAgent extends PipelineAgent { * @param dataRepository the {@link DataRepository} */ public InitialConnectionAgent(DataRepository dataRepository) { - super(InitialConnectionAgent.class.getSimpleName(), dataRepository); - - informants = List.of(new NameTypeConnectionInformant(dataRepository), new ExtractionDependentOccurrenceInformant(dataRepository)); - enabledInformants = informants.stream().map(e -> e.getClass().getSimpleName()).toList(); - } - - @Override - protected List getEnabledPipelineSteps() { - return findByClassName(enabledInformants, informants); - } - - @Override - protected void delegateApplyConfigurationToInternalObjects(SortedMap additionalConfiguration) { - informants.forEach(e -> e.applyConfiguration(additionalConfiguration)); + super(List.of(new NameTypeConnectionInformant(dataRepository), new ExtractionDependentOccurrenceInformant(dataRepository)), InitialConnectionAgent.class + .getSimpleName(), dataRepository); } } diff --git a/stages/connection-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/connectiongenerator/agents/InstanceConnectionAgent.java b/stages/connection-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/connectiongenerator/agents/InstanceConnectionAgent.java index 3aa16d7c9..8908b55b2 100644 --- a/stages/connection-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/connectiongenerator/agents/InstanceConnectionAgent.java +++ b/stages/connection-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/connectiongenerator/agents/InstanceConnectionAgent.java @@ -2,22 +2,15 @@ package edu.kit.kastel.mcse.ardoco.core.connectiongenerator.agents; import java.util.List; -import java.util.SortedMap; -import edu.kit.kastel.mcse.ardoco.core.configuration.Configurable; import edu.kit.kastel.mcse.ardoco.core.connectiongenerator.informants.InstantConnectionInformant; import edu.kit.kastel.mcse.ardoco.core.data.DataRepository; -import edu.kit.kastel.mcse.ardoco.core.pipeline.agent.Informant; import edu.kit.kastel.mcse.ardoco.core.pipeline.agent.PipelineAgent; /** * This connector finds names of model instance in recommended instances. */ public class InstanceConnectionAgent extends PipelineAgent { - private final List informants; - - @Configurable - private List enabledInformants; /** * Create the agent. @@ -25,19 +18,6 @@ public class InstanceConnectionAgent extends PipelineAgent { * @param dataRepository the {@link DataRepository} */ public InstanceConnectionAgent(DataRepository dataRepository) { - super(InstanceConnectionAgent.class.getSimpleName(), dataRepository); - - informants = List.of(new InstantConnectionInformant(dataRepository)); - enabledInformants = informants.stream().map(e -> e.getClass().getSimpleName()).toList(); - } - - @Override - protected List getEnabledPipelineSteps() { - return findByClassName(enabledInformants, informants); - } - - @Override - protected void delegateApplyConfigurationToInternalObjects(SortedMap additionalConfiguration) { - informants.forEach(e -> e.applyConfiguration(additionalConfiguration)); + super(List.of(new InstantConnectionInformant(dataRepository)), InstanceConnectionAgent.class.getSimpleName(), dataRepository); } } diff --git a/stages/connection-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/connectiongenerator/agents/ProjectNameFilterAgent.java b/stages/connection-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/connectiongenerator/agents/ProjectNameFilterAgent.java index c4875f30f..430b5cba8 100644 --- a/stages/connection-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/connectiongenerator/agents/ProjectNameFilterAgent.java +++ b/stages/connection-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/connectiongenerator/agents/ProjectNameFilterAgent.java @@ -2,13 +2,10 @@ package edu.kit.kastel.mcse.ardoco.core.connectiongenerator.agents; import java.util.List; -import java.util.SortedMap; import edu.kit.kastel.mcse.ardoco.core.api.recommendationgenerator.RecommendedInstance; -import edu.kit.kastel.mcse.ardoco.core.configuration.Configurable; import edu.kit.kastel.mcse.ardoco.core.connectiongenerator.informants.ProjectNameInformant; import edu.kit.kastel.mcse.ardoco.core.data.DataRepository; -import edu.kit.kastel.mcse.ardoco.core.pipeline.agent.Informant; import edu.kit.kastel.mcse.ardoco.core.pipeline.agent.PipelineAgent; /** @@ -17,10 +14,6 @@ * {@link RecommendedInstance} extremely improbable. */ public class ProjectNameFilterAgent extends PipelineAgent { - private final List informants; - - @Configurable - private List enabledInformants; /** * Create the agent. @@ -28,19 +21,6 @@ public class ProjectNameFilterAgent extends PipelineAgent { * @param dataRepository the {@link DataRepository} */ public ProjectNameFilterAgent(DataRepository dataRepository) { - super("ProjectNameFilterAgent", dataRepository); - - informants = List.of(new ProjectNameInformant(dataRepository)); - enabledInformants = informants.stream().map(e -> e.getClass().getSimpleName()).toList(); - } - - @Override - protected List getEnabledPipelineSteps() { - return findByClassName(enabledInformants, informants); - } - - @Override - protected void delegateApplyConfigurationToInternalObjects(SortedMap additionalConfiguration) { - informants.forEach(e -> e.applyConfiguration(additionalConfiguration)); + super(List.of(new ProjectNameInformant(dataRepository)), "ProjectNameFilterAgent", dataRepository); } } diff --git a/stages/connection-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/connectiongenerator/agents/ReferenceAgent.java b/stages/connection-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/connectiongenerator/agents/ReferenceAgent.java index d565227f2..fef93439a 100644 --- a/stages/connection-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/connectiongenerator/agents/ReferenceAgent.java +++ b/stages/connection-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/connectiongenerator/agents/ReferenceAgent.java @@ -2,12 +2,9 @@ package edu.kit.kastel.mcse.ardoco.core.connectiongenerator.agents; import java.util.List; -import java.util.SortedMap; -import edu.kit.kastel.mcse.ardoco.core.configuration.Configurable; import edu.kit.kastel.mcse.ardoco.core.connectiongenerator.informants.ReferenceInformant; import edu.kit.kastel.mcse.ardoco.core.data.DataRepository; -import edu.kit.kastel.mcse.ardoco.core.pipeline.agent.Informant; import edu.kit.kastel.mcse.ardoco.core.pipeline.agent.PipelineAgent; /** @@ -16,30 +13,12 @@ */ public class ReferenceAgent extends PipelineAgent { - private final List informants; - - @Configurable - private List enabledInformants; - /** * Create the agent. * * @param dataRepository the {@link DataRepository} */ public ReferenceAgent(DataRepository dataRepository) { - super(ReferenceAgent.class.getSimpleName(), dataRepository); - - informants = List.of(new ReferenceInformant(dataRepository)); - enabledInformants = informants.stream().map(e -> e.getClass().getSimpleName()).toList(); - } - - @Override - protected List getEnabledPipelineSteps() { - return findByClassName(enabledInformants, informants); - } - - @Override - protected void delegateApplyConfigurationToInternalObjects(SortedMap additionalConfiguration) { - informants.forEach(e -> e.applyConfiguration(additionalConfiguration)); + super(List.of(new ReferenceInformant(dataRepository)), ReferenceAgent.class.getSimpleName(), dataRepository); } } diff --git a/stages/diagram-recognition/src/main/kotlin/edu/kit/kastel/mcse/ardoco/lissa/DiagramRecognition.kt b/stages/diagram-recognition/src/main/kotlin/edu/kit/kastel/mcse/ardoco/lissa/DiagramRecognition.kt index 95fa353d9..7b5007048 100644 --- a/stages/diagram-recognition/src/main/kotlin/edu/kit/kastel/mcse/ardoco/lissa/DiagramRecognition.kt +++ b/stages/diagram-recognition/src/main/kotlin/edu/kit/kastel/mcse/ardoco/lissa/DiagramRecognition.kt @@ -2,15 +2,13 @@ package edu.kit.kastel.mcse.ardoco.lissa import edu.kit.kastel.mcse.ardoco.core.api.InputDiagramData import edu.kit.kastel.mcse.ardoco.core.api.diagramrecognition.DiagramRecognitionState -import edu.kit.kastel.mcse.ardoco.core.configuration.Configurable import edu.kit.kastel.mcse.ardoco.core.data.DataRepository import edu.kit.kastel.mcse.ardoco.core.pipeline.AbstractExecutionStage -import edu.kit.kastel.mcse.ardoco.core.pipeline.agent.PipelineAgent import edu.kit.kastel.mcse.ardoco.lissa.diagramrecognition.agents.DiagramRecognitionAgent import edu.kit.kastel.mcse.ardoco.lissa.diagramrecognition.model.DiagramImpl -import java.util.* +import java.util.SortedMap -class DiagramRecognition : AbstractExecutionStage { +class DiagramRecognition(dataRepository: DataRepository) : AbstractExecutionStage(listOf(DiagramRecognitionAgent(dataRepository)), ID, dataRepository) { companion object { const val ID = "DiagramRecognition" @@ -30,16 +28,6 @@ class DiagramRecognition : AbstractExecutionStage { } } - private val agents: List - - @Configurable - private var enabledAgents: MutableList - - constructor(dataRepository: DataRepository) : super(ID, dataRepository) { - this.agents = listOf(DiagramRecognitionAgent(dataRepository)) - enabledAgents = this.agents.map { it.id }.toMutableList() - } - override fun initializeState() { val inputDiagrams = dataRepository.getData(InputDiagramData.ID, InputDiagramData::class.java) if (inputDiagrams.isEmpty) { @@ -54,15 +42,4 @@ class DiagramRecognition : AbstractExecutionStage { } dataRepository.addData(DiagramRecognitionState.ID, diagramRecognitionState) } - - override fun getEnabledAgents(): MutableList { - return findByClassName(enabledAgents, agents) - } - - override fun delegateApplyConfigurationToInternalObjects(additionalConfiguration: SortedMap) { - super.delegateApplyConfigurationToInternalObjects(additionalConfiguration) - for (agent in agents) { - agent.applyConfiguration(additionalConfiguration) - } - } } diff --git a/stages/diagram-recognition/src/main/kotlin/edu/kit/kastel/mcse/ardoco/lissa/diagramrecognition/agents/DiagramRecognitionAgent.kt b/stages/diagram-recognition/src/main/kotlin/edu/kit/kastel/mcse/ardoco/lissa/diagramrecognition/agents/DiagramRecognitionAgent.kt index 224de510b..5989fa328 100644 --- a/stages/diagram-recognition/src/main/kotlin/edu/kit/kastel/mcse/ardoco/lissa/diagramrecognition/agents/DiagramRecognitionAgent.kt +++ b/stages/diagram-recognition/src/main/kotlin/edu/kit/kastel/mcse/ardoco/lissa/diagramrecognition/agents/DiagramRecognitionAgent.kt @@ -1,36 +1,25 @@ package edu.kit.kastel.mcse.ardoco.lissa.diagramrecognition.agents import edu.kit.kastel.mcse.ardoco.core.api.diagramrecognition.DiagramRecognitionState -import edu.kit.kastel.mcse.ardoco.core.configuration.Configurable import edu.kit.kastel.mcse.ardoco.core.data.DataRepository -import edu.kit.kastel.mcse.ardoco.core.pipeline.agent.Informant import edu.kit.kastel.mcse.ardoco.core.pipeline.agent.PipelineAgent import edu.kit.kastel.mcse.ardoco.lissa.diagramrecognition.informants.ObjectDetectionInformant import edu.kit.kastel.mcse.ardoco.lissa.diagramrecognition.informants.OcrInformant import edu.kit.kastel.mcse.ardoco.lissa.diagramrecognition.informants.RecognitionCombinatorInformant -import java.util.* /** * This agent uses the [DiagramRecognitionState] to extract the diagrams and sketches from images. */ -class DiagramRecognitionAgent(dataRepository: DataRepository) : PipelineAgent(ID, dataRepository) { - companion object { - const val ID = "DiagramRecognitionAgent" - } - - private val informants = listOf( +class DiagramRecognitionAgent(dataRepository: DataRepository) : PipelineAgent( + listOf( ObjectDetectionInformant(dataRepository), OcrInformant(dataRepository), RecognitionCombinatorInformant(dataRepository) - ) - - @Configurable - private var enabledInformants: MutableList = - informants.map { e: Informant -> e.javaClass.simpleName }.toMutableList() - - override fun getEnabledPipelineSteps(): MutableList = findByClassName(enabledInformants, informants) - - override fun delegateApplyConfigurationToInternalObjects(additionalConfiguration: SortedMap?) { - informants.forEach { it.applyConfiguration(additionalConfiguration) } + ), + ID, + dataRepository +) { + companion object { + const val ID = "DiagramRecognitionAgent" } } diff --git a/stages/inconsistency-detection/src/main/java/edu/kit/kastel/mcse/ardoco/core/inconsistency/InconsistencyChecker.java b/stages/inconsistency-detection/src/main/java/edu/kit/kastel/mcse/ardoco/core/inconsistency/InconsistencyChecker.java index be570c17e..68e68712d 100644 --- a/stages/inconsistency-detection/src/main/java/edu/kit/kastel/mcse/ardoco/core/inconsistency/InconsistencyChecker.java +++ b/stages/inconsistency-detection/src/main/java/edu/kit/kastel/mcse/ardoco/core/inconsistency/InconsistencyChecker.java @@ -4,32 +4,18 @@ import java.util.List; import java.util.SortedMap; -import org.eclipse.collections.api.factory.Lists; -import org.eclipse.collections.api.list.MutableList; - import edu.kit.kastel.mcse.ardoco.core.api.inconsistency.InconsistencyStates; -import edu.kit.kastel.mcse.ardoco.core.configuration.Configurable; import edu.kit.kastel.mcse.ardoco.core.data.DataRepository; import edu.kit.kastel.mcse.ardoco.core.inconsistency.agents.InitialInconsistencyAgent; import edu.kit.kastel.mcse.ardoco.core.inconsistency.agents.MissingModelElementInconsistencyAgent; import edu.kit.kastel.mcse.ardoco.core.inconsistency.agents.UndocumentedModelElementInconsistencyAgent; import edu.kit.kastel.mcse.ardoco.core.pipeline.AbstractExecutionStage; -import edu.kit.kastel.mcse.ardoco.core.pipeline.agent.Agent; -import edu.kit.kastel.mcse.ardoco.core.pipeline.agent.PipelineAgent; public class InconsistencyChecker extends AbstractExecutionStage { - private final MutableList agents; - - @Configurable - private List enabledAgents; - public InconsistencyChecker(DataRepository dataRepository) { - super("InconsistencyChecker", dataRepository); - - agents = Lists.mutable.of(new InitialInconsistencyAgent(dataRepository), new MissingModelElementInconsistencyAgent(dataRepository), - new UndocumentedModelElementInconsistencyAgent(dataRepository)); - enabledAgents = agents.collect(Agent::getId); + super(List.of(new InitialInconsistencyAgent(dataRepository), new MissingModelElementInconsistencyAgent(dataRepository), + new UndocumentedModelElementInconsistencyAgent(dataRepository)), "InconsistencyChecker", dataRepository); } /** @@ -51,17 +37,4 @@ protected void initializeState() { getDataRepository().addData(InconsistencyStates.ID, inconsistencyStates); } - @Override - protected List getEnabledAgents() { - return findByClassName(enabledAgents, agents); - } - - @Override - protected void delegateApplyConfigurationToInternalObjects(SortedMap additionalConfiguration) { - super.delegateApplyConfigurationToInternalObjects(additionalConfiguration); - for (var agent : agents) { - agent.applyConfiguration(additionalConfiguration); - } - } - } diff --git a/stages/inconsistency-detection/src/main/java/edu/kit/kastel/mcse/ardoco/core/inconsistency/agents/InitialInconsistencyAgent.java b/stages/inconsistency-detection/src/main/java/edu/kit/kastel/mcse/ardoco/core/inconsistency/agents/InitialInconsistencyAgent.java index 82d54d01d..bbe41a51b 100644 --- a/stages/inconsistency-detection/src/main/java/edu/kit/kastel/mcse/ardoco/core/inconsistency/agents/InitialInconsistencyAgent.java +++ b/stages/inconsistency-detection/src/main/java/edu/kit/kastel/mcse/ardoco/core/inconsistency/agents/InitialInconsistencyAgent.java @@ -2,33 +2,21 @@ package edu.kit.kastel.mcse.ardoco.core.inconsistency.agents; import java.util.List; -import java.util.SortedMap; - -import org.eclipse.collections.api.factory.Lists; -import org.eclipse.collections.api.list.MutableList; import edu.kit.kastel.mcse.ardoco.core.api.models.Metamodel; import edu.kit.kastel.mcse.ardoco.core.common.util.DataRepositoryHelper; -import edu.kit.kastel.mcse.ardoco.core.configuration.Configurable; import edu.kit.kastel.mcse.ardoco.core.data.DataRepository; import edu.kit.kastel.mcse.ardoco.core.inconsistency.informants.OccasionFilter; import edu.kit.kastel.mcse.ardoco.core.inconsistency.informants.RecommendedInstanceProbabilityFilter; import edu.kit.kastel.mcse.ardoco.core.inconsistency.informants.UnwantedWordsFilter; -import edu.kit.kastel.mcse.ardoco.core.pipeline.agent.Informant; import edu.kit.kastel.mcse.ardoco.core.pipeline.agent.PipelineAgent; public class InitialInconsistencyAgent extends PipelineAgent { - private final MutableList filters; - - @Configurable - private List enabledFilters; public InitialInconsistencyAgent(DataRepository dataRepository) { - super(InitialInconsistencyAgent.class.getSimpleName(), dataRepository); + super(List.of(new RecommendedInstanceProbabilityFilter(dataRepository), new OccasionFilter(dataRepository), new UnwantedWordsFilter(dataRepository)), + InitialInconsistencyAgent.class.getSimpleName(), dataRepository); - filters = Lists.mutable.of(new RecommendedInstanceProbabilityFilter(dataRepository), new OccasionFilter(dataRepository), new UnwantedWordsFilter( - dataRepository)); - enabledFilters = filters.collect(Informant::getId); } @Override @@ -46,14 +34,4 @@ protected void initializeState() { inconsistencyState.addRecommendedInstances(recommendationState.getRecommendedInstances().toList()); } } - - @Override - protected List getEnabledPipelineSteps() { - return findByClassName(enabledFilters, filters); - } - - @Override - protected void delegateApplyConfigurationToInternalObjects(SortedMap additionalConfiguration) { - filters.forEach(filter -> filter.applyConfiguration(additionalConfiguration)); - } } diff --git a/stages/inconsistency-detection/src/main/java/edu/kit/kastel/mcse/ardoco/core/inconsistency/agents/MissingModelElementInconsistencyAgent.java b/stages/inconsistency-detection/src/main/java/edu/kit/kastel/mcse/ardoco/core/inconsistency/agents/MissingModelElementInconsistencyAgent.java index bb993bd9f..a9ac09ea0 100644 --- a/stages/inconsistency-detection/src/main/java/edu/kit/kastel/mcse/ardoco/core/inconsistency/agents/MissingModelElementInconsistencyAgent.java +++ b/stages/inconsistency-detection/src/main/java/edu/kit/kastel/mcse/ardoco/core/inconsistency/agents/MissingModelElementInconsistencyAgent.java @@ -2,35 +2,14 @@ package edu.kit.kastel.mcse.ardoco.core.inconsistency.agents; import java.util.List; -import java.util.SortedMap; -import edu.kit.kastel.mcse.ardoco.core.configuration.Configurable; import edu.kit.kastel.mcse.ardoco.core.data.DataRepository; import edu.kit.kastel.mcse.ardoco.core.inconsistency.informants.MissingModelElementInconsistencyInformant; -import edu.kit.kastel.mcse.ardoco.core.pipeline.agent.Informant; import edu.kit.kastel.mcse.ardoco.core.pipeline.agent.PipelineAgent; public class MissingModelElementInconsistencyAgent extends PipelineAgent { - - private final List informants; - - @Configurable - private List enabledInformants; - public MissingModelElementInconsistencyAgent(DataRepository dataRepository) { - super(MissingModelElementInconsistencyAgent.class.getSimpleName(), dataRepository); - - informants = List.of(new MissingModelElementInconsistencyInformant(dataRepository)); - enabledInformants = informants.stream().map(e -> e.getClass().getSimpleName()).toList(); - } - - @Override - protected List getEnabledPipelineSteps() { - return findByClassName(enabledInformants, informants); - } - - @Override - protected void delegateApplyConfigurationToInternalObjects(SortedMap additionalConfiguration) { - informants.forEach(e -> e.applyConfiguration(additionalConfiguration)); + super(List.of(new MissingModelElementInconsistencyInformant(dataRepository)), MissingModelElementInconsistencyAgent.class.getSimpleName(), + dataRepository); } } diff --git a/stages/inconsistency-detection/src/main/java/edu/kit/kastel/mcse/ardoco/core/inconsistency/agents/UndocumentedModelElementInconsistencyAgent.java b/stages/inconsistency-detection/src/main/java/edu/kit/kastel/mcse/ardoco/core/inconsistency/agents/UndocumentedModelElementInconsistencyAgent.java index 11f7931e9..79a7fc658 100644 --- a/stages/inconsistency-detection/src/main/java/edu/kit/kastel/mcse/ardoco/core/inconsistency/agents/UndocumentedModelElementInconsistencyAgent.java +++ b/stages/inconsistency-detection/src/main/java/edu/kit/kastel/mcse/ardoco/core/inconsistency/agents/UndocumentedModelElementInconsistencyAgent.java @@ -2,12 +2,9 @@ package edu.kit.kastel.mcse.ardoco.core.inconsistency.agents; import java.util.List; -import java.util.SortedMap; -import edu.kit.kastel.mcse.ardoco.core.configuration.Configurable; import edu.kit.kastel.mcse.ardoco.core.data.DataRepository; import edu.kit.kastel.mcse.ardoco.core.inconsistency.informants.UndocumentedModelElementInconsistencyInformant; -import edu.kit.kastel.mcse.ardoco.core.pipeline.agent.Informant; import edu.kit.kastel.mcse.ardoco.core.pipeline.agent.PipelineAgent; /** @@ -16,25 +13,8 @@ */ public class UndocumentedModelElementInconsistencyAgent extends PipelineAgent { - private final List informants; - - @Configurable - private List enabledInformants; - public UndocumentedModelElementInconsistencyAgent(DataRepository dataRepository) { - super(UndocumentedModelElementInconsistencyAgent.class.getSimpleName(), dataRepository); - - informants = List.of(new UndocumentedModelElementInconsistencyInformant(dataRepository)); - enabledInformants = informants.stream().map(e -> e.getClass().getSimpleName()).toList(); - } - - @Override - protected List getEnabledPipelineSteps() { - return findByClassName(enabledInformants, informants); - } - - @Override - protected void delegateApplyConfigurationToInternalObjects(SortedMap additionalConfiguration) { - informants.forEach(e -> e.applyConfiguration(additionalConfiguration)); + super(List.of(new UndocumentedModelElementInconsistencyInformant(dataRepository)), UndocumentedModelElementInconsistencyAgent.class.getSimpleName(), + dataRepository); } } diff --git a/stages/model-provider/src/main/java/edu/kit/kastel/mcse/ardoco/core/models/ArCoTLModelProviderAgent.java b/stages/model-provider/src/main/java/edu/kit/kastel/mcse/ardoco/core/models/ArCoTLModelProviderAgent.java index 5c4a5db4e..c2fda81a3 100644 --- a/stages/model-provider/src/main/java/edu/kit/kastel/mcse/ardoco/core/models/ArCoTLModelProviderAgent.java +++ b/stages/model-provider/src/main/java/edu/kit/kastel/mcse/ardoco/core/models/ArCoTLModelProviderAgent.java @@ -2,7 +2,6 @@ package edu.kit.kastel.mcse.ardoco.core.models; import java.io.File; -import java.util.ArrayList; import java.util.List; import java.util.SortedMap; @@ -24,8 +23,6 @@ */ public class ArCoTLModelProviderAgent extends PipelineAgent { - private final List informants; - /** * Instantiates a new model provider agent. * The constructor takes a list of ModelConnectors that are executed and used to extract information from models. @@ -34,11 +31,11 @@ public class ArCoTLModelProviderAgent extends PipelineAgent { * @param extractors the list of ModelConnectors that should be used */ public ArCoTLModelProviderAgent(DataRepository data, List extractors) { - super(ArCoTLModelProviderAgent.class.getSimpleName(), data); - informants = new ArrayList<>(); - for (var extractor : extractors) { - informants.add(new ArCoTLModelProviderInformant(data, extractor)); - } + super(informants(data, extractors), ArCoTLModelProviderAgent.class.getSimpleName(), data); + } + + private static List informants(DataRepository data, List extractors) { + return extractors.stream().map(e -> new ArCoTLModelProviderInformant(data, e)).toList(); } public static ArCoTLModelProviderAgent get(File inputArchitectureModel, ArchitectureModelType architectureModelType, File inputCode, @@ -58,9 +55,4 @@ public static ArCoTLModelProviderAgent get(File inputArchitectureModel, Architec protected void delegateApplyConfigurationToInternalObjects(SortedMap additionalConfiguration) { // empty } - - @Override - protected List getEnabledPipelineSteps() { - return new ArrayList<>(informants); - } } diff --git a/stages/model-provider/src/main/java/edu/kit/kastel/mcse/ardoco/core/models/ModelProviderAgent.java b/stages/model-provider/src/main/java/edu/kit/kastel/mcse/ardoco/core/models/ModelProviderAgent.java index 1437e659f..74968a56b 100644 --- a/stages/model-provider/src/main/java/edu/kit/kastel/mcse/ardoco/core/models/ModelProviderAgent.java +++ b/stages/model-provider/src/main/java/edu/kit/kastel/mcse/ardoco/core/models/ModelProviderAgent.java @@ -3,12 +3,11 @@ import java.io.File; import java.io.IOException; -import java.util.ArrayList; import java.util.List; -import java.util.SortedMap; import edu.kit.kastel.mcse.ardoco.core.api.models.ArchitectureModelType; import edu.kit.kastel.mcse.ardoco.core.api.models.ModelConnector; +import edu.kit.kastel.mcse.ardoco.core.configuration.NoConfiguration; import edu.kit.kastel.mcse.ardoco.core.data.DataRepository; import edu.kit.kastel.mcse.ardoco.core.models.connectors.PcmXmlModelConnector; import edu.kit.kastel.mcse.ardoco.core.models.connectors.UmlModelConnector; @@ -20,10 +19,9 @@ /** * Agent that provides information from models. */ +@NoConfiguration public class ModelProviderAgent extends PipelineAgent { - private final List informants; - /** * Instantiates a new model provider agent. * The constructor takes a list of ModelConnectors that are executed and used to extract information from models. @@ -32,17 +30,15 @@ public class ModelProviderAgent extends PipelineAgent { * @param modelConnectors the list of ModelConnectors that should be used */ public ModelProviderAgent(DataRepository data, List modelConnectors) { - super(ModelProviderAgent.class.getSimpleName(), data); - informants = new ArrayList<>(); - for (var modelConnector : modelConnectors) { - informants.add(new ModelProviderInformant(data, modelConnector)); - } + super(informants(modelConnectors, data), ModelProviderAgent.class.getSimpleName(), data); + } + + private static List informants(List modelConnectors, DataRepository data) { + return modelConnectors.stream().map(e -> new ModelProviderInformant(data, e)).toList(); } private ModelProviderAgent(DataRepository data, LegacyCodeModelInformant codeModelInformant) { - super(ModelProviderAgent.class.getSimpleName(), data); - informants = new ArrayList<>(); - informants.add(codeModelInformant); + super(List.of(codeModelInformant), ModelProviderAgent.class.getSimpleName(), data); } /** @@ -66,14 +62,4 @@ public static ModelProviderAgent get(File inputArchitectureModel, ArchitectureMo public static ModelProviderAgent getCodeProvider(DataRepository dataRepository) { return new ModelProviderAgent(dataRepository, new LegacyCodeModelInformant(dataRepository)); } - - @Override - protected void delegateApplyConfigurationToInternalObjects(SortedMap additionalConfiguration) { - informants.forEach(e -> e.applyConfiguration(additionalConfiguration)); - } - - @Override - protected List getEnabledPipelineSteps() { - return new ArrayList<>(informants); - } } diff --git a/stages/recommendation-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/recommendationgenerator/RecommendationGenerator.java b/stages/recommendation-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/recommendationgenerator/RecommendationGenerator.java index 13c461bf5..09781f493 100644 --- a/stages/recommendation-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/recommendationgenerator/RecommendationGenerator.java +++ b/stages/recommendation-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/recommendationgenerator/RecommendationGenerator.java @@ -1,18 +1,13 @@ /* Licensed under MIT 2021-2023. */ package edu.kit.kastel.mcse.ardoco.core.recommendationgenerator; -import java.util.List; import java.util.SortedMap; import org.eclipse.collections.api.factory.Lists; -import org.eclipse.collections.api.list.MutableList; import edu.kit.kastel.mcse.ardoco.core.api.recommendationgenerator.RecommendationStates; -import edu.kit.kastel.mcse.ardoco.core.configuration.Configurable; import edu.kit.kastel.mcse.ardoco.core.data.DataRepository; import edu.kit.kastel.mcse.ardoco.core.pipeline.AbstractExecutionStage; -import edu.kit.kastel.mcse.ardoco.core.pipeline.agent.Agent; -import edu.kit.kastel.mcse.ardoco.core.pipeline.agent.PipelineAgent; import edu.kit.kastel.mcse.ardoco.core.recommendationgenerator.agents.InitialRecommendationAgent; import edu.kit.kastel.mcse.ardoco.core.recommendationgenerator.agents.PhraseRecommendationAgent; @@ -21,24 +16,15 @@ */ public class RecommendationGenerator extends AbstractExecutionStage { - private final MutableList agents; - - @Configurable - private List enabledAgents; - /** * Creates a new model connection agent with the given extraction state and ntr state. */ public RecommendationGenerator(DataRepository dataRepository) { - super("RecommendationGenerator", dataRepository); - - this.agents = Lists.mutable.of(// + super(Lists.mutable.of(// //new TermBuilder(dataRepository),// new InitialRecommendationAgent(dataRepository),// - new PhraseRecommendationAgent(dataRepository) - - ); - this.enabledAgents = agents.collect(Agent::getId); + new PhraseRecommendationAgent(dataRepository)),// + RecommendationGenerator.class.getSimpleName(), dataRepository); } /** @@ -59,17 +45,4 @@ protected void initializeState() { var recommendationStates = RecommendationStatesImpl.build(); getDataRepository().addData(RecommendationStates.ID, recommendationStates); } - - @Override - protected List getEnabledAgents() { - return findByClassName(enabledAgents, agents); - } - - @Override - protected void delegateApplyConfigurationToInternalObjects(SortedMap additionalConfiguration) { - super.delegateApplyConfigurationToInternalObjects(additionalConfiguration); - for (var agent : agents) { - agent.applyConfiguration(additionalConfiguration); - } - } } diff --git a/stages/recommendation-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/recommendationgenerator/agents/InitialRecommendationAgent.java b/stages/recommendation-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/recommendationgenerator/agents/InitialRecommendationAgent.java index b4194eed8..682169457 100644 --- a/stages/recommendation-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/recommendationgenerator/agents/InitialRecommendationAgent.java +++ b/stages/recommendation-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/recommendationgenerator/agents/InitialRecommendationAgent.java @@ -2,11 +2,8 @@ package edu.kit.kastel.mcse.ardoco.core.recommendationgenerator.agents; import java.util.List; -import java.util.SortedMap; -import edu.kit.kastel.mcse.ardoco.core.configuration.Configurable; import edu.kit.kastel.mcse.ardoco.core.data.DataRepository; -import edu.kit.kastel.mcse.ardoco.core.pipeline.agent.Informant; import edu.kit.kastel.mcse.ardoco.core.pipeline.agent.PipelineAgent; import edu.kit.kastel.mcse.ardoco.core.recommendationgenerator.informants.NameTypeInformant; @@ -14,25 +11,7 @@ * The Class InitialRecommendationAgent runs all extractors of this stage. */ public class InitialRecommendationAgent extends PipelineAgent { - - private final List informants; - - @Configurable - private List enabledInformants; - public InitialRecommendationAgent(DataRepository dataRepository) { - super(InitialRecommendationAgent.class.getSimpleName(), dataRepository); - informants = List.of(new NameTypeInformant(dataRepository)); - enabledInformants = informants.stream().map(e -> e.getClass().getSimpleName()).toList(); - } - - @Override - protected List getEnabledPipelineSteps() { - return findByClassName(enabledInformants, informants); - } - - @Override - protected void delegateApplyConfigurationToInternalObjects(SortedMap additionalConfiguration) { - informants.forEach(e -> e.applyConfiguration(additionalConfiguration)); + super(List.of(new NameTypeInformant(dataRepository)), InitialRecommendationAgent.class.getSimpleName(), dataRepository); } } diff --git a/stages/recommendation-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/recommendationgenerator/agents/PhraseRecommendationAgent.java b/stages/recommendation-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/recommendationgenerator/agents/PhraseRecommendationAgent.java index 3b36f47c6..e0e839645 100644 --- a/stages/recommendation-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/recommendationgenerator/agents/PhraseRecommendationAgent.java +++ b/stages/recommendation-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/recommendationgenerator/agents/PhraseRecommendationAgent.java @@ -2,35 +2,14 @@ package edu.kit.kastel.mcse.ardoco.core.recommendationgenerator.agents; import java.util.List; -import java.util.SortedMap; -import edu.kit.kastel.mcse.ardoco.core.configuration.Configurable; import edu.kit.kastel.mcse.ardoco.core.data.DataRepository; -import edu.kit.kastel.mcse.ardoco.core.pipeline.agent.Informant; import edu.kit.kastel.mcse.ardoco.core.pipeline.agent.PipelineAgent; import edu.kit.kastel.mcse.ardoco.core.recommendationgenerator.informants.CompoundRecommendationInformant; public final class PhraseRecommendationAgent extends PipelineAgent { - private final List informants; - - @Configurable - private List enabledInformants; - public PhraseRecommendationAgent(DataRepository dataRepository) { - super(PhraseRecommendationAgent.class.getSimpleName(), dataRepository); - - informants = List.of(new CompoundRecommendationInformant(dataRepository)); - enabledInformants = informants.stream().map(e -> e.getClass().getSimpleName()).toList(); - } - - @Override - protected List getEnabledPipelineSteps() { - return findByClassName(enabledInformants, informants); - } - - @Override - protected void delegateApplyConfigurationToInternalObjects(SortedMap additionalConfiguration) { - informants.forEach(e -> e.applyConfiguration(additionalConfiguration)); + super(List.of(new CompoundRecommendationInformant(dataRepository)), PhraseRecommendationAgent.class.getSimpleName(), dataRepository); } } diff --git a/stages/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/core/textextraction/TextExtraction.java b/stages/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/core/textextraction/TextExtraction.java index 6f0798308..5dc1f552c 100644 --- a/stages/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/core/textextraction/TextExtraction.java +++ b/stages/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/core/textextraction/TextExtraction.java @@ -4,15 +4,9 @@ import java.util.List; import java.util.SortedMap; -import org.eclipse.collections.api.factory.Lists; -import org.eclipse.collections.api.list.MutableList; - import edu.kit.kastel.mcse.ardoco.core.api.textextraction.TextState; -import edu.kit.kastel.mcse.ardoco.core.configuration.Configurable; import edu.kit.kastel.mcse.ardoco.core.data.DataRepository; import edu.kit.kastel.mcse.ardoco.core.pipeline.AbstractExecutionStage; -import edu.kit.kastel.mcse.ardoco.core.pipeline.agent.Agent; -import edu.kit.kastel.mcse.ardoco.core.pipeline.agent.PipelineAgent; import edu.kit.kastel.mcse.ardoco.core.textextraction.agents.InitialTextAgent; import edu.kit.kastel.mcse.ardoco.core.textextraction.agents.PhraseAgent; @@ -21,20 +15,12 @@ */ public class TextExtraction extends AbstractExecutionStage { - private final MutableList agents; - - @Configurable - private List enabledAgents; - /** * Instantiates a new text extractor. */ public TextExtraction(DataRepository dataRepository) { - super("TextExtraction", dataRepository); - this.agents = Lists.mutable.of(// - new InitialTextAgent(dataRepository),// - new PhraseAgent(dataRepository)); - this.enabledAgents = agents.collect(Agent::getId); + super(List.of(new InitialTextAgent(dataRepository), new PhraseAgent(dataRepository)), TextExtraction.class.getSimpleName(), dataRepository); + } /** @@ -59,17 +45,4 @@ protected void initializeState() { dataRepository.addData(TextState.ID, textState); } } - - @Override - protected List getEnabledAgents() { - return findByClassName(enabledAgents, agents); - } - - @Override - protected void delegateApplyConfigurationToInternalObjects(SortedMap additionalConfiguration) { - super.delegateApplyConfigurationToInternalObjects(additionalConfiguration); - for (var agent : agents) { - agent.applyConfiguration(additionalConfiguration); - } - } } diff --git a/stages/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/core/textextraction/agents/InitialTextAgent.java b/stages/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/core/textextraction/agents/InitialTextAgent.java index c3d3316b3..b75d048aa 100644 --- a/stages/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/core/textextraction/agents/InitialTextAgent.java +++ b/stages/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/core/textextraction/agents/InitialTextAgent.java @@ -2,12 +2,8 @@ package edu.kit.kastel.mcse.ardoco.core.textextraction.agents; import java.util.List; -import java.util.SortedMap; -import edu.kit.kastel.mcse.ardoco.core.configuration.Configurable; import edu.kit.kastel.mcse.ardoco.core.data.DataRepository; -import edu.kit.kastel.mcse.ardoco.core.pipeline.AbstractPipelineStep; -import edu.kit.kastel.mcse.ardoco.core.pipeline.agent.Informant; import edu.kit.kastel.mcse.ardoco.core.pipeline.agent.PipelineAgent; import edu.kit.kastel.mcse.ardoco.core.textextraction.informants.InDepArcsInformant; import edu.kit.kastel.mcse.ardoco.core.textextraction.informants.NounInformant; @@ -19,29 +15,13 @@ */ public class InitialTextAgent extends PipelineAgent { - private final List informants; - - @Configurable - private List enabledInformants; - /** * Instantiates a new initial text agent. * * @param data the {@link DataRepository} */ public InitialTextAgent(DataRepository data) { - super(InitialTextAgent.class.getSimpleName(), data); - informants = List.of(new NounInformant(data), new InDepArcsInformant(data), new OutDepArcsInformant(data), new SeparatedNamesInformant(data)); - enabledInformants = informants.stream().map(AbstractPipelineStep::getId).toList(); - } - - @Override - protected void delegateApplyConfigurationToInternalObjects(SortedMap additionalConfiguration) { - informants.forEach(e -> e.applyConfiguration(additionalConfiguration)); - } - - @Override - protected List getEnabledPipelineSteps() { - return findByClassName(enabledInformants, informants); + super(List.of(new NounInformant(data), new InDepArcsInformant(data), new OutDepArcsInformant(data), new SeparatedNamesInformant(data)), + InitialTextAgent.class.getSimpleName(), data); } } diff --git a/stages/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/core/textextraction/agents/MappingCombiner.java b/stages/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/core/textextraction/agents/MappingCombiner.java index 8bad57fe6..2a1a441be 100644 --- a/stages/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/core/textextraction/agents/MappingCombiner.java +++ b/stages/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/core/textextraction/agents/MappingCombiner.java @@ -2,35 +2,13 @@ package edu.kit.kastel.mcse.ardoco.core.textextraction.agents; import java.util.List; -import java.util.SortedMap; -import edu.kit.kastel.mcse.ardoco.core.configuration.Configurable; import edu.kit.kastel.mcse.ardoco.core.data.DataRepository; -import edu.kit.kastel.mcse.ardoco.core.pipeline.AbstractPipelineStep; -import edu.kit.kastel.mcse.ardoco.core.pipeline.agent.Informant; import edu.kit.kastel.mcse.ardoco.core.pipeline.agent.PipelineAgent; import edu.kit.kastel.mcse.ardoco.core.textextraction.informants.MappingCombinerInformant; public class MappingCombiner extends PipelineAgent { - - private final List informants; - - @Configurable - private List enabledInformants; - public MappingCombiner(DataRepository dataRepository) { - super(MappingCombiner.class.getSimpleName(), dataRepository); - informants = List.of(new MappingCombinerInformant(dataRepository)); - enabledInformants = informants.stream().map(AbstractPipelineStep::getId).toList(); - } - - @Override - protected List getEnabledPipelineSteps() { - return findByClassName(enabledInformants, informants); - } - - @Override - protected void delegateApplyConfigurationToInternalObjects(SortedMap additionalConfiguration) { - informants.forEach(e -> e.applyConfiguration(additionalConfiguration)); + super(List.of(new MappingCombinerInformant(dataRepository)), MappingCombiner.class.getSimpleName(), dataRepository); } } diff --git a/stages/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/core/textextraction/agents/PhraseAgent.java b/stages/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/core/textextraction/agents/PhraseAgent.java index 027b13aba..6238cc1e1 100644 --- a/stages/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/core/textextraction/agents/PhraseAgent.java +++ b/stages/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/core/textextraction/agents/PhraseAgent.java @@ -2,13 +2,9 @@ package edu.kit.kastel.mcse.ardoco.core.textextraction.agents; import java.util.List; -import java.util.SortedMap; import edu.kit.kastel.mcse.ardoco.core.api.textextraction.NounMapping; -import edu.kit.kastel.mcse.ardoco.core.configuration.Configurable; import edu.kit.kastel.mcse.ardoco.core.data.DataRepository; -import edu.kit.kastel.mcse.ardoco.core.pipeline.AbstractPipelineStep; -import edu.kit.kastel.mcse.ardoco.core.pipeline.agent.Informant; import edu.kit.kastel.mcse.ardoco.core.pipeline.agent.PipelineAgent; import edu.kit.kastel.mcse.ardoco.core.textextraction.informants.CompoundAgentInformant; @@ -17,30 +13,13 @@ */ public class PhraseAgent extends PipelineAgent { - private final List informants; - - @Configurable - private List enabledInformants; - /** * Instantiates a new initial text agent. * * @param dataRepository the {@link DataRepository} */ public PhraseAgent(DataRepository dataRepository) { - super(PhraseAgent.class.getSimpleName(), dataRepository); - informants = List.of(new CompoundAgentInformant(dataRepository)); - enabledInformants = informants.stream().map(AbstractPipelineStep::getId).toList(); - } - - @Override - protected List getEnabledPipelineSteps() { - return findByClassName(enabledInformants, informants); - } - - @Override - protected void delegateApplyConfigurationToInternalObjects(SortedMap additionalConfiguration) { - informants.forEach(e -> e.applyConfiguration(additionalConfiguration)); + super(List.of(new CompoundAgentInformant(dataRepository)), PhraseAgent.class.getSimpleName(), dataRepository); } } diff --git a/stages/text-preprocessing/src/main/java/edu/kit/kastel/mcse/ardoco/core/text/providers/TextPreprocessingAgent.java b/stages/text-preprocessing/src/main/java/edu/kit/kastel/mcse/ardoco/core/text/providers/TextPreprocessingAgent.java index 858e7f828..3f6907e1a 100644 --- a/stages/text-preprocessing/src/main/java/edu/kit/kastel/mcse/ardoco/core/text/providers/TextPreprocessingAgent.java +++ b/stages/text-preprocessing/src/main/java/edu/kit/kastel/mcse/ardoco/core/text/providers/TextPreprocessingAgent.java @@ -5,29 +5,19 @@ import java.util.SortedMap; import edu.kit.kastel.mcse.ardoco.core.api.text.NlpInformant; -import edu.kit.kastel.mcse.ardoco.core.configuration.Configurable; import edu.kit.kastel.mcse.ardoco.core.data.DataRepository; -import edu.kit.kastel.mcse.ardoco.core.pipeline.AbstractPipelineStep; -import edu.kit.kastel.mcse.ardoco.core.pipeline.agent.Informant; import edu.kit.kastel.mcse.ardoco.core.pipeline.agent.PipelineAgent; import edu.kit.kastel.mcse.ardoco.core.text.providers.informants.corenlp.CoreNLPProvider; public class TextPreprocessingAgent extends PipelineAgent { - private final List informants; - - @Configurable - private List enabledInformants; - /** * Instantiates a new initial text agent. * * @param data the {@link DataRepository} */ public TextPreprocessingAgent(DataRepository data) { - super(TextPreprocessingAgent.class.getSimpleName(), data); - informants = List.of(new CoreNLPProvider(data)); - enabledInformants = informants.stream().map(AbstractPipelineStep::getId).toList(); + super(List.of(new CoreNLPProvider(data)), TextPreprocessingAgent.class.getSimpleName(), data); } /** @@ -42,14 +32,4 @@ public static TextPreprocessingAgent get(SortedMap additionalCon textProvider.applyConfiguration(additionalConfigs); return textProvider; } - - @Override - protected void delegateApplyConfigurationToInternalObjects(SortedMap additionalConfiguration) { - informants.forEach(e -> e.applyConfiguration(additionalConfiguration)); - } - - @Override - protected List getEnabledPipelineSteps() { - return findByClassName(enabledInformants, informants); - } } diff --git a/tests/tests-base/src/main/java/edu/kit/kastel/mcse/ardoco/core/tests/eval/ConfigurationTestBase.java b/tests/tests-base/src/main/java/edu/kit/kastel/mcse/ardoco/core/tests/eval/ConfigurationTestBase.java index 4fff773ac..e617c8829 100644 --- a/tests/tests-base/src/main/java/edu/kit/kastel/mcse/ardoco/core/tests/eval/ConfigurationTestBase.java +++ b/tests/tests-base/src/main/java/edu/kit/kastel/mcse/ardoco/core/tests/eval/ConfigurationTestBase.java @@ -90,7 +90,7 @@ protected void processConfigurationOfClass(Map configs, Class fields, Map configs) throws IllegalAccessException { for (Field f : fields) { f.setAccessible(true); - var key = f.getDeclaringClass().getSimpleName() + AbstractConfigurable.CLASS_ATTRIBUTE_CONNECTOR + f.getName(); + var key = AbstractConfigurable.getKeyOfField(object, f.getDeclaringClass(), f); var rawValue = f.get(object); var value = getValue(rawValue); if (configs.containsKey(key)) { diff --git a/tests/tests-inconsistency/src/test/java/edu/kit/kastel/mcse/ardoco/core/tests/eval/baseline/InconsistencyBaseline.java b/tests/tests-inconsistency/src/test/java/edu/kit/kastel/mcse/ardoco/core/tests/eval/baseline/InconsistencyBaseline.java index ded0eeed4..aaa6cc6f6 100644 --- a/tests/tests-inconsistency/src/test/java/edu/kit/kastel/mcse/ardoco/core/tests/eval/baseline/InconsistencyBaseline.java +++ b/tests/tests-inconsistency/src/test/java/edu/kit/kastel/mcse/ardoco/core/tests/eval/baseline/InconsistencyBaseline.java @@ -5,7 +5,6 @@ import edu.kit.kastel.mcse.ardoco.core.data.DataRepository; import edu.kit.kastel.mcse.ardoco.core.pipeline.AbstractExecutionStage; -import edu.kit.kastel.mcse.ardoco.core.pipeline.agent.PipelineAgent; /** * Baseline approach for inconsistency detection @@ -13,16 +12,11 @@ public class InconsistencyBaseline extends AbstractExecutionStage { public InconsistencyBaseline(DataRepository dataRepository) { - super("InconsistencyBaseline", dataRepository); + super(List.of(new InconsistencyBaselineAgent(dataRepository)), "InconsistencyBaseline", dataRepository); } @Override protected void initializeState() { // do nothing } - - @Override - protected List getEnabledAgents() { - return List.of(new InconsistencyBaselineAgent(getDataRepository())); - } } diff --git a/tests/tests-inconsistency/src/test/java/edu/kit/kastel/mcse/ardoco/core/tests/eval/baseline/InconsistencyBaselineAgent.java b/tests/tests-inconsistency/src/test/java/edu/kit/kastel/mcse/ardoco/core/tests/eval/baseline/InconsistencyBaselineAgent.java index 8fd395293..3a330670f 100644 --- a/tests/tests-inconsistency/src/test/java/edu/kit/kastel/mcse/ardoco/core/tests/eval/baseline/InconsistencyBaselineAgent.java +++ b/tests/tests-inconsistency/src/test/java/edu/kit/kastel/mcse/ardoco/core/tests/eval/baseline/InconsistencyBaselineAgent.java @@ -4,20 +4,13 @@ import java.util.List; import edu.kit.kastel.mcse.ardoco.core.data.DataRepository; -import edu.kit.kastel.mcse.ardoco.core.pipeline.agent.Informant; import edu.kit.kastel.mcse.ardoco.core.pipeline.agent.PipelineAgent; /** * Agent for {@link InconsistencyBaseline} */ public class InconsistencyBaselineAgent extends PipelineAgent { - protected InconsistencyBaselineAgent(DataRepository dataRepository) { - super(InconsistencyBaselineAgent.class.getSimpleName(), dataRepository); - } - - @Override - protected List getEnabledPipelineSteps() { - return List.of(new InconsistencyBaselineInformant(getDataRepository())); + super(List.of(new InconsistencyBaselineInformant(dataRepository)), InconsistencyBaselineAgent.class.getSimpleName(), dataRepository); } }