Skip to content
Merged
Show file tree
Hide file tree
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 @@ -42,17 +42,18 @@
+ "See https://github.com/immutables/immutables/issues/291.")
public final class ImmutablesStyle extends BugChecker implements BugChecker.ClassTreeMatcher {

private static final Matcher<ClassTree> INLINE_STYLE_ANNOTATION = Matchers.hasAnnotation(Value.Style.class);
private static final Matcher<ClassTree> STYLE_ANNOTATION = Matchers.hasAnnotation(Value.Style.class);

@Override
public Description matchClass(ClassTree tree, VisitorState state) {
if (!STYLE_ANNOTATION.matches(tree, state)) {
return Description.NO_MATCH;
}

switch (tree.getKind()) {
case CLASS:
case INTERFACE:
if (INLINE_STYLE_ANNOTATION.matches(tree, state)) {
return describeMatch(tree);
}
break;
return describeMatch(tree);
case ANNOTATION_TYPE:
ClassSymbol classSymbol = ASTHelpers.getSymbol(tree);
if (!ElementPredicates.hasSourceRetention(classSymbol)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
package com.palantir.baseline.errorprone;

import com.google.errorprone.CompilationTestHelper;
import org.junit.Test;
import org.junit.jupiter.api.Test;

public class ImmutablesStyleTest {

Expand Down Expand Up @@ -99,6 +99,13 @@ public void testMetaAnnotation_sourceRetention() {
.doTest();
}

@Test
public void testOtherAnnotation() {
helper().addSourceLines("MyOtherAnnotation.java", "public @interface MyOtherAnnotation {}")
.addSourceLines("Person.java", "@MyOtherAnnotation", "public interface Person {}")
.doTest();
}

private CompilationTestHelper helper() {
return CompilationTestHelper.newInstance(ImmutablesStyle.class, getClass());
}
Expand Down