Commit 4d491196 authored by Simon Barner's avatar Simon Barner
Browse files

Avoid code clone and improve documentation of "covered" allocation types

Issue-Ref: 3735
Issue-Url: https://af3-developer.fortiss.org/issues/3735

Signed-off-by: Simon Barner's avatarSimon Barner <barner@fortiss.org>
parent 4a0d591e
AF3AllocationActivator.java fa98bbdbd34d9d3c76f7f2827f2f456105c90fa6 GREEN
IAllocationService.java d937da9be337e0fe063c18faa9a598b6c0ee5d00 GREEN
IAllocationService.java 2913979f5c4f76c9ab13c90d2fdb4872d2707002 YELLOW
......@@ -20,6 +20,7 @@ import java.util.Collection;
import org.fortiss.af3.allocation.internal.AllocationService;
import org.fortiss.af3.allocation.model.AllocationEntry;
import org.fortiss.af3.allocation.model.AllocationTable;
import org.fortiss.af3.allocation.model.AllocationTableCollection;
import org.fortiss.af3.allocation.model.IAllocationType;
import org.fortiss.tooling.base.model.element.IModelElement;
import org.fortiss.tooling.kernel.model.IProjectRootElement;
......@@ -170,8 +171,12 @@ public interface IAllocationService {
Class<? extends IProjectRootElement> targetModelType);
/**
* Returns the model types that are covered by the given {@link AllocationTable}
* specialization (in addition to its source/target model type).
* Returns the model types that are "covered" by the given {@link AllocationTable}
* specialization (in addition to its source/target model type). This means that the
* {@link AllocationTable} of the provided {@code atType} cannot exist within the same
* {@link AllocationTableCollection} since there is another {@link AllocationTable} that skips
* it. For example, a component-to-execution {@link AllocationTable} covers both the
* component-to-task and the task-to-execution unit {@link AllocationTable}.
*/
public Collection<Class<? extends IProjectRootElement>>
getCoveredModelTypes(Class<? extends AllocationTable> allocationTableType);
......
AllocationTableCollectionCompositorBase.java 03ad5e0c2e788d46ecf55c7a7dab45501e3f9277 RED
AllocationTableCollectionCompositorBase.java c163e6780f2c1e25607260cc7af0494812c5e2a0 YELLOW
AllocationTableCollectionFileProjectCompositor.java acae4d3f3f3b07d4c1d235dfc224c83a50b8e3d8 GREEN
ParameterTableCompositorBase.java 7164f1e3be098024652f8df7515984021d914062 GREEN
......@@ -130,43 +130,30 @@ public abstract class AllocationTableCollectionCompositorBase
// Check if source or target model has not already been occupied by another allocation table
for(AllocationTable at : container.getAllocationTables()) {
Class<? extends AllocationTable> atType = getAllocationTableType(at.getClass());
Class<? extends AllocationTable> currAtType = getAllocationTableType(at.getClass());
// Skip check for allocation tables of the same type (only relevant if
// maxAllocationTableInstances != 1)
if(allocationTableType.isAssignableFrom(atType)) {
if(allocationTableType.isAssignableFrom(currAtType)) {
continue;
}
// Skip check also for registered exceptions
if(as.getAdmissibleAllocationTables(allocationTableType).contains(atType)) {
if(as.getAdmissibleAllocationTables(allocationTableType).contains(currAtType)) {
continue;
}
final Collection<Class<? extends IProjectRootElement>> currSourceModelTypes =
as.getSourceModelTypes(currAtType);
final Collection<Class<? extends IProjectRootElement>> currTargetModelTypes =
as.getTargetModelTypes(currAtType);
// Check if source/target view of existing allocation table causes an overlap
final Collection<Class<? extends IProjectRootElement>> sourceViewTypes =
as.getSourceModelTypes(atType);
final Collection<Class<? extends IProjectRootElement>> targetViewTypes =
as.getTargetModelTypes(atType);
if(isAnyRootElementAssignable(sourceModelTypes, sourceViewTypes) ||
isAnyRootElementAssignable(targetModelTypes, targetViewTypes)) {
if(isAnyRootElementAssignable(sourceModelTypes, currSourceModelTypes) ||
isAnyRootElementAssignable(targetModelTypes, currTargetModelTypes)) {
return false;
}
// Check for overlaps due to model types that are additionally covered
// TODO(AD): Please add an example what "additionally covered model types" are (ports)?
// TODO(AD): Please indicate the difference between the following 6 LoC and the next
// ones. They look quite similar.
Collection<Class<? extends IProjectRootElement>> atTypeCoveredModelTypes =
as.getCoveredModelTypes(atType);
if(isAnyRootElementAssignable(atTypeCoveredModelTypes, sourceModelTypes) ||
isAnyRootElementAssignable(as.getCoveredModelTypes(atType), targetModelTypes)) {
return false;
}
Collection<Class<? extends IProjectRootElement>> allocationTableTypeCoveredModelTypes =
as.getCoveredModelTypes(allocationTableType);
if(isAnyRootElementAssignable(allocationTableTypeCoveredModelTypes, sourceModelTypes) ||
isAnyRootElementAssignable(allocationTableTypeCoveredModelTypes,
targetModelTypes)) {
if(isCoveredModelType(currAtType, sourceModelTypes, targetModelTypes) ||
isCoveredModelType(allocationTableType, sourceModelTypes, targetModelTypes)) {
return false;
}
}
......@@ -175,6 +162,23 @@ public abstract class AllocationTableCollectionCompositorBase
}
/**
* Predicate if any of the provided {@code sourceModelTypes} or {@code targeModelTypes} are
* covered by the provided {@code atType}.
*
* @see IAllocationService#getCoveredModelTypes(Class)
*/
private boolean isCoveredModelType(Class<? extends AllocationTable> atType,
Collection<Class<? extends IProjectRootElement>> sourceModelTypes,
Collection<Class<? extends IProjectRootElement>> targetModelTypes) {
IAllocationService as = IAllocationService.getInstance();
Collection<Class<? extends IProjectRootElement>> coveredModelTypes =
as.getCoveredModelTypes(atType);
return isAnyRootElementAssignable(coveredModelTypes, sourceModelTypes) ||
isAnyRootElementAssignable(coveredModelTypes, targetModelTypes);
}
/** {@inheritDoc} */
@Override
public boolean canComposePrototype(Prototype prototype) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment