rewrite-docs icon indicating copy to clipboard operation
rewrite-docs copied to clipboard

Improve documentation for org.openrewrite.java.style.ImportLayoutStyle.layout

Open MartinAhrer opened this issue 1 year ago • 4 comments

What problem are you trying to solve?

Implementing a style for formatting (rearranging) Java import statements

Describe the solution you'd like

Add documentation and examples showing how the layout property's list elements need to look like.

Have you considered any alternatives or workarounds?

It was only possible to figure out the format of a layout list element by reading the source code for org.openrewrite.java.style.Deserializer.

Example:

      layout:
        - 'import import java.*'
        - 'import import javax.*'
        - 'import import org.*'
        - 'import import com.*'
        - 'import all other imports'
        - 'import static all other imports'

MartinAhrer avatar Dec 20 '23 08:12 MartinAhrer

Hi @MartinAhrer , good seeing you here! Indeed seems like an area we haven't covered with our docs yet; thanks for pointing that out and providing an example. Perhaps we could work that into our page on Styles @mike-solomon ? https://github.com/openrewrite/rewrite-docs/blob/d8505db1f0cb1432e45b193c8cbffd750f083f1e/concepts-and-explanations/styles.md?plain=1#L13-L15

timtebeek avatar Dec 20 '23 09:12 timtebeek

Hey there @MartinAhrer -- I'm taking a look at this issue now, but I'm a bit confused. Hoping you might be able to help me understand the issue. Were you trying to define your style declaratively in YAML?

In taking a look at the schema, I don't see any layout defined there.

Is the issue that layout works when defining a style declaratively but the schema doesn't show it as an option and we don't document it in this table -- or is there some other issue I'm not understanding here?

Thanks for your time!

mike-solomon avatar Jan 23 '24 18:01 mike-solomon

Maybe you could even share the style yaml you arrived at, such that we can include it both in the docs and the json schema we have, if you're open to that.

timtebeek avatar Jan 23 '24 18:01 timtebeek

Yes, I was trying to do that using YML. Here is a more complete example:

name: xxx.openrewrite.ImportLayoutStyle
styleConfigs:
  - org.openrewrite.java.style.ImportLayoutStyle:
      classCountToUseStarImport: 9999
      nameCountToUseStarImport: 9999
      layout:
        - 'import java.**'
        - 'import javax.**'
        - 'import org.**'
        - 'import com.**'
        - 'import **'
        - 'static import **'

However import formatting didn't work as expected and was only correct partially. And this was the reason for requesting a more comprehensive documentation on that configuration.

MartinAhrer avatar Feb 20 '24 08:02 MartinAhrer