Skip to content

Commit 2c215e8

Browse files
committed
Additional metrics.
1 parent bb7adad commit 2c215e8

File tree

1 file changed

+29
-19
lines changed

1 file changed

+29
-19
lines changed

edu.cuny.hunter.streamrefactoring.eval/src/edu/cuny/hunter/streamrefactoring/eval/handlers/EvaluateConvertToParallelStreamRefactoringHandler.java

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
import edu.cuny.hunter.streamrefactoring.core.refactorings.ConvertToParallelStreamRefactoringProcessor;
7070
import edu.cuny.hunter.streamrefactoring.core.utils.TimeCollector;
7171
import edu.cuny.hunter.streamrefactoring.eval.utils.Util;
72+
import net.sourceforge.metrics.core.Constants;
7273
import net.sourceforge.metrics.core.Metric;
7374
import net.sourceforge.metrics.core.sources.AbstractMetricSource;
7475
import net.sourceforge.metrics.core.sources.Dispatcher;
@@ -164,15 +165,20 @@ private static Set<IMethod> getAllMethods(IJavaProject javaProject) throws JavaM
164165
return methods;
165166
}
166167

168+
@SuppressWarnings("unused")
167169
private static int getMethodLinesOfCode(IMethod method) {
168-
AbstractMetricSource metricSource = Dispatcher.getAbstractMetricSource(method);
170+
return getMetric(method, Constants.MLOC);
171+
}
172+
173+
private static int getMetric(IJavaElement elem, String key) {
174+
AbstractMetricSource metricSource = Dispatcher.getAbstractMetricSource(elem);
169175

170176
if (metricSource != null) {
171-
Metric value = metricSource.getValue("MLOC");
172-
int mLOC = value.intValue();
173-
return mLOC;
177+
Metric value = metricSource.getValue(key);
178+
int tLOC = value.intValue();
179+
return tLOC;
174180
} else {
175-
System.err.println("WARNING: Could not retrieve metric source for method: " + method.getElementName());
181+
System.err.println("WARNING: Could not retrieve metric source for: " + elem.getElementName());
176182
return 0;
177183
}
178184
}
@@ -204,23 +210,21 @@ private static int getNForStreams(IJavaProject project) throws IOException, Java
204210
}
205211
}
206212

213+
private static int getNumberOfClasses(IJavaProject javaProject) {
214+
return getMetric(javaProject, Constants.NUM_TYPES);
215+
}
216+
217+
private static int getNumberOfMethods(IJavaProject javaProject) {
218+
return getMetric(javaProject, Constants.NUM_METHODS);
219+
}
220+
207221
private static Collection<Entrypoint> getProjectEntryPoints(IJavaProject javaProject,
208222
ConvertToParallelStreamRefactoringProcessor processor) {
209223
return processor.getEntryPoints(javaProject);
210224
}
211225

212226
private static int getProjectLinesOfCode(IJavaProject javaProject) {
213-
AbstractMetricSource metricSource = Dispatcher.getAbstractMetricSource(javaProject);
214-
215-
if (metricSource != null) {
216-
Metric value = metricSource.getValue("TLOC");
217-
int tLOC = value.intValue();
218-
return tLOC;
219-
} else {
220-
System.err
221-
.println("WARNING: Could not retrieve metric source for project: " + javaProject.getElementName());
222-
return 0;
223-
}
227+
return getMetric(javaProject, Constants.TLOC);
224228
}
225229

226230
private static void printStreamAttributesWithMultipleValues(Set<?> set, CSVPrinter printer, Stream stream,
@@ -308,9 +312,9 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
308312

309313
IJavaProject[] javaProjects = Util.getSelectedJavaProjectsFromEvent(event);
310314

311-
List<String> resultsHeader = new ArrayList<>(Arrays.asList("subject", "SLOC", "#entrypoints", "N",
312-
"#streams", "#optimization available streams", "#optimizable streams", "#failed preconditions",
313-
"stream instances processed", "stream instances skipped"));
315+
List<String> resultsHeader = new ArrayList<>(Arrays.asList("subject", "SLOC", "classes", "methods",
316+
"#entrypoints", "N", "#streams", "#optimization available streams", "#optimizable streams",
317+
"#failed preconditions", "stream instances processed", "stream instances skipped"));
314318

315319
for (Refactoring refactoring : Refactoring.values())
316320
resultsHeader.add(refactoring.toString());
@@ -372,6 +376,12 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
372376
// lines of code
373377
resultsPrinter.print(getProjectLinesOfCode(javaProject));
374378

379+
// number of classes.
380+
resultsPrinter.print(getNumberOfClasses(javaProject));
381+
382+
// number of methods.
383+
resultsPrinter.print(getNumberOfMethods(javaProject));
384+
375385
// set up analysis for single project.
376386
TimeCollector resultsTimeCollector = new TimeCollector();
377387
int nToUseForStreams = getNForStreams(javaProject);

0 commit comments

Comments
 (0)