Skip to content

Commit

Permalink
MissingOverrideAnnotation: Ignore Kotlin sources
Browse files Browse the repository at this point in the history
Fixes: #234
  • Loading branch information
knutwannheden committed Jan 11, 2024
1 parent 0a4e1ac commit 4de0242
Showing 1 changed file with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.openrewrite.java.service.AnnotationService;
import org.openrewrite.java.tree.J;
import org.openrewrite.java.tree.TypeUtils;
import org.openrewrite.kotlin.tree.K;

import java.time.Duration;
import java.util.Collections;
Expand Down Expand Up @@ -70,6 +71,12 @@ public TreeVisitor<?, ExecutionContext> getVisitor() {
private class MissingOverrideAnnotationVisitor extends JavaIsoVisitor<ExecutionContext> {
private final AnnotationMatcher OVERRIDE_ANNOTATION = new AnnotationMatcher("@java.lang.Override");

@Override
public boolean isAcceptable(SourceFile sourceFile, ExecutionContext ctx) {
// Kotlin has a dedicated `override` keyword which is enforced by the compiler
return super.isAcceptable(sourceFile, ctx) && !(sourceFile instanceof K.CompilationUnit);
}

private Cursor getCursorToParentScope(Cursor cursor) {
return cursor.dropParentUntil(is -> is instanceof J.NewClass || is instanceof J.ClassDeclaration);
}
Expand Down

0 comments on commit 4de0242

Please sign in to comment.