Skip to content
This repository was archived by the owner on May 12, 2025. It is now read-only.

Commit 642ae3c

Browse files
committed
Kotlin formatting auto-detection should only sample Kotlin sources
1 parent 492b49b commit 642ae3c

File tree

1 file changed

+6
-14
lines changed

1 file changed

+6
-14
lines changed

src/main/java/org/openrewrite/kotlin/style/Autodetect.java

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import com.fasterxml.jackson.annotation.JsonCreator;
1919
import lombok.Data;
2020
import lombok.EqualsAndHashCode;
21+
import lombok.Getter;
2122
import lombok.Value;
2223
import org.jspecify.annotations.Nullable;
2324
import org.openrewrite.SourceFile;
@@ -69,7 +70,7 @@ public static class Detector {
6970
private final FindTrailingCommaVisitor findTrailingComma = new FindTrailingCommaVisitor();
7071

7172
public void sample(SourceFile cu) {
72-
if (cu instanceof JavaSourceFile) {
73+
if (cu instanceof K.CompilationUnit) {
7374
findImportLayout.visitNonNull(cu, 0);
7475
findIndent.visitNonNull(cu, indentStatistics);
7576
findSpaces.visitNonNull(cu, spacesStatistics);
@@ -174,16 +175,11 @@ private static class IndentStatistics {
174175
private int multilineAlignedToFirstArgument = 0;
175176
private int multilineNotAlignedToFirstArgument = 0;
176177

178+
@Getter
177179
private int depth = 0;
178-
private int continuationDepth = 1;
179-
180-
public int getDepth() {
181-
return depth;
182-
}
183180

184-
public int getContinuationDepth() {
185-
return continuationDepth;
186-
}
181+
@Getter
182+
private int continuationDepth = 1;
187183

188184
public void incrementDepth() {
189185
depth++;
@@ -621,13 +617,9 @@ public ImportLayoutStyle getImportLayoutStyle() {
621617

622618
// Add static imports at the top if it's the standard.
623619
boolean addNewLine = false;
624-
addNewLine = false;
625620

626621
// There are no non-static imports, add a block of all other import.
627622
if (!insertAllOthers) {
628-
if (addNewLine) {
629-
builder = builder.blankLine();
630-
}
631623

632624
builder = builder.importAllOthers();
633625
// Add java/javax if they're missing from the block that is being used as a template.
@@ -1145,7 +1137,7 @@ public J.If visitIf(J.If iff, SpacesStatistics stats) {
11451137
public J.Lambda visitLambda(J.Lambda lambda, SpacesStatistics stats) {
11461138
List<J> parameters = lambda.getParameters().getParameters();
11471139
if (parameters.size() > 1) {
1148-
List<JRightPadded<J>> paddedParameters = lambda.getParameters().getPadding().getParams();
1140+
List<JRightPadded<J>> paddedParameters = lambda.getParameters().getPadding().getParameters();
11491141
for (int i = 0; i < paddedParameters.size() - 1; i++) {
11501142
stats.beforeComma += hasSpace(paddedParameters.get(i).getAfter());
11511143
}

0 commit comments

Comments
 (0)