Skip to content
Snippets Groups Projects
Commit e6a26d74 authored by Eddie Groh's avatar Eddie Groh
Browse files

YELLOW

Issue-Ref: 4310
Issue-Url: af3#4310



Signed-off-by: default avatarEddie Groh <groh@fortiss.org>
parent ffe63d03
No related branches found
No related tags found
1 merge request!210Setting up Metric extraction plugin for AF3 : Issue 4310
Showing
with 138 additions and 95 deletions
......@@ -5,6 +5,11 @@
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.systemfocus.tooling.emfgeneration.git.EcoreBuilderGIT</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
......@@ -20,9 +25,25 @@
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.systemfocus.tooling.codereview.builder.CodeReviewBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.systemfocus.tooling.codereview.builder.RemoveWarningsBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.systemfocus.tooling.codereview.builder.GuidelinesCheckBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.systemfocus.tooling.codereview.nature.CodeReviewNature</nature>
</natures>
</projectDescription>
documentation.html aaa534ab30ef337c5e7bc75d37490eb6a5a4edd1 YELLOW
<html><body>
<h1>Developer Documentation for <i>AF3 Model Quality</i> (org.fortiss.tooling.ext.quality.ui)</h1>
<h2>Plugin description</h2>
<p>This is the user interface part of the tooling.ext.quality plugin. It provides a simple view to display collected metrics</p>
<h2>Package description</h2>
<ul>
<li><tt>quality.ui</tt>: main package with the UI plugin activator.</li>
<li><tt>quality.ui.view.fx</tt>: implementation of quality library view (FX-based).</li>
</ul>
</body></html>
org.fortiss.tooling.ext.quality.ui/icons/library.png

675 B

org.fortiss.tooling.ext.quality.ui/icons/metric.png

826 B

