|
69 | 69 | import edu.cuny.hunter.streamrefactoring.core.refactorings.ConvertToParallelStreamRefactoringProcessor; |
70 | 70 | import edu.cuny.hunter.streamrefactoring.core.utils.TimeCollector; |
71 | 71 | import edu.cuny.hunter.streamrefactoring.eval.utils.Util; |
| 72 | +import net.sourceforge.metrics.core.Constants; |
72 | 73 | import net.sourceforge.metrics.core.Metric; |
73 | 74 | import net.sourceforge.metrics.core.sources.AbstractMetricSource; |
74 | 75 | import net.sourceforge.metrics.core.sources.Dispatcher; |
@@ -164,15 +165,20 @@ private static Set<IMethod> getAllMethods(IJavaProject javaProject) throws JavaM |
164 | 165 | return methods; |
165 | 166 | } |
166 | 167 |
|
| 168 | + @SuppressWarnings("unused") |
167 | 169 | 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); |
169 | 175 |
|
170 | 176 | 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; |
174 | 180 | } 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()); |
176 | 182 | return 0; |
177 | 183 | } |
178 | 184 | } |
@@ -204,23 +210,21 @@ private static int getNForStreams(IJavaProject project) throws IOException, Java |
204 | 210 | } |
205 | 211 | } |
206 | 212 |
|
| 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 | + |
207 | 221 | private static Collection<Entrypoint> getProjectEntryPoints(IJavaProject javaProject, |
208 | 222 | ConvertToParallelStreamRefactoringProcessor processor) { |
209 | 223 | return processor.getEntryPoints(javaProject); |
210 | 224 | } |
211 | 225 |
|
212 | 226 | 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); |
224 | 228 | } |
225 | 229 |
|
226 | 230 | private static void printStreamAttributesWithMultipleValues(Set<?> set, CSVPrinter printer, Stream stream, |
@@ -308,9 +312,9 @@ public Object execute(ExecutionEvent event) throws ExecutionException { |
308 | 312 |
|
309 | 313 | IJavaProject[] javaProjects = Util.getSelectedJavaProjectsFromEvent(event); |
310 | 314 |
|
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")); |
314 | 318 |
|
315 | 319 | for (Refactoring refactoring : Refactoring.values()) |
316 | 320 | resultsHeader.add(refactoring.toString()); |
@@ -372,6 +376,12 @@ public Object execute(ExecutionEvent event) throws ExecutionException { |
372 | 376 | // lines of code |
373 | 377 | resultsPrinter.print(getProjectLinesOfCode(javaProject)); |
374 | 378 |
|
| 379 | + // number of classes. |
| 380 | + resultsPrinter.print(getNumberOfClasses(javaProject)); |
| 381 | + |
| 382 | + // number of methods. |
| 383 | + resultsPrinter.print(getNumberOfMethods(javaProject)); |
| 384 | + |
375 | 385 | // set up analysis for single project. |
376 | 386 | TimeCollector resultsTimeCollector = new TimeCollector(); |
377 | 387 | int nToUseForStreams = getNForStreams(javaProject); |
|
0 commit comments