77import java .util .*;
88import java .util .zip .ZipEntry ;
99import java .util .zip .ZipInputStream ;
10-
1110import de .fraunhofer .iem .swan .SwanPipeline ;
1211import org .slf4j .Logger ;
1312import org .slf4j .LoggerFactory ;
14-
1513import de .fraunhofer .iem .swan .features .code .type .IFeature .Type ;
1614import de .fraunhofer .iem .swan .data .Category ;
1715import de .fraunhofer .iem .swan .data .Method ;
@@ -33,7 +31,7 @@ public class Util {
3331 * @return The purged set of methods without duplicates
3432 */
3533 public static Set <Method > sanityCheck (Set <Method > methods , Set <Method > init ) {
36- Map <String , Method > signatureToMethod = new HashMap <String , Method >();
34+ Map <String , Method > signatureToMethod = new HashMap <>();
3735 for (Method m1 : methods ) {
3836 String sig = m1 .getSignature ();
3937 Method m2 = signatureToMethod .get (sig );
@@ -45,7 +43,7 @@ else if (!m1.equals(m2)) {
4543 }
4644 }
4745
48- Set <Method > ret = new HashSet <Method >();
46+ Set <Method > ret = new HashSet <>();
4947 for (Method m : signatureToMethod .values ()) {
5048 if (!init .contains (m ))
5149 ret .add (m );
@@ -57,7 +55,7 @@ else if (!m1.equals(m2)) {
5755 }
5856
5957 public static void printStatistics (String message , Set <Method > methods ) {
60- Map <Category , Integer > counters = new HashMap <Category , Integer >();
58+ Map <Category , Integer > counters = new HashMap <>();
6159 for (Method am : methods ) {
6260 for (Category category : am .getSrm ()) {
6361 if (counters .containsKey (category )) {
@@ -68,17 +66,17 @@ public static void printStatistics(String message, Set<Method> methods) {
6866 }
6967 }
7068
71- logger .info (message + ": total methods={}, categories={}" , methods .size (), counters . toString () );
69+ logger .info (message + ": total methods={}, categories={}" , methods .size (), counters );
7270 }
7371
7472 public static Set <String > getAllClassesFromDirectory (String dir ) throws IOException {
75- Set <String > classes = new HashSet <String >();
73+ Set <String > classes = new HashSet <>();
7674 File folder = new File (dir );
7775 File [] listOfFiles = folder .listFiles ();
7876 if (listOfFiles != null ) {
79- for (int i = 0 ; i < listOfFiles . length ; i ++ ) {
80- if (listOfFiles [ i ] .getName ().endsWith (".jar" ))
81- classes .addAll (getAllClassesFromJar (listOfFiles [ i ] .getAbsolutePath ()));
77+ for (File listOfFile : listOfFiles ) {
78+ if (listOfFile .getName ().endsWith (".jar" ))
79+ classes .addAll (getAllClassesFromJar (listOfFile .getAbsolutePath ()));
8280 }
8381 }
8482 return classes ;
@@ -89,12 +87,12 @@ public static Map<String, String> getAllClassesFromDir(String dir) throws IOExce
8987 File folder = new File (dir );
9088 File [] listOfFiles = folder .listFiles ();
9189 if (listOfFiles != null ) {
92- for (int i = 0 ; i < listOfFiles . length ; i ++ ) {
93- if (listOfFiles [ i ] .getName ().endsWith (".jar" ))
90+ for (File listOfFile : listOfFiles ) {
91+ if (listOfFile .getName ().endsWith (".jar" ))
9492
9593
96- for (String str : getAllClassesFromJar (listOfFiles [ i ] .getAbsolutePath ())) {
97- classes .put (str , listOfFiles [ i ] .getName ());
94+ for (String str : getAllClassesFromJar (listOfFile .getAbsolutePath ())) {
95+ classes .put (str , listOfFile .getName ());
9896 }
9997
10098 // classes.put(listOfFiles[i].getName() , getAllClassesFromJar(listOfFiles[i].getAbsolutePath()));
@@ -104,7 +102,7 @@ public static Map<String, String> getAllClassesFromDir(String dir) throws IOExce
104102 }
105103
106104 private static Set <String > getAllClassesFromJar (String jarFile ) throws IOException {
107- Set <String > classes = new HashSet <String >();
105+ Set <String > classes = new HashSet <>();
108106 ZipInputStream zip = new ZipInputStream (new FileInputStream (jarFile ));
109107 for (ZipEntry entry = zip .getNextEntry (); entry != null ; entry = zip .getNextEntry ()) {
110108 if (!entry .isDirectory () && entry .getName ().endsWith (".class" )) {
@@ -138,7 +136,7 @@ public static String buildCP(String dir) {
138136
139137 /**
140138 * Creates artificial annotations for non-overridden methods in subclasses. If
141- * the class A implements some method foo() which is marked as e.g. a source and
139+ * class A implements some method foo() which is marked as e.g. a source and
142140 * class B extends A, but does not overwrite foo(), B.foo() must also be a
143141 * source.
144142 *
@@ -214,16 +212,16 @@ private Method findMethod(SootMethod sm) {
214212
215213 public static Set <String > getFiles (String fileInDirectory ) throws IOException {
216214 String directory = fileInDirectory .substring (0 , fileInDirectory .lastIndexOf (File .separator ));
217- String fileName = fileInDirectory .substring (fileInDirectory .lastIndexOf (File .separator ) + 1 ,
218- fileInDirectory . length () );
219- Set <String > files = new HashSet <String >();
215+ String fileName = fileInDirectory .substring (fileInDirectory .lastIndexOf (File .separator ) + 1
216+ );
217+ Set <String > files = new HashSet <>();
220218 File folder = new File (directory );
221219 File [] listOfFiles = folder .listFiles ();
222- for (int i = 0 ; i < listOfFiles . length ; i ++ ) {
223- if (listOfFiles [ i ] .isFile () && listOfFiles [ i ] .getName ().endsWith (".txt" )
224- && !listOfFiles [ i ] .getName ().endsWith ("_" + Category .NONE + ".txt" )
225- && !listOfFiles [ i ] .getName ().equals (fileName )) {
226- files .add (listOfFiles [ i ] .getCanonicalPath ());
220+ for (File listOfFile : listOfFiles ) {
221+ if (listOfFile .isFile () && listOfFile .getName ().endsWith (".txt" )
222+ && !listOfFile .getName ().endsWith ("_" + Category .NONE + ".txt" )
223+ && !listOfFile .getName ().equals (fileName )) {
224+ files .add (listOfFile .getCanonicalPath ());
227225 }
228226 }
229227 return files ;
@@ -272,7 +270,7 @@ public static String getClassName(Instances instances) {
272270 /**
273271 * Export the instances to an ARFF file.
274272 *
275- * @param instances
273+ * @param instances WEKA instances to be exported
276274 */
277275 public static String exportInstancesToArff (Instances instances ) {
278276 ArffSaver saver = new ArffSaver ();
@@ -283,7 +281,10 @@ public static String exportInstancesToArff(Instances instances) {
283281
284282 try {
285283
286- String relationName = instances .relationName ().substring (0 , instances .relationName ().indexOf (":" ));
284+ String relationName = instances .relationName ();
285+
286+ if (instances .relationName ().contains (":" ))
287+ relationName = relationName .substring (0 , instances .relationName ().indexOf (":" ));
287288
288289 String arffFile = SwanPipeline .options .getOutputDir () + File .separator + "arff-data" + File .separator + relationName + ".arff" ;
289290 saver .setFile (new File (arffFile ));
0 commit comments