|
1 |
| -package main.java.testsmell.plugin.handlers; |
2 |
| - |
3 |
| -import java.io.IOException; |
4 |
| -import java.util.Collection; |
5 |
| -import java.util.HashMap; |
6 |
| -import main.java.testsmell.AbstractSmell; |
7 |
| -import main.java.testsmell.TestFile; |
8 |
| -import main.java.testsmell.TestSmellDetector; |
9 |
| - |
10 |
| -public class TSmellsDetection { |
11 |
| - |
12 |
| - private HashMap<String, String> paths = new HashMap<>(); |
13 |
| - private HashMap<String, Boolean> smells = new HashMap<String, Boolean>(); |
14 |
| - private static TSmellsDetection detectionObj; |
15 |
| - private static Collection<TestFile> testFiles; |
16 |
| - |
17 |
| - private TSmellsDetection(Collection<TestFile> t) { |
18 |
| - testFiles = t; |
19 |
| - } |
20 |
| - |
21 |
| - /** |
22 |
| - * Create a static method to get instance. |
23 |
| - */ |
24 |
| - public static TSmellsDetection getInstance(Collection<TestFile> t) { |
25 |
| - if (detectionObj == null) { |
26 |
| - detectionObj = new TSmellsDetection(t); |
27 |
| - } |
28 |
| - return detectionObj; |
29 |
| - } |
30 |
| - |
31 |
| - /** |
32 |
| - * Create a static method to get instance. |
33 |
| - */ |
34 |
| - public static TSmellsDetection getInstance() { |
35 |
| - return detectionObj; |
36 |
| - } |
37 |
| - |
38 |
| - public void detectSmells() { |
39 |
| - TestSmellDetector testSmellDetector = TestSmellDetector.createTestSmellDetector(); |
40 |
| - |
41 |
| - TestFile tempFile; |
42 |
| - for (TestFile file : testFiles) { |
43 |
| - try { |
44 |
| - tempFile = testSmellDetector.detectSmells(file); |
45 |
| - paths.put(file.getProductionFilePath(), file.getTestFilePath()); |
46 |
| - for (AbstractSmell smell : tempFile.getTestSmells()) { |
47 |
| - try { |
48 |
| - smells.put(smell.getSmellName(), smell.getHasSmell()); |
49 |
| - } catch (NullPointerException e) { |
50 |
| - |
51 |
| - } |
52 |
| - } |
53 |
| - } catch (IOException e) { |
54 |
| - e.printStackTrace(); |
55 |
| - } |
56 |
| - } |
57 |
| - } |
58 |
| - |
59 |
| - public String[] getProdFilePath() { |
60 |
| - String[] tempProdFilePaths = new String[paths.keySet().size()]; |
61 |
| - Object[] prodFileKeySet = paths.keySet().toArray(); |
62 |
| - for (int i = 0; i < tempProdFilePaths.length; i++) { |
63 |
| - tempProdFilePaths[i] = (String) prodFileKeySet[i]; |
64 |
| - } |
65 |
| - return tempProdFilePaths; |
66 |
| - } |
67 |
| - |
68 |
| - public String[] getTestFilePath() { |
69 |
| - String[] tempTestFilePaths = new String[paths.values().size()]; |
70 |
| - Object[] tempTestFileValues = paths.values().toArray(); |
71 |
| - for (int i = 0; i < tempTestFilePaths.length; i++) { |
72 |
| - tempTestFilePaths[i] = (String) tempTestFileValues[i]; |
73 |
| - } |
74 |
| - return tempTestFilePaths; |
75 |
| - } |
76 |
| - |
77 |
| - public String[] getSmellNames() { |
78 |
| - String[] tempSmellNames = new String[smells.keySet().size()]; |
79 |
| - Object[] tempSmellNamesKeySet = smells.keySet().toArray(); |
80 |
| - for (int i = 0; i < tempSmellNames.length; i++) { |
81 |
| - tempSmellNames[i] = (String) tempSmellNamesKeySet[i]; |
82 |
| - } |
83 |
| - return tempSmellNames; |
84 |
| - } |
85 |
| - |
86 |
| - public String[] hasSmells() { |
87 |
| - String[] tempHasSmells = new String[smells.values().size()]; |
88 |
| - Object[] tempHasSmellsValues = smells.values().toArray(); |
89 |
| - for (int i = 0; i < tempHasSmells.length; i++) { |
90 |
| - tempHasSmells[i] = ((Boolean) tempHasSmellsValues[i]).toString(); |
91 |
| - } |
92 |
| - return tempHasSmells; |
93 |
| - } |
94 |
| -} |
| 1 | +package main.java.testsmell.plugin.handlers; |
| 2 | + |
| 3 | +import java.io.IOException; |
| 4 | +import java.util.AbstractMap.SimpleEntry; |
| 5 | +import java.util.ArrayList; |
| 6 | +import main.java.testsmell.AbstractSmell; |
| 7 | +import main.java.testsmell.TestFile; |
| 8 | +import main.java.testsmell.TestSmellDetector; |
| 9 | + |
| 10 | +public class TSmellsDetection { |
| 11 | + |
| 12 | + private SimpleEntry<String, String> paths; |
| 13 | + private ArrayList<String> smells = new ArrayList<String>(); |
| 14 | + private TestFile testFile; |
| 15 | + |
| 16 | + protected TSmellsDetection(TestFile tf) { |
| 17 | + testFile = tf; |
| 18 | + } |
| 19 | + |
| 20 | + public void detectSmells() { |
| 21 | + TestSmellDetector testSmellDetector = TestSmellDetector.createTestSmellDetector(); |
| 22 | + TestFile tempFile; |
| 23 | + try { |
| 24 | + tempFile = testSmellDetector.detectSmells(testFile); |
| 25 | + paths = new SimpleEntry<String, String>(testFile.getProductionFilePath(),testFile.getTestFilePath()); |
| 26 | + for (AbstractSmell smell : tempFile.getTestSmells()) { |
| 27 | + try { |
| 28 | + if (smell.getHasSmell()) { |
| 29 | + smells.add(smell.getSmellName()); |
| 30 | + } |
| 31 | + } catch (NullPointerException e) { |
| 32 | + |
| 33 | + } |
| 34 | + } |
| 35 | + } catch (IOException e) { |
| 36 | + e.printStackTrace(); |
| 37 | + } |
| 38 | +// for (TestFile file : testFiles) { |
| 39 | +// try { |
| 40 | +// tempFile = testSmellDetector.detectSmells(file); |
| 41 | +// paths.put(file.getProductionFilePath(), file.getTestFilePath()); |
| 42 | +// for (AbstractSmell smell : tempFile.getTestSmells()) { |
| 43 | +// try { |
| 44 | +// smells.put(smell.getSmellName(), smell.getHasSmell()); |
| 45 | +// } catch (NullPointerException e) { |
| 46 | +// |
| 47 | +// } |
| 48 | +// } |
| 49 | +// } catch (IOException e) { |
| 50 | +// e.printStackTrace(); |
| 51 | +// } |
| 52 | +// } |
| 53 | + } |
| 54 | + |
| 55 | + public String[] getProdFilePath() { |
| 56 | + String[] tempProdFilePaths = new String[smells.size()]; |
| 57 | + String prodFile = paths.getKey(); |
| 58 | + for (int i = 0; i < tempProdFilePaths.length; i++) { |
| 59 | + tempProdFilePaths[i] = (String) prodFile; |
| 60 | + } |
| 61 | + return tempProdFilePaths; |
| 62 | + } |
| 63 | + |
| 64 | + public String[] getTestFilePath() { |
| 65 | + String[] tempTestFilePaths = new String[smells.size()]; |
| 66 | + String tempTestFile = paths.getValue(); |
| 67 | + for (int i = 0; i < tempTestFilePaths.length; i++) { |
| 68 | + tempTestFilePaths[i] = tempTestFile; |
| 69 | + } |
| 70 | + return tempTestFilePaths; |
| 71 | + } |
| 72 | + |
| 73 | + public String[] getSmellNames() { |
| 74 | + String[] tempSmellNames = new String[smells.size()]; |
| 75 | + for (int i = 0; i < smells.size(); i++) |
| 76 | + { |
| 77 | + tempSmellNames[i] = smells.get(i); |
| 78 | + } |
| 79 | + return tempSmellNames; |
| 80 | + } |
| 81 | + |
| 82 | +// public String[] hasSmells() { |
| 83 | +// String[] tempHasSmells = new String[smells.size()]; |
| 84 | +// Object[] tempHasSmellsValues = smells.values().toArray(); |
| 85 | +// for (int i = 0; i < tempHasSmells.length; i++) { |
| 86 | +// tempHasSmells[i] = ((Boolean) tempHasSmellsValues[i]).toString(); |
| 87 | +// } |
| 88 | +// return tempHasSmells; |
| 89 | +// } |
| 90 | +} |
0 commit comments