diff --git a/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/DataProvider.java b/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/DataProvider.java index 6450ae3..17e64bc 100644 --- a/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/DataProvider.java +++ b/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/DataProvider.java @@ -23,7 +23,6 @@ import com.checkmarx.ast.predicate.CustomState; import com.checkmarx.ast.predicate.Predicate; import com.checkmarx.ast.project.Project; -import com.checkmarx.ast.results.ReportFormat; import com.checkmarx.ast.results.Results; import com.checkmarx.ast.results.result.Node; import com.checkmarx.ast.results.result.Result; @@ -428,7 +427,9 @@ private Result createCleanResult(Result resultItem) { * @return Cleaned string with decoded HTML entities */ private String cleanHtmlEntities(String input) { - if (input == null) return null; + if (input == null) { + return null; + } return input .replace(""", "\"") .replace(""", "\"") @@ -810,4 +811,10 @@ private List getAllStatesFromPlatform() throws Exception { return allStates; } + + public List getCustomStates() { + return platformStates.stream().filter(state -> !FilterState.PREDEFINED_STATE_SET.contains(state.toUpperCase())) + .collect(Collectors.toList()); + } + } diff --git a/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/actions/ActionFilterStatePreference.java b/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/actions/ActionFilterStatePreference.java index a36a3af..f67d689 100644 --- a/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/actions/ActionFilterStatePreference.java +++ b/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/actions/ActionFilterStatePreference.java @@ -1,5 +1,7 @@ package com.checkmarx.eclipse.views.actions; +import java.util.List; + import org.eclipse.jface.action.Action; import org.eclipse.jface.action.IMenuCreator; import org.eclipse.swt.SWT; @@ -82,18 +84,22 @@ public Menu getMenu(final Control parent) { createMenuItem(menu, FILTER_IGNORED, FilterState.ignored, State.IGNORED); createMenuItem(menu, FILTER_NOT_IGNORED, FilterState.not_ignored, State.NOT_IGNORED); - // Add CUSTOM STATE filter option - MenuItem customItem = new MenuItem(menu, SWT.CHECK); - customItem.setText("CUSTOM STATE"); - customItem.setSelection(FilterState.customState); - customItem.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - FilterState.setCustomStateFilter(); - pluginEventBus.post(new PluginListenerDefinition(PluginListenerType.FILTER_CHANGED, - DataProvider.getInstance().sortResults())); - } - }); + // [AST-92100] Add CUSTOM STATE filter option + List customStates = DataProvider.getInstance().getCustomStates(); + + for (String customState : customStates) { + MenuItem item = new MenuItem(menu, SWT.CHECK); + item.setText(customState); + item.setSelection(FilterState.isCustomStateSelected(customState)); + item.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + FilterState.toggleCustomState(customState); + pluginEventBus.post(new PluginListenerDefinition(PluginListenerType.FILTER_CHANGED, + DataProvider.getInstance().sortResults())); + } + }); + } return menu; } @@ -121,4 +127,4 @@ public void widgetSelected(SelectionEvent e) { public Menu getMenu(final Menu parent) { return null; } -} +} \ No newline at end of file diff --git a/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/filters/FilterState.java b/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/filters/FilterState.java index d2eee9e..a3c41d0 100644 --- a/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/filters/FilterState.java +++ b/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/filters/FilterState.java @@ -25,6 +25,8 @@ public class FilterState { public static final List PREDEFINED_STATES = Arrays.asList("NOT_EXPLOITABLE", "PROPOSED_NOT_EXPLOITABLE", "TO_VERIFY", "CONFIRMED", "URGENT", "NOT_IGNORED", "IGNORED"); public static final Set PREDEFINED_STATE_SET = new HashSet<>(PREDEFINED_STATES); + // [AST-92100] Custom states are dynamically added based on results + private static final Set enabledCustomStates = new HashSet<>(); // FILTER STATE FLAGS public static boolean notExploitable = true; @@ -176,8 +178,8 @@ public static boolean isFilterStateEnabled(String state) { break; } } else { - // Not a predefined state, treat as custom - return customState; + // [AST-92100] Not a predefined state, check if this custom state is enabled + return enabledCustomStates.contains(normalized); } return false; } @@ -232,6 +234,22 @@ public static void resetFilters() { customState = true; } + public static boolean isCustomStateSelected(String stateName) { + return enabledCustomStates.contains(stateName.trim().toUpperCase()); + } + + /** + * Toggles selection for a specific custom state. + */ + public static void toggleCustomState(String stateName) { + String normalized = stateName.trim().toUpperCase(); + if (enabledCustomStates.contains(normalized)) { + enabledCustomStates.remove(normalized); + } else { + enabledCustomStates.add(normalized); + } + } + /** * Returns the list of filter state names for the filter panel. Shows all * predefined states and any custom states found in the results.