0

I'm working on a project that has generated code inside of normal Java files. These files look something like this:

...

public class BCHLRS_Aggregate extends BAggregate {
  /*+ ------------ BEGIN END AUTO GENERATED CODE ------------ +*/
  ...
  /*+ ------------ BEGIN BAJA AUTO GENERATED CODE ------------ +*/

  ...
}

I would like to disable all CodeStyle formatting for anything between the AUTO GENERATED CODE comments. I've tried to accomplish this by setting custom formatted regexes:

IntelliJ Settings

Formatter off: BEGIN BAJA AUTO GENERATED CODE Formatter on: END BAJA AUTO GENERATED CODE

This seems to help, but the methods inside of the comments are still being rearranged when I run Reformat Code.

Is there any way I can absolutely disable any code formatting for this generated code?

2
  • Shouldn't your "formatter off" trigger be different than your "formatter on" one? Oct 26, 2020 at 19:00
  • @RealSkeptic Sorry for the confusion. I didn't notice that the text was scrolled in the input. I've updated the question now. Oct 26, 2020 at 20:28

1 Answer 1

0

Suppose you have that order of generated code markers


public class BCHLRS_Aggregate extends BAggregate {
  ...
  /*+ ------------ BEGIN BAJA AUTO GENERATED CODE ------------ +*/

   // generated code

  /*+ ------------ BEGIN END AUTO GENERATED CODE ------------ +*/

  ...
}

Then your formatter control should look like this: enter image description here

Update

Rearange Code and Reformat Code are different Code Formatting Actions.

See: enter image description here

There are four different actions available: enter image description here

The Formatter Control dosen't prevent the Rearange Code action from sorting your methods.

In Intellij IDEA CE and Ultimate, these two actions are separate actions. When you execute the Formate Code actions, the code formatter is executed - declarations aren't rearanged.

Rearange code is only executed when you explicitly execute the Rearange Code action and that action doesn't respect the Formatter Control option.

Just downloaded Android Studio and it looks like this behaves the same way in there as well.

I don't know if this is intended or a bug.

1
  • This was a really good thought, but unfortunately, I don't think it's my problem. I didn't notice when I first posted the question that the text was scrolled inside of the inputs. I've updated my question now to better reflect the settings. Thanks for the response though! Oct 26, 2020 at 20:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.