From bfa1a581c248653af2124b18b3de0699a03710dd Mon Sep 17 00:00:00 2001 From: markiewb Date: Fri, 3 Apr 2015 14:35:57 +0200 Subject: [PATCH] Convert to Optional.isEmpty() - false positive #57 - simplified fix based on comment https://netbeans.org/bugzilla/show_bug.cgi?id=251618#c4 --- .../plugins/hints/optional/AssignNullToOptional.java | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/main/java/de/markiewb/netbeans/plugins/hints/optional/AssignNullToOptional.java b/src/main/java/de/markiewb/netbeans/plugins/hints/optional/AssignNullToOptional.java index 87bffae..02653d7 100644 --- a/src/main/java/de/markiewb/netbeans/plugins/hints/optional/AssignNullToOptional.java +++ b/src/main/java/de/markiewb/netbeans/plugins/hints/optional/AssignNullToOptional.java @@ -65,7 +65,7 @@ public class AssignNullToOptional { @TriggerPatterns({ @TriggerPattern(value = "$var1 = null", constraints = @ConstraintVariableType(variable = "$var1", type = "java.util.Optional")), - @TriggerPattern(value = "$class $var2 = null", constraints = @ConstraintVariableType(variable = "$var2", type = "java.util.Optional")), + @TriggerPattern(value = "$class $var2 = null", constraints = @ConstraintVariableType(variable = "$class", type = "java.util.Optional")), }) @Hint(displayName = "#DN_AssignNull", description = "#DESC_AssignNull", category = "bugs", hintKind = Hint.Kind.INSPECTION, severity = Severity.ERROR) @NbBundle.Messages("ERR_AssignNull=Replace with Optional.empty()") @@ -74,18 +74,10 @@ public static ErrorDescription toFix(HintContext ctx) { final Trees trees = ctx.getInfo().getTrees(); if (ctx.getVariables().containsKey("$var1")) { - String type = ctx.getInfo().getTypes().erasure(trees.getTypeMirror(ctx.getVariables().get("$var1"))).toString(); - - if ("java.util.Optional".equals(type)) { result = "$var1 = Optional.empty()"; - } } if (ctx.getVariables().containsKey("$var2")) { - String type = ctx.getInfo().getTypes().erasure(trees.getTypeMirror(ctx.getVariables().get("$var2"))).toString(); - - if ("java.util.Optional".equals(type)) { result = "$class $var2 = Optional.empty()"; - } } if (result != null) { Fix fix = org.netbeans.spi.java.hints.JavaFixUtilities.rewriteFix(ctx, Bundle.ERR_AssignNull(), ctx.getPath(), result);