Source code formatting and TestNG annnotations

It looks like our current code formatting settings will split annotations thus:

@Test(groups = { “Functional” })

reformats to

@Test(groups =

{ “Functional” })

It seems Eclipse is not smart enough to realise this is not an array declaration.

If I change this formatter preference (from ‘Next line’):

pastedImage.png

then the line is not split.

The option is saved in .settings/org.eclipse.jdt.core.prefs as

org.eclipse.jdt.core.formatter.brace_position_for_array_initializer=end_of_line

Shall we make this change to formatting?

It will affect array declarations as well as the annotations but I’m happy to have them on one line.

Mungo

The University of Dundee is a registered Scottish Charity, No: SC015096

···

Mungo Carstairs
Jalview Computational Scientist
The Barton Group
Division of Computational Biology
School of Life Sciences
University of Dundee, Dundee, Scotland, UK.
www.jalview.org
www.compbio.dundee.ac.uk

Hi.

It looks like our current code formatting settings will split annotations thus:

@Test(groups = { "Functional" })

reformats to

@Test(groups =

  { "Functional"})

... but they are both valid, I see.

It seems Eclipse is not smart enough to realise this is not an array declaration.

If I change this formatter preference (from 'Next line'):

then the line is not split.

The option is saved in .settings/org.eclipse.jdt.core.prefs as

org.eclipse.jdt.core.formatter.brace_position_for_array_initializer=end_of_line

Shall we make this change to formatting?

How about 'Next line on wrap' - and tick the 'keep empty array initializer' option. It's a nice compromise that fits with our current formatting style.

There's also a specific setting for annotation parameter elements which we probably ought to set.
1. Line Wrapping, select Annotations->element-value pairs
2. Set it to Wrap all elements, every element on a new line, and the indent policy to 'indent by one'.

We're going to be using annotation parameters an awful lot more with OSGi so it'd be good to finalise this now.

Jim

···

On 10/08/2015 12:46, Mungo Carstairs (Staff) wrote:

OK, I’ll commit those suggestions (against http://issues.jalview.org/browse/JAL-1551)) to develop.

I found that if the first annotation parameter is a list (in braces), then the ‘array initializer’ format takes precedence and parameters are all on one line.

Multiple annotation parameters are put on new lines correctly as long as the first one is single-valued.

mungo

Mungo Carstairs
Jalview Computational Scientist
The Barton Group
Division of Computational Biology
College of Life Sciences
University of Dundee, Dundee, Scotland, UK.
www.jalview.org
www.compbio.dundee.ac.uk

···

From: jalview-dev-bounces@jalview.org jalview-dev-bounces@jalview.org on behalf of Jim Procter foreveremain@gmail.com
Sent: 10 August 2015 13:22
To: jalview-dev@jalview.org
Subject: Re: [Jalview-dev] Source code formatting and TestNG annnotations

Hi.

On 10/08/2015 12:46, Mungo Carstairs (Staff) wrote:

It looks like our current code formatting settings will split
annotations thus:

@Test(groups = { “Functional” })

reformats to

@Test(groups =

{ “Functional”})

… but they are both valid, I see.

It seems Eclipse is not smart enough to realise this is not an array
declaration.

If I change this formatter preference (from ‘Next line’):

then the line is not split.

The option is saved in .settings/org.eclipse.jdt.core.prefs as

org.eclipse.jdt.core.formatter.brace_position_for_array_initializer=end_of_line

Shall we make this change to formatting?

How about ‘Next line on wrap’ - and tick the ‘keep empty array
initializer’ option. It’s a nice compromise that fits with our current
formatting style.

There’s also a specific setting for annotation parameter elements which
we probably ought to set.

  1. Line Wrapping, select Annotations->element-value pairs
  2. Set it to Wrap all elements, every element on a new line, and the
    indent policy to ‘indent by one’.

We’re going to be using annotation parameters an awful lot more with
OSGi so it’d be good to finalise this now.

Jim


Jalview-dev mailing list
Jalview-dev@jalview.org
http://www.compbio.dundee.ac.uk/mailman/listinfo/jalview-dev

The University of Dundee is a registered Scottish Charity, No: SC015096