Search in sources :

Example 1 with ErrorProneFlags

use of com.google.errorprone.ErrorProneFlags in project error-prone by google.

the class ScannerSupplier method plus.

/**
 * Composes this {@link ScannerSupplier} with the {@code other} {@link ScannerSupplier}. The set
 * of checks that are turned on is the intersection of the checks on in {@code this} and {@code
 * other}.
 */
@CheckReturnValue
public ScannerSupplier plus(ScannerSupplier other) {
    HashBiMap<String, BugCheckerInfo> combinedAllChecks = HashBiMap.create(this.getAllChecks());
    other.getAllChecks().forEach((k, v) -> {
        BugCheckerInfo existing = combinedAllChecks.putIfAbsent(k, v);
        if (existing != null && !existing.checkerClass().getName().contentEquals(v.checkerClass().getName())) {
            throw new IllegalArgumentException(String.format("Cannot combine scanner suppliers with different implementations of" + " '%s': %s, %s", k, v.checkerClass().getName(), existing.checkerClass().getName()));
        }
    });
    HashMap<String, SeverityLevel> combinedSeverities = new LinkedHashMap<>(this.severities());
    other.severities().forEach((k, v) -> {
        SeverityLevel existing = combinedSeverities.putIfAbsent(k, v);
        if (existing != null && !existing.equals(v)) {
            throw new IllegalArgumentException(String.format("Cannot combine scanner suppliers with different severities for" + " '%s': %s, %s", k, v, existing));
        }
    });
    ImmutableSet<String> disabled = ImmutableSet.copyOf(Sets.union(disabled(), other.disabled()));
    ErrorProneFlags combinedFlags = this.getFlags().plus(other.getFlags());
    return new ScannerSupplierImpl(ImmutableBiMap.copyOf(combinedAllChecks), ImmutableMap.copyOf(combinedSeverities), disabled, combinedFlags);
}
Also used : SeverityLevel(com.google.errorprone.BugPattern.SeverityLevel) BugCheckerInfo(com.google.errorprone.BugCheckerInfo) ErrorProneFlags(com.google.errorprone.ErrorProneFlags) LinkedHashMap(java.util.LinkedHashMap) CheckReturnValue(com.google.errorprone.annotations.CheckReturnValue)

Aggregations

BugCheckerInfo (com.google.errorprone.BugCheckerInfo)1 SeverityLevel (com.google.errorprone.BugPattern.SeverityLevel)1 ErrorProneFlags (com.google.errorprone.ErrorProneFlags)1 CheckReturnValue (com.google.errorprone.annotations.CheckReturnValue)1 LinkedHashMap (java.util.LinkedHashMap)1