Home > Archive > Java Help > November 2007 > Highlight Constructors in Eclipse ?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Highlight Constructors in Eclipse ?
|
|
| Thomas Adrian 2007-11-24, 7:14 pm |
| Is there a way that to highlight all constructors in my sourcecode in
Eclipse, or any other indicator that can make it easy for me to see
that the methid is a constructor ?
I mean in the sourcecode, not in the outline.
Thanks
Thomas
| |
| rossum 2007-11-24, 7:14 pm |
| On Sat, 24 Nov 2007 13:43:09 -0800 (PST), Thomas Adrian
<notessidan@gmail.com> wrote:
>Is there a way that to highlight all constructors in my sourcecode in
>Eclipse, or any other indicator that can make it easy for me to see
>that the methid is a constructor ?
>
>I mean in the sourcecode, not in the outline.
>
>Thanks
>Thomas
I use:
//////////////////
// Constructors //
//////////////////
rossum
| |
|
| rossum wrote:
> On Sat, 24 Nov 2007 13:43:09 -0800 (PST), Thomas Adrian
> <notessidan@gmail.com> wrote:
>
>
> I use:
>
> //////////////////
> // Constructors //
> //////////////////
I use positional dominance.
When I lay out a class, I usually do it in the order:
class declaration
{
static compile-time constants
static variables
instance variables
static methods
constructors
instance methods
}
This is less egregious than it might look, because most classes with lots of
static methods won't have any instance methods or instance variables, and most
classes with instance variables, constructors and instance methods won't have
a lot of static methods. I avoid non-constant static members, at least not in
private, unless seriously forced to use them.
If a class is complex enough that that layout is not obvious, I use a similar
idiom to rossum's, but with fewer characters, either:
// constructors
or
/* constructors
*/
with blank lines above and below.
Also, the first word in my constructor Javadocs is always "Constructor":
/** Constructor - no-arg.
*/
In NetBeans (sorry Eclipse fans) I also set the menu entry:
Tools / Options / Fonts & Colors / Language = Java /
Options "Constructor Declaration" and "Constructor Use",
although in my case I use the same highlighting as for methods (bold, black).
I didn't find such an option in the preferences for Eclipse here.
I lay out enums quite differently. For enums, constant declarations and
bodies come first, then stuff that intuitively (to me) seems to explain what's
going on best. I haven't formalized that for myself yet, but it goes
something like this:
enum declaration
{
enum constants and their bodies
instance variables
constructor (don't know that I'd ever define more than one for an enum)
static method valueOf()
custom stuff for the enum (similar to regular classes henceforth)
}
Two things are mandatory. The layout should promote readability of the
source, and there must be complete Javadoc comments.
--
Lew
| |
| Thomas Adrian 2007-11-25, 4:40 am |
| On 25 Nov, 02:05, Lew <l...@lewscanon.com> wrote:
> rossum wrote:
>
>
>
>
>
>
> I use positional dominance.
>
> When I lay out a class, I usually do it in the order:
>
> class declaration
> {
> static compile-time constants
> static variables
> instance variables
> static methods
> constructors
> instance methods
>
> }
>
> This is less egregious than it might look, because most classes with lots of
> static methods won't have any instance methods or instance variables, and most
> classes with instance variables, constructors and instance methods won't have
> a lot of static methods. I avoid non-constant static members, at least not in
> private, unless seriously forced to use them.
>
> If a class is complex enough that that layout is not obvious, I use a similar
> idiom to rossum's, but with fewer characters, either:
>
> // constructors
>
> or
>
> /* constructors
> */
>
> with blank lines above and below.
>
> Also, the first word in my constructor Javadocs is always "Constructor":
>
> /** Constructor - no-arg.
> */
>
> In NetBeans (sorry Eclipse fans) I also set the menu entry:
>
> Tools / Options / Fonts & Colors / Language = Java /
> Options "Constructor Declaration" and "Constructor Use",
>
> although in my case I use the same highlighting as for methods (bold, black).
>
> I didn't find such an option in the preferences for Eclipse here.
>
> I lay out enums quite differently. For enums, constant declarations and
> bodies come first, then stuff that intuitively (to me) seems to explain what's
> going on best. I haven't formalized that for myself yet, but it goes
> something like this:
>
> enum declaration
> {
> enum constants and their bodies
> instance variables
> constructor (don't know that I'd ever define more than one for an enum)
> static method valueOf()
> custom stuff for the enum (similar to regular classes henceforth)
>
> }
>
> Two things are mandatory. The layout should promote readability of the
> source, and there must be complete Javadoc comments.
>
> --
> Lew
Thank you for your answer, But my question was if there is a feature
in Eclipse that will higlight the constructors for me so I easaly find
them when browsing code.
| |
| Matt Humphrey 2007-11-25, 8:17 am |
|
"Thomas Adrian" <notessidan@gmail.com> wrote in message
news:df5ab105-158b-4421-b120-07d74f38423c@i29g2000prf.googlegroups.com...
> On 25 Nov, 02:05, Lew <l...@lewscanon.com> wrote:
<snip useful advice>
>
> Thank you for your answer, But my question was if there is a feature
> in Eclipse that will higlight the constructors for me so I easaly find
> them when browsing code.
In Eclipse 3.2.1 (the version I use) you can go to menu Window/Preferences
and select node Java/Editor/Syntax coloring. There is no entry there for
constructors so there may not be a direct way to get what you want. Under
Java/Appearance/Member Sort Order, however, you can specify that your
constructors are sorted to a particular location, such as the top or
wherever you think it will be best to find them. Additionally, under
Java/Code Style/Code Templates entry Code/Constructor Body you can specify a
template that will be used with newly created definitions. Also Java/Code
Style/Formatter will let you specify many different characteristics of the
constructor during reformatting. If these don't cover what you want, I
think you're out of luck. I don't know what features Eclipse 3.3 has.
Matt Humphrey http://www.iviz.com/
| |
|
| Thomas Adrian wrote:
> Thank you for your answer, But my question was if there is a feature
> in Eclipse that will higlight the constructors for me so I easaly find
> them when browsing code.
That indeed was your question.
--
Lew
| |
| Thomas Adrian 2007-11-25, 7:18 pm |
| On 25 Nov, 14:10, "Matt Humphrey" <ma...@iviz.com> wrote:
> "Thomas Adrian" <notessi...@gmail.com> wrote in message
>
> news:df5ab105-158b-4421-b120-07d74f38423c@i29g2000prf.googlegroups.com...
>
>
> <snip useful advice>
>
>
>
>
>
>
> In Eclipse 3.2.1 (the version I use) you can go to menu Window/Preferences
> and select node Java/Editor/Syntax coloring. There is no entry there for
> constructors so there may not be a direct way to get what you want. Under
> Java/Appearance/Member Sort Order, however, you can specify that your
> constructors are sorted to a particular location, such as the top or
> wherever you think it will be best to find them. Additionally, under
> Java/Code Style/Code Templates entry Code/Constructor Body you can specify a
> template that will be used with newly created definitions. Also Java/Code
> Style/Formatter will let you specify many different characteristics of the
> constructor during reformatting. If these don't cover what you want, I
> think you're out of luck. I don't know what features Eclipse 3.3 has.
>
> Matt Humphreyhttp://www.iviz.com/
Thank you.
The "Java/Editor/Syntax coloring" is really what I was looking for but
it seem to be missing, and I also find it very strange that there is
no visible indicator for a constructor in the left margin.
It is strange that the Eclipse developer leave out both the left
margin indicator and the syntax coloring for constructors . Is there a
way to vote for or add request to eclipse ?
- Thomas
| |
| Matt Humphrey 2007-11-25, 7:18 pm |
|
"Thomas Adrian" <notessidan@gmail.com> wrote in message
news:42150c92-918f-48f1-818e-32be82de0f78@s8g2000prg.googlegroups.com...
>
> Thank you.
> The "Java/Editor/Syntax coloring" is really what I was looking for but
> it seem to be missing, and I also find it very strange that there is
> no visible indicator for a constructor in the left margin.
I'm sure there are plenty of other syntactic structures for which there are
no colorings / markers. I would guess it just wasn't high on the priority
list.
> It is strange that the Eclipse developer leave out both the left
> margin indicator and the syntax coloring for constructors . Is there a
> way to vote for or add request to eclipse ?
I have no idea--you'll have to ask about that in an Eclipse group
Matt Humphrey http://www.iviz.com/
| |
| Wojtek 2007-11-26, 7:23 pm |
| Thomas Adrian wrote :
> Is there a
> way to vote for or add request to eclipse ?
Go to the Eclipse site, choose Bugs, and make the priority an
Enhancment
--
Wojtek :-)
|
|
|
|
|