|
|||
|
Hi,
I am using netbeans. One feature that I love is the insert code feature, for automatically making getters and setters it has saved me hours of braindead tedious work. I am looking at some code now that has gardually evolved into a mess and I think it is time to tidy it up. It does a lot of string comparisons. There are over 200 string literals in the main class! It strikes me as another braindead task that could be almost completely done by a computer. Is there a feature in netbeans (or any ide) that can extract String literals from a selection and replace them with centrally defined constants? Thanks. |
|
|
||||
|
||||
|
|
|
|||
|
In article
<21686352-958b-4b66-b24b-83901c1b569c@g26g2000yqe.googlegroups.com>, Mark Smith <marksmith5555@jungle-monkey.com> wrote: > I am using netbeans. One feature that I love is the insert code > feature, for automatically making getters and setters it has saved me > hours of braindead tedious work. I had to override hashCode() the other day, and the equals() it offered to generate was excellent. > I am looking at some code now that has gardually evolved into a mess > and I think it is time to tidy it up. It does a lot of string > comparisons. There are over 200 string literals in the main class! It > strikes me as another braindead task that could be almost completely > done by a computer. > > Is there a feature in netbeans (or any ide) that can extract String > literals from a selection and replace them with centrally defined > constants? See if "Introduce Constant" would be apropos: <http://wiki.netbeans.org/TS_60_Refactoring2#Test_suite:_Introduce_Constant> -- John B. Matthews trashgod at gmail dot com <http://sites.google.com/site/drjohnbmatthews> |
|
|||
|
On Thu, 26 Nov 2009 03:26:08 -0800 (PST), Mark Smith
<marksmith5555@jungle-monkey.com> wrote, quoted or indirectly quoted someone who said : > >Is there a feature in netbeans (or any ide) that can extract String >literals from a selection and replace them with centrally defined >constants? There is a tool to do it in IntelliJ Idea called "introduce constant". The catch is if you were to extract the literal 1, it would by default turn all the literal 1s into the same named constant. This buries a mine, that will hit you later if you change the value of the "constant". You have to keep your wits about you when you use it, and review all uses of the new named constant. see http://mindprod.com/jgloss/intellij.html -- Roedy Green Canadian Mind Products http://mindprod.com I mean the word proof not in the sense of the lawyers, who set two half proofs equal to a whole one, but in the sense of a mathematician, where half proof = 0, and it is demanded for proof that every doubt becomes impossible. ~ Carl Friedrich Gauss |
|
|||
|
Mark Smith wrote:
> I am using netbeans [sic]. One feature that I love is the insert code > feature, for automatically making getters and setters it has saved me > hours of braindead tedious work. > > I am looking at some code now that has gardually evolved into a mess > and I think it is time to tidy it up. It does a lot of string > comparisons. There are over 200 string literals in the main class! It > strikes me as another braindead task that could be almost completely > done by a computer. NetBeans and Eclipse (and its derivatives) have this feature. > Is there a feature in netbeans [sic] (or any ide [sic]) that can extract String > literals from a selection and replace them with centrally defined > constants? As John B. Matthews said of NetBeans: > See if "Introduce Constant" would be apropos: NetBeans: Menu: "Ref_a_ctor / Introduce _C_onstant" Eclipse: Menu: "Refac_t_or / Extr_a_ct Constant..." Both IDEs will refactor all instances of the same constant, but you must have a constant selected for the feature to know what to extract. Both give you the choice of access qualifier. Both preselect a suggested constant identifier that you can override. -- Lew |
|
|||
|
On Nov 26, 9:20*pm, Lew <no...@lewscanon.com> wrote:
> Mark Smith wrote: > > I am using netbeans [sic]. One feature that I love is the insert code > > feature, for automatically making getters and setters it has saved me > > hours of braindead tedious work. > > > I am looking at some code now that has gardually evolved into a mess > > and I think it is time to tidy it up. It does a lot of string > > comparisons. There are over 200 string literals in the main class! It > > strikes me as another braindead task that could be almost completely > > done by a computer. > > NetBeans and Eclipse (and its derivatives) have this feature. > > > Is there a feature in netbeans [sic] (or any ide [sic]) that can extract String > > literals from a selection and replace them with centrally defined > > constants? > > As John B. Matthews said of NetBeans: > > > See if "Introduce Constant" would be apropos: > > NetBeans: > Menu: "Ref_a_ctor / Introduce _C_onstant" > > Eclipse: > Menu: "Refac_t_or / Extr_a_ct Constant..." > > Both IDEs will refactor all instances of the same constant, but you must have > a constant selected for the feature to know what to extract. *Both giveyou > the choice of access qualifier. *Both preselect a suggested constant > identifier that you can override. > > -- > Lew Thanks all for the help. Introduce Constant feature worked great! |
|
|
![]() |
| Popular Tags in the Forum |
| automagically, constants, literals, string |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| KirbyBase : replacing string exceptions | Brendan | Newsgroup comp.lang.python | 2 | 11-23-2009 04:05 PM |
| substring assignment in fortran, C, etc. | LC's No-Spam Newsreading account | Newsgroup comp.lang.fortran | 57 | 05-25-2009 11:21 PM |
| substring assignment in fortran, C, etc. | LC's No-Spam Newsreading account | Newsgroup comp.lang.c | 42 | 05-23-2009 09:32 AM |
| String parsing question. | SpreadTooThin | Newsgroup comp.lang.java.programmer | 15 | 04-21-2009 03:30 PM |
| Regular Expressions - need a little help | Charles Patridge | Newsgroup comp.soft-sys.sas | 0 | 09-27-2006 01:24 PM |