That's what the "analysis scopes" are for:
/**
* Creates a new implementation for analyzing one or more issues
*
* @param detectorClass the class of the detector to find this issue
* @param scope the scope of files required to analyze this issue
* @param analysisScopes optional set of extra scopes the detector is capable of working in
*/
@SafeVarargs
public Implementation(
@NonNull Class<? extends Detector> detectorClass,
@NonNull EnumSet<Scope> scope,
@NonNull EnumSet<Scope>... analysisScopes) {
Basically, the "scope" parameter to Implementation says "ALL of the following scopes must be present in order for this detector to kick in".
However, there are cases where a detector can *still* do some useful work when looking at a subset of the files. In that case, you can pass in one more more subsets of the scope as subsequent arguments to the Implementation constructor. That means your check will also be called if any of those analysis scopes are matched -- and your detector will have to be more careful to make sure that it's doing the right thing (for example, it can look up the full scope via the driver, which it can access via the scope).
TEST_SCOPE is a bit of a "meta" scope; it overlaps others. So in 3.4 I recently made some changes such that I think you don't need to specify analysis scopes with it; if you pass in EnumSet.of(Scope.JAVA_FILE, Scope.TEST) I think it would also treat this as a single-file scope that would work in the IDE. (Let me know if that doesn't actually work.) But for 3.3 you'll still need to specify both.
-- Tor