Code generation: getters for Boolean and boolean

My IDEA 8.1.4 generate for both types is getters.
How I can generate "is" getter for boolean and "get" getter for Boolean ?

13 comments

So if you have a "boolean something" you want to generate both:

isSomething()

and

getSomething()

If that is the case I don't know of a way to do that. That is somewhat odd to want to do as well.

0

For boolean var1 I want to have boolean isVar1()
For Boolean var2 I want to have Boolean getVar2()

My IDEA generate isVar1() and isVar2() for both types: boolean and Boolean.

I need this because JSTL can't access Boolean varible in bean if it doesn't has "get" method.

This code is generated by IDEA:

public class Test {
    private boolean var1;
    private Boolean var2;

    public boolean isVar1() {
        return var1;
    }

    public Boolean isVar2() { // I need here public Boolean getVar2() {
        return var2;
    }
}

0

I don't have issue number.
I thought this can be setted in options.
My IDEA version is 8.1.4 build #9952.
Just check IDEA 9.0.1 build #9394 has same problem.

May be it just some option ?

0

Hello Alexander,

Dmitry was asking if you would open a You Track issue so they can make the change (i.e. feature enhancement) you are requesting. In other words, no it can not currently be done, but they will (try to) add it if  "formally" requested via their issue tracking system. You can go to http://youtrack.jetbrains.net to create a feature request for this.

Best Regards,
Mark

0

It is very difficult and not principle for me.
If far as I remember formerly my IDEA(don't remember version) generate "get" getters for both types.

0

On 3/1/2010 5:58 PM, Alexander Zinin wrote:

For boolean var1 I want to have boolean isVar1()
For Boolean var2 I want to have Boolean getVar2()

>

My IDEA generate isVar1() and isVar2() for both types: boolean and Boolean.

Are you sure about that? I've had it create getVar for Booleans.

0

Absolutely. Just now drop all settings(delete .IntelliJIdea* folder from user folder), but nothing changed.
I already told that previously(about year ago) I had "get" getters for both types. But I don't remember version of IDEA.

0

IDEA 9 generates "get" getters for Booleans.
Maybe you have third-party plugins installed?

0

No plugins except default installed. No settings imported. Clean 9.0.1 installation. OS – Windows 7 x64.

0

How do you generate the getter? I press Alt-Ins in a class, choose a Boolean
field and get a getXXX() method.

0

I do exactly the same as you.
May be it depends on JSDK version ? I have 1.6. I din't check it on 1.5.

0

It depends on type hinting. When you declare the member variable, if you are indicating that it is a boolean member, then the getter will begin with 'is' instead of 'get'. you can change boolean var2 to be something other than boolean, generate your getters, and then change it back. Here is the code template being used for PHP, which is probably similar to the one for your language:

/**
* @return ${TYPE_HINT}
*/
public ${STATIC} function ${GET_OR_IS}${NAME}()#if(${RETURN_TYPE}): ${RETURN_TYPE}#else#end
{
#if (${STATIC} == "static")
return self::$${FIELD_NAME};
#else
return $this->${FIELD_NAME};
#end
}

the ${GET_OR_IS}$ variable here is described as:

get/is prefix. Evaluates to "is" if the field has a boolean type (type hint) or to "get" string otherwise.

0

Please sign in to leave a comment.