Ability to refactor boolean expressions

What would you think about the ability to refactor boolean expressions?

For instance:
- extract !

(value <= 1) => !(value > 1)

- inline !

!(value == null) => (value != null)

- change && to ||

(a && b) => !(!a || !b)

- change || to &&

(a || b) => !(!a && !b)

I can imagine, that the most intuitive solution would be intentions.

Tom

40 comments
Comment actions Permalink

Dmitry,
You know my position on OpenAPI (more is good! even more is better!) and this is great that you are willing to open it up even unsupported. (now you just need to open up the refactorings ;)
As we have done with PSI, the community has been very good at supporting itself after the initial learning has occured.
I like the idea of having the community creating the documentation. We could do as we go. With a little more discipline we could document on wiki the things that people are asking (we kind have started this already).
Or is it unrealistic to think that the community could result in good documentation? Open Source software has always suffer from the lact of good documentation.
Somebody could also compile the discussions from the OpenApi forums.

Jacques

0
Comment actions Permalink

Excellent! (this goes to all others who reply of course)
We will open API for intentions (on the same terms as PSI) in the build
after the one we all are waiting for :)

Cheers,
Dmitry




Timur Zambalayev wrote:

I have no doubt there will be. And that eventually there will be many
different intention-based plugins if you open the API (even as
experimental and non-officially published). I agree that it could be a
good opportunity for the additional testing of the PSI API since looks
like they should be closely related (with intentions depending on PSI and
heavily using it).


Timur

>> Hi all,
>>
>> Supposing we open an interface for intention actions
>> on the same terms as
>> PSI, will there be undertakers for such a plugin?
>> We think it is rather a good opportunity for testing
>> PSI interfaces and
>> figuring out the state of PSI w.r.t. its becoming an
>> official OpenAPI,
>>
>> Friendly,
>> Dmitry

--
Dmitry Lomov
IntelliJ Labs / JetBrains Inc.
http://www.intellij.com
"Develop with pleasure!"

0
Comment actions Permalink

Outstanding! With a bit of luck and a good tail wind, I'll whomp up those intentions I listed in short order.
Here's a few more I'm planning on getting to:

Replace multiply/divide with shift-left/shift-right.
x = y*8; -> x = y<<3;
x *=8; -> x<<=3;


Replace assignment and operation with assignment operator x = x + 3; -> x += 3;

Simplify boolean literal equality
if(x == true) -> if(x)
if(x == false) -> if(!x)
if(x != false) -> if(x)

Convert int literal to hex/octal/decimal
15 -> 0xf;
15 -> 017;
017 -> 0xf;
etc.

0
Comment actions Permalink

I've got one more:

com.company.product.Clazz clazz = ...

==>

import com.company.product.Clazz;
...
Clazz clazz = ...

Tom

0
Comment actions Permalink

FYI: There's an SCR for this:

http://www.intellij.net/tracker/idea/viewSCR?publicId=9563

But, if we can get the functionality sooner via the OpenAPI, then great! :D

0
Comment actions Permalink

Few more:
assertTrue("", exp) <=> assertEquals("", true, exp);
assertFalse("", exp) <=> assertEquals("", false, exp);

0
Comment actions Permalink

Jacques Morel wrote:

Few more:
assertTrue("", exp) <=> assertEquals("", true, exp);
assertFalse("", exp) <=> assertEquals("", false, exp);


Why bidirectional? Why not:

assertEquals("", true, exp) => assertTrue("", exp)
assertEquals("", false, exp) => assertFalse("", exp)

Ciao,
Gordon

--
Gordon Tyler (Software Developer)
Quest Software <http://java.quest.com/>
260 King Street East, Toronto, Ontario M5A 4L5, Canada
Voice: 416-643-4846 | Fax: 416-594-1919

0
Comment actions Permalink

Gordon Tyler wrote:

Jacques Morel wrote:

>> Few more:
>> assertTrue("", exp) <=> assertEquals("", true, exp);
>> assertFalse("", exp) <=> assertEquals("", false, exp);


Why bidirectional? Why not:

assertEquals("", true, exp) => assertTrue("", exp)
assertEquals("", false, exp) => assertFalse("", exp)

Ciao,
Gordon

Because sometimes it's more suitable to do it in other direction in
order to extract then common part of test in separate method and pass
expected value of comparison

Friendly.

Sergey

0
Comment actions Permalink

When you are extracting a higher level assert from a bunch of hard coded asserts (to remove duplication usually) you usually have to take into account both false and true cases.

So come to think of it we have the other 2
assertNull("somthing", o) <=> assertEquals("someting", null, o);
assertNotNull("somthing", o) <=> assertFalse("someting", null != o);

Jacques

0
Comment actions Permalink


This functionality is now available in the Intention Power-Pack plugin, available at http://www.intellij.org/twiki/bin/view/Main/IntentionPowerPack. Requires Aurora build 816 or greater

0

Please sign in to leave a comment.