Package org.openrewrite.java.style
Class ImportLayoutStyle
java.lang.Object
org.openrewrite.java.style.ImportLayoutStyle
- All Implemented Interfaces:
JavaStyle,org.openrewrite.style.Style
A Java Style to define how imports are grouped and ordered. Additionally, this style provides configuration to dictate
how wildcard folding should be applied when multiple imports are in the same package or on the same, statically-imported
type.
classCountToUseStarImport - How many imports from the same package must be present before they should be collapsed into a star import. The default is 5.
nameCountToUseStarImport - How many static imports from the same type must be present before they should be collapsed into a static star import. The default is 3.
layout - An ordered list of import groupings which define exactly how imports should be organized within a compilation unit.
packagesToFold - An ordered list of packages which are folded when 1 or more types are in use.
The import layout consist of three properties:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceA block represents a grouping of imports based on matching rules.static class -
Constructor Summary
ConstructorsConstructorDescriptionImportLayoutStyle(int classCountToUseStarImport, int nameCountToUseStarImport, List<ImportLayoutStyle.Block> layout, List<ImportLayoutStyle.Block> packagesToFold) -
Method Summary
Modifier and TypeMethodDescriptionList<JRightPadded<org.openrewrite.java.tree.J.Import>> addImport(List<JRightPadded<org.openrewrite.java.tree.J.Import>> originalImports, org.openrewrite.java.tree.J.Import toAdd, @Nullable org.openrewrite.java.tree.J.Package pkg, Collection<JavaType.FullyQualified> classpath) Adds a new import in a block that best represents the import layout style without re-ordering any of the existing imports, i.e.static ImportLayoutStyle.Builderbuilder()static booleanisPackageAlwaysFolded(List<ImportLayoutStyle.Block> packagesToFold, org.openrewrite.java.tree.J.Import checkImport) List<JRightPadded<org.openrewrite.java.tree.J.Import>> orderImports(List<JRightPadded<org.openrewrite.java.tree.J.Import>> originalImports, Collection<JavaType.FullyQualified> classpath) This method will order and group a list of imports producing a new list that conforms to the rules defined by the import layout style.toString()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.openrewrite.style.Style
applyDefaults, getJacksonPolymorphicTypeTag, merge
-
Constructor Details
-
ImportLayoutStyle
public ImportLayoutStyle(int classCountToUseStarImport, int nameCountToUseStarImport, List<ImportLayoutStyle.Block> layout, List<ImportLayoutStyle.Block> packagesToFold)
-
-
Method Details
-
addImport
public List<JRightPadded<org.openrewrite.java.tree.J.Import>> addImport(List<JRightPadded<org.openrewrite.java.tree.J.Import>> originalImports, org.openrewrite.java.tree.J.Import toAdd, @Nullable org.openrewrite.java.tree.J.Package pkg, Collection<JavaType.FullyQualified> classpath) Adds a new import in a block that best represents the import layout style without re-ordering any of the existing imports, i.e. a minimally invasive add.- Parameters:
originalImports- The import list before inserting.toAdd- The import to add.pkg- A package declaration, if one exists.- Returns:
- The import list with a new import added.
-
orderImports
public List<JRightPadded<org.openrewrite.java.tree.J.Import>> orderImports(List<JRightPadded<org.openrewrite.java.tree.J.Import>> originalImports, Collection<JavaType.FullyQualified> classpath) This method will order and group a list of imports producing a new list that conforms to the rules defined by the import layout style.- Parameters:
originalImports- A list of potentially unordered imports.- Returns:
- A list of imports that are grouped and ordered.
-
builder
-
isPackageAlwaysFolded
public static boolean isPackageAlwaysFolded(List<ImportLayoutStyle.Block> packagesToFold, org.openrewrite.java.tree.J.Import checkImport) -
toString
-