Git Product home page Git Product logo

nb-additional-hints's People

Contributors

markiewb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

nb-additional-hints's Issues

Convert from/to ternary

FIXED

<!description="Convert to ternary">
    if ($cond$){
            $var = $a;
        }else{
            $var = $b;
        }
=>     

$var = ($cond$)?$a:$b;
;;

        if ($cond$){
            return $a;
        }else{
            return $b;
        }

return ($cond$)?$a:$b;


 <!description="Convert ternary to if/else">
return ($cond$)?$a:$b;
=>      if ($cond$){
            return $a;
        }else{
            return $b;
        }
;;

<!description="Convert ternary to if/else">
$var = ($cond$)?$a:$b;
=>      if ($cond$){
            $var = $a;
        }else{
            $var = $b;
        }
;;


Some more "invert ternary if/else" patterns

        @TriggerPattern(value = "($var1 != $c) ? $a : $b"),
        @TriggerPattern(value = "($var2 == $c) ? $a : $b"),
        @TriggerPattern(value = "($varc) ? $a : $b"),
        @TriggerPattern(value = "(!$varc) ? $a : $b"),

Hints for "Convert to assertTrue/assertFalse"

<!description="Convert to assertTrue/assertFalse">
org.junit.Assert.assertEquals(true, $any)
=> org.junit.Assert.assertTrue($any)
;;
org.junit.Assert.assertEquals($msg, true, $any)
=> org.junit.Assert.assertTrue($msg, $any)
;;
org.junit.Assert.assertEquals(false, $any)
=> org.junit.Assert.assertFalse($any)
;;
org.junit.Assert.assertEquals($msg, false, $any)
=> org.junit.Assert.assertFalse($msg, $any)
;;

Invert ternary if/else

See https://netbeans.org/bugzilla/show_bug.cgi?id=240079

(a != null) ? a.toString() : ""  
->
(a == null) ? "" : a.toString()

More pattern

        @TriggerPattern(value = "($var1 != null) ? $a : $b"),
        @TriggerPattern(value = "($var2 == null) ? $a : $b"),
        @TriggerPattern(value = "($var3 > $c) ? $a : $b"),
        @TriggerPattern(value = "($var4 < $c) ? $a : $b"),
        @TriggerPattern(value = "($var5 >= $c) ? $a : $b"),
        @TriggerPattern(value = "($var6 <= $c) ? $a : $b"),

Unnecessary semicolon

A hint "Unnecessary semicolon" should appear for this statement:

System.out.println("hello world");;

When the user presses Enter, the semicolon should be removed.

Literals with quoted Strings create uncompileable code

int a = 5;
String string = "foo";
double d = .5d;

String out = a + " is an integer and \"" + string + "\" is a string and " + d + " is an double";

Now, when you use “Replace ‘+’ with ‘String.format()’” the result is this:

String out = String.format("%s is an integer and " % s);

Join literal hint removes \\

                            String word_orig = "abc"+"bin\\sh.exe";

                            String word_actu = "abcbinsh.exe";
                            String word_expe = "abcbin\\sh.exe";

False positive of "Dead instanceof" hint

ACTUAL:

java.util.Set a = null; if (a instanceof java.util.HashSet) {} // ERROR
java.util.Set e = null; if (e instanceof java.util.ArrayList) {} //ERROR

EXPECTED:

java.util.Set a = null; if (a instanceof java.util.HashSet) {} // *NO* ERROR
java.util.Set e = null; if (e instanceof java.util.ArrayList) {} //ERROR

Replace + with... doesn't always appear

In this code:

String variable = name + " (" + position.getX() + ", " + position.getY() + ')';
return "Found " + variable + " entries";

Pressing Alt+Enter on the second line works, I see the three replacement options. Pressing it on the first line does nothing (brings up NB's standard actions).

When I replace the char literals with string literals, it works! I make it a StringBuilder and then I can then replace the literals with chars again because there is an overloaded method StringBuilder.append(char c)

Literals with quoted Strings won't be copied properly to clipboard

"package test;\n"
                        + "public class Test {\n"
                        + "    public static void main(String[] args) {\n"
                        + "        String a=\"foo|bar\";\n"
                        + "    }\n"
                        + "}\n"

will be copied to clipboard as

package test;
public class Test {
    public static void main(String[] args) {
        String a=\"foo|bar\";
    }
}

Replace with String.format doesn't support ternary operator

        logger.debug("ABC " + foo != null ? "notnull "+ foo : "null");

ACTUAL:

        logger.debug(String.format("ABC %s", foo) != null ? "notnull "+ foo : "null");

EXPECTED

        logger.debug(String.format("ABC %s", foo != null ? "notnull "+ foo : "null"));

False positive on dead instanceof hint

I am getting a false positive on the dead instanceof hint for the following code:

    for (final Object t : timerService.getTimers())
    {
        // If the timers aren't Timers, skip
        if (!(t instanceof Timer))
        {
            continue;
        }
        final Timer candidate = (Timer)t;

(Here timerService is a javax.ejb.TimerService and Timer is javax.ejb.Timer.)

Hint for converting to StringUtils.isBlank()/StringUtils.isNotBlank()/StringUtils.isEmpty() - Commons Lang

<!description="Convert to StringUtils.isBlank()">
$v == null || $v.trim().length() == 0
=> org.apache.commons.lang.StringUtils.isBlank($v)
;;
$v == null || $v.trim().isEmpty()
=> org.apache.commons.lang.StringUtils.isBlank($v)
;;
$v != null && $v.trim().length() == 0
=> org.apache.commons.lang.StringUtils.isBlank($v)
;;
$v != null && $v.trim().isEmpty()
=> org.apache.commons.lang.StringUtils.isBlank($v)
;;

<!description="Convert to StringUtils.isNotBlank()">
$v != null && $v.trim().length() > 0
=> org.apache.commons.lang.StringUtils.isNotBlank($v)
;;
$v != null && !$v.trim().isEmpty()
=> org.apache.commons.lang.StringUtils.isNotBlank($v)
;;

<!description="Convert to StringUtils.isEmpty()">
$v == null || $v.length() == 0
=> org.apache.commons.lang.StringUtils.isEmpty($v)
;;
$v == null || $v.isEmpty()
=> org.apache.commons.lang.StringUtils.isEmpty($v)
;;
$v != null && $v.isEmpty()
=> org.apache.commons.lang.StringUtils.isEmpty($v)
;;
$v != null && $v.length() == 0
=> org.apache.commons.lang.StringUtils.isEmpty($v)
;;

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.