IntelliJ IDEA 14.1 Ships with Nextgen of Code Generation

IntelliJ IDEA already has impressive code generation capabilities: it can create getters and setters, equals(), hashCode(), toString(), and other methods, some of which are really simple to generate, and some are quite not.

That’s why the toString() method generator included the support for Velocity templates that could be modified and tailored to your needs. In IntelliJ IDEA 14.1 we’re extending this support to all other generated methods.

generate_equals_hash_code

To fully support this new feature, the Template Editor has been upgraded with complete Velocity coding assistance.

edit_code_generation_templates

Note that this particular editor improvement is only available in the Ultimate Edition, because it requires Velocity plugin, but everything else works well in Community Edition.

After the code has been generated, IntelliJ IDEA will make it clean and good-looking with automatic application of code style, Code Cleanup, and adding @Override annotations where needed.

If you’d like to give this feature a try, grab the latest IntelliJ IDEA 14.1 EAP build, and share your feedback with us on our discussion forum and in the issue tracker.

Develop with Pleasure!

This entry was posted in EAP Releases, New Features and tagged , , . Bookmark the permalink.

11 Responses to IntelliJ IDEA 14.1 Ships with Nextgen of Code Generation

  1. Korosif says:

    Can I use the new Velocity based template system with AS3/Flex in IntelliJ, or is it a Java only feature?
    By the way, it would be very useful when you talk about a feature if you can always disclose if it’s a Java only one, or if other language are concerned. I know it’s a Java centric IDE at core, but we’re quite a few that use IntelliJ for other things…
    Thanks.

  2. Dmitry Kandalov says:

    Thank you, looks good.
    What about automatically regenerating these methods if class fields change?

  3. Alexander says:

    How to open this **** dialog?

    • Anna Kozlova says:

      Templates chooser is available over the member’s chooser. If you press ellipsis button, templates configurator would be shown

  4. John says:

    Any way to change the equalsHeader.vm?
    I want to have the generator add {} after every if statement

    • Anna Kozlova says:

      John, how is your code style configured? If it requires {} for if statements then generated code would contain them. In other words, generated code is automatically reformatted, so it is not expected that you need to change library part of the generators.

      Anna

  5. Max says:

    Hi,

    Usually I use JGoodies binding and write data bean/model that extent a Model class (it has PropertyChangeSupport) and need to call following method in each setter:
    firePropertyChange( String propertyName, Object oldValue, Object newValue).

    For example, I define propertyName and coresponding field as: public static final String PROPERTY_DISPLAY_NAME = "displayName";
    private String m_DisplayName;

    I don’t know the syntax to write custom getter/setter code template. Want to ask how to make such a code template that will create the setter like following for that property:


    public void setDisplayName( final String in_NewValue ){

    final String oldValue = m_DisplayName;
    m_DisplayName = in_NewValue;
    firePropertyChange( PROPERTY_DISPLAY_NAME, oldValue, in_NewValue );

    }

    Thanks!

    • Anna Kozlova says:

      Hi, Max!

      You need to write velocity template. looks like that you can leave untouched default setter name but instead of part “$field.name = $paramName;” you need to write your code which stores old value to the temp variable:

      {code}
      final String oldValue = $field.name;
      $field.name = in_NewValue;
      firePropertyChange( PROPERTY_$StringUtil.toUpperCase($field.name), oldValue, in_NewValue );
      {code}

Leave a Reply

Your email address will not be published. Required fields are marked *