diff --git a/java.hints/src/org/netbeans/modules/java/hints/Bundle.properties b/java.hints/src/org/netbeans/modules/java/hints/Bundle.properties --- a/java.hints/src/org/netbeans/modules/java/hints/Bundle.properties +++ b/java.hints/src/org/netbeans/modules/java/hints/Bundle.properties @@ -282,9 +282,11 @@ DN_FieldUnusedParam=Assign Unused Constructor Parameter to Field DSC_FieldUnusedParam=Assign Unused Constructor Parameter to Field -FIX_AssignToExisting=Assign to Existing Field -FIX_CreateField=Create Field -ERR_UnusedParameter=Unused Parameter +# {0} field name +FIX_AssignToExisting=Assign to Existing Field ''{0}'' +# {0} field name +FIX_CreateField=Create Field ''{0}'' +ERR_UnusedParameter=Unused Parameter ''{0}'' DN_org.netbeans.modules.java.hints.EqualsMethodHint=.equals Method not Checking Type diff --git a/java.hints/src/org/netbeans/modules/java/hints/FieldForUnusedParam.java b/java.hints/src/org/netbeans/modules/java/hints/FieldForUnusedParam.java --- a/java.hints/src/org/netbeans/modules/java/hints/FieldForUnusedParam.java +++ b/java.hints/src/org/netbeans/modules/java/hints/FieldForUnusedParam.java @@ -190,12 +190,20 @@ if (cancel.get() || found) { return null; } - - List fix = Collections.singletonList(new FixImpl(info.getJavaSource(), TreePathHandle.create(treePath, info), isFinalFields(getPreferences(null)), existing)); - String displayName = NbBundle.getMessage(FieldForUnusedParam.class, "ERR_UnusedParameter"); - ErrorDescription err = ErrorDescriptionFactory.createErrorDescription(Severity.HINT, displayName,fix, info.getFileObject(), offset, offset); - - return Collections.singletonList(err); + + if (treePath.getLeaf().getKind() == Kind.VARIABLE) { + final VariableTree vt = (VariableTree) treePath.getLeaf(); + final String name = vt.getName().toString(); + + List fix = Collections.singletonList(new FixImpl(info.getJavaSource(), TreePathHandle.create(treePath, info), isFinalFields(getPreferences(null)), existing, name)); + String displayName = NbBundle.getMessage(FieldForUnusedParam.class, "ERR_UnusedParameter", name); + ErrorDescription err = ErrorDescriptionFactory.createErrorDescription(Severity.HINT, displayName, fix, info.getFileObject(), offset, offset); + + return Collections.singletonList(err); + } + else{ + return null; + } } public String getId() { @@ -225,17 +233,19 @@ private final JavaSource js; private final TreePathHandle tph; private final boolean finalFields; + private final String fieldName; final boolean existing; - public FixImpl(JavaSource js, TreePathHandle tph, boolean finalFields, boolean existing) { + public FixImpl(JavaSource js, TreePathHandle tph, boolean finalFields, boolean existing, String fieldName) { this.js = js; this.tph = tph; this.finalFields = finalFields; this.existing = existing; + this.fieldName = fieldName; } - + public String getText() { - return existing ? NbBundle.getMessage(FieldForUnusedParam.class, "FIX_AssignToExisting") : NbBundle.getMessage(FieldForUnusedParam.class, "FIX_CreateField"); + return existing ? NbBundle.getMessage(FieldForUnusedParam.class, "FIX_AssignToExisting", fieldName) : NbBundle.getMessage(FieldForUnusedParam.class, "FIX_CreateField", fieldName); } public ChangeInfo implement() throws Exception {