Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7998429
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T15:12:37+00:00 2026-06-04T15:12:37+00:00

I have inherited code laden with ternary conditionals. This style is disallowed by our

  • 0

I have inherited code laden with ternary conditionals. This style is disallowed by our coding standards (which were introduced after the code has been written).

I am looking for a way to avoid rewriting all these statements manually. Is there a setting/plugin/sth. else in eclipse for this job?

Thank you.

PS. Though I am explicitly looking for a eclipse-based solution, I am not entirely averse to a nice ruby script for this 😉

EDIT : The “press Ctrl+1” approach by Joachim Sauer works for the example case, but does not not for a typical eclipse-generated hashCode

int prime = 31;         
int result = 1;
result{Ctrl+1} = prime * result + ((id == null) ? 0 : id.hashCode());

Pressing Ctrl+1 on the marked spot shows the following options only:
Rename in file, rename in workspace, Extract local, Copy to criteria Editor, Extract to local variable

If it would work universally, that would be great. Better still would be a solution that does not involve visting each occurrence.

I am using eclipse 3.7 on OpenSUSE 11, in case this is relevant.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T15:12:38+00:00Added an answer on June 4, 2026 at 3:12 pm

    Assuming this sample code:

        boolean someCondition = true;
        int a = someCondition ? 1 : 2;
    

    Place the cursor after the a and press Ctrl–1. Then select “Replace conditional with ‘if-else'”.

    That results in this code:

        int a;
        if (someCondition)
            a = 1;
        else
            a = 2;
    

    Use Refactor > Inline (Ctrl–Shift–I) as applicable to reduce unnecessary variable declarations.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Code which I have inherited keeps crashing out rather powerfully with the following error
I have inherited some code which involves a scheduled task that writes data (obtained
I have inherited some legacy code which generates a ton of inline styles. The
I have inherited a piece of code which calls NHibernateUtil.Initialize. I am relatively new
I have inherited code that looks like this: Stored Procedure UpdateSomeStuff Update Table1 Set
I have inherited a piece of code which has a series of functions like
I have inherited some legacy vb6 code. It's a tool which generates a local
I have inherited some code which uses uses the LinkedIn Company Profile API. At
I have inherited a load of VB6 code which has tons of individual OCX
I have inherited a code-base which uses a compiled logging library. I cannot update

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.