markiewb / nb-additional-hints Goto Github PK
View Code? Open in Web Editor NEWAdditional java hints for NetBeans IDE http://plugins.netbeans.org/plugin/47589/additional-hints
Additional java hints for NetBeans IDE http://plugins.netbeans.org/plugin/47589/additional-hints
@TriggerPattern(value = "($var1 != $c) ? $a : $b"),
@TriggerPattern(value = "($var2 == $c) ? $a : $b"),
@TriggerPattern(value = "($varc) ? $a : $b"),
@TriggerPattern(value = "(!$varc) ? $a : $b"),
See https://netbeans.org/bugzilla/show_bug.cgi?id=132511
public class NewClass {
public void SomeMethod(ArrayList foo) {
if (foo instanceof Map) {
System.out.println("No compile-time error");
}
}
}
Provide a transformation of
"foo[inner]bar" // [ ] shows the selection
to
"foo"+"inner"+"bar"
... so that they can be partially disabled
... or provide other options to disable them
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
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);
Reported by https://netbeans.org/bugzilla/show_bug.cgi?id=184673#c5
‘public’ and/or ‘static’ on nested classes.
A hint "Unnecessary semicolon" should appear for this statement:
System.out.println("hello world");;
When the user presses Enter, the semicolon should be removed.
Taken from a request at mailing list
I want to identify and refactor fields and member functions so that they all have the optional "this." present instead of possibly absent.
new BigDecimal("0.0")
new BigDecimal("0")
new BigDecimal("0.00")
new BigDecimal(0)
new BigDecimal(0L)
new BigDecimal(0.0f)
new BigDecimal(0.0d)
BigDecimal.valueOf(0)
BigDecimal.valueOf(0L)
BigDecimal.valueOf(0.0f)
should be transformed to
BigDecimal.ZERO
Same for
BigDecimal.TEN, BigDecimal.ONE
Also filed at https://netbeans.org/bugzilla/show_bug.cgi?id=236244
ACTUAL:
throw new RuntimeException("type "+ type+" ");
will not be detected
String a = null,b = null;
//hints apply
String var1;
var1 = (suffix == null) ? suffix : suffix;
//hints do not apply
String var2 = (suffix == null) ? suffix : suffix;
String a = null,b = null;
String var1 = (a != null) ? a: b;//can be converted
String var2 = a != null ? a: b;//ternary hints do not match here
Affected hints
To if/else
Invert ternary
<!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)
;;
"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\";
}
}
'?'+variable+'?'
isn't supported by additional hints
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)
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;
}
;;
Message.format("Hello cruel {0}", 42)
//hint should be able to create
"Hello cruel " + 42
//split at "\|["
String string="\\[";
//ACTUAL "\" + "
//EXPECTED "\\"+"["
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"),
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.)
Extracted from #24
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"));
Provide a transformation of
"foo|bar"
to
"foo"+"bar"
https://netbeans.org/bugzilla/show_bug.cgi?id=225984
<!description="Flip <>">
$a < $b
=>
$b > $a
;;
$a > $b
=>
$b < $a
;;
See https://netbeans.org/bugzilla/show_bug.cgi?id=155043
$1 $2;
$2 = $3;
=>
$1 $2 = $3;
;;
Support transformations
'c' -> "c"
"c" -> 'c'
//hint applied to
"a"+3+"B";
//will result in
;
//but
String b="a"+3+"B";// works
//--> String b=MessageFormat.format("a{0}B", 3);
String foo="bar";
return foo;
->
return "bar";
String word_orig = "abc"+"bin\\sh.exe";
String word_actu = "abcbinsh.exe";
String word_expe = "abcbin\\sh.exe";
Provide a hint to add parentheses
true ? "foo" : "bar"
to
(true) ? "foo" : "bar"
and backwards
@Override
public void foo()
{
super.foo();
}
or
@Override
public int foo()
{
return super.foo();
}
or
@Override
public void foo()
{
return;
}
or
@Override
public void foo()
{
}
Support transformation
"123" -> 123
123 -> "123"
For example the"Replace with ..." pollutes the right gutter.
<!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)
;;
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.