diff --git a/src/main/java/org/openrewrite/kotlin/AddImport.java b/src/main/java/org/openrewrite/kotlin/AddImport.java index 14feeced..a5885626 100644 --- a/src/main/java/org/openrewrite/kotlin/AddImport.java +++ b/src/main/java/org/openrewrite/kotlin/AddImport.java @@ -109,8 +109,8 @@ public AddImport(@Nullable String packageName, String typeName, @Nullable String if (alias == null) { // No need to add imports if the class to import is implicitly imported, or if the classes are within the same package - if ((IMPLICITLY_IMPORTED_PACKAGES.contains(packageName) && StringUtils.isBlank(member)) - || (cu.getPackageDeclaration() != null && packageName.equals(cu.getPackageDeclaration().getExpression().printTrimmed(getCursor())))) { + if ((IMPLICITLY_IMPORTED_PACKAGES.contains(packageName) && StringUtils.isBlank(member)) || + (cu.getPackageDeclaration() != null && packageName.equals(cu.getPackageDeclaration().getExpression().printTrimmed(getCursor())))) { return cu; } } diff --git a/src/main/java/org/openrewrite/kotlin/Assertions.java b/src/main/java/org/openrewrite/kotlin/Assertions.java index 9143729d..7e10c00c 100644 --- a/src/main/java/org/openrewrite/kotlin/Assertions.java +++ b/src/main/java/org/openrewrite/kotlin/Assertions.java @@ -207,8 +207,8 @@ public static UncheckedConsumer> spaceConscious() { } private static void assertValidTypes(TypeValidation typeValidation, J sf) { - if (typeValidation.identifiers() || typeValidation.methodInvocations() || typeValidation.methodDeclarations() || typeValidation.classDeclarations() - || typeValidation.constructorInvocations()) { + if (typeValidation.identifiers() || typeValidation.methodInvocations() || typeValidation.methodDeclarations() || typeValidation.classDeclarations() || + typeValidation.constructorInvocations()) { List missingTypeResults = findMissingTypes(sf); missingTypeResults = missingTypeResults.stream() .filter(missingType -> { @@ -463,10 +463,10 @@ public J.ParameterizedType visitParameterizedType(J.ParameterizedType type, Exec } private boolean isAllowedToHaveNullType(J.Identifier ident) { - return inPackageDeclaration() || inImport() || isClassName() - || isMethodName() || isMethodInvocationName() || isFieldAccess(ident) || isBeingDeclared(ident) || isParameterizedType(ident) - || isNewClass(ident) || isTypeParameter() || isMemberReference(ident) || isCaseLabel() || isLabel() || isAnnotationField(ident) - || isInJavaDoc(ident) || isWhenLabel() || isUseSite(); + return inPackageDeclaration() || inImport() || isClassName() || + isMethodName() || isMethodInvocationName() || isFieldAccess(ident) || isBeingDeclared(ident) || isParameterizedType(ident) || + isNewClass(ident) || isTypeParameter() || isMemberReference(ident) || isCaseLabel() || isLabel() || isAnnotationField(ident) || + isInJavaDoc(ident) || isWhenLabel() || isUseSite(); } private boolean inPackageDeclaration() { @@ -494,8 +494,8 @@ private boolean isMethodInvocationName() { private boolean isFieldAccess(J.Identifier ident) { Tree value = getCursor().getParentTreeCursor().getValue(); - return value instanceof J.FieldAccess - && (ident == ((J.FieldAccess) value).getName() || + return value instanceof J.FieldAccess && + (ident == ((J.FieldAccess) value).getName() || ident == ((J.FieldAccess) value).getTarget() && !((J.FieldAccess) value).getSimpleName().equals("class")); } @@ -515,8 +515,8 @@ private boolean isNewClass(J.Identifier ident) { } private boolean isTypeParameter() { - return getCursor().getParent() != null - && getCursor().getParent().getValue() instanceof J.TypeParameter; + return getCursor().getParent() != null && + getCursor().getParent().getValue() instanceof J.TypeParameter; } private boolean isMemberReference(J.Identifier ident) { @@ -551,8 +551,8 @@ private boolean isLabel() { private boolean isAnnotationField(J.Identifier ident) { Cursor parent = getCursor().getParent(); - return parent != null && parent.getValue() instanceof J.Assignment - && (ident == ((J.Assignment) parent.getValue()).getVariable() && getCursor().firstEnclosing(J.Annotation.class) != null); + return parent != null && parent.getValue() instanceof J.Assignment && + (ident == ((J.Assignment) parent.getValue()).getVariable() && getCursor().firstEnclosing(J.Annotation.class) != null); } private boolean isValidated(J.Identifier i) { diff --git a/src/main/java/org/openrewrite/kotlin/cleanup/ReplaceCharToIntWithCode.java b/src/main/java/org/openrewrite/kotlin/cleanup/ReplaceCharToIntWithCode.java index 7e1fd2b5..33b3cf79 100644 --- a/src/main/java/org/openrewrite/kotlin/cleanup/ReplaceCharToIntWithCode.java +++ b/src/main/java/org/openrewrite/kotlin/cleanup/ReplaceCharToIntWithCode.java @@ -38,9 +38,9 @@ public String getDisplayName() { @Override public String getDescription() { - return "Replace the usage of the deprecated `Char#toInt()` with `Char#code`. " - + "Please ensure that your Kotlin version is 1.5 or later to support the `Char#code` property. " - + "Note that the current implementation does not perform a Kotlin version check."; + return "Replace the usage of the deprecated `Char#toInt()` with `Char#code`. " + + "Please ensure that your Kotlin version is 1.5 or later to support the `Char#code` property. " + + "Note that the current implementation does not perform a Kotlin version check."; } @Override diff --git a/src/main/java/org/openrewrite/kotlin/format/MinimumViableSpacingVisitor.java b/src/main/java/org/openrewrite/kotlin/format/MinimumViableSpacingVisitor.java index 12cc5b7b..139346aa 100644 --- a/src/main/java/org/openrewrite/kotlin/format/MinimumViableSpacingVisitor.java +++ b/src/main/java/org/openrewrite/kotlin/format/MinimumViableSpacingVisitor.java @@ -240,10 +240,10 @@ private List> visitStatementList(List { Statement element = st.getElement(); - if (i == 0 - || element.getPrefix().getWhitespace().contains("\n") - || element.getPrefix().getLastWhitespace().contains("\n") - || statements.get(i - 1).getMarkers().findFirst(Semicolon.class).isPresent()) { + if (i == 0 || + element.getPrefix().getWhitespace().contains("\n") || + element.getPrefix().getLastWhitespace().contains("\n") || + statements.get(i - 1).getMarkers().findFirst(Semicolon.class).isPresent()) { return st; } return st.withElement(element.withPrefix(addNewline(element.getPrefix()))); diff --git a/src/main/java/org/openrewrite/kotlin/format/SpacesVisitor.java b/src/main/java/org/openrewrite/kotlin/format/SpacesVisitor.java index 46ea4d72..b4398d98 100644 --- a/src/main/java/org/openrewrite/kotlin/format/SpacesVisitor.java +++ b/src/main/java/org/openrewrite/kotlin/format/SpacesVisitor.java @@ -964,8 +964,8 @@ public J.Lambda visitLambda(J.Lambda lambda, P p) { JRightPadded lastParam = parameters.get(parameters.size() - 1); Space after = lastParam.getAfter(); trailingComma = lastParam.getMarkers().findFirst(TrailingComma.class).isPresent(); - lastParamHasSpace = after.getComments().isEmpty() && onlySpacesAndNotEmpty(after.getWhitespace()) - || lastParam.getMarkers().findFirst(TrailingComma.class).map(t -> onlySpacesAndNotEmpty(t.getSuffix().getWhitespace())).orElse(false); + lastParamHasSpace = after.getComments().isEmpty() && onlySpacesAndNotEmpty(after.getWhitespace()) || + lastParam.getMarkers().findFirst(TrailingComma.class).map(t -> onlySpacesAndNotEmpty(t.getSuffix().getWhitespace())).orElse(false); useSpaceBeforeLambdaArrow &= !trailingComma; } else { l = l.withArrow(Space.EMPTY); diff --git a/src/main/java/org/openrewrite/kotlin/format/TabsAndIndentsVisitor.java b/src/main/java/org/openrewrite/kotlin/format/TabsAndIndentsVisitor.java index 83714839..d0542b3d 100644 --- a/src/main/java/org/openrewrite/kotlin/format/TabsAndIndentsVisitor.java +++ b/src/main/java/org/openrewrite/kotlin/format/TabsAndIndentsVisitor.java @@ -109,8 +109,8 @@ public TabsAndIndentsVisitor(TabsAndIndentsStyle style, WrappingAndBracesStyle w tree instanceof J.Case || tree instanceof J.EnumValueSet || (tree instanceof J.Ternary && !wrappingStyle.getElvisExpressions().getUseContinuationIndent()) || - (tree instanceof J.FieldAccess || tree instanceof J.MethodInvocation) - && !wrappingStyle.getChainedFunctionCalls().getUseContinuationIndent() || + (tree instanceof J.FieldAccess || tree instanceof J.MethodInvocation) && + !wrappingStyle.getChainedFunctionCalls().getUseContinuationIndent() || tree instanceof J.Annotation ) { getCursor().putMessage("indentType", IndentType.INDENT); @@ -163,8 +163,8 @@ public Space visitSpace(Space space, Space.Location loc, P p) { !(getCursor().getParentOrThrow().getValue() instanceof J.Annotation); if ((loc == Space.Location.CLASS_KIND || - loc == Space.Location.METHOD_DECLARATION_PREFIX) - && value instanceof J.ClassDeclaration) { + loc == Space.Location.METHOD_DECLARATION_PREFIX) && + value instanceof J.ClassDeclaration) { J.ClassDeclaration c = (J.ClassDeclaration) value; if (!c.getLeadingAnnotations().isEmpty()) { alignToAnnotation = true; diff --git a/src/main/java/org/openrewrite/kotlin/internal/PsiTreePrinter.java b/src/main/java/org/openrewrite/kotlin/internal/PsiTreePrinter.java index 49846088..51c3df0d 100644 --- a/src/main/java/org/openrewrite/kotlin/internal/PsiTreePrinter.java +++ b/src/main/java/org/openrewrite/kotlin/internal/PsiTreePrinter.java @@ -296,9 +296,9 @@ public String print() { } // print current visiting element - String typeName = tree instanceof J - ? tree.getClass().getCanonicalName().substring(tree.getClass().getPackage().getName().length() + 1) - : tree.getClass().getCanonicalName(); + String typeName = tree instanceof J ? + tree.getClass().getCanonicalName().substring(tree.getClass().getPackage().getName().length() + 1) : + tree.getClass().getCanonicalName(); if (skipUnvisitedElement) { boolean leftPadded = diffPos >= 0; diff --git a/src/main/java/org/openrewrite/kotlin/style/Autodetect.java b/src/main/java/org/openrewrite/kotlin/style/Autodetect.java index 54d3b974..d9b48243 100644 --- a/src/main/java/org/openrewrite/kotlin/style/Autodetect.java +++ b/src/main/java/org/openrewrite/kotlin/style/Autodetect.java @@ -439,8 +439,8 @@ public Expression visitExpression(Expression expression, IndentStatistics stats) // (newline-separated) annotations on some common target are not continuations boolean isContinuation = !(expression instanceof J.Annotation && !( // ...but annotations which are *arguments* to other annotations can be continuations - getCursor().getParentTreeCursor().getValue() instanceof J.Annotation - || getCursor().getParentTreeCursor().getValue() instanceof J.NewArray + getCursor().getParentTreeCursor().getValue() instanceof J.Annotation || + getCursor().getParentTreeCursor().getValue() instanceof J.NewArray )); countIndents(expression.getPrefix().getWhitespace(), isContinuation, stats); diff --git a/src/main/java/org/openrewrite/kotlin/tree/K.java b/src/main/java/org/openrewrite/kotlin/tree/K.java index 096cd88d..167af696 100644 --- a/src/main/java/org/openrewrite/kotlin/tree/K.java +++ b/src/main/java/org/openrewrite/kotlin/tree/K.java @@ -397,8 +397,8 @@ public Space getPrefix() { @Override public J2 withPrefix(Space space) { - return (J2) (annotations.isEmpty() ? withExpression(expression.withPrefix(space)) - : withAnnotations(ListUtils.mapFirst(annotations, a -> a.withPrefix(space)))); + return (J2) (annotations.isEmpty() ? withExpression(expression.withPrefix(space)) : + withAnnotations(ListUtils.mapFirst(annotations, a -> a.withPrefix(space)))); } @Override @@ -1262,8 +1262,8 @@ public static class Padding { } public FunctionType withParameters(@Nullable JContainer parameters) { - return t.parameters == parameters ? t - : new FunctionType(t.id, t.prefix, t.markers, t.leadingAnnotations, t.modifiers, t.receiver, parameters, t.arrow, t.returnType); + return t.parameters == parameters ? t : + new FunctionType(t.id, t.prefix, t.markers, t.leadingAnnotations, t.modifiers, t.receiver, parameters, t.arrow, t.returnType); } } } diff --git a/src/test/java/org/openrewrite/kotlin/tree/WhenTest.java b/src/test/java/org/openrewrite/kotlin/tree/WhenTest.java index 07bffcc8..eeaa9bc7 100644 --- a/src/test/java/org/openrewrite/kotlin/tree/WhenTest.java +++ b/src/test/java/org/openrewrite/kotlin/tree/WhenTest.java @@ -269,8 +269,8 @@ fun method() { spec -> spec.afterRecipe(cu -> { K.When when = (K.When)((J.MethodDeclaration)(cu.getStatements().get(0))).getBody().getStatements().get(1); boolean allBranchesHasLiteralBody = when.getBranches().getStatements().stream().map(K.WhenBranch.class::cast).allMatch( - branch -> branch.getBody() instanceof J.Literal - || branch.getBody() instanceof J.Parentheses && ((J.Parentheses) branch.getBody()).getTree() instanceof J.Literal + branch -> branch.getBody() instanceof J.Literal || + branch.getBody() instanceof J.Parentheses && ((J.Parentheses) branch.getBody()).getTree() instanceof J.Literal ); assertThat(allBranchesHasLiteralBody).isTrue(); })