Search in sources :

Example 1 with CheckReturnValue

use of javax.annotation.CheckReturnValue in project jmxtrans by jmxtrans.

the class ConfigurationParser method mergeServerLists.

/**
	 * Merges two lists of servers (and their queries). Based on the equality of
	 * both sets of objects. Public for testing purposes.
	 * @param secondList
	 * @param firstList
	 */
// FIXME: the params for this method should be Set<Server> as there are multiple assumptions that they are unique
@CheckReturnValue
@VisibleForTesting
ImmutableList<Server> mergeServerLists(List<Server> firstList, List<Server> secondList) {
    ImmutableList.Builder<Server> results = ImmutableList.builder();
    List<Server> toProcess = new ArrayList<>(secondList);
    for (Server firstServer : firstList) {
        if (toProcess.contains(firstServer)) {
            Server found = toProcess.get(secondList.indexOf(firstServer));
            results.add(merge(firstServer, found));
            // remove server as it is already merged
            toProcess.remove(found);
        } else {
            results.add(firstServer);
        }
    }
    // add servers from the second list that are not in the first one
    results.addAll(toProcess);
    return results.build();
}
Also used : Server(com.googlecode.jmxtrans.model.Server) ImmutableList(com.google.common.collect.ImmutableList) ArrayList(java.util.ArrayList) CheckReturnValue(javax.annotation.CheckReturnValue) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 2 with CheckReturnValue

use of javax.annotation.CheckReturnValue in project error-prone by google.

the class ScannerSupplier method applyOverrides.

/**
   * Applies options to this {@link ScannerSupplier}.
   *
   * <p>Command-line options to override check severities may do any of the following:
   * <ul>
   * <li>Enable a check that is currently off</li>
   * <li>Disable a check that is currently on</li>
   * <li>Change the severity of a check that is on, promoting a warning to an error or demoting
   * an error to a warning</li>
   * </ul>
   *
   * @param errorProneOptions an {@link ErrorProneOptions} object that encapsulates the overrides
   * for this compilation
   * @throws InvalidCommandLineOptionException if the override map attempts to disable a check
   * that may not be disabled
   */
@CheckReturnValue
public ScannerSupplier applyOverrides(ErrorProneOptions errorProneOptions) throws InvalidCommandLineOptionException {
    Map<String, Severity> severityOverrides = errorProneOptions.getSeverityMap();
    if (severityOverrides.isEmpty() && !errorProneOptions.isEnableAllChecks() && !errorProneOptions.isDropErrorsToWarnings() && !errorProneOptions.isDisableAllChecks()) {
        return this;
    }
    // Initialize result allChecks map and enabledChecks set with current state of this Supplier.
    ImmutableBiMap<String, BugCheckerInfo> checks = getAllChecks();
    Map<String, SeverityLevel> severities = new LinkedHashMap<>(severities());
    Set<String> disabled = new HashSet<>(disabled());
    if (errorProneOptions.isEnableAllChecks()) {
        disabled.forEach(c -> severities.put(c, checks.get(c).defaultSeverity()));
        disabled.clear();
    }
    if (errorProneOptions.isDropErrorsToWarnings()) {
        getAllChecks().values().stream().filter(c -> c.defaultSeverity() == SeverityLevel.ERROR && c.suppressibility().disableable()).forEach(c -> severities.put(c.canonicalName(), SeverityLevel.WARNING));
    }
    if (errorProneOptions.isDisableAllChecks()) {
        getAllChecks().values().stream().filter(c -> c.suppressibility().disableable()).forEach(c -> disabled.add(c.canonicalName()));
    }
    // Process overrides
    severityOverrides.forEach((checkName, newSeverity) -> {
        BugCheckerInfo check = getAllChecks().get(checkName);
        if (check == null) {
            if (errorProneOptions.ignoreUnknownChecks()) {
                return;
            }
            throw new InvalidCommandLineOptionException(checkName + " is not a valid checker name");
        }
        switch(newSeverity) {
            case OFF:
                if (!check.suppressibility().disableable()) {
                    throw new InvalidCommandLineOptionException(check.canonicalName() + " may not be disabled");
                }
                severities.remove(check.canonicalName());
                disabled.add(check.canonicalName());
                break;
            case DEFAULT:
                severities.put(check.canonicalName(), check.defaultSeverity());
                disabled.remove(check.canonicalName());
                break;
            case WARN:
                // Demoting an enabled check from an error to a warning is a form of disabling
                if (!disabled().contains(check.canonicalName()) && !check.suppressibility().disableable() && check.defaultSeverity() == SeverityLevel.ERROR) {
                    throw new InvalidCommandLineOptionException(check.canonicalName() + " is not disableable and may not be demoted to a warning");
                }
                severities.put(check.canonicalName(), SeverityLevel.WARNING);
                disabled.remove(check.canonicalName());
                break;
            case ERROR:
                severities.put(check.canonicalName(), SeverityLevel.ERROR);
                disabled.remove(check.canonicalName());
                break;
            default:
                throw new IllegalStateException("Unexpected severity level: " + newSeverity);
        }
    });
    return new ScannerSupplierImpl(checks, ImmutableMap.copyOf(severities), ImmutableSet.copyOf(disabled));
}
Also used : Arrays(java.util.Arrays) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) Supplier(com.google.common.base.Supplier) BugChecker(com.google.errorprone.bugpatterns.BugChecker) Set(java.util.Set) Severity(com.google.errorprone.ErrorProneOptions.Severity) Sets(com.google.common.collect.Sets) ImmutableBiMap(com.google.common.collect.ImmutableBiMap) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) CheckReturnValue(javax.annotation.CheckReturnValue) ImmutableList(com.google.common.collect.ImmutableList) Predicate(com.google.common.base.Predicate) BugCheckerInfo(com.google.errorprone.BugCheckerInfo) ErrorProneOptions(com.google.errorprone.ErrorProneOptions) Map(java.util.Map) BugPattern(com.google.errorprone.BugPattern) VisibleForTesting(com.google.common.annotations.VisibleForTesting) InvalidCommandLineOptionException(com.google.errorprone.InvalidCommandLineOptionException) SeverityLevel(com.google.errorprone.BugPattern.SeverityLevel) BugCheckerInfo(com.google.errorprone.BugCheckerInfo) InvalidCommandLineOptionException(com.google.errorprone.InvalidCommandLineOptionException) Severity(com.google.errorprone.ErrorProneOptions.Severity) LinkedHashMap(java.util.LinkedHashMap) SeverityLevel(com.google.errorprone.BugPattern.SeverityLevel) HashSet(java.util.HashSet) CheckReturnValue(javax.annotation.CheckReturnValue)

