Main icon indicating copy to clipboard operation
Main copied to clipboard

Examples for live testing

Open michalcohen opened this issue 8 years ago • 4 comments

Here are some example you can paste to your IDE in order to see each tip in action:

import java.util.ArrayList;
import java.util.List;

public class x {


    //change param to cent
    public int x(int z) {
        return x(5);
    }

    public static void main(String[] args) {
        int x = 0;

        //change to x++
        x += 1;

        String str = "hello";
        //change to "hello".equals(str)
        str.equals("hello");

        //remove braces
        while(x<4){
            x++;
        }

        //remove braces
        if(true){
            x++;
        }

        //change to if(!(x==4)) x++;
        if(x == 4)
            ;
        else
            x++;


        //remove double not
        if (!(!(x>4)))
            ;

        //unless nano
        Integer t = x>6 ? null : x;
        //nullconditional nano
        String str2 = str == null ? null : str.toLowerCase();
        //defaulsto nano
        str2 = str != null ? str : "HELLO";
        List<Integer> l = new ArrayList<>();
        //lisplastelement nano
        l.get(l.size()-1);



        //fulentsetter. first click - first setter. second click - second setter.
        class B{
            private int x;
            private double y;

            B(){

            }

            double getY(){
                return y;
            }

            void setX(int ¢){
                this.x = ¢;
            }

            void setY(double ¢){
                this.y = ¢;
            }

        }
    }
}

michalcohen avatar Jun 01 '17 13:06 michalcohen

I'm working on a file to include all tippers available. When all tippers are done for next week, I will publish it here

amirsagiv83 avatar Jun 01 '17 13:06 amirsagiv83

Here is the updated file you should check the plugin with. I'll link it from the issue #1435

import java.util.ArrayList;
import java.util.List;

public class X {


    //change param to cent
    public int x(int z) {
        return x(5);
    }

    public static void main(String[] args) {
        int x = 0;

        //change to x++
        x += 1;

        String str = "hello";
        //change to "hello".equals(str)
        str.equals("hello");

        //remove braces
        while(x<4){
            x++;
        }

        //remove braces
        if(true){
            x++;
        }

        //change to if(!(x==4)) x++;
        if(x == 4)
            ;
        else
            x++;


        //remove double not
        if (!(!(x>4)))
            ;

        //unless nano
        Integer t = x>6 ? null : x;
        //nullconditional nano
        String str2 = str == null ? null : str.toLowerCase();
        //defaulsto nano
        str2 = str != null ? str : "HELLO";
        List<Integer> l = new ArrayList<>();
        //lisplastelement nano
        l.get(l.size()-1);

      // remove redundant try-finally clause
       try {
             t = 44;
      } finally {
        }

        //fulentsetter. first click - first setter. second click - second setter.
        class B{
            private int x;
            private double y;

            B(){

            }

            double getY(){
                return y;
            }

            void setX(int ¢){
                this.x = ¢;
            }

            void setY(double ¢){
                this.y = ¢;
            }

        }
    }
}

amirsagiv83 avatar Jun 03 '17 09:06 amirsagiv83

This is a permanent issue! please don't close it!

amirsagiv83 avatar Jun 27 '17 13:06 amirsagiv83

If it is permanent, consider either giving it better description or moving it to wiki.

OriRoth avatar Jun 27 '17 13:06 OriRoth