44import com .intellij .psi .JavaPsiFacade ;
55import com .intellij .psi .PsiClass ;
66import com .intellij .psi .search .GlobalSearchScope ;
7+ import de .fraunhofer .iem .swan .assist .util .Constants ;
78import de .fraunhofer .iem .swan .assist .util .Formatter ;
89import de .fraunhofer .iem .swan .data .Category ;
10+ import javafx .util .Pair ;
911
10- import java .util .*;
12+ import java .util .ArrayList ;
13+ import java .util .HashMap ;
14+ import java .util .HashSet ;
15+ import java .util .Set ;
1116
1217public class JSONFileLoader {
1318
1419 static private HashMap <String , MethodWrapper > methods ;
1520 static private String congFile = "" ;
1621 static public final int NEW_METHOD = 0 ;
1722 static public final int EXISTING_METHOD = 1 ;
18-
19-
20-
23+ static public final int RESTORED_METHOD = 2 ;
2124 static private boolean reloadingSwan = false ;
2225
2326 //Get configuration file location
@@ -32,8 +35,7 @@ public static String getConfigurationFile(boolean path) {
3235 if (path )
3336 return congFile ;
3437 else
35- return congFile .substring (congFile .lastIndexOf ("/" ) + 1 , congFile .length ());
36-
38+ return congFile .substring (congFile .lastIndexOf ("/" ) + 1 );
3739 }
3840
3941 //Returns whether or not a configuration file was selected
@@ -63,43 +65,74 @@ public static ArrayList<MethodWrapper> getMethods() {
6365 return new ArrayList <>(methods .values ());
6466 }
6567
68+ //Return list of methods as an array
69+ public static HashMap <String , MethodWrapper > getAllMethods () {
70+
71+ return methods ;
72+ }
6673
6774 //Return list of methods as an array using categories
68- public static ArrayList <MethodWrapper > getMethods (ArrayList <String > filters , String currentFile , boolean currentFileMode , boolean currentProjectMode , Project project ) {
75+ public static ArrayList <MethodWrapper > getMethods (ArrayList <Pair < String , String >> filters , String currentFile , Project project ) {
6976
70- if (filters .size () == 0 && ( currentFileMode || currentProjectMode ) ) {
77+ if (filters .size () > 0 ) {
7178
72- ArrayList <MethodWrapper > filteredList = new ArrayList <>();
79+ //case where file selected but no categories .
80+ if (filters .size () == 1 && filters .contains (Constants .FILE_FILTER )) {
7381
74- for ( String methodSignature : methods . keySet ()) {
82+ ArrayList < MethodWrapper > filteredList = new ArrayList <>();
7583
76- if ((methodSignature .contains (currentFile ) && currentFileMode ) || (inProject (methods .get (methodSignature ).getClassName (true ), project ) && currentProjectMode )) {
77- filteredList .add (methods .get (methodSignature ));
84+ for (String methodSignature : methods .keySet ()) {
85+ if (methodSignature .contains (currentFile )) {
86+ filteredList .add (methods .get (methodSignature ));
87+ }
7888 }
89+ return filteredList ;
90+ } else {
91+ //case where file is selected and categories
92+ return filterList (filters , currentFile );
7993 }
80- return filteredList ;
81- } else if (filters .size () > 0 ) {
82-
94+ } else {
8395 ArrayList <MethodWrapper > filteredList = new ArrayList <>();
8496
85- for (String methodSignature : methods .keySet ()) {
97+ for (MethodWrapper method : methods .values ()) {
8698
87- if ((!methodSignature .contains (currentFile ) && currentFileMode ) || (!inProject (methods .get (methodSignature ).getClassName (true ), project ) && currentProjectMode ))
99+
100+ if (method .getUpdateOperation ().equals (Constants .METHOD_DELETED ) || method .isTrainingMethod ())
88101 continue ;
89102
90- for (Category category : methods .get (methodSignature ).getCategories ()) {
103+ System .out .println (method .getSignature (true ));
104+ filteredList .add (method );
105+ }
106+ return filteredList ;
107+ }
108+ }
109+
110+ private static ArrayList <MethodWrapper > filterList (ArrayList <Pair <String , String >> filters , String currentFile ) {
111+ ArrayList <MethodWrapper > filteredList = new ArrayList <>();
91112
92- if (filters .contains (Formatter .capitalizeFirstCharacter (category .toString ()))) {
93- filteredList .add (methods .get (methodSignature ));
94- break ;
95- }
113+ for (String methodSignature : methods .keySet ()) {
114+
115+ if ((filters .contains (Constants .FILE_FILTER ) && !methodSignature .contains (currentFile ))
116+ || (!filters .contains (Constants .DELETED_FILTER ) && methods .get (methodSignature ).getUpdateOperation ().equals (Constants .METHOD_DELETED ))
117+ || (methods .get (methodSignature ).isTrainingMethod () && !filters .contains (Constants .TRAIN_FILTER )))
118+ continue ;
119+
120+ for (Category category : methods .get (methodSignature ).getCategories ()) {
121+
122+ if ((filters .contains (Constants .DELETED_FILTER ) && methods .get (methodSignature ).getUpdateOperation ().equals (Constants .METHOD_DELETED ))
123+ || filters .contains (new Pair <>(Constants .FILTER_TYPE , Formatter .toTitleCase (category .toString ())))
124+ || filters .contains (new Pair <>(Constants .FILTER_CWE , Formatter .toTitleCase (category .toString ())))
125+ || (methods .get (methodSignature ).isTrainingMethod () && filters .contains (Constants .TRAIN_FILTER ))) {
126+
127+ filteredList .add (methods .get (methodSignature ));
128+ break ;
96129 }
97130 }
98- return filteredList ;
99- } else
100- return new ArrayList <>(methods .values ());
131+ }
132+ return filteredList ;
101133 }
102134
135+
103136 //Return list of categories as a set
104137 public static Set <Category > getCategories () {
105138
@@ -127,13 +160,13 @@ public static int addMethod(MethodWrapper method) {
127160 }
128161 }
129162
130- //Add new method to the list
163+ //Check if method exists in list
131164 public static boolean methodExists (String methodSignature ) {
132165
133166 return methods .containsKey (methodSignature );
134167 }
135168
136- //Add new method to the list
169+ //Returns method for the specified signature
137170 public static MethodWrapper getMethod (String methodSignature ) {
138171
139172 return methods .get (methodSignature );
0 commit comments