private static UserPreferences readPreferences(Preferences settings, boolean defaultsToDisabled) { boolean atLeastOneEnabled = false; UserPreferences prefs = UserPreferences.createDefaultUserPreferences(); DetectorFactoryCollection dfc = DetectorFactoryCollection.instance(); for (DetectorFactory df : dfc.getFactories()) { boolean enable = false; if (!df.isHidden()) { for (BugPattern bp : df.getReportedBugPatterns()) { BugCategory c = dfc.getBugCategory(bp.getCategory()); if (c.isHidden()) continue; enable |= settings.getBoolean(bp.getType(), !defaultsToDisabled && prefs.isDetectorEnabled(df)); } } atLeastOneEnabled |= enable; prefs.enableDetector(df, enable); } return atLeastOneEnabled ? prefs : null; }
public static boolean isEnabledByDefault(BugPattern bp) { DetectorFactoryCollection dfc = DetectorFactoryCollection.instance(); for (DetectorFactory df : dfc.getFactories()) { if (df.getReportedBugPatterns().contains(bp)) { return UserPreferences.createDefaultUserPreferences().isDetectorEnabled(df); } } return false; }
private static Map<String, Set<String>> createIndexDetectorsShortNameByBugPatternType() { final Map<String, Set<String>> ret = new HashMap<String, Set<String>>(); for (final DetectorFactory detector : FindBugsPreferences.getDetectorFactorCollection().getFactories()) { for (final BugPattern bugPattern : detector.getReportedBugPatterns()) { Set<String> detectorsShortName = ret.get(bugPattern.getType()); if (detectorsShortName == null) { detectorsShortName = new HashSet<String>(); ret.put(bugPattern.getType(), detectorsShortName); } detectorsShortName.add(detector.getShortName()); } } return ret; }
private static UserPreferences forSingleBug(String id) { boolean atLeastOneEnabled = false; UserPreferences prefs = UserPreferences.createDefaultUserPreferences(); for (DetectorFactory df : DetectorFactoryCollection.instance().getFactories()) { boolean enable = false; for (BugPattern bp : df.getReportedBugPatterns()) { if (id.equals(bp.getType())) { enable = true; break; } } atLeastOneEnabled |= enable; prefs.enableDetector(df, enable); } return atLeastOneEnabled ? prefs : null; }