From 892b93ced0f96e498b2f068150ab08dc59d055af Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Tue, 12 Mar 2024 09:12:48 +0000 Subject: [PATCH] refactor: Add missing `@Override` to overriding and implementing methods Use this link to re-run the recipe: https://app.moderne.io/recipes/org.openrewrite.staticanalysis.MissingOverrideAnnotation?organizationId=T3BlblJld3JpdGU%3D Co-authored-by: Moderne --- .../java/org/openrewrite/kotlin/KotlinParser.java | 2 ++ .../java/org/openrewrite/kotlin/KotlinTemplate.java | 4 ++++ src/main/java/org/openrewrite/kotlin/tree/K.java | 13 +++++++++++++ 3 files changed, 19 insertions(+) diff --git a/src/main/java/org/openrewrite/kotlin/KotlinParser.java b/src/main/java/org/openrewrite/kotlin/KotlinParser.java index 0bae3fb4..5fc30952 100644 --- a/src/main/java/org/openrewrite/kotlin/KotlinParser.java +++ b/src/main/java/org/openrewrite/kotlin/KotlinParser.java @@ -329,6 +329,7 @@ private Collection resolvedClasspath() { return classpath; } + @Override public KotlinParser build() { return new KotlinParser(resolvedClasspath(), styles, logCompilationWarningsAndErrors, typeCache, moduleName, languageLevel, isKotlinScript); } @@ -338,6 +339,7 @@ public String getDslName() { return "kotlin"; } + @Override public KotlinParser.Builder clone() { KotlinParser.Builder clone = (KotlinParser.Builder) super.clone(); clone.typeCache = this.typeCache.clone(); diff --git a/src/main/java/org/openrewrite/kotlin/KotlinTemplate.java b/src/main/java/org/openrewrite/kotlin/KotlinTemplate.java index 6972cc96..372aba59 100644 --- a/src/main/java/org/openrewrite/kotlin/KotlinTemplate.java +++ b/src/main/java/org/openrewrite/kotlin/KotlinTemplate.java @@ -82,6 +82,7 @@ public static class Builder extends JavaTemplate.Builder { this.code = code; } + @Override public Builder imports(String... fullyQualifiedTypeNames) { for (String typeName : fullyQualifiedTypeNames) { validateImport(typeName); @@ -105,16 +106,19 @@ Builder parser(KotlinParser.Builder parser) { return this; } + @Override public Builder doAfterVariableSubstitution(Consumer afterVariableSubstitution) { this.onAfterVariableSubstitution = afterVariableSubstitution; return this; } + @Override public Builder doBeforeParseTemplate(Consumer beforeParseTemplate) { this.onBeforeParseTemplate = beforeParseTemplate; return this; } + @Override public KotlinTemplate build() { return new KotlinTemplate(false, parser, code, imports, onAfterVariableSubstitution, onBeforeParseTemplate); diff --git a/src/main/java/org/openrewrite/kotlin/tree/K.java b/src/main/java/org/openrewrite/kotlin/tree/K.java index 494b4dc2..d09c004b 100644 --- a/src/main/java/org/openrewrite/kotlin/tree/K.java +++ b/src/main/java/org/openrewrite/kotlin/tree/K.java @@ -70,8 +70,10 @@ default

J acceptKotlin(KotlinVisitor

v, P p) { return v.defaultValue(this, p); } + @Override Space getPrefix(); + @Override default List getComments() { return getPrefix().getComments(); } @@ -191,20 +193,24 @@ public SourceFile withCharset(Charset charset) { JRightPadded packageDeclaration; @Nullable + @Override public Package getPackageDeclaration() { return packageDeclaration == null ? null : packageDeclaration.getElement(); } + @Override public K.CompilationUnit withPackageDeclaration(Package packageDeclaration) { return getPadding().withPackageDeclaration(JRightPadded.withElement(this.packageDeclaration, packageDeclaration)); } List> imports; + @Override public List getImports() { return JRightPadded.getElements(imports); } + @Override public K.CompilationUnit withImports(List imports) { return getPadding().withImports(JRightPadded.withElements(this.imports, imports)); } @@ -223,6 +229,7 @@ public K.CompilationUnit withStatements(List statements) { @Getter Space eof; + @Override @Transient public List getClasses() { return statements.stream() @@ -242,6 +249,7 @@ public K.CompilationUnit withClasses(List classes) { return getPadding().withClasses(JRightPadded.withElements(this.getPadding().getClasses(), classes)); } + @Override public

J acceptKotlin(KotlinVisitor

v, P p) { return v.visitCompilationUnit(this, p); } @@ -251,6 +259,7 @@ public

TreeVisitor> printer(Cursor cursor) { return new KotlinPrinter<>(); } + @Override @Transient public TypesInUse getTypesInUse() { TypesInUse cache; @@ -267,6 +276,7 @@ public TypesInUse getTypesInUse() { return cache; } + @Override public Padding getPadding() { Padding p; if (this.padding == null) { @@ -1104,6 +1114,7 @@ final class FunctionType implements K, TypeTree, Expression { @With Space prefix; + @Override public Space getPrefix() { //noinspection ConstantConditions return prefix == null ? returnType.getElement().getPrefix() : prefix; @@ -1112,6 +1123,7 @@ public Space getPrefix() { @With Markers markers; + @Override public Markers getMarkers() { // For backwards compatibility with older LST before there was a prefix field //noinspection ConstantConditions @@ -1168,6 +1180,7 @@ public FunctionType withParameters(List parameters) { return returnType != null && returnType.getElement() != null ? returnType.getElement().getType() : null; } + @Override public T withType(@Nullable JavaType type) { TypeTree newType = returnType.getElement().withType(type); //noinspection unchecked