Reputation: 5352
I've imported a project from Eclipse into IntelliJ and I want to configure the code style settings. However I've encountered a problem when declaring Arrays.
The eclipse formatter formats the code as following:
@Before
public void prepareData() throws Exception //NOPMD
{
LOG.info("Preparing setup data");
new CoreBasicDataCreator().createEssentialData(null, null);
CatalogManager.getInstance().createEssentialData(Collections.EMPTY_MAP, null);
serviceLayerDataSetup.createJobPerformables();
impExSystemSetup.createAutoImpexEssentialData(new SystemSetupContext(Collections.EMPTY_MAP, Type.ESSENTIAL,
CuppyConstants.EXTENSIONNAME));
cuppySystemSetup.importBasics(new SystemSetupContext(Collections.singletonMap(CuppyConstants.PARAM_BASICS, new String[]
{ CuppyConstants.PARAM_BASICS_PLAYERS }), Type.NOTDEFINED, CuppyConstants.EXTENSIONNAME));
cuppySystemSetup.importWC2002(new SystemSetupContext(Collections.singletonMap(CuppyConstants.PARAM_WC2002, new String[]
{ CuppyConstants.PARAM_WC2002_SETUP, CuppyConstants.PARAM_WC2002_RESULTS_PRELIMINARIES,
CuppyConstants.PARAM_WC2002_RESULTS_FINALS, CuppyConstants.PARAM_WC2002_BETS_PRELIMINARIES,
CuppyConstants.PARAM_WC2002_BETS_FINALS }), Type.NOTDEFINED, CuppyConstants.EXTENSIONNAME));
LOG.info("Finished preparation of setup data");
LOG.info("Preparing session");
JaloSession.getCurrentSession().setUser(UserManager.getInstance().getUserByLogin("sternthaler"));
LOG.info("Finished preparation of session");
}
And IntelliJ reformats the code into:
@Before
public void prepareData() throws Exception //NOPMD
{
LOG.info("Preparing setup data");
new CoreBasicDataCreator().createEssentialData(null, null);
CatalogManager.getInstance().createEssentialData(Collections.EMPTY_MAP, null);
serviceLayerDataSetup.createJobPerformables();
impExSystemSetup.createAutoImpexEssentialData(new SystemSetupContext(Collections.EMPTY_MAP, Type.ESSENTIAL,
CuppyConstants.EXTENSIONNAME));
cuppySystemSetup.importBasics(new SystemSetupContext(Collections.singletonMap(CuppyConstants.PARAM_BASICS, new String[]
{ CuppyConstants.PARAM_BASICS_PLAYERS }), Type.NOTDEFINED, CuppyConstants.EXTENSIONNAME));
cuppySystemSetup.importWC2002(new SystemSetupContext(Collections.singletonMap(CuppyConstants.PARAM_WC2002, new String[]
{ CuppyConstants.PARAM_WC2002_SETUP, CuppyConstants.PARAM_WC2002_RESULTS_PRELIMINARIES,
CuppyConstants.PARAM_WC2002_RESULTS_FINALS, CuppyConstants.PARAM_WC2002_BETS_PRELIMINARIES,
CuppyConstants.PARAM_WC2002_BETS_FINALS }), Type.NOTDEFINED, CuppyConstants.EXTENSIONNAME));
LOG.info("Finished preparation of setup data");
LOG.info("Preparing session");
JaloSession.getCurrentSession().setUser(UserManager.getInstance().getUserByLogin("sternthaler"));
LOG.info("Finished preparation of session");
}
If you are an IntelliJ user you can play with this code samples inside of their code style editor. Hope anyone of you guys can figure this out: )
Upvotes: 0
Views: 2873
Reputation: 32016
If I am understanding you correctly, You want this:
cuppySystemSetup.importBasics(new SystemSetupContext(Collections.singletonMap(CuppyConstants.PARAM_BASICS, new String[]
{CuppyConstants.PARAM_BASICS_PLAYERS}), Type.NOTDEFINED, CuppyConstants.EXTENSIONNAME));
to format like this
cuppySystemSetup.importBasics(new SystemSetupContext(Collections.singletonMap(CuppyConstants.PARAM_BASICS, new String[]
{CuppyConstants.PARAM_BASICS_PLAYERS}), Type.NOTDEFINED, CuppyConstants.EXTENSIONNAME));
To do that, you need to set Settings > Code Style > Java > Tabs and Indents > "Continuation indent" to 0. Note however, that will make all wrapped lines flush. I'm not sure if that is what you desire. Or if you just want it for specific code. If so, can you please clarify.
Also note that in IDEA 13 (currently in beta/EAP) you can use turn off formatting for sections of code via comments. (This feature was added via IDEA-56995). The tags are configurable, and default to the values shown below
// @formatter:off
cuppySystemSetup.importBasics(new SystemSetupContext(Collections.singletonMap(CuppyConstants.PARAM_BASICS, new String[]
{CuppyConstants.PARAM_BASICS_PLAYERS}), Type.NOTDEFINED, CuppyConstants.EXTENSIONNAME));
// @formatter:on
You can easily create a surround with Live Template to add those tags to a block of code.
Upvotes: 1
Reputation: 7213
Maybe you should just use "keep when reformatting" "line breaks" in code style java.
Not really pretty, but it is sometimes the only way to deal with bad legacy code (with spaces and all...).
In your example, you can extract the declarations of arrays (and other variables) from your method calls, that way maybe you'll get the same result as Eclipse. Also, IMHO it could make your code easier to read as actually it is difficult to figure out quickly what this code is doing.
Upvotes: 0
Reputation: 4987
You could use this plugin in Idea: Eclipse Code Formatter
Just search and install it in Preferences -> Plugins -> Browse Repositories(button)
Upvotes: 1