Example 3 with CheckReturnValue

use of javax.annotation.CheckReturnValue in project error-prone by google.

the class IncompatibleArgumentType method populateTypesToEnforce.

@CheckReturnValue
private boolean populateTypesToEnforce(MethodSymbol declaredMethod, Type calledMethodType, Type calledReceiverType, List<RequiredType> requiredTypesAtCallSite, VisitorState state) {
    // We'll only search the first method in the hierarchy with an annotation.
    boolean found = false;
    com.sun.tools.javac.util.List<VarSymbol> params = declaredMethod.params();
    for (int i = 0; i < params.size(); i++) {
        VarSymbol varSymbol = params.get(i);
        CompatibleWith anno = ASTHelpers.getAnnotation(varSymbol, CompatibleWith.class);
        if (anno != null) {
            found = true;
            if (requiredTypesAtCallSite.size() <= i) {
                // void foo(String...); foo();
                break;
            }
            // Now we try and resolve the generic type argument in the annotation against the current
            // method call's projection of this generic type.
            RequiredType requiredType = resolveRequiredTypeForThisCall(state, calledMethodType, calledReceiverType, declaredMethod, anno.value());
            requiredTypesAtCallSite.set(i, requiredType);
        }
    }
    return found;
}
Also used : VarSymbol(com.sun.tools.javac.code.Symbol.VarSymbol) CompatibleWith(com.google.errorprone.annotations.CompatibleWith) CheckReturnValue(javax.annotation.CheckReturnValue)

Example 4 with CheckReturnValue

use of javax.annotation.CheckReturnValue in project grpc-java by grpc.

the class InProcessTransport method start.

@CheckReturnValue
@Override
public synchronized Runnable start(ManagedClientTransport.Listener listener) {
    this.clientTransportListener = listener;
    InProcessServer server = InProcessServer.findServer(name);
    if (server != null) {
        serverTransportListener = server.register(this);
    }
    if (serverTransportListener == null) {
        shutdownStatus = Status.UNAVAILABLE.withDescription("Could not find server: " + name);
        final Status localShutdownStatus = shutdownStatus;
        return new Runnable() {

            @Override
            public void run() {
                synchronized (InProcessTransport.this) {
                    notifyShutdown(localShutdownStatus);
                    notifyTerminated();
                }
            }
        };
    }
    return new Runnable() {

        @Override
        @SuppressWarnings("deprecation")
        public void run() {
            synchronized (InProcessTransport.this) {
                Attributes serverTransportAttrs = Attributes.newBuilder().set(Grpc.TRANSPORT_ATTR_REMOTE_ADDR, new InProcessSocketAddress(name)).build();
                serverStreamAttributes = serverTransportListener.transportReady(serverTransportAttrs);
                clientTransportListener.transportReady();
            }
        }
    };
}
Also used : Status(io.grpc.Status) Attributes(io.grpc.Attributes) CheckReturnValue(javax.annotation.CheckReturnValue)

Example 5 with CheckReturnValue

use of javax.annotation.CheckReturnValue in project core-java by SpineEventEngine.

the class Aggregate method toSnapshot.

/**
     * Transforms the current state of the aggregate into the {@link Snapshot} instance.
     *
     * @return new snapshot
     */
@CheckReturnValue
Snapshot toSnapshot() {
    final Any state = AnyPacker.pack(getState());
    final Snapshot.Builder builder = Snapshot.newBuilder().setState(state).setVersion(getVersion()).setTimestamp(getCurrentTime());
    return builder.build();
}
Also used : Any(com.google.protobuf.Any) CheckReturnValue(javax.annotation.CheckReturnValue)

Aggregations

CheckReturnValue (javax.annotation.CheckReturnValue)13 VisibleForTesting (com.google.common.annotations.VisibleForTesting)4 ArrayList (java.util.ArrayList)3 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 PropertyChangeListener (java.beans.PropertyChangeListener)2 Predicate (com.google.common.base.Predicate)1 Supplier (com.google.common.base.Supplier)1 ImmutableBiMap (com.google.common.collect.ImmutableBiMap)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Sets (com.google.common.collect.Sets)1 BugCheckerInfo (com.google.errorprone.BugCheckerInfo)1 BugPattern (com.google.errorprone.BugPattern)1 SeverityLevel (com.google.errorprone.BugPattern.SeverityLevel)1 ErrorProneOptions (com.google.errorprone.ErrorProneOptions)1 Severity (com.google.errorprone.ErrorProneOptions.Severity)1 InvalidCommandLineOptionException (com.google.errorprone.InvalidCommandLineOptionException)1 CompatibleWith (com.google.errorprone.annotations.CompatibleWith)1 BugChecker (com.google.errorprone.bugpatterns.BugChecker)1 Any (com.google.protobuf.Any)1