Lines 55-66
Link Here
|
55 |
import java.util.List; |
55 |
import java.util.List; |
56 |
import java.util.Set; |
56 |
import java.util.Set; |
57 |
import java.util.concurrent.atomic.AtomicBoolean; |
57 |
import java.util.concurrent.atomic.AtomicBoolean; |
|
|
58 |
import java.util.prefs.Preferences; |
58 |
import javax.lang.model.element.Element; |
59 |
import javax.lang.model.element.Element; |
59 |
import javax.lang.model.element.ElementKind; |
60 |
import javax.lang.model.element.ElementKind; |
60 |
import javax.lang.model.element.Modifier; |
61 |
import javax.lang.model.element.Modifier; |
61 |
import javax.lang.model.element.Name; |
62 |
import javax.lang.model.element.Name; |
62 |
import javax.lang.model.element.VariableElement; |
63 |
import javax.lang.model.element.VariableElement; |
63 |
import javax.lang.model.util.ElementFilter; |
64 |
import javax.lang.model.util.ElementFilter; |
|
|
65 |
import javax.swing.JComponent; |
64 |
import org.netbeans.api.java.source.CompilationInfo; |
66 |
import org.netbeans.api.java.source.CompilationInfo; |
65 |
import org.netbeans.api.java.source.GeneratorUtilities; |
67 |
import org.netbeans.api.java.source.GeneratorUtilities; |
66 |
import org.netbeans.api.java.source.JavaSource; |
68 |
import org.netbeans.api.java.source.JavaSource; |
Lines 71-77
Link Here
|
71 |
import org.netbeans.api.java.source.WorkingCopy; |
73 |
import org.netbeans.api.java.source.WorkingCopy; |
72 |
import org.netbeans.api.java.source.support.CancellableTreePathScanner; |
74 |
import org.netbeans.api.java.source.support.CancellableTreePathScanner; |
73 |
import org.netbeans.api.java.source.support.CaretAwareJavaSourceTaskFactory; |
75 |
import org.netbeans.api.java.source.support.CaretAwareJavaSourceTaskFactory; |
74 |
import org.netbeans.modules.java.hints.spi.TreeRule; |
76 |
import org.netbeans.modules.java.hints.spi.AbstractHint; |
75 |
import org.netbeans.spi.editor.hints.ChangeInfo; |
77 |
import org.netbeans.spi.editor.hints.ChangeInfo; |
76 |
import org.netbeans.spi.editor.hints.ErrorDescription; |
78 |
import org.netbeans.spi.editor.hints.ErrorDescription; |
77 |
import org.netbeans.spi.editor.hints.ErrorDescriptionFactory; |
79 |
import org.netbeans.spi.editor.hints.ErrorDescriptionFactory; |
Lines 82-91
Link Here
|
82 |
/** |
84 |
/** |
83 |
* |
85 |
* |
84 |
* @author Jan Lahoda |
86 |
* @author Jan Lahoda |
|
|
87 |
* @author Sam Halliday |
85 |
*/ |
88 |
*/ |
86 |
public class FieldForUnusedParam implements TreeRule { |
89 |
public class FieldForUnusedParam extends AbstractHint { |
87 |
|
90 |
|
88 |
private AtomicBoolean cancel = new AtomicBoolean(); |
91 |
private static final String FINAL_FIELDS = "final-fields"; |
|
|
92 |
|
93 |
public static boolean isFinalFields() { |
94 |
return new FieldForUnusedParam().getPreferences(null).getBoolean(FINAL_FIELDS, true); |
95 |
} |
96 |
|
97 |
public static void setFinalFields(Preferences p, boolean selected) { |
98 |
p.putBoolean(FINAL_FIELDS, selected); |
99 |
} |
100 |
|
101 |
public FieldForUnusedParam() { |
102 |
super(true, true, HintSeverity.CURRENT_LINE_WARNING); |
103 |
} |
104 |
|
105 |
private final AtomicBoolean cancel = new AtomicBoolean(); |
89 |
|
106 |
|
90 |
public Set<Kind> getTreeKinds() { |
107 |
public Set<Kind> getTreeKinds() { |
91 |
return EnumSet.of(Kind.VARIABLE); |
108 |
return EnumSet.of(Kind.VARIABLE); |
Lines 181-188
Link Here
|
181 |
return NbBundle.getMessage(FieldForUnusedParam.class, "DN_FieldUnusedParam"); |
198 |
return NbBundle.getMessage(FieldForUnusedParam.class, "DN_FieldUnusedParam"); |
182 |
} |
199 |
} |
183 |
|
200 |
|
|
|
201 |
@Override |
202 |
public JComponent getCustomizer(Preferences node) { |
203 |
return new FieldForUnusedParamCustomizer(node); |
204 |
} |
205 |
|
184 |
public void cancel() { |
206 |
public void cancel() { |
185 |
cancel.set(true); |
207 |
cancel.set(true); |
|
|
208 |
} |
209 |
|
210 |
@Override |
211 |
public String getDescription() { |
212 |
return NbBundle.getMessage(FieldForUnusedParam.class, "DSC_FieldUnusedParam"); |
186 |
} |
213 |
} |
187 |
|
214 |
|
188 |
static final class FixImpl implements Fix { |
215 |
static final class FixImpl implements Fix { |
Lines 232-238
Link Here
|
232 |
} |
259 |
} |
233 |
|
260 |
|
234 |
if (!existing) { |
261 |
if (!existing) { |
235 |
VariableTree field = make.Variable(make.Modifiers(EnumSet.of(Modifier.PRIVATE)), vt.getName(), vt.getType(), null); |
262 |
Set<Modifier> modifiers = EnumSet.of(Modifier.PRIVATE); |
|
|
263 |
if (isFinalFields()) { |
264 |
modifiers.add(Modifier.FINAL); |
265 |
} |
266 |
VariableTree field = make.Variable(make.Modifiers(modifiers), vt.getName(), vt.getType(), null); |
236 |
int insertPlace = -1; |
267 |
int insertPlace = -1; |
237 |
|
268 |
|
238 |
index = 0; |
269 |
index = 0; |