diff --git a/org.fortiss.tooling.ext.quality.ui/src/org/fortiss/tooling/ext/quality/ui/view/fx/.ratings b/org.fortiss.tooling.ext.quality.ui/src/org/fortiss/tooling/ext/quality/ui/view/fx/.ratings index 988b0e6731a953fd80ba5a76c6065f0e87018e42..623d2c92e4b7e44c2bea8eeb92f25b2c46770183 100644 --- a/org.fortiss.tooling.ext.quality.ui/src/org/fortiss/tooling/ext/quality/ui/view/fx/.ratings +++ b/org.fortiss.tooling.ext.quality.ui/src/org/fortiss/tooling/ext/quality/ui/view/fx/.ratings @@ -1,3 +1,3 @@ IModelQualityViewPart.java 708f8089645df12098ea67190805cce343045d2e GREEN -ModelQualityFXController.java c5577d2762eb916835386de5987109fc7899f1bc GREEN +ModelQualityFXController.java 9bbeb277389416bf61031ab884d4ca9ed0c0b669 GREEN ModelQualityFXViewPart.java 9cfc7f60a86ea5b915c726b16712f8be7dec2c5f GREEN diff --git a/org.fortiss.tooling.ext.quality.ui/src/org/fortiss/tooling/ext/quality/ui/view/fx/ModelQualityFXController.java b/org.fortiss.tooling.ext.quality.ui/src/org/fortiss/tooling/ext/quality/ui/view/fx/ModelQualityFXController.java index c5577d2762eb916835386de5987109fc7899f1bc..9bbeb277389416bf61031ab884d4ca9ed0c0b669 100644 --- a/org.fortiss.tooling.ext.quality.ui/src/org/fortiss/tooling/ext/quality/ui/view/fx/ModelQualityFXController.java +++ b/org.fortiss.tooling.ext.quality.ui/src/org/fortiss/tooling/ext/quality/ui/view/fx/ModelQualityFXController.java @@ -42,10 +42,10 @@ import org.fortiss.tooling.common.ui.javafx.layout.CompositeFXControllerBase; import org.fortiss.tooling.common.ui.javafx.style.FillStyle; import org.fortiss.tooling.common.ui.javafx.style.FontStyle; import org.fortiss.tooling.common.ui.javafx.style.LineStyle; -import org.fortiss.tooling.ext.quality.IMetricUpdateListener; import org.fortiss.tooling.ext.quality.data.MetricData; import org.fortiss.tooling.ext.quality.data.MetricKey; import org.fortiss.tooling.ext.quality.data.MetricTreeNode; +import org.fortiss.tooling.ext.quality.service.IMetricUpdateListener; import org.fortiss.tooling.ext.quality.service.IModelQualityService; import org.fortiss.tooling.kernel.model.IProjectRootElement; import org.fortiss.tooling.spiderchart.control.SpiderChartViewer; diff --git a/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/.ratings b/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/.ratings index 44fde8c402ed4300f3e45b7cf81b5dff1f3389ce..f2be5dc25e3a812b7d06b3d81843d2867e0bb775 100644 --- a/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/.ratings +++ b/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/.ratings @@ -1,5 +1,2 @@ -GraphMetricsProvider.java ce70c838b887df0bdf776f462b23cf594c700822 GREEN -HierarchicElementMetricProvider.java 966b3aeef92475034fc35e68ba5344688988b88a GREEN -IMetricProvider.java 99fc8993b0e65b2f8757978eeb0481d912f5608c GREEN -IMetricUpdateListener.java c24dc7c0f282623bbf1eefac1fbbb6752c97ddf0 GREEN +HierarchicElementMetricProvider.java 26859c9a74930039ea3e94f6790eb1549e53d48c GREEN ModelQualityActivator.java 6d5f0794aa48670cf45fb405bd7641bce6c1fec4 GREEN diff --git a/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/HierarchicElementMetricProvider.java b/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/HierarchicElementMetricProvider.java index 966b3aeef92475034fc35e68ba5344688988b88a..26859c9a74930039ea3e94f6790eb1549e53d48c 100644 --- a/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/HierarchicElementMetricProvider.java +++ b/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/HierarchicElementMetricProvider.java @@ -22,12 +22,14 @@ import org.fortiss.tooling.base.model.base.ExitConnectorBase; import org.fortiss.tooling.base.model.element.IHierarchicElement; import org.fortiss.tooling.ext.quality.data.MetricKey; import org.fortiss.tooling.ext.quality.data.MetricTreeNode; +import org.fortiss.tooling.ext.quality.service.IMetricProvider; import org.fortiss.tooling.kernel.model.IIdLabeled; import org.fortiss.tooling.kernel.model.INamedCommentedElement; /** * {@link IMetricProvider} to collect various metrics from an {@link IHierarchicElement}. * + * @author blaschke * @author groh */ public class HierarchicElementMetricProvider implements IMetricProvider<IHierarchicElement> { @@ -53,7 +55,7 @@ public class HierarchicElementMetricProvider implements IMetricProvider<IHierarc } else { intMetrics.put(MetricKey.NUMBER_OF_TOTAL_COMMENTABLE_ELEMENTS, 0); intMetrics.put(MetricKey.NUMBER_OF_TOTAL_COMMENTED_ELEMENTS, 0); - node.setName("No Name existant"); + node.setName("No name existent"); } if(currentElement instanceof IIdLabeled) { diff --git a/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/service/.ratings b/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/service/.ratings index b141dbcb15ec2e74544ca766c2081e19819783ee..018893e1b3424ce382415b2384c5deba9fb8d2b3 100644 --- a/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/service/.ratings +++ b/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/service/.ratings @@ -1,2 +1,4 @@ -IModelQualityService.java db237db72cf1a0905fa82b1dfd799f830d092a10 GREEN -ModelQualityService.java 9b2085c4b4846e4f4f5fc9ad51ede5a04736f163 GREEN +IMetricProvider.java d0b523c03c04491046f46cdcb6e3ff3d1220a762 GREEN +IMetricUpdateListener.java 49272484ae00dfe05ef0e966d9493c1803158476 GREEN +IModelQualityService.java 570086c0b758fd719972d59efc0078cb711e4883 GREEN +ModelQualityService.java 65b18f8e5f7c2919da76cf58ed267dece6418a4a GREEN diff --git a/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/IMetricProvider.java b/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/service/IMetricProvider.java similarity index 93% rename from org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/IMetricProvider.java rename to org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/service/IMetricProvider.java index 99fc8993b0e65b2f8757978eeb0481d912f5608c..d0b523c03c04491046f46cdcb6e3ff3d1220a762 100644 --- a/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/IMetricProvider.java +++ b/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/service/IMetricProvider.java @@ -13,11 +13,10 @@ | See the License for the specific language governing permissions and | | limitations under the License. | +--------------------------------------------------------------------------*/ -package org.fortiss.tooling.ext.quality; +package org.fortiss.tooling.ext.quality.service; import org.eclipse.emf.ecore.EObject; import org.fortiss.tooling.ext.quality.data.MetricTreeNode; -import org.fortiss.tooling.ext.quality.service.IModelQualityService; import org.fortiss.tooling.kernel.service.base.IEObjectAware; /** diff --git a/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/IMetricUpdateListener.java b/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/service/IMetricUpdateListener.java similarity index 97% rename from org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/IMetricUpdateListener.java rename to org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/service/IMetricUpdateListener.java index c24dc7c0f282623bbf1eefac1fbbb6752c97ddf0..49272484ae00dfe05ef0e966d9493c1803158476 100644 --- a/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/IMetricUpdateListener.java +++ b/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/service/IMetricUpdateListener.java @@ -13,7 +13,7 @@ | See the License for the specific language governing permissions and | | limitations under the License. | +--------------------------------------------------------------------------*/ -package org.fortiss.tooling.ext.quality; +package org.fortiss.tooling.ext.quality.service; import org.fortiss.tooling.kernel.model.IProjectRootElement; diff --git a/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/service/IModelQualityService.java b/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/service/IModelQualityService.java index db237db72cf1a0905fa82b1dfd799f830d092a10..570086c0b758fd719972d59efc0078cb711e4883 100644 --- a/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/service/IModelQualityService.java +++ b/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/service/IModelQualityService.java @@ -16,8 +16,6 @@ package org.fortiss.tooling.ext.quality.service; import org.eclipse.emf.ecore.EObject; -import org.fortiss.tooling.ext.quality.IMetricProvider; -import org.fortiss.tooling.ext.quality.IMetricUpdateListener; import org.fortiss.tooling.ext.quality.data.MetricData; import org.fortiss.tooling.kernel.extension.data.ITopLevelElement; diff --git a/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/service/ModelQualityService.java b/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/service/ModelQualityService.java index 9b2085c4b4846e4f4f5fc9ad51ede5a04736f163..65b18f8e5f7c2919da76cf58ed267dece6418a4a 100644 --- a/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/service/ModelQualityService.java +++ b/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/service/ModelQualityService.java @@ -18,6 +18,19 @@ package org.fortiss.tooling.ext.quality.service; import static java.util.Collections.emptyList; import static java.util.Collections.sort; import static java.util.stream.Collectors.groupingBy; +import static org.eclipse.core.runtime.Status.CANCEL_STATUS; +import static org.eclipse.core.runtime.Status.OK_STATUS; +import static org.fortiss.tooling.ext.quality.data.MetricKey.BETWEENESS_CENTRALITY; +import static org.fortiss.tooling.ext.quality.data.MetricKey.BETWEENESS_CENTRALITY_RECURSIVELY; +import static org.fortiss.tooling.ext.quality.data.MetricKey.CLUSTERING_COEFFICIENT; +import static org.fortiss.tooling.ext.quality.data.MetricKey.CONSTRAINT_VIOLATIONS_ERROR; +import static org.fortiss.tooling.ext.quality.data.MetricKey.CONSTRAINT_VIOLATIONS_WARNING; +import static org.fortiss.tooling.ext.quality.data.MetricKey.NESTING_LEVEL; +import static org.fortiss.tooling.ext.quality.storage.ModelQualityStorageManager.MODEL_QUALITY_PROJECT_DIR; +import static org.fortiss.tooling.ext.quality.utils.GraphMetricsUtils.calculateBetweennessCentrality; +import static org.fortiss.tooling.ext.quality.utils.GraphMetricsUtils.calculateClusteringCoefficent; +import static org.fortiss.tooling.kernel.extension.data.IConstraintViolation.ESeverity.ERROR; +import static org.fortiss.tooling.kernel.extension.data.IConstraintViolation.ESeverity.WARNING; import static org.fortiss.tooling.kernel.utils.KernelModelElementUtils.getRootElements; import java.io.IOException; @@ -35,22 +48,16 @@ import java.util.concurrent.ConcurrentLinkedQueue; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.jobs.Job; import org.eclipse.emf.common.util.EList; import org.eclipse.emf.ecore.EObject; import org.fortiss.tooling.base.model.element.IHierarchicElement; -import org.fortiss.tooling.ext.quality.GraphMetricsProvider; -import org.fortiss.tooling.ext.quality.IMetricProvider; -import org.fortiss.tooling.ext.quality.IMetricUpdateListener; import org.fortiss.tooling.ext.quality.data.DataRootElement; import org.fortiss.tooling.ext.quality.data.MetricData; import org.fortiss.tooling.ext.quality.data.MetricKey; import org.fortiss.tooling.ext.quality.data.MetricTreeNode; import org.fortiss.tooling.ext.quality.storage.CSVFileWriter; -import org.fortiss.tooling.ext.quality.storage.ModelQualityStorageManager; import org.fortiss.tooling.kernel.extension.data.IConstraintViolation; -import org.fortiss.tooling.kernel.extension.data.IConstraintViolation.ESeverity; import org.fortiss.tooling.kernel.extension.data.ITopLevelElement; import org.fortiss.tooling.kernel.internal.ConstraintCheckerService; import org.fortiss.tooling.kernel.introspection.IIntrospectionDetailsItem; @@ -66,7 +73,6 @@ import org.fortiss.tooling.kernel.service.listener.IPersistencyServiceListener; * This class implements the {@link IModelQualityService}. * * @author blaschke - * @author groh */ /* package */ class ModelQualityService extends EObjectAwareServiceBase<IMetricProvider<EObject>> implements IIntrospectiveKernelService, IModelQualityService, IPersistencyServiceListener { @@ -98,11 +104,11 @@ import org.fortiss.tooling.kernel.service.listener.IPersistencyServiceListener; // monitor is checked for cancellation at least once. do { if(monitor.isCanceled()) { - return Status.CANCEL_STATUS; + return CANCEL_STATUS; } ITopLevelElement toBeProcessed = queuedProcessableElements.poll(); if(toBeProcessed == null) { - return Status.OK_STATUS; + return OK_STATUS; } try { performMetricCollection(toBeProcessed); @@ -176,7 +182,7 @@ import org.fortiss.tooling.kernel.service.listener.IPersistencyServiceListener; List<IProjectRootElement> rootElements = new ArrayList<>( getRootElements(topLevelElement.getRootModelElement(), IProjectRootElement.class)); - // TODO(#XXX): Remove below workaround that makes assumptions on the overall structure of + // TODO(#4333): Remove below workaround that makes assumptions on the overall structure of // the model, and its implementation. String allocationTableClassName = "org.fortiss.af3.allocation.model.impl.AllocationTableCollectionImpl"; @@ -217,10 +223,10 @@ import org.fortiss.tooling.kernel.service.listener.IPersistencyServiceListener; // Collect violations and store them in the error and warning metric List<IConstraintViolation<? extends EObject>> violations = entry.getValue(); var integers = node.getIntegerMetrics(); - integers.put(MetricKey.CONSTRAINT_VIOLATIONS_ERROR, (int)violations.stream() - .filter(v -> v.getSeverity() == ESeverity.ERROR).count()); - integers.put(MetricKey.CONSTRAINT_VIOLATIONS_WARNING, (int)violations.stream() - .filter(v -> v.getSeverity() == ESeverity.WARNING).count()); + integers.put(CONSTRAINT_VIOLATIONS_ERROR, + (int)violations.stream().filter(v -> v.getSeverity() == ERROR).count()); + integers.put(CONSTRAINT_VIOLATIONS_WARNING, (int)violations.stream() + .filter(v -> v.getSeverity() == WARNING).count()); } } @@ -250,7 +256,7 @@ import org.fortiss.tooling.kernel.service.listener.IPersistencyServiceListener; int recursionLevel) { collectMetrics(node, currentElement); - node.getIntegerMetrics().put(MetricKey.NESTING_LEVEL, recursionLevel); + node.getIntegerMetrics().put(NESTING_LEVEL, recursionLevel); // Check if any of the specifications is an IHierarchicElement // This is for example the case for AF3 StateAutomatons @@ -297,13 +303,30 @@ import org.fortiss.tooling.kernel.service.listener.IPersistencyServiceListener; metricDataContainer.getTreeNodeLookupTable().put(currentElement, node); - // TODO (#4332) Restructure GraphMetricsProvider in quality Plugin - GraphMetricsProvider.calculateBetweennessCentrality(currentElement, metricDataContainer, - false); - GraphMetricsProvider.calculateBetweennessCentrality(currentElement, metricDataContainer, - true); - node.getDoubleMetrics().put(MetricKey.CLUSTERING_COEFFICIENT, - GraphMetricsProvider.calculateClusteringCoefficent(currentElement)); + // TODO (#4333)The quality Service should also not set the metrics, only the metric + // provider should + // include some value or MetrikKey into the MetricTreeNode + + Map<IHierarchicElement, Double> nonRecursiveBetweeness = + calculateBetweennessCentrality(currentElement, false); + Map<IHierarchicElement, Double> recursiveBetweeness = + calculateBetweennessCentrality(currentElement, true); + + saveMetric(currentElement, metricDataContainer, BETWEENESS_CENTRALITY, + nonRecursiveBetweeness); + saveMetric(currentElement, metricDataContainer, BETWEENESS_CENTRALITY_RECURSIVELY, + recursiveBetweeness); + node.getDoubleMetrics().put(CLUSTERING_COEFFICIENT, + calculateClusteringCoefficent(currentElement)); + } + } + + /** Saving the metrics for each contained element of an {@link IHierarchicElement}. */ + private static void saveMetric(IHierarchicElement scopeElement, MetricData metricData, + MetricKey key, Map<IHierarchicElement, Double> betweenness) { + for(IHierarchicElement child : scopeElement.getContainedElements()) { + MetricTreeNode node = metricData.getTreeNodeLookupTable().get(child); + node.getDoubleMetrics().put(key, betweenness.get(child)); } } @@ -412,8 +435,8 @@ import org.fortiss.tooling.kernel.service.listener.IPersistencyServiceListener; /** {@inheritDoc} */ @Override public void createQualityFolder() { - if(!ModelQualityStorageManager.MODEL_QUALITY_PROJECT_DIR.exists()) { - ModelQualityStorageManager.MODEL_QUALITY_PROJECT_DIR.mkdirs(); + if(!MODEL_QUALITY_PROJECT_DIR.exists()) { + MODEL_QUALITY_PROJECT_DIR.mkdirs(); } } } diff --git a/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/utils/.ratings b/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/utils/.ratings new file mode 100644 index 0000000000000000000000000000000000000000..8ae6727767e336ee5759ee0f1d90876e696e2b49 --- /dev/null +++ b/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/utils/.ratings @@ -0,0 +1 @@ +GraphMetricsUtils.java 6303342a7ce06f9a331b96b0c80161115453eb82 GREEN diff --git a/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/GraphMetricsProvider.java b/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/utils/GraphMetricsUtils.java similarity index 91% rename from org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/GraphMetricsProvider.java rename to org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/utils/GraphMetricsUtils.java index ce70c838b887df0bdf776f462b23cf594c700822..6303342a7ce06f9a331b96b0c80161115453eb82 100644 --- a/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/GraphMetricsProvider.java +++ b/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/utils/GraphMetricsUtils.java @@ -13,7 +13,7 @@ | See the License for the specific language governing permissions and | | limitations under the License. | +--------------------------------------------------------------------------*/ -package org.fortiss.tooling.ext.quality; +package org.fortiss.tooling.ext.quality.utils; import static org.fortiss.tooling.kernel.utils.EcoreUtils.pickInstanceOf; @@ -33,18 +33,15 @@ import org.fortiss.tooling.base.model.base.ExitConnectorBase; import org.fortiss.tooling.base.model.element.IConnection; import org.fortiss.tooling.base.model.element.IConnector; import org.fortiss.tooling.base.model.element.IHierarchicElement; -import org.fortiss.tooling.ext.quality.data.MetricData; -import org.fortiss.tooling.ext.quality.data.MetricKey; -import org.fortiss.tooling.ext.quality.data.MetricTreeNode; /** * Supplies methods to compute certain graph metrics. * + * @author blaschke * @author groh */ -// TODO (#4332) Restructure GraphMetricsProvider -public class GraphMetricsProvider { +public class GraphMetricsUtils { /** * Creates a list of nodes contained in the graph centered around the provided element. @@ -209,21 +206,18 @@ public class GraphMetricsProvider { * * @param scopeElement * the scope of this calculation - * @param metricData - * location to save the metrics * @param recursively * if true, all calculation will be carried out on leaf elements * if false, it is only computing the centrality with the children * which means the inner circle. + * @return betweenness map of the betweeness centrality value for each graph node */ - public static void calculateBetweennessCentrality(IHierarchicElement scopeElement, - MetricData metricData, boolean recursively) { - + public static Map<IHierarchicElement, Double> + calculateBetweennessCentrality(IHierarchicElement scopeElement, boolean recursively) { // Abort if no elements are found if(scopeElement.getContainedElements().isEmpty()) { - return; + return null; } - Set<IHierarchicElement> graphNodes = getLocalGraphView(scopeElement, recursively); // Initialize the betweenness values for all nodes to zero Map<IHierarchicElement, Double> betweenness = new HashMap<>(); @@ -270,19 +264,7 @@ public class GraphMetricsProvider { } } } - // Save metric - saveMetric(scopeElement, metricData, recursively, betweenness); - } - - /** Saving the metrics for each contained element of an {@link IHierarchicElement}. */ - private static void saveMetric(IHierarchicElement scopeElement, MetricData metricData, - boolean recursively, Map<IHierarchicElement, Double> betweenness) { - MetricKey key = recursively ? MetricKey.BETWEENESS_CENTRALITY_RECURSIVELY - : MetricKey.BETWEENESS_CENTRALITY; - for(IHierarchicElement child : scopeElement.getContainedElements()) { - MetricTreeNode node = metricData.getTreeNodeLookupTable().get(child); - node.getDoubleMetrics().put(key, betweenness.get(child)); - } + return betweenness; } /**