Skip to content

Commit

Permalink
Kotlin formatting auto-detection should only sample Kotlin sources
Browse files Browse the repository at this point in the history
  • Loading branch information
knutwannheden committed Oct 7, 2024
1 parent 492b49b commit 642ae3c
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions src/main/java/org/openrewrite/kotlin/style/Autodetect.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.fasterxml.jackson.annotation.JsonCreator;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Value;
import org.jspecify.annotations.Nullable;
import org.openrewrite.SourceFile;
Expand Down Expand Up @@ -69,7 +70,7 @@ public static class Detector {
private final FindTrailingCommaVisitor findTrailingComma = new FindTrailingCommaVisitor();

public void sample(SourceFile cu) {
if (cu instanceof JavaSourceFile) {
if (cu instanceof K.CompilationUnit) {
findImportLayout.visitNonNull(cu, 0);
findIndent.visitNonNull(cu, indentStatistics);
findSpaces.visitNonNull(cu, spacesStatistics);
Expand Down Expand Up @@ -174,16 +175,11 @@ private static class IndentStatistics {
private int multilineAlignedToFirstArgument = 0;
private int multilineNotAlignedToFirstArgument = 0;

@Getter
private int depth = 0;
private int continuationDepth = 1;

public int getDepth() {
return depth;
}

public int getContinuationDepth() {
return continuationDepth;
}
@Getter
private int continuationDepth = 1;

public void incrementDepth() {
depth++;
Expand Down Expand Up @@ -621,13 +617,9 @@ public ImportLayoutStyle getImportLayoutStyle() {

// Add static imports at the top if it's the standard.
boolean addNewLine = false;
addNewLine = false;

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

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

0 comments on commit 642ae3c

Please sign in to comment.