This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 146163
Collapse All | Expand All

(-)a/java.hints/src/org/netbeans/modules/java/hints/Bundle.properties (+2 lines)
Lines 241-246 Link Here
241
ERR_EQUALS_NOT_CHECKING_TYPE=equals() method not checking type of its parameter
241
ERR_EQUALS_NOT_CHECKING_TYPE=equals() method not checking type of its parameter
242
242
243
DN_FieldUnusedParam=Assign Unused Parameter to Field
243
DN_FieldUnusedParam=Assign Unused Parameter to Field
244
DSC_FieldUnusedParam=Assign Unused Parameter to Field
244
FIX_AssignToExisting=Assign to Existing Field
245
FIX_AssignToExisting=Assign to Existing Field
245
FIX_CreateField=Create Field
246
FIX_CreateField=Create Field
246
ERR_UnusedParameter=Unused Parameter
247
ERR_UnusedParameter=Unused Parameter
Lines 266-268 Link Here
266
HINT_SuspiciousCallIncompatibleTypes=Suspicious call to {0}:\nGiven object cannot contain instances of {1} (expected {2})
267
HINT_SuspiciousCallIncompatibleTypes=Suspicious call to {0}:\nGiven object cannot contain instances of {1} (expected {2})
267
DN_CollectionRemove=Suspicous method call
268
DN_CollectionRemove=Suspicous method call
268
DESC_CollectionRemove=Warns about suspicous calls to Collection.remove/contains and Map.containsKey/containsValue/remove
269
DESC_CollectionRemove=Warns about suspicous calls to Collection.remove/contains and Map.containsKey/containsValue/remove
270
FieldForUnusedParamCustomizer.finalFields.text=<html>Fields are <code>final</code></html>
(-)a/java.hints/src/org/netbeans/modules/java/hints/FieldForUnusedParam.java (-4 / +35 lines)
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;
(-)9ff885f3bede (+51 lines)
Added Link Here
1
<?xml version="1.0" encoding="UTF-8" ?>
2
3
<Form version="1.5" maxVersion="1.6" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
4
  <AuxValues>
5
    <AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="1"/>
6
    <AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
7
    <AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
8
    <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
9
    <AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="true"/>
10
    <AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="2"/>
11
    <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
12
    <AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
13
    <AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
14
  </AuxValues>
15
16
  <Layout>
17
    <DimensionLayout dim="0">
18
      <Group type="103" groupAlignment="0" attributes="0">
19
          <Group type="102" alignment="0" attributes="0">
20
              <EmptySpace min="-2" max="-2" attributes="0"/>
21
              <Component id="finalFields" max="32767" attributes="0"/>
22
              <EmptySpace min="-2" max="-2" attributes="0"/>
23
          </Group>
24
      </Group>
25
    </DimensionLayout>
26
    <DimensionLayout dim="1">
27
      <Group type="103" groupAlignment="0" attributes="0">
28
          <Group type="102" alignment="0" attributes="0">
29
              <EmptySpace max="-2" attributes="0"/>
30
              <Component id="finalFields" min="-2" max="-2" attributes="0"/>
31
              <EmptySpace max="32767" attributes="0"/>
32
          </Group>
33
      </Group>
34
    </DimensionLayout>
35
  </Layout>
36
  <SubComponents>
37
    <Component class="javax.swing.JCheckBox" name="finalFields">
38
      <Properties>
39
        <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
40
          <ResourceString bundle="org/netbeans/modules/java/hints/Bundle.properties" key="FieldForUnusedParamCustomizer.finalFields.text" replaceFormat="org.openide.util.NbBundle.getBundle({sourceFileName}.class).getString(&quot;{key}&quot;)"/>
41
        </Property>
42
      </Properties>
43
      <Events>
44
        <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="finalFieldsActionPerformed"/>
45
      </Events>
46
      <AuxValues>
47
        <AuxValue name="generateMnemonicsCode" type="java.lang.Boolean" value="true"/>
48
      </AuxValues>
49
    </Component>
50
  </SubComponents>
