An IntelliJ IDEA plugin adding a variety of useful intentions
for Java editing.
Boolean manipulations:
- Convert 'and' to 'or': foo && bar && baz -> !(!foo || !bar || !baz)
- Convert 'or' to 'and': foo || bar || baz -> !(!foo && !bar && !baz)
- Flip 'and' : foo && bar -> bar && foo
- Flip 'or: foo || bar -> bar || foo
(To use: click anywhere on the expression, and trigger the intention)
Equality manipulations:
- Flip 'equals' or 'equalsIgnoreCase': foo.equals(bar) -> bar.equals(foo)
- Convert 'equals' to '==': foo.equals(bar) -> foo == bar
- Convert '==' to 'equals': foo == bar -> foo.equals(bar)
- Convert '==' to saf'equals': foo
= bar -> foo= null?bar==null:foo.equals(bar)
- Convert '!=' to '! equals': foo != bar -> !foo.equals(bar)
(To use: Click anywhere in the expression, and trigger the intention)
Comparison manipulations:
- Invert Comparison: foo < bar -> !(foo >= bar)
- Flip Comparison: foo < bar -> bar > foo
(To use: Click anywhere in the expression, and trigger the intention)
Integer manipulation:
- Convert integer literal to decimal: 0x12 -> 18
- Convert integer literal to octal: 18 -> 022
- Convert integer literal to hexidecimal: 022 -> 0x12
(To use: click on an integer or long literal, and trigger the intention)
JUnit manipulation:
- Convert 'assertTrue' with equality comparisons to 'assertEquals':assertEquals("hey!", bar, foo) <-> assertTrue("hey!", bar.equals(foo));
- Convert 'assertEquals' to 'assertTrue':assertEquals("hey!", true, foo) <-> assertTrue("hey!", foo);
- Convert 'assertEquals' to 'assertFalse': assertEquals("hey!", false, foo) <-> assertFalse("hey!", foo);
- Convert 'assertEquals' to 'assertNull': assertEquals("hey!", null, foo) <-> assertNull("hey!", foo);
- Convert 'assertTrue' to 'assertFalse': assertTrue("hey!", foo) <-> assertFalse("hey!", !foo);
(To use: click anywhere on the expression, and trigger the intention)
Multiply to Shift optimizations:
- Convert multiply to right-shift: foo * 8 <-> foo << 3
- Convert multiply-assign to right-shift: foo *= 8 <-> foo <<= 3
- Convert divide to left-shift: foo / 8 <-> foo >> 3
- Convert divide-assign to left-shift: foo /= 8 <-> foo >>= 3
(To use: click anywhere on the expression, and trigger the intention)
Control flow:
- Replace ?: return with if-else: return foo?bar:baz; -> if(foo){return bar;}else{return baz;}
- Replace ?: assignment with if-else: bar=foo?1:2; -> if(foo){ bar = 1;}else{ baz = 2;}
- Replace ?: declaration with if-else: int bar=foo?1:2; -> int bar; if(foo){ bar = 1;}else{ baz = 2;}
(To use, click on the 'return' or assignment operator, and trigger the intention.
- Replace if-else-return with ?: if(foo){return bar;}else{return baz;} -> return foo?bar:baz;
- Replace if-else-assignment with ?: if(foo){x= bar;}else{x = baz;} -> x = (foo?bar:baz);
(To use: Click anywhere on the "if", and trigger the intention)
- Flip ?: : !foo?bar:baz; -> foo?baz:bar;
(To use: Click anywhere on the expression, and trigger the intention)
- Replace switch statement with if-then-else statement
(To use: Click on the 'switch' keyword, and trigger the intention)
- Replace if-then-else statement with switch statement
(To use: Click on the 'if' keyword, and trigger the intention)
Code cleanup:
- Replace simple assigment with operator assignment: a = a + 3; -> a += 3;
(To use: click anywhere in the assignment expresssion, and trigger the intention)
- Simplify trivial conditional expressions: foo?true:false ->foo foo?false:true ->!foo
(To use: click anywhere in the conditional expresssion, and trigger the intention)
- Simplify trivial if-then-else statements: if(foo){return true;}else{return false;} ->return foo;
(To use: click on the 'if', and trigger the intention)
- Remove unnecessary parentheses: if(((a)&&((b)))) -> if(a && b)
(To use: Click anywhere in the expression, and trigger the intention)
- Change fully qualified name to unqualified name: new java.util.HashMap() -> import java.util.HashMap; ... new HashMap?();
(To use: Click anywhere on the qualified name, and trigger the intention)
- Merge nested if statements: if(foo){if(bar) baz();} -> if(foo && bar){baz();}
(To use: Click on the outside 'if' keyword, and trigger the intention)
- Split else if statements: if(foo){ baz();}else if(bar()){baz2();} -> if(foo){ baz();}else {if(bar()){baz2();}
(To use: Click on the 'else' keyword, and trigger the intention)
- Detail Exceptions: if a try block has 'catchall' exception handlers, replace with more precise ones
(To use: Click on the outside 'try' keyword, and trigger the intention)
- Replace C-Style array declarations with Java-style: int foo[] -> int[] foo
(To use: Click anywhere of the declaration, and trigger the intention)
- "Replace conditional declaration with if-then-else" and "Replace fully qualified name with import" both sometimes cause the on-line syntax checker to become confused, and issue "red line" errors incorrectly. This doesn't seem to be harmful, and eventually goes away, but any insights on the issue from PSI gurus would be appreciated.
- Intention Power-pack has no capacity for moving the caret, so the position after any given intention is used may be somewhat surprising.
TODO:
Intention Power-Pack wouldn't have been possible with the good work of the PsiViewer? team, AndrewArmstrong, JacquesMorel, and OleMatzura.
- Download the ipp.jar file, and place it in your IntelliJ/plugins directory.
- Restart IntelliJ
- IMPORTANT: this plugin will only work with Aurora build 944 or higher!
| Plugin Author: | DaveGriffith |
| Plugin Version: | 23 May 2003 (V1.000) |
| Change History: | |
| 23 May 2003 (V1.000): | Initial version |
| Jar Dependencies: | none |
| Plugin Home: | http://www.intellij.org/twiki/bin/view/Main/IntentionPowerPack | Feedback: | http://www.intellij.org/twiki/bin/view/Main/IntentionPowerPackDev
Related Topics: PluginDocumentation, ProjectPluginTemplate, OpenAPI, IntellijPluginDocumentation,
IntellijPluginDocumentation, PluginDeployment, IdeasForPlugins
-- DaveGriffith - 31 May 2003
|
|