Skip to content

Commit

Permalink
Excavator: Upgrades Baseline to the latest version (#1313)
Browse files Browse the repository at this point in the history
  • Loading branch information
svc-excavator-bot authored Jan 12, 2022
1 parent bd01a2f commit dc0badd
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 18 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {

dependencies {
classpath 'com.google.errorprone:error_prone_core:2.10.0'
classpath 'com.palantir.baseline:gradle-baseline-java:4.56.0'
classpath 'com.palantir.baseline:gradle-baseline-java:4.57.0'
classpath 'com.palantir.gradle.consistentversions:gradle-consistent-versions:2.5.0'
classpath 'com.palantir.gradle.externalpublish:gradle-external-publish-plugin:1.6.0'
classpath 'com.palantir.gradle.gitversion:gradle-git-version:0.12.3'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@
import static com.palantir.logsafe.Preconditions.checkNotNull;

import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableSet;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Collections;
import java.util.IdentityHashMap;
import java.util.Set;
import javax.annotation.Nullable;

public final class AnnotationHelper {
Expand Down Expand Up @@ -88,16 +90,16 @@ public static <T extends Annotation> T getMethodAnnotation(
}

@VisibleForTesting
private static ImmutableSet<Class<?>> getParentClasses(Class<?> clazz) {
ImmutableSet.Builder<Class<?>> builder = ImmutableSet.builder();
builder.add(clazz.getInterfaces());
private static Set<Class<?>> getParentClasses(Class<?> clazz) {
Set<Class<?>> parentClasses = Collections.newSetFromMap(new IdentityHashMap<>());
parentClasses.addAll(Arrays.asList(clazz.getInterfaces()));
Class<?> superclass = clazz.getSuperclass();
while (superclass != null) {
builder.add(superclass.getInterfaces());
builder.add(superclass);
parentClasses.addAll(Arrays.asList(superclass.getInterfaces()));
parentClasses.add(superclass);
superclass = superclass.getSuperclass();
}
return builder.build();
return parentClasses;
}

public static final class MethodSignature {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import com.google.common.base.Strings;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.google.common.collect.ImmutableSet;
import com.palantir.logsafe.Preconditions;
import com.palantir.logsafe.Safe;
import com.palantir.logsafe.SafeArg;
Expand All @@ -47,6 +46,9 @@
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Arrays;
import java.util.Collections;
import java.util.IdentityHashMap;
import java.util.Map;
import java.util.Set;
import java.util.SortedMap;
Expand Down Expand Up @@ -444,10 +446,11 @@ private static <T extends Metric> T registerOrReplace(
if (existingMetric == null) {
return registry.register(name, metric);
} else {
Set<Class<?>> existingMetricInterfaces =
ImmutableSet.copyOf(existingMetric.getClass().getInterfaces());
Set<Class<?>> newMetricInterfaces =
ImmutableSet.copyOf(metric.getClass().getInterfaces());
Set<Class<?>> existingMetricInterfaces = Collections.newSetFromMap(new IdentityHashMap<>());
existingMetricInterfaces.addAll(
Arrays.asList(existingMetric.getClass().getInterfaces()));
Set<Class<?>> newMetricInterfaces = Collections.newSetFromMap(new IdentityHashMap<>());
newMetricInterfaces.addAll(Arrays.asList(metric.getClass().getInterfaces()));
if (!existingMetricInterfaces.equals(newMetricInterfaces)) {
throw new SafeIllegalArgumentException(
"Metric already registered at this name that implements a different set of interfaces",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ static void checkIsInterface(Class<?> iface) {
}
}

static void checkAreAllInterfaces(Set<Class<?>> interfaces) {
static void checkAreAllInterfaces(Iterable<Class<?>> interfaces) {
for (Class<?> possibleInterface : interfaces) {
checkIsInterface(possibleInterface);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;

import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableList;
import com.palantir.tritium.test.MoreSpecificReturn;
import com.palantir.tritium.test.TestImplementation;
import com.palantir.tritium.test.TestInterface;
Expand Down Expand Up @@ -58,13 +58,14 @@ void testCheckIsInterfaceOnClass() {

@Test
void testCheckAreAllInterfaces() {
Proxies.checkAreAllInterfaces(ImmutableSet.of(TestInterface.class, Runnable.class, Callable.class, List.class));
Proxies.checkAreAllInterfaces(
ImmutableList.of(TestInterface.class, Runnable.class, Callable.class, List.class));
}

@Test
void testCheckAreAllInterfacesWithClass() {
ImmutableSet<Class<?>> interfaces =
ImmutableSet.of(TestInterface.class, String.class, Runnable.class, Callable.class, List.class);
List<Class<?>> interfaces =
ImmutableList.of(TestInterface.class, String.class, Runnable.class, Callable.class, List.class);
assertThatExceptionOfType(IllegalArgumentException.class)
.isThrownBy(() -> Proxies.checkAreAllInterfaces(interfaces));
}
Expand Down

0 comments on commit dc0badd

Please sign in to comment.