github openrewrite/rewrite v7.15.0
7.15.0

latest releases: v8.62.4, v8.62.3, v8.62.2...
3 years ago

Grammar Islands

As we explored expanding Rewrite's language support to Typescript and Groovy, we discovered that their AST structures were almost identical to the existing Java model. Languages like Typescript and Java which have very different tooling ecosystems have a strong resemblance even down to the way type attribution is represented on their AST models. By extracting the common AST model (including type attribution) to a C-family "grammar island" we are able to leverage the same set of base recipes that operate on that common model across all of the languages in this family!

Groovy and Gradle Support

We are excited to announce that we have introduced a parser for Groovy! This allows us to also extend this parser to provide some initial support for Gradle files.

Printing

Tree now contains a print(Cursor) method. TreePrinter has been removed. This is a consequence of the extraction of grammar islands. One of the key differences between different languages in the same family is how AST elements are rendered in source code. So the same C.VariableDecls may be represented in Java as final Integer n = 42 and in Kotlin as val n: Int = 42. Printing then depends on understanding what the root of the AST is, whether it is a Java source file or a Kotlin. Further consequences of this change:

JavaSearchResult, XmlSearchResult, etc. have been removed in favor of plain RecipeSearchResult.

Other Enhancements:

  • New Recipe: RSPEC-2912 Use indexOf(String, int) 0e02079
  • New Recipe: RSPEC-1858 RemovestoString() from Strings #1016
  • New Recipe: RSPEC-1161 Add @Override to overriding and implementing methods #1017
  • New Recipe: RSPEC-2204 Atomic Boolean, Integer, and Long equality checks compare their values #1018
  • New Recipe: RSPEC-4087 Remove unnecessary AutoCloseable#close() statements in try-with-resources #1031
  • New Recipe: RSPEC-4682 Adding UnnecessaryPrimitiveAnnotations #1036
  • New Recipe: RSPEC-1317 StringBuilder and StringBuffer character constructor arg to String #1037
  • New Recipe: RSPEC-1197 No C-style array declarations #1041
  • New Recipe: RSPEC-1042 Replaces#valueOf(..) with the argument if the type is already a String. #1153
  • New Recipe: RSPEC-1319 Use Collection interfaces #1039
  • New Recipe: RSPEC-1948 Fix fields of a Serializable class #1043
  • New Recipe: RSPEC-2786 Remove static modifier from nested enum types since they are implicitly static #1044
  • New Recipe: RSPEC-1157 Adding CaseInsensitiveComparisonsDoNotChangeCase #1046
  • New Recipe: RSPEC-1604 Simplify lambda blocks to expressions #1054
  • New Recipe: RSPEC-2094 Find empty classes 220eb93
  • New Recipe: RSPEC-1171 No double brace initialization #1068
  • New Recipe: RSPEC-5445 Use Files#createTempDirectory #1075
  • New Recipe: MAVEN Change groupId and artifiactId #1074
  • New Recipe: GRADLE Find Gradle plugin 9925ea6
  • New Recipe: Delete files by source path 20bfcf3
  • New Recipe: Single line comments begin with a whitespace 9542cdb
  • New Recipe: Use postfix operators on for-loop control variables #1035
  • New Recipe: Delete properties from Properties files #1070
  • New Recipe: Simply Method Chain #1023
  • JSON/YAML: Replace XPATH matcher in favor of JsonPathMatcher #1011 #1021
  • JavaTemplate: Adding addImplements coordinate to ClassDeclarations #1043
  • JavaTemplate: Adding firstStatement coordinates to J.Block

Fixes:

  • Load runtime classpath from classloader of JavaParser instance 07fe73a
  • ExternalizableHasNoArgsConstructor recipe incorrectly adds no-args constructor #1012
  • UseDiamondOperator should remove unused import #1013
  • AddImport fails to add imports for static fields because it fails to find references to them #1030
  • ChangeFieldName should update statically imported identifier references #632
  • Fix BlankLinesVisitor equality checking for the first statement of a block #1034
  • FinalClass should not add 'final' modifier to abstract class #1061
  • Do not add a private constructor to abstract classes in HideUtilityClassConstructor #1060
  • TryWithResource having both J.Indentifier and J.VariableDeclarations resources prints an extra semicolon #1027
  • Use GeneralFormatStyle in EmptyNewlineAtEndOfFile #1045
  • Change default value for HiddenFieldStyle::setterCanReturnItsClass #1067
  • UnnecessaryThrows removes necessary Exception (fixes #1059)
  • Improvements to JavaType and flyweights fb2cccb 774edb7 4845990 fba0ca2
  • JavaDoc: Parse, format, and normalize new lines with CRLF characters. #1032
  • JavaDoc: Formatting Issue when an HTML paragraph tag is used #1026
  • JavaDoc: Preserve whitespace before HTML tags #1050
  • JavaDoc: RemoveUnusedImports removes import reference in javadoc @throws 1052
  • JavaDoc: Added preservation of space in an annotation if it precedes a comment #1051
  • JavaDoc: Added preservation of trailing commas #1053
  • JavaDoc: Preserve space before comment #1064
  • JavaDoc: Fixed parsing error while processing multiline javaDoc with CRLF. #1069
  • JavaDoc: Small change to margins in JavaDoc #1076
  • YAML: Support YAML FindKey matching on Yaml.Mapping #1057
  • YAML: Allow deleting sequence entries in YAML 389a2ce
  • YAML: Support merging YAML when Yaml.Mapping is the scope 8a2174b
  • YAML: Newlines on Yaml.Scalar literal should be part of the prefix of the next element. #1065
  • JSON/YAML: Support regex matches in JsonPath filter expressions. #1062
  • MAVEN: Add accessor for propertyOverrides in Pom #8314abd

Don't miss a new rewrite release

NewReleases is sending notifications on new releases.