51
</Form>
(-)9ff885f3bede (+91 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 * 
4
 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
5
 * 
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 * 
24
 * Contributor(s):
25
 * 
26
 * Portions Copyrighted 2009 Sun Microsystems, Inc.
27
 */
28
29
package org.netbeans.modules.java.hints;
30
import java.util.prefs.Preferences;
31
32
/**
33
 *
34
 * @author Sam Halliday
35
 */
36
@SuppressWarnings("serial")
37
public class FieldForUnusedParamCustomizer extends javax.swing.JPanel {
38
39
    private Preferences p;
40
41
    /** Creates new form LocalVariableFixCustomizer */
42
    public FieldForUnusedParamCustomizer(Preferences p) {
43
        initComponents();
44
        this.p = p;
45
        finalFields.setSelected(FieldForUnusedParam.isFinalFields());
46
    }
47
48
    /** This method is called from within the constructor to
49
     * initialize the form.
50
     * WARNING: Do NOT modify this code. The content of this method is
51
     * always regenerated by the Form Editor.
52
     */
53
    @SuppressWarnings("unchecked")
54
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
55
    private void initComponents() {
56
57
        finalFields = new javax.swing.JCheckBox();
58
59
        org.openide.awt.Mnemonics.setLocalizedText(finalFields, org.openide.util.NbBundle.getBundle(FieldForUnusedParamCustomizer.class).getString("FieldForUnusedParamCustomizer.finalFields.text")); // NOI18N
60
        finalFields.addActionListener(new java.awt.event.ActionListener() {
61
            public void actionPerformed(java.awt.event.ActionEvent evt) {
62
                finalFieldsActionPerformed(evt);
63
            }
64
        });
65
66
        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
67
        this.setLayout(layout);
68
        layout.setHorizontalGroup(
69
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
70
            .add(layout.createSequentialGroup()
71
                .addContainerGap()
72
                .add(finalFields, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
73
                .addContainerGap())
74
        );
75
        layout.setVerticalGroup(
76
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
77
            .add(layout.createSequentialGroup()
78
                .addContainerGap()
79
                .add(finalFields)
80
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
81
        );
82
    }// </editor-fold>//GEN-END:initComponents
83
84
    private void finalFieldsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_finalFieldsActionPerformed
85
        FieldForUnusedParam.setFinalFields(p, finalFields.isSelected());
86
}//GEN-LAST:event_finalFieldsActionPerformed
87
88
    // Variables declaration - do not modify//GEN-BEGIN:variables
89
    private javax.swing.JCheckBox finalFields;
90
    // End of variables declaration//GEN-END:variables
91
}
(-)a/java.hints/src/org/netbeans/modules/java/hints/errors/CreateElement.java (+4 lines)
Lines 77-82 Link Here
77
import org.netbeans.api.java.source.CompilationInfo;
77
import org.netbeans.api.java.source.CompilationInfo;
78
import org.netbeans.api.java.source.ElementHandle;
78
import org.netbeans.api.java.source.ElementHandle;
79
import org.netbeans.api.java.source.SourceUtils;
79
import org.netbeans.api.java.source.SourceUtils;
80
import org.netbeans.modules.java.hints.FieldForUnusedParam;
80
import org.netbeans.modules.java.hints.errors.CreateClassFix.CreateInnerClassFix;
81
import org.netbeans.modules.java.hints.errors.CreateClassFix.CreateInnerClassFix;
81
import org.netbeans.modules.java.hints.errors.CreateClassFix.CreateOuterClassFix;
82
import org.netbeans.modules.java.hints.errors.CreateClassFix.CreateOuterClassFix;
82
import org.netbeans.modules.java.hints.infrastructure.ErrorHintsProvider;
83
import org.netbeans.modules.java.hints.infrastructure.ErrorHintsProvider;
Lines 378-383 Link Here
378
                    if (target.getKind() == ElementKind.ENUM) {
379
                    if (target.getKind() == ElementKind.ENUM) {
379
                        result.add(new CreateEnumConstant(info, simpleName, modifiers, target, type, targetFile));
380
                        result.add(new CreateEnumConstant(info, simpleName, modifiers, target, type, targetFile));
380
                    } else {
381
                    } else {
382
                        if (firstMethod != null && info.getTrees().getElement(firstMethod).getKind() == ElementKind.CONSTRUCTOR && FieldForUnusedParam.isFinalFields()) {
383
                            modifiers.add(Modifier.FINAL);
384
                        }
381
                        result.add(new CreateFieldFix(info, simpleName, modifiers, target, type, targetFile));
385
                        result.add(new CreateFieldFix(info, simpleName, modifiers, target, type, targetFile));
382
                    }
386
                    }
383
                }
387
                }
(-)a/java.hints/src/org/netbeans/modules/java/hints/resources/layer.xml (-1 / +1 lines)
Lines 139-144 Link Here
139
                    <file name="org-netbeans-modules-java-hints-EqualsMethodHint.instance"/>
139
                    <file name="org-netbeans-modules-java-hints-EqualsMethodHint.instance"/>
140
                    <file name="org-netbeans-modules-java-hints-SyncOnNonFinal.instance"/>
140
                    <file name="org-netbeans-modules-java-hints-SyncOnNonFinal.instance"/>
141
                    <file name="org-netbeans-modules-java-hints-CollectionRemove.instance"/>
141
                    <file name="org-netbeans-modules-java-hints-CollectionRemove.instance"/>
142
                    <file name="org-netbeans-modules-java-hints-FieldForUnusedParam.instance"/>
142
                </folder>
143
                </folder>
143
144
144
                <folder name="errors">
145
                <folder name="errors">
Lines 287-293 Link Here
287
288
288
            <folder name="suggestions">
289
            <folder name="suggestions">
289
                <file name="org-netbeans-modules-java-hints-ConvertAnonymousToInner.instance"/>
290
                <file name="org-netbeans-modules-java-hints-ConvertAnonymousToInner.instance"/>
290
                <file name="org-netbeans-modules-java-hints-FieldForUnusedParam.instance"/>
291
                <file name="org-netbeans-modules-java-hints-DeclarationForInstanceOf.instance"/>
291
                <file name="org-netbeans-modules-java-hints-DeclarationForInstanceOf.instance"/>
292
            </folder>
292
            </folder>
293
         </folder>
293
         </folder>

Return to bug 146163