Skip to content

Commit 6e4604f

Browse files
committed
Use top-level super method to determine annotation for @internal apis
1 parent 58a4e03 commit 6e4604f

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/main/java/io/grpc/annotations/checkers/AnnotationChecker.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,20 @@
2929
import com.sun.source.tree.MemberSelectTree;
3030
import com.sun.source.tree.Tree;
3131
import com.sun.tools.javac.code.Symbol;
32+
import com.sun.tools.javac.code.Symbol.MethodSymbol;
3233
import javax.lang.model.element.AnnotationMirror;
34+
import java.util.Set;
3335

3436
abstract class AnnotationChecker extends BugChecker implements IdentifierTreeMatcher,
3537
MemberSelectTreeMatcher {
3638

3739
private final String annotationType;
3840

41+
// When this is set to true, method calls will look for an annotation on the top-level method
42+
// declaration. This is used to avoid io.grpc.internal implementations "hiding" publicly declared
43+
// API methods.
44+
protected boolean checkTopOfMethodHierarchy = false;
45+
3946
AnnotationChecker(String annotationType) {
4047
this.annotationType = checkNotNull(annotationType, "annotationType");
4148
}
@@ -64,6 +71,15 @@ private Description match(Tree tree, VisitorState state) {
6471
if (symbol == null) {
6572
return NO_MATCH;
6673
}
74+
if (checkTopOfMethodHierarchy && symbol instanceof MethodSymbol) {
75+
// Returns an ordered LinkedHashSet
76+
Set<MethodSymbol> superMethods =
77+
ASTHelpers.findSuperMethods((MethodSymbol) symbol, state.getTypes());
78+
for (MethodSymbol superMethod : superMethods) {
79+
// The last method in the set will be the top-level declaration
80+
symbol = superMethod;
81+
}
82+
}
6783
AnnotationMirror annotation = findAnnotatedApi(symbol);
6884
if (annotation == null) {
6985
return NO_MATCH;

src/main/java/io/grpc/annotations/checkers/InternalChecker.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public final class InternalChecker extends AnnotationChecker {
3838

3939
public InternalChecker() {
4040
super("io.grpc.Internal");
41+
checkTopOfMethodHierarchy = true;
4142
}
4243

4344
@Override

0 commit comments

Comments
 (0)