Package org.openrewrite.java.style
Class ImportLayoutStyle
- java.lang.Object
-
- org.openrewrite.java.style.ImportLayoutStyle
-
- All Implemented Interfaces:
JavaStyle,org.openrewrite.style.Style
public class ImportLayoutStyle extends java.lang.Object implements JavaStyle
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.The import layout consist of three properties:
- 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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceImportLayoutStyle.BlockA block represents a grouping of imports based on matching rules.static classImportLayoutStyle.Builder
-
Constructor Summary
Constructors Constructor Description ImportLayoutStyle(int classCountToUseStarImport, int nameCountToUseStarImport, java.util.List<ImportLayoutStyle.Block> layout, java.util.List<ImportLayoutStyle.Block> packagesToFold)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.List<JRightPadded<J.Import>>addImport(java.util.List<JRightPadded<J.Import>> originalImports, J.Import toAdd, J.Package pkg, java.util.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(java.util.List<ImportLayoutStyle.Block> packagesToFold, J.Import checkImport)java.util.List<JRightPadded<J.Import>>orderImports(java.util.List<JRightPadded<J.Import>> originalImports, java.util.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.java.lang.StringtoString()
-
-
-
Constructor Detail
-
ImportLayoutStyle
public ImportLayoutStyle(int classCountToUseStarImport, int nameCountToUseStarImport, java.util.List<ImportLayoutStyle.Block> layout, java.util.List<ImportLayoutStyle.Block> packagesToFold)
-
-
Method Detail
-
addImport
public java.util.List<JRightPadded<J.Import>> addImport(java.util.List<JRightPadded<J.Import>> originalImports, J.Import toAdd, @Nullable J.Package pkg, java.util.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 java.util.List<JRightPadded<J.Import>> orderImports(java.util.List<JRightPadded<J.Import>> originalImports, java.util.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
public static ImportLayoutStyle.Builder builder()
-
isPackageAlwaysFolded
public static boolean isPackageAlwaysFolded(java.util.List<ImportLayoutStyle.Block> packagesToFold, J.Import checkImport)
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-