......@@ -12,7 +12,7 @@
point="org.eclipse.ui.views">
<view
class="org.fortiss.tooling.ext.quality.ui.view.fx.ModelQualityFXViewPart"
icon="icons/library.png"
icon="icons/metric.png"
id="org.fortiss.tooling.ext.quality.ui.metricsView"
name="Metrics"
restorable="true">
......
ModelQualityExtractionMenu.java 87cdfa5d4f939cc9f21afc8d6361a2089f440f20 YELLOW
ModelQualityUIActivator.java 47787eb293198014ba5a5a9b21d004a379117f5e YELLOW
package org.fortiss.tooling.ext.quality.ui;
/*-------------------------------------------------------------------------+
| Copyright 2019 fortiss GmbH |
| Copyright 2023 fortiss GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
......@@ -15,6 +13,9 @@ package org.fortiss.tooling.ext.quality.ui;
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.ext.quality.ui;
import static java.util.Arrays.asList;
import static java.util.Collections.emptyList;
import static org.fortiss.tooling.kernel.ui.service.IContextMenuService.BOTTOM_MOST_MENU_SECTION_ID;
......@@ -34,7 +35,7 @@ import org.fortiss.tooling.kernel.ui.extension.IContextMenuContributor;
import org.fortiss.tooling.kernel.ui.extension.data.ContextMenuContextProvider;
/**
* Crates a context menu entry to generate the for the selected
* Creates a context menu entry to extract metrics for the selected {@link FileProject}.
*
* @author groh
*/
......@@ -62,13 +63,13 @@ public class ModelQualityExtractionMenu implements IContextMenuContributor {
/** Returns the icon that is visible in the context menu for this entry. */
protected ImageDescriptor getActionIcon() {
return ModelQualityUIActivator.getImageDescriptor("icons/componentarchitecture.gif");
return ModelQualityUIActivator.getImageDescriptor("icons/metric.png");
}
/** Action for generating the set of . */
protected class MetricExtractionAction extends Action {
/** */
/** {@link FileProject} on which the action will be triggered. */
private final FileProject fp;
/** Constructor. */
......
/*-------------------------------------------------------------------------+
| Copyright 2023 fortiss GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.ext.quality.ui;
import static org.eclipse.jface.resource.ResourceLocator.imageDescriptorFromBundle;
......@@ -7,8 +22,9 @@ import org.eclipse.jface.resource.ImageDescriptor;
import org.osgi.framework.BundleContext;
/**
* The activator class controls the plug-in life cycle.
*
* @author blaschke
*
*/
public class ModelQualityUIActivator extends Plugin {
......@@ -36,7 +52,7 @@ public class ModelQualityUIActivator extends Plugin {
/**
* Returns the shared instance.
*
* @return The shared instance of ModelQualityUIActivator
* @return The shared instance of {@link ModelQualityUIActivator}
*/
public static ModelQualityUIActivator getDefault() {
return plugin;
......
IModelQualityViewPart.java 708f8089645df12098ea67190805cce343045d2e YELLOW
ModelQualityFXController.java 391dc121678e1741b8ee98f90de18996ba2c37b2 YELLOW
ModelQualityFXViewPart.java 179abf18d6e3b6c844076620f53b43ac8a42c217 YELLOW
......@@ -16,7 +16,7 @@
package org.fortiss.tooling.ext.quality.ui.view.fx;
/**
* Interface for views displaying the Metrics view
* Interface for views displaying the Metrics view.
*
* @author groh
*/
......
......@@ -61,6 +61,7 @@ import javafx.scene.chart.PieChart;
import javafx.scene.chart.ScatterChart;
import javafx.scene.chart.XYChart;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.Label;
import javafx.scene.control.SplitPane;
import javafx.scene.layout.BorderPane;
......@@ -74,22 +75,19 @@ import javafx.scene.layout.BorderPane;
public class ModelQualityFXController extends CompositeFXControllerBase<SplitPane, Node>
implements ISelectionListener {
/** The {@link IProjectRootElement} in which the selected element is contained in. */
private IProjectRootElement currentRootElement;
/** a choiceBox */
/** ChoiceBox for selecting the metric which shall be displayed. */
@FXML
private ChoiceBox<MetricKey> choiceBox;
/** The bottom {@link BorderPane} for the spiderchart */
/** The bottom {@link BorderPane} for the spider chart. */
@FXML
private BorderPane borderPane;
/** a pieChart */
/** PieChart displaying the metrics. */
@FXML
private PieChart pieChart;
/** a scatterChart */
/** A scatter chart for displaying metrics. */
@FXML
private ScatterChart<Number, Number> scatterChart;
......@@ -106,8 +104,8 @@ public class ModelQualityFXController extends CompositeFXControllerBase<SplitPan
}
/**
* The last IHierachicElement which the user has clicked. Might be null when no or invalid
* Object is selected
* The last {@link EObject} which the user has clicked. Might be null when no or an invalid
* Object is selected.
*/
private EObject lastSelectedElement;
......@@ -115,38 +113,32 @@ public class ModelQualityFXController extends CompositeFXControllerBase<SplitPan
@Override
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
// Invalidate last selection, so if no new selection is found the charts are cleared
lastSelectedElement = null;
ModelQualityService.getInstance();
var manager = ModelQualityService.metricDataManagerInstance;
if(manager == null) {
// topLabel.setText("No Metrics were available at " +
// timeFormat.format(LocalDateTime.now()));
return;
}
var manager = ModelQualityService.getInstance().getMetricDataManagerInstance();
EObject selected = checkAndPickFirst(selection, EObject.class);
if(selected == null) {
// topLabel.setText("Nothing selected");
updateCharts();
return;
}
if(selected instanceof IProjectRootElement) {
currentRootElement = (IProjectRootElement)selected;
} else {
currentRootElement = getFirstParentWithType(selected, IProjectRootElement.class);
}
IProjectRootElement currentRootElement =
selected instanceof IProjectRootElement ? (IProjectRootElement)selected
: getFirstParentWithType(selected, IProjectRootElement.class);
if(currentRootElement == null) {
// There was no root element for the selected element. (Usually should be the
// FileProject.) This is not displayed here.
// topLabel.setText("No root found");
updateCharts();
return;
}
var root_provider = manager.getRootNodes().get(currentRootElement);
var root_provider = manager.getRootNodesMap().get(currentRootElement);
if(root_provider == null) {
// topLabel.setText("No Metric found for this project, did you export metrics?");
updateCharts();
return;
}
......@@ -155,25 +147,22 @@ public class ModelQualityFXController extends CompositeFXControllerBase<SplitPan
}
/**
* Is triggered when the refresh button is pressed.
* Is triggered when the choice box changes.
*/
public void onChoiceBoxChange() {
updateCharts();
}
/**
* Updates the chart in the metric view
*/
/** Updates the chart in the metric view. */
private void updateCharts() {
if(lastSelectedElement != null) {
MetricDataManager manager = ModelQualityService.metricDataManagerInstance;
MetricDataManager manager =
ModelQualityService.getInstance().getMetricDataManagerInstance();
MetricTreeNode node = manager.getTreeNodeLookupTable().get(lastSelectedElement);
if(node != null) {
// topLabel.setText("Text");
Set<MetricKey> validKeys = new HashSet<>();
validKeys.addAll(node.getStoredDoubles().keySet());
validKeys.addAll(node.getStoredIntegers().keySet());
......@@ -212,8 +201,6 @@ public class ModelQualityFXController extends CompositeFXControllerBase<SplitPan
scatterChart.getXAxis().setLabel("NUMBER_OF_TOTAL_LEAF_ELEMENTS");
scatterChart.getYAxis().setLabel("NUMBER_OF_TOTAL_CYCLOMATIC_COMPLEXITY");
// Create BubbleChart
// bubbleChart = new BubbleChart<>(xAxis, yAxis);
scatterChart.getData().clear();
for(var child : node.getChildren()) {
......@@ -234,23 +221,21 @@ public class ModelQualityFXController extends CompositeFXControllerBase<SplitPan
// Return, otherwise the data will be cleared
return;
}
} else {
// topLabel.setText("Element not in metrics");
}
}
borderPane.setCenter(null);
borderPane.setCenter(new Label("No metrics available for this selection"));
pieChart.getData().clear();
}
/**
* @param node
* of which the data will be visualized
* @param key
* {@link MetricKey} of the data to visualize
* @return {@link SpiderChartViewer} with the matching metrics
*/
private static SpiderChartViewer buildSpiderChart(MetricTreeNode node, MetricKey key) {
SpiderChart spiderChart = new SpiderChart();
// spiderChart.setTitle("Amount of Ports");
spiderChart.setLegendLabel("Legend");
ChartStyle chartStyle = new ChartStyle(true, true, true);
......
......@@ -40,7 +40,7 @@ public class ModelQualityFXViewPart extends AF3FXViewPart implements IModelQuali
}
/**
* Returns the initialized {@link ModelQualityFXController} for the reuse
* Returns the initialized {@link ModelQualityFXController} for the quality
* version of the {@link AF3FXViewPart}.
*
* @return The view controller for the metrics view
......
AF3QualityActivator.java 353c3d99f423997e4e99a896b3c095fd77d81431 YELLOW
GraphMetricsProvider.java 2d3fff61af2537bc5b10b3c210dc8e4b3ad49c1d YELLOW
HierarchicElementProvider.java 3c114abd47ecc0d7da751c3f05c83fd49a30717b YELLOW
IMetricProvider.java 5e3d0debc0f81ed4e6c7dbc0f8d0e55df1bfde39 YELLOW
......@@ -36,15 +36,16 @@ import org.fortiss.tooling.ext.quality.data.MetricKey;
import org.fortiss.tooling.kernel.utils.EcoreUtils;
/**
* Supplies methods to compute certain graph metrics.
*
* @author groh
*/
public class GraphMetricsProvider {
/**
* Creates a list of nodes contained in the graph centered around the provided element
* Creates a list of nodes contained in the graph centered around the provided element.
* It will contain all elements contained within the provided element as well as all elements
* connected to the provided element
* connected to the provided element.
*
* @param scopeElement
* element defining the scope of the graph
......@@ -54,9 +55,6 @@ public class GraphMetricsProvider {
*/
private static Set<IHierarchicElement> getLocalGraphView(IHierarchicElement scopeElement,
boolean recursively) {
// Create a view consisting of all nodes inside this element, as well as all elements
// connected to this element
// This ensures that elements inside this element communicating with elements outside
// this element are properly recognized
Set<IHierarchicElement> graphNodes = new HashSet<>();
......@@ -83,7 +81,7 @@ public class GraphMetricsProvider {
}
/**
* Get all leafs inside the provided element
* Get all leafs inside the provided element.
*
* @param element
* the element containing leafs
......@@ -100,7 +98,7 @@ public class GraphMetricsProvider {
/**
* Follows outgoing connections until the connector has no further outgoing connections and then
* saves the owner of this connector to the provided list
* saves the owner of this connector to the provided list.
*
* @param connector
* starting point for search
......@@ -124,8 +122,7 @@ public class GraphMetricsProvider {
/**
* Follows incoming connections until the connector has no further incoming connections and
* then
* saves the owner of this connector to the provided list
* then saves the owner of this connector to the provided list.
*
* @param connector
* starting point for search
......@@ -148,7 +145,7 @@ public class GraphMetricsProvider {
}
/**
* Collects all neighbors regardless of the direction of connection
* Collects all neighbors regardless of the direction of connection.
*
* @param element
* of which the neighbors should be collected
......@@ -156,6 +153,7 @@ public class GraphMetricsProvider {
*/
private static Set<IHierarchicElement> getUndirectedNeighbors(IHierarchicElement element) {
Set<IHierarchicElement> neighbors = new HashSet<>();
for(ExitConnectorBase exitConnectors : EcoreUtils.pickInstanceOf(ExitConnectorBase.class,
element.getConnectors())) {
recursivlyFollowOutgoingConnection(exitConnectors, neighbors);
......@@ -168,7 +166,7 @@ public class GraphMetricsProvider {
}
/**
* Calculates the clustering coefficient based on the neighborhood
* Calculates the clustering coefficient based on the neighborhood.
*
* @param element
* of which the coefficient shall be calculated
......@@ -183,6 +181,8 @@ public class GraphMetricsProvider {
return 0.0; // If there are fewer than 2 neighbors, the coefficient is undefined (or 0).
}
// Iterate over neighbors and get their neighbors and check if they are also our neighbor in
// which case we have a triangle
int triangles = 0;
for(IHierarchicElement neighbor : neighbors) {
......@@ -200,7 +200,7 @@ public class GraphMetricsProvider {
/**
* Calculates and saves the betweenness centrality of all elements contained inside the provided
* scopeElement
* scopeElement.
*
* @param scopeElement
* the scope of this calculation
......
......@@ -25,37 +25,23 @@ import org.fortiss.tooling.kernel.model.INamedCommentedElement;
import org.fortiss.tooling.kernel.utils.EcoreUtils;
/**
* {@link IMetricProvider} to count the ratio of filled out comments of
* INamedCommentedElements.
* {@link IMetricProvider} to collect various metrics from an {@link IHierarchicElement}.
*
* @author blaschke
* @author groh
*/
public class HierarchicElementProvider implements IMetricProvider<IHierarchicElement> {
/**
* returns an array of integers or <String,Double> Map Number of children of the
* hierarchical Element (on this level) Number of ports on the hierarchical
* Element (on this level) Number of channels in the hierarchical element (on
* this level) Number of totalPorts in whole tree Number of totalElements in
* whole tree Average SubTree Size
*/
/**
* List containing all HierarchicElementSizeProvider for components inside the
* IHierarchicElement
*/
/** */
public HierarchicElementProvider() {
super();
}
/** {@inheritDoc} */
@Override
public void collectMetrics(MetricTreeNode node, IHierarchicElement currentElement) {
var integers = node.getStoredIntegers();
// Only collect these metrics if the name is null, in which case they have not been
// collected before
// This is used in some cases to combine metrics from two different IHierarchicElement
if(node.getName() == null) {
// Metrics are always set to default value, as these metric are combined later
boolean isElementCommentable = currentElement instanceof INamedCommentedElement;
integers.put(MetricKey.NUMBER_OF_TOTAL_COMMENTABLE_ELEMENTS,
isElementCommentable ? 1 : 0);
......@@ -79,6 +65,7 @@ public class HierarchicElementProvider implements IMetricProvider<IHierarchicEle
integers.put(MetricKey.NUMBER_OF_CONTAINED_ELEMENTS,
currentElement.getContainedElements().size());
integers.put(MetricKey.NUMBER_OF_CONNECTIONS, currentElement.getConnections().size());
// depth metrics
integers.put(MetricKey.NUMBER_OF_TOTAL_CONNECTORS, connectors.size());
var entry_connectors = EcoreUtils.pickInstanceOf(EntryConnectorBase.class, connectors);
......
/*-------------------------------------------------------------------------+
| Copyright 2011 fortiss GmbH |
| Copyright 2023 fortiss GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
......@@ -21,9 +21,9 @@ import org.fortiss.tooling.ext.quality.service.IModelQualityService;
import org.fortiss.tooling.kernel.service.base.IEObjectAware;
/**
* Interface for the migration provider implementations.
* Interface for all metric providers.
* <P>
* migration provider extensions are handled by {@link IModelQualityService}.
* They are called by {@link IModelQualityService} to collect metrics on model elements.
*
* @author blaschke
*/
......
MetricDataManager.java 36dc2d04485702ce18dd914789d06d873eb99564 YELLOW
MetricKey.java ecb1c765a7de855091c7ac8b287eaf9503e0da33 YELLOW
MetricTreeNode.java d89ef9aab7171a66ff7fc30c904e06f50d164ff9 YELLOW
......@@ -22,19 +22,20 @@ import org.eclipse.emf.ecore.EObject;
import org.fortiss.tooling.kernel.model.IProjectRootElement;
/**
* Class containing all computed metrics for the current af3 instance.
*
* @author groh
*/
public class MetricDataManager {
/** a map to lookup the corresponding tree node */
/** a map to lookup the corresponding tree node for any {@link EObject} */
private Map<EObject, MetricTreeNode> treeNodeLookupTable;
/** the root tree node */
/** a map to lookup the corresponding root tree node for a project */
private Map<IProjectRootElement, MetricTreeNode> root_nodes;
/**
* Constructs a new instance of the MetricDataManager
* Constructor: Creates a new instance of the MetricDataManager.
*/
public MetricDataManager() {
root_nodes = new HashMap<>();
......@@ -42,16 +43,17 @@ public class MetricDataManager {
}
/**
* @return the lookup map
* @return the lookup mapping between {@link EObject} and a {@link MetricTreeNode}.
*/
public Map<EObject, MetricTreeNode> getTreeNodeLookupTable() {
return treeNodeLookupTable;
}
/**
* @return a map containing all root nodes
* @return the map between {@link IProjectRootElement} and the corresponding root
* {@link MetricTreeNode}.
*/
public Map<IProjectRootElement, MetricTreeNode> getRootNodes() {
public Map<IProjectRootElement, MetricTreeNode> getRootNodesMap() {
return root_nodes;
}
}
......@@ -19,6 +19,7 @@ import java.util.ArrayList;
import java.util.List;
/**
* Enum class representing a key which can be used to store a respective metric.
*
* @author groh
*/
......@@ -115,7 +116,7 @@ public enum MetricKey {
private boolean isDoubleValue;
/**
* Basic constructor
* Constructor for regular integer metric keys.
*
* @param isCollectorKey
* decides if this is a key returned by {@link MetricKey#getCollectorKeys()}
......@@ -125,6 +126,8 @@ public enum MetricKey {
}
/**
* Constructor for metric key storing a double.
*
* @param isCollectorKey
* decides if this is a key returned by {@link MetricKey#getCollectorKeys()}
* @param isDoubleValue
......@@ -137,6 +140,8 @@ public enum MetricKey {
}
/**
* Constructor for metric key storing a string.
*
* @param isCollectorKey
* decides if this is a key returned by {@link MetricKey#getCollectorKeys()}
* @param isStringValue
......@@ -150,7 +155,7 @@ public enum MetricKey {
/**
* If this value is true, it should be expected that the value corresponding to this key should
* be a string and be stored in an appropriate place
* be a string and be stored in an appropriate place.
*
* @return if the value associated with this key is a string
*/
......@@ -160,7 +165,7 @@ public enum MetricKey {
/**
* If this value is true, it should be expected that the value corresponding to this key should
* be a integer and be stored in an appropriate place
* be a integer and be stored in an appropriate place.
*
* @return if the value associated with this key is a integer
*/
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment