smell 'Primitive Obsession (Primitive Type)' added
diff --git a/org.eclipse.emf.refactor.metrics.uml24.ocl/bin/org/eclipse/emf/refactor/metrics/uml24/umlcl/NAPTC.class b/org.eclipse.emf.refactor.metrics.uml24.ocl/bin/org/eclipse/emf/refactor/metrics/uml24/umlcl/NAPTC.class
new file mode 100644
index 0000000..9a353d8
--- /dev/null
+++ b/org.eclipse.emf.refactor.metrics.uml24.ocl/bin/org/eclipse/emf/refactor/metrics/uml24/umlcl/NAPTC.class
Binary files differ
diff --git a/org.eclipse.emf.refactor.metrics.uml24.ocl/bin/org/eclipse/emf/refactor/metrics/uml24/umlcl/NCATC.class b/org.eclipse.emf.refactor.metrics.uml24.ocl/bin/org/eclipse/emf/refactor/metrics/uml24/umlcl/NCATC.class
new file mode 100644
index 0000000..dae7334
--- /dev/null
+++ b/org.eclipse.emf.refactor.metrics.uml24.ocl/bin/org/eclipse/emf/refactor/metrics/uml24/umlcl/NCATC.class
Binary files differ
diff --git a/org.eclipse.emf.refactor.metrics.uml24.ocl/plugin.xml b/org.eclipse.emf.refactor.metrics.uml24.ocl/plugin.xml
index 48f0ee8..47e12ac 100644
--- a/org.eclipse.emf.refactor.metrics.uml24.ocl/plugin.xml
+++ b/org.eclipse.emf.refactor.metrics.uml24.ocl/plugin.xml
@@ -24,6 +24,20 @@
metric_metamodel="http://www.eclipse.org/uml2/4.0.0/UML"
metric_name="NOPC">
</metric>
+<metric id="org.eclipse.emf.refactor.metrics.uml24.ncatc"
+ metric_calculate_class="org.eclipse.emf.refactor.metrics.uml24.umlcl.NCATC"
+ metric_context="Class"
+ metric_description="Number of constant attributes within the class"
+ metric_metamodel="http://www.eclipse.org/uml2/4.0.0/UML"
+ metric_name="NCATC">
+</metric>
+<metric id="org.eclipse.emf.refactor.metrics.uml24.naptc"
+ metric_calculate_class="org.eclipse.emf.refactor.metrics.uml24.umlcl.NAPTC"
+ metric_context="Class"
+ metric_description="Number of attributes within the class being of primitive type"
+ metric_metamodel="http://www.eclipse.org/uml2/4.0.0/UML"
+ metric_name="NAPTC">
+</metric>
</extension>
<extension point="org.eclipse.emf.refactor.metrics">
<metric id="org.eclipse.emf.refactor.metrics.uml24.ninppo"
diff --git a/org.eclipse.emf.refactor.metrics.uml24.ocl/src/org/eclipse/emf/refactor/metrics/uml24/umlcl/NAPTC.java b/org.eclipse.emf.refactor.metrics.uml24.ocl/src/org/eclipse/emf/refactor/metrics/uml24/umlcl/NAPTC.java
new file mode 100644
index 0000000..165b895
--- /dev/null
+++ b/org.eclipse.emf.refactor.metrics.uml24.ocl/src/org/eclipse/emf/refactor/metrics/uml24/umlcl/NAPTC.java
@@ -0,0 +1,25 @@
+package org.eclipse.emf.refactor.metrics.uml24.umlcl;
+
+import java.util.List;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.refactor.metrics.interfaces.IMetricCalculator;
+import org.eclipse.emf.refactor.metrics.ocl.managers.OCLManager;
+
+
+public final class NAPTC implements IMetricCalculator {
+
+ private final String expression =
+ "self.ownedAttribute -> select(type <> null and type.oclIsKindOf(uml::PrimitiveType)) -> size()";
+ private List<EObject> context;
+
+ @Override
+ public void setContext(List<EObject> context) {
+ this.context = context;
+ }
+
+ @Override
+ public double calculate() {
+ EObject contextObject = context.get(0);
+ return OCLManager.evaluateOCLOnContextObject(contextObject, expression);
+ }
+}
\ No newline at end of file
diff --git a/org.eclipse.emf.refactor.metrics.uml24.ocl/src/org/eclipse/emf/refactor/metrics/uml24/umlcl/NCATC.java b/org.eclipse.emf.refactor.metrics.uml24.ocl/src/org/eclipse/emf/refactor/metrics/uml24/umlcl/NCATC.java
new file mode 100644
index 0000000..872d0ed
--- /dev/null
+++ b/org.eclipse.emf.refactor.metrics.uml24.ocl/src/org/eclipse/emf/refactor/metrics/uml24/umlcl/NCATC.java
@@ -0,0 +1,25 @@
+package org.eclipse.emf.refactor.metrics.uml24.umlcl;
+
+import java.util.List;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.refactor.metrics.interfaces.IMetricCalculator;
+import org.eclipse.emf.refactor.metrics.ocl.managers.OCLManager;
+
+
+public final class NCATC implements IMetricCalculator {
+
+ private final String expression =
+ "self.ownedAttribute -> select(isReadOnly=true) -> size()";
+ private List<EObject> context;
+
+ @Override
+ public void setContext(List<EObject> context) {
+ this.context = context;
+ }
+
+ @Override
+ public double calculate() {
+ EObject contextObject = context.get(0);
+ return OCLManager.evaluateOCLOnContextObject(contextObject, expression);
+ }
+}
\ No newline at end of file
diff --git a/org.eclipse.emf.refactor.smells.uml24.metricbased/bin/org/eclipse/emf/refactor/smells/uml24/metricbased/PrimitiveObsessionConstants.class b/org.eclipse.emf.refactor.smells.uml24.metricbased/bin/org/eclipse/emf/refactor/smells/uml24/metricbased/PrimitiveObsessionConstants.class
new file mode 100644
index 0000000..c476f83
--- /dev/null
+++ b/org.eclipse.emf.refactor.smells.uml24.metricbased/bin/org/eclipse/emf/refactor/smells/uml24/metricbased/PrimitiveObsessionConstants.class
Binary files differ
diff --git a/org.eclipse.emf.refactor.smells.uml24.metricbased/bin/org/eclipse/emf/refactor/smells/uml24/metricbased/PrimitiveObsessionPrimitiveType.class b/org.eclipse.emf.refactor.smells.uml24.metricbased/bin/org/eclipse/emf/refactor/smells/uml24/metricbased/PrimitiveObsessionPrimitiveType.class
new file mode 100644
index 0000000..a9af456
--- /dev/null
+++ b/org.eclipse.emf.refactor.smells.uml24.metricbased/bin/org/eclipse/emf/refactor/smells/uml24/metricbased/PrimitiveObsessionPrimitiveType.class
Binary files differ
diff --git a/org.eclipse.emf.refactor.smells.uml24.metricbased/plugin.xml b/org.eclipse.emf.refactor.smells.uml24.metricbased/plugin.xml
index 44ecb54..41aaa2a 100644
--- a/org.eclipse.emf.refactor.smells.uml24.metricbased/plugin.xml
+++ b/org.eclipse.emf.refactor.smells.uml24.metricbased/plugin.xml
@@ -38,6 +38,20 @@
modelsmell_metamodel="http://www.eclipse.org/uml2/4.0.0/UML"
modelsmell_name="Long Parameter List">
</modelsmell>
+ <modelsmell
+ id="org.eclipse.emf.refactor.smells.uml24.primitiveobsessionconstants"
+ modelsmell_description="The model contains a class with more constant attributes than the specified limit."
+ modelsmell_finderclass="org.eclipse.emf.refactor.smells.uml24.metricbased.PrimitiveObsessionConstants"
+ modelsmell_metamodel="http://www.eclipse.org/uml2/4.0.0/UML"
+ modelsmell_name="Primitive Obsession (Constants)">
+ </modelsmell>
+ <modelsmell
+ id="org.eclipse.emf.refactor.smells.uml24.primitiveobsessionprimitivetype"
+ modelsmell_description="The model contains a class with more attributes being of primitive type than the specified limit."
+ modelsmell_finderclass="org.eclipse.emf.refactor.smells.uml24.metricbased.PrimitiveObsessionPrimitiveType"
+ modelsmell_metamodel="http://www.eclipse.org/uml2/4.0.0/UML"
+ modelsmell_name="Primitive Obsession (Primitive Type)">
+ </modelsmell>
</extension>
</plugin>
diff --git a/org.eclipse.emf.refactor.smells.uml24.metricbased/src/org/eclipse/emf/refactor/smells/uml24/metricbased/PrimitiveObsessionConstants.java b/org.eclipse.emf.refactor.smells.uml24.metricbased/src/org/eclipse/emf/refactor/smells/uml24/metricbased/PrimitiveObsessionConstants.java
new file mode 100644
index 0000000..fc35954
--- /dev/null
+++ b/org.eclipse.emf.refactor.smells.uml24.metricbased/src/org/eclipse/emf/refactor/smells/uml24/metricbased/PrimitiveObsessionConstants.java
@@ -0,0 +1,52 @@
+package org.eclipse.emf.refactor.smells.uml24.metricbased;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.refactor.metrics.core.Metric;
+import org.eclipse.emf.refactor.metrics.interfaces.IMetricCalculator;
+import org.eclipse.emf.refactor.smells.core.MetricBasedModelSmellFinderClass;
+
+public class PrimitiveObsessionConstants extends MetricBasedModelSmellFinderClass {
+
+ private String metricId = "org.eclipse.emf.refactor.metrics.uml24.ncatc";
+ private Metric localMetric = Metric.getMetricInstanceFromId(metricId);
+
+ @Override
+ public LinkedList<LinkedList<EObject>> findSmell(EObject root) {
+ LinkedList<EObject> rootList = new LinkedList<EObject>();
+ rootList.add(root);
+ IMetricCalculator localCalculateClass = localMetric.getCalculateClass();
+ double globalLimit = this.getLimit();
+ return findSmellyObjectGroups(root, globalLimit, localCalculateClass);
+ }
+
+ private LinkedList<LinkedList<EObject>> findSmellyObjectGroups(EObject root, double globalLimit,
+ IMetricCalculator localCalculateClass) {
+ String context = localMetric.getContext();
+ LinkedList<LinkedList<EObject>> smellyEObjects = new LinkedList<LinkedList<EObject>>();
+ List<EObject> containedEObjects = root.eContents();
+ for(EObject object : containedEObjects){
+ String objectType = object.eClass().getInstanceClass().getSimpleName();
+ if(objectType.equals(context)){
+ LinkedList<EObject> rootList = new LinkedList<EObject>();
+ rootList.add(object);
+ localCalculateClass.setContext(rootList);
+ double localValue = localCalculateClass.calculate();
+ if(limitReached(localValue, globalLimit)) {
+ LinkedList<EObject> currentObjects = new LinkedList<EObject>();
+ currentObjects.add(object);
+ smellyEObjects.add((currentObjects));
+ }
+ } else {
+ smellyEObjects.addAll(findSmellyObjectGroups(object, globalLimit, localCalculateClass));
+ }
+ }
+ return smellyEObjects;
+ }
+
+ private boolean limitReached(double localValue, double globalLimit) {
+ return (localValue > globalLimit);
+ }
+}
diff --git a/org.eclipse.emf.refactor.smells.uml24.metricbased/src/org/eclipse/emf/refactor/smells/uml24/metricbased/PrimitiveObsessionPrimitiveType.java b/org.eclipse.emf.refactor.smells.uml24.metricbased/src/org/eclipse/emf/refactor/smells/uml24/metricbased/PrimitiveObsessionPrimitiveType.java
new file mode 100644
index 0000000..72cd7bf
--- /dev/null
+++ b/org.eclipse.emf.refactor.smells.uml24.metricbased/src/org/eclipse/emf/refactor/smells/uml24/metricbased/PrimitiveObsessionPrimitiveType.java
@@ -0,0 +1,52 @@
+package org.eclipse.emf.refactor.smells.uml24.metricbased;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.refactor.metrics.core.Metric;
+import org.eclipse.emf.refactor.metrics.interfaces.IMetricCalculator;
+import org.eclipse.emf.refactor.smells.core.MetricBasedModelSmellFinderClass;
+
+public class PrimitiveObsessionPrimitiveType extends MetricBasedModelSmellFinderClass {
+
+ private String metricId = "org.eclipse.emf.refactor.metrics.uml24.naptc";
+ private Metric localMetric = Metric.getMetricInstanceFromId(metricId);
+
+ @Override
+ public LinkedList<LinkedList<EObject>> findSmell(EObject root) {
+ LinkedList<EObject> rootList = new LinkedList<EObject>();
+ rootList.add(root);
+ IMetricCalculator localCalculateClass = localMetric.getCalculateClass();
+ double globalLimit = this.getLimit();
+ return findSmellyObjectGroups(root, globalLimit, localCalculateClass);
+ }
+
+ private LinkedList<LinkedList<EObject>> findSmellyObjectGroups(EObject root, double globalLimit,
+ IMetricCalculator localCalculateClass) {
+ String context = localMetric.getContext();
+ LinkedList<LinkedList<EObject>> smellyEObjects = new LinkedList<LinkedList<EObject>>();
+ List<EObject> containedEObjects = root.eContents();
+ for(EObject object : containedEObjects){
+ String objectType = object.eClass().getInstanceClass().getSimpleName();
+ if(objectType.equals(context)){
+ LinkedList<EObject> rootList = new LinkedList<EObject>();
+ rootList.add(object);
+ localCalculateClass.setContext(rootList);
+ double localValue = localCalculateClass.calculate();
+ if(limitReached(localValue, globalLimit)) {
+ LinkedList<EObject> currentObjects = new LinkedList<EObject>();
+ currentObjects.add(object);
+ smellyEObjects.add((currentObjects));
+ }
+ } else {
+ smellyEObjects.addAll(findSmellyObjectGroups(object, globalLimit, localCalculateClass));
+ }
+ }
+ return smellyEObjects;
+ }
+
+ private boolean limitReached(double localValue, double globalLimit) {
+ return (localValue > globalLimit);
+ }
+}