Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consolidate the construction of ThreadSafety for ThreadSafe usage. #3812

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.errorprone.util.ASTHelpers.isStatic;

import com.google.async.threadsafety.annotations.ThreadSafe;
import com.google.auto.value.AutoValue;
import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableList;
Expand All @@ -31,6 +32,7 @@
import com.google.common.collect.Streams;
import com.google.errorprone.VisitorState;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.errorprone.annotations.Immutable;
import com.google.errorprone.bugpatterns.CanBeStaticAnalyzer;
import com.google.errorprone.suppliers.Supplier;
import com.google.errorprone.util.ASTHelpers;
Expand Down Expand Up @@ -87,6 +89,29 @@ public static Builder builder() {
return new Builder();
}

public static ThreadSafety.Builder threadSafeBuilder(
WellKnownThreadSafety wellKnownThreadSafety) {
return ThreadSafety.builder()
.setPurpose(Purpose.FOR_THREAD_SAFE_CHECKER)
.knownTypes(wellKnownThreadSafety)
.markerAnnotations(
ImmutableSet.of(
ThreadSafe.class.getName(), "com.google.errorprone.annotations.ThreadSafe"))
.acceptedAnnotations(ImmutableSet.of(Immutable.class.getName()))
.containerOfAnnotation(
ImmutableSet.of(
ThreadSafe.Element.class.getName(),
"com.google.errorprone.annotations.ThreadSafe$Element"))
.typeParameterAnnotation(
ImmutableSet.of(
ThreadSafe.TypeParameter.class.getName(),
"com.google.errorprone.annotations.ThreadSafe$TypeParameter"))
.suppressAnnotation(
ImmutableSet.of(
ThreadSafe.Suppress.class.getName(),
"com.google.errorprone.annotations.ThreadSafe$Suppress"));
}

/**
* The {@link ThreadSafety} utility class can be used by either the bug checker that enforces
* immutability or by the bug checker that enforces thread-safety. Depending on which of these bug
Expand Down Expand Up @@ -165,15 +190,9 @@ public Builder knownTypes(KnownTypes knownTypes) {
* example, when testing a class for immutability, this should be @Immutable.
*/
@CanIgnoreReturnValue
public Builder markerAnnotations(Set<String> markerAnnotations) {
return markerAnnotations(ImmutableSet.copyOf(markerAnnotations));
}

// TODO(ringwalt): Remove this constructor. We need it for binary compatibility.
@CanIgnoreReturnValue
public Builder markerAnnotations(ImmutableSet<String> markerAnnotations) {
public Builder markerAnnotations(Iterable<String> markerAnnotations) {
checkNotNull(markerAnnotations);
this.markerAnnotations = markerAnnotations;
this.markerAnnotations = ImmutableSet.copyOf(markerAnnotations);
return this;
}

Expand All @@ -184,15 +203,9 @@ public Builder markerAnnotations(ImmutableSet<String> markerAnnotations) {
* thread-safe.
*/
@CanIgnoreReturnValue
public Builder acceptedAnnotations(Set<String> acceptedAnnotations) {
return acceptedAnnotations(ImmutableSet.copyOf(acceptedAnnotations));
}

// TODO(ringwalt): Remove this constructor. We need it for binary compatibility.
@CanIgnoreReturnValue
public Builder acceptedAnnotations(ImmutableSet<String> acceptedAnnotations) {
public Builder acceptedAnnotations(Iterable<String> acceptedAnnotations) {
checkNotNull(acceptedAnnotations);
this.acceptedAnnotations = acceptedAnnotations;
this.acceptedAnnotations = ImmutableSet.copyOf(acceptedAnnotations);
return this;
}

Expand All @@ -206,7 +219,7 @@ public Builder containerOfAnnotation(Class<? extends Annotation> containerOfAnno

/** An annotation which marks a generic parameter as a container type. */
@CanIgnoreReturnValue
public Builder containerOfAnnotation(Set<String> containerOfAnnotation) {
public Builder containerOfAnnotation(Iterable<String> containerOfAnnotation) {
checkNotNull(containerOfAnnotation);
this.containerOfAnnotation = ImmutableSet.copyOf(containerOfAnnotation);
return this;
Expand All @@ -222,7 +235,7 @@ public Builder suppressAnnotation(Class<? extends Annotation> suppressAnnotation

/** An annotation which, when found on a class, should suppress the test */
@CanIgnoreReturnValue
public Builder suppressAnnotation(Set<String> suppressAnnotation) {
public Builder suppressAnnotation(Iterable<String> suppressAnnotation) {
checkNotNull(suppressAnnotation);
this.suppressAnnotation = ImmutableSet.copyOf(suppressAnnotation);
return this;
Expand All @@ -248,7 +261,7 @@ public Builder typeParameterAnnotation(Class<? extends Annotation> typeParameter
* only be instantiated with thread-safe types.
*/
@CanIgnoreReturnValue
public Builder typeParameterAnnotation(Set<String> typeParameterAnnotation) {
public Builder typeParameterAnnotation(Iterable<String> typeParameterAnnotation) {
checkNotNull(typeParameterAnnotation);
this.typeParameterAnnotation = ImmutableSet.copyOf(typeParameterAnnotation);
return this;
Expand Down