Skip to content

Commit

Permalink
Add temporary new methods to address ClassLoader issues in ThreadSafety.
Browse files Browse the repository at this point in the history
In a follow-up, we can cast all arguments to Set<String> to use the new methods, and then remove the old methods using ImmutableSet when binary compatibility is no longer an issue.

RELNOTES: N/A

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=178412582
  • Loading branch information
ringw authored and cushon committed Dec 13, 2017
1 parent bf09874 commit c1fca18
Showing 1 changed file with 42 additions and 2 deletions.
Expand Up @@ -77,6 +77,23 @@ public final class ThreadSafety {
* @param containerOfAnnotation an annotation which marks a generic parameter as a container type * @param containerOfAnnotation an annotation which marks a generic parameter as a container type
* @param suppressAnnotation an annotation which, when found on a class, should suppress the test * @param suppressAnnotation an annotation which, when found on a class, should suppress the test
*/ */
public ThreadSafety(
VisitorState state,
KnownTypes knownTypes,
Set<String> markerAnnotations,
Set<String> acceptedAnnotations,
@Nullable Class<? extends Annotation> containerOfAnnotation,
@Nullable Class<? extends Annotation> suppressAnnotation) {
this(
state,
knownTypes,
ImmutableSet.copyOf(checkNotNull(markerAnnotations)),
ImmutableSet.copyOf(checkNotNull(acceptedAnnotations)),
containerOfAnnotation,
suppressAnnotation);
}

// TODO(ringwalt): Remove this constructor. We currently need it for binary compatibility.
public ThreadSafety( public ThreadSafety(
VisitorState state, VisitorState state,
KnownTypes knownTypes, KnownTypes knownTypes,
Expand Down Expand Up @@ -158,6 +175,12 @@ public static Violation absent() {
* @param annotation the type's {@code @ThreadSafe} info * @param annotation the type's {@code @ThreadSafe} info
* @param type the type to check * @param type the type to check
*/ */
public Violation threadSafeInstantiation(
Set<String> threadSafeTypeParams, AnnotationInfo annotation, Type type) {
return threadSafeInstantiation(ImmutableSet.copyOf(threadSafeTypeParams), annotation, type);
}

// TODO(ringwalt): Remove this method. We currently need it for binary compatibility.
public Violation threadSafeInstantiation( public Violation threadSafeInstantiation(
ImmutableSet<String> threadSafeTypeParams, AnnotationInfo annotation, Type type) { ImmutableSet<String> threadSafeTypeParams, AnnotationInfo annotation, Type type) {
if (!annotation.containerOf().isEmpty() if (!annotation.containerOf().isEmpty()
Expand Down Expand Up @@ -196,15 +219,20 @@ public Violation threadSafeInstantiation(
} }


/** Returns an {@link Violation} explaining whether the type is threadsafe. */ /** Returns an {@link Violation} explaining whether the type is threadsafe. */
public Violation isThreadSafeType(Set<String> threadSafeTypeParams, Type type) {
return isThreadSafeType(ImmutableSet.copyOf(threadSafeTypeParams), type);
}

// TODO(ringwalt): Remove this method. We currently need it for binary compatibility.
public Violation isThreadSafeType(ImmutableSet<String> threadSafeTypeParams, Type type) { public Violation isThreadSafeType(ImmutableSet<String> threadSafeTypeParams, Type type) {
return type.accept(new ThreadSafeTypeVisitor(threadSafeTypeParams), null); return type.accept(new ThreadSafeTypeVisitor(threadSafeTypeParams), null);
} }


private class ThreadSafeTypeVisitor extends Types.SimpleVisitor<Violation, Void> { private class ThreadSafeTypeVisitor extends Types.SimpleVisitor<Violation, Void> {


private final ImmutableSet<String> threadSafeTypeParams; private final Set<String> threadSafeTypeParams;


private ThreadSafeTypeVisitor(ImmutableSet<String> threadSafeTypeParams) { private ThreadSafeTypeVisitor(Set<String> threadSafeTypeParams) {
this.threadSafeTypeParams = threadSafeTypeParams; this.threadSafeTypeParams = threadSafeTypeParams;
} }


Expand Down Expand Up @@ -329,6 +357,18 @@ && isThreadSafeType(ImmutableSet.of(), enclosing).isPresent()) {
* </pre> * </pre>
*/ */
public ImmutableSet<String> threadSafeTypeParametersInScope(Symbol sym) { public ImmutableSet<String> threadSafeTypeParametersInScope(Symbol sym) {
return ImmutableSet.copyOf(threadSafeTypeParameterSetInScope(sym));
}

/**
* Gets the set of in-scope threadsafe type parameters from the containerOf specs on annotations.
*
* @deprecated This method only exists to make a non-binary-compatible change to the {@link
* #threadSafeTypeParametersInScope} return value. It will be removed once we can safely
* change that method's return value.
*/
@Deprecated
public Set<String> threadSafeTypeParameterSetInScope(Symbol sym) {
if (sym == null) { if (sym == null) {
return ImmutableSet.of(); return ImmutableSet.of();
} }
Expand Down

0 comments on commit c1fca18

Please sign in to comment.