-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
After release! (before the 35th May presentation)
- Loading branch information
1 parent
81a9175
commit 355391c
Showing
3 changed files
with
113 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,6 @@ public void matcher() { | |
try { | ||
anyNumberOf(statement(0)); | ||
} finally { | ||
|
||
} | ||
/** end */ | ||
}); | ||
|
66 changes: 66 additions & 0 deletions
66
...intellij-spartanizer/src/test/il/org/spartan/Leonidas/plugin/tippers/PluginTest35May.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package il.org.spartan.Leonidas.plugin.tippers; | ||
|
||
import static spartanizer.SpartanizerUtils.eval; | ||
|
||
/** | ||
* @author Michal Cohen | ||
* @since 12/01/17 | ||
*/ | ||
public class PluginTest35May { | ||
|
||
int x; | ||
|
||
public static void main(String[] args) { | ||
int x = 7; | ||
Integer z = 4; | ||
Integer y = eval(4).unless(x > 0); // replace with unless nano pattern | ||
|
||
// remove braces | ||
if (x > 3) | ||
x++; | ||
|
||
// remove braces | ||
while (!(x > 3)) | ||
x++; | ||
|
||
// remove double negation | ||
if (x > 4) | ||
System.out.print("banana"); | ||
|
||
// flip condition | ||
if (x > 2) | ||
x++; | ||
|
||
// go fluent | ||
class Bloop { | ||
private int s; | ||
|
||
Bloop setX(int ¢) { | ||
this.s = ¢; | ||
return this; | ||
} | ||
|
||
int get() { | ||
return s; | ||
} | ||
} | ||
|
||
// change to x++ | ||
x++; | ||
|
||
String s = "banana"; | ||
// flip equals | ||
"split".equals(s); | ||
} | ||
|
||
private static void foo(boolean ¢) { | ||
System.out.print(¢); | ||
} | ||
|
||
// should change parameter to cent | ||
int f(int ¢) { | ||
¢ = ¢ + 5; | ||
return ¢ + 1; | ||
} | ||
} | ||
|
47 changes: 47 additions & 0 deletions
47
...tanizer/src/test/il/org/spartan/Leonidas/plugin/tippers/spartanizer/SpartanizerUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package il.org.spartan.Leonidas.plugin.tippers.spartanizer; | ||
|
||
import java.util.List; | ||
import java.util.function.Function; | ||
|
||
public class SpartanizerUtils { | ||
|
||
public static <T> Eval<T> eval(T y) { | ||
return new Eval<T>(y); | ||
} | ||
|
||
public static <T> T last(List<T> ts) { | ||
return ts.get(ts.size() - 1); | ||
} | ||
|
||
public static <T, R> R nullConditional(T x, Function<T, R> f) { | ||
return x == null ? null : f.apply(x); | ||
} | ||
|
||
public static <T> Defaults<T> defaults(T then) { | ||
return new Defaults<T>(then); | ||
} | ||
|
||
public static class Eval<T> { | ||
T y; | ||
|
||
public Eval(T y) { | ||
this.y = y; | ||
} | ||
|
||
public T unless(boolean x) { | ||
return !x ? y : null; | ||
} | ||
} | ||
|
||
public static class Defaults<T> { | ||
T then; | ||
|
||
public Defaults(T then) { | ||
this.then = then; | ||
} | ||
|
||
public T to(T else$) { | ||
return then != null ? then : else$; | ||
} | ||
} | ||
} |