From 355391cdff1debf41c6a57d013590e874db743d6 Mon Sep 17 00:00:00 2001 From: Michal Cohen Date: Sun, 4 Jun 2017 15:46:58 +0300 Subject: [PATCH] After release! (before the 35th May presentation) --- ...iminateTryBodyEmptyNoCatchesNoFinally.java | 1 - .../plugin/tippers/PluginTest35May.java | 66 +++++++++++++++++++ .../tippers/spartanizer/SpartanizerUtils.java | 47 +++++++++++++ 3 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 il.org.spartan.intellij-spartanizer/src/test/il/org/spartan/Leonidas/plugin/tippers/PluginTest35May.java create mode 100644 il.org.spartan.intellij-spartanizer/src/test/il/org/spartan/Leonidas/plugin/tippers/spartanizer/SpartanizerUtils.java diff --git a/il.org.spartan.intellij-spartanizer/src/main/il/org/spartan/Leonidas/plugin/tippers/leonidas/EliminateTryBodyEmptyNoCatchesNoFinally.java b/il.org.spartan.intellij-spartanizer/src/main/il/org/spartan/Leonidas/plugin/tippers/leonidas/EliminateTryBodyEmptyNoCatchesNoFinally.java index 791c2fe768..b6c9626ba4 100644 --- a/il.org.spartan.intellij-spartanizer/src/main/il/org/spartan/Leonidas/plugin/tippers/leonidas/EliminateTryBodyEmptyNoCatchesNoFinally.java +++ b/il.org.spartan.intellij-spartanizer/src/main/il/org/spartan/Leonidas/plugin/tippers/leonidas/EliminateTryBodyEmptyNoCatchesNoFinally.java @@ -23,7 +23,6 @@ public void matcher() { try { anyNumberOf(statement(0)); } finally { - } /** end */ }); diff --git a/il.org.spartan.intellij-spartanizer/src/test/il/org/spartan/Leonidas/plugin/tippers/PluginTest35May.java b/il.org.spartan.intellij-spartanizer/src/test/il/org/spartan/Leonidas/plugin/tippers/PluginTest35May.java new file mode 100644 index 0000000000..6a30763638 --- /dev/null +++ b/il.org.spartan.intellij-spartanizer/src/test/il/org/spartan/Leonidas/plugin/tippers/PluginTest35May.java @@ -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; + } +} + diff --git a/il.org.spartan.intellij-spartanizer/src/test/il/org/spartan/Leonidas/plugin/tippers/spartanizer/SpartanizerUtils.java b/il.org.spartan.intellij-spartanizer/src/test/il/org/spartan/Leonidas/plugin/tippers/spartanizer/SpartanizerUtils.java new file mode 100644 index 0000000000..f821492e9e --- /dev/null +++ b/il.org.spartan.intellij-spartanizer/src/test/il/org/spartan/Leonidas/plugin/tippers/spartanizer/SpartanizerUtils.java @@ -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 Eval eval(T y) { + return new Eval(y); + } + + public static T last(List ts) { + return ts.get(ts.size() - 1); + } + + public static R nullConditional(T x, Function f) { + return x == null ? null : f.apply(x); + } + + public static Defaults defaults(T then) { + return new Defaults(then); + } + + public static class Eval { + T y; + + public Eval(T y) { + this.y = y; + } + + public T unless(boolean x) { + return !x ? y : null; + } + } + + public static class Defaults { + T then; + + public Defaults(T then) { + this.then = then; + } + + public T to(T else$) { + return then != null ? then : else$; + } + } +} \ No newline at end of file