Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enforce determinism in ArDoCo by architecture tests #260

Merged
merged 20 commits into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
import edu.kit.kastel.mcse.ardoco.core.api.models.tracelinks.SadCodeTraceLink;
import edu.kit.kastel.mcse.ardoco.core.api.models.tracelinks.SamCodeTraceLink;
import edu.kit.kastel.mcse.ardoco.core.api.models.tracelinks.TransitiveTraceLink;
import edu.kit.kastel.mcse.ardoco.core.architecture.Deterministic;
import edu.kit.kastel.mcse.ardoco.core.data.PipelineStepData;

@Deterministic
public interface CodeTraceabilityState extends PipelineStepData {
String ID = "CodeTraceabilityState";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@
import edu.kit.kastel.mcse.ardoco.core.api.models.tracelinks.InstanceLink;
import edu.kit.kastel.mcse.ardoco.core.api.models.tracelinks.SadSamTraceLink;
import edu.kit.kastel.mcse.ardoco.core.api.recommendationgenerator.RecommendedInstance;
import edu.kit.kastel.mcse.ardoco.core.architecture.Deterministic;
import edu.kit.kastel.mcse.ardoco.core.configuration.IConfigurable;
import edu.kit.kastel.mcse.ardoco.core.pipeline.agent.Claimant;

/**
* The Interface IConnectionState.
*/
@Deterministic
public interface ConnectionState extends IConfigurable {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/**
* A model element. Has an identifier. Two model elements are equal if and only if they have the same identifier.
*/
public abstract class ModelElement {
public abstract class ModelElement implements Comparable<ModelElement> {

private final String id;

Expand Down Expand Up @@ -38,4 +38,11 @@ public boolean equals(Object obj) {
}
return Objects.equals(id, other.id);
}

@Override
public int compareTo(ModelElement o) {
if (this.equals(o))
return 0;
return this.id.compareTo(o.id);
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
/* Licensed under MIT 2021-2023. */
package edu.kit.kastel.mcse.ardoco.core.api.models;

import java.util.Set;

import org.eclipse.collections.api.list.ImmutableList;
import org.eclipse.collections.api.set.ImmutableSet;
import org.eclipse.collections.api.set.sorted.ImmutableSortedSet;

import edu.kit.kastel.mcse.ardoco.core.configuration.IConfigurable;

Expand Down Expand Up @@ -39,14 +37,14 @@ public interface ModelExtractionState extends IConfigurable {
*
* @return all instance types of this state
*/
ImmutableSet<String> getInstanceTypes();
ImmutableSortedSet<String> getInstanceTypes();

/**
* Returns all names that are contained by this state.
*
* @return all names of this state
*/
Set<String> getNames();
ImmutableSortedSet<String> getNames();

/**
* Returns all instances that are contained by this state.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
/* Licensed under MIT 2022-2023. */
package edu.kit.kastel.mcse.ardoco.core.api.models;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.SortedMap;
import java.util.SortedSet;
import java.util.TreeMap;
import java.util.TreeSet;

import edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.Model;
import edu.kit.kastel.mcse.ardoco.core.data.PipelineStepData;

public class ModelStates implements PipelineStepData {
public static final String ID = "ModelStatesData";

private transient Map<String, ModelExtractionState> modelExtractionStates = new HashMap<>();
private transient Map<String, Model> models = new HashMap<>();
private transient SortedMap<String, ModelExtractionState> modelExtractionStates = new TreeMap<>();
private transient SortedMap<String, Model> models = new TreeMap<>();

/**
* Constructor to create a {@link ModelStates} object that holds all {@link ModelExtractionState}s
Expand Down Expand Up @@ -46,17 +47,17 @@ public void addModelExtractionState(String id, ModelExtractionState modelState)
*
* @return the IDs of all contained {@link ModelExtractionState ModelExtractionStates}
*/
public Set<String> extractionModelIds() {
return modelExtractionStates.keySet();
public SortedSet<String> extractionModelIds() {
return new TreeSet<>(modelExtractionStates.keySet());
}

/**
* Return the set of IDs of all {@link Model Models} that are contained within this object.
*
* @return the IDs of all contained {@link Model Models}
*/
public Set<String> modelIds() {
return models.keySet();
public SortedSet<String> modelIds() {
return new TreeSet<>(models.keySet());
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* Licensed under MIT 2023. */
package edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.architecture;

import java.util.Set;
import java.util.SortedSet;

/**
* A representation of the model object <i>Component</i> from AMTL. Components
Expand All @@ -12,13 +12,13 @@
*/
public class ArchitectureComponent extends ArchitectureItem {

private final Set<ArchitectureComponent> subcomponents;
private final Set<ArchitectureInterface> providedInterfaces;
private final SortedSet<ArchitectureComponent> subcomponents;
private final SortedSet<ArchitectureInterface> providedInterfaces;

private final Set<ArchitectureInterface> requiredInterfaces;
private final SortedSet<ArchitectureInterface> requiredInterfaces;

public ArchitectureComponent(String name, String id, Set<ArchitectureComponent> subcomponents, Set<ArchitectureInterface> providedInterfaces,
Set<ArchitectureInterface> requiredInterfaces) {
public ArchitectureComponent(String name, String id, SortedSet<ArchitectureComponent> subcomponents, SortedSet<ArchitectureInterface> providedInterfaces,
SortedSet<ArchitectureInterface> requiredInterfaces) {
super(name, id);
this.subcomponents = subcomponents;
this.providedInterfaces = providedInterfaces;
Expand All @@ -30,7 +30,7 @@ public ArchitectureComponent(String name, String id, Set<ArchitectureComponent>
*
* @return the subcomponents of this component
*/
public Set<ArchitectureComponent> getSubcomponents() {
public SortedSet<ArchitectureComponent> getSubcomponents() {
return subcomponents;
}

Expand All @@ -40,7 +40,7 @@ public Set<ArchitectureComponent> getSubcomponents() {
*
* @return the provided interfaces of this component
*/
public Set<ArchitectureInterface> getProvidedInterfaces() {
public SortedSet<ArchitectureInterface> getProvidedInterfaces() {
return providedInterfaces;
}

Expand All @@ -50,7 +50,7 @@ public Set<ArchitectureInterface> getProvidedInterfaces() {
*
* @return the required interfaces of this component
*/
public Set<ArchitectureInterface> getRequiredInterfaces() {
public SortedSet<ArchitectureInterface> getRequiredInterfaces() {
return requiredInterfaces;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
package edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.architecture;

import java.util.Objects;
import java.util.Set;
import java.util.SortedSet;

public class ArchitectureInterface extends ArchitectureItem {

private final Set<ArchitectureMethod> signatures;
private final SortedSet<ArchitectureMethod> signatures;

public ArchitectureInterface(String name, String id, Set<ArchitectureMethod> signatures) {
public ArchitectureInterface(String name, String id, SortedSet<ArchitectureMethod> signatures) {
super(name, id);
this.signatures = signatures;
}

public Set<ArchitectureMethod> getSignatures() {
public SortedSet<ArchitectureMethod> getSignatures() {
return signatures;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.SortedSet;

import com.fasterxml.jackson.annotation.JsonGetter;
import com.fasterxml.jackson.annotation.JsonProperty;
Expand All @@ -20,7 +20,7 @@ private ClassUnit() {
content = new ArrayList<>();
}

public ClassUnit(CodeItemRepository codeItemRepository, String name, Set<? extends CodeItem> content) {
public ClassUnit(CodeItemRepository codeItemRepository, String name, SortedSet<? extends CodeItem> content) {
super(codeItemRepository, name);
this.content = new ArrayList<>();
for (var codeItem : content) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* Licensed under MIT 2023. */
package edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.code;

import java.util.Set;
import java.util.SortedSet;

import com.fasterxml.jackson.annotation.JsonTypeName;

Expand All @@ -12,7 +12,7 @@ private CodeAssembly() {
// Jackson
}

public CodeAssembly(CodeItemRepository codeItemRepository, String name, Set<? extends CodeItem> content) {
public CodeAssembly(CodeItemRepository codeItemRepository, String name, SortedSet<? extends CodeItem> content) {
super(codeItemRepository, name, content);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
package edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.code;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeName;
Expand All @@ -29,8 +29,8 @@ private CodeCompilationUnit() {
// Jackson
}

public CodeCompilationUnit(CodeItemRepository codeItemRepository, String name, Set<? extends CodeItem> content, List<String> pathElements, String extension,
ProgrammingLanguage language) {
public CodeCompilationUnit(CodeItemRepository codeItemRepository, String name, SortedSet<? extends CodeItem> content, List<String> pathElements,
String extension, ProgrammingLanguage language) {
super(codeItemRepository, name, content);
this.pathElements = new ArrayList<>(pathElements);
this.extension = extension;
Expand All @@ -49,8 +49,8 @@ public List<Datatype> getAllDataTypes() {
}

@Override
public Set<CodeCompilationUnit> getAllCompilationUnits() {
Set<CodeCompilationUnit> result = new HashSet<>();
public SortedSet<CodeCompilationUnit> getAllCompilationUnits() {
SortedSet<CodeCompilationUnit> result = new TreeSet<>();
result.add(this);
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
package edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.code;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonSubTypes;
Expand Down Expand Up @@ -60,14 +60,14 @@ public List<Datatype> getAllDataTypes() {
return new ArrayList<>();
}

public Set<CodeItem> getAllDataTypesAndSelf() {
Set<CodeItem> result = new HashSet<>(getAllDataTypes());
public SortedSet<CodeItem> getAllDataTypesAndSelf() {
SortedSet<CodeItem> result = new TreeSet<>(getAllDataTypes());
result.add(this);
return result;
}

public Set<ControlElement> getDeclaredMethods() {
Set<ControlElement> methods = new HashSet<>();
public SortedSet<ControlElement> getDeclaredMethods() {
SortedSet<ControlElement> methods = new TreeSet<>();
for (CodeItem codeItem : getContent()) {
if (codeItem instanceof ControlElement codeMethod) {
methods.add(codeMethod);
Expand All @@ -76,11 +76,11 @@ public Set<ControlElement> getDeclaredMethods() {
return methods;
}

public Set<CodeCompilationUnit> getAllCompilationUnits() {
return new HashSet<>();
public SortedSet<CodeCompilationUnit> getAllCompilationUnits() {
return new TreeSet<>();
}

public Set<? extends CodePackage> getAllPackages() {
return new HashSet<>();
public SortedSet<? extends CodePackage> getAllPackages() {
return new TreeSet<>();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
package edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.code;

import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.SortedMap;

import org.eclipse.collections.api.factory.Maps;
import org.eclipse.collections.api.factory.SortedMaps;

import com.fasterxml.jackson.annotation.JsonProperty;

public class CodeItemRepository {

@JsonProperty
private final Map<String, CodeItem> repository = Maps.mutable.empty();
private final SortedMap<String, CodeItem> repository = SortedMaps.mutable.empty();

public Map<String, CodeItem> getRepository() {
public SortedMap<String, CodeItem> getRepository() {
return repository;
}

Expand All @@ -27,6 +27,8 @@ boolean containsCodeItem(String id) {
}

CodeItem getCodeItem(String id) {
if (id == null)
return null;
return repository.get(id);
}

Expand Down
Loading