Skip to content

Commit 30ac5d2

Browse files
Modifying the filter for custom states(AST-99342) (#211)
* Displaying and managing custom states in Eclipse IDE * Removing CustomStateIntegrationTest.java from integration test * Removed extra method and added necessary comments * Modified the filter to populate all the custom states
1 parent 07b2f09 commit 30ac5d2

3 files changed

Lines changed: 48 additions & 17 deletions

File tree

checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/DataProvider.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import com.checkmarx.ast.predicate.CustomState;
2424
import com.checkmarx.ast.predicate.Predicate;
2525
import com.checkmarx.ast.project.Project;
26-
import com.checkmarx.ast.results.ReportFormat;
2726
import com.checkmarx.ast.results.Results;
2827
import com.checkmarx.ast.results.result.Node;
2928
import com.checkmarx.ast.results.result.Result;
@@ -428,7 +427,9 @@ private Result createCleanResult(Result resultItem) {
428427
* @return Cleaned string with decoded HTML entities
429428
*/
430429
private String cleanHtmlEntities(String input) {
431-
if (input == null) return null;
430+
if (input == null) {
431+
return null;
432+
}
432433
return input
433434
.replace(""", "\"")
434435
.replace(""", "\"")
@@ -810,4 +811,10 @@ private List<String> getAllStatesFromPlatform() throws Exception {
810811

811812
return allStates;
812813
}
814+
815+
public List<String> getCustomStates() {
816+
return platformStates.stream().filter(state -> !FilterState.PREDEFINED_STATE_SET.contains(state.toUpperCase()))
817+
.collect(Collectors.toList());
818+
}
819+
813820
}

checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/actions/ActionFilterStatePreference.java

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.checkmarx.eclipse.views.actions;
22

3+
import java.util.List;
4+
35
import org.eclipse.jface.action.Action;
46
import org.eclipse.jface.action.IMenuCreator;
57
import org.eclipse.swt.SWT;
@@ -82,18 +84,22 @@ public Menu getMenu(final Control parent) {
8284
createMenuItem(menu, FILTER_IGNORED, FilterState.ignored, State.IGNORED);
8385
createMenuItem(menu, FILTER_NOT_IGNORED, FilterState.not_ignored, State.NOT_IGNORED);
8486

85-
// Add CUSTOM STATE filter option
86-
MenuItem customItem = new MenuItem(menu, SWT.CHECK);
87-
customItem.setText("CUSTOM STATE");
88-
customItem.setSelection(FilterState.customState);
89-
customItem.addSelectionListener(new SelectionAdapter() {
90-
@Override
91-
public void widgetSelected(SelectionEvent e) {
92-
FilterState.setCustomStateFilter();
93-
pluginEventBus.post(new PluginListenerDefinition(PluginListenerType.FILTER_CHANGED,
94-
DataProvider.getInstance().sortResults()));
95-
}
96-
});
87+
// [AST-92100] Add CUSTOM STATE filter option
88+
List<String> customStates = DataProvider.getInstance().getCustomStates();
89+
90+
for (String customState : customStates) {
91+
MenuItem item = new MenuItem(menu, SWT.CHECK);
92+
item.setText(customState);
93+
item.setSelection(FilterState.isCustomStateSelected(customState));
94+
item.addSelectionListener(new SelectionAdapter() {
95+
@Override
96+
public void widgetSelected(SelectionEvent e) {
97+
FilterState.toggleCustomState(customState);
98+
pluginEventBus.post(new PluginListenerDefinition(PluginListenerType.FILTER_CHANGED,
99+
DataProvider.getInstance().sortResults()));
100+
}
101+
});
102+
}
97103

98104
return menu;
99105
}
@@ -121,4 +127,4 @@ public void widgetSelected(SelectionEvent e) {
121127
public Menu getMenu(final Menu parent) {
122128
return null;
123129
}
124-
}
130+
}

checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/filters/FilterState.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ public class FilterState {
2525
public static final List<String> PREDEFINED_STATES = Arrays.asList("NOT_EXPLOITABLE", "PROPOSED_NOT_EXPLOITABLE",
2626
"TO_VERIFY", "CONFIRMED", "URGENT", "NOT_IGNORED", "IGNORED");
2727
public static final Set<String> PREDEFINED_STATE_SET = new HashSet<>(PREDEFINED_STATES);
28+
// [AST-92100] Custom states are dynamically added based on results
29+
private static final Set<String> enabledCustomStates = new HashSet<>();
2830

2931
// FILTER STATE FLAGS
3032
public static boolean notExploitable = true;
@@ -176,8 +178,8 @@ public static boolean isFilterStateEnabled(String state) {
176178
break;
177179
}
178180
} else {
179-
// Not a predefined state, treat as custom
180-
return customState;
181+
// [AST-92100] Not a predefined state, check if this custom state is enabled
182+
return enabledCustomStates.contains(normalized);
181183
}
182184
return false;
183185
}
@@ -232,6 +234,22 @@ public static void resetFilters() {
232234
customState = true;
233235
}
234236

237+
public static boolean isCustomStateSelected(String stateName) {
238+
return enabledCustomStates.contains(stateName.trim().toUpperCase());
239+
}
240+
241+
/**
242+
* Toggles selection for a specific custom state.
243+
*/
244+
public static void toggleCustomState(String stateName) {
245+
String normalized = stateName.trim().toUpperCase();
246+
if (enabledCustomStates.contains(normalized)) {
247+
enabledCustomStates.remove(normalized);
248+
} else {
249+
enabledCustomStates.add(normalized);
250+
}
251+
}
252+
235253
/**
236254
* Returns the list of filter state names for the filter panel. Shows all
237255
* predefined states and any custom states found in the results.

0 commit comments

Comments
 (0)